1. Get Application pointers
cmyapp* papp= (cmyapp*) AfxGetApp ();
2. Get the main frame pointer
The public member variable in CWINAPP m_pMainWnd is the pointer to the main frame
cmainframe* pMainFrame = (cmainframe*) (AfxGetApp ()->m_pmainwnd);
Or
cmainframe* pMainFrame = (cmainframe*) AfxGetMainWnd ();
3. Get menu pointer
cmenu* Pmenu = AfxGetMainWnd ()->getmenu ();
4, get the toolbar, status bar pointers
The main frame can be directly used m_wndToolBar, M_wndstatusbar
Other:
ctoolbar* Ptoolbar = (ctoolbar*) AfxGetMainWnd ()->getdescendantwindow (Afx_idw_toolbar);
cstatusbar* Pstatusbar = (cstatusbar*) AfxGetMainWnd ()->getdescendantwindow (Afx_idw_status_bar);
5. Get Control pointer
First use GetDlgItem () and then convert, such as:
cbutton* Pbutton = (cbutton*) GetDlgItem (Idc_mybutton);
6, through the framework to obtain documents, view pointers
Sdi:
cmainframe* pMainFrame = (cmainframe*) AfxGetMainWnd ();
cyourdoc* PDoc = (cyourdoc*) pmainframe->getactivedocument ();
cyourview* PView = (cyourview*) Pmainframe->getactiveview ();
Mdi:
cmainframe* pMainFrame = (cmainframe*) AfxGetMainWnd ();
cchildframe* pchildframe = (cchildframe*) pmainframe->getactiveframe ();
cyourdoc* PDoc = (cyourdoc*) pchildframe->getactivedocument ();
cyourview* PView = (cyourview*) Pchildframe->getactiveview ();
7. Documents, views
To get a document pointer from a view:
cyourdoc* PDoc = GetDocument ();
To get a view pointer from a document:
Using member functions GetFirstViewPosition () and GetNextView () traversal
Virtual POSITION getfirstviewposition () const;
Virtual cview* GetNextView (position& rposition) const;
Sdi:
cyourview* PView;
POSITION pos = getfirstviewposition ();
PView = GetNextView (POS);
Mdi:
Defining functions
cview* Cyourdoc::getview (cruntimeclass* pclass)
{
cview* PView;
POSITION pos=getfirstviewposition ();
while (Pos!=null)
{
Pview=getnextview (POS);
if (!pview->iskindof (Pclass))
Break
}
if (!pview->iskindof (Pclass))
{
AfxMessageBox ("Connt Locate the View.");
return NULL;
}
return pView;
}
Use the following:
cyourview* pview= (cyourview*) GetView (Runtime_class (Cyourview));
8, document template, document
To obtain a document template pointer from a document:
cdoctemplate* getdoctemplate () const;
To get a document pointer from a document template:
Viaual POSITION getfirstdocposition () const = 0;
Visual cdocument* Getnextdoc (POSITION & rpos) const = 0;
9. Get a pointer to each view in the Split view
Defined in the main frame: CSplitterWnd m_wndsplitter;
Define two view classes: CView1, CView2
Overload in a framework class:
BOOL cmainframe::oncreateclient (lpcreatestruct, ccreatecontext* pContext)
{
VERIFY (M_splitter. CreateStatic (this,2,1)); Split into two rows and one column
VERIFY (M_splitter. CreateView (0,0,runtime_class (CView1), CSize (100,100), pContext));
VERIFY (M_splitter. CreateView (1,0,runtime_class (CVIEW2), CSize (100,100), pContext));
return TRUE;
}
Get Split View pointer
cview1* pView1 = (cview1*) m_wndsplitter.getpane (0,0);
cview2* pView2 = (cview2*) m_wndsplitter.getpane (1,0);
10, through the mouse to obtain child window pointer
cwnd* Childwindowfrompoint (point point) const;
cwnd* Childwindowfrompoint (Point point,uint nflags) const;
Used to determine the child window that contains the specified point
If the specified point is outside the client area, the function returns null;
If the specified point is in the client area but does not belong to any of the child windows, the function returns the pointer to the CWnd;
If multiple child windows contain a specified point, the pointer to the first child window is returned.
Also note that the function returns a pseudo window pointer and cannot be saved for later use.
There are several meanings for the second argument nflags:
Cwp_all file://does not ignore any child windows
Cwp_skipnivsible file://ignore Invisible child windows
cwp_skipdisabled file://Ignore prohibited child windows
Cwp_skipransparent file://Ignore transparent child windows