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
Solved

Open windows in MDI applications

Posted on 1999-01-26
6
190 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
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Include multiple hostnames in this command? 3 55
no14 challenge 14 70
zeroMAx challenge 20 112
FizzBuzz challenge 9 82
Introduction: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
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.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

860 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