Visual C + + Pragmatic programming 280 Chapter I Windows 1.2 getting pointers to the main application window

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.