Solved

Open windows in MDI applications

Posted on 1999-01-26
6
186 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
Comment Utility
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
Comment Utility
Sorry I made a mistake: it must be
((YourView *)view)->SendMessage(WM_CLOSE);
0
 
LVL 2

Author Comment

by:jrmcg
Comment Utility
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
Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

 
LVL 1

Expert Comment

by:atari
Comment Utility
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
Comment Utility
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
Comment Utility
Thank you.

J.R.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now