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. Tree Control and CDocument

Tree Control and CDocument

Scheduled Pinned Locked Moved C / C++ / MFC
data-structureshelpquestion
9 Posts 2 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.
  • A Offline
    A Offline
    Azadeh
    wrote on last edited by
    #1

    I've written a program which has a tree control placed on a dialogbar in a MDI application.I want my tree control to have this ability that if I click on a tree item , it shows the coresponding item that I've drawn before on the document.I wrote some codes for it but when I use the "SetModifiedFlag" and "UpdateAllViews" functions, it issues error that "program should be terminated and the instruction at the specified address couldn't be read.".Is this possible to do ?

    N 1 Reply Last reply
    0
    • A Azadeh

      I've written a program which has a tree control placed on a dialogbar in a MDI application.I want my tree control to have this ability that if I click on a tree item , it shows the coresponding item that I've drawn before on the document.I wrote some codes for it but when I use the "SetModifiedFlag" and "UpdateAllViews" functions, it issues error that "program should be terminated and the instruction at the specified address couldn't be read.".Is this possible to do ?

      N Offline
      N Offline
      Neville Franks
      wrote on last edited by
      #2

      Well most anything is possible, and I can't see why this should be an exception. I suggest you run your app as a Debug Build and you should be able to see valuable information about the crash when it occures. One would assume you are corrupting memory somewhere or something like that. Neville Franks, Author of ED for Windows. www.getsoft.com

      A 1 Reply Last reply
      0
      • N Neville Franks

        Well most anything is possible, and I can't see why this should be an exception. I suggest you run your app as a Debug Build and you should be able to see valuable information about the crash when it occures. One would assume you are corrupting memory somewhere or something like that. Neville Franks, Author of ED for Windows. www.getsoft.com

        A Offline
        A Offline
        Azadeh
        wrote on last edited by
        #3

        I run it in debug mode.I have written a function in my class CMyDoc::CDocument and I call it without any problem but when I call SetModifiedFlagfunction , an exception raises. I think this problem relates to the way I call these functions.I defined a global pointer to CMyDoc and initialized it with the GetDocument function in the CMyView::CView .So I use this global pointer to call CMyDoc functions.Of course I call these functions in another class CMyTreeCtrl::CTreeCtrl.

        N 1 Reply Last reply
        0
        • A Azadeh

          I run it in debug mode.I have written a function in my class CMyDoc::CDocument and I call it without any problem but when I call SetModifiedFlagfunction , an exception raises. I think this problem relates to the way I call these functions.I defined a global pointer to CMyDoc and initialized it with the GetDocument function in the CMyView::CView .So I use this global pointer to call CMyDoc functions.Of course I call these functions in another class CMyTreeCtrl::CTreeCtrl.

          N Offline
          N Offline
          Neville Franks
          wrote on last edited by
          #4

          Well the first thing I'd do is get rid of the global and all other globals. You are just asking for trouble using globals. Presumeably you know the view or can find it and then use it's GetDocument() function. Neville Franks, Author of ED for Windows. www.getsoft.com

          A 1 Reply Last reply
          0
          • N Neville Franks

            Well the first thing I'd do is get rid of the global and all other globals. You are just asking for trouble using globals. Presumeably you know the view or can find it and then use it's GetDocument() function. Neville Franks, Author of ED for Windows. www.getsoft.com

            A Offline
            A Offline
            Azadeh
            wrote on last edited by
            #5

            Even I used CFrameWnd::GetActiveDocument() to get pointer to the document , but it wasn't useful and the same error is repeated.

            N 1 Reply Last reply
            0
            • A Azadeh

              Even I used CFrameWnd::GetActiveDocument() to get pointer to the document , but it wasn't useful and the same error is repeated.

              N Offline
              N Offline
              Neville Franks
              wrote on last edited by
              #6

              Azadeh wrote: Even I used CFrameWnd::GetActiveDocument() to get pointer to the document , but it wasn't useful and the same error is repeated. Are you checking that CFrameWnd::GetActiveDocument() isn't returning NULL? Neville Franks, Author of ED for Windows. www.getsoft.com

              A 1 Reply Last reply
              0
              • N Neville Franks

                Azadeh wrote: Even I used CFrameWnd::GetActiveDocument() to get pointer to the document , but it wasn't useful and the same error is repeated. Are you checking that CFrameWnd::GetActiveDocument() isn't returning NULL? Neville Franks, Author of ED for Windows. www.getsoft.com

                A Offline
                A Offline
                Azadeh
                wrote on last edited by
                #7

                Yes , you had right , it was NULL .But what can I do ? I don't know how to access to active document.My code is as follows: void MyTreeCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) { HTREEITEM hItem = GetSelectedItem ( ) ; Symbol* item; CRect rectSave1; CMyDoc* doc; CMDIFrameWnd f; doc=(CMyDoc*)f.GetActiveDocument(); if(doc!=NULL) { if ((item=doc->Find(hItem))!=NULL) { CRectTracker rectTracker=item->tracker; doc->ChangeTrackerStyle(rectTracker); doc->SetModifiedFlag(); rectTracker.GetTrueRect(rectSave1); doc->UpdateAllViews(NULL, (LPARAM)(LPCRECT)rectSave1); doc->UpdateAllViews(NULL); } } *pResult = 0; } I work with an MDI application.

                N 1 Reply Last reply
                0
                • A Azadeh

                  Yes , you had right , it was NULL .But what can I do ? I don't know how to access to active document.My code is as follows: void MyTreeCtrl::OnDblclk(NMHDR* pNMHDR, LRESULT* pResult) { HTREEITEM hItem = GetSelectedItem ( ) ; Symbol* item; CRect rectSave1; CMyDoc* doc; CMDIFrameWnd f; doc=(CMyDoc*)f.GetActiveDocument(); if(doc!=NULL) { if ((item=doc->Find(hItem))!=NULL) { CRectTracker rectTracker=item->tracker; doc->ChangeTrackerStyle(rectTracker); doc->SetModifiedFlag(); rectTracker.GetTrueRect(rectSave1); doc->UpdateAllViews(NULL, (LPARAM)(LPCRECT)rectSave1); doc->UpdateAllViews(NULL); } } *pResult = 0; } I work with an MDI application.

                  N Offline
                  N Offline
                  Neville Franks
                  wrote on last edited by
                  #8

                  Azadeh wrote: CMDIFrameWnd f; doc=(CMyDoc*)f.GetActiveDocument(); It would be a good idea to actually assign the MDIFrameWnd to f don't you think. Also don't use old C Style casts. In this case you should be using dynamic_cast( ... ). Neville Franks, Author of ED for Windows. www.getsoft.com

                  A 1 Reply Last reply
                  0
                  • N Neville Franks

                    Azadeh wrote: CMDIFrameWnd f; doc=(CMyDoc*)f.GetActiveDocument(); It would be a good idea to actually assign the MDIFrameWnd to f don't you think. Also don't use old C Style casts. In this case you should be using dynamic_cast( ... ). Neville Franks, Author of ED for Windows. www.getsoft.com

                    A Offline
                    A Offline
                    Azadeh
                    wrote on last edited by
                    #9

                    Thank you and my problem is solved by adding the following lines to my code which I found in MSDN: CMDIFrameWnd *pFrame = (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd; // Get the active MDI child window. CMDIChildWnd *pChild = (CMDIChildWnd *) pFrame->GetActiveFrame(); // or CMDIChildWnd *pChild = pFrame->MDIGetActive(); // Get the active view attached to the active MDI child // window. CMyDoc *pDoc = (CMyDoc *) pChild->GetActiveDocument(); You're right,using C style casts isn't good ,but I don't know exactly where I can use dynamic_cast and static_cast operators.Once I wanted to type cast a pointer to a base class to a pointer to one of its derived class with these operators but I wan't successful. Base b; // suppose base class has a pointer to Base named link Derived* d; b.link=new Derived; First of all ,can I use b.link as a pointer to Derived and use fields of Derived?

                    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