如题。查过资料了,好像要自己重载DrawItem,没试成功。希望能给个解决方法。
在CSDN有一个是重载了Button的DrawItem,但把它改成Radio Button时,观感有问题,呵呵。// ============ 底下是参考的原文,是修改成Button的,没能成功地改成Radio Button你可以试下这个:DrawItem()   
  因为它是CButton::DrawItem   ,   
  你的RADIO也是继承CButton类的,   
  你重载下DrawItem()。   
    
  下面是MSDN上的关于DrawItem的例子。   
  void   CMyButton::DrawItem(LPDRAWITEMSTRUCT   lpDrawItemStruct)     
  {   
        UINT   uStyle   =   DFCS_BUTTONPUSH;   
    
        //   This   code   only   works   with   buttons.   
        ASSERT(lpDrawItemStruct->CtlType   ==   ODT_BUTTON);   
    
        //   If   drawing   selected,   add   the   pushed   style   to   DrawFrameControl.   
        if   (lpDrawItemStruct->itemState   &   ODS_SELECTED)   
              uStyle   |=   DFCS_PUSHED;   
    
        //   Draw   the   button   frame.   
        ::DrawFrameControl(lpDrawItemStruct->hDC,   &lpDrawItemStruct->rcItem,     
              DFC_BUTTON,   uStyle);   
    
        //   Get   the   button's   text.   
        CString   strText;   
        GetWindowText(strText);   
    
        //   Draw   the   button   text   using   the   text   color   red.   
        COLORREF   crOldColor   =   ::SetTextColor(lpDrawItemStruct->hDC,   RGB(255,0,0));   
        ::DrawText(lpDrawItemStruct->hDC,   strText,   strText.GetLength(),     
              &lpDrawItemStruct->rcItem,   DT_SINGLELINE|DT_VCENTER|DT_CENTER);   
        ::SetTextColor(lpDrawItemStruct->hDC,   crOldColor);   
  }  

解决方案 »

  1.   

    不用重绘吧
    重载CMyButton中的CtrlColor
    pDC->setTextColor();大概是这样,你试一下。
      

  2.   

    在Dialog中添加WM_CTRLCOLOR响应,添加代码:
       if(pWnd->GetDlgCtrlID()==IDC_RADIO)
             pDC->SetTextColor(RGB(255,0,0))//就可以设置为红色了
      

  3.   

    不知道在64位下有什么替换的方法没?
    同样的设置颜色的代码,在32位下工作正常,64位下就不能改颜色。注:把32位下编译好的程序在64位下运行,RaidoButton的字体颜色也没有改动。
      

  4.   

    加粗字体只需要用SelectObject选进去的字体是粗体的就行,字体属性的lfWeight(好象是这个),至于64位下为什么不起作用就没法乱猜了. :)
      

  5.   

    CPaintDC dc(this); // device context for painting
    LOGFONT lf;
    CRect   rect; 
    CRect winRect;
    CFont fontTemp, * pFontOld; dc.GetCurrentFont()->GetLogFont(&lf);
    //lstrcpy(lf.lfFaceName, _T("华文隶书"));
    lf.lfWidth = 0;
    lf.lfWeight = FW_HEAVY;
    lf.lfHeight = 0x0F;
    fontTemp.CreateFontIndirect(&lf);
    pFontOld = dc.SelectObject(&fontTemp);
    /*((CButton*)GetDlgItem(IDC_RADIO_TEST))->SetWindowText(_T("Test Bold."));*/
    CButton * btn = (CButton*)GetDlgItem(IDC_RADIO_TEST);
    btn->GetWindowRect(&rect);
    this->GetWindowRect(&winRect);
    //dc.DrawText(_T("test bold test."), &rect, DT_BOTTOM);
    dc.TextOut(rect.left - winRect.left, rect.top - winRect.top, _T("test bold test."));
    //dc.TextOut(100, 0, _T("test bold test."));
    dc.SelectObject(pFontOld);
    // =================
     我用上面的方法改了下,发现用dc的输出是,我可以在Radio Button的位置将字改成粗体,但是那样的话我要把原先的Radio Button的文本位置挑很小,这样的话那些加粗的字才能显示出来。但是这样子的话,就相当与在Radio Button的右边放一个CStatic的控件了,与原先的Radio Button的行为有区别的(比如点字的时候,就可以选中Radio Button)。
      

  6.   

    不知道为什么我用如下的以前好像好使过,现在又不行了:在Dialog中添加WM_CTRLCOLOR响应,添加代码:if(pWnd->GetDlgCtrlID()==IDC_RADIO)
    pDC->SetTextColor(RGB(255,0,0))//就可以设置为红色了// 现在这个代码不好使了
      

  7.   

    我用的VS2008.其他的颜色都能改的了,
    ///////////////////////////////////////
    在Dialog中添加WM_CTRLCOLOR响应,添加代码: if(pWnd-> GetDlgCtrlID()==IDC_RADIO) 
    pDC-> SetTextColor(RGB(255,0,0))//就可以设置为红色了 
    //////////////////////////////////////////就是改Radio的颜色不行。。不知道怎么回事。