Board index » delphi » Using Application.OnMessage to get WM_USER message from other apps

Using Application.OnMessage to get WM_USER message from other apps

I'm trying to use the "Application.OnMessage" event handler to trap a
WM_USER message coming from another application. The problem is that the
way my code is defined, I seem to be having a problem receiving the
message I want. Here's my code:

procedure TForm1.AppMessage(var Msg: TMsg; var Handled:Boolean);
begin
        if (Msg.Message = WM_USER+203) then showmessage('Message Received');
end;

When I activate the above procedure (in a TForm1.Button1Click procedure)
by:

Application.onmessage := AppMessage

It doesn't see the message.

However, I notice if I replace "WM_USER+203" with "WM_CHAR" (to look for
keystrokes), this code works as long as my application is in the
foreground. My guess is that what's happening here is that I need to do
something(?) to make my app look at ALL WM_USER messages? Or can I
narrow my 'focus' down by looking at messages that are coming from a
particular window handle? Will the Application.onmessage work for what
I'm tring to do, or do I need to use something like PeekMessage (which
seems a lot harder to use)?

Any Ideas?

-Jeremy

 

Re:Using Application.OnMessage to get WM_USER message from other apps


   Only a tip:  why not trapping the WM_USER message by

       private
           procedure WM_USER (var Msg: TMsg); message WM_USER+203;

   Jeremy Wells <n...@oneworld.owt.com> wrote:

Quote
>I'm trying to use the "Application.OnMessage" event handler to trap a
>WM_USER message coming from another application. The problem is that the
>way my code is defined, I seem to be having a problem receiving the
>message I want. Here's my code:

>procedure TForm1.AppMessage(var Msg: TMsg; var Handled:Boolean);
>begin
>    if (Msg.Message = WM_USER+203) then showmessage('Message Received');
>end;

>When I activate the above procedure (in a TForm1.Button1Click procedure)
>by:

>Application.onmessage := AppMessage

>It doesn't see the message.

>However, I notice if I replace "WM_USER+203" with "WM_CHAR" (to look for
>keystrokes), this code works as long as my application is in the
>foreground. My guess is that what's happening here is that I need to do
>something(?) to make my app look at ALL WM_USER messages? Or can I
>narrow my 'focus' down by looking at messages that are coming from a
>particular window handle? Will the Application.onmessage work for what
>I'm tring to do, or do I need to use something like PeekMessage (which
>seems a lot harder to use)?

>Any Ideas?

>-Jeremy

--

          ___                                              ___
          L_|_                                            _|_J
         ( -O>                                            <O- )
      ___//\J  __________________________________________  L/\\___
     //-,\    |                                          |    /,-\\
    || / \\___L   AVONTURE Christophe (c) AVC Software   J___// \ ||
  _ ''/\/ '---J    Christophe.Avont...@is.belgacom.be    L---' \/\'' _
 / \ //\\.    |__________________________________________|    .//\\ / \
|_/\'/  ||                                                    ||  \'/\_|
     '   ||_         "Make sure that, always!, you            _||   '
         |__)       reply to my private mail adress"         (__|

Delphi Super Page: http://sunsite.icm.edu.pl/archive/delphi/_index.html

 "Postings are personnal, and don't reflect Belgacom's opinion"

Other Threads