tags:

views:

336

answers:

2

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?

A: 

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.

Roel
A: 

Try this

CButton* pBtn= (CButton*)GetDlgItem(ID_WIZBACK);

pBtn->ModifyStyle( 0, BS_ICON );

HICON hIcn= (HICON)LoadImage( AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDI_ICON3), IMAGE_ICON, 0,0, // use actual size LR_DEFAULTCOLOR );

pBtn->SetIcon( hIcn );
kiddo