Access other classes through the Global handle (extern hwnd)

Source: Internet
Author: User

Generally, we define a class object to define the member variables and functions of the class. This is relatively simple, for example:
Cpage1 m_page1;
Then, you can use m_page1 to access the defined functions in the cpage1 class, such as m_page1.add (2, 3 );

But what if I need to access the functions in the main window class in the cpage1 class?
We can access it through a handle.

1. define it in test. H (main program header file) or stdafx. h.

Extern hwnd g_hwnd;

2. In testdlg. cpp, ensure that the test. h header file is referenced and

Hwnd g_hwnd;

3. In ctestdlg: oninitdialog ()

G_hwnd = m_hwnd;

So it can be referenced anywhere in cpage1, for example:

(Ctestdlg *) fromhandle (g_hwnd)-> m_page1.showwindow (sw_hide );

Of course, because g_hwnd is also the handle of the Main Window of the program, g_hwnd can also be written as afxgetmainwnd ()-> m_hwnd

This method is common in the same class. For example, cpage1, cpage2, and cpage3 are defined. They reference each other using a handle.

 

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.