vc6.0 MFC 单文档 静态分割窗口
2013-07-12 16:55
351 查看
静态分割窗口
(1) MFCApplication(exe)单文档工程。不妨将工程名为Test04.
(2) 添加一对话框资源,insertàresource-àdialog,选择IDD_FORMVIEW。对话框的Styles更改如下:
为新建的对话框添加类,类的名字:Ctest,类型:CFormView。
(3) 使用CSplitterWnd分割窗口:
在MainFrame类中添加一个public成员变量,名字m_MySplitter,类型CSplitterWnd。
在MainFrm.cpp中添加头文件
#include “Test04View.h”
#include “test.h”
(4) 利用classwizard类向导为CMainFrame类添加OnCreateClient事件,代码如下:
m_MySplitter.CreateStatic(this,1,2);
m_MySplitter.CreateView(0,0,RUNTIME_CLASS(Ctest), CSize(250, 150), pContext); //Ctest是对话框类
m_MySplitter.CreateView(0,1,RUNTIME_CLASS(CTest04View), CSize(250, 0), pContext); //CTest04View是视图类
SetActiveView((CTest04View*)m_MySplitter.GetPane(0,1)); //指定类视图
return true;
编译,错误:
Compiling...
MainFrm.cpp
c:\documents and settings\administrator\桌面\vc\0513\test04\test04view.h(21)
: error C2143: syntax error : missing ';' before '*'
c:\documents and settings\administrator\桌面\vc\0513\test04\test04view.h(21)
: error C2501: 'CTest04Doc' : missing storage-class or type specifiers
c:\documents and settings\administrator\桌面\vc\0513\test04\test04view.h(21)
: error C2501: 'GetDocument' : missing storage-class or type specifiers
解决:
在Test04View.h中的class
---的前面添加 class CTest04Doc;
显示:
(4) 添加一个按钮,及编辑框,使在编辑框中输入数字,在单文档中显示。
编辑若显示出现乱码,则首先在对话框列表中的对应对话框右击,改为chinese,并将对话框属性中字体改为宋体。
如图:
为按钮关联一个int类型变量m_int,
双击按钮,更改函数名为OnShowInt,编辑代码
void Ctest::OnShowInt()
{
// TODO: Add your control notification handler code here
CTest04Doc* pDoc =(CTest04Doc*) GetDocument();
UpdateData(TRUE);
pDoc->x=m_int;
pDoc->UpdateAllViews(NULL);
}
并且在test.cpp其开始处添加头文件#include
"Test04Doc.h"
为编辑框中输入的数据在CTest04Doc中传输设置一个变量int类型,名字x。CTest04Doc类的构造函数中将其初始化0即:x=0;
在CTest04View类的OnDraw()函数中添加代码,
void CTest04View::OnDraw(CDC* pDC)
{
CTest04Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
CString str;
str.Format("%d", pDoc->x);
pDC->TextOut(0,0,str);
}
注意头文件的添加。
相关文章推荐
- vc6.0 MFC 单文档 静态分割窗口
- vc6.0 MFC 单文档 静态分割窗口
- vc6.0 MFC 单文档 静态分割窗口 --learn 3
- vc6.0 MFC 单文档 静态分割窗口
- MFC多文档窗口的静态分割和坐标轴的绘制
- MFC单文档分割窗口
- Ogre学习笔记(三)OgreMFC 单文档分割窗口
- 可切换视图的单文档静态分割窗口总结
- MFC基于单文档分割窗口
- 在线等:使用MFC单文档将窗口分割成一行两列
- VS2010/MFC编程入门之四十一(文档、视图和框架:分割窗口)
- MFC窗口静态分割
- MFC静态分割视图窗口,切换,固定
- CSplitterWnd类分割MFC单文档应用程序窗口
- MFC CSplitterWnd 静态分割窗口
- VS2010/MFC编程入门之四十一(文档、视图和框架:分割窗口)
- MFC CSplitterWnd 静态分割窗口
- 【数字图像处理】 二.MFC单文档分割窗口显示图片
- MFC对单文档进行窗口分割。
- MFC 多文档程序分割窗口