C++: Handle the Syslink click event

0 Comments

Once you have the SysLink control working, you can respond to link clicks by adding a notification listener to your parent window.

01.case WM_NOTIFY: {
02.  LPNMHDR pnmh = (LPNMHDR) lParam;
03. 
04.  // If the notification came from the syslink control
05.  if (pnmh->idFrom == IDC_SYSLINK_WEBSITE) {
06.    // NM_CLICK is the notification is normally used.
07.    // NM_RETURN is the notification needed for return keypress, otherwise the control is not keyboard accessible.
08.    if ((pnmh->code == NM_CLICK) || (pnmh->code == NM_RETURN)) {
09.      // Recast lParam to an NMLINK item because it also contains NMHDR as part of its structure
10.      PNMLINK link = (PNMLINK) lParam;
11. 
12.      ShellExecute(NULL, L"open", link->item.szUrl, NULL, NULL, SW_SHOWNORMAL);
13.    }
14. 
15.  }
16. 
17.  break;
18.}

The link->item.szUrl field is the "href" given in the syslink control markup.

 
Copyright © Twig's Tech Tips
Theme by BloggerThemes & TopWPThemes Sponsored by iBlogtoBlog