Getting the activeview from a dialogbox
Posted on 1999-07-26
I am a VC++ beginner using VC++6.0 Prof on Windows 98.
I have an MDI app in which I have so far created one child window. This is a splitter window, one part of which is a CListView (in reportview with subitems). I have got so far as doubleclicking on an item from the listview, which produces a Propertysheet with three pages. This propertysheet is supposed to show data relating to the item in the listview.
I have the following problems:
1) I need to get a pointer to the view that was active before I called up the Propertypages.
2) With this I need to get the itemtext of the selected item in the listview.
I do not know how to do either of the above items. I have produced the following code:
//parent of the propertysheet
CMDIChildWnd* mpaul = (CMDIChildWnd*)GetParent();
//active view of the parent
CListView* msteve = (CListView*)mpaul->GetActiveView();
CListCtrl &mjohn = msteve->GetListCtrl();
//don't know how to get selected item
CString mhelen = mjohn.GetItemText(2,0);
CString mtext = "Select * from AddressBook where Displayname = '" +
mhelen + "'";
// recordset class ClassWizard created
m_PSet = new CAddrRset1(mtext);
//error handling & open recordset for use in prop pages
This code produces a runtime error saying it can't find the CListCtrl. The code is supposed to get the listview item, and with it create the recordset needed to prime the propertypages which I am calling up. I call it in OnCreate() of page one of the new propertypages.
I would be very grateful for code showing how to do the above. Especially I am interested in how to extract the itemtext of the selected listview item.