Option Explicit
' Win32 APIs used to toggle border styles.
Private Declare Function GetWindowLong Lib "user32" _
Alias "GetWindowLongA" _
(ByVal hwnd As Long, _
ByVal nIndex 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 WS_CAPTION = &HC00000
'Force total pRedraw that shows new styles.
Private Const SWP_FRAMECHANGED = &H20
Private Const SWP_NOMOVE = &H2
Private Const SWP_NOZORDER = &H4
Private Const SWP_NOSIZE = &H1
'==================================================================
Private Function fStyle(mhWnd As Long, _
Optional ByVal NewBits As Long = 0) As Long
' Set new style bits.
If NewBits Then
Call SetWindowLong(mhWnd, GWL_STYLE, NewBits)
End If
' Retrieve current style bits.
fStyle = GetWindowLong(mhWnd, GWL_STYLE)
End Function
'==================================================================
Private Sub pRedraw(mhWnd As Long)
' Redraw window with new style.
Const swpFlags As Long = SWP_FRAMECHANGED Or SWP_NOMOVE Or _
SWP_NOZORDER Or SWP_NOSIZE
Call SetWindowPos(mhWnd, 0, 0, 0, 0, 0, swpFlags)
End Sub
'==================================================================
Public Sub ShowTitlebar(ByVal Value As Boolean, mhWnd As Long)
' Set WS_CAPTION On or Off as requested.
If CBool(fStyle(mhWnd) And WS_CAPTION) And Value = False Then
'Hide the titkebar
Call fFlipBit(WS_CAPTION, Value, mhWnd)
ElseIf Not CBool(fStyle(mhWnd) And WS_CAPTION) And Value = True Then
'Show the titkebar
Call fFlipBit(WS_CAPTION, Value, mhWnd)
End If
End Sub
'==================================================================
Private Function fFlipBit(ByVal Bit As Long, _
ByVal Value As Boolean, _
mhWnd As Long) As Boolean
Dim lStyle As Long
' Retrieve current style bits.
lStyle = GetWindowLong(mhWnd, GWL_STYLE)
' Set requested bit On or Off and Redraw.
If Value Then
lStyle = lStyle Or Bit
Else
lStyle = lStyle And Not Bit
End If
Call SetWindowLong(mhWnd, GWL_STYLE, lStyle)
Call pRedraw(mhWnd)
' Return success code.
fFlipBit = (lStyle = GetWindowLong(mhWnd, GWL_STYLE))
End Function