VC窗口最大化方法

一、主框架窗口最大化 一般方法

1.修改App::InitInstance中的

m_pMainWnd->ShowWindow(m_nCmdShow);
m_pMainWnd->UpdateWindow();

m_pMainWnd->ShowWindow(SW_SHOWMAXIMIZED);
m_pMainWnd->UpdateWindow();

2.修改CMainFrame::PreCreateWindow(CREATESTRUCT& cs)

cs.style=...........

 

二、子框架窗口最大化 一般方法

  修改CChildFrame::PreCreateWindow(CREATESTRUCT& cs)

 

 

 

三、一般方法中存在的问题--由窗口多次显示造成闪烁现象--解决方案

  用ClassWizard为CChildFrame类添加ActiveFrame消息  
  void   CChildFrame::ActivateFrame(int   nCmdShow)    
  {  
        if(GetMDIFrame()->MDIGetActive())    
                CMDIChildWnd::ActivateFrame(nCmdShow);    
          else   //   else   open   maximized.    
                  CMDIChildWnd::ActivateFrame(SW_SHOWMAXIMIZED);     
   }    

 

附注:

一、窗口多次显示的过程

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

问题解决。

  cs.style|=WS_VISIBLE|WS_MAXIMIZE;

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值