// XHyperLink.cpp Version 1.0
//
// XHyperLink static control. Will open the default browser with the given URL
// when the user clicks on the link.
//
// Copyright (C) 1997 - 1999 Chris Maunder
// All rights reserved. May not be sold for profit.
//
// Thanks to P�l K. T�nder for auto-size and window caption changes.
//
// "GotoURL" function by Stuart Patterson
// As seen in the August, 1997 Windows Developer's Journal.
// Copyright 1997 by Miller Freeman, Inc. All rights reserved.
// Modified by Chris Maunder to use TCHARs instead of chars.
//
// "Default hand cursor" from Paul DiLascia's Jan 1998 MSJ article.
//
// 2/29/00 -- P. Shaffer standard font mod.
//
///////////////////////////////////////////////////////////////////////////////
//
// Modified by: Hans Dietrich
// hdietrich2@hotmail.com
//
///////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "XHyperLink.h"
#include "atlconv.h" // for Unicode conversion
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#define TOOLTIP_ID 1
// Uncomment following line to enable error message box for URL navigation
//#define XHYPERLINK_REPORT_ERROR
#ifndef IDC_HAND
#define IDC_HAND MAKEINTRESOURCE(32649) // From WINUSER.H
#endif
// sends message to parent when hyperlink is clicked (see SetNotifyParent())
UINT WM_XHYPERLINK_CLICKED = ::RegisterWindowMessage(_T("WM_XHYPERLINK_CLICKED"));
///////////////////////////////////////////////////////////////////////////////
// CXHyperLink
BEGIN_MESSAGE_MAP(CXHyperLink, CStatic)
//{{AFX_MSG_MAP(CXHyperLink)
ON_WM_CTLCOLOR_REFLECT()
ON_WM_SETCURSOR()
ON_WM_MOUSEMOVE()
ON_WM_TIMER()
ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
ON_WM_ERASEBKGND()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
///////////////////////////////////////////////////////////////////////////////
// ctor
CXHyperLink::CXHyperLink()
{
m_hLinkCursor = NULL; // No cursor as yet
m_crLinkColour = RGB(0,0,238); // Blue
m_crVisitedColour = RGB(85,26,139); // Purple
m_crHoverColour = RGB(255,0,0); // Red
m_bOverControl = FALSE; // Cursor not yet over control
m_bVisited = FALSE; // Hasn't been visited yet.
m_nUnderline = ulHover; // Underline the link?
m_bAdjustToFit = TRUE; // Resize the window to fit the text?
m_strURL = _T("");
m_nTimerID = 100;
m_bNotifyParent = FALSE; // TRUE = notify parent
m_bIsURLEnabled = TRUE; // TRUE = navigate to url
m_bToolTip = TRUE; // TRUE = display tooltip
m_crBackground = (UINT) -1; // set to default (no bg color)
m_bAlwaysOpenNew = FALSE; // TRUE = always open new browser window
}
///////////////////////////////////////////////////////////////////////////////
// dtor
CXHyperLink::~CXHyperLink()
{
TRACE(_T("in CXHyperLink::~CXHyperLink\n"));
if (m_hLinkCursor)
DestroyCursor(m_hLinkCursor);
m_hLinkCursor = NULL;
m_UnderlineFont.DeleteObject();
if (m_Brush.GetSafeHandle())
m_Brush.DeleteObject();
}
/////////////////////////////////////////////////////////////////////////////
// CXHyperLink overrides
///////////////////////////////////////////////////////////////////////////////
// DestroyWindow
BOOL CXHyperLink::DestroyWindow()
{
KillTimer(m_nTimerID);
return CStatic::DestroyWindow();
}
///////////////////////////////////////////////////////////////////////////////
// PreTranslateMessage
BOOL CXHyperLink::PreTranslateMessage(MSG* pMsg)
{
m_ToolTip.RelayEvent(pMsg);
return CStatic::PreTranslateMessage(pMsg);
}
///////////////////////////////////////////////////////////////////////////////
// PreSubclassWindow
void CXHyperLink::PreSubclassWindow()
{
// We want to get mouse clicks via STN_CLICKED
DWORD dwStyle = GetStyle();
::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
// Set the URL as the window text
if (m_strURL.IsEmpty())
GetWindowText(m_strURL);
// Check that the window text isn't empty. If it is, set it as the URL.
CString strWndText;
GetWindowText(strWndText);
if (strWndText.IsEmpty())
{
ASSERT(!m_strURL.IsEmpty()); // Window and URL both NULL. DUH!
SetWindowText(m_strURL);
}
CFont* pFont = GetFont();
if (!pFont)
{
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
if (hFont == NULL)
hFont = (HFONT) GetStockObject(ANSI_VAR_FONT);
if (hFont)
pFont = CFont::FromHandle(hFont);
}
ASSERT(pFont->GetSafeHandle());
// Create the underline font
LOGFONT lf;
pFont->GetLogFont(&lf);
m_StdFont.CreateFontIndirect(&lf);
lf.lfUnderline = (BYTE) TRUE;
m_UnderlineFont.CreateFontIndirect(&lf);
PositionWindow(); // Adjust size of window to fit URL if necessary
SetDefaultCursor(); // Try and load up a "hand" cursor
SetUnderline();
// Create the tooltip
if (m_bToolTip)
{
CRect rect;
GetClientRect(rect);
m_ToolTip.Create(this);
m_ToolTip.AddTool(this, m_strURL, rect, TOOLTIP_ID);
}
CStatic::PreSubclassWindow();
}
/////////////////////////////////////////////////////////////////////////////
// CXHyperLink message handlers
///////////////////////////////////////////////////////////////////////////////
// OnClicked
void CXHyperLink::OnClicked()
{
m_bOverControl = FALSE;
int result = HINSTANCE_ERROR + 1;
if (m_bIsURLEnabled)
result = (int)GotoURL(m_strURL, SW_SHOW, m_bAlwaysOpenNew);
m_bVisited = (result > HINSTANCE_ERROR);
if (!m_bVisited)
{
MessageBeep(MB_ICONEXCLAMATION); // Unable to follow link
ReportError(result);
}
else
SetVisited(); // Repaint to show visited colour
NotifyParent();
}
///////////////////////////////////////////////////////////////////////////////
// CtlColor
#ifdef _DEBUG
HBRUSH CXHyperLink::CtlColor(CDC* pDC, UINT nCtlColor)
#else
HBRUSH CXHyperLink::CtlColor(CDC* pDC, UINT /*nCtlColor*/)
#endif
{
ASSERT(nCtlColor == CTLCOLOR_STATIC);
if (m_bOverControl)
pDC->SetTextColor(m_crHoverColour);
else if (m_bVisited)
pDC->SetTextColor(m_crVisitedColour);
else
pDC->SetTextColor(m_crLinkColour);
// transparent text.
pDC->SetBkMode(TRANSPARENT);
if (m_Brush.GetSafeHandle())
{
pDC->SetBkColor(m_crBackground);
return (HBRUSH) m_Brush;
}
else
{
return (HBRUSH)GetStockObject(NULL_BRUSH);
}
}
///////////////////////////////////////////////////////////////////////////////
// OnMouseMove
void CXHyperLink::OnMouseMove(UINT nFlags, CPoint point)
{
if (!m_bOverControl) // Cursor has just moved over control
{
m_bOverControl = TRUE;
if (m_nUnderline == ulHover)
SetFont(&m_UnderlineFont);
Invalidate();
SetTimer(m_nTimerID, 100, NULL);
}
CStatic::OnMouseMove(nFlags, point);
#if 0 // -----------------------------------------------------------
if (m_bOverControl != FALSE)
{
CRect rect;
GetClientRect(&rect);
if (rect.PtInRect(point) == FALSE)
{
m_bOverControl = FALSE;
if (m_nUnderline == ulHover)
SetFont(&m_StdFont);
Invalidate();
ReleaseCapture();
}
}
else
{
m_bOverControl = TRUE;
if (m_nUnderline == ulHover)
SetFont(&m_UnderlineFont);
Invalidate();
SetCapture();
}
CStatic::OnMouseMove(nFlags, point);
#endif
}
///////////////////////////////////////////////////////////////////////////////
// OnTimer
void CXHyperLink::OnTimer(UINT nIDEvent)
{
CPoint p(GetMessagePos());
ScreenToClient(&p);
CRect rect;
GetClientRect(rect);
if (!rect.PtInRect(p))
{
m_bOverControl = FALSE;
KillTimer(m_nTimerID);
if (m_nUnderline != ulAlways)
SetFont(&m_StdFont);
rect.bottom+=10;
InvalidateRect(rect);
}
CStatic::OnTimer(nIDEvent);
}
///////////////////////////////////////////////////////////////////////////////
// OnSetCursor
BOOL CXHyperLink::OnSetCursor(CWn
没有合适的资源?快使用搜索试试~ 我知道了~
一个字体,大小,颜色可定义的自绘静态框控件-XColorStatic 类
共30个文件
h:8个
cpp:7个
bmp:2个
4星 · 超过85%的资源 需积分: 10 42 下载量 124 浏览量
2017-07-14
15:15:46
上传
评论
收藏 835KB RAR 举报
温馨提示
XColor Static是一个简单的基于静态框的控件,它提供字体更改,文本和背景颜色以及图标显示。 http://blog.csdn.net/greless/article/details/75090417
资源推荐
资源详情
资源评论
收起资源包目录
XColorStatic_demo.rar (30个子文件)
XColorStatic_demo
FontSize.cpp 1KB
.vs
XColorStaticTest
v14
.suo 51KB
hans.ico 766B
sherlock.ico 766B
XColorStaticTestDlg.h 1KB
XColorStaticTest.cpp 1KB
XColorStatic.cpp 7KB
XColorStaticTest.h 1KB
About.cpp 732B
1.bmp 1.37MB
XColorStaticTest.sln 1KB
About.h 725B
XColorStatic.h 2KB
XColorStaticTest.dsp 7KB
XColorStaticTest.rc 6KB
FontSize.h 602B
XHyperLink.h 5KB
StdAfx.cpp 218B
resource.h 1KB
StdAfx.h 757B
XHyperLink.cpp 18KB
XColorStaticTest.vcxproj 15KB
UpgradeLog.htm 34KB
Debug
1.bmp 1.37MB
XColorStaticTest.exe 149KB
XColorStaticTest.exe 36KB
XColorStaticTest.vcxproj.filters 3KB
XColorStaticTest.dsw 557B
XColorStaticTestDlg.cpp 6KB
XColorStaticTest.aps 42KB
共 30 条
- 1
资源评论
- laplaya2019-06-10感觉还行,感谢!
Greless
- 粉丝: 330
- 资源: 67
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功