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

📄 hyperlink.cpp

📁 本程序提供了一种编写定时提醒功能的例子。
💻 CPP
字号:
// HyperLink.cpp : implementation file

#include "stdafx.h"
#include "HyperLink.h"
#include "resource.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TOOLTIP_ID 1

/////////////////////////////////////////////////////////////////////////////
// CHyperLink

CHyperLink::CHyperLink()
{
	m_hLinkCursor = (HCURSOR) AfxGetApp()->LoadCursor(IDC_CURSOR_HAND);
	m_crLinkColour = RGB(0, 0, 238);
	m_crHoverColour = RGB(255, 0, 255);
	m_bOverControl = FALSE;
}

CHyperLink::~CHyperLink()
{
	m_Font.DeleteObject();
}

BEGIN_MESSAGE_MAP(CHyperLink, CStatic)
	//{{AFX_MSG_MAP(CHyperLink)
	ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
	ON_WM_CTLCOLOR_REFLECT()
	ON_WM_SETCURSOR()
	ON_WM_MOUSEMOVE()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CHyperLink message handlers

void CHyperLink::OnClicked()
{
	CString strURL, strMailAddress;

	// 得到邮件地址, CStatic Control Caption
	GetWindowText(strMailAddress);
	// 装配成 URL 地址
	strURL.Format("mailto:%s", (LPCTSTR) strMailAddress);

	// 调用 ShellExecute() 执行邮件发送
	int iRet = (int) ShellExecute(NULL, _T("open"), (LPCTSTR) strURL, NULL,
						NULL, SW_SHOW);
	if (iRet <= HINSTANCE_ERROR)
		AfxMessageBox(IDC_MAIL_LINK, MB_OK | MB_ICONEXCLAMATION);
}

HBRUSH CHyperLink::CtlColor(CDC* pDC, UINT nCtlColor)
{
	ASSERT(nCtlColor == CTLCOLOR_STATIC);

	if (m_bOverControl)
		pDC->SetTextColor(m_crHoverColour);
	else
		pDC->SetTextColor(m_crLinkColour);

	pDC->SetBkMode(TRANSPARENT);

	return (HBRUSH) GetStockObject(NULL_BRUSH);
}

void CHyperLink::OnMouseMove(UINT nFlags, CPoint point)
{
	CStatic::OnMouseMove(nFlags, point);

	if (m_bOverControl)
	{
		CRect rc;
		GetClientRect(&rc);

		if (!rc.PtInRect(point))
		{
			m_bOverControl = FALSE;
			ReleaseCapture();
			RedrawWindow();
			return;
		}
	}
	else
	{
		m_bOverControl = TRUE;
		RedrawWindow();
		SetCapture();
	}
}

BOOL CHyperLink::OnSetCursor(CWnd* /*pWnd*/, UINT /*nHitTest*/,
	UINT /*message*/)
{
	::SetCursor(m_hLinkCursor);
	return TRUE;
}

void CHyperLink::PreSubclassWindow()
{
	// 要求得到 STN_CLICKED 通知消息
	DWORD dwStyle = GetStyle();
	::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);

	// 设置字体下划线
	LOGFONT lf;
	GetFont()->GetLogFont(&lf);
	lf.lfUnderline = TRUE;
	m_Font.CreateFontIndirect(&lf);
	SetFont(&m_Font);

	CStatic::PreSubclassWindow();
}
void CHyperLink::SetURL(CString strURL)
{
	//	m_strURL = strURL;

	if (::IsWindow(GetSafeHwnd()))
	{
		ShowWindow(SW_HIDE);
		//		AdjustWindow();
		m_ToolTip.UpdateTipText(strURL, this, TOOLTIP_ID);
		ShowWindow(SW_SHOW);
	}
}

⌨️ 快捷键说明

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