1 #include "stdafx.h"
2 #include "vba.h"
3 #include "Hyperlink.h"
4
5 #ifdef _DEBUG
6 #define new DEBUG_NEW
7 #undef THIS_FILE
8 static char THIS_FILE[] = __FILE__;
9 #endif
10
11 /////////////////////////////////////////////////////////////////////////////
12 // Hyperlink
13
Hyperlink()14 Hyperlink::Hyperlink()
15 {
16 m_over = false;
17 }
18
~Hyperlink()19 Hyperlink::~Hyperlink()
20 {
21 m_underlineFont.DeleteObject();
22 }
23
24
BEGIN_MESSAGE_MAP(Hyperlink,CStatic)25 BEGIN_MESSAGE_MAP(Hyperlink, CStatic)
26 //{{AFX_MSG_MAP(Hyperlink)
27 ON_WM_CTLCOLOR_REFLECT()
28 ON_WM_ERASEBKGND()
29 ON_WM_MOUSEMOVE()
30 //}}AFX_MSG_MAP
31 ON_CONTROL_REFLECT(STN_CLICKED, OnClicked)
32 END_MESSAGE_MAP()
33
34 /////////////////////////////////////////////////////////////////////////////
35 // Hyperlink message handlers
36
37 void Hyperlink::PreSubclassWindow()
38 {
39 DWORD dwStyle = GetStyle();
40 ::SetWindowLong(GetSafeHwnd(), GWL_STYLE, dwStyle | SS_NOTIFY);
41
42 // 32649 is the hand cursor
43 m_cursor = LoadCursor(NULL, MAKEINTRESOURCE(32649));
44
45 CFont *font = GetFont();
46
47 LOGFONT lg;
48 font->GetLogFont(&lg);
49
50 lg.lfUnderline = TRUE;
51
52 m_underlineFont.CreateFontIndirect(&lg);
53 SetFont(&m_underlineFont);
54
55 CStatic::PreSubclassWindow();
56 }
57
OnClicked()58 void Hyperlink::OnClicked()
59 {
60 CString url;
61 GetWindowText(url);
62 ::ShellExecute(0, _T("open"), url,
63 0, 0, SW_SHOWNORMAL);
64 }
65
CtlColor(CDC * pDC,UINT nCtlColor)66 HBRUSH Hyperlink::CtlColor(CDC* pDC, UINT nCtlColor)
67 {
68 pDC->SetTextColor(RGB(0,0,240));
69
70 return (HBRUSH)GetStockObject(NULL_BRUSH);
71 }
72
OnEraseBkgnd(CDC * pDC)73 BOOL Hyperlink::OnEraseBkgnd(CDC* pDC)
74 {
75 CRect rect;
76 GetClientRect(rect);
77 pDC->FillSolidRect(rect, ::GetSysColor(COLOR_3DFACE));
78
79 return TRUE;
80 }
81
OnMouseMove(UINT nFlags,CPoint point)82 void Hyperlink::OnMouseMove(UINT nFlags, CPoint point)
83 {
84 if(!m_over) {
85 m_over = true;
86 SetCapture();
87 ::SetCursor(m_cursor);
88 } else {
89 CRect r;
90 GetClientRect(&r);
91
92 if(!r.PtInRect(point)) {
93 m_over = false;
94 ReleaseCapture();
95 }
96 }
97 }
98