OnInitialUpdate函数 UpdateAllViews函数 说明

1.GetDocument 获得文档指针 修改文档

2.SetModifiedFlag 设置脏标志(为文档从最近一次保存以来所作的修改设置标识)

3.框架调用UpdateAllViews 其第一个参数表示忽略的视图

4.UpdateAllViews 调用每个指定视图的 OnUpdate (传递第二个参数和第三个参数)



virtual void OnInitialUpdate( );

视图窗口完成建立后第一个被框架调用的函数,框架在第一次调用OnDraw前会调用OnInitialUpdate,因此OnInitialUpdate是设置滚动视图的逻辑尺寸和映射模式的最适合的地方。
       时间上,两者先后顺序不同,构造函数生成本类的对象,但没有创建窗口,OnCreate后窗口产生,然后才是视图的OnInitialUpDate,一般在这里对视图的显示做初始化。简单点,就是OnCreate只是产生View的基本结构和变量而在OnInitialUpDate()中,主要初始化视图中控件等,对各个变量进行初始化操作。

 

视图被附加到文档时,框架中调用。OnInitialUpdate( )。

Called by the framework after the view is first attached to the document, but before the view is initially displayed. The default implementation of this function calls theOnUpdate member function with no hint information (that is, using the default values of 0 for the lHint parameter and NULL for the pHint parameter).



virtual void OnUpdate( CView* pSender, LPARAM lHint, CObject* pHint );

当试图中的文档被修改后,框架中调用。OnUpdate

Called by the framework after the view’s document has been modified;


void UpdateAllViews( CView* pSender, LPARAM lHint = 0L, CObject* pHint = NULL );

当文档被修改时调用UpdateAllViews,当你调用SetModifiedFlag函数时,UpdateAllViews被调用。

Call this function after the document has been modified. You should call this function after you call the SetModifiedFlag member function.




/**************************************/

诸位看样子都没搞清楚UpdateAllViews后面第一个参数的含义啊
void UpdateAllViews( CView* pSender, LPARAM lHint = 0L, CObject* pHint = NULL );

MSDN说得很清楚:
This function informs each view attached to the document, except for the view specified by pSender, that the document has been modified.

UpdateAllViews会通知除了pSender外的所有和当前文档关联的视图,所以用UpdateAllViews(this)是不会调用通知当前视图进行更新的,当然也就不会调用当前视图的OnUpdate了!

看看MSDN吧

/**************************************/



/**************************************/

1.请看看这两个函数的原形:
UpdateAllViews(CView * pSender,LPARAM lHint,CObject * pHint);
它会自动调用每个视图的OnUpdate
OnUpdate(CView * pSender,LPARAM lHint,CObject * pHint)
其中,LPARAM lHint可用来做标识,CObject * pHint可用来传递其种数据如RECT对象的地址,而且当UpdateAllViews调用OnUpdate时会将LPARAM lHint,CObject * pHint参数传给OnUpdate.

例如:在操作后调用UpdateAllViews(NULL,0x7C,(CObject*)pRect);如你想让一个视图响应这个特定的UpdateAllViews,你可重载它的OnUpdate
OnUpdate(CView * pSender,LPARAM lHint,CObject * pHint)
{
if (lHint==ox7C)
{
CRect *pRect=(CRect *)pHint;
InvalidateRect(pRect);
return;
}
CView::OnUpdate(pSender,lHint,pHint)
}

2.CView * pSender表示从更新循环操作中忽略由pSender指定的视图,如CView * pSender为NULL
则更新所有视图.

/**************************************/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值