多文档MFC应用程序全屏效果实现

//实现方案1

在CMainFrame类中添加成员变量,函数

public:

//全屏实现
 WINDOWPLACEMENT m_OldWndPlacement;

 CRect m_FullScreenRect;

 BOOL m_bFullScreen;
 void  OnFullScreen();
 void  OnExitFullScreen();

 

构造函数中初始化m_bFullScreen = FALSE;

 

cpp文件中实现函数



void   CMainFrame::OnFullScreen()    
{  
 if(!m_bFullScreen)  
 {  
  GetWindowPlacement(&m_OldWndPlacement);  
  CRect   WindowRect;  
  GetWindowRect(&WindowRect);  
  CRect   ClientRect;  
  RepositionBars(0,   0xffff,   AFX_IDW_PANE_FIRST,   reposQuery,   &ClientRect);  
  ClientToScreen(&ClientRect);//   获取屏幕的分辨率  
  int   nFullWidth=GetSystemMetrics(SM_CXSCREEN);  
  int   nFullHeight=GetSystemMetrics(SM_CYSCREEN);//   将除控制条外的客户区全屏显示到从(0,0)到(nFullWidth,   nFullHeight)区  
  //域,   将(0,0)和(nFullWidth,   nFullHeight)两个点外扩充原窗口和除控制条之外的   客  
  //户区位置间的差值,   就得到全屏显示的窗口位置  
  m_FullScreenRect.left=WindowRect.left-ClientRect.left-1;  
  m_FullScreenRect.top=WindowRect.top-ClientRect.top-1;  
  m_FullScreenRect.right=WindowRect.right-ClientRect.right+nFullWidth+2;  
  //m_FullScreenRect.bottom=WindowRect.bottom/*-ClientRect.bottom+nFullHeight+2*/;   //这种保留任务栏
  //m_FullScreenRect.bottom=WindowRect.bottom-ClientRect.bottom+nFullHeight+2;    //原始默认
  //m_FullScreenRect.bottom=nFullHeight;           //这样也保留也任务栏
  m_FullScreenRect.bottom=WindowRect.bottom-ClientRect.bottom+nFullHeight+2;
  m_bFullScreen=TRUE;   //   设置全屏显示标志为   TRUE  
  //   进入全屏显示状态  
  WINDOWPLACEMENT   wndpl;  
  wndpl.length=sizeof(WINDOWPLACEMENT);  
  wndpl.flags=0;  
  wndpl.showCmd=SW_SHOWNORMAL;  
  wndpl.rcNormalPosition=m_FullScreenRect;  
  SetWindowPlacement(&wndpl);  
 }  
 //else//恢复显示,可以单独写成一个函数,如果用快捷键可以直接切换  
 //{  
 // m_bFullScreen=false;  
 // ShowWindow(SW_SHOW);  
 // SetWindowPlacement(&m_OldWndPlacement);  
 //}  
 
}  


void   CMainFrame::OnExitFullScreen()    
{  
 if(m_bFullScreen)//恢复显示,可以单独写成一个函数,如果用快捷键可以直接切换  
 {  
  m_bFullScreen=false;  
  ShowWindow(SW_SHOW);  
  SetWindowPlacement(&m_OldWndPlacement);  
 }
}  

视图类中调用访法:


void CXxForm::OnBnClickedBtnFull()
{
 ShowCtrl(SW_HIDE); //设置两状态下,相关控件的显隐状态
 m_bFull = true;
 CMainFrame *myFram = (CMainFrame*)AfxGetMainWnd();
 myFram->OnFullScreen();
}

void CXxForm::OnBnClickedBtnExitfull()
{

 ShowCtrl(SW_SHOW);

 m_bFull = false;
 CMainFrame *myFram = (CMainFrame*)AfxGetMainWnd();
 myFram->OnExitFullScreen();

}
void CXxForm::OnSize(UINT nType, int cx, int cy) //用于动态设置控件的位置
{
 CFormView::OnSize(nType, cx, cy);
 if(!bFlag)
  return;

 CRect rect;
 GetClientRect(&rect);
 if (m_bFull)
 {
  m_ListCtrl.MoveWindow(0, 0, rect.Width(), rect.Height());
  m_ListCtrl.RedrawItems(0, m_ListCtrl.GetItemCount()-1);
 }
 else
 {
  m_ListCtrl.MoveWindow(120, 0, rect.Width()-120, rect.Height());
  m_ListCtrl.RedrawItems(0, m_ListCtrl.GetItemCount()-1);
 }

}

 //实现方案2

 

 

//方案2  .h

 

 BOOL                           m_FullScreen;  
 WINDOWPLACEMENT     m_WPPrev;  
 CRect                 m_FullScreenWindowRect;  
 CToolBar                 *m_pWndFullScreenBar; 
 void  OnFullScreen2();
 void  OnExitFullScreen2();

.cpp


//方案2
void   CMainFrame::OnFullScreen2()  
{  
 RECT   DesktopRect;  
 WINDOWPLACEMENT   WPNew;  

 m_FullScreen   =   m_FullScreen   ?   TRUE   :   FALSE;  

 if(!m_FullScreen)  
 {  
  //   need   to   hide   all   status   bars  
//  m_wndStatusBar.ShowWindow(SW_HIDE);  
  //隐藏工具条  
  m_wndDlgBar.ShowWindow(SW_HIDE);
//  m_wndToolBar.ShowWindow(SW_HIDE);  
  /*m_Layout.ShowWindow(SW_HIDE);  
  m_LayoutGL.ShowWindow(SW_HIDE);*/  

  //   We'll   need   these   to   restore   the   original   state.  
  GetWindowPlacement   (&m_WPPrev);  

  m_WPPrev.length   =   sizeof   m_WPPrev;  

  //Adjust   RECT   to   new   size   of   window  
  ::GetWindowRect(::GetDesktopWindow(),   &DesktopRect);  

  DesktopRect.left   -=   1;  
  DesktopRect.top   -=   1;  
  DesktopRect.bottom   +=   2;  
  DesktopRect.right   +=   2;  

  ::AdjustWindowRectEx(&DesktopRect,   GetStyle(),   TRUE,   GetExStyle());  

  //   Remember   this   for   OnGetMinMaxInfo()  
  m_FullScreenWindowRect   =   DesktopRect;  

  WPNew   =   m_WPPrev;  
  WPNew.showCmd   =     SW_SHOWNORMAL;   //SW_SHOWNORMAL
  WPNew.rcNormalPosition   =   DesktopRect;  

  //m_pWndFullScreenBar=new   CToolBar;  


  //if(!m_pWndFullScreenBar->Create(this,CBRS_SIZE_DYNAMIC|CBRS_FLOATING)   ||  
  // !m_pWndFullScreenBar->LoadToolBar(IDR_FULLSCREEN_GLTOOL))  
  //{  
  // TRACE0("Failed   to   create   toolbar/n");  
  // return;   //   fail   to   create  
  //}  


  don't   allow   the   toolbar   to   dock  
  //m_pWndFullScreenBar->EnableDocking(0);  
  //m_pWndFullScreenBar->SetWindowPos(0,   0,0,   0,0,SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);  
  //m_pWndFullScreenBar->SetWindowText(_T("Hold   Ctrl+F   to   switch   between   normal   and   a   full   screen"));  
  //FloatControlBar(m_pWndFullScreenBar,   CPoint(0,0));  
  //m_pWndFullScreenBar->EnableToolTips(TRUE);  
  m_FullScreen=TRUE;  
  /*m_Workshop.ShowWindow(SW_HIDE);   */
 }  
 //else  
 //{  
 // /*m_pWndFullScreenBar->DestroyWindow();  
 // delete   m_pWndFullScreenBar;   */

 // m_FullScreen=FALSE;  

 // /*m_wndStatusBar.ShowWindow(SW_SHOWNORMAL);  
 // m_wndToolBar.ShowWindow(SW_SHOWNORMAL); */ 
 // /*m_Layout.ShowWindow(SW_SHOWNORMAL);  
 // m_LayoutGL.ShowWindow(SW_SHOWNORMAL);  
 // m_Workshop.ShowWindow(SW_SHOWNORMAL);  */
 // WPNew   =   m_WPPrev;  
 //}  

 SetWindowPlacement(&WPNew);  
}  


void   CMainFrame::OnExitFullScreen2()    

 WINDOWPLACEMENT   WPNew;
 if(m_FullScreen)//恢复显示,可以单独写成一个函数,如果用快捷键可以直接切换  
 {  
  m_FullScreen=false;  
  ShowWindow(SW_SHOW);  
  m_wndDlgBar.ShowWindow(SW_SHOWNORMAL);
  WPNew   =   m_WPPrev;
  SetWindowPlacement(&WPNew);
 }
 
}  

OnGetMinMaxInfo(..)

{

//方案2
 /*if(m_FullScreen)  
 {  
  lpMMI->ptMaxSize.y   =   m_FullScreenWindowRect.Height();  
  lpMMI->ptMaxTrackSize.y   =   lpMMI->ptMaxSize.y;  
  lpMMI->ptMaxSize.x   =   m_FullScreenWindowRect.Width();  
  lpMMI->ptMaxTrackSize.x   =   lpMMI->ptMaxSize.x;  
 }   */
 // CCJFrameWnd::OnGetMinMaxInfo(lpMMI);

}

 

方案2 与方案1 类似 这里注意m_wndDlgBar.ShowWindow(SW_HIDE); 工具栏设置显隐的方法 和  RepositionBars(0,   0xffff,   AFX_IDW_PANE_FIRST,   reposQuery,   &ClientRect);   的用法对比


 //实现方案3

http://hi.baidu.com/stone2108/blog/item/4f181ecb15bdc319bf09e6b0.html

 http://hi.baidu.com/stone2108/blog/item/572e7b17547988074b90a7b1.html

 .h 中

CFullScreen m_CFullScreen;
 void  OnFullScreen3();
 void  OnExitFullScreen3();
 

.cpp中


void   CMainFrame::OnFullScreen3()  
{  
 m_CFullScreen.SetFrameView(GetSafeHwnd(),m_hWndMDIClient);
 //m_CFullScreen.SetFrameView(GetSafeHwnd(),GetActiveView()->GetSafeHwnd());
 m_CFullScreen.FullScreen();

}  


void   CMainFrame::OnExitFullScreen3()    

 m_CFullScreen.Restore();
 
}  
OnGetMinMaxInfo函数中加入

 //CWnd * pView = GetActiveView( ); // 单文档窗口,直接取VIEW   
 // 多文档窗口应该使用 m_hWndMDIClient   
 // 改为下面的样子:   
 /*CWnd * pView = CWnd::FromHandle(m_hWndMDIClient);
 if (pView==NULL)   
 {     
  __super::OnGetMinMaxInfo(lpMMI);     
  return;  
 }  

 CPoint Point(CFullScreen::FullScreenRect(this,pView).Size());
 lpMMI->ptMaxSize = Point;
 lpMMI->ptMaxTrackSize = Point;*/

 

 

  //实现方案4

http://www.phome.asiawww.phome.asia/article/164.html

void FullScan();

 


//方案4
void CMainFrame::FullScan()
{
 static bool isfull=true;
 static CRect m_OldWndRect;
 static CMenu m_OrgMenu;
 if(isfull==true)
 {
  GetWindowRect(&m_OldWndRect);//得到原窗口位置
  隐藏工具栏和状态栏
  //if(m_wndToolBar.IsWindowVisible())
  //{
  // m_wndToolBar.ShowWindow(SW_HIDE);
  //}
  //if(m_wndStatusBar.IsWindowVisible())
  //{
  // m_wndStatusBar.ShowWindow(SW_HIDE);
  //}
  m_wndDlgBar.ShowWindow(SW_HIDE);
  //隐藏菜单栏
  CMenu* pOldMenu=GetMenu();
  m_OrgMenu.Attach(pOldMenu->Detach());
  SetMenu((CMenu*)NULL);
  //隐藏标题栏
  LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  style&=~WS_CAPTION;
  ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  //窗体最前
  ::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_TOPMOST,-1,-1,-1,-1,SWP_NOMOVE|SWP_NOSIZE);
  //全屏
  ShowWindow(SW_SHOWMAXIMIZED);
  RecalcLayout();//重绘框架
  isfull=false;
 }
 else
 {
  //显示工具栏和状态栏
  /*m_wndToolBar.ShowWindow(SW_SHOW);
  m_wndStatusBar.ShowWindow(SW_SHOW);*/
  m_wndDlgBar.ShowWindow(SW_SHOW);
  //显示菜单栏
  SetMenu(&m_OrgMenu);
  m_OrgMenu.Detach();
  //显示标题栏
  LONG style=::GetWindowLong(m_hWnd,GWL_STYLE);
  style|=WS_CAPTION;
  ::SetWindowLong(m_hWnd,GWL_STYLE,style);
  //取消窗体最前
  ::SetWindowPos(AfxGetMainWnd()->m_hWnd,HWND_NOTOPMOST,m_OldWndRect.left,m_OldWndRect.top,m_OldWndRect.right-m_OldWndRect.left,m_OldWndRect.bottom-m_OldWndRect.top,SWP_SHOWWINDOW);
  //恢复
  ShowWindow(SW_SHOWNOACTIVATE);
  MoveWindow(m_OldWndRect);
  RecalcLayout();//重绘框架
  isfull=true;
 }
 return ;
}

 

以上方案对视图全屏实现不彻底,下面有一个窄条没有添满,还望指教!

另外几种方法参考下面网址,还没写上,不过实现后的效果,都如上所示,有一条窄条 !!!?????

 

此问题已解决:把这句话加到view里面的init或者OnSize里面,切换的时候就没有什么问题了GetActiveFrame()->ModifyStyle(WS_CAPTION,0); 去掉子框架的WM_CAPTION

退出全屏后可设置回GetActiveFrame()->ModifyStyle(0,WS_CAPTION);

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值