Excel hide caption bar...

S

Shaka215

Happy 2007 Everyone!

I am in need of some code to completely remove the CAPTION BAR from a
VB User Form (The bar at the top of the user form that has the form
caption, minimize, maximize, and close buttons). I use to have a
working example of the code but I managed to lose it. Any help is much
appreciated!!!
 
T

Tom Ogilvy

Put all this in the Userform code module at the top: (make sure you have a
way to close the userform - such as the code in the commandbutton).

Private Declare Function FindWindow _
Lib "user32" _
Alias "FindWindowA" _
( _
ByVal lpClassName As String, _
ByVal lpWindowName As String _
) _
As Long


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 DrawMenuBar _
Lib "user32" _
( _
ByVal hWnd As Long _
) _
As Long

Private Function fncHasUserformCaption _
( _
bState As Boolean _
)
'change the style of the Userform window to have a
'caption or not to


'declarations of variables
Dim Userform_hWnd As Long
Dim Userform_Style As Long


'required API consatants
Const GWL_STYLE = (-16)
Const WS_CAPTION = &HC00000


'get a handle to the userform window
Userform_hWnd = FindWindow _
( _
lpClassName:=IIf(Val(Application.Version) > 8, _
"ThunderDFrame", _
"ThunderXFrame"), _
lpWindowName:=Me.Caption _
)


'get the current style of the window
Userform_Style = GetWindowLong _
( _
hWnd:=Userform_hWnd, _
nIndex:=GWL_STYLE _
)


'deside whether to redraw the form with a caption or without
'based on the bState parameter
If bState = True Then
Userform_Style = Userform_Style Or WS_CAPTION
Else
Userform_Style = Userform_Style And Not WS_CAPTION
End If
'set the new style to the window
Call SetWindowLong _
( _
hWnd:=Userform_hWnd, _
nIndex:=GWL_STYLE, _
dwNewLong:=Userform_Style _
)


'redraw the window using the new style
Call DrawMenuBar _
( _
hWnd:=Userform_hWnd _
)



End Function


Private Sub CommandButton1_Click()
Unload Me
End Sub


Private Sub UserForm_Initialize()
fncHasUserformCaption False
End Sub
 
S

Shaka215

Code worked great Tom! When I become a millionaire Ill track you down
and name a wing of a hospital after you...LoL Happy New Years Buddy!

-Todd
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top