Home » Forms » How to Hide/Show the Title bar at Run-Time
How to Hide/Show the Title bar at Run-Time
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | 'Forms - How to Hide/Show the Title bar at Run-Time Option Explicit 'Add 2 Command Buttons to your Form. The first one is for to hide the titlebar. 'The second one is to show it again. Warning: if you will click one of the 'buttons twice a row, For example pressing the hide titlebar button when the titlebar 'is already hidden, and vise versia, you will get errors. 'Insert the following code to your form: 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 Private Const WS_MAXIMIZEBOX = &H10000 Private Const WS_MINIMIZEBOX = &H20000 Private Const WS_SYSMENU = &H80000 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 Enum ESetWindowPosStyles SWP_SHOWWINDOW = &H40 SWP_HIDEWINDOW = &H80 SWP_FRAMECHANGED = &H20 SWP_NOACTIVATE = &H10 SWP_NOCOPYBITS = &H100 SWP_NOMOVE = &H2 SWP_NOOWNERZORDER = &H200 SWP_NOREDRAW = &H8 SWP_NOREPOSITION = SWP_NOOWNERZORDER SWP_NOSIZE = &H1 SWP_NOZORDER = &H4 SWP_DRAWFRAME = SWP_FRAMECHANGED HWND_NOTOPMOST = -2 End Enum Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long Private Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Private Function ShowTitleBar(ByVal bState As Boolean) Dim lStyle As Long Dim tR As RECT GetWindowRect Me.hwnd, tR lStyle = GetWindowLong(Me.hwnd, GWL_STYLE) If (bState) Then Me.Caption = Me.Tag If Me.ControlBox Then lStyle = lStyle Or WS_SYSMENU End If If Me.MaxButton Then lStyle = lStyle Or WS_MAXIMIZEBOX End If If Me.MinButton Then lStyle = lStyle Or WS_MINIMIZEBOX End If If Me.Caption <> "" Then lStyle = lStyle Or WS_CAPTION End If Else Me.Tag = Me.Caption 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 End If SetWindowLong Me.hwnd, GWL_STYLE, lStyle SetWindowPos Me.hwnd, 0, tR.Left, tR.Top, tR.Right - tR.Left, tR.Bottom - tR.Top, _ SWP_NOREPOSITION Or SWP_NOZORDER Or SWP_FRAMECHANGED Me.Refresh End Function Private Sub Command1_Click() ShowTitleBar False End Sub Private Sub Command2_Click() ShowTitleBar True End Sub |
Enjoy this article?
Filed under: Forms
Leave a comment