Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows System Hooks

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
I have been trying for ages to create a keyboard hook, but my program doesn't work, and I have absolutely no idea why. I have tried for hours to get this to work, I've e-mailed one of the guys at microsoft, and also looked at several example downloads and I am still stuck. I am new to using DLLs and hooks, and I would REALLY apprieciate some input on this! Thanks

The program I've been trying to do can be found at

It is supposed to put a message on the screen every two seconds. If you press escape, it should display "Timer Dead" and then stop the messages, but this only works when the program window is selected.
 
what is your OS? John Fill
1c.bmp


ivfmd@mail.md
 
How about this one?
#include<windows.h>
HHOOK x=0;
LRESULT CALLBACK KeyboardProc(int code,WPARAM wParam,LPARAM lParam)
{
//put here code to hook
return 1;
}

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR,int)
{
x=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,hInstance,0);
MSG msg;
while(GetMessage(&msg,0,0,0))DispatchMessage(&msg);
return 0;
}
John Fill
1c.bmp


ivfmd@mail.md
 
I got the system hook procedure to work, but how do you get it to send a custom message to the WndProc? SendMessage and PostMessage only work when the program window is selected.
 
There exists some SendThreadMessage. Theese messages are sent to threads and dispathed in theirs main message loops. Also you can CallNextHookEx (is highly recommended). By the way, after executing the program you should UnhookWindowsHookEx (also highly recommended). John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top