// LabelLink.cpp : implementation file // // LabelLink static control. // #include "stdafx.h" #include "LabelLink.h" #include "windows.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// // CLabelLink HCURSOR CLabelLink::g_hLinkCursor = NULL; CLabelLink::CLabelLink() { m_bOverControl = FALSE; // Cursor not yet over control m_strURL.Empty(); // Set URL to an empty string } CLabelLink::~CLabelLink() { } IMPLEMENT_DYNAMIC(CLabelLink, CStatic) BEGIN_MESSAGE_MAP(CLabelLink, CStatic) //{{AFX_MSG_MAP(CLabelLink) ON_WM_CTLCOLOR_REFLECT() ON_WM_SETCURSOR() ON_WM_MOUSEMOVE() ON_WM_LBUTTONUP() ON_WM_NCHITTEST() //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CLabelLink message handlers void CLabelLink::PreSubclassWindow() { // If the URL string is empty try to set it to the window text if (m_strURL.IsEmpty()) GetWindowText(m_strURL); // Check that the window text isn't empty. // If it is, set it as URL string. CString strWndText; GetWindowText(strWndText); if (strWndText.IsEmpty()) CStatic::SetWindowText(m_strURL); CString strWndDir; GetWindowsDirectory(strWndDir.GetBuffer(MAX_PATH), MAX_PATH); strWndDir.ReleaseBuffer(); strWndDir += TEXT("\\winhlp32.exe"); HMODULE hModule = LoadLibrary(strWndDir); g_hLinkCursor = LoadCursor(hModule, MAKEINTRESOURCE(106)); FreeLibrary(hModule); CStatic::PreSubclassWindow(); } HBRUSH CLabelLink::CtlColor(CDC* pDC, UINT nCtlColor) { pDC->SetTextColor(RGB(0, 0, 255)); // Set transparent drawing mode pDC->SetBkMode(TRANSPARENT); return (HBRUSH)GetStockObject(NULL_BRUSH); } void CLabelLink::OnMouseMove(UINT nFlags, CPoint point) { if (m_bOverControl) // Cursor currently over control { CRect rect; GetClientRect(rect); if (!rect.PtInRect(point)) { m_bOverControl = FALSE; ReleaseCapture(); Invalidate(); return; } } else // Cursor has left control area { m_bOverControl = TRUE; Invalidate(); SetCapture(); } } ////////////////////////////////////////////////////////////////////////// UINT CLabelLink::OnNcHitTest(CPoint point) { return HTCLIENT; } void CLabelLink::OnLButtonUp(UINT nFlags, CPoint point) { ShellExecute(NULL, TEXT("open"), m_strURL, NULL, NULL, SW_SHOW); } BOOL CLabelLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message) { if (g_hLinkCursor) { ::SetCursor(g_hLinkCursor); return TRUE; } return FALSE; }