本帖最后由 duoxiangliuti 于 2011-01-12 14:02:28 编辑

解决方案 »

  1.   

    我的主对话框里有静态文本控件和编辑框等控件,但是在执行这个函数的时候,没有执行判断为编辑框控件的if语句里面。就执行的判断为静态控件的if语句里,但是却把其他类型的空间的颜色也改变了,可是我想对每种不同类型的控件修改为不同的颜色,实现不了,望指教!
      

  2.   

    楼主遇到的问题和我一样,我也郁闷,控件ID肯定没有写错,但是if函数里面的代码根本没有运行。
    基类是View类的OnCtlColor函数就没有这个问题,但是基类是CDialog就会出现楼主说的问题。
      

  3.   

    http://topic.csdn.net/t/20040315/15/2844901.html你的控件会不会存在类似的问题?
      

  4.   

    有啥问题呢 是这样的啊  有些其他控件也算CTLCOLOR_EDIT 比如combobox
      

  5.   

    我刚才看了,谢谢你的回答。编辑框控件的问题是解决了。但是我里面的button按钮还是没有变化,下面是我的代码,我设断点调试过,会执行这里,但就是颜色没有改变 if(nCtlColor==CTLCOLOR_BTN)
           {
    pDC->SetBkColor(m_bkcl);
            pDC->SetTextColor(RGB(100,100,255));  //设置字体颜色
    return brush;
       }
      

  6.   

    http://topic.csdn.net/t/20030521/09/1811806.html
    button不行
      

  7.   

    CButton需要你重写CButton类,添加处理虚函数DrawItem
    MSDN上的例子// 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);
    }
      

  8.   


    button是不行,我以前试过,groupbox什么的都不行