1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| '--- dans un module:
Option Explicit
'--- https://ccm.net/faq/27876-vba-minimize-maximize-a-userform
Public Declare Function FindWindowA& Lib "User32" (ByVal lpClassName$, ByVal lpWindowName$)
Public Declare Function GetWindowLongA& Lib "User32" (ByVal hWnd&, ByVal nIndex&)
Public Declare Function SetWindowLongA& Lib "User32" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&)
' Déclaration des constantes
Public Const GWL_STYLE As Long = -16
Public Const WS_MINIMIZEBOX = &H20000
Public Const WS_MAXIMIZEBOX = &H10000
Public Const WS_FULLSIZING = &H70000
'Attention, envoyer après changement du caption de l'UF
Public Sub InitMaxMin(mCaption As String, _
Optional Max As Boolean = True, _
Optional Min As Boolean = True, _
Optional Sizing As Boolean = True)
Dim hWnd As Long
hWnd = FindWindowA(vbNullString, mCaption)
If Min Then SetWindowLongA hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) Or WS_MINIMIZEBOX
If Max Then SetWindowLongA hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) Or WS_MAXIMIZEBOX
If Sizing Then SetWindowLongA hWnd, GWL_STYLE, GetWindowLongA(hWnd, GWL_STYLE) Or WS_FULLSIZING
End Sub
Sub Voir()
UserForm1.Show
End Sub
'--- dans le code du formulaire UserForm
Private Sub UserForm_Initialize()
InitMaxMin Me.Caption
End Sub |
Partager