为什么消息总是接受2次.
BOOL APIENTRY DllMain(HANDLE hModule,DWORD ul_reason_for_call,LPVOID lpReserved)
{
if(ul_reason_for_call==DLL_PROCESS_ATTACH)
{
pid=FindWindow("接受消息",NULL);
if(pid==NULL)
return TRUE;
hooker=SetWindowsHookEx(WH_KEYBOARD,HookProc,(HINSTANCE)hModule,0);
}
return TRUE;
}
extern "C" __declspec(dllexport) LRESULT CALLBACK HookProc(int nCode,WPARAM wParam,LPARAM lParam)
{
PostMessage(pid,WM_KEYDOWN,wParam,lParam);
return CallNextHookEx(hooker,nCode,wParam,lParam);
}
我切换到其他窗口.接受消息的窗口还是接受2次消息.谁知道哦.
如果切换到当前窗口,就接受3次消息..郁闷死............
[解决办法]
WH_KEYBOARD里有WM_KEYDOWN和WM_KEYUP消息,你得判断过滤下
if(lParam&0x80000000)
PostMessage(pid,WM_KEYDOWN,wParam,lParam);