create非模态对话框的assertion failure错误

来源:百度知道 编辑:UC知道 时间:2024/06/08 00:25:02
CNew *dlg=new CNew;
dlg->Create(IDD_DIALOG2, this);
出现assertion failure
用另一种方法:
CNew nw;
nw.Create(IDD_DIALOG2,this);
同样是assertion failure,都是winocc.cpp line279有错。

出错的地方是这:
void CWnd::MoveWindow(int x, int y, int nWidth, int nHeight, BOOL bRepaint)
{
ASSERT(::IsWindow(m_hWnd)); //line279

if (m_pCtrlSite == NULL)
::MoveWindow(m_hWnd, x, y, nWidth, nHeight, bRepaint);
else
m_pCtrlSite->MoveWindow(x, y, nWidth, nHeight, bRepaint);
}

请高手指教错误原因,怎么消除?
非常感谢!

你的CNew应该是继承CDialog的吧。dialog不能用create创建,那是普通的CWnd的创建方式。你可以重载你的CNew类的构造函数,大体意思如下,调用CDialog的构造函数。

CNew::CNew(m_parentHwnd = this):CDialog(IDD_DIALOG2,m_parentHwnd);