现在的位置: 首页 > 综合 > 正文

OnInitialUpdate函数 UpdateAllViews函数 说明

2013年08月01日 ⁄ 综合 ⁄ 共 2259字 ⁄ 字号 评论关闭

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
则更新所有视图.

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

抱歉!评论已关闭.