Toolbar_ToggleFlat


Description:
Simple function that changes the styles for a toolbar to modify the TBSTYLE_FLAT style, allowing VB to easily use the flat toolbars that have become so popular.
 
Code:
Option Explicit

Private Const WM_USER = &H400
Private Const TB_SETSTYLE = WM_USER + 56
Private Const TB_GETSTYLE = WM_USER + 57
Private Const TBSTYLE_FLAT = &H800

Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" ( _
   ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam _
   As Any) As Long
   
Private Declare Function FindWindowEx Lib "user32" Alias _
   "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal _
   lpsz1 As String, ByVal lpsz2 As String) As Long

Public Sub Toolbar_ToggleFlat(tlb As Toolbar)
   
    Dim nStyle As Long
    Dim hWndToolbar As Long
    
    hWndToolbar = FindWindowEx(tlb.hWnd, 0&, "ToolbarWindow32", vbNullString)
    
    nStyle = SendMessage(hWndToolbar, TB_GETSTYLE, 0&, ByVal 0&)
    
    nStyle = nStyle Xor TBSTYLE_FLAT
    
    SendMessage hWndToolbar, TB_SETSTYLE, 0, ByVal nStyle
    
    tlb.Refresh

End Sub
 
Sample Usage:
 
    Toolbar_ToggleFlat Me.Toolbar1