Option Explicit
#If VBA7 Then
#If Win64 Then
'certaines api se déclare différemment en 32 ou 64 dans VBA7 ou VBA7.01
'ici c'est bon c'est pas le cas
#Else
'donc on met tout dans VBA7 tout court
Private Declare PtrSafe Function GetActiveWindow Lib "user32" () As LongPtr
Private 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
Private Declare PtrSafe Function GetParent Lib "user32" (ByVal hwnd As LongPtr) As LongPtr
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
#Else 'si Excel 32 inferieur à 2010
Private Declare Function GetActiveWindow Lib "user32" () As Long
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
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
#End If
#If Win64 Or VBA7 Then
Dim hwnd As LongPtr, HwndP As LongPtr
#Else
Dim hwnd As Long, HwndP As Long
#End If
Private Sub UserForm_Activate()
Dim Avant As Long, Après As Long
'hwnd = GetForegroundWindow
hwnd = GetActiveWindow
SetWindowPos hwnd, -2, 0, 0, 0, 0, &H43 ' Au dessus seulement des fenêtres qui ne sont pas en -1 mais sous celles ci.
'Avant = GetWindowLong(hwnd, -8)
Avant = GetParent(hwnd)
SetWindowLong hwnd, -8, 0 ' Pour le rendre indépendant de toute autre fenêtre.
'Après = GetWindowLong(hwnd, -8)
Après = GetParent(hwnd)
MsgBox "GetWindowLong(" & hwnd & ", -8) :" _
& vbLf & "Avant SetWindowLong " & hwnd & ", -8, 0 : = " & Avant _
& vbLf & "Après SetWindowLong " & hwnd & ", -8, 0 : = " & Après
End Sub