My previous article is about "the way to send and receive the transmission and reception of two custom messages" can be encountered when I use a message to transfer, I have encountered a confused problem, so I finally solved it. .
-------------------------------------------------- ----------- I have done it for a message, using cmainframe * pmf = (cmainframe *) AFXGetApp () -> m_pmainwnd; // By getting current frame pointer cView * Active = PMF-> getActiveView (); // Get the current viewer pointer if (active! = null) active-> postmessage (WM_MY_MESSAGE, 0, 0); // Use postMessage to send messages to send I defined messages. So smooth, I received the message in the View class to receive.
However, two custom messages are defined in a class, and when they send two different View view classes, if they still take photos, they have some problems.
Why do you say that there will be a problem?
Please note that in the above code, how to get a pointer to the View class. Yes, it is used to getActiveView (), which is the function of this function to get the "Current" view pointer.
The reason why I have a problem, which is the reason for a VIEW class that cannot be received.
-------------------------------------------------- ---------- The following detailed explanation of the process and resolution process I am wrong.
Source: A SDI is used in a static separation, and is divided into two parts of the left and right size, and the two parts points to two new classes created by themselves: CMYLEFTVIEW and CMYRightView, their base classes are CeditView. . So the views of these two are ready to receive messages, except for the name, there is nothing unhappy.
A dialog (CMYFINDDIALOG class) has 2 Radio Button controls, and a certaintable button, which makes it only to be single, and they respectively said in the previous selection. Two parts of the left and right, after selecting, click the OK button to send a message to which view is sent.
Do a good job of sending and receiving, running discovery, only one message is received, void cmyfinddialog :: onbuttonfind () {mainframe * PMF = (cmainframe *) AFXGetApp () -> m_pmainwnd; cView * Active = PMF-> getActiveView (); // Gets the current viewpoint pointer // error is wrong in the previous sentence, the Active is an "uncertain" object. if (m_selLeft == TRUE) {if (active = NULL!) active-> PostMessage (WM_MY_MESSAGE_LEFT, 0,0);} else if (m_selRight == TRUE) {if (! active = NULL) active-> PostMessage (WM_MY_MESSAGE_RIGHT , 0, 0); Else MessageBox ("Must Choose One!");
By getActiveView (), the focus (cursor) is on the left before you open the dialog, then the left can receive the message on the left, how can you receive it on the right? If you open the dialog, the focus (cursor) is on the right, then it is to receive the message on the right, how can you receive it on the left? After the program is running, the focus (cursor) The default is on the left, which also causes me that I have a problem with the reception message on the right. In fact, if you change the focus (cursor) to the right after the program is running, then open the dialog to test the send and receive, it will become the left pass the message, and the message can be received. (This is still in the forum, others have reminded that they found the mistake. Otherwise, it is still considered whether the reception is part of the problem.) For such a message issue to 2 View classes, it is to pay attention to you Who is the object of the postMessage? Correct code as follows: void CMyFindDialog :: OnButtonFind () {CMainFrame * pMF = (CMainFrame *) AfxGetApp () -> m_pMainWnd; CMyLeftView * pLV = (CMyLeftView *) pMF-> m_wndSplitter.GetPane (0,0); CMyRightView * PRV = (CMYRIGHTVIEW *) PMF-> m_wndsplitter.getpane (0, 1); // For me, it is to get it actually and determined // view class pointer by dividing the object m_wndsplitter. // If you are also a plurality of view classes, but not cut, but not, just pay attention to // getting you determine the view object pointer. IF (m_selleft == true) {if (PLV! = null) PLV-> PostM_MY_MESSAGE_LEFT, 0, 0);} else if (m_selright == true) {if (pRV! = null) PRV-> PostM_MY_MESSAGE_RIGHT , 0, 0); Else MessageBox ("Must Choose One!");
Summary: When you need to send a message to multiple view objects, consider what you are sending a message to what kind of view object.
If you are sending a message to the current view object in multiple view objects, then the method I originally "error" is correct for you.
But if you are not sending messages to the current view object, but there is a clear goal, then you should pay attention to it, you must get the determined view pointer, then use (view *) -> PostMessage (,) When sending messages, the recipient can receive to your message.