使用CView类绘制我的文档数据 [英] Using CView class to draw my document data

查看:91
本文介绍了使用CView类绘制我的文档数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经创建了一个基于MFC SDI CFormview的应用程序,并且我刚刚成功添加了另一个从CView派生的视图,我一直坚持将文档数据添加到这个新视图中.我可以通过执行以下操作在OnDraw部分中添加文本:pDC-> TextOutW(100,250,L"WOW !!,这真令人困惑!!");如何显示文档中的数据?

I have created an MFC SDI CFormview based app and I just successfully added another view derived from CView, I''m stuck on adding my document data to this new view. I can add text to it in the OnDraw section by doing this: pDC->TextOutW(100, 250, L"WOW!!, this is really confusing!!"); How do I display my data from my document?

推荐答案

CView类具有名为GetDocument的方法,该方法返回指向文档的指针. > 您可以将返回的CDocument指针转换为派生文档类的指针.
如果使用向导创建了新视图,则视图类中应该有一个名为GetDocument的包装方法. 否则,请检查表单视图类的完成方式.
The CView class has a method called GetDocument that returns a pointer to the document.
You can typecast this returned CDocument pointer to a pointer of your derived document class.
If you''ve created the new view using the wizard, there should be a wrapper method called GetDocument in the view class.
Otherwise, check the form view class on how it is done.


如_Superman_所述,请使用GetDocument()从文档类中获取数据.

很少使用OnDraw()视图.如果您的视图派生自Windows控件或包含多个控件,请从视图的OnUpdate()函数调用特定于控件的更新函数,例如SetWindowText()SetItem().在创建具有对话框的OnInitDialog()之类的视图之后,使用OnInitialUpdate()初始化控件.

一个简单的例子:
As already noted by _Superman_, use GetDocument() to get the data from your document class.

OnDraw() of views is rather seldom used. If your view is derived from a Windows control or contains multiple controls, call the control specific update functions like SetWindowText(), SetItem() from the OnUpdate() function of your view. Use OnInitialUpdate() to initiliaze the controls after the view has been created like OnInitDialog() with dialogs.

A simple example:
void CMyView::OnInitialUpdate()
{
    m_editText1.SetLimitText(255);
    CView::OnInitialUpdate();
}
void CMyView::OnUpdate(CView* pSender, LPARAM lHint, CObject* pHint)
{
    m_editText1.SetWindowText(GetDocument()->GetText1());
}



lParampHint参数只能用于更新视图的特定部分.要触发更新,请使用CDocument::UpdateAllViews().



The lParam and pHint parameters can be used to update only specific parts of your view. To trigger an update, use CDocument::UpdateAllViews().


Microsoft具有 ^ ]关于除任何类以外的任何类的打印的过时文章CView.在短短的几个星期内,我正在打印数据. :-)

-DrB
Microsoft had this[^] outdated article on printing from any class other than CView. With a few minor tweeks, I''m printing my data. :-)

-DrB


这篇关于使用CView类绘制我的文档数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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