You are on page 1of 2

MAXIMIZAR E MINIMIZAR FORM

(MÓDULO)

Option Explicit

'Declare Function FindWindowA& Lib "User32" (ByVal lpClassName$, ByVal lpWindowName$)

'Declare Function GetWindowLongA& Lib "User32" (ByVal hWnd&, ByVal nIndex&)

'Declare Function SetWindowLongA& Lib "User32" (ByVal hWnd&, ByVal nIndex&, ByVal
dwNewLong&)

Public Declare PtrSafe Function FindWindowA& Lib "User32" (ByVal lpClassName$, ByVal
lpWindowName$)

Public Declare PtrSafe Function GetWindowLongA& Lib "User32" (ByVal hWnd&, ByVal
nIndex&)

Public Declare PtrSafe 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
(USERFORM)

'Declarações

Option Explicit

Dim Lg As Single

Dim Ht As Single

Dim Fini As Boolean

Private Sub UserForm_Initialize()

InitMaxMin Me.Caption

Ht = Me.Height

Lg = Me.Width

End Sub

'Instrução para redimensionar o formulário

Private Sub UserForm_Resize()

Dim RtL As Single, RtH As Single

If Me.Width < 300 Or Me.Height < 200 Or Fini Then Exit Sub

RtL = Me.Width / Lg

RtH = Me.Height / Ht

Me.Zoom = IIf(RtL < RtH, RtL, RtH) * 100

End Sub

Private Sub UserForm_Terminate()

Fini = True

End Sub

You might also like