CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2016
    Posts
    35

    Finding Filename of activated document

    Hello,

    I have an MDI application which shows all the opened documents under the Window Menu.

    The user can switch the view from one document to another by just clicking on the document.

    How can I programatically determine the filename of the document that has been activated?

    Can I use ON_WM_MDIACTIVATE for this purpose?

    Sample code will be appreciated..

    Any help please?
    Last edited by robertzp; October 13th, 2017 at 11:17 AM.

  2. #2
    Join Date
    Jul 2016
    Posts
    35

    Re: Finding Filename of activated document

    Hello,

    I solved the problem with the following code!

    The code will display the pathname of the active document being displayed on the screen on the status bar!

    Hope this helps others who have the same needs.

    Code:
    void CChildFrame::OnMDIActivate(BOOL bActivate, CWnd* pActivateWnd, CWnd* pDeactivateWnd)
    {
    	CMDIChildWnd::OnMDIActivate(bActivate, pActivateWnd, pDeactivateWnd);
    
    	/*
    	On Activation, get the filename annd store in status pane
    	*/
    
    	if (bActivate)
    	{
    		CDocument* pDoc = ((CFrameWnd*)pActivateWnd)->GetActiveDocument();
    		const CString& strFile = pDoc->GetPathName();
    		if (!strFile.IsEmpty())
    		{
    			CMainFrame* pWnd = (CMainFrame*)AfxGetMainWnd();
    			pWnd->m_wndStatusBar.SetPaneText(2, strFile);
    			CWindowDC dc(&pWnd->m_wndStatusBar);
    			CSize sizeText = dc.GetTextExtent(strFile);
    			pWnd->m_wndStatusBar.SetPaneInfo(2, ID_SEPARATOR, SBPS_NORMAL, sizeText.cx);
    		}
    	}
    }
    Last edited by 2kaud; October 15th, 2017 at 02:42 AM. Reason: Added code tags

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