\
比如怎么改变一个按钮的颜色啊?怎么在按钮上贴图?谢谢!

解决方案 »

  1.   

    如何改变控件内的字体颜色?
    (VCKBASE发表于2001-8-13 10:01:23)  [问题提出]
      有时对突出问题,或要重点描述的时候,改变控件的字体颜色是很重要的事.
      [解决方法]
      在MFC类库提供了CWnd::OnCtlColor函数,在工作框架的子窗口被重画时将调用该成员函数.因此可以重载WM_CTLCOLOR消息的响应函数.此函数的原型:
      afx_msg HBRUSH OnCtlColor(CDC *pDC,CWnd *pWnd,UINT nCtlColor);
      参数nCtlColor用于指定控件的类型,可以是:
      .CTLCOLOR_BTN       按钮控件
      .CTLCOLOR_DLG       对话框
      .CTLCOLOR_EDIT      编辑框
      .CTLCOLOR_LISTBOX   列表控件
      .CTLCOLOR_MSGBOX    消息控件
      .CTLCOLOR_SCROLLBAR 滚动条控件
      .CTLCOLOR_STATIC    静态控件
      [程序实现]
      假设你已有了名为My的对话框工程.你有了一个Edit的控件.
      HBRUSH CMyDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
      {
            HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
      
            // TODO: Change any attributes of the DC here
            if(nCtlColor==CTLCOLOR_EDIT)
               pDC->SetTextColor(RGB(255,0,0));
      
            // TODO: Return a different brush if the default is not desired
            return hbr;
      } 
      

  2.   

    看看这里
    http://www.vckbase.com/bbs/prime/index.asp
      

  3.   


    if(nCtlColor==CTLCOLOR_EDIT)
               pDC->SetTextColor(RGB(255,0,0));
    是正确的,但是如果CTLCOLOR_EDIT换成CTLCOLOR_BTN       就不行了,编译通过就是不起作用,为什么啊?
      

  4.   

    按钮要自绘DrawItem()
    pDC->FillRect(rect(按钮的矩形),COLORREF(颜色));
      

  5.   

    按钮要自绘DrawItem()
    pDC->FillRect(rect(按钮的矩形),COLORREF(颜色));
    rect(按钮的矩形),这个怎么得到啊?
    谢谢帮助!
      

  6.   

    用classwizard重载DrawItem函数。编写代码如下所示:void CXXXXButton::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct)
    {
         CDC* pDC=CDC::FromHandle(lpDrawItemStruct->hDC);
         ASSERT_VALID(pDC);
         CRect rectClient=lpDrawItemStruct->rcItem;
           pDC->FillRect(rectClient,COLORREF(颜色));
    }