⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 statlink.cpp

📁 这是一个学生信息管理系统
💻 CPP
字号:

#include "StdAfx.h"
#include "StatLink.h"

COLORREF CStaticLink::g_colorUnvisited  = RGB(0,0,255);		 // blue
COLORREF CStaticLink::g_colorVisited    = RGB(128,0,128);	 // purple
COLORREF CStaticLink::g_colorOver		= RGB(255,0,0);	     // Red

HCURSOR	CStaticLink::g_hCursorLink = NULL;

IMPLEMENT_DYNAMIC(CStaticLink, CStatic)

BEGIN_MESSAGE_MAP(CStaticLink, CStatic)
	ON_WM_CTLCOLOR_REFLECT()
	ON_WM_LBUTTONDOWN()
	ON_WM_SETCURSOR()
	ON_WM_TIMER()
	ON_WM_NCHITTEST()
END_MESSAGE_MAP()


CStaticLink::CStaticLink(LPCTSTR lpText, BOOL bDeleteOnDestroy)
{
	m_link = lpText;								// link text (NULL ==> window text)
	m_color = g_colorUnvisited;				// not visited yet
	m_bDeleteOnDestroy = bDeleteOnDestroy;	// delete object with window?
    m_bOverControl     = FALSE;                // Cursor not yet over control
    m_nTimerID         = 1;
}


HBRUSH CStaticLink::CtlColor(CDC* pDC, UINT nCtlColor)
{
	ASSERT(nCtlColor == CTLCOLOR_STATIC);
	DWORD dwStyle = GetStyle();
	
	HBRUSH hbr = NULL;
	if ((dwStyle & 0xFF) <= SS_RIGHT) {
		// this is a text control: set up font and colors
		if (!(HFONT)m_font) {
			// first time init: create font
			LOGFONT lf;
			GetFont()->GetObject(sizeof(lf), &lf);
//			lf.lfUnderline = TRUE;
			m_font.CreateFontIndirect(&lf);
		}

		// use underline font and visited/unvisited colors
		pDC->SelectObject(&m_font);
		pDC->SetTextColor(m_color);
		pDC->SetBkMode(TRANSPARENT);

		// return hollow brush to preserve parent background color
		hbr = (HBRUSH)::GetStockObject(HOLLOW_BRUSH);

	}
	return hbr;
}

/////////////////
// Handle mouse click: navigate link
//
void CStaticLink::OnLButtonDown(UINT nFlags, CPoint point)
{
	if (m_link.IsEmpty()) {
		// no link: try to load from resource string or window text 
		m_link.LoadString(GetDlgCtrlID()) || (GetWindowText(m_link),1);
		if (m_link.IsEmpty())
			return;
	}

	// Call ShellExecute to run the file.
	// For an URL, this means opening it in the browser.
	//
	HINSTANCE h = m_link.Navigate();
	if ((UINT)h > 32) {						 // success!
		m_color = g_colorVisited;			 // change color
		Invalidate();						 // repaint 
	} else {
		MessageBeep(0);		// unable to execute file!
		TRACE(_T("*** WARNING: CStaticLink: unable to navigate link %s\n"),
			(LPCTSTR)m_link);
	}
}

void CStaticLink::OnTimer(UINT nIDEvent) 
{
    CPoint p(GetMessagePos());
    ScreenToClient(&p);

	HBRUSH hbr = NULL;
    CRect rect;
    GetClientRect(rect);
    if (!rect.PtInRect(p))
    {
        m_bOverControl = FALSE;
	    KillTimer(m_nTimerID);
		m_color = g_colorUnvisited;	// change color
		Invalidate();			// repaint 
        rect.bottom+=10;
        InvalidateRect(rect);
	}
	CStatic::OnTimer(nIDEvent);
}


BOOL CStaticLink::OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message)
{
	if(g_hCursorLink==NULL)
	{
		BOOL bTriedOnce=FALSE;
		if(!bTriedOnce)
		{
			g_hCursorLink =AfxGetApp()->LoadCursor(IDC_CURSOR1);
		    bTriedOnce = TRUE;
		}
	}
	if (g_hCursorLink) {
		::SetCursor(g_hCursorLink);
		return TRUE;
	}
	return FALSE;
}

void CStaticLink::PostNcDestroy()
{
	if (m_bDeleteOnDestroy)
		delete this;
}


LRESULT CStaticLink::OnNcHitTest(CPoint point)
{
	// TODO: 在此添加消息处理程序代码和/或调用默认值
	if (!m_bOverControl)        // Cursor has just moved over control
	{
		m_bOverControl = TRUE;
		m_color = g_colorOver;	// change color
		Invalidate();			// repaint 

		SetTimer(m_nTimerID, 100, NULL);
	}
//	return CStatic::OnNcHitTest(point);
	return HTCLIENT;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -