I'm trying to load bitmaps for my buttons with the function SetImage
from the CMFCButton
. I don't get any error or something, just a plain button. I'm doing the same thing with icons
and it works, but I need it to load bitmap
too. I need to LoadImage
from a path and not from the resources.
Here's my code :
iconResource = path + m_type + _T("U") + extension; //i.e : C:\test\earthU.bmp
HANDLE hIcon = ::LoadImage(nullptr, iconResource, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
//same thing for Hot and Disable bitmap
and the call for the SetImage
function :
SetImage((HBITMAP)hIcon, 0, (HBITMAP)hIconHot, 0 , (HBITMAP)hIconDis);
Use LR_CREATEDIBSECTION|LR_LOADFROMFILE
flag when loading bitmap files for CMFCButton
::LoadImage(nullptr, bitmapfile, IMAGE_BITMAP, 0, 0, LR_CREATEDIBSECTION|LR_LOADFROMFILE);
Partial explanation:
MFC source code for CMFCButton
("afxbutton.cpp"
) shows it adds LR_CREATEDIBSECTION
for LoadImage
. This is not documented and it is not clear why it needs that. It seems LR_CREATEDIBSECTION
is required when source bitmap is not 32-bit.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With