如何在执行EXE后挂接到记事本 [英] How to hook to notepad after executing EXE

查看:83
本文介绍了如何在执行EXE后挂接到记事本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好

我有一个挂在记事本上并记录键盘笔触的应用程序,仅当在执行应用程序之前打开记事本时,此方法才能正常工作.一旦应用程序运行,然后我打开记事本,我的应用程序不起作用.我的问题是假设我先执行了我的应用程序,然后启动了我的记事本,我该如何挂接到该记事本.

第二个问题是假设我已经打开了说5个记事本,而我的应用程序已经在运行,我该如何记录活动记事本的击键.我的意思是,首先我可以使用记事本5,然后将其最小化或关闭,然后开始使用第二个记事本,以此类推....如何捕获当前活动记事本的击键.

代码是

C ++语法(切换纯文本)

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

C++ Syntax (Toggle Plain Text)

#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;
	BOOL bret;
	MSG msg;
	/*system("notepad.exe");*/
	wndhnd=FindWindow(NULL,_T("Untitled - Notepad"));
	while((bret=GetMessage(&msg,wndhnd,0,0))!=0);
	{
		
		if(bret==-1)
		{
			printf("sleep");
			Sleep(3000);
			wndhnd=FindWindow(NULL,_T("Untitled - Notepad"));
			
		}
		else
		{
			
			TranslateMessage(&msg);
			DispatchMessage(&msg);
		}
	}
				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.....

推荐答案

我相信您可以使用SetWindowsHookEx [
I beleave you can use SetWindowsHookEx[^] specifying WH_CALLWNDPROC as the hook type, then watch for WM_CREATE and check if that new window is Notepad, if it is then hook it.

regarding your second question; There is no reason, as far as I can see, for you to monotor which notepad is active, you''re hooked into all of them, the one getting input is the active one. That said, you can the use the same hook you setup with SetWindowsHookEx and listen for WM_ACTIVATE or WM_NCACTIVATE.


这篇关于如何在执行EXE后挂接到记事本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆