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.