Click to See Complete Forum and Search --> : ::ExtractIconEx()


dscott
June 16th, 1999, 07:50 PM
Hi,

Currently I am extracting an icon from an excutable and adding that icon to a toolbar button within my application. The following code shows how I accomplish this:

void CZManagerApp::LoadUserDefinedToolBarIcons()
{
CZString strTool;
HICON hIconSmall;
ICONINFO IconInfo;
TBBUTTON tbButton;


m_uStartID = m_uCommandID;

strTool = "some executable file.exe";

::ExtractIconEx((LPCTSTR)strTool, 0, NULL, &hIconSmall, 1);

::GetIconInfo(hIconSmall, &IconInfo);

// Where m_TBControl is of type "CToolBarCtrl"
tbButton.iBitmap = m_TbControl.AddBitmap(1, CBitmap::FromHandle(IconInfo.hbmColor));

tbButton.idCommand = m_uCommandID;
tbButton.fsState = TBSTATE_ENABLED;
tbButton.fsStyle = TBSTYLE_BUTTON;
tbButton.dwData = 0;
tbButton.iString = 0;

m_TbControl.AddButtons(1, &tbb);

DestroyIcon(hIconSmall);

m_uCommandID++;
}

This works great except for when the icon is transparent in areas then I get the transparent areas showing up as black. Does anyone know what I'm missing?

Dan

Robert Bielik
June 22nd, 1999, 02:47 AM
The ICONINFO structure contains two bitmaps. One is the hbmColor, and the other is the hbmMask. What you'd need to do is to create a CBitmap that uses the hbmMask to map your desired background color. One way of doing this would be to create a DC via GetDC(NULL), selecting a compatible bitmap into it, fill the bitmap with your toolbar background color, then ::DrawIcon(... hIconSmall ..) into it. That way, you let DrawIcon do the masking and stuff for you. Then you add that bitmap to your toolbar control in the same manner as you do now.

Regards,
/Robert