两个对话框的类:
CTestDlg1 对应头文件TestDlg1.h
CTestDlg2 对应头文件TestDlg2.h
当在TestDlg1.h中包含了TestDlg2.h后,在TestDlg2.h中再包含TestDlg1.h时编译就会出错。
可以这样使用:
TestDlg2.h
#include TestDlg1.h
(如果还有错,可以在此处只声明class CTestDlg1, 然后在TestDlg2.cpp中包含头文件)
Class CTestDlg2 :public CDialog
{
Private:
CTestDlg1 * pCTestDlg1;
}
TestDlg2.cpp
CTestDlg2:: CTestDlg2()
{
pCTestDlg1 = NULL;
}
再用的时候可以用指针访问CTestDlg1中的成员函数。
另外:
如果想在CTestDlg2的对话框弹出来的时候,pCTestDlg1就拥有CTestDlg1对话框的所有值,可利用this指针。
方法如下:
CTestDlg2 dlg;
dlg. pCTestDlg1 = this;// pCTestDlg1为空有变量