怎么使基于MFC的对话框程序启动时最小化?如下代码不能实现,为什么
如何使基于MFC的对话框程序启动时最小化?如下代码不能实现,为什么?
BOOL CClocktimeApp::InitInstance()
{
if(++g_lAppInstance> 1)
{
AfxMessageBox( "程序已经运行! ");
return FALSE;
}
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.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CClocktimeDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
ShowWindow(GetMainWnd()-> GetSafeHwnd(),SW_HIDE); //使窗口最小化
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;
}
------解决方案--------------------
m_pMainWnd -> ShowWindow(SW_HIDE);
------解决方案--------------------
这样写ShowWindow根本没有在对话框显示时执行
ShowWindow写到 ClocktimeDlg.cpp中去
------解决方案--------------------
还要在ON_SIZE消息的响应函数中添加 m_pMainWnd -> ShowWindow(SW_HIDE);
不然对话框还是会出来.
------解决方案--------------------
SW_HIDE似乎也不是最小化,而是隐藏窗口,最小化是SW_MINIMIZE
BOOL CClocktimeApp::InitInstance()
{
if(++g_lAppInstance> 1)
{
AfxMessageBox( "程序已经运行! ");
return FALSE;
}
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.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
CClocktimeDlg dlg;
m_pMainWnd = &dlg;
int nResponse = dlg.DoModal();
ShowWindow(GetMainWnd()-> GetSafeHwnd(),SW_HIDE); //使窗口最小化
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;
}
------解决方案--------------------
m_pMainWnd -> ShowWindow(SW_HIDE);
------解决方案--------------------
这样写ShowWindow根本没有在对话框显示时执行
ShowWindow写到 ClocktimeDlg.cpp中去
------解决方案--------------------
还要在ON_SIZE消息的响应函数中添加 m_pMainWnd -> ShowWindow(SW_HIDE);
不然对话框还是会出来.
------解决方案--------------------
SW_HIDE似乎也不是最小化,而是隐藏窗口,最小化是SW_MINIMIZE