Welcome to Dream.In.Code
Become a C++ Expert!

Join 149,946 C++ Programmers for FREE! Get instant access to thousands of C++ experts, tutorials, code snippets, and more! There are 1,404 people online right now. Registration is fast and FREE... Join Now!




[C++] Transparent toolbar bitmap.

 
Reply to this topicStart new topic

[C++] Transparent toolbar bitmap.

Syndication
6 Jan, 2008 - 12:27 PM
Post #1

New D.I.C Head
*

Joined: 6 Jan, 2008
Posts: 2

Hello,

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:

CODE
// 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:

CODE
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.
User is offlineProfile CardPM
+Quote Post

Reply to this topicStart new topic
Time is now: 1/8/09 05:03PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live C++ Help!

C++ Tutorials

Reference Sheets

C++ Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month