Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a thread that is receiving serial COM data. It puts the data into the buffer used by the View to display the received data.

My problem is: How to tell the View that new data has been put into the buffer.

I have tried using PostMessage to the m_hWnd of the View. But it does not get there. SendNotifyMessage also does not work.

I have read this article:
Message Management[^]

He suggests using a Registered User Message to send a message to the View. Is this what I need to do, or is there another easier way, maybe one that I have overlooked?

Gary
Posted

You will probably need to use PostThreadMessage()[^] to get it to the View.


wrote:
He suggests using a Registered User Message


That is a possibility; the important thing is that whatever message you choose, the View is able to intercept it and process it correctly. Using a user defined message ensures that it will be ignored by the Windows framework.
 
Share this answer
 
I finally got it to work.

Had to follow the suggestions in this article:
Message Management

My worker thread does a PostMessage to the Main window handle, with a registered user message. The Main Frame has a handler to receive it. This sends the message to the Child Frame, which has a handler, which sends it to the View. In the View I do UpdateAllViews. This worked.

Gary
 
Share this answer
 
wrote:
PostThreadMessage sends the message in the wrong direction. I need it to go from the thread to the View.

You have (at least) two threads, the worker thread (the one receiving data on the serial line) and the main (GUI) one. You need to call PostThreadMessage passing, as first argument, the id of the main thread (see the documentation PostThreadMessage Function).
:)
 
Share this answer
 
wrote:
PostThreadMessage sends the message in the wrong direction. I need it to go from the thread to the View.


I don't understand what you mean by this. If your code is in a separate thread from the View, then you just send it to the View's thread; probably the application main thread.
 
Share this answer
 
So I may be wrong about not being able to use PostThreadMessage. I am trying it.

I have put the PostThreadMessage call in my worker thread, pointing it to the View.

What 'OnXxxx' or 'WM_Xxx' function do I choose to receive this in the View? OnNotify and OnCommand do not seem to catch it.

Thanks for the responses. I appreciate the help. I am still learning this.
Gary
 
Share this answer
 
wrote:
What 'OnXxxx' or 'WM_Xxx' function do I choose to receive this in the View? OnNotify and OnCommand do not seem to catch it.


Not sure how you do this it's rather a long time since I did any MFC. However, I thought there was a simple macro for messages that do not have specific ones in the library. Something like:
ON_MESSAGE(WM_USERVALUE, MyFunction)
 
Share this answer
 
I have not written the 'ON_MESSAGE' handler yet, because it was suggested that what I could do more simply is to just do UpdateAllViews.

I have tried this, first using the Document pointer, then calling UAV:
pDoc->UpdateAllViews(NULL);

But this gives me a Runtime error, a Debug Assertion Failed.

Any more suggestions?
Gary
 
Share this answer
 
wrote:
But this gives me a Runtime error, a Debug Assertion Failed.


This message is a hint to you to take a look at the information provided and see why the assertion occurred. It is most likely to be caused by trying to use an uninitialised or wrongly set pointer. If you are not sure exactly which line is failing then try trapping with the debugger.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900