Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Excel hide caption bar...

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!!!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Excel hide caption bar...

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

--
Regards,
Tom Ogilvy

wrote in message
ups.com...
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!!!



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 162
Default Excel hide caption bar...

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


Tom Ogilvy wrote:
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

--
Regards,
Tom Ogilvy

wrote in message
ups.com...
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!!!


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how do I add a caption to a picture in Excel SooDesuNe Excel Discussion (Misc queries) 4 November 15th 07 05:29 PM
Caption attribute at Cell in Excel XML dob_xml Excel Discussion (Misc queries) 0 November 27th 06 12:05 PM
Caption at Cell level of Excel XML dob_xml Excel Discussion (Misc queries) 0 November 27th 06 12:01 PM
Hide Window Caption Bar Mats Nilsson Excel Programming 4 August 28th 06 07:02 PM
How to reference win.caption, when caption changes Paul987[_21_] Excel Programming 3 April 7th 06 05:09 PM


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

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"