基于CDialog的应用程序启动时,如何将我的辅助对话框窗口带到顶部
How to bring my secondary dialog window to the top when the CDialog-based app starts?
我已经编码了基于MFC CDialog
的应用程序。在正常情况下,它是通过从InitInstance
处理程序显示CDialog
窗口开始的:
CMyDialog dlg;
INT_PTR nResponse = dlg.DoModal();
但是,该应用程序首次运行,我需要在屏幕上的主对话框之前从CMyDialog::OnInitDialog
中显示另一个对话框。所以我做了类似的事情:
CIntroDialog idlg(this);
idlg.DoModal();
但是,这种方法的问题是我的第二个CIntroDialog
未显示在前景中。因此,我试图通过从CIntroDialog::OnInitDialog
中调用以下内容来解决此问题:
this->SetForegroundWindow();
this->BringWindowToTop();
,但没有做任何事情。
然后,我尝试从InitInstance
调用::AllowSetForegroundWindow(ASFW_ANY);
进行应用,但这也没有做任何事情。
当应用程序启动时如何将第二个对话框带到前景?
ps。由于该应用程序的结构,我需要从CMyDialog::OnInitDialog
内调用CIntroDialog::DoModal
,以防止大量重写。
您是否考虑在应用程序类中使用InitInstance
?
BOOL CMyApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
CMyDlg 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
}
// Since the dialog has been closed, return FALSE so that we exit the
// application, rather than start the application's message pump.
return FALSE;
}
我已经删除了一些默认实现,但是您会看到这一点:
CMyDlg 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
}
没有什么可以阻止您做这样的事情:
CMyDlg2 dlg2;
if(dlg2.DoModal() == IDOK)
{
CMyDlg 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
}
}
else
{
// Handle IDCANCEL
}
我承认我尚未测试上述代码,但是我看不出为什么您不能执行第一次对话,然后是第二个对话。
相关文章:
- 如何在 VC6 中的对话框中将图标设置为按钮
- 如何在主窗口标签的对话框中显示QLineEdit的输入
- 静态库中的对话框资源
- 连接类实例和另一个类实例中的对话框之间的槽和信号
- 注销侏儒会话时如何从Qt应用程序执行"confirm" gnome会话管理器的对话框(不使用QSessionManager)
- C 从回调函数中的对话框获取并设置值
- 从QT中的对话框中声明指向主窗口的指针
- 从QT中的对话框访问主窗口
- 创建不会阻止主应用 MFC 的对话框
- MFC C++中的对话框
- c++ qt 主窗口设置图像后的对话框"确定"按钮
- VC++2010:显示打开的对话框挂起
- 如何从 MFC 中的对话框头文件访问静态变量
- 从Qt中的对话框获取数据并在Ui中使用
- 在C++资源中的对话框上的左上角图标
- 关闭其他线程的对话框后无法从主窗口聚焦
- 为什么我的对话框在 MFC 中没有响应 OnRButtonDown()?
- 当我使用 SDK 7.1 编译它时,我的对话框没有显示
- 当我在win32项目c++应用程序中单击菜单项时,如何编写代码来加载一个特殊的对话框?
- 可视"我的"对话框未显示在 MFC C++中