Option Explicit
'argument nCmdShow pour showwindow
'SW_NORMAL 1 Identique à SW_SHOWNORMAL.
'SW_SHOWMINIMIZED 2 Affiche la fenêtre minimisée.
'SW_SHOWMAXIMIZED 3 Affiche la fenêtre maximisée.
'SW_MAXIMIZE 3 Identique à SW_SHOWMAXIMIZED.
'SW_SHOWNOACTIVATE 4 Affiche dans l'état actuel sans activer la fenêtre.
'SW_SHOW 5 Affiche la fenêtre dans son dernier état et l’active.
'SW_MINIMIZE 6 Réduit la fenêtre et active la suivante.
'SW_SHOWMINNOACTIVE 7 Affiche la fenêtre minimisée sans l’activer.
'SW_SHOWNA 8 Affiche la fenêtre dans son état actuel sans l’activer.
'SW_RESTORE 9 Restaure une fenêtre minimisée ou maximisée dans son état normal.
'SW_SHOWDEFAULT 10 L’état d'affichage est déterminé par le programme qui la lance.
#If VBA7 Then
Declare PtrSafe Function ShowWindow Lib "user32" (ByVal hwnd As LongPtr, ByVal nCmdShow As Long) As Long
Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Declare PtrSafe Function SetWindowPos Lib "user32" (ByVal hwnd As LongPtr, ByVal hWndInsertAfter As LongPtr, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
#Else
Declare Function GetActiveWindow Lib "user32" () As Long
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
Declare Function ShowWindow Lib "user32" (ByVal hwnd As Long, ByVal nCmdShow As Long) As Long
#End If
Sub a()
Dim HactiF As LongPtr, param As Long
[b1:b3].ClearContents
param = &H1 + &H2 + &H20 + &H40 + &H200 'les paramètre de position et Flag c'est la totale in firstplan (indémontable)
UserForm1.Show vbModeless
DoEvents
[b3] = GetActiveWindow
'on titille la fenêtre successivement au premier plan et juste en dessous
SetWindowPos Application.hwnd, -1, 0&, 0&, 0&, 0&, param 'pemier plan
SetWindowPos Application.hwnd, 1, 0&, 0&, 0&, 0&, param 'on redescend d'un cran
ShowWindow Application.hwnd, 5 'pas d'ambiguité showWindow hwnd,5 affiche et active!!!!! la fenêtre (voir les options en haut de module en commentaire )
HactiF = GetActiveWindow 'recuperation de la fenêtre active
'MsgBox HactiF & vbCrLf & Application.hwnd 'le message de verdict
[b1] = GetActiveWindow
[b2] = Application.hwnd
End Sub