How to make an open document the active document

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.