Ask a question:
There is a tree control that stores a document pointer in its Tvitem user section. When you double-click an item, I want to activate the document from the list of open documents. So how do you activate this pointer in an MDI application for a given document class (CDocument) pointer?
Before answering this question, it is necessary to correct that the document cannot be activated, and only the window can be activated. Implicit in the question is the assumption that each document has only one view, and that the MDI child framework is associated with this view. So to activate the document is to stare at a few pointers. From the document you can get its view.
POSITION pos = pdoc->getfirstviewposition ();
cview* PView = Pdoc->getnextview (POS);
PView is the first view associated with a document. This assumes that this document has one and only one view. If this document has more than one associated view (for example, two windows open for the same document user in an MDI application), you must decide which one to activate. The easiest way to do this is to first use the first view in the list. Once you have this vision, you must obtain the MDI child framework that contains it.
CFrameWnd *pframe = Pview->getparentframe ();
GetParentFrame gets the first parent frame of a given window-the first parent window is CFrameWnd. Assuming that the application is MDI, the view that contains the child frame should be cmdichildwnd. Once you have the MDI child framework, you can invoke pframe->mdiactivate to activate it. In addition, you must also forcibly convert the pointer to CMDIChildWnd.