开发者

MFC button with Bitmap and text

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 t开发者_如何学Co 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.


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 );
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜