www.pudn.com > 数控仿真与网络控制系统.rar > DopeEdit.cpp


/*CDopeEdit by Ryan Lederman 
  rlederman@mad.scientist.com 
  if you use my code, atleast mention me please*/ 
 
#include "stdafx.h" 
#include "DopeEdit.h" 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
BOOL CURSOR_INSIDE; 
///////////////////////////////////////////////////////////////////////////// 
// CDopeEdit 
 
CDopeEdit::CDopeEdit() 
{ 
	 
	SetLimitText(1000); 
	m_BackColor = RGB(255,255,255); 
	bkBrush.CreateSolidBrush(m_BackColor); 
 
} 
 
CDopeEdit::~CDopeEdit() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CDopeEdit, CEdit) 
	//{{AFX_MSG_MAP(CDopeEdit) 
	ON_WM_MOUSEMOVE() 
	ON_WM_NCPAINT() 
	ON_WM_PAINT() 
	ON_WM_CREATE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CDopeEdit message handlers 
 
 
void CDopeEdit::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	if (nFlags == MK_LBUTTON) 
	{ 
		CEdit::OnMouseMove(nFlags,point); 
		return; 
	} 
	CPoint cursorLoc; 
	GetCursorPos(&cursorLoc); 
	GetWindowRect(&m_WindowRect); 
	CEdit::OnMouseMove(nFlags,point); 
	SetCapture(); 
 
	if (PtInRect(&m_WindowRect,cursorLoc)) 
	{ 
		CURSOR_INSIDE = TRUE; 
 
	} 
	else 
	{ 
		CURSOR_INSIDE = FALSE; 
		ReleaseCapture(); 
	 
	} 
	 
	CDopeEdit::OnPaint(); 
} 
 
void CDopeEdit::OnSelAll() 
{ 
	SetSel(0,GetWindowTextLength()); 
 
} 
void CDopeEdit::OnNcPaint()  
{ 
	CPaintDC dc(this); // device context for painting 
	CWnd* theDlg = (CWnd*)AfxGetMainWnd(); 
	RECT lpRect; 
	GetRect(&lpRect); 
 
	WINDOWPLACEMENT theWP; 
	GetWindowPlacement(&theWP); 
 
	lpRect.bottom = theWP.rcNormalPosition.bottom - theWP.rcNormalPosition.top +2 ; 
	lpRect.left = -2; 
	lpRect.top = -2; 
	lpRect.right = theWP.rcNormalPosition.right - theWP.rcNormalPosition.left +2; 
 
	dc.SetBkMode(TRANSPARENT); 
	dc.SetBkColor(m_BackColor); 
 
	switch (CURSOR_INSIDE) 
	{ 
	case FALSE: // EDGE_ETCHED 
		dc.DrawEdge(&lpRect,EDGE_ETCHED,BF_RECT); 
 
		break; 
 
	case TRUE: // EDGE_SUNKEN 
		dc.DrawEdge(&lpRect,EDGE_SUNKEN,BF_RECT); 
 
		break; 
 
	} 
	CDopeEdit::Invalidate(); 
	m_WindowRect = lpRect; 
 
	//CDopeEdit::RedrawWindow(); 
 
} 
 
 
 
void CDopeEdit::OnPaint()  
{ 
	 
	SendMessage(WM_NCPAINT); 
	CEdit::OnPaint(); 
	 
} 
 
 
 
 
 
int CDopeEdit::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CEdit::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	CFont font; 
	CDC *pDC = GetDC(); 
	font.CreateFont(-12,0,0,0,FW_NORMAL,0,0,0,0,0,0,0,0,"Tahoma"); 
	CFont *pFont = (CFont *)pDC->SelectObject(&font); 
	SetFont(&font); 
	 
	return 0; 
}