Hi everyone
I have an application which hooks to notepad and records the keyboard strokes, this works fine only when i have an notepad open before executing my application. Once the appl is running and then i open notepad my appl doesnt work. My ques is suppose i have first executed my appl and then starts my notepad, how can i hook to this notepad.
Second ques is suppose i have opened say some 5 notepads, and my appl is already running how can i record keystrokes of the active notepad. I mean, first i may work with notepad 5, then i minimize it or close it and starts working with 2 nd notepad so on .... How to capture keystrokes of the current active notepad.
The code is
#include "stdafx.h"
#include "windows.h"
#include "stdio.h"
#include "conio.h"
HINSTANCE hins;
HOOKPROC hkprc;
HHOOK hk;
HANDLE hnd;
FILE *fp;
char c;
int flag=0;
int i;
int _tmain(int argc, _TCHAR* argv[])
{
//Sleep(1000);
HWND wndhnd;
DWORD threadid;
system("notepad.exe");
wndhnd=FindWindow(NULL,_T("Untitled - Notepad"));
threadid=GetWindowThreadProcessId(wndhnd,NULL);
hins=LoadLibrary(TEXT("C:\\Documents and Settings\\manu\\My Documents\\Visual Studio 2008\\Projects\\globalkeyhook\\Debug\\globalkeyhook.dll"));
hkprc=(HOOKPROC)GetProcAddress(hins,"KeyboardProc");
hk=SetWindowsHookEx(WH_KEYBOARD,hkprc,hins,threadid);
if(threadid==0)
{
printf("Unhooked\n");
UnhookWindowsHookEx(hk);
}
else
{
printf("hooked to threadid-->%lu:",threadid);
}
PLease help me ...i am newbie to system programming.....