Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Borderstyle..
#5
Using the code Minatours posted I managed to change the code to allow changing between Borderstyle 1-5 without problems.

Put this code into any module:
Code:
Option Explicit
Private Const GWL_STYLE As Long = (-16&)
Private Const GWL_EXSTYLE As Long = (-20&)
Private Const WS_THICKFRAME As Long = &H40000
Private Const WS_MINIMIZEBOX As Long = &H20000
Private Const WS_MAXIMIZEBOX As Long = &H10000

Private Const WS_EX_TOOLWINDOW As Long = &H80&

Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd&, ByVal nIndex&) As Long
Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd&, ByVal nIndex&, ByVal dwNewLong&) As Long
    

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

Private Const SWP_DRAWFRAME = SWP_FRAMECHANGED
Private Const SWP_NOREPOSITION = SWP_NOOWNERZORDER

' SetWindowPos() hwndInsertAfter values
Private Const HWND_TOP = 0
Private Const HWND_BOTTOM = 1
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Declare Function SetWindowPos Lib "user32" (ByVal hWnd&, ByVal hWndInsertAfter&, ByVal x&, ByVal y&, ByVal cx&, ByVal cy&, ByVal wFlags&) As Long


Public Sub ChangeBorderStyle(TheForm As Form, Style As Byte)
Dim bToggleStyle As Boolean, bToggleExStyle As Boolean, cStyle As Byte
    
    'This makes sure the selected style is within acceptable range
    If Style > 5 Or Style < 0 Then Style = TheForm.BorderStyle
    
    cStyle = TheForm.BorderStyle
    TheForm.BorderStyle = Style
    
    'Checks the current BorderStyle and changes the variables to comply with selected style
    If Style = 0 Then
        'Don't know yet >_>...
    ElseIf Style = 1 Then
        If cStyle = 2 Then
            bToggleStyle = True
        ElseIf cStyle = 3 Then
            bToggleStyle = False
        ElseIf cStyle = 4 Then
            bToggleExStyle = True
        ElseIf cStyle = 5 Then
            bToggleStyle = True
            bToggleExStyle = True
        End If
    ElseIf Style = 2 Then
        If cStyle = 1 Then
            bToggleStyle = True
            bToggleExStyle = False
        ElseIf cStyle = 3 Then
            bToggleStyle = True
        ElseIf cStyle = 4 Then
            bToggleStyle = True
            bToggleExStyle = True
        ElseIf cStyle = 5 Then
            bToggleStyle = False
            bToggleExStyle = True
        End If
    ElseIf Style = 3 Then
        If cStyle = 1 Then
            bToggleStyle = False
        ElseIf cStyle = 2 Then
            bToggleStyle = True
        ElseIf cStyle = 4 Then
            bToggleExStyle = True
        ElseIf cStyle = 5 Then
            bToggleStyle = True
            bToggleExStyle = True
        End If
    ElseIf Style = 4 Then
        If cStyle = 1 Then
            bToggleExStyle = True
        ElseIf cStyle = 2 Then
            bToggleStyle = True
            bToggleExStyle = True
        ElseIf cStyle = 3 Then
            bToggleExStyle = True
        ElseIf cStyle = 5 Then
            bToggleStyle = True
            bToggleExStyle = False
        End If
    Else
        If cStyle = 1 Then
            bToggleStyle = True
            bToggleExStyle = True
        ElseIf cStyle = 2 Then
            bToggleExStyle = True
        ElseIf cStyle = 3 Then
            bToggleStyle = True
            bToggleExStyle = True
        ElseIf cStyle = 4 Then
            bToggleStyle = True
            bToggleExStyle = False
        End If
    End If
    
    If bToggleStyle Then 'Toggles between Fixed and Sizeable
        Call SetWindowLong(TheForm.hWnd, GWL_STYLE, GetWindowLong(TheForm.hWnd, GWL_STYLE) Xor (WS_THICKFRAME Or WS_MINIMIZEBOX Or WS_MAXIMIZEBOX))
    End If
    
    If bToggleExStyle Then 'Toggles between ToolWindow and Regular Window
        Call SetWindowLong(TheForm.hWnd, GWL_EXSTYLE, GetWindowLong(TheForm.hWnd, GWL_EXSTYLE) Xor WS_EX_TOOLWINDOW)
    End If

    Call SetWindowPos(TheForm.hWnd, 0&, 0&, 0&, 0&, 0&, SWP_NOMOVE Or SWP_NOSIZE Or SWP_NOZORDER Or SWP_FRAMECHANGED)
End Sub

Example of using this code:
Code:
ChangeBorderStyle frmChangeBorderStyle, 1
frmChangeBorderStyle is the form that I'm changing the Border Style.
1 is the style number.

Probably not the best way or code, but it works Smile
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)