' 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 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 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 mhWnd As Long
Public Property Let Titlebar(ByVal Value As Boolean)
' Set WS_CAPTION On or Off as requested.
Call fFlipBit(WS_CAPTION, Value)
End Property
Public Property Get Titlebar() As Boolean
' Return value of WS_CAPTION bit.
Titlebar = CBool(fStyle And WS_CAPTION)
End Property
Public Property Set Client(ByVal obj As Form)
' Store reference to client form.
Set mClient = obj
' Cache hWnd as it'll be accessed frequently.
If mClient Is Nothing Then
mhWnd = 0
Else
mhWnd = mClient.hWnd
End If
End Property
Public Sub pRedraw()
' 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
Private Function fStyle(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 Function fFlipBit(ByVal Bit As Long, ByVal Value As Boolean) 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
' Return success code.
fFlipBit = (lStyle = GetWindowLong(mhWnd, GWL_STYLE))
End Function