如何正确地将MFC链接控件添加到对话框?

时间:2019-04-04 10:20:45

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

我为游戏制作了一个插件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;
}

这是对话框资源

Dialog in the Visual Studio 2015 Editor

在将 MFC链接控制元素添加到对话框之前,它工作得很好,运行时将显示该对话框并打印以下调试消息

[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)

1 个答案:

答案 0 :(得分:0)

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

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

对于win32 herehere,有一个普通的超级链接控件。