Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleChange a window's style (border, title bar, control box, etc.) at run time
Keywordswindow style, border, title bar, control box
Categories
 
Use GetWindowLong to get the window's style or extended style. Use and SetWindowLong to set or clear the desired value. Finish by using SetWindowPos to redraw the window.

The SetWindowStyle subroutine makes a lot of this easy.

The code was modified by Peter Chamberlin UK to allow the ShowInTaskbar property to be altered as well (requires window hide/show).

 
' Set or clear a style or extended style value.
Private Sub SetWindowStyle(ByVal hwnd As Long, ByVal _
    extended_style As Boolean, ByVal style_value As Long, _
    ByVal new_value As Boolean, ByVal brefresh As Boolean)
Dim style_type As Long
Dim style As Long
   
    If extended_style Then
        style_type = GWL_EXSTYLE
    Else
        style_type = GWL_STYLE
    End If

    ' Get the current style.
    style = GetWindowLong(hwnd, style_type)

    ' Add or remove the indicated value.
    If new_value Then
        style = style Or style_value
    Else
        style = style And Not style_value
    End If

    ' Hide Window if Changing ShowInTaskBar
    If brefresh Then
        ShowWindow hwnd, SW_HIDE
    End If

    ' Set the style.
    SetWindowLong hwnd, style_type, style

    ' Show Window if Changing ShowInTaskBar
    If brefresh Then
        ShowWindow hwnd, SW_SHOW
    End If

    ' Make the window redraw.
    SetWindowPos hwnd, 0, 0, 0, 0, 0, _
        SWP_FRAMECHANGED Or _
        SWP_NOMOVE Or _
        SWP_NOSIZE Or _
        SWP_NOZORDER
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated