NiceEdit.cpp
上传用户:szhuagan
上传日期:2021-05-27
资源大小:2676k
文件大小:3k
- // ColorEdit.cpp : implementation file
- //
- #include "stdafx.h"
- #include "NiceEdit.h"
- #include "Color.h" // File Holding (#define)'s for COLORREF Values
- #include ".niceedit.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CNiceEdit
-
- CNiceEdit::CNiceEdit()
- : m_bHasEntered(FALSE)
- {
- m_crBkColor = BLACK; // Initializing background color to black
- m_crTextColor = GREEN; // Initializing text color to black
- m_brBkgnd.CreateSolidBrush(m_crBkColor); // Creating the Brush Color For the Edit Box Background
- m_crInitBorderColor = LIGHTGREEN; //Initial defualt border Color
- m_crBorderColor = m_crInitBorderColor;
- }
- CNiceEdit::~CNiceEdit()
- {
- }
- BEGIN_MESSAGE_MAP(CNiceEdit, CEdit)
- //{{AFX_MSG_MAP(CNiceEdit)
- ON_WM_CTLCOLOR_REFLECT()
- //}}AFX_MSG_MAP
- ON_WM_LBUTTONDOWN()
- ON_WM_KILLFOCUS()
- ON_WM_SETFOCUS()
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CNiceEdit message handlers
- void CNiceEdit::SetTextColor(COLORREF crColor)
- {
- m_crTextColor = crColor; // Passing the value passed by the dialog to the member varaible for Text Color
- RedrawWindow();
- }
- void CNiceEdit::SetBkColor(COLORREF crColor)
- {
- m_crBkColor = crColor;
- m_brBkgnd.DeleteObject(); //删除已经存在的填充画刷
- m_brBkgnd.CreateSolidBrush(crColor);
- RedrawWindow();
- }
- HBRUSH CNiceEdit::CtlColor(CDC* pDC, UINT nCtlColor)
- {
- HBRUSH hbr;
- hbr = (HBRUSH)m_brBkgnd; //把预定义的画刷句柄给hbr
- pDC->BeginPath();
- pDC->SetBkColor(m_crBkColor);
- pDC->SetTextColor(m_crTextColor);
- pDC->EndPath();
- pDC->SelectClipPath( RGN_XOR );
- if( ! m_bHasEntered )
- {
- GetWindowRect( m_rcEntire );
- m_rcEntire.SetRect ( -3, -3, m_rcEntire.Width() - 3, m_rcEntire.Height() - 3 );
- }
- CPen borderPen(PS_JOIN_ROUND , 2, m_bHasEntered ? m_crBorderColor : m_crInitBorderColor ),*pOldPen = NULL;
- pOldPen = pDC->SelectObject( &borderPen );
- pDC->MoveTo( m_rcEntire.TopLeft() );
- pDC->LineTo( m_rcEntire.right, m_rcEntire.top );
- pDC->MoveTo( m_rcEntire.right, m_rcEntire.top );
- pDC->LineTo( m_rcEntire.BottomRight() );
- pDC->MoveTo( m_rcEntire.BottomRight() );
- pDC->LineTo( m_rcEntire.left, m_rcEntire.bottom );
- pDC->MoveTo( m_rcEntire.left, m_rcEntire.bottom);
- pDC->LineTo( m_rcEntire.TopLeft() );
-
- pDC->SelectObject( pOldPen );
- borderPen.DeleteObject();
- return hbr;
- }
- BOOL CNiceEdit::SetReadOnly(BOOL flag)
- {
- SetBkColor(m_crBkColor);
- return CEdit::SetReadOnly(flag);
- }
- void CNiceEdit::OnLButtonDown(UINT nFlags, CPoint point)
- {
- // TODO: 在此添加消息处理程序代码和/或调用默认值
- if( m_crBorderColor != m_crInitBorderColor ) //不为原始边框颜色
- m_crBorderColor = 0x00FFFFFF & ~m_crInitBorderColor;
- m_bHasEntered = TRUE;
- RedrawWindow();
- CEdit::OnLButtonDown(nFlags, point);
- }
- void CNiceEdit::OnKillFocus(CWnd* pNewWnd)
- {
- CEdit::OnKillFocus(pNewWnd);
- m_crBorderColor = m_crInitBorderColor;
- m_bHasEntered = FALSE;
- RedrawWindow();
- // TODO: 在此处添加消息处理程序代码
- }
- void CNiceEdit::OnSetFocus(CWnd* pOldWnd)
- {
- CEdit::OnSetFocus(pOldWnd);
- m_crBorderColor = 0x00FFFFFF & ~m_crBorderColor;
- m_bHasEntered = TRUE;
- RedrawWindow();
- // TODO: 在此处添加消息处理程序代码
- }
- // 设置变宽颜色
- void CNiceEdit::SetBorderColor(COLORREF newValue)
- {
- m_crInitBorderColor = newValue;
- RedrawWindow();
- }