Board index » delphi » Intercepting external windows messages

Intercepting external windows messages

Does anyone have an example program which shows how to intercept an Windows
message which has originated from another application. I'm trying to link my
program onto anothers menu so that when the user selects my option on the
menu, my program will be able to trap it.

Thanks,

Simon.

 

Re:Intercepting external windows messages


Quote
m...@iol.ie (Simon O'Doherty) wrote:
>Does anyone have an example program which shows how to intercept an Windows
>message which has originated from another application. I'm trying to link my
>program onto anothers menu so that when the user selects my option on the
>menu, my program will be able to trap it.

>Thanks,

>Simon.

Check the Application.Onmessage event. There's sample code with it
in the docs both printed and online.
Quote

_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
_/  Green Meddler  kilga...@tde.com   Nathan F. Wallace _/
_/     http://www.webcom.com/~kilgalen/welcome.html     _/
_/     http://www.webcom.com/~kilgalen/nerelon.html     _/
_/    C.I.U.P.K.C. Software -- Unleashing the Power!    _/
_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Re:Intercepting external windows messages


In message <44mhe8$...@tde2.tde.com> - The Green Meddler <kilga...@tde.com> wri
tes:

Quote

>m...@iol.ie (Simon O'Doherty) wrote:
>>Does anyone have an example program which shows how to intercept an Windows
>>message which has originated from another application. I'm trying to link my
>>program onto anothers menu so that when the user selects my option on the
>>menu, my program will be able to trap it.

>>Thanks,

>>Simon.

>Check the Application.Onmessage event. There's sample code with it
>in the docs both printed and online.

>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
>_/  Green Meddler  kilga...@tde.com   Nathan F. Wallace _/
>_/     http://www.webcom.com/~kilgalen/welcome.html     _/
>_/     http://www.webcom.com/~kilgalen/nerelon.html     _/
>_/    C.I.U.P.K.C. Software -- Unleashing the Power!    _/
>_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/

Alternately if you want to trap a message for a particular form:

Define something like the following in the "private" declaration
area of a form type:

    procedure UserEvent( var aiMessage : TMessage ); message Wm_User;

For the handler:

    procedure TMainWin.UserEvent( var aiMessage : TMessage );
    begin

        case aiMessage.wParam of
        ...

        { Set return value. }
        aiMessage.result := 0;
        ...

    end;

Read help on "TMessage" for further info.  Hope this helps.

+---------------------------------------------------------------------
| Andrew Kostiuk
| Ark Communications
| Andrew.Kost...@sasknet.sk.ca
+---------------------------------------------------------------------

Re:Intercepting external windows messages


kilga...@tde.com (The Green Meddler)  wrote

Quote
> Check the Application.Onmessage event. There's sample code with it
> in the docs both printed and online.

I understood that this will only enable you to handle messages which reach  
your own application not messages for others.

Other opinions?

Michael
--

Michael Suedkamp                                      m...@suedkm.franken.de

Re:Intercepting external windows messages


Quote
m...@iol.ie (Simon O'Doherty) wrote:
>Does anyone have an example program which shows how to intercept an Windows
>message which has originated from another application. I'm trying to link my
>program onto anothers menu so that when the user selects my option on the
>menu, my program will be able to trap it.

If the message has originated from a non-Delphi app, then the best bet
is to use a MessageHook (vis Windows API). There is a similar problem
in the news group at the moment. I have a sample program, but I'm
currently converting it from C to Delphi. I have posted the sample C
source code which uses plain API calls to hook mouse events. You could
do the same, but hook into a different message class. (See the API
documentation on SetWindowsHookEx). The only problem with this, is
that the hook procedure must be in a DLL. Good hunting... :)

--------------------------------------------------------------
"Just my opinion"

Paul Grimstrup
PaulG @ Manawatu.gen.NZ  (New Zealand!)
--------------------------------------------------------------

Re:Intercepting external windows messages


Quote
m...@iol.ie (Simon O'Doherty) wrote:
>Does anyone have an example program which shows how to intercept an Windows
>message which has originated from another application. I'm trying to link my
>program onto anothers menu so that when the user selects my option on the
>menu, my program will be able to trap it.

If the message has originated from a non-Delphi app, then the best bet
is to use a MessageHook (vis Windows API). There is a similar problem
in the news group at the moment. I have a sample program, but I'm
currently converting it from C to Delphi. I have posted the sample C
source code which uses plain API calls to hook mouse events. You could
do the same, but hook into a different message class. (See the API
documentation on SetWindowsHookEx). The only problem with this, is
that the hook procedure must be in a DLL. Good hunting... :)

--------------------------------------------------------------
"Just my opinion"

Paul Grimstrup
PaulG @ Manawatu.gen.NZ  (New Zealand!)
--------------------------------------------------------------

Other Threads