Udostępnij za pośrednictwem


How to add Full Screen Mode in your MFC app (Visual Studio 2008 or later)?

Recently I need to add full screen mode for one of my MFC projects. Like what we did usually, my first impression is to hide the tool bar of main frame and expand the size of view. Thus, I need to calculate the system screen size (GetSystemMetrics() API), to calculate the current size of windows frame (GetWindowRect() API), and to reset the location/coordinator of main frame( SetWindowPos() API). 

It is not hard, but it really took me much time on implementating it. Then, I tested it and found the full screen mode can be displayed. However, when I tried to go back to normal size, my Ribbonbar dissappeared! Thus, I realized that I need to do more work about Ribbon bar. When I read the documentation on MSDN, fortunately I found a very interesting class "CFullScreenImpl" class in MFC. https://msdn.microsoft.com/en-us/library/cc308980.aspx

Thus, I tried it in my Visual Studio 2010. Easy!!! You only need to do three things:

  1. Create a button or check box or any control (you want users to click) to get full screen mode. Remmember its ID, for example, ID_VIEW_FULLSCREEN
  2. In MainFrm.cpp, at the end of OnCreate() API, write two lines

int

CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)

{

............

// enable full screen mode

EnableFullScreenMode (ID_VIEW_FULLSCREEN); // the ID of your control you created in step 1

EnableFullScreenMainMenu(FALSE);

return 0;

}

        3.  In MainFrm.cpp, add an event handler function for your control in step (1), and add ShowFullScreeen(). 

void

CMainFrame::OnViewFullscreen()

{

ShowFullScreen();

}

 That is it! Very simple! I hope more and more people can enjoy it!

Comments

  • Anonymous
    May 28, 2010
    realy?VS2008  i can not achieve it

  • Anonymous
    January 10, 2011
    Really!, you have to use either CMDIFrameWndEx or CFrameWndEx.

  • Anonymous
    November 22, 2011
    How to set Full Screen Mode like as when we use Acrobat to display a pdf file with mode Full Screen. In this mode, all of elements of the main frame are hidden, only show the document page. Thank you!