主窗口作为无模式对话框的 MFC 应用程序
我正在开发一个MFC应用程序并将其导出到dll中。该应用程序只有一个窗口,我希望该窗口是无模式的。在 InitInstance() 内部,如果我希望它是模态的,我只需要这样做:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CUIWelcomeDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
return false;
它作为模态工作得很好。这是无模式代码:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CUIWelcomeDlg * dlg;
dlg=new CUIWelcomeDlg();
m_pMainWnd=dlg;
if(dlg!=NULL) {
dlg->Create(IDD_UIWELCOME_DIALOG,NULL);
dlg->ShowWindow(SW_SHOW);
}
return true;
我尝试调试它。直到达到return true就可以了;之后,对话框窗口冻结并且没有响应。有谁知道如何解决这个问题?
I am developing an MFC application and exporting it into dll. The application has only one window, and I want that window modeless. Inside InitInstance(), if I want it to be modal, I only need to do this:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CUIWelcomeDlg dlg;
m_pMainWnd = &dlg;
INT_PTR nResponse = dlg.DoModal();
if (nResponse == IDOK)
{
// TODO: Place code here to handle when the dialog is
// dismissed with OK
}
else if (nResponse == IDCANCEL)
{
// TODO: Place code here to handle when the dialog is
// dismissed with Cancel
}
return false;
It works just fine as a modal. This is the code for the modeless one:
AFX_MANAGE_STATE(AfxGetStaticModuleState());
CUIWelcomeDlg * dlg;
dlg=new CUIWelcomeDlg();
m_pMainWnd=dlg;
if(dlg!=NULL) {
dlg->Create(IDD_UIWELCOME_DIALOG,NULL);
dlg->ShowWindow(SW_SHOW);
}
return true;
I tried to debug it. It is fine until it reaches return true; After that, the dialog window freezes and is not responding. Does anyone know how to fix this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试删除以下行:
m_pMainWnd = dlg;
(如果这里 dlg 是一个指针,则应该将其称为 pdlg)。
Try to remove the following line:
m_pMainWnd = dlg;
(if dlg is a pointer here, you should call it pdlg).
您需要实现自己的无限循环。当然,您不想停止 UI 线程进行响应,因此您需要在此循环内捕获和分派消息。尝试在 ShowWindow 之后添加以下内容:
You need to implement your own endless loop. Of course you don't want to stop the UI thread to be responsive so you need to capture and dispatch message inside this loop. Try adding this after ShowWindow: