Message pump question
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7

Thread: Message pump question

  1. #1
    Join Date
    Dec 2010
    Posts
    587

    Message pump question

    Code:
    BOOL CMDIApp::OnIdle(LONG lCount)
    {
    	// TODO: Add your specialized code here and/or call the base class
    	if (app)
    	{
    		 app->Run();
    	}
    
    	return CWinApp::OnIdle(lCount);
    }
    Thanks guys for answering my previous questions, I managed to create the object as single instance and there is no problem. Thanks a lot. However, I have some difficulty with the following problem. As shown above, the application (as a single instance, I should have named it something else ), is completely engaged in rendering and ignores all messages toward other MDI child windows. So the result is a plain window which looks like a SDI.

    See mdi1.png

    Which is supposed to look like mdi2.png

    Does anyone know how to alter the program to make it look exactly like picture 2 while
    preserving dx functionalities?
    Thanks
    Jack
    Attached Images Attached Images   
    Last edited by lucky6969b; December 7th, 2010 at 03:02 AM. Reason: Want to reattach the pictures

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,288

    Re: Message pump question

    Please, attach your pictures to your post.
    Victor Nijegorodov

  3. #3
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Message pump question

    I asume that 'Hello 1' and 'Bounce 1' are different documents and not only different views on the same document.

    If so, you would need two frame classes, two doc classes and two view classes. For the second triple of frame, doc and view you would use a second doc template in order to create them. That is done in the InitInstance function of your app class.

  4. #4
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Message pump question

    The above would mean that beside of the mainframe class you have two further frame classes both derived from CMDIChildWnd and both equipped with an own menu (which would replace the one in main frame).

    A smaller solution only would create a second document with a further call of OnFileNew and show the views for both documents non-maximized. Actually that is only SDI and not MDI cause the latter implies multiple document types rather than multiple documents.

  5. #5
    Join Date
    Dec 2010
    Posts
    587

    Re: Message pump question

    Quote Originally Posted by itsmeandnobodyelse View Post
    The above would mean that beside of the mainframe class you have two further frame classes both derived from CMDIChildWnd and both equipped with an own menu (which would replace the one in main frame).

    A smaller solution only would create a second document with a further call of OnFileNew and show the views for both documents non-maximized. Actually that is only SDI and not MDI cause the latter implies multiple document types rather than multiple documents.
    I wonder SDI could be able to display multiple child windows, not multiple documents(one doc but multiple views). So should I stick with SDI instead? because yes, I have no multiple documents to deal with, just one document but multiple views.
    Thanks
    Jack

  6. #6
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,288

    Re: Message pump question

    Quote Originally Posted by lucky6969b View Post
    I wonder SDI could be able to display multiple child windows, not multiple documents(one doc but multiple views). So should I stick with SDI instead? because yes, I have no multiple documents to deal with, just one document but multiple views.
    No, you should not "stick with SDI instead".
    MDI is mush more convenient than SDI allowing you to simultaneously have a lot of frames with one or more Views in each one.
    If I plan to use more than one View in my App I always create this App as MDI, not SDI.
    Victor Nijegorodov

  7. #7
    Join Date
    Oct 2009
    Posts
    577

    Smile Re: Message pump question

    Quote Originally Posted by lucky6969b View Post
    I wonder SDI could be able to display multiple child windows, not multiple documents(one doc but multiple views). So should I stick with SDI instead? because yes, I have no multiple documents to deal with, just one document but multiple views.
    Thanks
    Jack
    Actually each wizard-generated MDI project firstly is an SDI project cause it has only one doc template, hence only one frame-doc-view combination is present. Furthermore, some former code you posted used the mainframe as frame class in the doc template and not a second (wizard-generated) frame class derived from CMDIChildWnd. So an MDI project which only provides one document type is already behaving like an SDI and you must not change the base created by the wizard.

    For creating a new view for an existing document you may look at the following sample code (of an old but real working project).

    Code:
    // I added a menu item and a toolbar button for creating a search view for the current document 
    BEGIN_MESSAGE_MAP(CMaterialItemDoc, CFoodItemDoc)
    	//{{AFX_MSG_MAP(CMaterialItemDoc)
    	ON_COMMAND(ID_VIEW_COMPTREE, OnViewCompTree)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    // that creates a new doc template combining doc, frame and view
    CMultiDocTemplate* CMaterialItemDoc::CreateCompSelTemplate()
    {
        return new CMultiDocTemplate(IDR_TREE, 
    	  RUNTIME_CLASS(CMaterialItemDoc),
    	  RUNTIME_CLASS(CFoodChildFrame),
    	  RUNTIME_CLASS(CComponentSelView));
    }
    
    // that is the handler which creates the new view
    void CMaterialItemDoc::OnViewCompTree()
    {
          if (m_pCompSelTemplate == NULL)
          {
               // I store the template in a member
               m_pCompSelTemplate = CreateCompSelTemplate();
               // my app class has a container which manages all templates
               theApp.AddDocTemplate(m_pCompSelTemplate);
          }
       else
       {
        // I lookup for the existing view and activate it if existing
        POSITION    pos = m_pCompSelTemplate->GetFirstDocPosition();
        CDocument*  pDoc;
        if (pos != NULL)
        {  
            pDoc = m_pCompSelTemplate->GetNextDoc(pos);
            if (pDoc != NULL)
            {
                pos = pDoc->GetFirstViewPosition();
                CView* pView = pDoc->GetNextView(pos);
                if (pView != NULL)
                    pView->GetParentFrame()->ActivateFrame();
                return;
            } 
        }
       }
        CreateCompSelView();
    }
    
    void CMaterialItemDoc::CreateCompSelView()
    {  
        // that creates the frame
        CFrameWnd* pFrame   = m_pCompSelTemplate->CreateNewFrame(this, NULL);
        // that creates the view for the existing doc
        m_pCompSelTemplate->InitialUpdateFrame(pFrame, this, TRUE);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center