// ColorEdit.cpp : implementation file // #include "stdafx.h" #include "ColorEdit.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif / // CColorEdit CColorEdit::CColorEdit() { m_BackColor = RGB(255,255,255); m_TextColor = RGB(0,0,0); } CColorEdit::~CColorEdit() { } BEGIN_MESSAGE_MAP(CColorEdit, CEdit) //{{AFX_MSG_MAP(CColorEdit) ON_WM_CTLCOLOR_REFLECT() ON_WM_CHAR() ON_WM_RBUTTONDOWN() //}}AFX_MSG_MAP END_MESSAGE_MAP() / // CColorEdit message handlers HBRUSH CColorEdit::CtlColor(CDC* pDC, UINT nCtlColor) { // TODO: Change any attributes of the DC here HBRUSH hbr; hbr=(HBRUSH)m_Brush; pDC->SetBkColor(m_BackColor); pDC->SetTextColor(m_TextColor); return hbr; // TODO: Return a non-NULL brush if the parent's handler should not be called } void CColorEdit::SetBackColor(COLORREF crColor) { m_BackColor = crColor; m_Brush.DeleteObject(); m_Brush.CreateSolidBrush(m_BackColor); RedrawWindow(); } void CColorEdit::SetTextColor(COLORREF crColor) { m_TextColor = crColor; m_Brush.DeleteObject(); m_Brush.CreateSolidBrush(m_BackColor); RedrawWindow(); } void CColorEdit::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) { // TODO: Add your message handler code here and/or call default if ((nChar>=0x30)&&(nChar<=0x39)||(nChar == VK_BACK)) //Enter number. { CEdit::OnChar(nChar, nRepCnt, nFlags); } } void CColorEdit::OnRButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default //CEdit::OnRButtonDown(nFlags, point); }
设置Edit和Static的BkColor和TextColor.(重载)
最新推荐文章于 2020-02-18 00:56:17 发布