MFC General: How do I create full screen applications?
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: MFC General: How do I create full screen applications?

Threaded View

  1. #1
    Join Date
    Feb 2000
    Location
    Indore, India
    Posts
    1,046

    MFC General: How do I create full screen applications?

    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'.

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

    Here is the code for 'ToggleView()':

    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;
    }
    This works for both for SDI and MDI applications.

    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:

    Code:
    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);
    }
    With this, a SDI application will expand to full screen mode on calling 'ToggleView()'. One can call this function from anywhere in the application by

    Code:
    ((CMainFrame*) AfxGetMainWnd())->ToggleView();
    One has to include the file 'MainFrm.h' if the 'CMainFrame' class is not defined where you make the function call.

    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);
    }
    Last edited by Andreas Masur; November 13th, 2005 at 08:53 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center