I'm trying to add a clickable URL on my window. I'm using the Win32 API, C++, and Visual Studio.
When I try the example from Microsoft, the link appears as plain text, with the <a> tags.
They put the Hyperlink in the title bar, but they use WS_CHILD, which hides it. So I used WS_CAPTION to show it.
What am I missing? Is it supposed to work only in dialogs?
Here are the related code parts:
wWinMain():
INITCOMMONCONTROLSEX icex;
icex.dwSize = sizeof(INITCOMMONCONTROLSEX);
icex.dwICC = ICC_LINK_CLASS;
InitCommonControlsEx(&icex);
MyRegisterClass2():
WNDCLASSEXW wcex;
wcex.cbSize = sizeof(WNDCLASSEX);
wcex.style = CS_HREDRAW | CS_VREDRAW;
wcex.lpfnWndProc = WndProc2;
wcex.cbClsExtra = 0;
wcex.cbWndExtra = 0;
wcex.hInstance = hInstance;
wcex.hIcon = NULL;
wcex.hCursor = LoadCursor(nullptr, IDC_ARROW);
wcex.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
wcex.lpszMenuName = NULL;
wcex.lpszClassName = WC_LINK;
wcex.hIconSm = NULL;
return RegisterClassExW(&wcex);
InitInstance():
hWndMain = CreateWindowW(
szWindowClass,
szTitle,
WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU,
xPos,
yPos,
windowWidth,
windowHeight,
nullptr,
nullptr,
hInstance,
nullptr
);
RECT rectLink = {
30,
30,
300,
40
};
hWndLink = CreateWindowEx(
0,
WC_LINK,
L"link: <A HREF=\"https://www.google.com\">click</A>",
WS_VISIBLE | WS_CHILD | WS_TABSTOP | WS_CAPTION,
rectLink.left,
rectLink.top,
rectLink.right,
rectLink.bottom,
hWndMain,
NULL,
hInstance,
NULL);
if (!hWndLink)
{
return FALSE;
}
ShowWindow(hWndMain, nCmdShow);
ShowWindow(hWndLink, nCmdShow);
UpdateWindow(hWndMain);
UpdateWindow(hWndLink);
WndProc2():
LRESULT CALLBACK WndProc2(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
EndPaint(hWnd, &ps);
}
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hWnd, message, wParam, lParam);
}
return 0;
}

It's a little hard to be sure what you have wrong.
The main steps you need to get a functioning SysLink control are:
You didn't mention anything about doing this, but without it,
InitCommonControlsExwill fail, and the control won't be created or displayed at all (at least on older versions of Windows--I guess I've never tested what happens if you skip that on a recent version).InitCommonControlsEx, usually right inWinMain, before creating your main window:WndProc, create the SysLink:ComCtl32.libHere's a quick demo program that puts all of the above together. The skeleton is just what Visual Studio generates for an empty Windows program, with the above bits added in appropriate places.
In action, it looks like this:
When clicked, it pops up a message box like this:
The exact look you get for the window frames and such will depend a bit on how you build it, the OS Version you run it on, and so on. You indicated an interest in Windows XP. I don't have a copy of that handy to test on any more, but I ran this on the oldest I still have around (Windows 7).