在一对话框控件上有一静态文本框控件, 如何使静太文本框中的文字有颜色?

解决方案 »

  1.   

    相应WM_CTLCOLORSTATIC 消息 LRESULT OnCtlColorStatic(UINT uMsg, WPARAM wParam, LPARAM lParam , BOOL& bHandled)
    {
       HDC hDC=(HDC)wParam;
      

       ::SetTextColor(hDC,RGB(245,0,9));
       ::SetBkMode(hDC,TRANSPARENT);
       return NULL;
    }
      

  2.   

    // 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;
    }