Code:
1 voidcclass_twodlg::ontest ()2 {3 //Todo:add your control notification handler code here4 //get a pointer to the Cclass_twoapp class5cclass_twoapp* Papp = (cclass_twoapp*) AfxGetApp ();6 //Create pointer variable gets to the pointer let him point to the member m_pMainWnd7cwnd* pMainWnd =papp->m_pMainWnd;8 //Create a CString variable to assign an empty value9CString StrText =_t ("");Ten //formatting text OneStrtext.format ("pmainwnd=ox%x\nthis=ox%x\n", pMainWnd, This); A //display text - AfxMessageBox (strText); - the}
Gets a pointer to the application's main window.
Call Function:
AfxGetApp (); Returns the application pointer without parameters
Calling member variables
m_pMainWnd;
Because Papp is a pointer, he can access the parent class of the derived class: For more information, learn C + +.
Visual C + + Pragmatic programming 280 Chapter I Windows 1.2 getting pointers to the main application window