Fenster Dauerhaft im Vordergrund

Hall VBler,

wie erreiche ich, dass ein VB-Programm dauerhaft im Vordergrund bleibt, und wie lässt sich diese Funktion wieder rückgänig machen

mj58

’ Definitionen dafür, dass das Fenster immer das Oberste ist
Private Declare Function SetWindowPos& Lib _
„user32“ (ByVal hWnd&, ByVal WndInsertAfter&, _
Hi!

Hiermit ist Form1 immer sichtbar. Wie das rückgängig geht, weiss ich gerade nicht…
Probiere einfach was mit dem Code weiter unten aus…

’ START

ByVal X&, ByVal Y&, ByVal cx&, ByVal cy&, _
ByVal wFlags&amp:wink:

Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_TOPMOST = -1

Private Sub Form_Resize()
’ Formular als Oberstes bestimmen
SetWindowPos Form1.hWnd, HWND_TOPMOST, Left / _
Screen.TwipsPerPixelX, Top / _
Screen.TwipsPerPixelY, Width / _
Screen.TwipsPerPixelX, Height / _
Screen.TwipsPerPixelY, SWP_SHOWWINDOW
End Sub

’ ENDE

Viele Grüße
Patrick

http://www.Network4Friends.de
Dein Trend. Dein Netz. Deine Welt

Oops
Oops, sorry, da fehlte noch was…

Hier der komplette Code:

’ Definitionen dafür, dass das Fenster immer das Oberste ist
Private Declare Function SetWindowPos& Lib _
„user32“ (ByVal hWnd&, ByVal WndInsertAfter&, _
ByVal X&, ByVal Y&, ByVal cx&, ByVal cy&, _
ByVal wFlags&amp:wink:

Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_TOPMOST = -1

Private Sub Form_Resize()
’ Formular als Oberstes bestimmen
SetWindowPos Form1.hWnd, HWND_TOPMOST, Left / _
Screen.TwipsPerPixelX, Top / _
Screen.TwipsPerPixelY, Width / _
Screen.TwipsPerPixelX, Height / _
Screen.TwipsPerPixelY, SWP_SHOWWINDOW
End Sub

Noch etwas eleganter
Hallo

Hier der selbe Code noch etwas eleganter und bereits in eine Funktion
verpackt:

’ Deklaration:
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_SHOWWINDOW = &H40
Private 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

Private Sub SetWinPos(frmForm As Form, bolSetToForeground As Boolean)
If bolSetToForeground = True Then
Call SetWindowPos(frmForm.hWnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE
Or SWP_NOSIZE Or SWP_SHOWWINDOW)
Else
Call SetWindowPos(frmForm.hWnd, HWND_NOTOPMOST, 0, 0, 0, 0,
SWP_NOMOVE Or SWP_NOSIZE Or SWP_SHOWWINDOW)
End If
End Sub

’ (1) In den Vordergrund holen:
Call SetWinPos(Me, True)

’ (2) Nicht mehr in den Vordergrund holen
Call SetWinPos(Me, False)

Mit freundlichen Grüssen

Samuel

Team: Name entfernt