【问题标题】:MFC button with Bitmap and text带位图和文本的 MFC 按钮
【发布时间】:2010-02-19 08:14:37
【问题描述】:

我有一个自定义 CButton 加载位图,使用 CButton::SetBitmap(bitmap);

同时,我想在位图上方的同一个按钮上显示一个文本。

我尝试实现 OnPaint(),但它不显示文本,只显示位图

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

我还能做些什么来显示文本?

【问题讨论】:

    标签: mfc cbutton


    【解决方案1】:

    使用 GetClientRect()。传递给 DrawText() 的参数需要在客户端坐标中。

    也就是说,忘记这一点并使用 CMFCButton。它比您在合理的时间内自己编写的任何东西都要好。

    【讨论】:

      【解决方案2】:

      试试这个

      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, // 使用实际大小 LR_DEFAULTCOLOR );

      pBtn->SetIcon( hIcn );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2016-09-03
        • 1970-01-01
        • 1970-01-01
        • 2021-12-18
        • 2012-09-03
        • 2011-10-11
        • 2013-07-10
        • 2014-05-22
        相关资源
        最近更新 更多