不会,谢谢大家了!

解决方案 »

  1.   

    重载啊
    不知道OnCtrlColor行不行,不行就DrawItem了
      

  2.   

    错了!Button的字体颜色的改变只能用自画按钮来做,上面那么多人,别耽误了人家,不知道别乱说,OnCtrlColor,你在里面做做看呢?!
      

  3.   

    错了!Button的字体颜色的改变只能用自画按钮来做,上面那么多人,别耽误了人家,不知道别乱说,OnCtrlColor,你在里面做做看呢?!
      

  4.   

    既是先设置按钮的属性为自画按钮,然后在DrawItem里面自画该按钮。
      

  5.   

    唉!不知道顶楼的几位朋友自己试过没有?
    不要误人子弟,叫人笑掉大牙!
    -----------------------
    WM_DRAWITEM 消息
    并且设置按钮具有OWNERDRAW 风格
    void CToolDialog::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your message handler code here and/or call default
      if(nIDCtl==IDC_BUTTON_TEST)
      {
    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;
       CButton *pButton=(CButton*)this->GetDlgItem(IDC_BUTTON_TEST);
       if(pButton)
       pButton->GetWindowText(strText);
       // Draw the button text using the text blue red.
       COLORREF crOldColor = ::SetTextColor(lpDrawItemStruct->hDC, RGB(0,0,255));
       ::DrawText(lpDrawItemStruct->hDC, strText, strText.GetLength(), 
          &lpDrawItemStruct->rcItem, DT_SINGLELINE|DT_VCENTER|DT_CENTER);
       ::SetTextColor(lpDrawItemStruct->hDC, crOldColor);
      }
    CDialog::OnDrawItem(nIDCtl, lpDrawItemStruct);
    }
      

  6.   

    OnCtlColor 是没有用的,重载按钮内实现自绘按钮,如果你觉得麻烦的话,可以找现成的代码加到你的工程中去,CButtonST 是一个很不错的按钮类,功能很完善。
    http://www.vckbase.com/ 上面可以去下一个,需要把 BCMenu.h/cpp 和 BtnST.h/cpp 加到你的工程中去
      

  7.   

    以下通过定制方形彩色按纽来说明: 第一步:派生出自己的按纽类。//CcolorButton.h class CColorButton : public CButton{DECLARE_DYNAMIC(CColorButton)public:CColorButton(); virtual ~CColorButton(); 
    BOOL Attach(const UINT nID, CWnd* pParent, const COLORREF BGColor = RGB(192, 123, 192), // 按纽的背景色const COLORREF FGColor = RGB(1, 1, 1), // 文本颜色);protected:virtual void DrawItem(LPDRAWITEMSTRUCT lpDIS); //重定义虚拟函数DrawItemvoid DrawFrame(CDC *DC, CRect R); //绘制按纽框void DrawFilledRect(CDC *DC, CRect R, COLORREF color); //填充按纽框void DrawLine(CDC *DC, CRect EndPoints, COLORREF color); void DrawLine(CDC *DC, long left, long top, long right, long bottom, COLORREF color);void DrawButtonText(CDC *DC, CRect R, const char *Buf, COLORREF TextColor);//绘制按纽上的文本
    COLORREF GetFGColor() { return m_fg; } COLORREF GetBGColor() { return m_bg; }private:COLORREF m_fg, m_bg;};#endif
    第二步:定义各函数//CcolorButton.cpp……// CColorButtonIMPLEMENT_DYNAMIC(CColorButton, CButton)CColorButton::CColorButton() { } CColorButton::~CColorButton(){} 
    //定义Attach()函数BOOL CColorButton::Attach(const UINT nID, CWnd* pParent, const COLORREF BGColor, const COLORREF FGColor){if (!SubclassDlgItem(nID, pParent))return FALSE;m_fg = FGColor;m_bg = BGColor; return TRUE;}
    //重载DrawItem()void CColorButton::DrawItem(LPDRAWITEMSTRUCT lpDIS){CDC* pDC = CDC::FromHandle(lpDIS->hDC);UINT state = lpDIS->itemState; CRect focusRect, btnRect;focusRect.CopyRect(&lpDIS->rcItem); //按纽的选中虚线框btnRect.CopyRect(&lpDIS->rcItem); 
    // 设置表示按纽被选中的虚线框focusRect.left += 4;focusRect.right -= 4;focusRect.top += 4;focusRect.bottom -= 4;
    // 按纽标题const int bufSize = 512;TCHAR buffer[bufSize];GetWindowText(buffer, bufSize);
    // 绘制并标志按纽 DrawFilledRect(pDC, btnRect, GetBGColor()); DrawFrame(pDC, btnRect);DrawButtonText(pDC, btnRect, buffer, GetFGColor());
    // 如果按纽处于选中状态则在其上绘制选中虚线框if (state & ODS_FOCUS) {DrawFocusRect(lpDIS->hDC, (LPRECT)&focusRect);}}void CColorButton::DrawFrame(CDC *DC, CRect R){ //绘制按纽,用户通过定制该函数可实现不同形状的按纽。DrawLine(DC, R.left, R.top, R.right, R.top, RGB(255, 255, 255)); DrawLine(DC, R.left, R.top, R.left, R.bottom, RGB(255, 255, 255)); //以下绘制按纽的外围框线以使按纽有立体感DrawLine(DC, R.left + 1, R.bottom - 1, R.right, R.bottom - 1, RGB(1, 1, 1));//绘制按纽左框线和上框线DrawLine(DC, R.right - 1, R.top + 1, R.right - 1, R.bottom, RGB(1, 1, 1));//绘制按纽右框线和下框线 }//用色彩填充按纽框void CColorButton::DrawFilledRect(CDC *DC, CRect R, COLORREF color){ CBrush B;B.CreateSolidBrush(color);DC->FillRect(R, &B);}// DrawLine用于绘制按纽,其为多态函数void CColorButton::DrawLine(CDC *DC, CRect EndPoints, COLORREF color){ ……}void CColorButton::DrawLine(CDC *DC, long left, long top, long right, long bottom, COLORREF color){ ……}//绘制按纽文本void CColorButton::DrawButtonText(CDC *DC, CRect R, const char *Buf, COLORREF TextColor){COLORREF prevColor = DC->SetTextColor(TextColor);DC->SetBkMode(TRANSPARENT);DC->DrawText(Buf, strlen(Buf), R, DT_CENTER|DT_VCENTER|DT_SINGLELINE);DC->SetTextColor(prevColor);}
    第三步:引用定制类定制任意对话框CColorDlg,在其上画一按键控件。ID为IDOK。//CColorDlg.hclass CColorDlg : public CDialog{…..// Implementationprotected:CColorButton m_btnOK;}
    //CColorDlg.cpp…….BOOL CColorBtnSampleDlg::OnInitDialog(){CDialog::OnInitDialog();…….VERIFY(m_btnOK.Attach(IDOK, this, RED, BLUE, YELLOW));…….}……
      

  8.   

    OnCtrlColor 不行,只能改它的背景色.而且改后字也没了.
    要用上面的方法.
    自己画.
      

  9.   

    我对着上面的一步一步来,还是不行,好像重画程序没有执行到。
    我不明白怎么把一个IDOK一样的画上去的button跟一个自己定义的button类结合起来。
      

  10.   

    在View里用Create建的Button一旦设置了自画属性,执行时就会死机!