[UserForm P2] Oter cadre et barre de titre
Si l'ont veux un peu sortir du design traditionnel des UserForm ont peu commencer par enlever le cadre, c'est ce que cette fonction fait.
Voir une démo générale sur ce tuto.
Coller le code ci-dessous dans un module général (Module1 par exemple)
Option Explicit
'Pour enlever la barre de titre du UF
Public Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Public Const GWL_STYLE = (-16)
Public Const WS_CAPTION = &HC00000
Public Const SWP_FRAMECHANGED = &H20
Public Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Public Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, lpRect As RECT) As Long
Public Declare Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Public 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
Sub OteTitleBarre(stCaption As String, pbVisible As Boolean)
Dim vrWin As RECT
Dim style As Long
Dim lHwnd As Long
'- Recherche du handle de la fenêtre par son Caption
lHwnd = FindWindowA(vbNullString, stCaption)
If lHwnd = 0 Then
MsgBox "Handle de " & stCaption & " Introuvable", vbCritical
Exit Sub
End If
GetWindowRect lHwnd, vrWin
style = GetWindowLong(lHwnd, GWL_STYLE)
If pbVisible Then
SetWindowLong lHwnd, GWL_STYLE, style Or WS_CAPTION
Else
SetWindowLong lHwnd, GWL_STYLE, style And Not WS_CAPTION
End If
SetWindowPos lHwnd, 0, vrWin.Left, vrWin.Top, vrWin.Right - vrWin.Left, _
vrWin.Bottom - vrWin.Top, SWP_FRAMECHANGED
End Sub
Et dans l'UserForm
Private Sub UserForm_Initialize()
'Enlever le cadre de l'UF
OteTitleBarre Me.Caption, False 'True pour le remettre
End Sub
Le cadre étant enlever il n'y a plus la possibilité de déplacer l'UserForm, s'il est nécessaire de le déplacer Voir [UserForm P3]
Bonjour,
C'est du VBA mais il est fait appel aux API de Windows
Tu colle les codes dans les modules spécifiés et ça fonctionne sur Excel.
A+