Note: The following uses a homemade dialogue class (MyMessageDLG) to send a custom message to the view class (MessageTestView) as an example, indicating a custom message for both different methods.
Summary: Message Password 1: Using ON_MESSAGE Use ON_MESSAGE response message, you must match the definition message #define WM_MY_MESSAGE (WM_USER 100)
For sending a message -myessagedlg, in its mymessagedlg.h, #DEFINE WM_MY_MESSAGE (WM_USER 100) is defined in its mymessagedlg.cpp: #include "mainfrm.h" is used because of the use of CMAINFRAME * definition objects. And there must be a function of testing message: void mymessagedlg :: onbuttonmsg () {// Todo: add your control notification handler code here cmainframe * PMF = (cmainframe *) AFXGetApp () -> m_pmainwnd; // First get the current frame pointer CView * Active = PMF-> getActiveView (); // can get the current viewing class pointer if (Active! = Null) // Get the current viewer pointer to send a message Active-> PostMessage (WM_MY_MESSAGE, 0, 0); / / Use PostMessage Send Message}
-MessageTestView message to the recipient, in which the MessageTestView.h well defining #define WM_MY_MESSAGE (WM_USER 100) and defining message mapping function -OnMyMessage () protected: // {{AFX_MSG (CMessageTestView) afx_msg LRESULT OnMyMessage (WPARAM wParam, LPARAM lParam); //}} AFX_MSG DECLARE_MESSAGE_MAP () in which the MessageTestView.cpp, first Assertion response message: BEGIN_MESSAGE_MAP (CMessageTestView, CEditView) // {{AFX_MSG_MAP (CMessageTestView) ON_MESSAGE (WM_MY_MESSAGE, OnMyMessage) //} } AFX_MSG_MAP Add Message Response Function: LRESULT CMESSAGETESTVIEW :: ONMYMESSAGETESTVIEW :: ONMYMESSAGETSTVIEW :: ONMYMESSAGE (WPARAM WPARAM, LPARAM LPARAM) {MessageBox ("OnmyMESSAGE!"); Return 0;}
Method of message delivery: Use on_registered_message to use the on_registered_message registration message, you must cooperate with Static Uint WM_MY_MESSAGE = RegisterWindowMessage ("Message");
For the sender-MyMessagedlg of the message, in its mymessagedlg.h, as long as the Static Uint WM_MY_MESSAGE = RegisterWindowMessage ("Message") is defined; Add: #include "mainfrm.h" in its mymessagedlg.cpp. And there must be a function of testing message: void mymessagedlg :: onbuttonmsg () {// Todo: add your control notification handler code here cmainframe * PMF = (cmainframe *) AFXGetApp () -> m_pmainwnd; // First get the current frame pointer CView * Active = PMF-> getActiveView (); // can get the current viewing class pointer if (Active! = Null) // Get the current viewer pointer to send a message Active-> PostMessage (WM_MY_MESSAGE, 0, 0); / / Use PostMessage Send Message ► Receiver -MessageTestView for messages, do not define Static Uint WM_MY_MESSAGE = RegisterWindowMessage ("Message" in its messagetestView.h; you should put this definition in MessageTestView.cpp, should not appear: Redefinition MessageTestView.h defined in its message as long as the mapping functions protected: // {{aFX_MSG (CMessageTestView) afx_msg LRESULT OnMyMessage (WPARAM wParam, LPARAM lParam); //}} aFX_MSG DECLARE_MESSAGE_MAP () in which the MessageTestView.cpp, define static UINT WM_MY_MESSAGE = RegisterWindowMessage ( "message"); and then the registration message: BEGIN_MESSAGE_MAP (CMessageTestView, CEditView) // {{AFX_MSG_MAP (CMessageTestView) ON_REGISTERED_MESSAGE (WM_MY_MESSAGE, OnMyMessage) //}} AFX_MSG_MAP added last message response function implemented: LRESULT CMessageTestView: : ONMYMESSAGE (WPARAM WPARAM, LPARAM LPARAM) {MessageBox ("O" O "O" NmyMessage! "); return 0;} ----------------------------------------- ------------------------ compare two methods, just slightly different. But be careful to be cautious, so as not to receive the information that does not receive the message.
-------------------------------------------------- -----------------
Other considerations:
Before sending a message - MyMessagedlg.cpp, Static Uint WM_MY_MY_MESSAGE = RegisterWindowMessage ("Message");
Before receiving the message - BessageTestView.cpp, Static Uint WM_MY_MY_MESSAGE = RegisterWindowMessage ("Message");