Fullscreen AND MFC help plz?

Hello, I’m learning OpenGL with MFC and everything works fine. But then I tried to put the fullscreen code from NeHe’s 1st tutorial in my MFC code but nothing happens! I can switch the display mode to another resolution but the window doesn’t go fullscreen. I placed the code in the PreCreate method since the tutorials states that you must switch to fullscreen before you create window. Can anyone help me plz?

Not really - I don’t know MFC. But I do know GLFW (which I am the author of), and it can do fullscreen for you in only one line of code (!). It has some other nice things too, but only you can decide if it’s what you really want:

Besides, the GLFW fullscreen code is really alot better than the NeHe code.

Good luck!

Prico, you can’t put all of NeHe’s code in PreCreateWindow. Some of that code, like the code to maximize a window, needs to go in OnCreate or perhaps OnSize. These functions need to occur after you create a window.

Hmm, I found the problem. I put the code in the PreCreate of my View class and it should be in the MainFrm class. Now it goes well, except that I have a border now. I read somewhere this is due to the CFrameWnd and should not occur when using CWnd, so I’m gonna try to inherit the CMainFrame from a CWnd. I’ll also check out that GLFW if it doesn’t go well.

I think that you should check out GLFW anyway. It may not be what you want (it is not able to do Windows GUI stuff, “only” OpenGL window related management - and some other stuff), but it does solve alot of issues with fullscreen mode. For instance:

  • It has means for dealing with things like ALT+TAB
  • It has some nice code for selecting a best match mode, if an exact match is not available (e.g. you can select a 500x500x17 screen mode, and you would probably get a 640x480x16 mode)
  • It has a function for returning a nice sorted list of screen modes
  • It also works for Unix/X11 (e.g. Linux)


I already did go to your site. I’m still learning OpenGl, and I already tried some frameworks, of which I liked none, so now I’m trying to make my own. It’s just finished and it works great, no problems anymore. So I don’t feel like switching again. And I need MFC for the menu’s and stuff, I don’t know how to do it otherwise.

Try my websites. There is a full screen MFC demo.

I’d like to know what you think of the site below. It is newer and has a counter.

Wait. You can’t inherit CMainWnd from CWnd if you’re using Doc/View. The CView class expects to find a CFrameWnd (and will likely start casting CWnd’s to CFrameWnds). And the CDocument class expects the main window to be a CFrameWnd.

You could instead change the window style of the window that CFrameWnd uses to not have borders. I don’t remember the commands, but they almost certainly go in PreCreateWindow. It probably has something to do with changing values in the argument to that function.

You may want to read my tutorial about OpenGL rendering with MFC: http://hem.passagen.se/emiper/OpenGL/Tutorials/OpenGL_Basic_Framework/index.html

This routine is the one I use to switch to fullscreen in my MFC apps. The idea was taken from somewhere on the web but I can’t remember where (perhaps MSDN ?). Sorry for not being able to credit the author…

The “OnWindowFullscreen” function is the handler for my menu command “Window/Fullscreen”. Note when going fullscreen, I hide the Edit and File toolbars but not the others (this software has something like 10 toolbars). You can hide everything if you want…

Also note that this is not real fullscreen: you simply make the view as large as the screen…

void CMainFrame::OnGetMinMaxInfo(MINMAXINFO FAR* lpMMI)

if (m_bFullScreen)


void CMainFrame::OnWindowFullscreen()
CChildFrame *ActiveFrame;
CRect rectDesktop;

ActiveFrame=(CChildFrame*) GetActiveFrame();
if (m_bFullScreen)
GetWindowPlacement (&m_wpPrev);
m_wpPrev.length = sizeof m_wpPrev;
//Adjust RECT to new size of window
// Remember this for OnGetMinMaxInfo()
wpNew.showCmd = SW_SHOWNORMAL;


Hope this helps !



Thanks for all the help. I solved it by starting with an SDI application, without the Doc/View Architecture. Then I deleted almost every class except the main App. Then I built my own window class derived from CWnd. With some adjustements in the App class, I got a very clean OpenGl framework with all the advantages of MFC ( easy message handling etc)

Originally posted by Eric:
Also note that this is not real fullscreen: you simply make the view as large as the screen…

No, it is real. When you maximize the window, which hasnt got a border, you will have a true full screen mode.

U dont belive? So do sth like that:

  • create maximized window without border;
  • Draw a few frames to be sure it is “hot”.
  • And if you reach eg. 5 frames, draw a quad in a upper-letf corener of the view.
  • SwapBuffers();
  • Draw again a quad, but in a lower-right corner.
  • SwapBuffers() again;
  • And now, dont do anything, just SwapBuffers ().

If you are in fullscreen, you will see a flickering quads, beacuse in a fullscreen frame buffers arent copied but flipped.