类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
程序的流程是这样的:
1.在对话框中动态创建按钮
2.按钮中的响应事件是创建一个窗口(继承自CFrameWnd)
3.在窗口中加入一个视图,视图是继承自CFormView
其中(1)、(2)项都已解决了,问题出在(3)项中,我是在CMyFrameWnd::OnCreateClient中用如下语句创建视图的,但是出错了,不知道何解???
CRuntimeClass* pNewViewClass;
pNewViewClass = RUNTIME_CLASS(CMyForm);
pContext.m_pNewViewClass = pNewViewClass;
出错的提示:
error C2065: IDD_MYFORMVIEW : undeclared identifier (IDD_MYFORMVIEW是资源,我明明在Dialog中创建了,真奇怪)
error C2057: expected constant expression
error C2228: left of .m_pNewViewClass must have class/struct/union type Error executing cl.exe.
或者要实现第三步,哪位大哥有代码了,谢谢!!!!
main.exe - 3 error(s), 0 warning(s)
网友回答:
混分
IDR_MAINFRAME 这个资源一定要有, 菜单 工具条之类的,
CYourDoc
CMainFrame
CYourView
一定要作好,也可以从别的项目拷贝过来
CYourApp::InitInstance()
{
...
SetRegistryKey(_T("应用程序向导生成的本地应用程序"));
// 添加下面的代码 , 可以从别的项目拷贝过来
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME, // 注意这个资源要有 菜单。
RUNTIME_CLASS(CYourDoc),
RUNTIME_CLASS(CMainFrame),
RUNTIME_CLASS(CYourView));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
......
}
// 在单击消息里添加代码
void CYourDlg::OnBnClickedButton1()
{
CCommandLineInfo cmdInfo;
AfxGetApp() -> ParseCommandLine(cmdInfo);
if (!AfxGetApp() -> ProcessShellCommand(cmdInfo))
return ;
AfxGetApp() -> m_pMainWnd -> ShowWindow (SW_SHOW) ;
AfxGetApp() -> m_pMainWnd -> UpdateWindow () ;
}
你的对话框 关闭时 m_pMainWnd 也将关闭。
我认为还是应该 建立一个 DOC/View 项目 ,
然后在m_pMainWnd -> ShowWindow (SW_SHOW) ;
之前显示一个对话框,比较自然。