- HBRUSH ClassName::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- /* These are things that need to be placed throughout your class
- //theese goes in declairations
- private:
- CBrush m_InputBrush;
- CBrush m_DisplayBrush;
- public:
- afx_msg HBRUSH OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor);
- // this goes in the body of the constructor
- m_InputBrush.CreateSolidBrush(RGB(255,255,255));
- m_DisplayBrush.CreateSolidBrush(RGB(212,208,200));
- //goes after begin message map:
- ON_WM_CTLCOLOR()
- add bool Input to class
- //dont forget the onfocus function for the edit control
- //and set to Input to false when displaying data
- Input = false;
- Invalidate(false);
- */
- // 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.
- switch(pWnd->GetDlgCtrlID())
- {
- case IDC_EDIT_SL_IN:
- // Set the text color
- pDC->SetTextColor(RGB(0, 0, 0));
- // Set the background mode for text to transparent
- // so background will show thru.
- pDC->SetBkMode(TRANSPARENT);
- // Return handle to our CBrush object
- if(Input)
- {
- hbr = m_InputBrush;
- }
- else
- {
- hbr = m_DisplayBrush;
- }
- break;
- case IDC_EDIT_SAH_IN:
- // Set the text color
- pDC->SetTextColor(RGB(0, 0, 0));
- // Set the background mode for text to transparent
- // so background will show thru.
- pDC->SetBkMode(TRANSPARENT);
- // Return handle to our CBrush object
- if(InputSAH)
- {
- hbr = m_InputBrush;
- }
- else
- {
- hbr = m_DisplayBrush;
- }
- break;
- default:
- break;
- }
- return hbr;
- }
- //该片段来自于http://www.codesnippet.cn/detail/070120131386.html
来源: http://www.codesnippet.cn/detail/070120131386.html