vb@rchiv
VB Classic
VB.NET
ADO.NET
VBA
C#
Schützen Sie Ihre Software vor Software-Piraterie - mit sevLock 1.0 DLL!  
 vb@rchiv Quick-Search: Suche startenErweiterte Suche starten   Impressum  | Datenschutz  | vb@rchiv CD Vol.6  | Shop Copyright ©2000-2025
 
zurück

 Sie sind aktuell nicht angemeldet.Funktionen: Einloggen  |  Neu registrieren  |  Suchen

Visual-Basic Einsteiger
Re: Form immer im Vordergrund 
Autor: VBMichi
Datum: 22.11.06 12:07

Form immer oben halten:

Code im Modul:

Private Declare Function CreateSolidBrush Lib "gdi32" (ByVal crColor As Long) _
  As Long
 
Private Declare Function GetMenu Lib "user32" (ByVal hWnd As Long) As Long
 
Private Declare Function DrawMenuBar Lib "user32" _
    (ByVal hWnd As Long) As Long
 
Private Declare Function SetMenuInfo Lib "user32" _
    (ByVal Hmenu As Long, Mi As MENUINFO) As Long
 
Private Declare Function OleTranslateColor Lib "olepro32.dll" _
    (ByVal OLE_COLOR As Long, ByVal HPALETTE As Long, _
    pccolorref As Long) As Long
 
Private Declare Function GetSystemMenu Lib "user32" _
    (ByVal hWnd As Long, ByVal bRevert As Long) As Long
 
Private Declare Function GetMenuItemCountA Lib "user32" Alias _
    "GetMenuItemCount" (ByVal Hmenu As Long) As Long
 
Private Declare Function GetSubMenu Lib "user32" _
    (ByVal Hmenu As Long, ByVal nPos As Long) As Long
 
Private Type MENUINFO
    cbSize          As Long
    fMask           As Long
    dwStyle         As Long
    cyMax           As Long
    hbrBack         As Long
    dwContextHelpID As Long
    dwMenuData      As Long
End Type
 
Public Enum MenuNFO
    mMenuBarColor = 1
    mMenuColor = 2
    mSysMenuColor = 3
End Enum
 
Private Const MIM_BACKGROUND As Long = &H2&
Private Const MIM_APPLYTOSUBMENUS As Long = &H80000000
 
Public Function Set_MenuColor(SetWhat As MenuNFO, _
    ByVal hWnd As Long, ByVal Color As Long, _
    Optional MenuIndex As Integer, _
    Optional IncludeSubmenus As Boolean = False) As Boolean
 
    Dim Mi As MENUINFO
    Dim clrref As Long, hSysMenu As Long, mHwnd As Long
 
    On Local Error GoTo Quit
 
    clrref = Convert_OLEtoRBG(Color)
 
    Mi.cbSize = Len(Mi)
    Mi.hbrBack = CreateSolidBrush(clrref)
 
    Select Case SetWhat
        Case mMenuBarColor
            Mi.fMask = MIM_BACKGROUND
            Call SetMenuInfo(GetMenu(hWnd), Mi)
 
        Case mMenuColor
            If MenuIndex = 0 Then
                Set_MenuColor = Set_MenuColor(mMenuBarColor, hWnd, Color)
                Exit Function
            End If
 
            If MenuIndex < 1 Or Get_MenuItemCount(hWnd) < MenuIndex Then _
                Exit Function
 
            Mi.fMask = IIf(IncludeSubmenus, _
                           MIM_BACKGROUND Or MIM_APPLYTOSUBMENUS, _
                           MIM_BACKGROUND)
 
            mHwnd = GetMenu(hWnd)
            mHwnd = GetSubMenu(mHwnd, MenuIndex - 1)
 
            Call SetMenuInfo(mHwnd, Mi)
            hWnd = mHwnd
 
        Case mSysMenuColor
            hSysMenu = GetSystemMenu(hWnd, False)
 
            Mi.fMask = MIM_BACKGROUND _
                       Or MIM_APPLYTOSUBMENUS
 
            Call SetMenuInfo(hSysMenu, Mi)
            hWnd = hSysMenu
    End Select
 
    Call DrawMenuBar(hWnd)
    Set_MenuColor = True
Quit:
End Function
 
Private Function Convert_OLEtoRBG(ByVal OLEcolor As Long) As Long
    Call OleTranslateColor(OLEcolor, 0, Convert_OLEtoRBG)
End Function
 
Private Function Get_MenuItemCount(ByVal hWnd As Long) As Long
    Get_MenuItemCount = GetMenuItemCountA(Get_MenuHwnd(hWnd))
End Function
 
Private Function Get_MenuHwnd(ByVal hWnd As Long) As Long
    Get_MenuHwnd = GetMenu(hWnd)
End Function
Deklaration in der Form:

Private Const SWP_NOMOVE As Long = &H2
Private Const SWP_NOSIZE As Long = &H1
Private Const HWND_TOPMOST As Long = -1&
Private Const HWND_NOTOPMOST As Long = -2&
 
Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd As Long, _
    ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, _
    ByVal cx As Long, _
    ByVal cy As Long, ByVal wFlags As Long) As Long
Code in der Form zum aktivieren:

SetWindowPos hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE + _
    SWP_NOSIZE
Code in der Form zum deaktivieren:

SetWindowPos hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE + _
    SWP_NOSIZE
Grüße
alle Nachrichten anzeigenGesamtübersicht  |  Zum Thema  |  Suchen

 ThemaViews  AutorDatum
Form immer im Vordergrund861ronnie22.11.06 09:27
Re: Form immer im Vordergrund728effeff22.11.06 09:50
Re: Form immer im Vordergrund662vbtricks22.11.06 10:40
Re: Form immer im Vordergrund682VBMichi22.11.06 12:07
Re: Form immer im Vordergrund645vbtricks22.11.06 12:30

Sie sind nicht angemeldet!
Um auf diesen Beitrag zu antworten oder neue Beiträge schreiben zu können, müssen Sie sich zunächst anmelden.

Einloggen  |  Neu registrieren

Funktionen:  Zum Thema  |  GesamtübersichtSuchen 

nach obenzurück
 
   

Copyright ©2000-2025 vb@rchiv Dieter Otter
Alle Rechte vorbehalten.
Microsoft, Windows und Visual Basic sind entweder eingetragene Marken oder Marken der Microsoft Corporation in den USA und/oder anderen Ländern. Weitere auf dieser Homepage aufgeführten Produkt- und Firmennamen können geschützte Marken ihrer jeweiligen Inhaber sein.

Diese Seiten wurden optimiert für eine Bildschirmauflösung von mind. 1280x1024 Pixel