各位,AfxMessageBox()运行后主程序进入什么状态了,是挂起还是阻塞了呢?
有什么方式让程序进入运行AfxMessageBox()后的状态而不需要运行AfxMessageBox()?
急切的期待着解答!
谢谢

解决方案 »

  1.   

    父窗口的部分消息被阻塞了有什么方式让程序进入运行AfxMessageBox()后的状态而不需要运行AfxMessageBox()?
    ----
    EnableWindow(FALSE) ??
      

  2.   

    可以参考一下CDialog::DoModal()函数的实现
      

  3.   

    楼主的意思是不是弹出AfxMessageBox()后程序不阻塞继续运行啊?
      

  4.   

    不是啊,我是想知道AfxMessageBox()运行后弹出对话框了,主进程进入了什么状态。如何不用AfxMessageBox()也能使主进程进入这一状态
      

  5.   

    >>不是啊,我是想知道AfxMessageBox()运行后弹出对话框了,主进程进入了什么状态。如何不用
        AfxMessageBox()也能使主进程进入这一状态模态对话框运行会暂时接管模态对话框所在程序的消息循环,所以其他窗口暂时无法响应,如果想不弹出模态对话框而实现这种效果,参考下DoModal函数的实现  nt CDialog::DoModal()
    {
    // can be constructed with a resource template or InitModalIndirect
    ASSERT(m_lpszTemplateName != NULL || m_hDialogTemplate != NULL ||
    m_lpDialogTemplate != NULL); // load resource as necessary
    LPCDLGTEMPLATE lpDialogTemplate = m_lpDialogTemplate;
    HGLOBAL hDialogTemplate = m_hDialogTemplate;
    HINSTANCE hInst = AfxGetResourceHandle();
    if (m_lpszTemplateName != NULL)
    {
    hInst = AfxFindResourceHandle(m_lpszTemplateName, RT_DIALOG);
    HRSRC hResource = ::FindResource(hInst, m_lpszTemplateName, RT_DIALOG);
    hDialogTemplate = LoadResource(hInst, hResource);
    }
    if (hDialogTemplate != NULL)
    lpDialogTemplate = (LPCDLGTEMPLATE)LockResource(hDialogTemplate); // return -1 in case of failure to load the dialog template resource
    if (lpDialogTemplate == NULL)
    return -1; // disable parent (before creating dialog)
    HWND hWndParent = PreModal();
    AfxUnhookWindowCreate();
    BOOL bEnableParent = FALSE;
    if (hWndParent != NULL && ::IsWindowEnabled(hWndParent)) //如果有父窗口,禁用父窗口的一切输入
    {
    ::EnableWindow(hWndParent, FALSE);
    bEnableParent = TRUE;
    } 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(); // unlock/free resources as necessary
    if (m_lpszTemplateName != NULL || m_hDialogTemplate != NULL)
    UnlockResource(hDialogTemplate);
    if (m_lpszTemplateName != NULL)
    FreeResource(hDialogTemplate); return m_nModalResult;
    }
      

  6.   

    在线程内写MessageBox,当发现已经有MessageBox,则关掉已经存在的,重新谈出一个新的MessageBox,且MessageBox的参数中句柄为NULL每次想MessageBox,就调用线程