RichEdit 的 EM_AUTOURLDETECT 消息识别链接,但我无法单击它

发布于 2024-11-11 17:37:33 字数 958 浏览 4 评论 0原文

我的对话框中有一个 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;
}

I have a RichEdit control in a dialog box. The RichEdit control displays RTF text. EM_AUTOURLDETECT causes the RichEdit control to properly format and recognize the hyperlink. When the mouse hovers over the link, the pointer changes to a hand, but the browser doesn't launch once the link is clicked.

Am I missing some kind of event handler code?

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;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

晨曦慕雪 2024-11-18 17:37:33

您可以尝试这样的操作:

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 启动它。

You can try something like this:

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;

Basically, when the WM_NOTIFY code is EN_LINK, you get the clicked URL and launch it using ShellExecute.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文