Solved

Open windows in MDI applications

Posted on 1999-01-26
6
191 Views
Last Modified: 2013-11-20
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.
0
Comment
Question by:jrmcg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 1

Accepted Solution

by:
atari earned 100 total points
ID: 1328348
Try this:

POSITION templatepos,documentpos,viewpos;
CDocTemplate *templt=NULL;
CDocument *document=NULL;
CView *view=NULL;

templatepos=App()->GetFirstDocTemplatePosition();
while (templatepos)
 {
    templt=((YourProgram *)AfxGetApp())->GetNextDocTemplate(templatepos);
    documentpos=templt->GetFirstDocPosition();
    while (documentpos)
    {
      document=templt->GetNextDoc(documentpos);      
      viewpos=document->GetFirstViewPosition();
      while (viewpos)
      {
        view=(CView *)(document->GetNextView(viewpos));
        if (view->IsKindOf(RUNTIME_CLASS(YourView)))
            ((CGraphView *)view)->SendMessage(WM_CLOSE);
      }
     }
  }

And modify if you want to test for a certain document then you must insert at the
appropriate position: if (document->IsKindOf(RUNTIME_CLASS(YourDocument))

Hope this helps,
bye,
atari
0
 
LVL 1

Expert Comment

by:atari
ID: 1328349
Sorry I made a mistake: it must be
((YourView *)view)->SendMessage(WM_CLOSE);
0
 
LVL 2

Author Comment

by:jrmcg
ID: 1328350
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.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Expert Comment

by:atari
ID: 1328351
Try to answer this, but let me first write a small test program.
Wait for my answer, please.
Bye,
atari
0
 
LVL 1

Expert Comment

by:atari
ID: 1328352
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()->GetActiveView()->GetDocument());
doc->OnCloseDocument();
}

which shows, that OnCloseDocument() closes the document, that was exactly, what you wanted.

Bye,
atari
0
 
LVL 2

Author Comment

by:jrmcg
ID: 1328353
Thank you.

J.R.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Installing Microsoft R server on REDHAT or SUSE Linux 4 152
Unix / Linux grid computing 5 169
maxBlock challenge 30 146
"Black Box" Testing of Control System Software 2 98
In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
In this post we will learn different types of Android Layout and some basics of an Android App.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question