'Enlever la barre de titre d'un userform et retrouver la taille initial dans le inside du userform
'created by patricktoulon et @Dudu2
'Discussion:https://excel-downloads.com/threads/vba-redimensionner-un-userform-apres-le-retrait-de-la-barre-du-menu-systeme-caption.20085127/page-4#post-20667195
#If VBA7 Then
#If Win64 Then
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongPtrA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#Else
Private Declare PtrSafe Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As LongPtr, ByVal nIndex As Long, ByVal dwNewLong As LongPtr) As LongPtr
#End If
Private Declare PtrSafe Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
#Else
Private Declare Function SetWindowLongPtr Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
#End If
Sub NoTitleBar(form)
Dim OldInW, OldInH
With form
'memo des dimensions interieures original (Affichage)
OldInW = .InsideWidth
OldInH = .InsideHeight
'on enlève la caption
hWnd = FindWindow(vbNullString, form.Caption)
SetWindowLongPtr hWnd, -16, &H94080080 'on retire la barre de titre
'Pour provoquer l'update des Inside après le SetWindowLongPtr()
.Width = .Width + 1
.Width = .Width - 1
'Correction des dimensions interieuresen enelebant la différence du inside actuel a celui de lancien
.Width = .Width - (.InsideWidth - OldInW)
.Height = .Height - (.InsideHeight - OldInH)
End With
End Sub
Sub showpat()
Unload UserForm1
UserForm1.Show 0
End Sub
Sub showpat2()
NoTitleBar UserForm1
End Sub
Sub showpat3()
Dim OldL, OldT
'memo des position left et top
'on reload le userform en exitant son initialise en faisant appel a sa propriété caption
'ce qui a pour consequance de reloader le userform avec la barre de titre caption
'remise en position left et top avec les positions memorisées
With UserForm1
OldL = .Left
OldT = .Top
.Caption = .Caption
.Left = OldL
.Top = OldT
End With
End Sub