Re: SetWindowsHookEx stop receivings notifications after focus lost
Hello everyone,
I know this tread is 2 years old and I deeply hope you guys are still around!!!
Its been almost 6 months of research since I started looking for a solution to my problem and after this time I finally found something that is really close to my problem.
Instead of a WM_SHELL hook, Im trying to set up a keyboard and mouse hook. Here we go...
The following code works untill it loses the focus, just like macabre13 has mentioned, so I made what Igor Vartanov said:
Code:
#pragma data_seg("HENRIHOOK")
HWND server = NULL;
#pragma data_seg()
But still, the same old problem. Here is the .cpp file [1]: http://pastebin.com/xnvKeAdZ
The only way I got it to work, was putting a FindWindow in the DLL_PROCESS_ATTACH, however, it will not work properly if the user opens more than 1 instance of my program. Example: Only 1 window will receive both messages, from the program 1 and program 2, because FindWindow gets the handle of the first window found from the given params.
Thats when I had the idea to make a function that retrieves the HWND of the target dll caller window but then it leads me to the "focus lost" problem. Here is the .cpp file [2]: http://pastebin.com/5VmeXUMC
NOTES: When I say it does not work, thats because the onHook is not being called somewhy. I realized this debugging, using MessageBox's, GetLastError's and such.
I am using Borland C++ Builder with Windows 7 professional.
Ignore any sintaxe error.
I have used ChangeWindowMessageFilterEx to allow my application to receive the messages from my dll.
Thanks for answering.
Henri
Re: SetWindowsHookEx stop receivings notifications after focus lost
Compare the two:
1. Your real code on pastebin
Code:
#pragma data_seg( "HENRIHOOK" )
HWND server; // Window to receive the dll messages
#pragma data_seg()
2. "...what Igor Vartanov said:"
Code:
#pragma data_seg("HENRIHOOK")
HWND server = NULL;
#pragma data_seg()
See any difference?