Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

PostThreadMessage & GetMessage

277 views
Skip to first unread message

Hon Yuen, Ng

unread,
Jun 5, 2003, 2:15:25 AM6/5/03
to
hi

I wish to post a message to a thread. If i'm not wrong i should use the
PostThreadMessage and GetMessage. However, i can not grab the message from
the thread's message queue. Can anybody gimme some hint where i did wrong?
Thanks in advance. =)

Here is my code snippet

procedure TTestThread.Execute;
var
msgMine: MSG;
begin
while not terminated do
begin
GetMessage(msgMine, ThreadID, 0, 0);
if msgMine.message = CSM_TEST then
Form1.Label1.Caption := IntToStr(msgMine.wParam);
end;
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
PostThreadMessage(thA.ThreadID, CSM_TEST, 1234, 0);
end;

From,
Hon Yuen, Ng

Rob Kennedy

unread,
Jun 5, 2003, 2:44:40 AM6/5/03
to
Hon Yuen, Ng wrote:
> I wish to post a message to a thread. If i'm not wrong i should use the
> PostThreadMessage and GetMessage. However, i can not grab the message from
> the thread's message queue. Can anybody gimme some hint where i did wrong?
> Thanks in advance. =)
>
> Here is my code snippet
>
> procedure TTestThread.Execute;
> var
> msgMine: MSG;
> begin
> while not terminated do
> begin
> GetMessage(msgMine, ThreadID, 0, 0);

The second parameter must be a window handle. Window handles and thread
IDs are *not* the same.

To retreive messages posted with PostThreadMessage, you must specify
zero for the window handle. The last three parameters will all be zero,
in your case.

> if msgMine.message = CSM_TEST then
> Form1.Label1.Caption := IntToStr(msgMine.wParam);

Never ever use a line like that above. Do not modify VCL components from
other threads, only from the main thread.

--
Rob


Hon Yuen, Ng

unread,
Jun 5, 2003, 2:55:40 AM6/5/03
to
It works, thanks Rob!

"Rob Kennedy" <rken...@cs.wisc.edu> wrote in message
news:3ede...@newsgroups.borland.com...

0 new messages