class HLink
{
class _autoinitializer
{
public:
_autoinitializer();
~_autoinitializer();
protected:
HMODULE hModule;
};
friend class _autoinitializer;
public:
HLink();
virtual ~HLink();
void create(int id, HWND parent);
public:
char m_url [256];
HWND m_hwnd;
HFONT m_font;
static _autoinitializer __autoinitializer;
static HCURSOR cursor;
static int WndProc(HWND hwnd, WORD msg, WPARAM wParam, LPARAM lParam);
};
//===========================================================
HLink::_autoinitializer::_autoinitializer() : hModule(NULL)
{
WNDCLASS hc;
hc.style = 0;
hc.lpfnWndProc = (WNDPROC)HLink::WndProc;
hc.cbClsExtra = 0;
hc.cbWndExtra = sizeof(HLink*);
hc.hInstance = NULL;
hc.hIcon = NULL;
hc.hCursor = NULL;
hc.hbrBackground = NULL;
hc.lpszMenuName = NULL;
hc.lpszClassName = WNDCLASSNAME;
RegisterClass(&hc);
HLink::cursor = :

oadCursor(NULL, MAKEINTRESOURCE(32649));
if (HLink::cursor == NULL)
{
TCHAR dir[MAX_PATH];
GetWindowsDirectory(dir ,MAX_PATH);
strcat(dir,"\\winhlp32.exe");
hModule = LoadLibrary(dir);
if (hModule)
HLink::cursor = :

oadCursor(hModule, MAKEINTRESOURCE(106));
}
}
HLink::_autoinitializer::~_autoinitializer()
{
if (hModule != NULL)
FreeLibrary(hModule);
}
HLink::_autoinitializer HLink::__autoinitializer;
HCURSOR HLink::cursor = NULL;
HLink::HLink()
{
}
HLink::~HLink()
{}
void HLink::create(int id, HWND parent)
{
HWND old = ::GetDlgItem(parent, id);
RECT rc;
POINT pos;
GetWindowText(old, m_url, sizeof(m_url));
GetWindowRect(old, &rc);
pos.x = rc.left;
pos.y = rc.top;
ScreenToClient(parent, &pos);
rc.left = pos.x;
rc.top = pos.y;
pos.x = rc.right;
pos.y = rc.bottom;
ScreenToClient(parent, &pos);
rc.right = pos.x;
rc.bottom = pos.y;
m_font = (HFONT)SendMessage(old, WM_GETFONT, 0, 0);
m_hwnd = ::CreateWindow(WNDCLASSNAME, m_url, WS_CHILD | WS_VISIBLE,
rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top,
parent, NULL, NULL, NULL);
SetWindowLong(m_hwnd, GWL_USERDATA, (LONG)this);
DestroyWindow(old);
}
int HLink::WndProc(HWND hwnd, WORD wMsg, WPARAM wParam, LPARAM lParam)
{
HLink *hl = (HLink*) GetWindowLong(hwnd, GWL_USERDATA);
HDC hdc;
PAINTSTRUCT ps;
RECT rect;
SIZE size;
POINT pt;
switch (wMsg)
{
case WM_LBUTTONDOWN:
ShellExecute(NULL, "open", hl->m_url, NULL, NULL, SW_SHOWNORMAL);
break;
case WM_PAINT:
hdc = ::BeginPaint(hwnd, &ps);
GetClientRect(hwnd, &rect);
SelectObject(hdc, hl->m_font);
SetTextColor(hdc, RGB(0,0,255));
SetBkMode(hdc, TRANSPARENT);
DrawText(hdc, hl->m_url, strlen(hl->m_url), &rect, 0);
EndPaint(hwnd, &ps);
break;
case WM_SETCURSOR:
hdc = GetDC(hwnd);
GetTextExtentPoint32(hdc, hl->m_url, strlen(hl->m_url), &size);
ReleaseDC(hwnd, hdc);
GetWindowRect(hwnd, &rect);
rect.right = rect.left + size.cx;
rect.bottom = rect.top + size.cy;
GetCursorPos(&pt);
if (PtInRect(&rect, pt))
SetCursor(HLink::cursor);
break;
default:
DefWindowProc(hwnd, wMsg, wParam, lParam);
}
return TRUE;
}