Tree Control and CDocument
-
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 ?
-
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 ?
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
-
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
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.
-
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.
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
-
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
-
Even I used CFrameWnd::GetActiveDocument() to get pointer to the document , but it wasn't useful and the same error is repeated.
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
-
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
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.
-
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.
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
-
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
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?