Problem with hiding Userform Title bar andCaption bar

PlamenGop

New Member
Joined
Jan 19, 2014
Messages
6
Hi, anyone who can help....

In a small application (Excel 2010, 64 bit) I nave some Userform and on some I want to hide the caption bar with the Close, Minimize, etc. buttons. I am using this code:

Private Const GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000
Private Declare PtrSafe Function FindWindow Lib "user32" Alias _
"FindWindowA" (ByVal lpClassName As String, ByVal _
lpWindowName As String) As LongPtr
Private Declare PtrSafe Function GetWindowLong Lib "user32" Alias _
"GetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex _
As Long) As LongPtr
Private Declare PtrSafe Function SetWindowLong Lib "user32" Alias _
"SetWindowLongA" (ByVal hwnd As LongPtr, ByVal nIndex _
As Long, ByVal dwNewLong As LongPtr) As LongPtr
Private Declare PtrSafe Function SendMessage Lib "user32" Alias _
"SendMessageA" (ByVal hwnd As LongPtr, ByVal wMsg As Long, _
ByVal wParam As Integer, ByVal lParam As Long) As LongPtr
Private Declare PtrSafe Function DrawMenuBar Lib "user32" (ByVal _
hwnd As LongPtr) As LongPtr
and in the Activate event:
If Val(Application.Version) >= 9 Thenwhandle = FindWindow("ThunderDFrame", Me.Caption)
Else
whandle = FindWindow("ThunderXFrame", Me.Caption)
End If
If whandle = 0 Then Exit Sub
''
lStyle = GetWindowLong(whandle, GWL_STYLE)
Me.Caption = ""
lStyle = lStyle And Not WS_SYSMENU
lStyle = lStyle And Not WS_MAXIMIZEBOX
lStyle = lStyle And Not WS_MINIMIZEBOX
lStyle = lStyle And Not WS_CAPTION
'SetWindowLong whandle, -20, frm
SetWindowLong whandle, GWL_STYLE, lStyle
DrawMenuBar whandle
It works fine - hides what I need .... The problem is that if I don't close the app, with every unload /unload of the form, the content is moving up - I suppose some of the functions "cuts"a piece of the content a belt with the height of the border ...
Is there any code to restore the form in the initial state before unloading ?
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"

Forum statistics

Threads
1,223,150
Messages
6,170,378
Members
452,322
Latest member
CrimsonCoure

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top