void CDataView::OnBnClickedButton1()
{
// TODO: 在此添加控件通知处理程序代码
CDataView *DataView=(CDataView*)this->GetParent();//<--出错代码
CMainFrame* MainFrame=DataView->GetParent();
int c=MainFrame->p_jhView->m_listJh.GetItemCount();
CString s;
s.Format("%d",c);
AfxMessageBox(s);
}error“CMainFrame”:为声明的标识符已经include "mainfrm.h"
{
// TODO: 在此添加控件通知处理程序代码
CDataView *DataView=(CDataView*)this->GetParent();//<--出错代码
CMainFrame* MainFrame=DataView->GetParent();
int c=MainFrame->p_jhView->m_listJh.GetItemCount();
CString s;
s.Format("%d",c);
AfxMessageBox(s);
}error“CMainFrame”:为声明的标识符已经include "mainfrm.h"
------------------
CMainFrame * pMainFrame = AfxGetMainWnd();
技术上可行
符合你的要求吗?
如果不明白
请给我发短消息
请附: 帖子的地址
或在
http://www.338888.com/VCShare/Default.asp
上提问
为什么会说CMainFrame是未声明的标识符?
//
#include "SplitterEx.h"
#include "jhView.h"
#include "DataView.h"#pragma once
class CMainFrame : public CFrameWnd
{
protected: // 仅从序列化创建
CMainFrame();
DECLARE_DYNCREATE(CMainFrame)// 属性
public:// 操作
public:// 重写
public:
virtual BOOL PreCreateWindow(CREATESTRUCT& cs);// 实现
public:
virtual ~CMainFrame();
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected: // 控件条嵌入成员
CStatusBar m_wndStatusBar;
CToolBar m_wndToolBar;
CSplitterEx m_wndSplitter;// 生成的消息映射函数
protected:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
DECLARE_MESSAGE_MAP()
virtual BOOL OnCreateClient(LPCREATESTRUCT lpcs, CCreateContext* pContext);
public:
CjhView * p_jhView;
CDataView * p_DataView;
afx_msg void OnBnClickedButton1();
};
在MyView.h内又include了MainFrm.h
这种嵌套性质的include在C++中是不是不允许呀?如果不允许,我在MyView中如何引用CMainFrame的变量呢?
//
/////////////////////////////////////////////////////////////////////////////#if !defined(AFX_FROMVIEW1DOC_H__62202C37_A301_4B97_B92D_4CEC7CC08F74__INCLUDED_)
#define AFX_FROMVIEW1DOC_H__62202C37_A301_4B97_B92D_4CEC7CC08F74__INCLUDED_
......
这保证文件只会编绎一次