Link to home
Start Free TrialLog in
Avatar of BoJack
BoJackFlag for Türkiye

asked on

Need a message hook!

I need a message hook that hooks WM_USER+1 message sent from any other top level windows.
I tried examples in prior threads but none of them worked (exactly I couldn't make them work).
Could anybody sends me an examle code for this?

Regards.
Avatar of nestorua
nestorua

HI,
Have you tried to use the examples that propose DELPHI?
I mean "Help Topics: Win32 Programmer's Reference/Hooks".
Sincerely,
Nestorua.
Normally next code should work just fine:

const
 // the message you send using SendMessage( aHandle, WM_IMREADY, 0, 0 );
 WM_IMREADY= WM_USER + 4000;

{
 Callback procedure that checks whether the other program sends a
 message WM_IMREADY. If so, it calls the procedure HandleInput.
}
procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
 if Msg.message = WM_FFTREADY
  then
   begin
    HandleInput( Msg.wParam = 1 );
    Handled :=true;
   end;
end;

I would recommend to take a larger value for the 1 in your code. Take something like WM_USER + 3000 and larger because Windows uses the first ... values (you can find the correct number on the net i assume...)

Keep on delphiing!
Evarest
Avatar of BoJack

ASKER

I looked Programmers reference but it is C code and  i could not understand it
Avatar of BoJack

ASKER

Evarest code works fine but handles messages only sent my application. I need a hook for messages sent any other window. a kind of message sniffer I need. (sorry i forgot to write that) I will keep your advise about larger numbers thank you.
This is possible if you check all messages you want. Can you tell me which messages you're interested in? I ask this because if you want to develop a so-called sniffer, you will soon find out that there are TONS of messages sent every second and less!

You will just have to filter out the junk...

And sorry there was a bug in the code, i see now:

procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
begin
if Msg.message = WM_IMREADY  // <- this line was wrong
 then
  begin
   HandleInput( Msg.wParam = 1 );
   Handled :=true;
  end;
end;

is correct.

Evarest
ASKER CERTIFIED SOLUTION
Avatar of Member_2_248744
Member_2_248744
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of BoJack

ASKER

Thank you very much Slick812. VEry nice code and does what I exactly wanted.
Hello sir Slick812

 I am new to developing System wide hook dll and i have to create this dll in vc++

1. i need help how to implement system wide hook (begginers level)
2.how to implement my idea using that dll

 My requirement is this
 i need to develop a software where i have to change
the ascii character into extended ascii character and send
to the active application.

 say if a user type A from the keyboard it should be
converted to say ? irrespective of whatever the
application is running may be it is visual studio or word
or notepad or photshop u name it.
I have to implement  Wh_getmessage hook and  WH_CALLWNDPROC  and able to
intercept keyboard messages.But  i need the codings of
intercepting that message and load that message with
extended ascii character(system wide and not for any
single application)

thanks in advance

 
hello vimalpercy

you are not following the "Standard Procedure" of this Experts Exchange web site.. . .
I will not answer any questions added to another EE question as you have done. . .

Here at Experts Exchange, , you should ask your question in the "Expert Area" for the type of question it has, This is the Delphi Area of EE
if you want  code answers for   to create this dll in vc++
as you have said, then post your question in the C++  area. . .
if it for Delphi then post your code in the Delphi area. . .
I do not do code for  C++

I will respond to any questions you have about using Experts Exchange here in this question, but I will not give any code help to you here
BoJack

You are welcome.