SysLink Control Example

To create a syslink control specify WC_LINK as the window class and register the class by specifying the ICC_LINK_CLASS bit flag in the accompanying INITCOMMONCONTROLSEX structure.

// syslink control demo
#include <windows.h>
#include <commctrl.h>
#pragma comment(lib, "comctl32.lib") //adds link to control control DLL
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,LPSTR lpCmdLine, int nCmdShow)
{
WNDCLASSEX wc;
MSG msg;

wc.cbSize = sizeof(WNDCLASSEX);
wc.style = 0;
wc.lpfnWndProc = WndProc;
wc.cbClsExtra = 0;
wc.cbWndExtra = 0;
wc.hInstance = hInstance;
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
wc.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
wc.lpszMenuName = NULL;
wc.lpszClassName = TEXT("myWindowClass");
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
RegisterClassEx(&wc);

CreateWindowEx(WS_EX_CLIENTEDGE,TEXT("myWindowClass"),TEXT("SysLink Control Demo" ), WS_VISIBLE | WS_OVERLAPPEDWINDOW,CW_USEDEFAULT, CW_USEDEFAULT, 300, 120, NULL, NULL, hInstance, NULL);

while(GetMessage(&msg, NULL, 0, 0) > 0)
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
return msg.wParam;
}

//WndProc procedure. Application acts on messages
LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
static HWND link;
switch(msg)
{
case WM_CREATE:
{
HINSTANCE hInstance = (HINSTANCE)::GetModuleHandle(NULL);
// load common control class WC_LINK from the dynamic-link library (DLL).
INITCOMMONCONTROLSEX iccex;
iccex.dwICC = ICC_LINK_CLASS| ICC_STANDARD_CLASSES;
iccex.dwSize = sizeof(iccex);
InitCommonControlsEx(&iccex);
//create link window
link=CreateWindowEx(0, WC_LINK, TEXT("For more information, <A HREF=\"http://www.google.com\">click here</A>"), WS_VISIBLE | WS_CHILD | WS_TABSTOP,10, 10,300,50,hwnd, NULL, hInstance, NULL);
}
break;
case WM_NOTIFY:
//detects change in link control
switch (((LPNMHDR)lParam)->code)
{
case NM_CLICK:
case NM_RETURN:
{
PNMLINK pNMLink = (PNMLINK)lParam;
LITEM item = pNMLink->item;
item.iLink;
ShellExecute(NULL,TEXT("open"), pNMLink->item.szUrl, NULL, NULL,SW_SHOWMAXIMIZED);
break;
}

}
break;
case WM_CLOSE:
DestroyWindow(hwnd);
break;
case WM_DESTROY:
PostQuitMessage(0);
break;
default:
return DefWindowProc(hwnd, msg, wParam, lParam);
}
return 0;
}