关于AfxMessageBox问题 各位,AfxMessageBox()运行后主程序进入什么状态了,是挂起还是阻塞了呢?有什么方式让程序进入运行AfxMessageBox()后的状态而不需要运行AfxMessageBox()?急切的期待着解答!谢谢 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 父窗口的部分消息被阻塞了有什么方式让程序进入运行AfxMessageBox()后的状态而不需要运行AfxMessageBox()?----EnableWindow(FALSE) ?? 可以参考一下CDialog::DoModal()函数的实现 楼主的意思是不是弹出AfxMessageBox()后程序不阻塞继续运行啊? 不是啊,我是想知道AfxMessageBox()运行后弹出对话框了,主进程进入了什么状态。如何不用AfxMessageBox()也能使主进程进入这一状态 >>不是啊,我是想知道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;} 在线程内写MessageBox,当发现已经有MessageBox,则关掉已经存在的,重新谈出一个新的MessageBox,且MessageBox的参数中句柄为NULL每次想MessageBox,就调用线程 求助:怎样在VB2008中添加ActiveX控件? 能不能在按钮上画图和文字 rpc程序报错,IO pending,这是为什么? 多线程中的问题~~~大家帮忙看看~~ 如何将一个CScrollView中的所显示对象都存储为BMP图像? 怎样实现录音功能(line in,mic),最好是源码,[email protected] Mediaplayer控件的注册问题!!! 请问怎么用MFC的CTime类修改机器时间 如何更底层的控制串口?不是说CreateFile\Read/WriteFile一类。 vc写ftp server? 基于当文档的程序 MFC怎么向Edit添加数据?
----
EnableWindow(FALSE) ??
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;
}