🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Messages and threads

#14886
From: Joe Walker
Date: Tue, 29 Jul 2003 18:21
113 lines
4149 bytes
"Remy Lebeau (TeamB)" <gambit47@yahoo.com> wrote in message
news:3f26a1e2$1@newsgroups.borland.com...
>
> Messages cannot be broadcasted to threads directly, only to windows.  To
> broadcast a message to multiple threads, you'll have to either 1) give
each
> thread its own individual window, or 2) maintain a list of thread IDs and
> then send your message to each ID one at a time.

Yes, you are right..Since I am new at this topic, I didnt know it..



>
> > BEGIN_MESSAGE_MAP
> >     MESSAGE_HANDLER(WM_MYFIRSTMESSAGE, TMessage, MyMessageHandler)
> > END_MESSAGE_MAP(TThread);
>
> You cannot use a MESSAGE_MAP with a thread.
>
No, I can use..:)
Actually I have modified the BEGIN_MESSAGE_MAP macro definition.. It simply
calls the Dispatch method and it takes void *

#define BEGIN_MESSAGE_MAP virtual void __fastcall Dispatch(void *Message)
{switch  (((PMessage)Message)->Msg) }{

I have defined this macro as follows:

#define MY_BEGIN_MESSAGE_MAP virtual void __fastcall Dispatch(tagMSG
*Message) { switch  (Message->message)    {

and my handler function takes argument as tagMSG* ( not TMessage)..

and the code->

                   while( (bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
                   {
                        if (msg.message==WM_MYFIRSTMESSAGE)
                                Dispatch(&msg);
                   }

now, my handler works greate..


> >                     MSG msg;
> >                     HANDLE HWND
> >                    if ((bRet = GetMessage( &msg,HWND, 0, 0)) != 0)
>
> You are passing an invalid HWND to GetMessage().  For a thread, pass NULL
> instead:
>
You are right


>     if ((bRet = GetMessage( &msg, NULL, 0, 0 )) != 0)
>
> >                                    TranslateMessage(&msg);
> >                                     DispatchMessage(&msg);
>
> You are not using any windows in your thread.  so there is no need to
> translate the message.  Simply perform your operations directly:
>
>     if (msg.message==WM_MYFIRSTMESSAGE)
>     {
>         int a=2;
>         //...
>     }
>
> Or:
>
>     void __fastcall MyMessageHandler(MSG &msg);
>
>     void __fastcall TExampleThread::MyMessageHandler(MSG &msg)
>     {
>         int a=2;
>         //...
>     }
>
>     if( msg.message == WM_MYFIRSTMESSAGE )
>         MyMessageHandler(msg);
>
No Need it anymore. Dispacth Method calls the correct handler..


> >         ShowMessage(PostMessage(HWND_BROADCAST,WM_MYFIRSTMESSAGE, 1,2));
>
> That is not the correct way to send a message to a thread.  HWND_BROADCAST
> sends the message to all top-level windows.  Your thread has no such
window.
>
> > ShowMessage(PostThreadMessage(ExampleThread->ThreadID,WM_MYFIRSTMESSAGE,
> > 1,2));
>
> That is the correct way to send a message to a thread.
>

You are right again..

> > Both returns 1 but, my first thread cant get message?
>
> Correct, because 1) the message was never sent to the thread in the first
> place, and 2) you are not reading the messages for that thread correctly
> anyway.
>
>
> Gambit
>
>


Thanks to everyone who answered my questions..
Technical Details
Message-ID: <3f26bb1d@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f264d2b@newsgroups.borland.com> <3f26a1e2$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 10cc67,c519897f9efe71e1
X-Google-Attributes: gid10cc67,public
X-Google-ArrivalTime: 2003-07-29 11:40:45 PST
From: "Joe Walker" <__JoeW@hotmail.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f264d2b@newsgroups.borland.com> <3f26a1e2$1@newsgroups.borland.com>
Subject: Re: Messages and threads
Date: Tue, 29 Jul 2003 21:21:27 +0300
Lines: 115
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
NNTP-Posting-Host: 144.122.180.3
Message-ID: <3f26bb1d@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1059502877 144.122.180.3 (29 Jul 2003 11:21:17 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-06!sn-xit-09!supernews.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail