在SDI中,如何从 formview向对话框中传递数据
在VC++ SDI中,我在 formview设置一些编辑控件与相应的变量,然后通过formview上的一个按钮打开一个对话框, 在该对话框中显示图像,但要从formview中得到一些变量数据,如何从 formview向对话框中传递数据。
我想通过指针的方式解决上面的问题,我昨天网上查了下:
Test.h:(应用程序类头文件)
class CTestApp : public CWinApp
{ public:
class CTestView* g_pView; //全局变量 视图类指针
…………
}
TestView.cpp:(视图类文件)
CTestView::CTestView()
{ ((CELIDMAFApp *)AfxGetApp())->g_pView=this; //在视图中初始化 视图指针
}
在对话框中的某函数中要访问视图类中的某个变量m_x:
void CDlg::XXX()
{ float temp;
CTestView *app = ((CTestApp *)AfxGetApp())->g_pView; //生成指向应用程序类的视图指针
temp=app->m_x; //访问视图中的变量m_x;
}
问题是:
如果不要 temp=app->m_x; 这行,则编译成功;
如果运行 temp=app->m_x; ,则编译失败,显示此句错误:use of undefined type 'CTestView'
添加testview后,编译失败
error C2143: syntax error : missing ';' before '*'
error C2501: 'CTestDoc' : missing storage-class or type specifiers
error C2501: 'GetDocument' : missing storage-class or type specifiers
不知道怎么回事? 请帮助,谢谢各位