CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Aug 2011
    Posts
    69

    Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    Hi,

    Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    I have this metho:

    Code:
    BOOL CDlgForm::OnInitDialog()
    {
    	CDialogEx::OnInitDialog();
    
    	CAdestDoc* pDoc = GetMDIActiveDocument();
    	ASSERT_VALID(pDoc);	
    	CString titulo = pDoc->GetTitle ();
    	CString aux;
    	CRect r;
    	m_Lista_Caract.GetWindowRect (&r);
    	m_Lista_Caract.InsertColumn (0, _T(" "), LVCFMT_LEFT, r.Width () -5);
    	m_Lista_Caract.DeleteAllItems ();
    
    	if (titulo.Right (4) == ".ped")
    	{
    		// Hemos abierto un archivo
    		// Mostramos sus caracterĂ*sticas
    		m_Lista_Caract.InsertItem (0, _T(""));
    		aux.Format (_T("\t Espacio de trabajo:  %s"), titulo);
    		m_Lista_Caract.InsertItem (1, aux);
    		aux.Format (_T("\t \t NĂșmero de variables: %d"), pDoc->Variables.GetSize ());
    		m_Lista_Caract.InsertItem (2, aux);
    		aux.Format (_T("\t \t NĂșmero de informes: %d"), pDoc->Informes.GetSize ());
    		m_Lista_Caract.InsertItem (3, aux);
    	}
    	else
    		m_Lista_Caract.InsertItem (0, _T("Espacio de trabajo vacĂ*o"));
    
    	return TRUE;  // return TRUE unless you set the focus to a control
    	// EXCEPCIÓN: las páginas de propiedades OCX deben devolver FALSE
    }
    I use GetMDIActiveDocument in other method and there aren't problem, but in this method I get this error:

    Error 1 error C3861: 'GetMDIActiveDocument': didn't find the identifier

  2. #2
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    Did you include the appropriate header?

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

    Re: Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    Quote Originally Posted by a343 View Post
    Hi,

    Are there any problem if I use GetMDIActiveDocument in OnInitDialog?
    ...
    I get this error:

    Error 1 error C3861: 'GetMDIActiveDocument': didn't find the identifier
    What is GetMDIActiveDocument?
    Where does it come from?
    Victor Nijegorodov

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    A better approach is to just pass the document pointer in the constructor of CDlgForm.

  5. #5
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,635

    Re: Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    Quote Originally Posted by VictorN View Post
    What is GetMDIActiveDocument?
    Where does it come from?
    It's in the faq here.
    http://www.codeguru.com/forum/showthread.php?t=473808

  6. #6
    Join Date
    Feb 2003
    Location
    Iasi - Romania
    Posts
    8,234

    Re: Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    Quote Originally Posted by GCDEF View Post
    Quote Originally Posted by VictorN View Post
    What is GetMDIActiveDocument?
    Where does it come from?
    It's in the faq here.
    http://www.codeguru.com/forum/showthread.php?t=473808
    Huh!?
    I didn't know my humble function already included in the MFC framework.
    Ovidiu
    "When in Rome, do as Romans do."
    My latest articles: https://codexpertro.wordpress.com/

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

    Re: Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    Quote Originally Posted by ovidiucucu View Post
    Quote Originally Posted by GCDEF View Post
    Huh!?
    I didn't know my humble function already included in the MFC framework.
    I didn't know it either!
    So I only searched MSDN for it... without success.

    Anyway...
    Quote Originally Posted by a343 View Post
    Hi,

    Are there any problem if I use GetMDIActiveDocument in OnInitDialog?

    I have this metho:

    Code:
    BOOL CDlgForm::OnInitDialog()
    {
    	CDialogEx::OnInitDialog();
    
    	CAdestDoc* pDoc = GetMDIActiveDocument();
    	ASSERT_VALID(pDoc);	
    	CString titulo = pDoc->GetTitle ();
    	...
    }
    Yes, there are:
    1. You have to be sure the return value of GetMDIActiveDocument points the the object of CAdestDoc class (or of some class derived from it) like Ovidiu pointed out in his FAQ
    2. You have to cast the return value of GetMDIActiveDocument to your CAdestDoc type



    But better solution was suggested by Arjay:
    Quote Originally Posted by Arjay View Post
    A better approach is to just pass the document pointer in the constructor of CDlgForm.
    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