ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   UserForm collapse ? (https://www.excelbanter.com/excel-programming/308725-userform-collapse.html)

vbastarter

UserForm collapse ?
 
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

Vasant Nanavati

UserForm collapse ?
 
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.

--

Vasant


"vbastarter" wrote in message
...
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




vbastarter

UserForm collapse ?
 
Thank you it works.

"Vasant Nanavati" wrote:

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.

--

Vasant


"vbastarter" wrote in message
...
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






All times are GMT +1. The time now is 03:49 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com