求解VC高手
一个WIN32工程写一个MFC的窗口切分的例子代码://MFCSplit.cpp:Definestheentrypointfortheapplication.//#inc...
一个WIN32工程写一个MFC的窗口切分的例子
代码:
// MFCSplit.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include <afxhtml.h>
//支持动态创建的视图类
class CMyView:public CView
{
DECLARE_DYNCREATE(CMyView)
DECLARE_MESSAGE_MAP()
public:
virtual void OnDraw( CDC* pDC );
protected:
afx_msg void OnTest();
};
BEGIN_MESSAGE_MAP(CMyView,CView)
ON_COMMAND(ID_TEST,OnTest)
END_MESSAGE_MAP()
void CMyView::OnTest()
{
MessageBox("CMyView::OnTest");
}
void CMyView::OnDraw( CDC* pDC )
{
pDC->TextOut(10,10,"Hello MFCSplit!");
}
IMPLEMENT_DYNCREATE(CMyView,CView)
//框架窗口类
class CMainFrame:public CFrameWnd
{
public:
virtual BOOL OnCreateClient( LPCREATESTRUCT lpcs,
CCreateContext* pContext );
CSplitterWnd m_wndSplit;//切分窗口对象
CSplitterWnd m_wndSplit2;//再切分窗口对象
};
/*
//动态切分
BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs,
CCreateContext* pContext )
{
//完成动态切分窗口
// 1 指定窗口切分使用的视图类
CCreateContext cxt;
cxt.m_pNewViewClass=RUNTIME_CLASS(CMyView);
//2 创建切分窗口
m_wndSplit.Create(this,2,2,CSize(200,200),&cxt);
return TRUE;
}
*/
//静态切分
BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs,
CCreateContext* pContext )
{
//1 创建静态切分
m_wndSplit.CreateStatic(this,1,2);
//2 窗口的再切分
m_wndSplit2.CreateStatic(&m_wndSplit,2,1,
WS_CHILD|WS_VISIBLE,m_wndSplit.IdFromRowCol(0,0));
//2 创建视图窗口
/*
m_wndSplit.CreateView(0,0,RUNTIME_CLASS(CMyView),
CSize(200,200),pContext);
*/
m_wndSplit2.CreateView(0,0,RUNTIME_CLASS(CMyView),
CSize(200,200),pContext);
m_wndSplit2.CreateView(1,0,RUNTIME_CLASS(CEditView),
CSize(200,200),pContext);
m_wndSplit.CreateView(0,1,RUNTIME_CLASS(CHtmlView),
CSize(200,200),pContext);
//获取CHtmlView视图对象
CHtmlView *pView=
(CHtmlView *)m_wndSplit.GetPane(0,1);
//打开指定路径的资源
pView->Navigate("C:\\");
//设置分割条位置
m_wndSplit.SetColumnInfo(0,200,1);
m_wndSplit2.SetRowInfo(0,100,1);
//为了处理菜单消息,设置活动视图
m_wndSplit2.SetActivePane(0,0);
return TRUE;
}
//应用程序类
class CSplitApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
CSplitApp theApp;//唯一的全局应用程序变量
BOOL CSplitApp::InitInstance()
{
CMainFrame *pFrame=new CMainFrame;
pFrame->LoadFrame(IDR_MAINFRAME);
m_pMainWnd=pFrame;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
} 展开
代码:
// MFCSplit.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include "resource.h"
#include <afxhtml.h>
//支持动态创建的视图类
class CMyView:public CView
{
DECLARE_DYNCREATE(CMyView)
DECLARE_MESSAGE_MAP()
public:
virtual void OnDraw( CDC* pDC );
protected:
afx_msg void OnTest();
};
BEGIN_MESSAGE_MAP(CMyView,CView)
ON_COMMAND(ID_TEST,OnTest)
END_MESSAGE_MAP()
void CMyView::OnTest()
{
MessageBox("CMyView::OnTest");
}
void CMyView::OnDraw( CDC* pDC )
{
pDC->TextOut(10,10,"Hello MFCSplit!");
}
IMPLEMENT_DYNCREATE(CMyView,CView)
//框架窗口类
class CMainFrame:public CFrameWnd
{
public:
virtual BOOL OnCreateClient( LPCREATESTRUCT lpcs,
CCreateContext* pContext );
CSplitterWnd m_wndSplit;//切分窗口对象
CSplitterWnd m_wndSplit2;//再切分窗口对象
};
/*
//动态切分
BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs,
CCreateContext* pContext )
{
//完成动态切分窗口
// 1 指定窗口切分使用的视图类
CCreateContext cxt;
cxt.m_pNewViewClass=RUNTIME_CLASS(CMyView);
//2 创建切分窗口
m_wndSplit.Create(this,2,2,CSize(200,200),&cxt);
return TRUE;
}
*/
//静态切分
BOOL CMainFrame::OnCreateClient( LPCREATESTRUCT lpcs,
CCreateContext* pContext )
{
//1 创建静态切分
m_wndSplit.CreateStatic(this,1,2);
//2 窗口的再切分
m_wndSplit2.CreateStatic(&m_wndSplit,2,1,
WS_CHILD|WS_VISIBLE,m_wndSplit.IdFromRowCol(0,0));
//2 创建视图窗口
/*
m_wndSplit.CreateView(0,0,RUNTIME_CLASS(CMyView),
CSize(200,200),pContext);
*/
m_wndSplit2.CreateView(0,0,RUNTIME_CLASS(CMyView),
CSize(200,200),pContext);
m_wndSplit2.CreateView(1,0,RUNTIME_CLASS(CEditView),
CSize(200,200),pContext);
m_wndSplit.CreateView(0,1,RUNTIME_CLASS(CHtmlView),
CSize(200,200),pContext);
//获取CHtmlView视图对象
CHtmlView *pView=
(CHtmlView *)m_wndSplit.GetPane(0,1);
//打开指定路径的资源
pView->Navigate("C:\\");
//设置分割条位置
m_wndSplit.SetColumnInfo(0,200,1);
m_wndSplit2.SetRowInfo(0,100,1);
//为了处理菜单消息,设置活动视图
m_wndSplit2.SetActivePane(0,0);
return TRUE;
}
//应用程序类
class CSplitApp:public CWinApp
{
public:
virtual BOOL InitInstance();
};
CSplitApp theApp;//唯一的全局应用程序变量
BOOL CSplitApp::InitInstance()
{
CMainFrame *pFrame=new CMainFrame;
pFrame->LoadFrame(IDR_MAINFRAME);
m_pMainWnd=pFrame;
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询