Icon or bitmap (HBITMAP)? I have a button subclassed from CXTButton that loads an HBITMAP from a resource file. f you have an HBITMAP, you can do the following:
BITMAP bm = {0};
::GetObject( m_hbmImage, sizeof(bm), &bm );
CBitmap bmpIcon;
bmpIcon.Attach(m_hbmImage);
CSize iconSize(bm.bmWidth, bm.bmHeight);
// convert the bitmap to a transparent icon.
HICON hIcon = CXTPTransparentBitmap(bmpIcon).ConvertToIcon();
CXTPImageManagerIconHandle hIconHandle; // do not set equal to hIcon here or it will NOT destrory the icon
hIconHandle = hIcon; // Will call DestoyIcon;
SetIcon(iconSize, hIconHandle, CXTPImageManagerIconHandle(), FALSE);
m_hbmImage = NULL; // consumed and then deleted by bmpIcon in the CBitmap dtor that runs when this block of code goes out of scope.
By default, pixel(0,0) is considered the background color that drives transparency. I once posted a question as to whether there was a way to specifically set the background color so the first pixel is not used and Oleg said there was. Unfortunately I don't recall what the member or method is but you can probably search the forum to find his answer (probably just find all my posts and his replies).
If you actually have an icon, you should be able to use one of the SetIcon overloads (perhaps the one that takes in a CXTPImageManagerIcon, which has various member methods for loading your image). For instance I have some code that loads a bitmap from a file on disk and I do this:
BOOL bAlphaBitmap = FALSE;
HBITMAP hbmMenuItem = CXTPImageManagerIcon::LoadBitmapFromFile( lpszImageFileName, &bAlphaBitmap );
|