站内搜索

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

  在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);
  }

  • 上一篇:代理服务器的源程序
  • 下一篇:瞎侃编译和解释