🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.nativeapi
Article #14713

Re: Threads and messages again

#14713
From: Remy Lebeau (TeamB)
Date: Sun, 03 Aug 2003 22:28
55 lines
3136 bytes
"Joe Walker" <__JoeW@hotmail.com> wrote in message
news:3f2d85c4@newsgroups.borland.com...

> Now, the question is, what if I use GetMessage method
> outside of Execute method..? What does GetMessage do
> outside Execute method?

That depends on where it is actually being called from.  GetMessage()
retreives a message from the queue of the *calling* thread.  If you do not
call GetMessage() from Execute() directly, then you must call GetMessage()
from a method that that is called within the *context* of Execute().
Otherwise it will not work correctly as GetMessage() would be called from
the context of the wrong thread.

Please post your ACTUAL thread code as-is.

> It gets all the messages including main VCL thread?

Not unless the MessageA handler was running in the context of the main
thread instead of your worker thread.

> Here is a simple example how I use the GetMessage outside Execute
method...

That will only work if the MessageA handler is running in the context of the
same thread where the message was sent to.

> What happens here is that when I use NULL for the HWND
> parameter of GetMessage, it gets all messages (I think) even
> including mousemove

MouseMove messages only apply to thread with their own windows.  All NULL
does is tells GetMessage() to look for a message destinated for a window
belonging to the thread **or** look for a message posted via
PostThreadMessage().

> When I use (HWN)-1 for HWND parameter

That is an invalid parameter.  Never use -1 for the HWND.

> it gets nothing

Because you are asking for messages for an invalid HWND.

> and somehow program goes infinite loop

That's probably because you are not testing the return value of GetMessage()
correctly, so your are never breaking your loop appropriately.  Always test
the return value of GetMessage().  It will return -1 if an error occured.
It will return 0 if WM_QUIT was found.  It will return a value >0 if a valid
message was found.


Gambit
Technical Details
Message-ID: <3f2d8b2e$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!216.170.153.135.MISMATCH!tdsnet-transit!newspeer.tds.net!news-out1.nntp.be!propagator2-sterling!news-in-sterling.nuthinbutnews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail
References: <3f2d218e@newsgroups.borland.com> <3f2d6395@newsgroups.borland.com> <3f2d85c4@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,b0f5f87125b64df6
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-08-03 15:31:43 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f2d218e@newsgroups.borland.com> <3f2d6395@newsgroups.borland.com> <3f2d85c4@newsgroups.borland.com>
Subject: Re: Threads and messages again
Date: Sun, 3 Aug 2003 15:28:44 -0700
Lines: 57
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 207.175.226.26
Message-ID: <3f2d8b2e$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1059949358 207.175.226.26 (3 Aug 2003 15:22:38 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-04!sn-xit-03!sn-xit-01!sn-xit-09!supernews.com!216.170.153.135.MISMATCH!tdsnet-transit!newspeer.tds.net!news-out1.nntp.be!propagator2-sterling!news-in-sterling.nuthinbutnews.com!newsfeed.wirehub.nl!news.kweb.on.ca!KWeb!newsgroups.borland.com!not-for-mail