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'