Hi,
I tried to implement the default MFC-Icon in an Menu. Got it, but unfortunatly, the background of the icon is NOT transparent. why not and how can I set it to transparent?
my source code:
CMenu* mmenu = GetMenu();
HICON hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
mmenu->SetMenuItemBitmaps(ID_TEST, MF_BYCOMMAND, ConvertIconToBitmap(hIcon), NULL);
the converting function:
CBitmap* CTestDlg::ConvertIconToBitmap(HICON hIcon)
{
CDC dc;
CBitmap bmp;
CClientDC ClientDC(this);
dc.CreateCompatibleDC(&ClientDC);
bmp.CreateCompatibleBitmap(&ClientDC, 16, 16);
CBitmap* pOldBmp = (CBitmap*)dc.SelectObject(&bmp);
::DrawIconEx(dc.GetSafeHdc(), 0, 0, hIcon, 16, 16, 0, (HBRUSH)RGB(255, 255, 255), DI_NORMAL);
dc.SelectObject(pOldBmp);
dc.DeleteDC();
HBITMAP hBitmap = (HBITMAP)::CopyImage((HANDLE)((HBITMAP)bmp), IMAGE_BITMAP, 0, 0, LR_DEFAULTSIZE);
return CBitmap::FromHandle(hBitmap);
}
I tried to change the HBRUSH within the DrawIconEx, but the background changes only to black when RGB is (0,0,0). All other combinations paint the background white :(