The use of pointers in the MFC application

xiaoxiao2021-04-03  220

Suppose you build Yousdi project.

1, get the DOC pointer in the View class

CYOUSDIDOC * PDOC = getDocument ();

2. Get the m_pmainwnd variable in the mainframe pointer in the app is the MAINFRAME's pointer.

CMAINFRAME * PMAIN = (CMAINFRAME *) AFXGETMAINWND ();

3, get the mainframe pointer in View

CMAINFRAME * PMAIN = (cmaimframe *) AFXGetApp () -> m_pmainwnd;

4, get the View class pointer

CMAINFRAME * PMAIN = (cmaimframe *) AFXGetApp () -> m_pmainwnd;

Cyouview * pView = (cyouview *) PMain-> getActiveView ();

5, get the current document pointer

CDocument * pcurrentdoc = (cframewnd *) m_pmainwnd-> getActiveDocument ();

6, get the status bar and toolbar pointer

CSTATUSBAR * PSTATUSBAR = (cStatusbar *) AFXGETMAINWND () -> getDescendantWindow (AFX_IDW_STATUS_BAR);

CToolBar * ptoolbar = (ctoolbar *) AFXGETMAINWND () -> getDescendantWindow;

7, get menu pointer in mainframe

CMenu * pmenu = m_pmainwnd-> getMenu ();

8. Available in any class to obtain an application class MFC global function AFXGetApp ().

9, get a pointer to the view class from the document class

Position POS = getFirstViewPosition ();

CTestView * PTestView = GetNextView (POS);

To determine if a class pointer is pointed to an instance of a class, you can use the iskindof () member function to check, such as:

PView-> iskindof (runtime_class (ctestView));

10, one document can have multiple views. Each document retains and maintains a list of all relevant views.

CDocument :: AddView The view is connected to the document, and the view is added to the list of documents, and the document pointer will point to this document.

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

New Post(0)