Window mode switching in MFC
I''ve been searching MSDN library for about the last hour and a half, as well as looking for articles online about this - to no avail.
Here''s my deal: I''m writing myself a template sort of thing in super-stripped down MFC (similar to a template I''ve been using some time for software animations) for my future OpenGL projects. This is not an OpenGL swpecific question however, as if this were the case it would be in the appropriate forum.
The trouble I''m having is that I need to be able to switch between window mode and fullscreen mode (and also in fullscreen mode between resolutions). I know how to switch resolutions - note that this is NOT the question.
I know how to do this in Win32. I don''t want to use pure Win32 code for this, I am, as before stated, writing an MFC template for this. I''ve tried doing things very similar to what I would do in Win32 in MFC instead, but as we all know MFC throws some often nasty kinks in that abstract from us the true mechanics of a situation - that is where my problem lies.
So, in general, this is what I''m doing (after this I will describe exactly what I need to be able to DO).
1. Rewrite CWnd::Create. In here I use AfxRegisterWndClass to set up a window. Initially it''s however I specify (right now I have the code asking me with a dialog box if I want fullscreen or window, eventually it could be anything of course). If I want fullscreen, I store extended style and standard styles in a variable, switch resolution to whatever my window size would have been, set window position (0,0)-(width,height) etc. If i chose windowed mode, I store the extended and standard styles appropriately here as well. After this, I use AdjustWindowRectEx so that I am sure to have a client area of exactly width x height in the case I selected windowed mode. After all this, I use CreateEx with the style variables I mentioned before and of course teh return value from AfxRegisterWndClass. I then do all the wgl stuff, setting pixel formats, and call an InitGL function that I wrote that performs simple operations that I want it to This doesn''t really matter, clearly.
2. Now, assume this has all gone smoothly, and an event occurs at which I want to switch from fullscreen to window or vice verse. In Win32, conventionally, I would release my dc, destroy my window, and unregister my window class, then basically redo my creation stuff with different settings. However, I can''t seem to get THIS part working right in MFC. What I do when said event occurs is the following: I call a KillWindow function which restores resolution if necessary, kills rendering context, calls CloseWindow(), and that''s it. Back in the event code, I flip a fullscreen flag, and re-call Create(). While this makes sense SOMEWHAT, it has some problems. First off, I''m not sure if this really unregisters the window class. The reason I''m not sure of this is because... say the event happens, and I was in fullscreen mode. I force the event that switches the mode - the resolution restores fine, everything works well, and the window shows. HOWEVER, looking in the taskbar reveals what appears to be TWO of the project running. When I force a WM_CLOSE, the program cleans up properly and exits (both visible "instances" of the program disappearing).
Does anyone know what could be the trouble here? What is the usual flowpath for destroying the registered window class and recreating it, or is there a simpler way to just change the window styles without destroying/recreating ANYTHING?
Thanks a bunch,
Jay
I''m not sure what your question is, so I''m just guessing.
Maybe this link might give you an idea:
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=00000993&forum=3dtheory&id=-1
I used this method in my OpenGL windowing code when toggling fullscreen.
Maybe this link might give you an idea:
http://www.flipcode.com/cgi-bin/msg.cgi?showThread=00000993&forum=3dtheory&id=-1
I used this method in my OpenGL windowing code when toggling fullscreen.
That''s basically what I''d do in pure Win32 C code... much like what is shown in the NeHe tutorials. The trouble I''m having is that I can''t unregister the window class and completely "start over" from scratch.
Oh, I haven''t looked at HeNe for a while, but I seem to remember he was always doing the create/destroy thing.
This code isn''t destroying/recreating anything, they just resize the window to cover the whole desktop and change the window styles so its now a fullscreen window. Didn''t you want a "simpler way to just change the window styles without destroying/recreating ANYTHING?"
Sorry I couldn''t be of assistance.
This code isn''t destroying/recreating anything, they just resize the window to cover the whole desktop and change the window styles so its now a fullscreen window. Didn''t you want a "simpler way to just change the window styles without destroying/recreating ANYTHING?"
Sorry I couldn''t be of assistance.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement