Comment faire pour qu'une fenêtre reste toujours au premier plan ?
Il faut utiliser l'API SetWindowsPos. Voici le code d'une fonction permettant
d'activer ou de désactiver l'affichage au premier plan d'une fenêtre :
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_SHOWWINDOW = &H40
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2
Private Const Flags = SWP_NOACTIVATE Or SWP_SHOWWINDOW Or SWP_NOMOVE Or
SWP_NOSIZE
Private Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos"
(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 Function SetTopMostWindow(Window As Form, Topmost As Boolean) As Long
If Topmost = True Then
SetTopMostWindow = SetWindowPos(Window.hwnd,
HWND_TOPMOST, 0, 0, 0, 0, Flags)
Else
SetTopMostWindow = SetWindowPos(Window.hwnd,
HWND_NOTOPMOST, 0, 0, 0, 0, Flags)
End If
End Function
Private Sub Form_Load()
'Exemples d'utilisations de la fonction :
SetTopMostWindow Me, True 'Active l'affichage au premier plan
SetTopMostWindow Me, False 'Désactive l'affichage au premier
plan
End Sub |