1
//============================================================================
3
// SSSS tt lll lll XX XX
4
// SS SS tt ll ll XX XX
5
// SS tttttt eeee ll ll aaaa XX XX
6
// SSSS tt ee ee ll ll aa XXX
7
// SS tt eeeeee ll ll aaaaa XX XX
8
// SS SS tt ee ll ll aa aa XX XX
9
// SSSS ttt eeeee llll llll aaaaa XX XX
11
// Copyright (c) 1995-2000 by Jeff Miller
12
// Copyright (c) 2004 by Stephen Anthony
14
// See the file "license" for information on usage and redistribution of
15
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
17
// $Id: HyperLink.cxx,v 1.2 2004/07/15 03:03:27 stephena Exp $
18
//============================================================================
21
#include "HyperLink.hxx"
25
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
26
CHyperLink::CHyperLink()
27
: m_bOverControl(FALSE),
32
m_crLinkColor = RGB( 0, 0, 238); // Blue
33
m_crVisitedColor = RGB( 85, 26, 139); // Purple
34
m_crHoverColor = ::GetSysColor(COLOR_HIGHLIGHT);
39
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
40
CHyperLink::~CHyperLink()
44
DeleteObject( m_hFont );
49
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
50
void CHyperLink::SetURL( LPCTSTR ctszURL )
55
lstrcpy(m_tszURL, ctszURL);
58
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
59
void CHyperLink::PreSubclassWindow( HWND hwnd )
61
GetWindowText( hwnd, m_tszText, MAX_HYPERLINK_TEXT_LEN );
62
m_hFont = (HFONT)::SendMessage(hwnd, WM_GETFONT, 0, 0);
65
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
66
LRESULT CHyperLink::WndProc( HWND hwnd, UINT msg, WPARAM wParam,
67
LPARAM lParam, BOOL& rfHandled )
77
return OnSetCursor(hwnd, LOWORD(lParam), HIWORD(lParam));
81
return OnLButtonUp(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
85
return OnMouseMove(hwnd, wParam, LOWORD(lParam), HIWORD(lParam));
91
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
92
LRESULT CHyperLink::OnPaint( HWND hwnd )
95
HDC hdc = BeginPaint(hwnd, &ps);
97
SelectObject(hdc, m_hFont);
100
SetTextColor(hdc, m_crHoverColor);
102
SetTextColor(hdc, m_crVisitedColor);
104
SetTextColor(hdc, m_crLinkColor);
106
SetBkMode( hdc, TRANSPARENT );
107
TextOut( hdc, 0, 0, m_tszText, lstrlen(m_tszText) );
113
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
114
BOOL CHyperLink::OnSetCursor( HWND hwnd, WORD nHittest, WORD wMouseMsg )
116
UNUSED_ALWAYS( hwnd );
117
UNUSED_ALWAYS( nHittest );
118
UNUSED_ALWAYS( wMouseMsg );
122
SetCursor(m_hLinkCursor);
129
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
130
LRESULT CHyperLink::OnLButtonUp( HWND hwnd, WPARAM fwKeys, WORD xPos, WORD yPos )
132
UNUSED_ALWAYS( fwKeys );
133
UNUSED_ALWAYS( xPos );
134
UNUSED_ALWAYS( yPos );
136
int result = (int)GotoURL(m_tszURL, SW_SHOW);
137
m_bVisited = (result > HINSTANCE_ERROR);
140
MessageBeep(MB_ICONEXCLAMATION);
146
InvalidateRect(hwnd, NULL, FALSE);
152
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
153
LRESULT CHyperLink::OnMouseMove( HWND hwnd, WPARAM fwKeys, WORD xPos, WORD yPos )
155
UNUSED_ALWAYS( fwKeys );
157
// call defwindowproc?
161
GetClientRect(hwnd, &rc);
163
POINT pt = { xPos, yPos };
164
if (!PtInRect(&rc, pt))
166
m_bOverControl = FALSE;
168
RedrawWindow(hwnd, NULL, NULL,
169
RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
174
m_bOverControl = TRUE;
175
RedrawWindow(hwnd, NULL, NULL,
176
RDW_INVALIDATE | RDW_UPDATENOW | RDW_ERASE);
183
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
184
// The following appeared in Paul DiLascia's Jan 1998 MSJ articles.
185
// It loads a "hand" cursor from the winhlp32.exe module
186
void CHyperLink::SetDefaultCursor()
188
if (m_hLinkCursor == NULL) // No cursor handle - load our own
190
// Get the windows directory
191
TCHAR tszWndDir[MAX_PATH + 1];
192
GetWindowsDirectory(tszWndDir, MAX_PATH);
194
lstrcat(tszWndDir, _T("\\winhlp32.exe"));
196
// This retrieves cursor #106 from winhlp32.exe, which is a hand pointer
197
HMODULE hModule = LoadLibrary(tszWndDir);
200
HCURSOR hHandCursor = ::LoadCursor(hModule, MAKEINTRESOURCE(106));
202
m_hLinkCursor = CopyCursor(hHandCursor);
204
FreeLibrary(hModule);
208
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
209
LONG CHyperLink::GetRegKey( HKEY key, LPCTSTR subkey, LPTSTR retdata )
212
LONG retval = RegOpenKeyEx(key, subkey, 0, KEY_QUERY_VALUE, &hkey);
214
if (retval == ERROR_SUCCESS)
216
long datasize = MAX_PATH;
217
TCHAR data[MAX_PATH];
218
RegQueryValue(hkey, NULL, data, &datasize);
219
lstrcpy(retdata,data);
226
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
227
void CHyperLink::ReportError( int nError )
229
TCHAR tsz[MAX_HYPERLINK_TEXT_LEN + 1];
234
lstrcpy(tsz, _T("The operating system is out\nof memory or resources."));
238
lstrcpy(tsz, _T("The specified path was not found."));
242
lstrcpy(tsz, _T("The specified file was not found."));
245
case ERROR_BAD_FORMAT:
246
lstrcpy(tsz, _T("The .EXE file is invalid\n(non-Win32 .EXE or error in .EXE image)."));
249
case SE_ERR_ACCESSDENIED:
250
lstrcpy(tsz, _T("The operating system denied\naccess to the specified file."));
253
case SE_ERR_ASSOCINCOMPLETE:
254
lstrcpy(tsz,_T("The filename association is\nincomplete or invalid."));
258
lstrcpy(tsz, _T("The DDE transaction could not\nbe completed because other DDE transactions\nwere being processed."));
262
lstrcpy(tsz, _T("The DDE transaction failed."));
265
case SE_ERR_DDETIMEOUT:
266
lstrcpy(tsz, _T("The DDE transaction could not\nbe completed because the request timed out."));
269
case SE_ERR_DLLNOTFOUND:
270
lstrcpy(tsz, _T("The specified dynamic-link library was not found."));
274
lstrcpy(tsz, __T("There is no application associated\nwith the given filename extension."));
278
lstrcpy(tsz, _T("There was not enough memory to complete the operation."));
282
lstrcpy(tsz, _T("A sharing violation occurred."));
286
wsprintf(tsz, _T("Unknown error %d occurred."), nError);
290
TCHAR tszCaption[MAX_HYPERLINK_TEXT_LEN + 1];
291
lstrcpy(tszCaption, _T("Unable to open hyperlink"));
293
MessageBox(NULL, tsz, tszCaption, MB_ICONEXCLAMATION | MB_OK);
296
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
297
HINSTANCE CHyperLink::GotoURL( LPCTSTR url, int showcmd )
299
TCHAR key[MAX_PATH + MAX_PATH];
301
// First try ShellExecute()
302
HINSTANCE result = ShellExecute(NULL, _T("open"), url, NULL,NULL, showcmd);
304
// If it failed, get the .htm regkey and lookup the program
305
if ((UINT)result <= HINSTANCE_ERROR)
307
if (GetRegKey(HKEY_CLASSES_ROOT, _T(".htm"), key) == ERROR_SUCCESS)
309
lstrcat(key, _T("\\shell\\open\\command"));
311
if (GetRegKey(HKEY_CLASSES_ROOT,key,key) == ERROR_SUCCESS)
314
pos = _tcsstr(key, _T("\"%1\""));
317
pos = strstr(key, _T("%1")); // Check for %1, without quotes
318
if (pos == NULL) // No parameter at all...
319
pos = key+lstrlen(key)-1;
321
*pos = '\0'; // Remove the parameter
324
*pos = '\0'; // Remove the parameter
326
lstrcat(pos, _T(" "));
328
result = (HINSTANCE) WinExec(key,showcmd);