Get a form handle

xiaoxiao2021-03-06  38

Interactive function between MDI objects

Class function return value GlobalAfxGetAppCWinApp * (pointing to the current program) GlobalAfxGetMainWndCWnd * (pointing to the program's main window frame) CMDIFrameWndMDIGetActiveCMDIChild Wnd * (pointing to the currently active MDI child window) CWnd GetParentFrameCFrameWnd * (point to the parent window frame) CFrameWndGetActiveViewCView * (pointing to the currently active view) the CFrameWnd GetActiveDocumentCdocument * (point to the current activity document) CViewgetDocumentcDocument * (Contact this view class) CDocument getFirstViewPosition The first view class CDocumentGetNextView in the Documentation Class CDocumentGetNextView in the following view class location

E.G. CMAINFRAME * MFRM = (CMAINFRAME *) AFXGETMAINWND ();

E.G .: Get the current view:

CframeWnd * Pmain = (cframewnd *) AFXGETMAINWND ();

CframeWnd * pchild = (cframewnd *) PMain-> getActiveFrame ();

CView * m_pagentview = (cView *) pchild-> getActiveView ();

Visit the current activity view and activity documentation

1. For the SDI program, the main frame window is the document box window, which can take the following method to get the current documentation and view:

Get the event documentation:

CMYDocument * pdoc;

PDOC = (CMYDocument *) ((cframewnd *) AFXGetApp () -> m_pmainwnd) -> getActiveDocument ();

or

PDOC = (CMYDocument *) (cframeWnd *) AFXGETMAINWND ());

Both are equivalent.

Get an active view:

CMYVIEW * PVIEW;

PVIEW = (CMYVIEW *) ((cframewnd *) AFXGetApp () -> m_pmainwnd -> getActiveView ();

2. For the MDI program, since the sub-window is the document box window, first get the active subframe window with getActiveFrame (), then obtain the activity document and the view through the sub-window:

CMDICHILDWND * PCHILD = (cmdichildwnd *) ((cframewnd *) AFXGetApp () -> m_pmainwnd -> getActiveFrame ();

Get the event documentation:

CMYDocument * pdoc = pchild-> getActiveDocument ();

CMYVIEW * PVIEW = (CMYVIEW *) PCHILD-> getActiveView ();

The above function fragment can be made into static member functions, such as:

Static CMYDocument :: getcurrentdoc ()

{

CMDICHILDWND * PCHILD = (cmdichildwnd *) ((cframewnd *) AFXGetApp () -> m_pmainwnd -> getActiveFrame ();

CMYDocument * pdoc = pchild-> getActiveDocument ();

}

This will acquire an active document (or view) in the following manner:

CMYDocument :: getcurrentdoc ();

Note: No specific objects are associated with the static member function call. Document template to find a document

example:

CMULTIDEMPLATE * PDOCTMPL;

PdoctMPL = ((cimpapp *) AFXGetApp ()) -> m_pdoctemplate;

Position Posdoc = pdoctmpl-> getfirstdocPosition ();

While (null! = POSDOC)

{

Pfrmdoc = (cfrmdoc *) pdoctMPL-> getNextdoc (POSDOC);

NDocorder ;

}

转载请注明原文地址:https://www.9cbs.com/read-70588.html

New Post(0)