Sign in to follow this  
SiS-Shadowman

MFC application and SDI layout [solved]

Recommended Posts

SiS-Shadowman    359
I've moved my level editor from a Dialog project to a SDI project in order to learn how to deal with SDI/MDI as well. However I now remember why I didn't want to learn those things in the first place. Here is my problem: From what I know, when a new file gets loaded or another one opened, the CDocument is created from somewhere within the CDocTemplate, but before the CFormView (or whatever view I choose). And that's a big problem for me. I need CFormView to be created before the document is loaded. I'm initializing a game engine that is in need of the CWnd to draw on (wich will be an item on the form). Therefore I'm creating my engine just once on the CFormView::OnInitialUpdate function (I can skip every further call, cause the CFormView is never destroyed in an SDI application, just like the CDocument). Loading my document has to happen after that, to ensure that the directx device is valid. I could easily just call the loading function from within CFormView::OnInitialUpdate, however I cannot signal a failure to the framework. Is there a way to achieve what I want? *edit* I solved the problem. Was not easy, but it is possible. I realized I had to overwrite the CSingleDocTemplate::OpenDocumentFile function to call OnInitialUpdate before calling CDocument::OnOpenDocument/OnNewDocument. The source code can be found in "C:\Program Files\Microsoft Visual Studio 9.0\VC\atlmfc\src\mfc\docsingl.cpp". I've just copied the code from the funtion into my derrived CSingleDocTemplateEx class and moved the InitialUpdateFrame call in front of the CDocument::On*Document block. That solved my problem :) [Edited by - SiS-Shadowman on October 25, 2008 6:49:17 AM]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this