Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

"Hide" the Titlebar? 3

Status
Not open for further replies.

jmrdaddy

Technical User
Jun 10, 2002
31
0
0
US
Is there a property for userforms by which one could "hide" the Titlebar? I'm imagining something like...

Titlebar.Visible = False

Or is it more complex than that?
 
No there isn't a Property of the Userform.
There is however one for all Windows. To do this you need API's.

Note. If you remove this you cannot move or close the form. Thats because this area houses the menus.

The following code requires a Checkbox and is just an Example .... it includes code to Move the Form.

Code:
Option Explicit

Private Declare Function GetWindowRect _
    Lib "User32" ( _
    ByVal hWnd As Long, _
    lpRect As RECT) _
As Long
   
Private Declare Function SetWindowRgn _
    Lib "User32" ( _
        ByVal hWnd As Long, _
        ByVal hRgn As Long, _
        ByVal bRedraw As Long) _
As Long

Private Declare Function FindWindow Lib "User32" _
   Alias "FindWindowA" ( _
   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 GWL_STYLE = (-16)
Private Const WS_CAPTION = &HC00000    ' WS_BORDER Or WS_DLGFRAME
Private Const WS_MAXIMIZEBOX = &H10000
Private Const WS_MINIMIZEBOX = &H20000
Private Const WS_SYSMENU = &H80000

'// Used for moving Captionless form
Private Declare Function SetWindowPos Lib "User32" ( _
   ByVal hWnd As Long, _
   ByVal hWndInsertAfter As Long, _
   ByVal X As Long, _
   ByVal Y As Long, _
   ByVal cx As Long, _
   ByVal cy As Long, _
   ByVal wFlags As Long) As Long

Private Declare Function SendMessage Lib "User32" _
   Alias "SendMessageA" ( _
   ByVal hWnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

Private Declare Sub ReleaseCapture Lib "User32" ()
'//

Private Const SWP_SHOWWINDOW = &H40
Private Const SWP_HIDEWINDOW = &H80
Private Const SWP_FRAMECHANGED = &H20 ' The frame changed: send WM_NCCALCSIZE
Private Const SWP_NOACTIVATE = &H10
Private Const SWP_NOCOPYBITS = &H100
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOOWNERZORDER = &H200    ' Don't do owner Z ordering
Private Const SWP_NOREDRAW = &H8
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER
Private Const SWP_NOSIZE = &H1
Private Const SWP_NOZORDER = &H4
Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const HWND_NOTOPMOST = -2

Private Type POINTAPI
    X As Long
    Y As Long
End Type

Private Type RECT
    Left   As Long
    Top    As Long
    Right  As Long
    Bottom As Long
End Type

Dim FrmWndh  As Long

Private Function ShowTitleBar(ByVal bState As Boolean)
Dim lStyle As Long
Dim tR As RECT

'// Get the window's position:
GetWindowRect FrmWndh, tR

'// Modify whether title bar will be visible:
lStyle = GetWindowLong(FrmWndh, GWL_STYLE)
    '
 If Not bState Then
    lStyle = lStyle And Not WS_SYSMENU
    lStyle = lStyle And Not WS_MAXIMIZEBOX
    lStyle = lStyle And Not WS_MINIMIZEBOX
    lStyle = lStyle And Not WS_CAPTION
Else
    lStyle = lStyle Or WS_SYSMENU
    lStyle = lStyle Or WS_MAXIMIZEBOX
    lStyle = lStyle Or WS_MINIMIZEBOX
    lStyle = lStyle Or WS_CAPTION
End If

SetWindowLong FrmWndh, GWL_STYLE, lStyle

'// Ensure the style takes and make the window the
'// same size, regardless that the title bar
'// is now a different size:
SetWindowPos FrmWndh, 0, tR.Left, tR.Top, tR.Right - tR.Left, tR.Bottom - tR.Top, _
    SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED
Me.Repaint

End Function

Private Sub CheckBox1_Click()
   ShowTitleBar Not (CheckBox1.Value)
End Sub

' MODIFIED: Ivan F Moala 2/6/2002

Private Sub UserForm_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
'// Leave this here as your backdoor, incase you have NO CLOSE BUTTON
    Unload UserForm1
End Sub

Private Sub UserForm_Initialize()
'// Get Forms window handle set Variable NOW!
    FrmWndh = FindWindow(vbNullString, Me.Caption)
    ShowTitleBar True
End Sub

Private Sub UserForm_MouseDown(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
'// allows us to move the Captionless form, only IF Captionless!
    Const WM_NCLBUTTONDOWN = &HA1
    Const HTCAPTION = 2
    If Button = 1 And (CheckBox1.Value) Then
        ReleaseCapture
        SendMessage FrmWndh, WM_NCLBUTTONDOWN, HTCAPTION, 0&
    End If
End Sub

Ivan F Moala
xcelsmall.bmp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top