Hyperlink using comctrl32.dll

Does anyone know how to make a hyperlink using comctrl32.dll cause I heard it's possible and I can't find any tutorial on it?
http://msdn.microsoft.com/en-us/library/bb760704%28v=VS.85%29.aspx

This shall help, I guess... (it is all You need to know to get it running on a window)


Or the Command Link Button -> (see http://msdn.microsoft.com/en-us/library/bb775947%28v=VS.85%29.aspx - > first picture)
Last edited on
could someone show me an example code of creating SysLink in runtime? :|
Last edited on
Before creating SysLink controls, call InitCommonControlsEx, specifying the ICC_LINK_CLASS.

To create a SysLink, call CreateWindow or CreateWindowEx, specifying the WC_LINK window class. The lpWindowName parameter common to these functions specifies a pointer to a zero-terminated string containing the marked-up text to display. For window styles particular to SysLink controls, see Syslink Control Styles.

All the new functionality defined in ComCtl32.dll version 6 supports only Unicode. Therefore, you cannot create ANSI versions of SysLink controls, only Unicode versions.

The following example function creates a SysLink that displays two links. The first is an URL, and the second is identified by an application-defined string. Specifying the WS_TABSTOP style ensures that the user will be able to select a link by tabbing to it and pressing the Enter key. It is assumed that InitCommonControlsEx has already been called.


1
2
3
4
5
6
7
8
9
HWND CreateSysLink(HWND hDlg, HINSTANCE hInst, RECT rect)
{
    return CreateWindowEx(0, WC_LINK, 
        L"For more information, <A HREF=\"http://www.microsoft.com\">click here</A> " \
        L"or <A ID=\"idInfo\">here</A>.", 
        WS_VISIBLE | WS_CHILD | WS_TABSTOP, 
        rect.left, rect.top, rect.right, rect.bottom, 
        hDlg, NULL, hInst, NULL);
}


The notifications associated with SysLink controls are NM_CLICK (syslink) and (for links that can be activated by the Enter key) NM_RETURN.

The following example shows how an application might process a notification that one of the links in the previous example has been clicked. If the notification is from the first link (index 0), the URL is opened in the default browser. If the notification is from the link that was identified as "idInfo" when the control was created, a message box is shown. The example is intended to show two different ways of identifying a link, and should not be taken as model code.



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// g_hLink is the handle of the SysLink control.
case WM_NOTIFY:
    switch (((LPNMHDR)lParam)->code)
    {
    case NM_CLICK:
    case NM_RETURN:
        {
            PNMLINK pNMLink = (PNMLINK)lParam;
            LITEM item = pNMLink->item;
            if ((((LPNMHDR)lParam)->hwndFrom == g_hLink) && (item.iLink == 0))
            {
                ShellExecute(NULL, L"open", item.szUrl, NULL, NULL, SW_SHOW);
            }
            else if (wcscmp(item.szID, L"idInfo") == 0)
            {
                MessageBox(hDlg, L"This isn't much help.", L"Example", MB_OK);
            }
            break;
        }
    ...
    }
    break;
Thank you very much but what HINSTANCE should i pass in when calling CreateSysLink, NULL?
You pass main hInstance (or whatever is called) global variable of the parent window. Look at CreateWindowEx documentation.
I dont get it why do i get NULL for the HWND SysLink in this code
1
2
3
4
5
6
7
8
9
	INITCOMMONCONTROLSEX iccex;
	
	switch (message) {
	    case WM_CREATE:
			iccex.dwICC = ICC_LINK_CLASS;
			iccex.dwSize = sizeof(iccex);
			InitCommonControlsEx(&iccex);
			CreateSysLink(hWnd); 
	}

1
2
3
4
5
6
7
8
9
10
11
HWND CreateSysLink(HWND hwnd){
	HWND SysLink;
	SysLink = CreateWindowEx(0, (LPCSTR)WC_LINK,  "Produced by <A HREF=\"http://google.com\">click test</A>", WS_CHILD | WS_VISIBLE | WS_TABSTOP,
		0 , 0, CW_USEDEFAULT, CW_USEDEFAULT, hwnd, NULL, GetModuleHandle(NULL), NULL);
	if (SysLink == NULL){
		MessageBox(NULL, "Error in creation of syslink.", "Error!", MB_OK | MB_ICONEXCLAMATION);
		return 0;
	}
	else
		return SysLink;
}
Last edited on
Your code will not work as you pass ANSI strings. If your project is not unicode, call CreateWindowExW() directly.
Topic archived. No new replies allowed.