[C++] Transparent toolbar bitmap.

Discussion in 'C++' started by Syndication, Jan 6, 2008.

  1. Syndication

    Syndication New Member

    Jan 6, 2008
    Likes Received:
    Trophy Points:

    I'm using VS [C++] 2008 Express (no MFC). I've been trying all day to get a toolbar onto my app that uses a .bmp file for the icons. The code I've used to do this is:

    // Load toolbar bitmap. (48 pixel wide, 16 high)
    HBITMAP hbmTool = (HBITMAP)LoadImage(g_mainhInstance, "tool.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS);
    // blah blah, setup buttons..
    HWND hWnd = CreateToolbarEx(g_mainWinHandle, WS_CHILD | WS_VISIBLE, IDTB_MAIN,  3, NULL, (UINT)hbmTool, tbButtons,              
    3, 16, 16, 16, 16, sizeof(TBBUTTON)); 
    This works OK, but for the fact that the background part of the tool.bmp that is supposed to be transparent is showing as white.

    I've literally been googling this problem all day trying to find out how I resolve this to the point I now have a headache. X( I realise I need to be using TransparentBlt and/or BitBlt. I had no luck with TransparentBlt, but this is as far as I've got using BitBlt:

     HBITMAP hbmTool = (HBITMAP)LoadImage(g_mainhInstance, "tool2.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_LOADMAP3DCOLORS);
    HDC hdcTool, hdcNew;
    hdcTool = CreateCompatibleDC(0);
    SelectBitmap(hdcTool, hbmTool);
    HBITMAP hbmNew = CreateBitmap(48, 16, 1, 1, NULL);
    hdcNew = CreateCompatibleDC(0);
    SelectBitmap(hdcNew, hbmNew);
    SetBkColor(hdcTool, (COLORREF)RGB(130, 255, 255)); // This is the background color of the tool.bmp
    BitBlt(hdcNew, 0, 0, 48, 16, hdcTool, 0, 0, SRCCOPY);
    // .. tidy up etc
    So I have a HDC/HBITMAT to a 1 bit bitmap that is a black mask of the actual 'icons' in tool2.bmp, and the background of it is now transparent, but I can't find or understand the process of printing the color of the 'icons' in the tool.bmp to a final HBITMAP using this mask.

    I've read every resource I can find on the net but I can't make sense of this final stage. This has become a brickwall in my learning project, I'd HUGELY appreciate any one who can take a moment out and reveal (and briefly explain if possible) this last step to me.

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice