forked from ImpulseAdventure/JPEGsnoop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HyperlinkStatic.cpp
182 lines (157 loc) · 4.99 KB
/
HyperlinkStatic.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
// JPEGsnoop - JPEG Image Decoder & Analysis Utility
// Copyright (C) 2017 - Calvin Hass
// http://www.impulseadventure.com/photo/jpeg-snoop.html
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// ====================================================================================================
// SOURCE CODE ACKNOWLEDGEMENT
// ====================================================================================================
// The following code is derived from the following project on CodeGuru:
//
// Title: HyperlinkStatic
// Author: Franz Wong
// URL: http://www.codeguru.com/cpp/controls/staticctrl/article.php/c5801
// Date: Jan 14, 2003
//
// ====================================================================================================
// HyperlinkStatic.cpp : implementation file
//
#include "stdafx.h"
#include "HyperlinkStatic.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//CAL! Added the following as otherwise we need
// to set WINVER >= 0x0500
#define IDC_HAND MAKEINTRESOURCE(32649)
/////////////////////////////////////////////////////////////////////////////
// CHyperlinkStatic
CHyperlinkStatic::CHyperlinkStatic()
{
_strCaption = _strHyperlink = _T("");
_bMouseInControl = _bCreateFont = _bGetCaptionSize = false;
_hHandCursor = ::LoadCursor(0, IDC_HAND);
_hArrowCursor = ::LoadCursor(0, IDC_ARROW);
}
CHyperlinkStatic::~CHyperlinkStatic()
{
}
BEGIN_MESSAGE_MAP(CHyperlinkStatic, CStatic)
//{{AFX_MSG_MAP(CHyperlinkStatic)
ON_WM_LBUTTONDOWN()
ON_WM_PAINT()
ON_WM_DESTROY()
ON_WM_MOUSEMOVE()
//}}AFX_MSG_MAP
ON_MESSAGE(WM_MOUSELEAVE, OnMouseLeave)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CHyperlinkStatic message handlers
void CHyperlinkStatic::SetHyperlink(CString strHyperlink)
{
_strHyperlink = strHyperlink;
}
void CHyperlinkStatic::SetCaption(CString strCaption)
{
_strCaption = strCaption;
_bGetCaptionSize = false;
}
void CHyperlinkStatic::OnLButtonDown(UINT nFlags, CPoint point)
{
if ( _bGetCaptionSize == false )
GetCaptionSize();
if (InCaptionRange(point))
ShellExecute(0, _T("open"), _strHyperlink, 0, 0, SW_SHOWNORMAL);
CStatic::OnLButtonDown(nFlags, point);
}
void CHyperlinkStatic::OnPaint()
{
if ( _bCreateFont == false )
CreateFont();
CPaintDC dc(this);
CFont *pOldFont = (CFont*)dc.SelectObject(&_fontCaption);
dc.SetBkMode(TRANSPARENT);
dc.SetTextColor(RGB(0,0,255));
dc.TextOut(0, 0, _strCaption);
dc.SelectObject(pOldFont);
}
void CHyperlinkStatic::OnDestroy()
{
CStatic::OnDestroy();
_fontCaption.DeleteObject();
}
void CHyperlinkStatic::PreSubclassWindow()
{
ModifyStyle(0, SS_NOTIFY, TRUE);
GetWindowText(_strCaption);
_bGetCaptionSize = false;
CStatic::PreSubclassWindow();
}
LRESULT CHyperlinkStatic::OnMouseLeave(WPARAM wParam, LPARAM lParam)
{
lParam; // Unreferenced param
wParam; // Unreferenced param
_bMouseInControl = false;
::SetCursor(_hArrowCursor);
return 0;
}
void CHyperlinkStatic::OnMouseMove(UINT nFlags, CPoint point)
{
if ( _bMouseInControl == false ) {
//Track the mouse leave event
TRACKMOUSEEVENT tme;
tme.cbSize = sizeof(tme);
tme.hwndTrack = GetSafeHwnd();
tme.dwFlags = TME_LEAVE;
_TrackMouseEvent(&tme);
_bMouseInControl = true;
}
else {
if ( _bGetCaptionSize == false )
GetCaptionSize();
::SetCursor((InCaptionRange(point))?_hHandCursor:_hArrowCursor);
}
CStatic::OnMouseMove(nFlags, point);
}
void CHyperlinkStatic::CreateFont()
{
CFont* pFontParent = GetParent()->GetFont();
if ( pFontParent ) {
LOGFONT lf;
pFontParent->GetObject(sizeof(lf), &lf);
lf.lfUnderline = TRUE;
_fontCaption.CreateFontIndirect(&lf);
_bCreateFont = true;
}
}
void CHyperlinkStatic::GetCaptionSize()
{
if (( _bGetCaptionSize == false ) && ( _bCreateFont )) {
CClientDC dc(this);
CFont *pOldFont = dc.SelectObject(&_fontCaption);
_sizeCaption = dc.GetTextExtent(_strCaption);
dc.SelectObject(pOldFont);
_bGetCaptionSize = true;
}
}
bool CHyperlinkStatic::InCaptionRange(CPoint &point)
{
if ( _bGetCaptionSize == false )
return false;
return (( point.x >= 0 )&&( point.x < _sizeCaption.cx ) &&
( point.y >= 0 )&&( point.y < _sizeCaption.cy ));
}