[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Open windows in MDI applications

Posted on 1999-01-26
6
Medium Priority
?
196 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 300 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Survive A High-Traffic Event with Percona

Your application or website rely on your database to deliver information about products and services to your customers. You can’t afford to have your database lose performance, lose availability or become unresponsive – even for just a few minutes.

Question has a verified solution.

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

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses

656 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