• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 179
  • Last Modified:

Getting the activeview from a dialogbox

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:

void CAddrPage1::GetRecordset()
        //parent of the propertysheet
 CMDIChildWnd* mpaul = (CMDIChildWnd*)GetParent();
        //active view of the parent
 CListView* msteve = (CListView*)mpaul->GetActiveView();
        //underlying listcontrol
 CListCtrl &mjohn = msteve->GetListCtrl();
        //don't know how to get selected item
 CString mhelen = mjohn.GetItemText(2,0);
        //SQL statement
 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.

Paul Trimming
1 Solution
If CAddrPage1 is a property page GetParent() returns a pointer to the Property Sheet. It's not guaranteed that the parent of the property sheet is the View (default is the desktop). You should store the pointer to the view or list control in a member variable of the property sheet before using it.
I think you really don't need to go thru all this pain of getting the active view and stuff. You can accomplish your thing by passing the pointer to the selected item in the constructor of your property sheet. For this you just need to your own property sheet class which has LV_ITEM pointer as constructor argument.

CPropertySheet propSheet (LV_ITEM* pItem);

I think it should work for you.... Try it. I have not tried it..
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now