I use the following code to remove captions, however if my script opens multiple forms then it only removes the caption from the last opened form, utill I click on the others and then it removes them.
Can someone please help with a code to remove each caption when the forms open.
My remove caption script is already in the form module, as per note at the end.
NOTE: I already have the remove caption in the form code as follows
Can someone please help with a code to remove each caption when the forms open.
My remove caption script is already in the form module, as per note at the end.
Code:
'Option Private Module
'Returns the Window Handle of the Window
'that is accepting User input.
Public Declare Function GetForegroundWindow _
Lib "user32.dll" () As Long
Private Declare Function GetWindowLong _
Lib "user32.dll" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long) As Long
Private Declare Function SetWindowLong _
Lib "user32.dll" _
Alias "SetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
'Redraw the Icons on the Window's Title Bar
Private Declare Function DrawMenuBar _
Lib "user32.dll" _
(ByVal hwnd As Long) As Long
Private Const GWL_STYLE As Long = (-16)
Private Const WS_CAPTION = &HC00000
Sub RemoveCaption(ByVal hwnd As Long)
Dim BitMask As Long
Dim WindowStyle As Long
WindowStyle = GetWindowLong(hwnd, GWL_STYLE)
BitMask = WindowStyle And (Not WS_CAPTION)
Call SetWindowLong(hwnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hwnd)
End Sub
Sub RestoreCaption(ByVal hwnd As Long)
Dim BitMask As Long
Dim WindowStyle As Long
WindowStyle = GetWindowLong(hwnd, GWL_STYLE)
BitMask = WindowStyle Or WS_CAPTION
Call SetWindowLong(hwnd, GWL_STYLE, BitMask)
Call DrawMenuBar(hwnd)
End Sub
'Example of Restoring Excel's Caption
'Sub Restore_Windows_Caption()
'RestoreCaption Application.hwnd
'End Sub
NOTE: I already have the remove caption in the form code as follows
Code:
Private Sub UserForm_Activate()
RemoveCaption GetForegroundWindow
end sub