UserForm collapse ?

V

vbastarter

Hi Just wondering If anyone knows a way to add the icon "_" to collapse a
userform along with "X"(close form icon) that usually comes up on the form
Thanks
 
V

Vasant Nanavati

Try (not fully tested):

Option Explicit

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) 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 GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nindex As Long) As Long

Private Const WS_MINIMIZEBOX = &H20000
Private Const GWL_STYLE = (-16)

Private Sub UserForm_Initialize()
SetWindowStyle FindWindowA(vbNullString, Me.Caption), _
WS_MINIMIZEBOX, True
End Sub

Private Sub SetWindowStyle(hWnd As Long, _
mAttribute As Long, Enable As Boolean)
Dim x As Long
x = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
x = x Or mAttribute
Else
x = x And Not mAttribute
End If
SetWindowLong hWnd, GWL_STYLE, x
End Sub

All the code should go into the UserForm module.
 
V

vbastarter

Thank you it works.

Vasant Nanavati said:
Try (not fully tested):

Option Explicit

Private Declare Function FindWindowA Lib "user32" _
(ByVal lpClassName As String, ByVal lpWindowName _
As String) 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 GetWindowLong Lib "user32" _
Alias "GetWindowLongA" (ByVal hWnd As Long, _
ByVal nindex As Long) As Long

Private Const WS_MINIMIZEBOX = &H20000
Private Const GWL_STYLE = (-16)

Private Sub UserForm_Initialize()
SetWindowStyle FindWindowA(vbNullString, Me.Caption), _
WS_MINIMIZEBOX, True
End Sub

Private Sub SetWindowStyle(hWnd As Long, _
mAttribute As Long, Enable As Boolean)
Dim x As Long
x = GetWindowLong(hWnd, GWL_STYLE)
If Enable Then
x = x Or mAttribute
Else
x = x And Not mAttribute
End If
SetWindowLong hWnd, GWL_STYLE, x
End Sub

All the code should go into the UserForm module.
 
Top