有什么好办法,我不想用自绘,因为绘不出Button的外观,或者说很麻烦,我只想改变字体颜色而已。我试了用反射也不行,不知道我用对了没有,请哪位给点代码,谢谢!

解决方案 »

  1.   

    virtual COLORREF SetTextColor(
       COLORREF crColor 
    );抄自MSDN的一部分代码:HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
       // Call the base class implementation first! Otherwise, it may
       // undo what we're trying to accomplish here.
       HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);   // Are we painting the IDC_MYSTATIC control? We can use
       // CWnd::GetDlgCtrlID() to perform the most efficient test.
       if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
       {
          // Set the text color to red
          pDC->SetTextColor(RGB(255, 0, 0));      // Set the background mode for text to transparent 
          // so background will show thru.
          pDC->SetBkMode(TRANSPARENT);      // Return handle to our CBrush object
          hbr = m_brush;
       }   return hbr;
    }
      

  2.   

    mscf(sophist),请问你试过吗?我用这个方法怎么不行,button不向父窗口发送
    WM_CTLCOLOR消息吧。这个方法对于static,group box有效!
      

  3.   

    你可以在create按钮之后,settextcolor( hdc, rgb )
      

  4.   

    http://www.pcvc.net/category/content.asp?sendid=28
      

  5.   

    在.h文件
    private: 
      CFont m_font;
    在.cpp文件
    BOOL CMyDialog::OnInitDialog()
    {
     ...
     m_font.Create();//指定字体颜色
     ...
     GetDlgItem(IDC_BUTTON)->SetFont(&m_font);
     ...
    }
      

  6.   

    何必自绘,去下载一个XPButton类,拿来就用