如何创建视图的对象? [英] how to create an object of a view ?

查看:125
本文介绍了如何创建视图的对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

实际上,我在视图中所做的绘制很少,现在我想将视图中的所有内容收集到一个对象中,以便可以通过序列化方法将其写到磁盘上?

actually I have done few drawing in the view and now i want to collect everything in view in to an object so that i can write it on the disk by serialize method ?

推荐答案

亲爱的Pradeep,

您的思维方式不是一个好的方法.正确的方法是在CDocument类中定义将包含图形对象属性的变量,并在文档类中重写CObject :: Serialize成员函数以序列化所有变量.并使用此初始化变量在CView :: OnDraw()中绘制对象.

例如.要绘制矩形,您将需要在CDocument中使用CRect变量,并在CView :: OnDraw()中使用此变量绘制Rectangle.在CDocument :: Serialize()中,使用CRect变量存储矩形.
Dear Pradeep,

The way you are thinking is not a good approach. The correct way is to define the variable in your CDocument Class which will holds a properties of your graphical object and Override the CObject::Serialize member function in your document class to serialize all the variable. And use this initialized variable to draw the object in CView::OnDraw().

eg. To draw a rectangle you will need CRect variable in CDocument and in CView::OnDraw() use this variable to draw the Rectangle. In CDocument::Serialize() use CRect variable to store the rectangle.


这篇关于如何创建视图的对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆