【问题标题】:How to properly add MFC Link Control to Dialog?如何正确地将 MFC 链接控件添加到对话框?
【发布时间】:2019-04-04 10:20:45
【问题描述】:

我为游戏制作了一个插件 DLL。现在我想将许可证激活添加到我的插件中,所以我使用 Visual Studio 资源向导制作了一个简单的对话框 (LicenseActivation.rc)。

当附加 DLL 时,我将 HMODULE 保存为 m_hModule 成员变量,并在新线程中运行以下代码

DialogBox(m_hModule, MAKEINTRESOURCE(IDD_DIALOG1), NULL, About);

而About回调函数实现如下

INT_PTR CALLBACK About(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
    PrintDebug(L"About(%d, %#x, %d, %d)", hDlg, message, wParam, lParam);
    switch (message)
    {
    case WM_INITDIALOG:
        //PrintDebug(L"case WM_INITDIALOG");
        return (INT_PTR)TRUE;

    case WM_COMMAND:
        //PrintDebug(L"case WM_COMMAND");
        switch (LOWORD(wParam))
        {
        case IDOK:
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        case IDCANCEL:
            EndDialog(hDlg, LOWORD(wParam));
            return (INT_PTR)TRUE;
        }
        break;
    }
    return (INT_PTR)FALSE;
}

这是对话框资源

在我将 MFC Link Control 元素添加到 Dialog 之前,它工作得很好,运行时会显示 Dialog 并打印以下调试消息

[11848] About(1380712, 0x30, 1544171096, 0)
[11848] About(1380712, 0x110, 6359660, 0)
[11848] About(1380712, 0x46, 0, 253295812)
[11848] About(1380712, 0x1c, 1, 0)
[11848] About(1380712, 0x86, 0, 0)
[11848] About(1380712, 0x7f, 2, 0)
[11848] About(1380712, 0x7f, 0, 0)
[11848] About(1380712, 0x7f, 1, 0)
[11848] About(1380712, 0x6, 1, 0)
[11848] About(1380712, 0x400, 0, 0)
[11848] About(1380712, 0x127, 3, 0)
[11848] About(1380712, 0x128, 196609, 0)
[11848] About(1380712, 0x31f, 1, 0)
[11848] About(1380712, 0x18, 1, 0)
[11848] About(1380712, 0x46, 0, 253296052)
[11848] About(1380712, 0x85, 1, 0)
[11848] About(1380712, 0x7f, 2, 0)
[11848] About(1380712, 0x7f, 0, 0)
[11848] About(1380712, 0x7f, 1, 0)
[11848] About(1380712, 0x14, 16855179, 0)
[11848] About(1380712, 0x136, 16855179, 1380712)
[11848] About(1380712, 0x47, 0, 253296052)
[11848] About(1380712, 0x7f, 2, 0)
[11848] About(1380712, 0x7f, 0, 0)
[11848] About(1380712, 0x7f, 1, 0)
[11848] About(1380712, 0xf, 0, 0)
[11848] About(1380712, 0x135, 16855179, 6359660)
[11848] About(1380712, 0x135, 16855179, 1445800)
[11848] About(1380712, 0x138, 16855179, 1446218)
[11848] About(1380712, 0x133, 16855179, 2363706)
[11848] About(1380712, 0x133, 16855179, 2363706)
[11848] About(1380712, 0x138, 16855179, 1577080)
[11848] About(1380712, 0x7f, 2, 96)
[11848] About(1380712, 0x7f, 0, 96)
[11848] About(1380712, 0x7f, 1, 96)
[11848] About(1380712, 0x7f, 2, 0)
[11848] About(1380712, 0x7f, 0, 0)
[11848] About(1380712, 0x7f, 2, 0)
[11848] About(1380712, 0x7f, 0, 0)
[11848] About(1380712, 0x7f, 2, 0)
[11848] About(1380712, 0x7f, 0, 0)

但只要我将 MFC 链接控件 添加到 对话框,对话框就不会出现并打印以下调试消息

[9748] About(3018840, 0x30, 1393179198, 0)
[9748] About(3018840, 0x90, 0, 0)
[9748] About(3018840, 0x2, 0, 0)
[9748] About(3018840, 0x82, 0, 0)

【问题讨论】:

    标签: c++ visual-studio-2015 mfc


    【解决方案1】:

    我看到你有一个普通的 Win32 程序。

    链接控件仅适用于 MFC 项目。您既没有从 CDialogEx 派生的对话框,也没有像 MFC 那样使用任何技术来创建或处理控件。

    win32 here 和 here 有一个普通的超链接控件。

    【讨论】:

    • 这是否意味着不为超链接编写一行代码就无法使其工作?当我在 VS 中转到格式 > 测试对话框 (CTR+T) 时,它工作得很好。这是正常的吗?我想知道为什么 VS 不抱怨或给出任何提示。
    • 没有。这是特殊的 MFC 东西。而且您没有使用 MFC!测试容器是 MFC 感知的。 Windows 本身没有这样的链接控制。我在答案中添加了另一个代码示例。
    • 你添加的那两个链接是什么? Windows 具有适用于 Vista 及更高版本的本机 SysLink control。 “SysLink Control”在对话框设计框中,在“MFC Link Control”旁边
    • @xMRi 感谢您的回复,但不幸的是,您的回答对我来说有点复杂。有什么方法可以让我的 DLL MFC 知道吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-04-27
    • 1970-01-01
    • 1970-01-01
    • 2010-09-25
    • 2016-12-17
    • 2010-11-05
    • 2021-12-28
    相关资源
    最近更新 更多