在onButton()函数里我想重载 OnCtrlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 函数.
     在一般就可以直接写 该函数名等,可想OnCtrlColor函数后面还有CDC,CWnd,nCtlColor
三个值不知这样写? 有位朋友教我用WM_CTLCOLOR消息但我不知具体代码这写?
     

解决方案 »

  1.   

    如果只想改变Button的颜色,建议使用CBitmapButton
    WM_CTLCOLOR在Button的窗口中处理,但对button不管用!
      

  2.   

    我不是改变Button的颜色我是想改变STATIC的颜色 在Button里只是作为一事件.在重新调有
    OnCtrlColor (...)函数 来重新改变STATIC的颜色 
             HBRUSH CBackstaticDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    if (pWnd->GetDlgCtrlID() == IDC_STATIC1)
      {
          // Set the text color to red
          pDC->SetTextColor(RGB(255, 0, 0));      // Set the background mode for text to transparent 
          // so background will show thru.
         pDC->SetBkMode(TRANSPARENT);
         
          // Return handle to our CBrush object
          hbr = m_brush;
      }
    BOOL CBackstaticDlg::OnInitDialog()
    {
    CDialog::OnInitDialog();
    m_brush.CreateSolidBrush(RGB(0,255,255));
       
    return TRUE;  // return TRUE  unless you set the focus to a control
    }
         只要我在onButton()里重新给m_brush.CreateSolidBrush(RGB(0,255,0));
     在重载 OnCtrlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 不是ok吗?
      

  3.   

    那你可以在OnCtlColor中设个开关,在OnButton中重新设置开关值,不用直接调用!
      

  4.   

    m_bButtonClicked为CXXXDlg的成员变量初始设为FALSE;
    void CXXXDlg::OnButton1() 
    {
    // TODO: Add your control notification handler code here
    m_bButtonClicked=TRUE;
    Invalidate();
    }
    HBRUSH CXXXDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    if(nCtlColor==CTLCOLOR_STATIC&&m_bButtonClicked)
    {
    pDC->SetBkColor(RGB(0,255,255));
    CBrush Brush(RGB(0,255,255));
    hbr=(HBRUSH)(Brush.GetSafeHandle());
    }
    // TODO: Return a different brush if the default is not desired
    return hbr;
    }