Original Post
I am trying to read Windows Messages from another window. I have gotten this code to work with notepad:
and my hook proc:
The code works fine when reading from notepad. I get the "hooked" text in my program and it says the correct name of the window. When I use the keyboard in notepad i get the "HookProc" text in my program.
The problem is that when I try to use this same program to target something other than notepad. I get the dialog that says I hooked it properly so I believe I am hooking the right window, but none of the keyboard messages are making it back to my program.
I am trying to follow the logic of spy++:
http://blogs.msdn.co...-internals.aspx
I have used a program to make sure that the program I am trying to read messages from is using user32 since I am placing my hook there:
http://www.dependencywalker.com/
I believe it has to be possible because spy++ is somehow able to get the mouse/key info i would like to have. I have tinkered around with this for a while and I am starting to get stumped. Any help would be greatly appreciated.
Ty for any help in advance =).
edit: sorry about the weird spacing in code brackets i just cant get it to look right lol.
HINSTANCE HookhInstance = NULL;
DWORD ThreadId = 0;
DWORD ProcessId = 0;
HookhInstance = GetModuleHandle( __TEXT("user32") );
ThreadId = GetWindowThreadProcessId(InputWindow, &ProcessId);
hkb = SetWindowsHookEx(WH_KEYBOARD,(HOOKPROC)MyHookProc,HookhInstance,ThreadId);
if(hkb != NULL)
{
char title[80];
GetWindowTextA(InputWindow,title,sizeof(title));
string titlestring(title);
cout << "hooked " << titlestring << endl;
}
and my hook proc:
LRESULT CALLBACK MyHookProc(int intCode, WPARAM wParam, LPARAM lParam)
{
cout << "HookProc" <<endl;
}
The code works fine when reading from notepad. I get the "hooked" text in my program and it says the correct name of the window. When I use the keyboard in notepad i get the "HookProc" text in my program.
The problem is that when I try to use this same program to target something other than notepad. I get the dialog that says I hooked it properly so I believe I am hooking the right window, but none of the keyboard messages are making it back to my program.
I am trying to follow the logic of spy++:
http://blogs.msdn.co...-internals.aspx
I have used a program to make sure that the program I am trying to read messages from is using user32 since I am placing my hook there:
http://www.dependencywalker.com/
I believe it has to be possible because spy++ is somehow able to get the mouse/key info i would like to have. I have tinkered around with this for a while and I am starting to get stumped. Any help would be greatly appreciated.
Ty for any help in advance =).
edit: sorry about the weird spacing in code brackets i just cant get it to look right lol.