Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. GetDocument in a dialog?

GetDocument in a dialog?

Scheduled Pinned Locked Moved C / C++ / MFC
helpquestionc++
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Mister Transistor
    wrote on last edited by
    #1

    I have an MFC app and I want to use a dialog to filter data in the document. But how do I get hold of GetDocument()? All I can find that almost works is to use in OnInitDialog CTransistDoc* pDoc = (CTransistDoc*) CLeftPaneView::GetDocument(); ie I try to get it via my View, but this fails with error C2352: 'CView::GetDocument' : illegal call of non-static member function Which seems to be saying that OnInitDialog() is a static function. It is declared normally virtual BOOL OnInitDialog(); How do I sort this out? And where is this kind of nonsense explained? Thanks in advance for any help.

    W D 2 Replies Last reply
    0
    • M Mister Transistor

      I have an MFC app and I want to use a dialog to filter data in the document. But how do I get hold of GetDocument()? All I can find that almost works is to use in OnInitDialog CTransistDoc* pDoc = (CTransistDoc*) CLeftPaneView::GetDocument(); ie I try to get it via my View, but this fails with error C2352: 'CView::GetDocument' : illegal call of non-static member function Which seems to be saying that OnInitDialog() is a static function. It is declared normally virtual BOOL OnInitDialog(); How do I sort this out? And where is this kind of nonsense explained? Thanks in advance for any help.

      W Offline
      W Offline
      will1383
      wrote on last edited by
      #2

      Mister Transistor wrote: CTransistDoc* pDoc = (CTransistDoc*) CLeftPaneView::GetDocument(); You are calling GetDocument as a static function (shown by the ::GetDocument). What you need to do here is get pointer to the class that contains the docuement, and call the GetDocument from that pointer. So it'd be something like this: CLeftPaneView *pLeftView; CTransistDoc *pDoc; CWnd* pWnd; pWnd = m_wndSplitter.GetPane(0, 1); pLeftView = DYNAMIC_DOWNCAST(CLeftPaneView, pWnd); pLeftView = pDoc->GetDocument(); This is how I get my document pointers in order to manipulate my docuement information. Hope this helps! :)

      M 1 Reply Last reply
      0
      • M Mister Transistor

        I have an MFC app and I want to use a dialog to filter data in the document. But how do I get hold of GetDocument()? All I can find that almost works is to use in OnInitDialog CTransistDoc* pDoc = (CTransistDoc*) CLeftPaneView::GetDocument(); ie I try to get it via my View, but this fails with error C2352: 'CView::GetDocument' : illegal call of non-static member function Which seems to be saying that OnInitDialog() is a static function. It is declared normally virtual BOOL OnInitDialog(); How do I sort this out? And where is this kind of nonsense explained? Thanks in advance for any help.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        Create another constructor in your dialog class that accepts a CDocument pointer. Then construct your dialog object like: CMyDialog dlg(this); dlg.DoModal(); Now your dialog class can communicate with the document class with the saved pointer.

        W 1 Reply Last reply
        0
        • D David Crow

          Create another constructor in your dialog class that accepts a CDocument pointer. Then construct your dialog object like: CMyDialog dlg(this); dlg.DoModal(); Now your dialog class can communicate with the document class with the saved pointer.

          W Offline
          W Offline
          will1383
          wrote on last edited by
          #4

          Ooo. That's quick and easy. I like that! Thanks Dave!

          J 1 Reply Last reply
          0
          • W will1383

            Ooo. That's quick and easy. I like that! Thanks Dave!

            J Offline
            J Offline
            Jonathan Craig
            wrote on last edited by
            #5

            will1383, DavidCrow has a good idea, but remember that the default constructor for a dialog is: CMyDialog(CWnd *pParent); So you should create it like this: CMyDialog dlg(this); The this parameter being a pointer to the parent window. It is good practice to always set the parent for a dialog. Don't create them like this: CMyDialog dlg; If you do dialogs can sometimes not come to the top or fall behind other windows. So define your new constructor like so: CMyDialog(CWnd *pParent, CMyDoc *pDoc); Now create your dialog like this: CMyDialog dlg(this, GetDocument()); Now you have the best of both. :) Jonathan Craig www.mcw-tech.com

            1 Reply Last reply
            0
            • W will1383

              Mister Transistor wrote: CTransistDoc* pDoc = (CTransistDoc*) CLeftPaneView::GetDocument(); You are calling GetDocument as a static function (shown by the ::GetDocument). What you need to do here is get pointer to the class that contains the docuement, and call the GetDocument from that pointer. So it'd be something like this: CLeftPaneView *pLeftView; CTransistDoc *pDoc; CWnd* pWnd; pWnd = m_wndSplitter.GetPane(0, 1); pLeftView = DYNAMIC_DOWNCAST(CLeftPaneView, pWnd); pLeftView = pDoc->GetDocument(); This is how I get my document pointers in order to manipulate my docuement information. Hope this helps! :)

              M Offline
              M Offline
              Mister Transistor
              wrote on last edited by
              #6

              that's very interesting thank you ... I think you mean pDoc = pLeftView->GetDocument(); I'll try that shortly. Thanks again. Andrew

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups