Flat and List Toolbar Styles


Author: Chris Eastwood

Flat and List Toolbar Styles


One of the most asked questions when VB5 was released was 'How do I get those great flat style toolbars with VB5?'. VB didn't give you any way of creating them until Microsoft made some changes to Internet Explorer which updated the Common Controls DLL.

In the VBCodeLibrary project on the CodeGuru site, I gave the ToolBar the flat-look with some very simple code. In this example, I'll also be changing the styles of the buttons to allow text and Icons on the same level.

The standard method for changing a toolbar to Flat Style is :



   Dim lStyle as Long
   Dim lTBHwnd  as Long
   
   lTBHwnd = FindWindowEx(Toolbar1.hwnd, 0&, "ToolbarWindow32", vbNullString)
   
   lStyle = SendMessageLong(lTBHwnd, TB_GETSTYLE, 0&, 0&)
   
   If lStyle And TBSTYLE_FLAT then
'
' Ignore it - or remove it with
'
' lStyle = lStyle XOr TBSTYLE_FLAT
'
   else
     lStyle = lStyle Or TBSTYLE_FLAT
   End If
   
   SendMessageLong lTBHwnd, TB_SETSTYLE, 0, lStyle
   Toolbar1.Refresh

If you want to change the buttons to a List Style (i.e. Icon and Text on the same line), you need to change another style bit on the Toolbar :


'
' Check if it already has a List Style
'
    If lStyle And TBSTYLE_LIST then
    '
    ' Ignore it - or remove it with
    '
    ' lStyle = lStyle XOr TBSTYLE_LIST
    '
    else
        lStyle = lStyle Or TBSTYLE_LIST
    End If
'
' set the new Style for the Toolbar
'
    SendMessageLong lTBHwnd, TB_SETSTYLE, 0, lStyle


The overall effect should look like this :


Flat and List Styles


Using a combination of the methods above, you can get great looking applications without the need for an expensive third party ocx.


Download Sample

Posted On: 21-Feb-1999

Add Comment



Goto HomePage
© 1998 CodeGuru 
Contact : vb@codeguru.com