Tipp 10.12 - TOPMOST-Modus

Wie kann ich eine Form TOPMOST anzeigen?

Mit dieser Funktion können Sie eine Form TOPMOST anzeigen. Kopieren Sie einfach nachfolgenden Quellcode in die Zwischenablage und fügen Sie anschließend den Inhalt der Zwischenablage in ein neues Modul ein. Die Aufrufparameter finden Sie im Quellcode beschrieben.

Api-AufrufeVerwendete Win32-Api-Aufrufe und Typen: SetWindowPos

Beispiel:

Option Explicit
 
Public Const HWND_TOPMOST   As Long = -1
Public Const HWND_NOTOPMOST As Long = -2
Public Const SWP_NOMOVE     As Long = &H2
Public Const SWP_NOSIZE     As Long = &H1
Public Const SWP_NOACTIVATE As Long = &H10
Public Const SWP_SHOWWINDOW As Long = &H40
Public Const FLAGS          As Long = SWP_NOMOVE Or _
                                      SWP_NOSIZE
 
Public Declare Function SetWindowPos Lib "user32.dll" _
                       (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
'** In der Form
Private Sub Form_Load()
    Call SetWindowPos(Me.hwnd, _
                      HWND_TOPMOST, _
                      0, _
                      0, _
                      0, _
                      0, _
                      FLAGS)
'** bzw. zurücksetzen:
'   Call SetWindowPos(Me.hwnd, _
                      HWND_NOTOPMOST, _
                      0, _
                      0, _
                      0, _
                      0, _
                      FLAGS)
End Sub