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

GUI Threads

0 views
Skip to first unread message

Michael Broda

unread,
Apr 23, 2002, 4:27:16 PM4/23/02
to
Hi,

I have a child dialog box that runs on its own GUI thread.
How can I pass parameters to the GUI thread in a safe way? I have been told
that PostThreadMessage(...) is the way to go but what if I have ten
parameters to pass? Would I have to post ten message, one for each
parameter? Thanks.


David Schwartz

unread,
Apr 23, 2002, 4:50:49 PM4/23/02
to
Michael Broda wrote:

Just create a structure to hold all the information you want to pass.
Allocate the structure with malloc or new. Pass the address of the
structure to the GUI thread. When the GUI thread is done with the
structure, have it free/delete it.

DS

Alexander Terekhov

unread,
Apr 23, 2002, 5:43:37 PM4/23/02
to

David Schwartz wrote:
>
> Michael Broda wrote:
>
> > I have a child dialog box that runs on its own GUI thread.
^^^^^^^^^^

> > How can I pass parameters to the GUI thread in a safe way? I have been told
> > that PostThreadMessage(...) is the way to go but what if I have ten
> > parameters to pass? Would I have to post ten message, one for each
> > parameter? Thanks.
>
> Just create a structure to hold all the information you want to pass.
> Allocate the structure with malloc or new. Pass the address of the
> structure to the GUI thread. When the GUI thread is done with the
> structure, have it free/delete it.

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/winui/messques_1ued.asp

"Messages sent by PostThreadMessage are not associated with a window.
Messages that are not associated with a window cannot be dispatched
by the DispatchMessage function. Therefore, if the recipient thread
is in a modal loop (as used by MessageBox or DialogBox), the messages
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
will be lost. To intercept thread messages while in a modal loop,
use a thread-specific hook. "

BTW, I really like this:

"Remarks

The thread to which the message is posted must have created a
message queue, or else the call to PostThreadMessage fails.
Use one of the following methods to handle this situation:

Call PostThreadMessage. If it fails, call the Sleep function
and call PostThreadMessage again. Repeat until PostThreadMessage
succeeds. "

;-)

Well, but to be fair, pthread_create/EAGAIN isn't much better,
I think (unless I'm missing something -- PLEASE HELP)! ;-)

Oh, Ah, BTW, my *THREADING LINK OF THE YEAR*:

http://msdn.microsoft.com/downloads/default.asp?URL=/downloads/sample.asp?url=/MSDN-FILES/027/001/901/msdncompositedoc.xml
("The Shared Source CLI Beta" -- have some ".Net" fun, folks!!!)

regards,
alexander.

0 new messages