Summary: Pointer, is very common in VC , here we don't plan to explain in detail in C pointer usage (we will have another article to discuss in detail), here mainly talk about the common to the pointer in VC Method, including: toolbar, status, control, and window pointers.
Get the toolbar's pointer in the default, there is a default toolbar AFX_IDW_TOOLBAR, we can get the toolbar pointer according to the corresponding ID, the method is as follows: ctoolbar * ptoolbar = (ctoolbar *) AFXGETMAINWND () -> getDescendantWindow (AFX_IDW_TOOLBAR ); Is not it simple? Getting the pointer of the status bar In the default state, there is a default status bar AFX_IDW_STATUS_BAR, we naturally obtain the status strip pointer according to the corresponding ID, the method is as follows: cstatusbar * ptoolbar = (cstatusbar *) AFXGETMAINWND () -> getDescendantWindow (AFX_IDW_STATUS_BAR); Is it very simple?
There are two ways to get the pointer to the control. First, call CWnd:: getdlgitem, get a CWND * pointer call member function. For example, we want to get the CButton pointer, the method is as follows: CButton * pbutton = (cbutton *) getDLGITEM (IDC_MYBUTTON); Second, you can use ClassWizard to link controls and member variables. Simply select the MEMBER VARIABLES tab in ClassWizard and select the Add Variable ... button. If you press the CTRL key and double-click the control in the dialog resource editor and you can go to the Add Member Variable conversation.
Tune the view class pointer in the document class. We can use the document class's member function getFirstView () and getNextView () traversal view.
The document class is called in the view class. In fact, there is a ready-made member function in the view class for us to use, that is: getDocument (); use it we can easily get a document pointer, let's take a look at the getDocument () function implementation: CColorButtonDoc * CColorButtonView :: GetDocument () {ASSERT (m_pDocument-> IsKindOf (RUNTIME_CLASS (CColorButtonDoc))); return (CColorButtonDoc *) m_pDocument;} will actually cast here m_pDocument into CColorButtonDoc *, which is what we want need.
In the framework class, the document class is called, and the view category here we can use getActiveXxxxxx () to remove the currently activated document and view: cmydoc * pdoc = (cmydoc *) getActiveDocument (); cmyview * pView = (CMYVIEW *) getActiveView ()
This is very simple to get the application pointer, a sentence to get: cmyapp * PAPP = (cmyapp *) AFXGetApp ();