Thread: Transparent toolbar buttons

  1. #1
    Registered User
    Join Date
    Aug 2004
    Posts
    193

    Transparent toolbar buttons

    I made custom buttons for my toolbar, but I dont know how to make the background of the buttons transparent. Like what color does the background need to be so the background is transparent?

  2. #2
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    I don't know if it would work, but you could try making the toolbar a layered window.

  3. #3
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    How do toolbars like the google toolbar make their buttons then? Like I can make the buttons a certain background color and it would work, but if I change my style from like the default XP style to another style, its not transparent anymore, but thats not the case with the google toolbar.

  4. #4
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Your using the default XP style's background color, and changing the style/theme changes it, your program needs to get the bgcolor from the system.

  5. #5
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    If I do get the background color from the system (which I'm not sure how to do, but I could google it), how would I change the background color of the bitmap to the color from the system?

    Thanks for your help so far.

  6. #6
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Hmm...

    Have you tried making the background of your custom toolbar image an RGB of 192,192,192?
    I seems to work on my win2kpro OS, no matter what the desktop style/theme is. (This is without making the window layered.)

  7. #7
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    I just tried that, but that didnt work.

  8. #8
    ... arjunajay's Avatar
    Join Date
    May 2005
    Posts
    203
    Just before you paint backgrnd, use GetSysColor( COLOR_3DFACE ); to get the color.
    likewise there many COLOR_XXXXXXXXXXX values you can substitute.
    Hope this helps.

    I think every time the visual style changes, you get a 'WM_' message. not sur which one.

  9. #9
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    What would I do with this color? Its not like I can change the background color of the bitmap to this color from within the program. I didnt think this was that complicated because almost every program has transparent toolbar buttons.

  10. #10
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    Does your toolbar have the TBSTYLE_FLAT window style bit set?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  11. #11
    Registered User Joelito's Avatar
    Join Date
    Mar 2005
    Location
    Tijuana, BC, México
    Posts
    310
    Owner draw them?
    * PC: Intel Core 2 DUO E6550 @ 2.33 GHz with 2 GB RAM: Archlinux-i686 with xfce4.
    * Laptop: Intel Core 2 DUO T6600 @ 2.20 GHz with 4 GB RAM: Archlinux-x86-64 with xfce4.

  12. #12
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    >> I just tried that, but that didnt work.

    Are you saving your custom toolbar image as a 16bit bitmap?

  13. #13
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    I have TBSTYLE_FLAT style set so that the separator line thing is visible. I'm assuming owner-drawn is within the application. Everything is owner-drawn except I use a resource file to load the .bmp file (or whatever the proper vocabulary is). I used 32-bit to save my bitmap because I thought that was the best option. The default was 24-bit, but the toolbar buttons were black squares, so I changed it to 32-bit. Trying 16-bit with RGB(192,192,192) as background had the same result as 24-bit, where all the toolbar buttons are black squares.

    Here is the code I use to create the toolbar if that helps:

    Code:
    HWND hTool = CreateWindowEx(0, TOOLBARCLASSNAME, NULL, WS_CHILD|WS_VISIBLE|WS_BORDER|TBSTYLE_FLAT, 0, 0, 0, 0, hWnd, (HMENU)ID_TOOLBAR, hInst, NULL);
    SendMessage(hTool, TB_SETBITMAPSIZE, 0, (LPARAM)MAKELONG(60,45));
    SendMessage(hTool, TB_BUTTONSTRUCTSIZE, (WPARAM)sizeof(TBBUTTON), 0);
    TBBUTTON tbb[NUM_TOOLS]; // NUM_TOOLS == 12
    TBADDBITMAP tbab;
    tbab.hInst = hInst;
    tbab.nID = ID_BITMAP;
    SendMessage(hTool, TB_ADDBITMAP, (WPARAM)10, (LPARAM)&tbab);
    ZeroMemory(&tbb, sizeof(tbb));
    for(int x=0; x<NUM_TOOLS; x++) {
    	tbb[x].fsState = TBSTATE_ENABLED;
    	tbb[x].fsStyle = TBSTYLE_BUTTON | TBSTYLE_CHECKGROUP;
    }
    tbb[0].iBitmap = 0;
    tbb[0].idCommand = ID_HOME;
    tbb[0].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Home");
    tbb[1].fsStyle = TBSTYLE_SEP | TBSTYLE_CHECKGROUP;
    tbb[2].iBitmap = 1;
    tbb[2].idCommand = ID_UPLOAD;
    tbb[2].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Upload");
    tbb[3].iBitmap = 2;
    tbb[3].idCommand = ID_BATCH;
    tbb[3].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Batch Upload");
    tbb[4].iBitmap = 3;
    tbb[4].idCommand = ID_DOWNLOAD;
    tbb[4].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Download");
    tbb[5].iBitmap = 4;
    tbb[5].idCommand = ID_MANAGE;
    tbb[5].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Manage");
    tbb[6].iBitmap = 5;
    tbb[6].idCommand = ID_REQUEST;
    tbb[6].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Request");
    tbb[7].iBitmap = 6;
    tbb[7].idCommand = ID_PM;
    tbb[7].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"PM");
    tbb[8].fsStyle = TBSTYLE_SEP | TBSTYLE_CHECKGROUP;
    tbb[9].iBitmap = 7;
    tbb[9].idCommand = ID_SETTINGS;
    tbb[9].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Settings");
    tbb[10].iBitmap = 8;
    tbb[10].idCommand = ID_HELP;
    tbb[10].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Help");
    tbb[10].fsStyle = TBSTYLE_BUTTON;
    tbb[11].iBitmap = 9;
    tbb[11].idCommand = ID_EXIT;
    tbb[11].iString = (int)SendMessage(hTool, TB_ADDSTRING, (WPARAM)0, (LPARAM)(LPSTR)"Exit");
    SendMessage(hTool, TB_ADDBUTTONS, (WPARAM)NUM_TOOLS, (LPARAM)&tbb);
    SendMessage(hTool, TB_CHECKBUTTON, (WPARAM)ID_HOME, (LPARAM)MAKELONG(true,0));

  14. #14
    Registered User Queatrix's Avatar
    Join Date
    Apr 2005
    Posts
    1,342
    Maybe you could destroy and create your whole toolbar every time a kind of wm_syscommand or somthing like that is called.

  15. #15
    Registered User
    Join Date
    Aug 2004
    Posts
    193
    I download the source to a program that uses a toolbar how I'm using a toolbar (like a tab type system). The only images I could find in the source were .ico images. I can easily make all the button images into a .ico format, but how would I put a .ico file as the image of the button?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Toolbar Buttons...What am I doing wrong?
    By dcboy in forum Windows Programming
    Replies: 0
    Last Post: 04-17-2006, 08:26 PM
  2. getting buttons onto a floating toolbar
    By eth0 in forum Windows Programming
    Replies: 0
    Last Post: 03-16-2006, 05:45 AM
  3. getting toolbar buttons onto a window
    By eth0 in forum Windows Programming
    Replies: 4
    Last Post: 02-24-2006, 12:59 PM
  4. Clipart for Toolbar Buttons?
    By Davros in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 02-24-2006, 10:23 AM
  5. Toolbar Buttons
    By G'n'R in forum Windows Programming
    Replies: 2
    Last Post: 10-02-2003, 04:35 AM