HWND g_hLogin = NULL;
DWORD dwThreadID ;
g_hLogin=FindWindowEx(NULL,g_hLogin,"Notepad",NULL); //修改
if(g_hLogin!=NULL)
{
dwThreadID = GetWindowThreadProcessId(g_hLogin, NULL);
glhHook=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,NULL,dwThreadID);
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
.....
}
发现不能钩住记事本的键盘
改为g_hLogin=FindWindowEx(NULL,g_hLogin,"#32770","KeyHook"); //修改
则可以钩住本身程序的键盘,不知道是什么原因.
我检查过能够找到记事本的线程id
DWORD dwThreadID ;
g_hLogin=FindWindowEx(NULL,g_hLogin,"Notepad",NULL); //修改
if(g_hLogin!=NULL)
{
dwThreadID = GetWindowThreadProcessId(g_hLogin, NULL);
glhHook=SetWindowsHookEx(WH_KEYBOARD,KeyboardProc,NULL,dwThreadID);
}
LRESULT CALLBACK KeyboardProc(int nCode, WPARAM wParam, LPARAM lParam)
{
.....
}
发现不能钩住记事本的键盘
改为g_hLogin=FindWindowEx(NULL,g_hLogin,"#32770","KeyHook"); //修改
则可以钩住本身程序的键盘,不知道是什么原因.
我检查过能够找到记事本的线程id
解决方案 »
- 使用CRecordset获取数据报内存错误
- VC调用DELPHI编写的DLL,调用出错,
- Socket怎么发送Keep-Ailve的请求
- 这里哪位兄弟有写过VPN拨号器之类的程序的?
- CRichEditCtrl如何Paste图片
- 将一个文件名保存在一个字符串里,怎么将该文件名的主文件名和扩展名分离?(100分)
- 谁知道webzip里面的像K线图的进度指示,是如何实现的?
- CSliderCtrl控制:滑块停靠在左边
- 用VC可是实现关闭XP防火墙吗?
- MFC的程序,F5调试运行老师先蹦出来一个“新建”对话框,点了确定才运行,怎么解决
- 我的程序在InitInstance中启动了其它程序,如何使我的程序在启动完成后在最上面,并有焦点?
- Release可以用,Debug不可以用,为什么
[in] Specifies the identifier of the thread with which the hook procedure is to be associated. If this parameter is zero, the hook procedure is associated with all existing threads running in the same desktop as the calling thread. dwThreadId为0时是全局钩子The global hooks are a shared resource, and installing one affects all applications in the same desktop as the calling thread. All global hook functions must be in libraries. 全局钩子必须在DLL中实现
// 第3个参数指定的是CALLBACK函数所在的模块。如果为NULL,则表示在创建该线程的进程内。
//你应该改成DLL的模块句柄hMod
Handle to the DLL containing the hook procedure pointed to by the lpfn parameter. The hMod parameter must be set to NULL if the dwThreadId parameter specifies a thread created by the current process and if the hook procedure is within the code associated with the current process.//www.vckbase.com的源代码可是这样写的
g_hKey = SetWindowsHookEx(WH_KEYBOARD, KeyboardProc, g_hInstDLL, dwThreadID);
hMod为NULL表示dwThreadId参数指定的线程是由当前进程创建的并且Hook函数在当前进程关联代码内。
",NULL);