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

x
?
Solved

OnIdle processing for specific view in an MDI application

Posted on 2006-10-29
4
Medium Priority
?
442 Views
Last Modified: 2013-11-20
I have an MDI application that has three views (see code excerpt below). Each view may be opened independently and are not automatically opened when the appplication starts. I want to do some background tasks on a specifc view only if the view has been activated and the message pump is idle. I know that I need to use the virtual OnIdle function from withing the CWinApp derived class.

My question is how do I access the proper view and call the appropriate background task. In this case the 'COrderEntryView'

BOOL COrderEntryApp::InitInstance() // partial code below...

                pOrderViewTemplate = new CMultiDocTemplate(
            IDR_ORDERETYPE,
            RUNTIME_CLASS(COrderEntryDoc),
            RUNTIME_CLASS(CChildFrame), // custom MDI child frame
            RUNTIME_CLASS(COrderEntryView));
      AddDocTemplate(pOrderViewTemplate);

      pLineSearchTemplate = new CMultiDocTemplate(
            IDR_LINEVIEWTYPE,
            RUNTIME_CLASS(CLineSearchDoc),
            RUNTIME_CLASS(CLineSearchFrame), // custom MDI child frame
            RUNTIME_CLASS(CLineSearchview));
      AddDocTemplate(pLineSearchTemplate);

      pReportViewTemplate = new CMultiDocTemplate(
            IDR_REPORTVIEWTYPE,
            RUNTIME_CLASS(CReportsDoc),
            RUNTIME_CLASS(CReportsFrame), // custom MDI child frame
            RUNTIME_CLASS(CReportsView));
      AddDocTemplate(pReportViewTemplate);

///////////////////////////////////////////////////////////////////////////////////////////////

BOOL COrderEntryApp::OnIdle(LONG lCount)
{

      if (CWinApp::OnIdle(lCount))
            return TRUE;  

               // If there are no messages in the pump I want to call a function within a particular view to do background processing
              //  For Example COrderEntryView::MyBackGroundTask()


               return TRUE;
}
0
Comment
Question by:carlmahon
[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
  • 2
4 Comments
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 17832101
Why not use a thread in the view?
0
 
LVL 22

Accepted Solution

by:
mahesh1402 earned 1400 total points
ID: 17832726
>>My question is how do I access the proper view and call the appropriate background task. In this case the 'COrderEntryView'

You can call  GetActiveView( ) from your CFramWnd class to get a pointer to your active view.  you have to cast your pointer from  GetActiveView( ) to your view class.

        CFrameWnd *pFrame = (CFrameWnd *) AfxGetMainWnd();
        COrderEntryView *pView = (COrderEntryView *) pFrame->GetActiveView();
   
-Otherwise you may use following function to get instance of 'Specific' view from your OnIdle function :

CWnd *FindClassView(CRuntimeClass *pViewClass)
{
    CWinApp* pApp = AfxGetApp();        
    CDocTemplate* pTemplate;
    POSITION pos = pApp->GetFirstDocTemplatePosition();
    while (pos != NULL)
    {
        pTemplate = pApp->GetNextDocTemplate(pos);
        ASSERT(pTemplate);

        POSITION pos2 = pTemplate->GetFirstDocPosition();
        while (pos2)
        {
            CDocument* pDoc = pTemplate->GetNextDoc(pos2);
            ASSERT(pDoc);

            POSITION pos3 = pDoc->GetFirstViewPosition();
            while (pos3 != NULL)
            {
                CView* pView = pDoc->GetNextView(pos3);
                ASSERT(pView);
                if (::IsWindow(pView->GetSafeHwnd()))
                {
                    if(pView->IsKindOf(pViewClass))
                    {
                        return pView;
                    }                    
                }
            }
        }
    }
    return NULL;
}


Use it like :---

BOOL COrderEntryApp::OnIdle(LONG lCount)
{

     if (CWinApp::OnIdle(lCount))
          return TRUE;  

    COrderEntryView *pView;
    pView=static_cast<COrderEntryView *>(FindClassView(RUNTIME_CLASS(COrderEntryView)));

   // Invoke function :
  if(pView)
    pView->MyFunction(...)
   
  //.......
 
  return TRUE;
}

-MAHESH
0
 
LVL 4

Author Comment

by:carlmahon
ID: 17839113
MAHESH - Thanks for the code! I knew what had to be done I was just unsure of the casting to get the specific view I needed. The code plugged in and worked perfectly. I will award all points to you.

Thanks for other responses, I had thought about the thread as well too, but since the questions was how to to the onIdle() I will not split points for other alternatives.
0
 
LVL 45

Expert Comment

by:AndyAinscow
ID: 17840218
Fine by me - I mentioned it in case you either hadn't thought of it or just were afraid (too complex to code) of it.
0

Featured Post

What’s Wrong with Your Cloud Strategy ?

Even as many CIOs are embracing a cloud-first strategy, the reality is that moving to the cloud is a lengthy process and the end-state is likely to be a blend of multiple clouds—public and private. Learn why multicloud solutions matter in this webinar by Nimble Storage.

Question has a verified solution.

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

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

649 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