1 WM_COMMAND与一般的windows消息有什么区别,分别作什么工作?
2为什么一般的windows消息一定由派生类流向基类,而 wm_command的路线比较奇特,它遵循什么原则?
3是不是只有wm_command 放于_messageEntries[]中?
4何谓reference to pointer,怎么利用?
2为什么一般的windows消息一定由派生类流向基类,而 wm_command的路线比较奇特,它遵循什么原则?
3是不是只有wm_command 放于_messageEntries[]中?
4何谓reference to pointer,怎么利用?
WM_COMMAND遵循的原则是:如果frame收到消息,先让该frame的active view处理(如果是mainframe则让active child frame处理),如果view不处理,则自己处理;如果自己也不能处理,则让消息流向app类;如果view收到消息,先自己处理,再让自己的active document处理,都未处理则返回false;如果document收到消息,先自己处理,再让对应的doc template处理,都未处理则返回false.
你说的reference to pointer是指指针的引用?它跟别的引用没什么区别嘛。
因为涉及到文档视图的框架结构,所以必须作特殊的处理。
比如:
在多文档视图程序中,用户选择了保存文件的菜单,文件的保存一般是文档类处理,但是文档类本身并没有消息循环。MFC通过消息映射来做到这一点,使得文档类也能处理消息。第四个问题,reference to pointer 看名字应该是“指针的引用”。
我没有这样使用过。
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.