SysLink control demo

For Visual C++ 6.0 compatibility, the control requires the common controls library and the ICC_LINK_CLASS initialization flag.

#include <windows.h> #include <commctrl.h> #include <shellapi.h> #ifndef UNICODE #define UNICODE #endif // Force the compiler/linker to use Common Controls Version 6 for Visual Styles & SysLink support #pragma comment(linker,"\"/manifestdependency:type='win32' \ name='Microsoft.Windows.Common-Controls' version='6.0.0.0' \ processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"") // Link against the common controls library #pragma comment(lib, "comctl32.lib") const wchar_t CLASS_NAME[] = L"SysLinkWindowClassName"; HWND hwndLink = NULL; LRESULT CALLBACK WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) { switch (uMsg) { case WM_CREATE: { // Initialize common controls specifically for SysLink INITCOMMONCONTROLSEX iccex; iccex.dwSize = sizeof(INITCOMMONCONTROLSEX); iccex.dwICC = ICC_LINK_CLASS; InitCommonControlsEx(&iccex); // Explicitly using the Unicode creation variant hwndLink = CreateWindowExW( 0, WC_LINK, L"Click here to visit <A HREF=\"https://www.google.com\">Google</A>.", WS_VISIBLE | WS_CHILD | WS_TABSTOP, 20, 30, 250, 30, hwnd, NULL, ((LPCREATESTRUCT)lParam)->hInstance, NULL ); return 0; } case WM_NOTIFY: { LPNMHDR pnmh = (LPNMHDR)lParam; if (pnmh->hwndFrom == hwndLink && pnmh->code == NM_CLICK) { PNMLINK pNMLink = (PNMLINK)lParam; ShellExecuteW(NULL, L"open", pNMLink->item.szUrl, NULL, NULL, SW_SHOWNORMAL); return TRUE; } break; } case WM_DESTROY: PostQuitMessage(0); return 0; } return DefWindowProc(hwnd, uMsg, wParam, lParam); } int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { WNDCLASS wc = {}; wc.lpfnWndProc = WindowProc; wc.hInstance = hInstance; wc.lpszClassName = CLASS_NAME; wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); RegisterClass(&wc); HWND hwnd = CreateWindowExW( 0, CLASS_NAME, L"Win32 SysLink Example", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, 400, 150, NULL, NULL, hInstance, NULL ); if (hwnd == NULL) return 0; ShowWindow(hwnd, nCmdShow); MSG msg = {}; while (GetMessage(&msg, NULL, 0, 0) > 0) { if (!IsDialogMessage(hwnd, &msg)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return 0; }