谁能帮助我...GOD!本人创建一个MFC SDI界面...
主界面用CSplitterWnd分割为左右两个视窗.代码:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
m_wndSplitter.CreateStatic(this, 1, 2); //m_wndSplitter.CreateView(0, 0, pContext->m_pNewViewClass/*RUNTIME_CLASS(CtestwndView)*/, CSize(230, 0), pContext); // 左面的视窗,用来放一个控件(Out Look Bar control)
m_wndSplitter.CreateView(0, 1, /*RUNTIME_CLASS(CSplitFrame)*/pContext->m_pNewViewClass, CSize(0, 0), pContext); // 右面的视窗.用来放一个自己定义框架(CMyFrameWnd 对象)
m_wndSplitter.SetActivePane(0, 1); m_wndSplitter.RecalcLayout();
m_wndSplitter.SetSplitterStyle(XT_SPLIT_NOFULLDRAG); return TRUE;
}自己定义框架CMyFrameWnd 的定义 和 实现:
lass CViewCgMap;class CFrameWndCgMap : public CFrameWnd
{
DECLARE_DYNCREATE(CFrameWndCgMap)protected:
CFrameWndCgMap();
virtual ~CFrameWndCgMap();public:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
public:
protected: CXTPDockingPaneManager m_paneManager; DECLARE_MESSAGE_MAP()
public:
CViewCgMap *m_pNewView;
afx_msg void OnNcPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};-----------------实现-----------------
#include "ViewCgMap.h"// CFrameWndCgMapIMPLEMENT_DYNCREATE(CFrameWndCgMap, CFrameWnd)CFrameWndCgMap::CFrameWndCgMap() : m_pdlgAttrib(NULL), m_pNewView(0), m_pDoc(0)
{
}CFrameWndCgMap::~CFrameWndCgMap()
{}BEGIN_MESSAGE_MAP(CFrameWndCgMap, CFrameWnd/*CFormView*/)
ON_WM_CREATE()
ON_WM_NCPAINT()
END_MESSAGE_MAP()
// CFrameWndCgMap 诊断#ifdef _DEBUG
void CFrameWndCgMap::AssertValid() const
{
CFrameWnd::AssertValid();
}void CFrameWndCgMap::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUGint CFrameWndCgMap::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码 // 创建CViewCgMap 这样做的好处是不用在框架中调整框架的位置
CCreateContext ccontext;
ccontext.m_pNewViewClass = RUNTIME_CLASS(CViewCgMap);
ccontext.m_pCurrentDoc = m_pDoc;
ccontext.m_pNewDocTemplate = m_pDoc->GetDocTemplate()/*NULL*/;
ccontext.m_pLastView = NULL;
ccontext.m_pCurrentFrame = NULL/*this*/; m_pNewView = STATIC_DOWNCAST(CViewCgMap, CFrameWnd::CreateView(&ccontext,AFX_IDW_PANE_FIRST)); // 为什么这句代码在XP系统中成功,而在win2000中返回NULL?
if (!m_pNewView)
{
MessageBox("视窗没有创建成功。");
//return -1;
}
else
{
m_pNewView->OnInitialUpdate();
SetActiveView(m_pNewView);
m_pNewView->ShowWindow(SW_SHOW);
RecalcLayout();
}
// 下面装载工具栏和工具窗口(docking pane)
// 代码................
// ...................
return 0;
}
void CFrameWndCgMap::OnNcPaint()
{
CFrameWnd::OnNcPaint(); CWnd *pWnd = AfxGetMainWnd();
if (pWnd)
{
pWnd->SendMessage(WM_SIZE); // 向主框架发送WM_SIZE消息,改变IDC_FLAT_TABCTRL控件的大小
}
}-------------------------------------------------------------------------视图类CViewCgMap 的定义
class CViewCgMap : public CView
{
DECLARE_DYNCREATE(CViewCgMap)protected:
CViewCgMap(); // 动态创建所使用的受保护的构造函数
virtual ~CViewCgMap();public:
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制此视图
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
};
这个实现代码就不写了...无关紧要.
主界面用CSplitterWnd分割为左右两个视窗.代码:
BOOL CMainFrame::OnCreateClient(LPCREATESTRUCT /*lpcs*/, CCreateContext* pContext)
{
m_wndSplitter.CreateStatic(this, 1, 2); //m_wndSplitter.CreateView(0, 0, pContext->m_pNewViewClass/*RUNTIME_CLASS(CtestwndView)*/, CSize(230, 0), pContext); // 左面的视窗,用来放一个控件(Out Look Bar control)
m_wndSplitter.CreateView(0, 1, /*RUNTIME_CLASS(CSplitFrame)*/pContext->m_pNewViewClass, CSize(0, 0), pContext); // 右面的视窗.用来放一个自己定义框架(CMyFrameWnd 对象)
m_wndSplitter.SetActivePane(0, 1); m_wndSplitter.RecalcLayout();
m_wndSplitter.SetSplitterStyle(XT_SPLIT_NOFULLDRAG); return TRUE;
}自己定义框架CMyFrameWnd 的定义 和 实现:
lass CViewCgMap;class CFrameWndCgMap : public CFrameWnd
{
DECLARE_DYNCREATE(CFrameWndCgMap)protected:
CFrameWndCgMap();
virtual ~CFrameWndCgMap();public:
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endif
public:
protected: CXTPDockingPaneManager m_paneManager; DECLARE_MESSAGE_MAP()
public:
CViewCgMap *m_pNewView;
afx_msg void OnNcPaint();
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};-----------------实现-----------------
#include "ViewCgMap.h"// CFrameWndCgMapIMPLEMENT_DYNCREATE(CFrameWndCgMap, CFrameWnd)CFrameWndCgMap::CFrameWndCgMap() : m_pdlgAttrib(NULL), m_pNewView(0), m_pDoc(0)
{
}CFrameWndCgMap::~CFrameWndCgMap()
{}BEGIN_MESSAGE_MAP(CFrameWndCgMap, CFrameWnd/*CFormView*/)
ON_WM_CREATE()
ON_WM_NCPAINT()
END_MESSAGE_MAP()
// CFrameWndCgMap 诊断#ifdef _DEBUG
void CFrameWndCgMap::AssertValid() const
{
CFrameWnd::AssertValid();
}void CFrameWndCgMap::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUGint CFrameWndCgMap::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
// TODO: 在此添加您专用的创建代码 // 创建CViewCgMap 这样做的好处是不用在框架中调整框架的位置
CCreateContext ccontext;
ccontext.m_pNewViewClass = RUNTIME_CLASS(CViewCgMap);
ccontext.m_pCurrentDoc = m_pDoc;
ccontext.m_pNewDocTemplate = m_pDoc->GetDocTemplate()/*NULL*/;
ccontext.m_pLastView = NULL;
ccontext.m_pCurrentFrame = NULL/*this*/; m_pNewView = STATIC_DOWNCAST(CViewCgMap, CFrameWnd::CreateView(&ccontext,AFX_IDW_PANE_FIRST)); // 为什么这句代码在XP系统中成功,而在win2000中返回NULL?
if (!m_pNewView)
{
MessageBox("视窗没有创建成功。");
//return -1;
}
else
{
m_pNewView->OnInitialUpdate();
SetActiveView(m_pNewView);
m_pNewView->ShowWindow(SW_SHOW);
RecalcLayout();
}
// 下面装载工具栏和工具窗口(docking pane)
// 代码................
// ...................
return 0;
}
void CFrameWndCgMap::OnNcPaint()
{
CFrameWnd::OnNcPaint(); CWnd *pWnd = AfxGetMainWnd();
if (pWnd)
{
pWnd->SendMessage(WM_SIZE); // 向主框架发送WM_SIZE消息,改变IDC_FLAT_TABCTRL控件的大小
}
}-------------------------------------------------------------------------视图类CViewCgMap 的定义
class CViewCgMap : public CView
{
DECLARE_DYNCREATE(CViewCgMap)protected:
CViewCgMap(); // 动态创建所使用的受保护的构造函数
virtual ~CViewCgMap();public:
public:
virtual void OnDraw(CDC* pDC); // 重写以绘制此视图
#ifdef _DEBUG
virtual void AssertValid() const;
virtual void Dump(CDumpContext& dc) const;
#endifprotected:
DECLARE_MESSAGE_MAP()
public:
afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
afx_msg void OnSize(UINT nType, int cx, int cy);
};
这个实现代码就不写了...无关紧要.
解决方案 »
- MFC虽然说有点老,但绝对值得一学
- 送分100分:VC++6中有没有字符串变量,不要跟我讲字符串数组。
- ID为ID_FILE_MRU_FILE1(最近文件)的菜单项无法自绘,进入不了DrawItem函数.
- 我有一个关于无线网络的问题!!!
- 如何给日期格式的字符串加上一天?
- 同一段代码,Xp就行,98就不行?
- 简单的多线程CreateThread问题
- 如何自动检测某牌号打印是不是所连的端口号?
- 如何响应F1键?
- api,sdk,mfc?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!?!??!?!?!?!?!?!??!?!?!?!?!?
- 用recordset open来执行存储过程,如有修改删除表数据等操作,取其EndOfFile程序会崩溃,怎么解决?
- 怎样用VC++操作word实现文字替换
// 创建状态信息窗口
if ( m_MyFrame&& ::IsWindow( m_MyFrame->m_hWnd ) )
{
m_MyFrame->DestroyWindow();
}
CCreateContext cc;
ZeroMemory(&cc, sizeof(cc));
m_MyFrame= (CFrameWndCgMap*)RUNTIME_CLASS(CFrameWndCgMap)->CreateObject();
if (!m_MyFrame|| !((CWnd *)m_MyFrame)->Create(
NULL, NULL, WS_CHILD, rectDummy, m_pFlatTabCtrl, IDC_MYFRAME, &cc))
{
TRACE0( "Failed to create m_pFVSatus.\n" );
return ;
}
总是出错Error: Trying to create object which is not DECLARE_DYNCREATE
or DECLARE_SERIAL: CScrollView.
Warning: Dynamic create of view type CScrollView failed.