CButton* button = (CButton*)thedlg->GetDlgItem(IDC_CONN);
CDC* bcdc = button->GetDC();
bcdc->SetTextColor(RGB(255,0,0));
button->UpdateWindow();

我用以上语句尝试没有任何效果,请高人给一个比较简单的实现方法。。谢谢!

解决方案 »

  1.   


    // NOTE: CMyButton is a class derived from CButton. The CMyButton
    // object was created as follows:
    //
    // CMyButton myButton;
    // myButton.Create(_T("My button"), 
    //      WS_CHILD|WS_VISIBLE|BS_PUSHBUTTON|BS_OWNERDRAW, 
    //      CRect(10,10,100,30), pParentWnd, 1);
    //// This example implements the DrawItem method for a CButton-derived 
    // class that draws the button's text using the color red.
    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);
    }
      

  2.   

    自绘,void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);直接设置不行
      

  3.   

    也就是说必须要实现一个新的Button类继承CButton,重写DrawItem是不是?
    DrawItem要如何调用和传参呢?
      

  4.   

    case WM_CTLCOLORBTN:
    {
        SetTextColor((HDC)wParam,RGB(255,0,0));
        return (long)CreateSolidBrush(RGB(255,255,255));
    }
    注意此时的按钮必需是自绘风格如果真的想不这样做
    SetSysColor();也可以做到,但是这个是所有窗体都会变
    你说:就没有简单点的方法吗?我就为一个按钮上的字改个颜色还得费这么大工夫啊
    使用好默认的按钮不 是一件容易的事,要是我就不会用默认的按钮,自己实现的很简单,但是系统的不简单,找到接口很麻烦  
      

  5.   

    还是CSDN高手多!!!!!!!!
      

  6.   

    想简单? 贴图最简单快捷,自己在资源里自己画个按钮图(在资源里面添加一个空的BITMAP资源,然后自己绘制这个BITMAP,这个BITMAP就凭你为所欲为了,在资源里还害怕有什么字体设置不出来?),然后就贴图:
    m_bitmap = ::LoadBitmap(AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDB_MYBUT_BITMAP));
    m_Button.SetBitmap(IDB_MYBUT_BITMAP);
      

  7.   

    只有重写CButton的DrawItem方法才能实现你的问题
      

  8.   

    在MSDN里面不是有这个实例的么,我用了一下蛮管用的,你嫌多了就直接复制粘贴