CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    200

    Help needed on GetDocument

    We can use GetDocument to return a pointer to the CDocument associated with the view(eg CFormView).

    However if i have created a dialog box (CDialog class), how do i get a pointer to the CDocument???

  2. #2
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128
    I think you would have to pass a pointer to the parent to the dialog box...e.g. either the View or the Document class pointer.

    Using this you can get to the other classes.

  3. #3
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    200
    OK... ..


    Is there any sample code you can show me??

  4. #4
    Join Date
    May 2002
    Posts
    1,435
    PHP Code:
    //
    // In your view (or document, or frame, etc.)
    //
    CMyView::OnDialogBox()
    {
      
    CMyDialog dlg(GetDocument());
      
    dlg.DoModal();
    }

    //
    // In your dialog box header file:
    //
    class CMyDocument;

    class 
    CDialog : public CDialog
    {
      
    // Modify the normal constructor
      
    CMyDialog(CMyDocument *pDocCWnd *pParent=NULL);
      
    // Don't allow default constructor
      
    CMyDialog(){ ASSERT(FALSE); }

    protected:
      
    CMyDocument *m_pDoc;
    }

    //
    // In your dialog box cpp file
    //
    CMyDialog::CMyDialog(CMyDocument *pDocCWnd *pParent/*=NULL*/)
      :: 
    CDialog(CMyDialog::IDD,pParent), m_pDoc(pDoc)
    {


  5. #5
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128
    Is the dialog box you are creating modeless or modal ?

  6. #6
    Join Date
    Jan 2001
    Location
    Singapore
    Posts
    200
    The dialog box i am creating is modal

  7. #7
    Join Date
    Jun 2001
    Location
    UK
    Posts
    128
    The code snippet from "0xC0000005" is ideally what you should do.
    Nice job 0xC0000005

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