在 CDialog 派生类上创建使用 VS2015 CLR 返回 0,在 VC++ 6 中工作正常

Create on a CDialog derived class returns 0 with VS2015 CLR, worked fine in VC++ 6

本文关键字:VC++ 工作 返回 CLR 派生 CDialog 创建 VS2015      更新时间:2023-10-16

我正在尝试迁移基于 VC++ 6 的代码以使用 VS2015 CLR。我的主要功能在工作,但 UI 缺少一些东西。

我已经将此问题追溯到由于父 CWnd 的空 HWnd 而导致的 SubclassDlgItem 失败。它是 NULL,因为在 CDialog 派生的父类上创建在 dlgcore 中返回 0 .cpp

if (hWnd != NULL && !(m_nFlags & WF_CONTINUEMODAL))
    {
        ::DestroyWindow(hWnd);
        hWnd = NULL;
    }

m_nFlags = 256(定义为 #define WF_OLECTLCONTAINER 0x0100//某个后代是 afxwin.h 中的 OLE 控件)

hWnd 不是 NULL,但 '::CreateDialogIndirect() 没有创建窗口(即由于模板中的错误)并根据Microsoft注释返回 NULL'

以下是父 CWnd 的代码

CreateEx(
            WS_EX_NOPARENTNOTIFY,
            NULL,
            "MainClient",
            WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_CLIPSIBLINGS,
            0, 0,       // Locate at upper left corner of client area
            1, 1,       // Initial size doesn't matter - will be sized to fit parent
            parent->GetSafeHwnd(),
            NULL
        );

以下是创建 CDialog 的代码

m_pMainDialog = new CxMainDialog();
m_pMainDialog->Create(IDD_MAIN_DIALOG, this);

下面是 CxMainDialog 构造函数

CxMainDialog::CxMainDialog(CWnd* pParent /*=NULL*/)
    : CDialog(CxMainDialog::IDD, pParent)
{
    //{{AFX_DATA_INIT(CxMainDialog)
        // NOTE: the ClassWizard will add member initialization here
    //}}AFX_DATA_INIT
}

我怎样才能让它工作?

此问题已通过在创建时删除导致问题的 ActiveX 控件来修复对话框模板来解决。我创建了一个重复的对话框并将其清空以测试创建是否成功。