文一:转载(http://dev.csdn.net/htmls/28/28675.html)html
doc_view结构中让窗口一开始就最大化探讨web
做者:enoloo通常的作法是在 C**App::InitInstance()中,修改为这样:
{
//...
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
//...
}
或者,还在 CMainFrame::PreCreateWindow(CREATESTRUCT& cs)中,添加:
{
//...
cs.style |= WS_MAXIMIZE;
//...
}ide
这种作法能产生窗口最大化,但效果是显示的时候窗口从普通大小"闪"到最大化。还有的作法,是先将窗口隐藏,而后再最大化。那么怎样使窗口正常一开始出现就最大化?看看下面的流程,从 C**App::InitInstance()中的ProcessShellCommand(...)开始:
{
//...
//ProcessShellCommand中第一次显示了窗口
if (!ProcessShellCommand(cmdInfo))
return FALSE;
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
//...
}函数
->CWinApp::ProcessShellCommand
->AfxGetApp()->OnCmdMsg(ID_FILE_NEW, 0, NULL, NULL)
//若是你本身处理了ID_FILE_NEW要调用CWinApp::OnFileNew()
->CWinApp::OnFileNew()
->CDocManager::OnFileNew()
->CSingleDocTemplate::OpenDocumentFile //当前文档模板初始化
->CSingleDocTemplate::CreateNewDocument //建立文档
//加载资源并建立主窗口(顺便建立视图),但没显示
->CSingleDocTemplate::CreateNewFrame
->CFrameWnd::InitialUpdateFrame
{
//...
int nCmdShow = -1; // default
CWinApp* pApp = AfxGetApp();
if (pApp != NULL && pApp->m_pMainWnd == this)
{
nCmdShow = pApp->m_nCmdShow; // use the parameter from WinMain
pApp->m_nCmdShow = -1; // set to default after first time
}
ActivateFrame(nCmdShow); //在这里第一次显示窗口
//...
}
->CFrameWnd::ActivateFrame(int nCmdShow)
// nCmdShow is the normal show mode this frame should be in
{
// translate default nCmdShow (-1)
if (nCmdShow == -1)
{
if (!IsWindowVisible())
nCmdShow = SW_SHOWNORMAL;
else if (IsIconic())
nCmdShow = SW_RESTORE;
}this
// bring to top before showing
BringToTop(nCmdShow);spa
if (nCmdShow != -1)
{
// show the window as specified
ShowWindow(nCmdShow); //第一次显示窗口.net
// and finally, bring to top after showing
BringToTop(nCmdShow);
}
}
->***rest
从上面能够看出,CWinApp::ProcessShellCommand函数建立了窗口并显示,这是窗口第一次显示,先于:
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();code
怎么解决问题? 然窗口第一次显示就最大化?orm
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
//在ParseCommandLine以后,ProcessShellCommand以前,添加这句!!!
m_nCmdShow = SW_SHOWMAXIMIZED;
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();
问题解决。
文二:转载http://blog.csdn.net/ziren235/archive/2006/05/19/745651.aspx
这两天在网上搜了好多,都不行,由于都是同一篇文章的转载,因而只好本身慢慢摸索。终于,黄天不负苦心人。
只需将App类InitInstance()函数中m_pMainWnd->ShowWindow()的参数改成SW_SHOWMAXIMIZED便可。
微软MSDN网页中有相关介绍:
MFC Library Reference |
Sets the visibility state of the window.
BOOL ShowWindow( int nCmdShow );
Specifies how the CWnd is to be shown. It must be one of the following values:
Nonzero if the window was previously visible; 0 if the CWnd was previously hidden.