我有一个对话框在执行到CDialog::domodal()函数的时候,没什么异常发生的就给我把对话框给销毁了。
TRY
{
// create modeless dialog
AfxHookWindowCreate(this);
if (CreateDlgIndirect(lpDialogTemplate,
CWnd::FromHandle(hWndParent), hInst))
{
if (m_nFlags & WF_CONTINUEMODAL)
{
// enter modal loop
DWORD dwFlags = MLF_SHOWONIDLE;
if (GetStyle() & DS_NOIDLEMSG)
dwFlags |= MLF_NOIDLEMSG;
VERIFY(RunModalLoop(dwFlags) == m_nModalResult);
} // hide the window before enabling the parent, etc.
if (m_hWnd != NULL)
SetWindowPos(NULL, 0, 0, 0, 0, SWP_HIDEWINDOW|
SWP_NOSIZE|SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOZORDER);
}
}
CATCH_ALL(e)
{
DELETE_EXCEPTION(e);
m_nModalResult = -1;
}
END_CATCH_ALL if (bEnableParent)
::EnableWindow(hWndParent, TRUE);
if (hWndParent != NULL && ::GetActiveWindow() == m_hWnd)
::SetActiveWindow(hWndParent); // destroy modal window
DestroyWindow(); //代码能一路顺利的执行到这里,按说是应该在前面的某处阻塞的
PostModal();请问一般问题应该是出现在哪里??

解决方案 »

  1.   

    进了RunModalLoop函数吗?modal对话框在这里会有一个消息循环
      

  2.   

    CreateDlgIndirect(lpDialogTemplate,
    CWnd::FromHandle(hWndParent), hInst)
    返回是零 其中
    lpDialogTemplate ==肯定有效的指针值
    hWndParent ==看样子也是个有效的
    hInst = 0x 100000
      

  3.   

    在函数BOOL CWnd::CreateDlgIndirect(LPCDLGTEMPLATE lpDialogTemplate,
    CWnd* pParentWnd, HINSTANCE hInst)中
    if (hWnd != NULL && !(m_nFlags & WF_CONTINUEMODAL))

    ::DestroyWindow(hWnd); //函数没有执行到这里
    hWnd = NULL;
    }if (hTemplate != NULL)
    {
    GlobalUnlock(hTemplate); //也没有执行到这里
    GlobalFree(hTemplate);
    }// help with error diagnosis (only if WM_INITDIALOG didn't EndDialog())
    if (hWnd == NULL && (m_nFlags & WF_CONTINUEMODAL))
    {
    #ifdef _DEBUG
    #ifndef _AFX_NO_OCC_SUPPORT
    if (afxOccManager == NULL)  //到了 这里
    {
    TRACE0(">>> If this dialog has OLE controls:\n");
    TRACE0(">>> AfxEnableControlContainer has not been called yet.\n");
    TRACE0(">>> You should call it in your app's InitInstance function.\n");
    }
    else if (dwError != 0)
    {//没有执行这里
    TRACE1("Warning: Dialog creation failed!  GetLastError returns 0x%8.8X\n", dwError);
    }
    #endif //!_AFX_NO_OCC_SUPPORT
    #endif //_DEBUG
    return FALSE;//执行了这该死的一步
    } ASSERT(hWnd == m_hWnd);
      

  4.   

    多设几个断点。
    TRACE和OutputDebugString。
      

  5.   

    我是知道问题是在哪的但是不知道为什么会出这个问题
    就是CWnd::CreateDlgIndirect 失败吗 
    救命啊 ~~~
      

  6.   

    在前面添加一个显示messagebox的函数看看
      

  7.   

    如果是对话框没有显示出来就销毁了
    建议你在DoModal后面加上消息循环
    while(::GetMessage(...))
    {
       ::TranslateMessage
       ::DispatchMessage
    }
    问题好像处在对话框没有产生自己的消息循环
    而这应该是DoModal默认产生的
      

  8.   

    对话框上放了什么东西,如果有RichEdit空间的话,如果不先初始化OLE对话框就无法显示
      

  9.   

    对啊 对话况上放了一个控件结果就成这样了 莫非真如afc所说没有初始化ole??不过在哪里,怎么初始化ole啊
      

  10.   

    i get it  
    afc大侠 太感谢你了 呵呵