CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Close [X] aplication issue

    Hi!!

    I have a MDI aplication that has MDI windows and top windows and unfortunately the document interface is not implemented. When I press the X button on the aplication (not on the child frame) I need to save all modified documents on MDI and on Top Windows, but before save the documents and close the window I need to get the name of the file that is on the view.

    The problem is that I cant get acess the all views from the childframe. In OnClose on the MainFrame I made a while to acess all views and get the file name but it is not working. I have tried get the view form several messages like GetActiveView() GetWindow() and send message (WM_SETFOCUS) from all possible ways. (If I get the focus on the view I can get the filename.) nothing is working. What is Wrong?

    I wrote on Onclose of the MainFrame:

    Code:
    void CMainFrame::OnClose() 
    {
      
      int Maximized(0);
      CMDIChildWnd *CW(MDIGetActive(&Maximized)),*PrimCW(CW);
    
      while(CW) 
      {
         //--- none of these is working.... ----------------------------------------
    
        CW->GetDesktopWindow()->SetFocus();
        CW->GetDesktopWindow()->SendMessage(WM_SETFOCUS);
        CW->GetWindow(WM_SETFOCUS);
     
        ///--------------------------------------------------------------------------
    
        CW->SendMessage(WM_CLOSE);   //--- Ok but I don´t get the file name.
        MDINext();
        CW = MDIGetActive(&Maximized);
    
        if(CW == PrimCW) CW = NULL;   
      }
      
      CMDIFrameWnd::OnClose();
    }

    Thank you
    Last edited by Rabelo; February 28th, 2018 at 07:07 AM.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Close [X] aplication issue

    Have a look at ths code snippet from MSDN (https://msdn.microsoft.com/en-us/lib...activedocument ) :
    Code:
       CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->GetMainWnd();
    
       // Get the active MDI child window.
       CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
    
       // or CMDIChildWnd *pChild = pFrame->MDIGetActive();
    
       // Get the active view attached to the active MDI child window.
       CMyView *pView = (CMyView*)pChild->GetActiveView();
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2003
    Location
    Brazil
    Posts
    335

    Re: Close [X] aplication issue

    I did:

    Code:
      int Maximized(0);
      CMDIChildWnd *CW(MDIGetActive(&Maximized)),*PrimCW(CW);
    
      while(CW) 
      {
        //-----------------------------------------------------------------------------------------
    
       CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->GetMainWnd();
    
       // Get the active MDI child window.
       CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
    
       // or CMDIChildWnd *pChild = pFrame->MDIGetActive();
    
       // Get the active view attached to the active MDI child window.
    
       CView *pView = (CView*)pChild->GetActiveView();
    
       ((DesSecaoView*)pView)->SendMessage(WM_SETFOCUS);    //--- dont work
    
       ((DesSecaoView*)pView)->SetFocus());        //--- dont work
    
    //------------------------------------------------------------------------------------------
        CW->SendMessage(WM_CLOSE);
        MDINext();
        CW = MDIGetActive(&Maximizada);
    
        if(CW == PrimCW) CW = NULL;    //---  buffer circular.
      }
    And the SetFocus message dont get to the view...

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Hanover Germany
    Posts
    20,396

    Re: Close [X] aplication issue

    Quote Originally Posted by Rabelo View Post
    I did:

    Code:
      int Maximized(0);
      CMDIChildWnd *CW(MDIGetActive(&Maximized)),*PrimCW(CW);
    
      while(CW) 
      {
        //-----------------------------------------------------------------------------------------
    
       CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->GetMainWnd();
       CMDIChildWnd *pChild = (CMDIChildWnd*)pFrame->GetActiveFrame();
       ...
       CView *pView = (CView*)pChild->GetActiveView();
    
       ((DesSecaoView*)pView)->SendMessage(WM_SETFOCUS);    //--- dont work
    ...
      }
    And the SetFocus message dont get to the view...
    Sure it doesn't! Just because the WM_SETFOCUS is a notification message! See https://msdn.microsoft.com/en-us/lib...(v=vs.85).aspx
    To set a focus you have call the SetFocus API or MFC Cwnd::SetFocus method.
    Victor Nijegorodov

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured