Posted on 1999-06-30
Medium Priority
Last Modified: 2008-02-20
Woh to make the backstyle transparent?
Question by:ArievS
  • 2
LVL 13

Accepted Solution

Mirkwood earned 200 total points
ID: 1520950
Put the code below in a module and call
private sub form_load
   MakeCoolbar toolbar1
end sub

private sub form_size
 resizeCoolbar toolbar1
end sub

Option Explicit

'API declarations

'Windows functions
Private Declare Function UpdateWindow Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) 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
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 SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function GetDC Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function ReleaseDC Lib "user32" (ByVal hwnd As Long, ByVal hDC As Long) As Long
'ImageList functions
Private Declare Function ImageList_SetBkColor Lib "ComCtl32" (ByVal himl As Long, ByVal clrBk As Long) As Long

'ImageList constants

'CommonControl styles
Private Const CCS_NORESIZE = &H4            'Prevents a toolbar from trying to resize to fill the top edge of the parent's client area.
Private Const CCS_NODIVIDER = &H40          'Prevents a toolbar from drawing a divider line on the top edge.
'Toolbar styles
Private Const TBSTYLE_LIST = &H1000         'Puts captions beside buttons instead of below.
Private Const TBSTYLE_FLAT = &H800          'Makes toolbar buttons transparent and flat.
Private Const TBSTYLE_TRANSPARENT = &H8000  'Makes a toolbar transparent, but not the buttons.
'Note: Under IE3, TBSTYLE_FLAT by itself makes a toolbar fully flat and transparent. Under IE4, TBSTYLE_FLAT and TBSTYLE_TRANSPARENT are both required.

'Window messages
Private Const WM_PAINT = &HF
Private Const WM_USER = &H400&
'Toolbar messages
Private Const TB_GETSTYLE = (WM_USER + 57)
Private Const TB_SETSTYLE = (WM_USER + 56)

Public Sub ResizeCoolbar(ByVal tbar As ToolBar)
    Dim hwndOCX As Long
    Dim hwndDll As Long
     On Error Resume Next
    'Cache the window handles
    hwndOCX = tbar.hwnd
    hwndDll = FindWindowEx(hwndOCX, 0, "ToolbarWindow32", vbNullString)
    Call MoveWindow(hwndDll, tbar.left / Screen.TwipsPerPixelX, tbar.top / Screen.TwipsPerPixelY, tbar.width / Screen.TwipsPerPixelX - 8, tbar.height / Screen.TwipsPerPixelY, True)
    Call UpdateWindow(hwndDll)
End Sub

Public Sub MakeCoolbar(ByVal tbar As ToolBar, Optional fAsList As Boolean)
   Dim hwndOCX As Long
   Dim hwndDll As Long
   Dim tbStyle As Long
   Dim hDC As Long
    'Cache the window handles and style bits
    hwndOCX = tbar.hwnd
    hwndDll = FindWindowEx(hwndOCX, 0, "ToolbarWindow32", vbNullString)
    tbStyle = SendMessage(hwndDll, TB_GETSTYLE, 0, ByVal 0)

    'The following code allows you to create a transparent toolbar with working
    '   tooltips in Form_Load. Without this code, the regular toolbar must be
    '   shown and refreshed before it is made transparent in order for the
    '   tooltips to show up.
    hDC = GetDC(hwndOCX)
    SendMessage hwndOCX, WM_PAINT, hDC, ByVal 0
    ReleaseDC hwndOCX, hDC

    'Make the images transparent
    MakeImagesTransparent tbar
   'Removed transparent to prevent black toolbars
   If (fAsList) Then
      tbStyle = tbStyle Or TBSTYLE_LIST
   End If
   SendMessage hwndDll, TB_SETSTYLE, 0, ByVal tbStyle
   'Refresh the toolbar
   RefreshToolbar tbar
 End Sub

Private Sub MakeImagesTransparent(ByVal tbar As ToolBar)
    Dim oImageList As ComctlLib.ImageList

    'Get the relevant ImageList, if any
    Set oImageList = tbar.ImageList
    If oImageList Is Nothing Then Exit Sub

    'Set the ImageList's backcolor to transparent
    ImageList_SetBkColor oImageList.hImageList, CLR_NONE
End Sub

Private Sub RefreshToolbar(ByVal tbar As ToolBar)
    If tbar.Buttons.count = 0 Then Exit Sub
    With tbar.Buttons(1)
        .Image = .Image
    End With
End Sub


Author Comment

ID: 1520951
I want to thank Mirkwood for his answer but his code doesn't work in vb6! The Problem : My toolbars don't seem to be transparant, whatever I try to do.

I didn't test it in vb5 because I erased it from my harddisk!

Thanx Arie!


Author Comment

ID: 1520952
Oh I forgot to tell that:

 - My Toolbar is positioned inside a coolbar.

 - The coolbar has a tiled background picture.



Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question