www.pudn.com > VC生成漂亮界面.zip > HyperLink.cpp


// HyperLink.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "VCFace.h" 
#include "HyperLink.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CHyperLink 
 
CHyperLink::CHyperLink() 
{ 
	m_nTextColor=RGB(0,0,255); 
	m_bCursorOn=false; 
} 
 
CHyperLink::~CHyperLink() 
{ 
} 
 
 
BEGIN_MESSAGE_MAP(CHyperLink, CStatic) 
	//{{AFX_MSG_MAP(CHyperLink) 
	ON_WM_CTLCOLOR_REFLECT() 
	ON_WM_MOUSEMOVE() 
	ON_WM_SETCURSOR() 
	ON_WM_CAPTURECHANGED() 
	ON_CONTROL_REFLECT(BN_CLICKED, OnClicked) 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CHyperLink message handlers 
 
void CHyperLink::DoDataExchange(CDataExchange* pDX)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	 
	CStatic::DoDataExchange(pDX); 
} 
 
HBRUSH CHyperLink::CtlColor(CDC* pDC, UINT nCtlColor)  
{ 
	// TODO: Change any attributes of the DC here	 
	if(m_bCursorOn) 
	{ 
		pDC->SetTextColor(m_nTextColor); 
	} 
	else 
	{ 
		pDC->SetTextColor(RGB(0,0,0)); 
	} 
	 
	pDC->SetBkMode(TRANSPARENT); 
	// TODO: Return a non-NULL brush if the parent's handler should not be called 
	return (HBRUSH)GetStockObject(NULL_BRUSH); 
} 
 
void CHyperLink::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if(m_bCursorOn) 
	{ 
		CRect rect; 
		GetWindowRect(&rect); 
 
		rect.right-=rect.left; 
		rect.bottom-=rect.top; 
		rect.left=0; 
		rect.top=0; 
 
		if(!rect.PtInRect(point)) 
		{ 
			m_bCursorOn=false; 
			::ReleaseCapture(); 
			this->Invalidate(); 
		} 
 
	} 
	else 
	{ 
		m_bCursorOn=true; 
		this->SetCapture(); 
		this->Invalidate(); 
	} 
 
	CStatic::OnMouseMove(nFlags, point); 
} 
 
BOOL CHyperLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)  
{ 
	// TODO: Add your message handler code here and/or call default 
	if(m_hCursor) 
	{ 
		::SetCursor(m_hCursor); 
		return true; 
	} 
	return CStatic::OnSetCursor(pWnd, nHitTest, message); 
} 
 
void CHyperLink::OnCaptureChanged(CWnd *pWnd)  
{ 
	// TODO: Add your message handler code here 
	m_bCursorOn=false; 
	::ReleaseCapture(); 
	this->Invalidate(); 
	CStatic::OnCaptureChanged(pWnd); 
} 
 
void CHyperLink::OnClicked()  
{ 
	// TODO: Add your control notification handler code here 
	CString CmdLine,HyperLink; 
	GetWindowText(HyperLink); 
	CmdLine.Format("Explorer.exe %s",HyperLink.GetBuffer(0)); 
	WinExec(CmdLine.GetBuffer(0),SW_NORMAL); 
}