| 1 |
// EditEx.cpp : implementation file |
|---|
| 2 |
// |
|---|
| 3 |
|
|---|
| 4 |
#include "stdafx.h" |
|---|
| 5 |
#include "EditEx.h" |
|---|
| 6 |
|
|---|
| 7 |
#ifdef _DEBUG |
|---|
| 8 |
#define new DEBUG_NEW |
|---|
| 9 |
#undef THIS_FILE |
|---|
| 10 |
static char THIS_FILE[] = __FILE__; |
|---|
| 11 |
#endif |
|---|
| 12 |
|
|---|
| 13 |
///////////////////////////////////////////////////////////////////////////// |
|---|
| 14 |
// CEditEx |
|---|
| 15 |
|
|---|
| 16 |
CEditEx::CEditEx() |
|---|
| 17 |
{ |
|---|
| 18 |
m_bMouseOver=FALSE; |
|---|
| 19 |
brHot.CreateSolidBrush(RGB(255,255,255)); |
|---|
| 20 |
br.CreateSolidBrush(RGB(221,221,221)); |
|---|
| 21 |
} |
|---|
| 22 |
|
|---|
| 23 |
CEditEx::~CEditEx() |
|---|
| 24 |
{ |
|---|
| 25 |
} |
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 |
BEGIN_MESSAGE_MAP(CEditEx, CEdit) |
|---|
| 29 |
//{{AFX_MSG_MAP(CEditEx) |
|---|
| 30 |
ON_WM_SETFOCUS() |
|---|
| 31 |
ON_WM_MOUSEMOVE() |
|---|
| 32 |
ON_WM_KILLFOCUS() |
|---|
| 33 |
ON_WM_CTLCOLOR_REFLECT() |
|---|
| 34 |
ON_CONTROL_REFLECT(EN_VSCROLL, OnVscroll) |
|---|
| 35 |
ON_WM_PAINT() |
|---|
| 36 |
//}}AFX_MSG_MAP |
|---|
| 37 |
END_MESSAGE_MAP() |
|---|
| 38 |
|
|---|
| 39 |
///////////////////////////////////////////////////////////////////////////// |
|---|
| 40 |
// CEditEx message handlers |
|---|
| 41 |
void CEditEx::OnMouseMove(UINT nFlags, CPoint point) |
|---|
| 42 |
{ |
|---|
| 43 |
CEdit::OnMouseMove(nFlags, point); |
|---|
| 44 |
if(m_bIsFocused) return; |
|---|
| 45 |
if(GetCapture()!=this)//come in for the first time |
|---|
| 46 |
{ |
|---|
| 47 |
m_bMouseOver=TRUE; |
|---|
| 48 |
SetCapture(); |
|---|
| 49 |
Invalidate(TRUE); |
|---|
| 50 |
} |
|---|
| 51 |
else |
|---|
| 52 |
{ |
|---|
| 53 |
CRect rect; |
|---|
| 54 |
GetClientRect(&rect); |
|---|
| 55 |
if(!rect.PtInRect(point))//Mouse move out of Edit control |
|---|
| 56 |
{ |
|---|
| 57 |
m_bMouseOver=FALSE; |
|---|
| 58 |
Invalidate(TRUE); |
|---|
| 59 |
ReleaseCapture(); |
|---|
| 60 |
} |
|---|
| 61 |
} |
|---|
| 62 |
|
|---|
| 63 |
} |
|---|
| 64 |
|
|---|
| 65 |
void CEditEx::OnSetFocus(CWnd* pOldWnd) |
|---|
| 66 |
{ |
|---|
| 67 |
CEdit::OnSetFocus(pOldWnd); |
|---|
| 68 |
m_bIsFocused=TRUE; |
|---|
| 69 |
m_bMouseOver=TRUE; |
|---|
| 70 |
Invalidate(TRUE); |
|---|
| 71 |
|
|---|
| 72 |
} |
|---|
| 73 |
|
|---|
| 74 |
void CEditEx::OnKillFocus(CWnd* pNewWnd) |
|---|
| 75 |
{ |
|---|
| 76 |
CEdit::OnKillFocus(pNewWnd); |
|---|
| 77 |
m_bIsFocused=FALSE; |
|---|
| 78 |
m_bMouseOver=FALSE; |
|---|
| 79 |
Invalidate(TRUE); |
|---|
| 80 |
} |
|---|
| 81 |
|
|---|
| 82 |
|
|---|
| 83 |
|
|---|
| 84 |
HBRUSH CEditEx::CtlColor(CDC* pDC, UINT nCtlColor) |
|---|
| 85 |
{ |
|---|
| 86 |
if(m_bMouseOver) |
|---|
| 87 |
{ |
|---|
| 88 |
pDC->SetBkColor(RGB(255,255,255)); |
|---|
| 89 |
return brHot; |
|---|
| 90 |
} |
|---|
| 91 |
else |
|---|
| 92 |
{ |
|---|
| 93 |
pDC->SetBkColor(RGB(221,221,221)); |
|---|
| 94 |
return br; |
|---|
| 95 |
} |
|---|
| 96 |
} |
|---|
| 97 |
|
|---|
| 98 |
void CEditEx::OnVscroll() |
|---|
| 99 |
{ |
|---|
| 100 |
InitializeFlatSB(GetSafeHwnd()); |
|---|
| 101 |
} |
|---|
| 102 |
|
|---|
| 103 |
|
|---|
| 104 |
void CEditEx::OnPaint() |
|---|
| 105 |
{ |
|---|
| 106 |
CEdit::OnPaint(); |
|---|
| 107 |
CRect rect; |
|---|
| 108 |
GetClientRect(&rect); |
|---|
| 109 |
rect.InflateRect(1,1,1,1); |
|---|
| 110 |
|
|---|
| 111 |
CBrush brush; |
|---|
| 112 |
brush.CreateSolidBrush(RGB(0,0,0)); |
|---|
| 113 |
|
|---|
| 114 |
CDC *pDC=GetDC(); |
|---|
| 115 |
pDC->FrameRect(rect,&brush); |
|---|
| 116 |
} |
|---|