Simple MFC question(or is it?)

Started by
14 comments, last by CProgrammer 20 years, 1 month ago
quote:Original post by CProgrammer
According to all the post the following idea seems feasable:
I use a boolean in the CDocument derived class to save wether the programm was opened with a file. In OnUpdate or so in CView I then chack that value and load. I could use fstream for that, but isnt there a command like ''Load(char *file)'' to recall the Serizlize function and tell it to load the file?
-CProgrammer


I was not suggesting that you move the load code to your CView class. Your CDocument class should not need to access the CView window handle during a document load. I think you need to re-think what you''re trying to accomplish. Why does your CDocument need access to a window handle? Once the document is loaded and the view is created, the view can then take care of updating whatever it needs to based on the document.
Advertisement
But how will the CView class know when a new document was created. Is there perhaps a fucntion for the CView class.
Sorry for my lack on MFC knowledge
-CProgrammer
I'm not to sure but, here goes:

The application object that overrides CWinApp, in the cpp file also overrides the InitiInstance( ) method. After the the lines of code you should have this:

CMyApp::InitInstance( )
{
...

CCommandLineInfo cmdInfo;
ParseCommandLine ( cmdInfo ); // supposed to get the command line

if ( !ProcessShellCommand( cmdInfo ) ) // do whatever the command line asks: printing, opening, bla bla
return FALSE;

...


return TRUE;
}

I hope that puts you in the right path. ProcessShellCommand is supposed to do exactly that it says, unless I'm wrong.


[edited by - brownbean on March 1, 2004 12:06:48 AM]
My understanding of the Document/View architecture is that the document is responsible for loading the data, and then the view is responsible for .. well .. presenting a view into the document. What I normally do is use the CDocument::OnUpdateAllViews() function to post hints to the views to help them know when they need to do work. Maybe that will work for you. Create an enum of all the hint types and use that as the hint for your views.

I''m still a little unclear why you can''t just use CView::OnInitialUpdate() to create the binding from your CView derived class into your CDocument data.

Can you elaborate on why you need to do this?
Well basically I have a static Functin in the CView class which is called by CDocument class when a project is being created(the function params tell CView what to do). Now since i''m accessing CView through CDocument I cant access CDocument from CView. This is an MFC-DirectX app. So initializing DirectX must happen before any project is loaded.
I guess the problem is as been stated that I need to delete the static function and instead have some message function in CView(afx_msg something) which is called when a Project is created.
UpdateAllViews() seems to be the perfect solution. I''m gonna go fix that now. Thanks a bunch.
-CProgrammer
You should be able to get to the active document of a view using the following code in your CView:
	CMyDocument* pDoc = GetDocument();	ASSERT_VALID(pDoc);

That will give you a pointer to the valid document, and check that the document pointer is valid.

This topic is closed to new replies.

Advertisement