| 订阅 | 在线投稿
分享
 
 
 

为MFC应用程序添全屏幕显示功能

来源:互联网网民  宽屏版  评论
2006-12-16 17:27:41

在CMainFrame类中添加下列成员变量和成员函数(使用ClassWizard),下面是这些变量和函数的功能说明:

成员变量:

BOOL m_bFullScreen; //全屏幕显示标志

CRect m_FullScreenWindowRect; //全屏幕显示窗口Rect

WINDOWPLACEMENT m_wpPrev; //用于保存正常视图时的窗口位置信息

CToolBar * m_wndFullScreenBar; //全屏幕显示时的浮动工具条

成员函数:

void OnMenuFullscreen(); //全屏幕显示的处理函数

void OnGetMinMaxInfo(); //捕获WM_GETMINMAXINFO消息以便允许你增加窗口大小

void OnUpdateViewFullScreen(); //更新“全屏幕显示”菜单的状态

源码

void CMainFrame::OnMenuFullscreen()

{//全屏幕显示的处理函数

RECT rectDesktop;

WINDOWPLACEMENT wpNew;

if (m_bFullScreen)

{//全屏幕显示模式

//隐藏工具条和状态条

m_wndStatusBar.ShowWindow(SW_HIDE);

m_wndToolBar.ShowWindow(SW_HIDE);

//保存正常视图时的窗口位置信息以便恢复原来状态

GetWindowPlacement (&m_wpPrev);

m_wpPrev.length = sizeof m_wpPrev;

//调整RECT为新的窗口尺寸

::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );

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

//保存RECT以便OnGetMinMaxInfo()使用

m_FullScreenWindowRect = rectDesktop;

wpNew = m_wpPrev;

wpNew.showCmd = SW_SHOWNORMAL;

wpNew.rcNormalPosition = rectDesktop;

//生成新的工具条

m_wndFullScreenBar=new CToolBar;

if(!m_wndFullScreenBar->Create(this, CBRS_SIZE_DYNAMIC|CBRS_FLOATING)

|| !m_wndFullScreenBar->LoadToolBar(IDR_FULLSCREEN))

{

TRACE0("Failed to create toolbar\n");

return; // fail to create

}

||||||//不允许工具条停泊

m_wndFullScreenBar->EnableDocking(FALSE);

m_wndFullScreenBar->SetWindowPos(0,100,100,0,0,SWP_NOSIZE

|SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);

m_wndFullScreenBar->SetWindowText(_T("全屏幕显示"));

FloatControlBar(m_wndFullScreenBar, CPoint(100,100));

m_bFullScreen=TRUE;

}

else

{//正常显示模式

//删除全屏幕工具条

m_wndFullScreenBar->DestroyWindow();

delete m_wndFullScreenBar;

m_bFullScreen=FALSE;

//恢复工具条和状态条

m_wndStatusBar.ShowWindow(SW_SHOWNORMAL);

m_wndToolBar.ShowWindow(SW_SHOWNORMAL);

wpNew = m_wpPrev;

}

//设置窗口显示状态

SetWindowPlacement ( &wpNew );

}

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)

{

if (m_bFullScreen)

{

lpMMI->ptMaxSize.y = m_FullScreenWindowRect.Height();

lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;

lpMMI->ptMaxSize.x = m_FullScreenWindowRect.Width();

lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;

}

}

void CMainFrame::OnUpdateMenuFullscreen(CCmdUI* pCmdUI)

{//更新菜单的状态

pCmdUI->Enable();

pCmdUI->SetCheck(m_bFullScreen);

}

 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
  在CMainFrame类中添加下列成员变量和成员函数(使用ClassWizard),下面是这些变量和函数的功能说明:   成员变量:   BOOL m_bFullScreen; //全屏幕显示标志   CRect m_FullScreenWindowRect; //全屏幕显示窗口Rect   WINDOWPLACEMENT m_wpPrev; //用于保存正常视图时的窗口位置信息   CToolBar * m_wndFullScreenBar; //全屏幕显示时的浮动工具条   成员函数:   void OnMenuFullscreen(); //全屏幕显示的处理函数   void OnGetMinMaxInfo(); //捕获WM_GETMINMAXINFO消息以便允许你增加窗口大小   void OnUpdateViewFullScreen(); //更新“全屏幕显示”菜单的状态   源码   void CMainFrame::OnMenuFullscreen()   {//全屏幕显示的处理函数   RECT rectDesktop;   WINDOWPLACEMENT wpNew;   if (m_bFullScreen)   {//全屏幕显示模式   //隐藏工具条和状态条   m_wndStatusBar.ShowWindow(SW_HIDE);   m_wndToolBar.ShowWindow(SW_HIDE);   //保存正常视图时的窗口位置信息以便恢复原来状态   GetWindowPlacement (&m_wpPrev);   m_wpPrev.length = sizeof m_wpPrev;   //调整RECT为新的窗口尺寸   ::GetWindowRect ( ::GetDesktopWindow(), &rectDesktop );   ::AdjustWindowRectEx(&rectDesktop, GetStyle(), TRUE, GetExStyle());   //保存RECT以便OnGetMinMaxInfo()使用   m_FullScreenWindowRect = rectDesktop;   wpNew = m_wpPrev;   wpNew.showCmd = SW_SHOWNORMAL;   wpNew.rcNormalPosition = rectDesktop;   //生成新的工具条   m_wndFullScreenBar=new CToolBar;   if(!m_wndFullScreenBar->Create(this, CBRS_SIZE_DYNAMIC|CBRS_FLOATING)   || !m_wndFullScreenBar->LoadToolBar(IDR_FULLSCREEN))   {   TRACE0("Failed to create toolbar\n");   return; // fail to create   } ||||||  //不允许工具条停泊   m_wndFullScreenBar->EnableDocking(FALSE);   m_wndFullScreenBar->SetWindowPos(0,100,100,0,0,SWP_NOSIZE   |SWP_NOZORDER|SWP_NOACTIVATE|SWP_SHOWWINDOW);   m_wndFullScreenBar->SetWindowText(_T("全屏幕显示"));   FloatControlBar(m_wndFullScreenBar, CPoint(100,100));   m_bFullScreen=TRUE;   }   else   {//正常显示模式   //删除全屏幕工具条   m_wndFullScreenBar->DestroyWindow();   delete m_wndFullScreenBar;   m_bFullScreen=FALSE;   //恢复工具条和状态条   m_wndStatusBar.ShowWindow(SW_SHOWNORMAL);   m_wndToolBar.ShowWindow(SW_SHOWNORMAL);   wpNew = m_wpPrev;   }   //设置窗口显示状态   SetWindowPlacement ( &wpNew );   }   void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)   {   if (m_bFullScreen)   {   lpMMI->ptMaxSize.y = m_FullScreenWindowRect.Height();   lpMMI->ptMaxTrackSize.y = lpMMI->ptMaxSize.y;   lpMMI->ptMaxSize.x = m_FullScreenWindowRect.Width();   lpMMI->ptMaxTrackSize.x = lpMMI->ptMaxSize.x;   }   }   void CMainFrame::OnUpdateMenuFullscreen(CCmdUI* pCmdUI)   {//更新菜单的状态   pCmdUI->Enable();   pCmdUI->SetCheck(m_bFullScreen);   }
󰈣󰈤
 
 
 
>>返回首页<<
 
 热帖排行
 
 
静静地坐在废墟上,四周的荒凉一望无际,忽然觉得,凄凉也很美
©2005- 王朝网络 版权所有