解决方案 »

  1.   

    HBRUSH Cbaojing::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here
    // if (nCtlColor==IDC_palm)
    if(pWnd->GetDlgCtrlID()==IDC_palm)
           pDC->SetTextColor(RGB(255,0,255));
    return hbr;
    }
    绝对可以!
      

  2.   

    首先你的主窗体需要创建一个CBrush对象
    然后再初始化的过程中Create最后在OnCtlColor里面返回它的句柄就行了
    注意,千万不要在OnCtlColor中来创建一个CBrush对象,因为这样的话,这个函数结束后它的生命期也就结束了。除非用指针,但这样依然有许许多多的问题,包括释放以及第一次创建的时候需要Create等等的问题。
      

  3.   

    我刚试过了,可以的。另外!你的StaticText必须是透明的。用SetBkMode来设置
      

  4.   

    贴一个例子。Example// This OnCtlColor handler will change the color of a static control
    // with the ID of IDC_MYSTATIC. The code assumes that the CMyDialog
    // class has an initialized and created CBrush member named m_brush.
    // The control will be painted with red text and a background
    // color of m_brush.HBRUSH CZilchDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
       // Call the base class implementation first! Otherwise, it may
       // undo what we're trying to accomplish here.
       HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);   // Are we painting the IDC_MYSTATIC control? We can use
       // CWnd::GetDlgCtrlID() to perform the most efficient test.
       if (pWnd->GetDlgCtrlID() == IDC_MYSTATIC)
       {
          // 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;
       }   return hbr;
    }
      

  5.   

    不好意思!
    if (pWnd->GetDlgCtrlID()==IDC_palm)
    {
    pDC->SetBkMode(TRANSPARENT);
    pDC->SetBkColor(RGB(255, 255, 255));
    static CBrush m_brushEdit(RGB(255, 255, 255));
    hbr = m_brushEdit;
    }