Option Explicit
#If VBA7 Then
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function GetWindowRect Lib "user32" (ByVal hwnd As LongPtr, lpRect As RECT) As Long
Private Declare PtrSafe Function GetDesktopWindow Lib "user32" () As LongPtr
Private Declare PtrSafe Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#Else
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
Private Declare Function GetDesktopWindow Lib "user32" () As Long
Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
#End If
Private Type RECT: Left As Long: Top As Long: Right As Long: Bottom As Long: End Type
Function ptopx() 'fonction coeff point to pixel
With ActiveWindow.ActivePane: ptopx = (.PointsToScreenPixelsX(100) - .PointsToScreenPixelsX(0)) / 100: End With
End Function
Private Sub CommandButton1_Click()
Unload Me
End Sub
Private Sub UserForm_Activate()
MsgBox GetSystemMetrics(6)
Dim r1 As RECT, r2 As RECT
GetWindowRect GetDesktopWindow, r1 'le rectangle de l'ecran
GetWindowRect FindWindow("shell_traywnd", ""), r2 'le rectangle de la barre des taches
r1.Bottom = r2.Top + GetSystemMetrics(15) - GetSystemMetrics(5) ' on remplace le bottom de r1 par le r2.top(top taskbar)
r1.Top = r1.Top - (GetSystemMetrics(15)+ GetSystemMetrics(5))
'Me.Move 0, 0, Int(r1.Right / ptopx), Int(r1.Bottom / ptopx) 'et on place le userform
Me.Move 0, r1.Top / ptopx, Int(r1.Right / ptopx), Int(r1.Bottom / ptopx) 'et on place le userform pas de caption
End Sub