|
-
April 9th, 1999, 01:22 AM
#1
[RESOLVED] Posting Messages
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
#2
Re: Posting Messages
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();
-
April 9th, 1999, 11:49 PM
#3
Re: Posting Messages
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
#4
Re: Posting Messages
SendMessage to main app from a thread is DANGEROUS. It can cuase dead locks. Don't do it!
-
April 10th, 1999, 10:05 AM
#5
Re: Posting Messages
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()?
-
April 12th, 1999, 09:25 PM
#6
Re: Posting Messages
LocalFree is called on the receiving side
Sally
-
April 13th, 1999, 08:44 AM
#7
Re: Posting Messages
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?
-
April 13th, 1999, 09:46 AM
#8
-
April 13th, 1999, 07:38 PM
#9
Re: Posting Messages
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|