Command Link Button Control

What are Command Links?

Among other new controls supported in Windows Vista and newer Windows versions, we can find  Command Link controls, that contain:

  • an icon;
  • a label text;
  • an additional explanatory text.

Command Link Control Example

In fact, it is a common Windows button control (of class “Button“) that has BS_COMMANDLINK or BS_DEFCOMMANDLINK type style set.
We’ll further show how to deal with such type of controls in our own aplications.

How to add a Command Link Button

If working with Microsoft Visual Studio 2008 or newer, then we can find “Command Button Control” in the resource editor toolbox.
So first, we just have to drag it from toolbox in the resource dialog template.

Adding Command Control to dialog template

The label text can be set at design time by changing the Caption property; it can be also changed at run-time by calling CWnd::SetWindowText.
The additional explanatory text has to be set at run-time by calling CButton::SetNote.
The default arrow icon can be changed at run-time using CButton::SetIcon.
Here is an example:

Further, we can work like with any other classic push button, as for example handling BN_CLICKED  notification.

Additional notes

  1. Command Link Button controls are available in Windows Vista and newer.
  2. For for additional environment info, see “Build Requirements for Windows Vista Common Controls” link below.
  3. In raw-WinAPI applications (not using MFC), can use the corresponding Windows SDK functions/macros instead of of CWnd/CButton methods.
  4. Command Button Control is available in the resource editor, beginning with Visual Studio 2008. However, you can still use this kind of control in older Visual Studio versions. For this purpose you can:
    • Add to dialog template a regular push button then manually edit the resource script (.rc) file or, a little bit better…
    • …add to dialog template a Custom Control.
      Adding Command Button Control (VS2005)
      As shown in the image, you must set “BUTTON” class property and “0x5001000e” style property (WS_CHILD|WS_VISIBLE|WS_TABSTOP|BS_COMMANDLINK).
      Also, in the source code you have to send BCM_SETNOTE message instead of calling CButton::SetNote. For more details, see the attached VS 2005 demo project.



Leave a Reply