this is my first question on stackoverflow and i hope i do everything right:S
As described in my titel i am working on a visual studio(2012) project with mfc. I try to add a bitmap to my cbutton, which was inserted in the design view to my dialog.
All post i've read about this, describe to use setBitmap or sendMessage to do so. I always try to do this in the onInit()-function of my dialog. When i (try to) use setBitmap() like this:
m_backButton.Attach (LoadBitmap (AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BACK_BUTTON))); //m_backButton is a private CBitmap member of my dialog
CButton* pButton = (CButton* )GetDlgItem(IDC_BUTTON1);
pButton->SetBitmap(m_backButton);
It results in an IntelliSense-Error:
IntelliSense: class "CButton" has no member "setBitmap"
Another try was to use sendMessage:
m_backButton.Attach (LoadBitmap (AfxGetInstanceHandle(), MAKEINTRESOURCE(IDB_BACK_BUTTON)));
CButton* pButton = (CButton* )GetDlgItem(IDC_BUTTON1);
HBITMAP hBitmap = (HBITMAP)m_backButton;
pButton->SendMessage(BM_SETIMAGE,(WPARAM)IMAGE_BITMAP,(LPARAM)hBitmap);
First i got another IntelliSense-Error:
IntelliSense: identifier "BM_SETIMAGE" is undefined
Like i've read in another post, i defined "BM_SETIMAGE" by my own:
#define BM_SETIMAGE 0x00F7
Now the code is able to compile, but the button still shows no bitmap... Since every post in the internet uses one of this two solutions i'm helpless. Anybody an idea whats wrong? And if not, also thank you for reading:)
So i think i found a solution:) I thought i post it here, that other may have use of it too. Also i cannot let this question be unansweared:S
My solution is from http://www.flounder.com/bitmapbutton.htm and adapted to fit my needs. It now can be used with Microsoft Embedded Compact 2013. Thx to the autor!
My short version looks like this:
ImageButton.h
ImageButton.cpp
Than you can add a normal CButton with ressource editor or dynamically(i think, not tested), cast it to ImageButton and load the bitmap with loadBitmapForButton. The property owner-draw of the CButton must be set to true. Thats all:)
PS, i did not checked the code for correct memory deallocation until now...I will do so soon, if i found sth missing i will add this in my post. If someone else can help in this point, feel free to teach me;)