Visual Basic Common Control API Routines
FindWindowEx: Change a VB Toolbar to a Rebar-Style Toolbar
     
Posted:   Sunday January 25, 1998
Updated:   Monday December 26, 2011
     
Applies to:   VB4-32, VB5, VB6
Developed with:   VB5, Windows 95
OS restrictions:   None
Author:   VBnet - Randy Birch
     

Related:  

FindWindowEx: Fix the IE5/MsComCtrl 5 Toolbar Problem
     
 Prerequisites
This method is intended for Visual Basic 5 or Visual Basic 6 where the Common Control library used is the MSComCtl 5 version (comctl32.ocx). Because the VB6-specific mscomctl.ocx (Common Controls 6) is a complete implementation of comctl32.dll and not reliant on the version of comctl32.dll installed, this routine may not work when applied to a listview created from the VB6-specific mscomctl.ocx.

Enhanced Comctl32 functionality is only available to users with comctl32.dll version 4.70 or greater installed. This dll is typically installed with IE3.x or greater.


vbnsflattb.gif (6109 bytes)Here's a quick routine to set a standard VB toolbar to a IE-style Rebar style control (aka 'coolbar') for IE4 Active Desktop users. The illustration shows the original and flattened style for the same toolbar.

Place a toolbar with images (and optionally text), and add a placeholder.  Set the placeholder width to 1500, and set the placeholder key to "Combo1".  Onto the toolbar, draw a combo box (Combo1).  Note the toolbar is a container control, so the ComboBox must be drawn onto or pasted into the toolbar itself for it to function properly (not just placed onto the form).

 BAS Module Code
Place the following code into the general declarations area of a bas module:

Option Explicit
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Copyright ©1996-2011 VBnet/Randy Birch, All Rights Reserved.
' Some pages may also contain other copyrights by the author.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
' Distribution: You can freely use this code in your own
'               applications, but you may not reproduce 
'               or publish this code on any web site,
'               online service, or distribute as source 
'               on any media without express permission.
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Public Const WM_USER = &H400
Public Const TB_SETSTYLE = WM_USER + 56
Public Const TB_GETSTYLE = WM_USER + 57
Public Const TBSTYLE_FLAT = &H800

Public Declare Function SendMessage Lib "user32" _
   Alias "SendMessageA" _
  (ByVal hwnd As Long, _
   ByVal wMsg As Long, _
   ByVal wParam As Long, _
   lParam As Any) As Long

Public 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
 Form Code
To the form, add the following code:

Option Explicit
Private Sub Form_Load()

    With Combo1
        .Width = Toolbar1.Buttons("combo1").Width
        .Top = (Toolbar1.Height - Combo1.Height) \ 2
        .Left = Toolbar1.Buttons("combo1").Left
        .AddItem "Black" ' Add colours for text.
        .AddItem "Blue"
        .AddItem "Red"
        .ListIndex = 0
    End With

End Sub

Private Sub Command1_Click()

   Dim style As Long
   Dim hToolbar As Long
   
  'get the handle of the toolbar
   hToolbar = FindWindowEx(Toolbar1.hwnd, 0&, "ToolbarWindow32", vbNullString)
   
  'retrieve the toolbar styles
   style = SendMessage(hToolbar, TB_GETSTYLE, 0&, ByVal 0&)
   
  'Set the new style flag
   If style And TBSTYLE_FLAT Then
      style = style Xor TBSTYLE_FLAT
   Else
      style = style Or TBSTYLE_FLAT
   End If
   
  'apply the new style to the toolbar
   Call SendMessage(hToolbar, TB_SETSTYLE, 0, ByVal style)
   Toolbar1.Refresh
   
End Sub
 Comments
Run your project and press the button.  The toolbar will take on the IE-style, and passing the mouse over the buttons causes the same behaviour as an IE toolbar exhibits. This code should ultimately be placed into the form load sub.

Note as well that the toolbar editing features still operate, and that new separators added appear as the IE style vertical bars.


 
 

PayPal Link
Make payments with PayPal - it's fast, free and secure!

 
 
 
 

Copyright ©1996-2011 VBnet and Randy Birch. All Rights Reserved.
Terms of Use  |  Your Privacy

 

Hit Counter