Click to See Complete Forum and Search --> : Posting Messages
Andrew Truckle
April 9th, 1999, 01:22 AM
I have a thread which sends user defined messages to another window.
How can I get it to send a text string?
For example, the window which receives a certain message has a static text control which I would like to update.
At the moment I have derived a series of CONSTANTS and sent those. Then the message handler sets the text according to which CONSTANT was received.
There must be a more flexible approach.
I hope someone can help.
April 9th, 1999, 04:06 AM
In the thread you can send the message using something like:
CString sendstring = _T("Send this text");
char *lpszPostedBytes = (char *) LocalAlloc(LPTR,sendstring.Length() + 1);
if (lpszPostedBytes != NULL)
{
strcpy(lpszPostedBytes, (LPCTSTR) sendstring);
PostMessage(myWnd, YOUR_MESSAGE, (LPARAM) lpszPostedBytes, 0L);
}
Then release the memory when the message been processed using:
LocalFree();
anuvk
April 9th, 1999, 11:49 PM
I HAVE done this before...
I did Send Message() ;
I didnt find the necessity for any user defined messages
U can instead adhere to WM_SETTEXT
It worked perfectly
April 10th, 1999, 01:32 AM
SendMessage to main app from a thread is DANGEROUS. It can cuase dead locks. Don't do it!
Andrew Truckle
April 10th, 1999, 10:05 AM
Hi, thanks for your sample code.
I've added it in, but have one problem. How to I do when the message has been processed so that I can call LocalFree()?
sally
April 12th, 1999, 09:25 PM
LocalFree is called on the receiving side
Sally
Sally
April 12th, 1999, 09:25 PM
LocalFree is called on the receiving side
Sally
Andrew Truckle
April 13th, 1999, 08:44 AM
Hi Sally
I've tried putting LocalFree(var) into the message handler function, but it doesn't like the parameter being passed which is now a LPARAM.
Any ideas?
MikeL
April 13th, 1999, 09:46 AM
LocalFree((char*) var)?
April 13th, 1999, 07:38 PM
Sure, for some strange reason I couldn't log in today.....
you have to cast the LPARAM to the correct datatype to be freed
Sally
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.