void CALLBACK TimerFunc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime) { DWORD wso; wso = WaitForSingleObject(hSynhroMutex, 0); if (wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED) { KillTimer(0, nTimerid); if ((GlobalData->LastWND!=0)&&(GlobalData->LastWND == GetWindowFromPoint(GlobalData->LastPt))) { SendWordToServer(); } ReleaseMutex(hSynhroMutex); } }
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) { DWORD wso; if ((nCode == HC_ACTION) && ((wParam == WM_MOUSEMOVE) || (wParam == WM_NCMOUSEMOVE)) && (GlobalData != NULL)) { wso = WaitForSingleObject(hSynhroMutex, 0); if (wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED) { HWND WND; TCHAR wClassName[64]; if(TimerID && ( GlobalData->LastPt.x!=((PMOUSEHOOKSTRUCT)lParam)->pt.x || GlobalData->LastPt.y!=((PMOUSEHOOKSTRUCT)lParam)->pt.y ) ) { KillTimer(0, TimerID); TimerID = 0; } WND = GetWindowFromPoint(((PMOUSEHOOKSTRUCT)lParam)->pt); if(WND == NULL) { ReleaseMutex(hSynhroMutex); return CallNextHookEx(GlobalData->g_hHookMouse, nCode, wParam, lParam); } if (GetClassName(WND, wClassName, sizeof(wClassName) / sizeof(TCHAR))) { const char* DisableClasses[] = { "gdkWindowChild", "gdkWindowTemp", "Progman", "WorkerW", }; int i; for (i=0; i<4; i++) { if (lstrcmp(wClassName, DisableClasses[i])==0) break; } if (i<4) { ReleaseMutex(hSynhroMutex); return CallNextHookEx(GlobalData->g_hHookMouse, nCode, wParam, lParam); } } if(GlobalData->LastPt.x!=((PMOUSEHOOKSTRUCT)lParam)->pt.x || GlobalData->LastPt.y!=((PMOUSEHOOKSTRUCT)lParam)->pt.y || GlobalData->LastWND != WND) { GlobalData->LastWND = WND; GlobalData->LastPt = ((PMOUSEHOOKSTRUCT)lParam)->pt; TimerID = SetTimer(0, TimerID, MOUSEOVER_INTERVAL, TimerFunc); } ReleaseMutex(hSynhroMutex); } } return CallNextHookEx(GlobalData->g_hHookMouse, nCode, wParam, lParam); }
void CALLBACK TimerFunc(HWND hWnd,UINT nMsg,UINT_PTR nTimerid,DWORD dwTime) { (void) hWnd; (void) nMsg; (void) dwTime; DWORD wso; wso = WaitForSingleObject(hSynhroMutex, 0); if (wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED) { KillTimer(0, nTimerid); TimerID = 0; while( 1 ) { POINT curPt; HWND targetWnd; DWORD winProcessID = 0; if( !GetCursorPos( &curPt ) ) break; if( GlobalData == NULL || GlobalData->LastPt.x != curPt.x || GlobalData->LastPt.y != curPt.y) break; if( ( targetWnd = GetWindowFromPoint( curPt ) ) == NULL ) break; if( GlobalData->LastWND != targetWnd ) break; GetWindowThreadProcessId( targetWnd, &winProcessID ); if( winProcessID != ourProcessID ) { char className[64]; if( !GetClassName( targetWnd, className, sizeof(className) ) ) break; if( lstrcmpi( className, "ConsoleWindowClass" ) != 0 ) break; } SendWordToServer(); break; } ReleaseMutex(hSynhroMutex); } }
void HookProc( POINT *ppt ) { HWND WND; TCHAR wClassName[64]; DWORD winProcessID; WND = GetWindowFromPoint( *ppt ); if(WND == NULL) return; if ( !GetClassName(WND, wClassName, sizeof(wClassName) / sizeof(TCHAR)) ) return; GetWindowThreadProcessId( WND, &winProcessID ); if( winProcessID != ourProcessID && lstrcmpi( wClassName, _T("ConsoleWindowClass") ) != 0 ) return; if(TimerID && ( GlobalData->LastPt.x != ppt->x || GlobalData->LastPt.y != ppt->y ) ) { KillTimer(0, TimerID); TimerID = 0; } const char* DisableClasses[] = { "gdkWindowChild", "gdkWindowTemp", "Progman", "WorkerW", }; int i; for (i=0; i<4; i++) { if (lstrcmp(wClassName, DisableClasses[i])==0) break; } if (i<4) return; if(GlobalData->LastPt.x != ppt->x || GlobalData->LastPt.y != ppt->y || GlobalData->LastWND != WND ) { GlobalData->LastWND = WND; GlobalData->LastPt = *ppt; TimerID = SetTimer(0, TimerID, MOUSEOVER_INTERVAL, TimerFunc); } }
void MouseInput(s32 x,s32 y,u32 key_state) { HWND hwnd; POINT pt; RECT rc; pt.x =x; pt.y =y; GDD_Lock(); hwnd =GetWindowFromPoint(&pt); //记录LButtonDown窗口. // LBUTTON if(key_state&MK_LBUTTON) { if(!_IsKeyDown(VK_LBUTTON)) { _SetKeyDown(VK_LBUTTON); HWND_LButton_Down =hwnd; //记录LButtonDown窗口. GetClientRectToScreen(hwnd,&rc); if(_PtInRect(&rc,&pt)) { LButton_Msg =MSG_LBUTTON_DOWN; _ScreenToClient(hwnd,&pt,1); //客户区使用客户坐标. } else { LButton_Msg =MSG_NCLBUTTON_DOWN; } PostMessage(hwnd,LButton_Msg,0,(pt.y<<16)|(pt.x)); } } else { if(_IsKeyDown(VK_LBUTTON)) { _SetKeyUp(VK_LBUTTON); hwnd =HWND_LButton_Down; if(LButton_Msg==MSG_LBUTTON_DOWN) { _ScreenToClient(hwnd,&pt,1); //客户区使用客户坐标. LButton_Msg =MSG_LBUTTON_UP; } else { LButton_Msg =MSG_NCLBUTTON_UP; } PostMessage(hwnd,LButton_Msg,0,(pt.y<<16)|(pt.x)); } } if((cursor_x!=x) || (cursor_y!=y)) { cursor_x =x; cursor_y =y; pt.x =x; pt.y =y; ScreenToClient(hwnd,&pt,1); PostMessage(hwnd,MSG_MOUSE_MOVE,key_state,(pt.y<<16)|(pt.x)); } GDD_Unlock(); }