1.假如我开启了一个线程调用文档中的函数修改了文档的数据, 怎样**立即**让相关的视图(因为文档对应好几个视图)更新? 如果在那个函数用UpdateAllViews(NULL)会出错, 不知道是不是和多线程有关.2.视图的OnDraw函数会在什么情况下触发?用 UpdateAllViews好像不会触发这个函数.3.在第一问中, 假如文档对应的视图有很多个, 如果数据的变化仅仅需要更新到其中一个View, 用UpdateAllViews的话, 视图全部刷新一次, 会不会很影响效率? 一般来说是怎样做的?按照我的的想法是更新视图的时候, 要在视图里面先GetDocument()将文档的相关数据读取出来, 再全部更新到视图. 但是假如数据变化很少, 如何做到只更新数据改变的部分(例如增/删CListView中的某一项?) 是否要让文档自己指定相关的View然后调用那个View的函数去更新? 但是用文档去指引View这样做的话界面/数据的分离就变得没有意义了...

解决方案 »

  1.   

    1 send a message to the view and call UpdateAllViews(NULL) in the handler function
    2 use RedrawWindow
    3 call UpdateAllViews with hints
      

  2.   

    你要更新某个视图,你可以调用此视图的Invalidate函数,别的视图就不会被更新了。
      

  3.   

    to jiangsheng(蒋晟.Net[MVP])
    我在Doc类用CView *保存了 CXXXView的指针
    然后用 pView->SendMessage(WM_USER+1)
    在CXXXView里面的PreTranslateMessage没有得到这个消息.why ne
      

  4.   

    Older books on Windows programming tell about how to define user-defined messages using the symbol WM_USER. This technique is obsolete. There were too many problems with WM_USER-based symbols conflicting with messages that Microsoft was using. The new method is to use WM_APP as the base.from http://blogs.msdn.com/oldnewthing/archive/2003/12/02/55914.aspx......Valid window messages break down into four categories. 0 .. 0x3FF (WM_USER-1): System-defined messages. 0x400 .. 0x7FFF (WM_USER .. WM_APP-1): Class-defined messages. 
    The meanings of these messages is determined by the implementor of the window class. (Informally: By the person who calls RegisterClass for that window class.) For example, the WM_USER+1 message means TB_ENABLEBUTTON if the window is a toolbar control, but it means TTM_ACTIVATE if it is a tooltip control, and it means DM_SETDEFID if it is a dialog box. If you created your own control, it would mean something else completely different. Since anybody can create a message in this range, the operating system does not know what the parameters mean and cannot perform automatic marshalling. 0x8000 .. 0xBFFF (WM_APP ... MAXINTATOM-1): Application-defined messages. 0xC000 .. 0xFFFF (MAXINTATOM .. MAXWORD): Registered messages.