Resizeable Userform mit Min- und Max- Systemmenü
Beispieldatei (MinMaxResizeForm.zip
16 kB)
Sie möchten die Größe der Userform mit der Maus verändern,
wie sie es von anderen Fenstern kennen und außerdem wollen sie noch in der Titelleiste die Min/Max-Buttons
anzeigen?
Kein Problem. In dem man den Fensterstil
der Userform anpasst, ist so etwas recht einfach möglich.
In das Klassenmenü der Userform:
Option Explicit
'Für Min-Max Schaltfläche und Resize
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal _
nIndex As Long) As Long
Private Declare Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex _
As Long, ByVal dwNewLong As Long) As Long
Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) As Long
Private Declare Function DrawMenuBar Lib "user32" _
(ByVal hwnd As Long) As Long
Private Const GWL_STYLE = (-16)
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_THICKFRAME = &H40000
Private hForm As Long
Private Sub MinMaxMenu()
Dim lStyle As Long
Dim sTitel As String
If hForm = 0 Then
sTitel = Me.Caption
Me.Caption = "lhdsgterfsdt"
hForm = FindWindowA(vbNullString, "lhdsgterfsdt")
Me.Caption = sTitel
End If
lStyle = GetWindowLong(hForm, GWL_STYLE)
lStyle = lStyle Or WS_MAXIMIZEBOX
lStyle = lStyle Or WS_MINIMIZEBOX
lStyle = lStyle Or WS_THICKFRAME
SetWindowLong hForm, GWL_STYLE, lStyle
DrawMenuBar hForm
End Sub
Private Sub UserForm_Activate()
MinMaxMenu
End Sub
Private Sub UserForm_Resize()
MinMaxMenu
End Sub