Man kunne forstille sig noget i stil med:
#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, 290, 50}};
HWND LinkHwnd[NUM_LINK];
typedef enum
{
NormalState,
HoverState,
ActiveState
}LinkStateType;
LinkStateType LinkState[NUM_LINK] = {NormalState, NormalState};
const char * const LinkText[NUM_LINK] =
{
"http://www.udvikleren.dk",
"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)
{
SendMessage(LinkHwnd[idx], WM_SETFONT, (WPARAM )HoverFont, 1);
LinkState[idx] = HoverState;
}
}
else
{
if(LinkState[idx] != NormalState)
{
SendMessage(LinkHwnd[idx], WM_SETFONT, (WPARAM )NormalFont, 1);
LinkState[idx] = NormalState;
}
}
}
}
LRESULT CALLBACK DialogProc(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_CREATE:
{
int idx;
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");
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;
POINT P;
P.x = LOWORD(lParam);
P.y = HIWORD(lParam);
HandleMouse(P);
break;
}
case WM_TIMER:
{
POINT P;
GetCursorPos(&P);
ScreenToClient(hwndDlg, &P);
HandleMouse(P);
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_MINIMIZEBOX | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | WS_MAXIMIZEBOX | WS_CAPTION | WS_BORDER | WS_SYSMENU,
100, 100, 300, 100,
NULL,
NULL,
InstanceHandle,
0);
MSG Msg;
while(GetMessage(&Msg, WindowHandle, 0, 0xFFFF) > 0)
{
if(!IsDialogMessage(WindowHandle, &Msg))
{
TranslateMessage(&Msg);
DispatchMessage(&Msg);
}
}
return 0;
}
[Redigeret d. 15/11-04 00:39:25 af Bertel Brander]