jrmcg
asked on
Open windows in MDI applications
I have a MDI application that uses 4 or 5 different Document templates. I want to be able to check to see if any of these windows are open at some point and if they are I want to close them. I want to do this from my MainApp Class. I know I need to use GetActiveView and all that but I would like some exact code to use. They don't need to be searched for in any particular order but depending on which documents are open, I may need to access some functions inside the View class of the document. I guess what I need is a methodical way of searching through all documents that are open in an application and tell them to close, keeping in mind that the documents will be from different classes.
Thanks
J.R.
Thanks
J.R.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks--
Ok - That works to a point...
This will set the view to NULL but the window remains.
In the meantime the Child class of the view has DialogBars that are accessing variables inside the view. So you can see the problem there. The DialogBar tries to access a variable inside the view which no longer exists.
Inside the code you gave me - where can I get the child class or Frame so that I can send the close message there which will in turn close the document and view?
Right now I have coded the ChildClass Dialog Bar ON_UPDATE_COMMAND_UI
message to check to see if the view is NULL, if it is then I send the close message to the child frame window which closes the window. That is kind of going around the elbow to get to the ear. How can I do that in one shot inside the code you posted?
Either way I will accept your answer - but if you can help me out there I would appreciate it.
Thanks - J.R.
Ok - That works to a point...
This will set the view to NULL but the window remains.
In the meantime the Child class of the view has DialogBars that are accessing variables inside the view. So you can see the problem there. The DialogBar tries to access a variable inside the view which no longer exists.
Inside the code you gave me - where can I get the child class or Frame so that I can send the close message there which will in turn close the document and view?
Right now I have coded the ChildClass Dialog Bar ON_UPDATE_COMMAND_UI
message to check to see if the view is NULL, if it is then I send the close message to the child frame window which closes the window. That is kind of going around the elbow to get to the ear. How can I do that in one shot inside the code you posted?
Either way I will accept your answer - but if you can help me out there I would appreciate it.
Thanks - J.R.
Try to answer this, but let me first write a small test program.
Wait for my answer, please.
Bye,
atari
Wait for my answer, please.
Bye,
atari
Small code snippets for closing doc's from CMainFrame:
You have to implement this only in my above code, which scans
all the documents from CMainFrame:
void CMainFrame::FileClose()
{
CYourDocument *doc=(CYourDocument *)(GetActiveFrame()->GetAc tiveView() ->GetDocum ent());
doc->OnCloseDocument();
}
which shows, that OnCloseDocument() closes the document, that was exactly, what you wanted.
Bye,
atari
You have to implement this only in my above code, which scans
all the documents from CMainFrame:
void CMainFrame::FileClose()
{
CYourDocument *doc=(CYourDocument *)(GetActiveFrame()->GetAc
doc->OnCloseDocument();
}
which shows, that OnCloseDocument() closes the document, that was exactly, what you wanted.
Bye,
atari
ASKER
Thank you.
J.R.
J.R.
((YourView *)view)->SendMessage(WM_CL