HWND hWndDest = FindWindow(NULL, _T("Test"));
DWORD dwThreadDest = GetWindowThreadProcessId(hWndDest, NULL);
hk_GetMsg = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hInstDLL, dwThreadDest);LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam)
{
if(HC_ACTION == code)
{
pMsg = (MSG *)lParam;
if(WM_CHAR == pMsg->message && pMsg->wParam == '1')
{
pMsg->wParam = '2';
}
} return CallNextHookEx(hk_GetMsg, code, wParam, lParam);
}可为什么不能修改消息呢?我试过了,按下'1',结果显示还是'1',没有变成'2'MSDN是说可以的呀:
The GetMsgProc hook procedure can examine or modify the message. After the hook procedure returns control to the system, the GetMessage or PeekMessage function returns the message, along with any modifications, to the application that originally called it. 为了方便调试,就先给自已(对话框,不知道是否跟这个有关?)挂个钩子试试看
跟踪按下'1',会进入GetMsgProc两次,第一次改为'2',但第二次进来还是'1',再次改为'2',然后edit显示仍然为'1'
DWORD dwThreadDest = GetWindowThreadProcessId(hWndDest, NULL);
hk_GetMsg = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc, hInstDLL, dwThreadDest);LRESULT CALLBACK GetMsgProc(int code, WPARAM wParam, LPARAM lParam)
{
if(HC_ACTION == code)
{
pMsg = (MSG *)lParam;
if(WM_CHAR == pMsg->message && pMsg->wParam == '1')
{
pMsg->wParam = '2';
}
} return CallNextHookEx(hk_GetMsg, code, wParam, lParam);
}可为什么不能修改消息呢?我试过了,按下'1',结果显示还是'1',没有变成'2'MSDN是说可以的呀:
The GetMsgProc hook procedure can examine or modify the message. After the hook procedure returns control to the system, the GetMessage or PeekMessage function returns the message, along with any modifications, to the application that originally called it. 为了方便调试,就先给自已(对话框,不知道是否跟这个有关?)挂个钩子试试看
跟踪按下'1',会进入GetMsgProc两次,第一次改为'2',但第二次进来还是'1',再次改为'2',然后edit显示仍然为'1'
解决方案 »
- 低级问题,勿喷!!
- 如何用工作者线程接收消息
- 用OpenProcess的时候,返回了句柄但是GetLastError()有错误?
- 如何获得拨号连接时的事件通知(关于RasDial函数的使用方法)(在线等)
- 关于USB的问题,有比较深入了解usb的兄弟姐妹进来帮忙看看!
- 我在弹出对话框的OnCtlColor中设了背景颜色,如何让上面STATIC控件的背景透明啊
- waitcommevent参数的true和false干什么用的
- 对话框应用的问题
- 低手有如下程序编译
- 调查~~~~~~~~~~~~~~高中毕业就写vc的人多吗~?
- 调用API获取进程名——怎么显示中文进程名
- 图片存储后显示为黑色是怎么回事?
AfxGetApp()->PreTranslateMessage((LPMSG)lParam) );
或者直接再SendMessage