Tech Support > Microsoft Windows > Development Resources > How to create a windows hook?
How to create a windows hook?
Posted by ajcrm125 on September 8th, 2006


I want to create a hook (I think) so that I can create an ap that
tracks the movement (and resizing) of another window. I've been able
to use EnumWIndows to find the hWnd and hInstance of the window in
question.... but how can I catupr move and resize events to that window
so I can pass that info to my other app?
Thanks,
-Adam

Posted by Bertel Brander on September 8th, 2006


ajcrm125 wrote:
Try:
http://windowssdk.msdn.microsoft.com.../ms644990.aspx

--
Just another homepage:
http://damb.dk
But it's mine - Bertel

Posted by ajcrm125 on September 8th, 2006


I tried that but the parameter that list me was the hMod parameter. I
have to point this to a DLL?
I'm a complete DLL noobie. :-(
Can someone help me with the usage of this funtion? I'm not sure how
to point to a DLL or what DLL I should be pointing to.

Thanks,
-Adam
Bertel Brander wrote:

Posted by Bertel Brander on September 8th, 2006


ajcrm125 wrote:
I does not have to be a DLL, any program will do.

I have a example of a keyboard hook here:
http://damb.dk/snip/rmkey.html

I might find some time later tonight to create
sample of what you are trying to do.

--
Just another homepage:
http://damb.dk
But it's mine - Bertel

Posted by Grzegorz Wróbel on September 8th, 2006


Bertel Brander wrote:
It does have to be a DLL if you're going to intercept messages passed to another aplication. Since your hook procedure must reside within the dll, you can also place in that dll your call to SetWindowsHookEx(). This way you'll have the HINSTANCE parameter (obtained in DllMain on DLL_PROCESS_ATTACH so you can pass it to SetWindowsHookEx() as third parameter.

Search for some dll sample to understand this.

--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D

Posted by Bertel Brander on September 8th, 2006


Grzegorz Wróbel wrote:
For some hooks you need a DLL.

I was playing with this and created this:
http://damb.dk/zip/hook.zip

It should be used with care, it might have
unpredictable behaviour. You should
close mytest.exe before the other.

It seems to work when compiled with Borland,
but when compiled with mingw the DllMain
is not called? And it does not work.

With Borland the "mine" dialog box follows
the "other" dialog box when moved.

I did not try it with dmc nor VisualC++

I hope someone can shed some light on this.

--
Just another homepage:
http://damb.dk
But it's mine - Bertel

Posted by Grzegorz Wróbel on September 9th, 2006


Bertel Brander wrote:
You don't need DLL only if you want to hook messages within your own process. If you want too set hook systemwide or for other processes you do need a DLL.

Or you should rather add a check within your hook procedure if "MyWindow" is not NULL.

Try using this declaration for DllMain (HINSTANCE instead of HANDLE):

BOOL WINAPI DllMain(HINSTANCE hInstance, ULONG ulReason, LPVOID pvReserved);

--
Grzegorz Wróbel
http://www.4neurons.com/
677265676F727940346E6575726F6E732E636F6D

Posted by Bertel Brander on September 9th, 2006


Grzegorz Wróbel wrote:
HINSTANCE is the correct parameter, but it does not seem
to make a difference.

--
Just another homepage:
http://damb.dk
But it's mine - Bertel

Posted by ajcrm125 on September 11th, 2006


Got it to compile with MC VCPP 6.0 and it seems to be working. :-)
Thanks!!!

This should give me a good head start.
-Adam
Bertel Brander wrote:

Posted by Ahmed Samieh on September 12th, 2006


this will help you
http://www.codeproject.com/dll/hooks.asp
http://www.codeproject.com/dll/subhook.asp

ajcrm125 wrote:

Posted by ajcrm125 on September 13th, 2006


Great links (especially the first one!)

Thanks!
-Adam
Ahmed Samieh wrote:


Similar Posts