如何发送,键盘消息镜像到edit1控件
gMsgHook = SetWindowsHookEx(WH_KEYBOARD_LL, GetMsgHookProc, ghInstDll, 0);
…………
extern "C" HOOK_DLL_API LRESULT CALLBACK GetMsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0){
CallNextHookEx(gMsgHook, nCode, wParam, lParam);
}
KBDLLHOOKSTRUCT *dl = (KBDLLHOOKSTRUCT*)wParam;
if (nCode >= HC_ACTION){
// message mirror to hEdit1
// doesnt typing work
SendMessage(hEdit1, wParam, wParam, lParam);
}
return CallNextHookEx(gMsgHook, nCode, wParam, lParam);
}
gMsgHook = SetWindowsHookEx(WH_KEYBOARD_LL, GetMsgHookProc, ghInstDll, 0);
.......
extern "C" HOOK_DLL_API LRESULT CALLBACK GetMsgHookProc(int nCode, WPARAM wParam, LPARAM lParam)
{
if (nCode < 0){
CallNextHookEx(gMsgHook, nCode, wParam, lParam);
}
KBDLLHOOKSTRUCT *dl = (KBDLLHOOKSTRUCT*)wParam;
if (nCode >= HC_ACTION){
// message mirror to hEdit1
// doesnt typing work
SendMessage(hEdit1, wParam, wParam, lParam);
}
return CallNextHookEx(gMsgHook, nCode, wParam, lParam);
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的代码片段中有很多错误。
首先,传递给钩子的 KBDLLHOOKSTRUCT 位于 lParam 中,而不是 wParam 中。 wParam 包含窗口消息。
其次,将 lParam 按原样传递给编辑控件。您需要构造适当的 lParam(请参阅 WM_KEYDOWN、WM_KEYUP 等的文档)。
第三,将 wParam 传递给钩子过程(即消息)作为重新生成的键盘消息的 wParam - 它应该是从 KBDLLHOOKSTRUCT 获取的虚拟键代码。
第四,如果nCode<; 0 你最终会调用 CallNextHookEx 两次。
There are numerous errors in your code snippet.
First, the KBDLLHOOKSTRUCT that is passed to the hook is in lParam, not wParam. wParam contains the window message.
Second, you pass the lParam as is to the edit control. You need to construct the appropriate lParam (see the documentation for WM_KEYDOWN, WM_KEYUP, etc.).
Third, you pass wParam to the hook proc (which is the message) as the wParam for the regenerated keyboard message - it should be the virtual key code that you get from the KBDLLHOOKSTRUCT.
Fourth, if nCode < 0 you'll wind up calling CallNextHookEx twice.