Solved

Open windows in MDI applications

Posted on 1999-01-26
6
189 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
  • 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Creating Labels and Frequency list style reports in SAS code 9 98
Tab names are off by one 5 54
sumNumber challenge 16 122
matchUp  challenge 6 64
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

810 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