闲来无聊,看了下MSDN,原来syslink控件是这样实现的:
步骤:
1.拖放syslink控件至对话框
2.修改caption为你想要的任何链接名(如:百度一下)
3.在WM_NOTIFY消息里进行如下处理
代码:
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code)
{
case NM_CLICK:
case NM_RETURN:
{
HWND g_hLink=GetDlgItem(hDlg,IDC_SYSLINK1);
PNMLINK pNMLink = (PNMLINK)lParam;
LITEM item = pNMLink->item;
if ((((LPNMHDR)lParam)->hwndFrom == g_hLink) && (item.iLink == 0))
{
ShellExecute(NULL, L"open",L"http://www.baidu.com", 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;
手动创建syslink(msdn):
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); }
然后响应用户点击:
case WM_NOTIFY: switch (((LPNMHDR)lParam)->code) { case NM_CLICK: // Fall through to the next case. 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;
PS:我在利用syslink进行运行时能够正常弹出对话框,因为我将对话框设置成主窗口,后来我发现,当syslink控件不是在这个主窗口上时,对话框无法弹出,看了MSDN,解释说syslink控件只支持Unicode,不知道是什么意思,如果有哪位高手路过,还请麻烦您能够花费您几分钟时间留言解决一下,不甚感激!!!