Syslink Control in MFC 9.0

Visual Studio 2008 (formely code-named ‘Orcas’) has several important updates for VC++ and MFC. Among them the possibility to create syslink controls, command or split buttons and network address controls. In this post I will show how you can work with the syslink control. The control provides a way to embed hypertext links in a window. It is actually a window that renders marked-up text just as hyperlinks in a web browser. Multiple links can be put in a single control, and are accessed by a zero-based index.

Currently it supports the anchor tag (<A>) with the HREF and ID attributes. HREF is used to specify a URL of any protocol (http, ftp, mailto, etc.). On the other hand ID specifies an unique name within the control, associated with an individual link.

The content is available in the toolbar, so you can simply drag and drop syslink controls onto you dialog template.

Syslink controls on dialog

You can specify the text, including the anchor tag from the properties page, or you can use the SetWindowText function to set it at run-time.

You have to handle the NM_CLICK notification, check which link was clicked and take the appropriate action:

In MFC 9.0 (version that will ship with Visual Studio 2008) class CLinkCtrl is a wrapper over the Windows API for working with the syslink control.

You can associate an instance of CLinkCtrl with a syslink control through the DDX mechanism:

In my demo application that you can download from here I used a second syslink with an ID attribute. Each time the link is clicked it increments a counter, which is shown. For that I created two helper functions first, one to generate part of the text and the second to set the text to the link control:

When handling the NM_CLICK notification, I checked the szID member of structure LITEM and took the appropriate action:

The result is shown here:

Syslink controls on dialog

Hopefully the sample code that I put together will help you work with CLinkCtrl and the syslink control in VS 2008.

8 Comments on "Syslink Control in MFC 9.0"


  1. Yes, it works on Win XP too. The syslink control was created for Win XP. But you could only created it with the Win API. In MFC 9.0 there is a class, CLinkCtrl that wraps over the Win API, and you can add it on a dialog from the resource editor. From the pictures, you can see I wrote the sample and run the application on Win XP, not Vista.


  2. And would there be a way to customize the look of the links? I mean if I would like to match color to with a non-standard color scheme. On MSDN they mention state LIS_DEFAULTCOLORS though it’s unclear what it means.

    Also there is a promising LIS_HOTTRACK fellow. Would it be possible to underline the link only when a mouse pointer is over it?


  3. I don’t exactly know how to customize the look. As you can see, there isn’t much documentation about this. If I’ll find more I promise to post it here.


  4. I’m using vs2005. I add a syslink control manually into the rc file like this:
    CONTROL “syslink“,IDC_LINK_MAIL,”SysLink”,WS_TABSTOP,139,66,70,14
    I define the IDC_LINK_MAIL macro in resource.h file. The code works when compiled using unicode but failed when compiled using mbcs settings.

    What wrong?

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.