🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Messages and threads

#14880
From: Remy Lebeau (TeamB)
Date: Tue, 29 Jul 2003 16:39
76 lines
3543 bytes
"Fatih Keles" <fatihks@hotmail.com> wrote in message
news:3f264d2b@newsgroups.borland.com...
> Hi, I have a question about window messages. I have
> sent this post some groups and couldnt get an answer,
> maybe this group works:)

Please read the newsgroup guidelines at http://www.borland.com/newsgroups
for instructions on where you should be posting particular questions.  When
in doubt, ask in the .non-technical group where you should post.

> And in each thread I want to broadcast messages to all other threads.

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.

> BEGIN_MESSAGE_MAP
>     MESSAGE_HANDLER(WM_MYFIRSTMESSAGE, TMessage, MyMessageHandler)
> END_MESSAGE_MAP(TThread);

You cannot use a MESSAGE_MAP with a thread.

>                     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:

    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);

>         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.

> 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
Technical Details
Message-ID: <3f26a1e2$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!green.readfreenews.net!news.readfreenews.net!cox.net!news-xfer.cox.net!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <3f264d2b@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 09:40:58 PST
From: "Remy Lebeau \(TeamB\)" <gambit47@yahoo.com>
Newsgroups: borland.public.cppbuilder.nativeapi
References: <3f264d2b@newsgroups.borland.com>
Subject: Re:  Messages and threads
Date: Tue, 29 Jul 2003 09:39:28 -0700
Lines: 78
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: <3f26a1e2$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1059496418 207.175.226.26 (29 Jul 2003 09:33:38 -0700)
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!sn-xit-02!sn-xit-03!sn-xit-01!sn-xit-08!supernews.com!priapus.visi.com!news-out.visi.com!green.readfreenews.net!news.readfreenews.net!cox.net!news-xfer.cox.net!npeer.de.kpn-eurorings.net!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail