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. Getting document pointer

Getting document pointer

Scheduled Pinned Locked Moved C / C++ / MFC
c++debugginghelptutorialquestion
6 Posts 3 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.
  • D Offline
    D Offline
    Developer101
    wrote on last edited by
    #1

    I have made a sdi application in MFC. I added a menu item, and a routine when it is clicked. That routine creates an instance of, and displays, an information dialog I created. What I need to do though is display some information in that dialog from the loaded in document. The biggest problem I always seem to have is finding out how to access the document in another class like my dialog class. So I am wondering what I need to do to get a document pointer to my dialog class. Either by passing it in from MainFrm when I create the dialog, or better yet, have my dialog class itself get a pointer to the document. Anyone have any ideas or code samples? I notice my view class has something like: CDXtoXDDoc* CDXtoXDView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDXtoXDDoc))); return (CDXtoXDDoc*)m_pDocument; }

    J D 2 Replies Last reply
    0
    • D Developer101

      I have made a sdi application in MFC. I added a menu item, and a routine when it is clicked. That routine creates an instance of, and displays, an information dialog I created. What I need to do though is display some information in that dialog from the loaded in document. The biggest problem I always seem to have is finding out how to access the document in another class like my dialog class. So I am wondering what I need to do to get a document pointer to my dialog class. Either by passing it in from MainFrm when I create the dialog, or better yet, have my dialog class itself get a pointer to the document. Anyone have any ideas or code samples? I notice my view class has something like: CDXtoXDDoc* CDXtoXDView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDXtoXDDoc))); return (CDXtoXDDoc*)m_pDocument; }

      J Offline
      J Offline
      jmostei
      wrote on last edited by
      #2

      yes, i supose that you have defined the message handler of this menu item in the view class. I supose too that you call de DoModal() function of the dialog class in this message handler. Therefore your´s dialog parent window is the view window. If you call the dialogs method: CWnd * GetParentWnd() and cast teh result to a (CDXtoXDView *). Just doing this: (CDXtoXDView *)GetParentWnd(), then you have a pointer to the view object. You just have to call GetDocument() view´s method to obtain the document pointer. This should work.;)

      D 1 Reply Last reply
      0
      • D Developer101

        I have made a sdi application in MFC. I added a menu item, and a routine when it is clicked. That routine creates an instance of, and displays, an information dialog I created. What I need to do though is display some information in that dialog from the loaded in document. The biggest problem I always seem to have is finding out how to access the document in another class like my dialog class. So I am wondering what I need to do to get a document pointer to my dialog class. Either by passing it in from MainFrm when I create the dialog, or better yet, have my dialog class itself get a pointer to the document. Anyone have any ideas or code samples? I notice my view class has something like: CDXtoXDDoc* CDXtoXDView::GetDocument() // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDXtoXDDoc))); return (CDXtoXDDoc*)m_pDocument; }

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

        If the menu's handler function is in the view, try:

        CDXtoXDView::OnMenuItem()
        {
        CDXtoXDDoc *pDoc = GetDocument();
        CMyDialog dlg(pDoc->somedata);

        dlg.DoModal();
        

        }


        "Opinions are neither right nor wrong. I cannot change your opinion. I can, however, change what influences your opinion." - David Crow

        1 Reply Last reply
        0
        • J jmostei

          yes, i supose that you have defined the message handler of this menu item in the view class. I supose too that you call de DoModal() function of the dialog class in this message handler. Therefore your´s dialog parent window is the view window. If you call the dialogs method: CWnd * GetParentWnd() and cast teh result to a (CDXtoXDView *). Just doing this: (CDXtoXDView *)GetParentWnd(), then you have a pointer to the view object. You just have to call GetDocument() view´s method to obtain the document pointer. This should work.;)

          D Offline
          D Offline
          Developer101
          wrote on last edited by
          #4

          I'll give the suggestions a try. Thank you. When I use the classwizard to create the onclick event, it put it in MainFrame: void CMainFrame::OnToolsShpproperties() { CDLGShpFileBreakdown dlgSHPBreakdown; dlgSHPBreakdown.DoModal(); } Your code will still work?

          J 1 Reply Last reply
          0
          • D Developer101

            I'll give the suggestions a try. Thank you. When I use the classwizard to create the onclick event, it put it in MainFrame: void CMainFrame::OnToolsShpproperties() { CDLGShpFileBreakdown dlgSHPBreakdown; dlgSHPBreakdown.DoModal(); } Your code will still work?

            J Offline
            J Offline
            jmostei
            wrote on last edited by
            #5

            no, it won´t work for sure. All is about getting the current view when creating the dialog. If you have the view, you have the doc with GetDocument(). From the dialog, you can get a pointer to the main frame with the method: GetParentFrame( ). Once you have the pointer to the frame, you can call its GetActiveView() method to get the current view. Thats all, i hope i have been usefull to you.

            D 1 Reply Last reply
            0
            • J jmostei

              no, it won´t work for sure. All is about getting the current view when creating the dialog. If you have the view, you have the doc with GetDocument(). From the dialog, you can get a pointer to the main frame with the method: GetParentFrame( ). Once you have the pointer to the frame, you can call its GetActiveView() method to get the current view. Thats all, i hope i have been usefull to you.

              D Offline
              D Offline
              Developer101
              wrote on last edited by
              #6

              It's fine. I figured it out. In the past when I have added a command handler for a menu item, I have always just used the default in the drop down which is mainfrm. I removed that one, and selected my dialog in the list this time. It put the menu command handler in my document class this time, and all the data I want to display is in that class, so easy solution. :) Thanks for all the help.

              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