您的位置:首页 > 其它

vc6.0 MFC 单文档 静态分割窗口

2013-07-12 16:55 351 查看

静态分割窗口

(1)       MFC
Application(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);
 
}
注意头文件的添加。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: