我在对话框中有一个RichEdit控件。 RichEdit控件显示RTF文本。 EM_AUTOURLDETECT
使RichEdit控件正确格式化并识别超链接。当鼠标悬停在链接上时,指针会变为手形,但单击链接后浏览器不会启动。
我错过了某种事件处理程序代码吗?
case WM_INITDIALOG:
{
// Create Richedit
HWND hwndRE = CreateWindowA("RichEdit20A", "", WS_CHILD | WS_BORDER | WS_VSCROLL | ES_READONLY | ES_MULTILINE, 10, 10, 480, 220, hDlgWnd, 0, hInst, 0);
SendMessage(hwndRE ,EM_AUTOURLDETECT,(WPARAM)TRUE,(LPARAM)0);
//SendMessage(hwndRE ,EM_SETEVENTMASK, 1, ENM_LINK | ENM_CHANGE);
ShowWindow(hwndRE, SW_SHOWNORMAL);
SETTEXTEX SetTextEx;
char* aboutdata = "{\\rtf1\\ansi\\ansicpg1252\\deff0\\deflang1033{\\fonttbl{\\f0\\fnil\\fcharset0 Verdana;}}\\viewkind4\\uc1\\pard\\qc\\b\\f0\\fs20 www.whateverdomain.com} ");
SendMessage(hwndRE, EM_SETTEXTEX,(WPARAM)&SetTextEx, (LPARAM)(LPCTSTR)aboutdata);
return TRUE;
}
答案 0 :(得分:3)
您可以尝试这样的事情:
case WM_NOTIFY:
switch (((LPNMHDR)lParam)->code)
{
case EN_LINK:
ENLINK * enLinkInfo = (ENLINK *)lParam;
if (enLinkInfo->msg == WM_LBUTTONUP)
{
// code which gets clicked URL using enLinkInfo->chrg and saves it in
// "urlString"
ShellExecute(NULL, "open", urlString, NULL, NULL, SW_SHOWNORMAL);
}
break;
.... // More cases on WM_NOTIFY switch.
}
break;
基本上,当WM_NOTIFY代码为EN_LINK时,您将获得单击的URL并使用ShellExecute启动它。
答案 1 :(得分:0)