Q: How do I create full screen applications?
A: A common technique to create full screen applications is to expand the application window such that window elements like title bar, menu bar etc are beyond the visible region of the display. Only the client area will be visible.
The example shown below modifies the class 'CMainFrame' to achieve the full screen effect. Expanding the application to full screen mode or to normal mode is done by a member function named 'ToggleView()'. The steps to achieve full screen functionality are as follows:
Define a member variable of type 'CRect' (say 'm_rectFull') for the class 'CMainFrame' indicating the size of the window in full screen mode. 'm_rectFull' is calculated in the constructor of 'CMainFrame'.
In the function 'ToggleView()', toggling of the view is carried out. Toolbar and status bar are hidden after storing their visibility status and the window is expanded such that only the client area will be visible. Size and position of the window is also stored before expanding. Calling 'ToggleView()' a second time, the window is displayed in the original size and position again.Code:CMainFrame::CMainFrame() { // TODO: add member initialization code here // Calculates window position and span in full screen mode // Calculates span of display area HDC hDC = ::GetDC(NULL); int XSpan = GetDeviceCaps(hDC, HORZRES); int YSpan = GetDeviceCaps(hDC, VERTRES); ::ReleaseDC(NULL, hDC); // Calculates size of window elements int XBorder = GetSystemMetrics(SM_CXFRAME); int YCaption = GetSystemMetrics(SM_CYCAPTION); int YMenu = GetSystemMetrics(SM_CYMENU); int YBorder = GetSystemMetrics(SM_CYFRAME); // Calculates window origin and span for full screen mode CPoint Origin = CPoint(-XBorder, -YBorder - YCaption - YMenu); XSpan += 2 * XBorder, YSpan += 2 * YBorder + YMenu + YCaption; // Calculates full screen window rectangle rectFull = CRect(Origin, CSize(XSpan, YSpan)); }
Here is the code for 'ToggleView()':
This works for both for SDI and MDI applications.Code:void CMainFrame::ToggleView() { // Previous window status parameters static CRect rectNormal; static boolFull = FALSE, boolStatus, boolTool; // Checks SDI / MDI application if (IsKindOf(RUNTIME_CLASS(CMDIFrameWnd))) { // MDI Application static nCmdShow; // Previous child-window status CMDIChildWnd* pChild = ((CMDIFrameWnd*) this)->MDIGetActive(); if (boolFull) { // Resets child window show status pChild->ShowWindow(nCmdShow); } else { // Gets child window show status WINDOWPLACEMENT WP; pChild->GetWindowPlacement(&WP); nCmdShow = WP.showCmd; // Maximizes child window pChild->ShowWindow(SW_SHOWMAXIMIZED); } } if (boolFull) { // Toggles from full screen to normal mode // Shows status bar and tool bar if they were visible if (boolStatus) m_wndStatusBar.ShowWindow(SW_SHOW); if (boolTool) m_wndToolBar.ShowWindow(SW_SHOW); RecalcLayout(); } else { // Toggles from normal to full screen mode // Saves status bar and toolbar status and hides them if (boolStatus = m_wndStatusBar.IsWindowVisible()) m_wndStatusBar.ShowWindow(SW_HIDE); if (boolTool = m_wndToolBar.IsWindowVisible()) m_wndToolBar.ShowWindow(SW_HIDE); RecalcLayout(); // Saves current window position and size GetWindowRect(rectNormal); } // Shows window in full screen / normal mode MoveWindow(boolFull ? rectNormal : rectFull); // Toggles window status boolFull = !boolFull; }
We have to set the maximum size and position of the window by overriding the message handler function 'CMainFrame::OnGetMinMaxInfo()', handling the 'WM_GETMINMAXINFO' message. Here is the message handler function:
With this, a SDI application will expand to full screen mode on calling 'ToggleView()'. One can call this function from anywhere in the application byCode:void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { // TODO: Add your message handler code here and/or call default // Resets position and maximum window size for full screen mode lpMMI->ptMaxPosition = rectFull.TopLeft(); lpMMI->ptMaxTrackSize = lpMMI->ptMaxSize = CPoint(rectFull.Size()); CMDIFrameWnd::OnGetMinMaxInfo(lpMMI); }
One has to include the file 'MainFrm.h' if the 'CMainFrame' class is not defined where you make the function call.Code:((CMainFrame*) AfxGetMainWnd())->ToggleView();
For an MDI application, you have to handle the 'WM_GETMINMAXINFO' message for the 'CChildFrame' class also to effect the expansion properly. 'CChildFrame::OnGetMinMaxInfo()' can be implemented as
Code:#include "MainFrm.h" void CChildFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI) { // TODO: Add your message handler code here and/or call default // Resets position and maximum child window size for full screen mode CSize Span = ((CMainFrame*) AfxGetMainWnd())->rectFull.Size(); lpMMI->ptMaxPosition = ((CMainFrame*) AfxGetMainWnd())->rectFull.TopLeft(); lpMMI->ptMaxTrackSize = lpMMI->ptMaxSize = CPoint(Span.cx, Span.cy); CMDIChildWnd::OnGetMinMaxInfo(lpMMI); }




Reply With Quote