I'm trying to implement the OnPaint()
method in the subclass of the CButton
MFC class.
class CImageButton : public CButton
public:
using CButton::CButton;
protected:
afx_msg void OnPaint();
DECLARE_MESSAGE_MAP()
};
BEGIN_MESSAGE_MAP(CImageButton, CButton)
ON_WM_PAINT()
END_MESSAGE_MAP()
void CImageButton::OnPaint()
{ /* Draws an image; Doesn't call the CButton::OnPaint(). */ }
Then, I have a dialog. In the resource editor, I placed the button on its form. In the dialog declaration, I wrote
CImageButton m_btn;
and
DDX_Control(pdc, IDC_BUTTON, m_btn);
in the DoDataExchange()
. So, I think, I done all in order to my painting routine be working. But I got the strange thing: when my dialog is opening the image is painted OK (without the button's border, as I implemented in my method).
But, if I'm trying to click on it, the image disappears the button's border is drawn as well a text which I specified in the VS resource editor. I.e., it looks like the superclass'es OnPaint()
method is called by some way. I even was placing a debugging output on the entry of my method -- it is really not called. Then, if I switch the focus to some other control, my button is being redrawn with image.