1 WM_COMMAND与一般的windows消息有什么区别,分别作什么工作?
2为什么一般的windows消息一定由派生类流向基类,而 wm_command的路线比较奇特,它遵循什么原则?
3是不是只有wm_command 放于_messageEntries[]中?
4何谓reference to pointer,怎么利用?

解决方案 »

  1.   

    建议你去问masterz,绝对高手,一般人是不成的!
      

  2.   

    所有的消息都在_messageEntries中留有入口。CWnd::OnWndMsg收到消息以后,判断如果是WM_COMMAND,就调用OnCommand来处理这个消息,否则直接在_messageEntries中寻找对应的消息进行处理。
       WM_COMMAND遵循的原则是:如果frame收到消息,先让该frame的active view处理(如果是mainframe则让active child frame处理),如果view不处理,则自己处理;如果自己也不能处理,则让消息流向app类;如果view收到消息,先自己处理,再让自己的active document处理,都未处理则返回false;如果document收到消息,先自己处理,再让对应的doc template处理,都未处理则返回false.
      你说的reference to pointer是指指针的引用?它跟别的引用没什么区别嘛。
      

  3.   

    看看<<深入浅出MFC>>吧
      

  4.   

    前三个问题你找一本侯捷的《深入浅出MFC》,里面有你需要的答案。WM_COMMAND 一般是菜单消息,包括主菜单消息,弹出式菜单消息。
    因为涉及到文档视图的框架结构,所以必须作特殊的处理。
    比如:
    在多文档视图程序中,用户选择了保存文件的菜单,文件的保存一般是文档类处理,但是文档类本身并没有消息循环。MFC通过消息映射来做到这一点,使得文档类也能处理消息。第四个问题,reference to pointer 看名字应该是“指针的引用”。
    我没有这样使用过。
      

  5.   

    MFC Library Message Mapping
    Refer to the OnLButtonDown member function in the previous example application. You might think that OnLButtonDown would be an ideal candidate for a virtual function. A window base class would define virtual functions for mouse event messages and other standard messages, and derived window classes could override the functions as necessary. Some Windows class libraries do work this way. The MFC library application framework doesn't use virtual functions for Windows messages. Instead, it uses macros to "map" specified messages to derived class member functions. Why the rejection of virtual functions? Suppose MFC used virtual functions for messages. The CWnd class would declare virtual functions for more than 100 messages. C++ requires a virtual function dispatch table, called a vtable, for each derived class used in a program. Each vtable needs one 4-byte entry for each virtual function, regardless of whether the functions are actually overridden in the derived class. Thus, for each distinct type of window or control, the application would need a table consisting of over 400 bytes to support virtual message handlers. What about message handlers for menu command messages and messages from button clicks? You couldn't define these as virtual functions in a window base class because each application might have a different set of menu commands and buttons. The MFC library message map system avoids large vtables, and it accommodates application-specific command messages in parallel with ordinary Windows messages. It also allows selected nonwindow classes, such as document classes and the application class, to handle command messages. MFC uses macros to connect (or map) Windows messages to C++ member functions. No extensions to the C++ language are necessary. An MFC message handler requires a function prototype, a function body, and an entry (macro invocation) in the message map. ClassWizard helps you add message handlers to your classes. You select a Windows message ID from a list box, and the wizard generates the code with the correct function parameters and return values. 
      

  6.   

    指针和引用都是指向一个对象(或简单类型变量的).所不同者,指针可以为空,而引用指向的对象必须存在,并且只能在定义时赋值。(愚民认为引用是为复制构造函数而作。因为,如果传值,岂不成循环了?如果传指针,若是NULL怎办,故而一代英杰-----引用出世了).指针的引用,若无特殊之用,权当是指针的指针罢(int **p;)