Change the window style
(by adding Maximize/Minimize-buttons, making the window resizeable;)
Option Explicit
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
'Get/SetWindowLong flags
Const GWL_EXSTYLE As Long = (-20)
Const GWL_STYLE As Long = (-16)
'WINDOW STYLES
Const WS_BORDER As Long = &H800000
Const WS_CAPTION As Long = &HC00000
Const WS_CHILD As Long = &H40000000
Const WS_CHILDWINDOW As Long = (WS_CHILD)
Const WS_CLIPCHILDREN As Long = &H2000000
Const WS_CLIPSIBLINGS As Long = &H4000000
Const WS_DISABLED As Long = &H8000000
Const WS_DLGFRAME As Long = &H400000
Const WS_GROUP As Long = &H20000
Const WS_HSCROLL As Long = &H100000
Const WS_MAXIMIZE As Long = &H1000000
Const WS_MAXIMIZEBOX As Long = &H10000
Const WS_MINIMIZE As Long = &H20000000
Const WS_ICONIC As Long = WS_MINIMIZE
Const WS_MINIMIZEBOX As Long = &H20000
Const WS_OVERLAPPED As Long = &H0&
Const WS_SYSMENU As Long = &H80000
Const WS_THICKFRAME As Long = &H40000
Const WS_OVERLAPPEDWINDOW As Long = (WS_OVERLAPPED Or WS_CAPTION Or WS_SYSMENU Or WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX)
Const WS_POPUP As Long = &H80000000
Const WS_POPUPWINDOW As Long = (WS_POPUP Or WS_BORDER Or WS_SYSMENU)
Const WS_SIZEBOX As Long = WS_THICKFRAME
Const WS_TABSTOP As Long = &H10000
Const WS_TILED As Long = WS_OVERLAPPED
Const WS_TILEDWINDOW As Long = WS_OVERLAPPEDWINDOW
Const WS_VISIBLE As Long = &H10000000
Const WS_VSCROLL As Long = &H200000
Private Sub UserForm_Initialize()
ChangeWindowStyle
End Sub
Sub ChangeWindowStyle()
Dim lRet As Long
Dim hWnd As Long
hWnd = GetUserFormHandle(Me)
If hWnd = 0 Then
MsgBox "Could not get handle to Userform!" & vbCrLf _
& "Quitting ...", vbOKOnly Or vbCritical, "DisableExit"
Exit Sub
End If
lRet = GetWindowLong(hWnd, GWL_STYLE)
If lRet <> 0 Then
SetWindowLong hWnd, GWL_STYLE, lRet Or WS_OVERLAPPEDWINDOW
End If
End Sub
Function GetUserFormHandle(UF As UserForm) As Long
Dim hWnd_UF As Long
hWnd_UF = FindWindow("ThunderDFrame", UF.Caption)
GetUserFormHandle = hWnd_UF
End Function
You cannot combine all styles.
Some may need additional event handling in WindowProc., e.g. a scrollbar without a handler for WM_XScroll events is useless.