/* The original version of this program can be found at http://damb.dk */
#include <windows.h>
#define IDC_LINK1 1200
#define IDC_LINK2 1201
#define IDT_TIMER1 1300
#define NUM_LINK 2
HINSTANCE InstanceHandle;
HFONT NormalFont;
HFONT HoverFont;
HFONT ActiveFont;
RECT LinkRect[NUM_LINK] = {{10, 10, 290, 20}, {10, 30, 310, 50}};
HWND LinkHwnd[NUM_LINK];
typedef enum
{
NormalState,
HoverState,
ActiveState
}LinkStateType;
LinkStateType LinkState[NUM_LINK] = {NormalState, NormalState};
HBRUSH BackBrush;
const char * const LinkText[NUM_LINK] =
{
"http://www.google.com",
"http://home20.inet.tele.dk/midgaard/sample.html"
};
void HandleMouse(POINT P)
{
int idx;
for(idx = 0; idx < NUM_LINK; idx++)
{
if(PtInRect(&LinkRect[idx], P))
{
if(LinkState[idx] != HoverState)
{
LinkState[idx] = HoverState;
SendMessage(LinkHwnd[idx], WM_SETFONT, (WPARAM )HoverFont, 1);
}
}
else
{
if(LinkState[idx] != NormalState)
{
LinkState[idx] = NormalState;
SendMessage(LinkHwnd[idx], WM_SETFONT, (WPARAM )NormalFont, 1);
}
}
}
}
LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
POINT P;
int idx;
switch(msg)
{
case WM_CREATE:
NormalFont = CreateFont(16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, "Arial");
HoverFont = CreateFont(16, 0, 0, 0, 0, 0, TRUE, 0, 0, 0, 0, 0, 0, "Arial");
ActiveFont = CreateFont(16, 0, 0, 0, FW_BOLD, 0, TRUE, 0, 0, 0, 0, 0, 0, "Arial");
BackBrush = CreateSolidBrush(GetSysColor(COLOR_BTNFACE));
for(idx = 0; idx < NUM_LINK; idx++)
{
LinkHwnd[idx] = CreateWindow("STATIC",
LinkText[idx],
WS_CHILD | WS_VISIBLE | SS_LEFT,
LinkRect[idx].left, LinkRect[idx].top, LinkRect[idx].right, LinkRect[idx].bottom,
hwndDlg,
(HMENU)(IDC_LINK1 + idx),
InstanceHandle,
0);
SendMessage(LinkHwnd[idx], WM_SETFONT, (WPARAM )NormalFont, 0);
}
SetTimer(hwndDlg, IDT_TIMER1, 1000, 0);
break;
case WM_MOUSEMOVE:
if(wParam & MK_LBUTTON)
break;
P.x = LOWORD(lParam);
P.y = HIWORD(lParam);
HandleMouse(P);
break;
case WM_TIMER:
GetCursorPos(&P);
ScreenToClient(hwndDlg, &P);
HandleMouse(P);
break;
case WM_CTLCOLORSTATIC:
for(idx = 0; idx < NUM_LINK; idx++)
{
if((HWND )lParam == LinkHwnd[idx])
{
if(LinkState[idx] != NormalState)
SetTextColor((HDC )wParam, RGB(255, 0, 0));
else
SetTextColor((HDC )wParam, RGB(0, 0, 0));
SetBkMode((HDC )wParam, TRANSPARENT);
return (LRESULT )BackBrush;
}
}
break;
case WM_LBUTTONDOWN:
POINT P;
int idx;
P.x = LOWORD(lParam);
P.y = HIWORD(lParam);
for(idx = 0; idx < NUM_LINK; idx++)
{
if(PtInRect(&LinkRect[idx], P))
{
LinkState[idx] = ActiveState;
SendMessage(LinkHwnd[idx], WM_SETFONT, (WPARAM )ActiveFont, 1);
ShellExecute(hwndDlg, "Open", LinkText[idx], 0, 0, SW_SHOW);
}
}
break;
}
return DefWindowProc(hwndDlg, msg, wParam, lParam);
}
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR lpCmdLine, INT nCmdShow)
{
WNDCLASS wc;
InstanceHandle = hInstance;
memset(&wc, 0, sizeof(WNDCLASS));
wc.style = CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS;
wc.lpfnWndProc = DialogProc;
wc.hInstance = InstanceHandle;
wc.hbrBackground = (HBRUSH )(COLOR_BTNFACE + 1);
wc.lpszClassName = "WhateverClass";
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
if(!RegisterClass(&wc))
return FALSE;
HWND WindowHandle = CreateWindow("WhateverClass",
"Whatever",
WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_CAPTION | WS_BORDER | WS_SYSMENU,
100, 100, 330, 100,
NULL,
NULL,
InstanceHandle,
0);
MSG Msg;
while(GetMessage(&Msg, WindowHandle, 0, 0xFFFF) > 0)
{
if(!IsDialogMessage(WindowHandle, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return 0;
}