I have a Custom CButton which loads a bitmap, using CButton::SetBitmap(bitmap);
Meanwhile, I want to display a text above the bitmap, on the same button.
I tried implementing OnPaint(), but it does not display the text, just the bitmap
void CBitmapToggleButton::OnPaint()
{
CButton::OnPaint();
CPaintDC dc(this); // device context for painting
CString caption(_T("test message"));
GetWindowText(caption);
CRect rect;
GetWindowRect(&rect);
dc.DrawText(caption, &rect, DT_CENTER);
}
What can I do to display the text too?
Use GetClientRect(). The argument passed to DrawText() needs to be in client coordinates.
That said, forget about this and use CMFCButton. It's way better than anything you can write yourself in a reasonable amount of time.