VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Toggle a Form's Caption Bar at Runtime

by Stephen Kent (10 Submissions)
Category: Windows API Call/Explanation
Compatability: Visual Basic 3.0
Difficulty: Beginner
Date Added: Wed 3rd February 2021
Rating: (2 Votes)

This code allows a user to Toggle the caption bar (toolbox and all) on a form at runtime. Normally you cannot visually change some of the form's settings at runtime this solves one of those instances.
Code can be fairly easily changed so as to accept a parameter for if you want the caption or not. This is just a simple example.

Assumes
This simply changes the window style of the form and then does a couple of extremely quick re-sizes so that the caption area is forced to redraw. This will only work as is if the code is placed in the form you want to affect. Sub must be called for changes to take effect.
API Declarations
Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Private Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) 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 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 Const GWL_STYLE = (-16)
Private Const SWP_NOMOVE = &H2
Private Const WS_CAPTION = &HC00000
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Rate Toggle a Form's Caption Bar at Runtime

Private Sub ToggleFormCaption()
  Dim rcWindow As RECT
  Dim lRet As Long
  lRet = GetWindowRect(Me.hwnd, rcWindow)
  lRet = SetWindowLong(Me.hwnd, GWL_STYLE, GetWindowLong(Me.hwnd, GWL_STYLE) Xor WS_CAPTION)
  lRet = SetWindowPos(Me.hwnd, 0, 0, 0, rcWindow.Right - rcWindow.Left + 1, rcWindow.Bottom - rcWindow.Top, SWP_NOMOVE)
  lRet = SetWindowPos(Me.hwnd, 0, 0, 0, rcWindow.Right - rcWindow.Left, rcWindow.Bottom - rcWindow.Top, SWP_NOMOVE)
End Sub

Download this snippet    Add to My Saved Code

Toggle a Form's Caption Bar at Runtime Comments

No comments have been posted about Toggle a Form's Caption Bar at Runtime. Why not be the first to post a comment about Toggle a Form's Caption Bar at Runtime.

Post your comment

Subject:
Message:
0/1000 characters