中国IT动力,最新最全的IT技术教程
最新100篇 | 推荐100篇 | 专题100篇 | 排行榜 | 搜索 | 在线API文档 | 网通镜像
首 页 | 程序开发 | 操作系统 | 软件应用 | 图形图象 | 网络应用 | 精文荟萃 | 教育认证 | 硬件维护 | 未整理篇 | 站长教程
ASP JS PHP工程 ASP.NET 网站建设 UML J2EESUN .NET VC VB VFP 网络维护 数据库 DB2 SQL2000 Oracle Mysql
服务器 Win2000 Office C DreamWeaver FireWorks Flash PhotoShop 上网宝典 CorelDraw 协议大全 网络安全 微软认证
硬件维护  CPU  主板  硬盘  内存  显卡  显示器  键盘鼠标  声卡音箱  打印机  机箱电源  BIOS  网卡  C#  Java  Delphi  vs.net2005
  当前位置:> 程序开发 > 编程语言 > 综合其它
【MFC】doc_view结构中让窗口一开始就最大化探讨 选择自 enoloo 的 Blog
作者:未知 时间:2005-09-13 23:33 出处:Blog.ChinaUnix.net 责编:chinaitpower
              摘要:【MFC】doc_view结构中让窗口一开始就最大化探讨 选择自 enoloo 的 Blog

【MFC】doc_view结构中让窗口一开始就最大

and 一开始不打开文档

开始不打开文档

SDI应用,但每次启动时它都会打开一个文档("untitled"),如何不让它打开该文档呢?

看看InitInstance函数中有没有关于OnFileNew的调用,去掉它即可.

MDI在CxxApp::InitInstance()中if (!ProcessShellCommand(cmdInfo))前加上,cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;

窗口一开始就最大

一般的做法是在 C**App::InitInstance()中,修改成这样:
{
 //...
 m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
 m_pMainWnd->UpdateWindow();
 //...
}
或者,还在 CMainFrame::PreCreateWindow(CREATESTRUCT& cs)中,添加:
{
 //...
 cs.style |= WS_MAXIMIZE;
 //...
}

这种做法能产生窗口最大化,但效果是显示的时候窗口从普通大小"闪"到最大化。还有的做法,是先将窗口隐藏,然后再最大化。那么怎样使窗口正常一开始出现就最大化?看看下面的流程,从 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;
 }

 // bring to top before showing
 BringToTop(nCmdShow);

 if (nCmdShow != -1)
 {
  // show the window as specified
  ShowWindow(nCmdShow); 
//第一次显示窗口

  // and finally, bring to top after showing
  BringToTop(nCmdShow);
 }
  }
->***

从上面可以看出,CWinApp::ProcessShellCommand函数创建了窗口并显示,这是窗口第一次显示,先于:
 m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
 m_pMainWnd->UpdateWindow();


怎么解决问题? 然窗口第一次显示就最大化?

 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();

问题解决。

 cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;

 m_nCmdShow = SW_SHOWMAXIMIZED; 
 // Dispatch commands specified on the command line
 if (!ProcessShellCommand(cmdInfo))

关闭本页
 
首页 | 投资与合作 | 服务条款 | 隐私政策 | 收藏本站 | 设为首页 | 新用户注册 | 免责声明 | 使用帮助
Copyright ©2005-2008 chinaitpower.com All rights reserved. www.chinaitpower.com 版权所有