Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Toolbar

Posted on 1999-06-30
3
Medium Priority
?
195 Views
Last Modified: 2008-02-20
Woh to make the backstyle transparent?
0
Comment
Question by:ArievS
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 13

Accepted Solution

by:
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

'Functions:
'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

'Constants:
'ImageList constants
Private Const CLR_NONE = &HFFFFFFFF

'Styles:
'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.

'Messages:
'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
   tbStyle = tbStyle Or CCS_NORESIZE Or CCS_NODIVIDER Or TBSTYLE_FLAT 'Or TBSTYLE_TRANSPARENT
   If (fAsList) Then
      tbStyle = tbStyle Or TBSTYLE_LIST
   End If
   
   SendMessage hwndDll, TB_SETSTYLE, 0, ByVal tbStyle
   
   
   tbar.Refresh
   '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




0
 

Author Comment

by:ArievS
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!


0
 

Author Comment

by:ArievS
ID: 1520952
Oh I forgot to tell that:

 - My Toolbar is positioned inside a coolbar.

 - The coolbar has a tiled background picture.

Arie

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

721 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