mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
Win32 mouseover patches by Abs62.
This commit is contained in:
parent
de7701b417
commit
c71678221b
|
@ -407,22 +407,34 @@ BOOL WINAPI ExtTextOutWCallbackProc(HDC hdc, int nXStart, int nYStart, UINT fuOp
|
||||||
|
|
||||||
static void InstallTextOutHooks()
|
static void InstallTextOutHooks()
|
||||||
{
|
{
|
||||||
|
if (TextOutANextHook==NULL)
|
||||||
HookAPI("gdi32.dll", "TextOutA", (PROC)TextOutACallbackProc, (PROC*)&TextOutANextHook);
|
HookAPI("gdi32.dll", "TextOutA", (PROC)TextOutACallbackProc, (PROC*)&TextOutANextHook);
|
||||||
|
if (TextOutWNextHook==NULL)
|
||||||
HookAPI("gdi32.dll", "TextOutW", (PROC)TextOutWCallbackProc, (PROC*)&TextOutWNextHook);
|
HookAPI("gdi32.dll", "TextOutW", (PROC)TextOutWCallbackProc, (PROC*)&TextOutWNextHook);
|
||||||
|
if (ExtTextOutANextHook==NULL)
|
||||||
HookAPI("gdi32.dll", "ExtTextOutA", (PROC)ExtTextOutACallbackProc, (PROC*)&ExtTextOutANextHook);
|
HookAPI("gdi32.dll", "ExtTextOutA", (PROC)ExtTextOutACallbackProc, (PROC*)&ExtTextOutANextHook);
|
||||||
|
if (ExtTextOutWNextHook==NULL)
|
||||||
HookAPI("gdi32.dll", "ExtTextOutW", (PROC)ExtTextOutWCallbackProc, (PROC*)&ExtTextOutWNextHook);
|
HookAPI("gdi32.dll", "ExtTextOutW", (PROC)ExtTextOutWCallbackProc, (PROC*)&ExtTextOutWNextHook);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void UninstallTextOutHooks()
|
static void UninstallTextOutHooks()
|
||||||
{
|
{
|
||||||
if (TextOutANextHook)
|
if (TextOutANextHook) {
|
||||||
HookAPI("gdi32.dll", "TextOutA", (PROC)TextOutANextHook, NULL);
|
HookAPI("gdi32.dll", "TextOutA", (PROC)TextOutANextHook, NULL);
|
||||||
if (TextOutWNextHook)
|
TextOutANextHook=NULL;
|
||||||
|
}
|
||||||
|
if (TextOutWNextHook) {
|
||||||
HookAPI("gdi32.dll", "TextOutW", (PROC)TextOutWNextHook, NULL);
|
HookAPI("gdi32.dll", "TextOutW", (PROC)TextOutWNextHook, NULL);
|
||||||
if (ExtTextOutANextHook)
|
TextOutWNextHook=NULL;
|
||||||
|
}
|
||||||
|
if (ExtTextOutANextHook) {
|
||||||
HookAPI("gdi32.dll", "ExtTextOutA", (PROC)ExtTextOutANextHook, NULL);
|
HookAPI("gdi32.dll", "ExtTextOutA", (PROC)ExtTextOutANextHook, NULL);
|
||||||
if (ExtTextOutWNextHook)
|
ExtTextOutANextHook=NULL;
|
||||||
|
}
|
||||||
|
if (ExtTextOutWNextHook) {
|
||||||
HookAPI("gdi32.dll", "ExtTextOutW", (PROC)ExtTextOutWNextHook, NULL);
|
HookAPI("gdi32.dll", "ExtTextOutW", (PROC)ExtTextOutWNextHook, NULL);
|
||||||
|
ExtTextOutWNextHook=NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
DLLIMPORT void __gdGetWord (TCurrentMode *P)
|
DLLIMPORT void __gdGetWord (TCurrentMode *P)
|
||||||
|
|
|
@ -7,6 +7,7 @@ const int WM_MY_SHOW_TRANSLATION = WM_USER + 301;
|
||||||
|
|
||||||
HINSTANCE g_hInstance = NULL;
|
HINSTANCE g_hInstance = NULL;
|
||||||
HANDLE hSynhroMutex = 0;
|
HANDLE hSynhroMutex = 0;
|
||||||
|
HANDLE hNewMousePosEvent = 0;
|
||||||
HINSTANCE hGetWordLib = 0;
|
HINSTANCE hGetWordLib = 0;
|
||||||
typedef void (*GetWordProc_t)(TCurrentMode *);
|
typedef void (*GetWordProc_t)(TCurrentMode *);
|
||||||
GetWordProc_t GetWordProc = NULL;
|
GetWordProc_t GetWordProc = NULL;
|
||||||
|
@ -35,32 +36,27 @@ static void SendWordToServer()
|
||||||
|
|
||||||
void CALLBACK TimerFunc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
|
void CALLBACK TimerFunc(HWND hWnd,UINT nMsg,UINT nTimerid,DWORD dwTime)
|
||||||
{
|
{
|
||||||
if (WaitForSingleObject(hSynhroMutex, 0) == WAIT_OBJECT_0) {
|
DWORD wso;
|
||||||
if (GlobalData->TimerID) {
|
if (WaitForSingleObject(hNewMousePosEvent, 0) == WAIT_OBJECT_0) {
|
||||||
if (KillTimer(0, GlobalData->TimerID))
|
|
||||||
GlobalData->TimerID=0;
|
|
||||||
}
|
|
||||||
ReleaseMutex(hSynhroMutex);
|
|
||||||
}
|
|
||||||
if ((GlobalData->LastWND!=0)&&(GlobalData->LastWND == WindowFromPoint(GlobalData->LastPt))) {
|
if ((GlobalData->LastWND!=0)&&(GlobalData->LastWND == WindowFromPoint(GlobalData->LastPt))) {
|
||||||
if (WaitForSingleObject(hSynhroMutex, 0) == WAIT_OBJECT_0) {
|
wso = WaitForSingleObject(hSynhroMutex, 0);
|
||||||
|
if (wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED) {
|
||||||
SendWordToServer();
|
SendWordToServer();
|
||||||
ReleaseMutex(hSynhroMutex);
|
ReleaseMutex(hSynhroMutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||||
{
|
{
|
||||||
|
DWORD wso;
|
||||||
if ((nCode == HC_ACTION) && ((wParam == WM_MOUSEMOVE) || (wParam == WM_NCMOUSEMOVE))) {
|
if ((nCode == HC_ACTION) && ((wParam == WM_MOUSEMOVE) || (wParam == WM_NCMOUSEMOVE))) {
|
||||||
if (WaitForSingleObject(hSynhroMutex, 0) == WAIT_OBJECT_0) {
|
wso = WaitForSingleObject(hSynhroMutex, 0);
|
||||||
|
if (wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED) {
|
||||||
HWND WND;
|
HWND WND;
|
||||||
TCHAR wClassName[64];
|
TCHAR wClassName[64];
|
||||||
|
|
||||||
if (GlobalData->TimerID) {
|
|
||||||
if (KillTimer(0, GlobalData->TimerID))
|
|
||||||
GlobalData->TimerID=0;
|
|
||||||
}
|
|
||||||
WND = WindowFromPoint(((PMOUSEHOOKSTRUCT)lParam)->pt);
|
WND = WindowFromPoint(((PMOUSEHOOKSTRUCT)lParam)->pt);
|
||||||
|
|
||||||
if (GetClassName(WND, wClassName, sizeof(wClassName) / sizeof(TCHAR))) {
|
if (GetClassName(WND, wClassName, sizeof(wClassName) / sizeof(TCHAR))) {
|
||||||
|
@ -78,9 +74,10 @@ LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam)
|
||||||
return CallNextHookEx(GlobalData->g_hHookMouse, nCode, wParam, lParam);
|
return CallNextHookEx(GlobalData->g_hHookMouse, nCode, wParam, lParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
GlobalData->TimerID = SetTimer(0, 0, MOUSEOVER_INTERVAL, TimerFunc);
|
GlobalData->TimerID = SetTimer(0, GlobalData->TimerID, MOUSEOVER_INTERVAL, TimerFunc);
|
||||||
GlobalData->LastWND = WND;
|
GlobalData->LastWND = WND;
|
||||||
GlobalData->LastPt = ((PMOUSEHOOKSTRUCT)lParam)->pt;
|
GlobalData->LastPt = ((PMOUSEHOOKSTRUCT)lParam)->pt;
|
||||||
|
SetEvent(hNewMousePosEvent);
|
||||||
ReleaseMutex(hSynhroMutex);
|
ReleaseMutex(hSynhroMutex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,20 +89,22 @@ DLLIMPORT void ActivateTextOutSpying (int Activate)
|
||||||
// After call SetWindowsHookEx(), when you move mouse to a application's window,
|
// After call SetWindowsHookEx(), when you move mouse to a application's window,
|
||||||
// this dll will load into this application automatically. And it is unloaded
|
// this dll will load into this application automatically. And it is unloaded
|
||||||
// after call UnhookWindowsHookEx().
|
// after call UnhookWindowsHookEx().
|
||||||
|
DWORD wso;
|
||||||
if (Activate) {
|
if (Activate) {
|
||||||
if (GlobalData->g_hHookMouse != NULL) return;
|
if (GlobalData->g_hHookMouse != NULL) return;
|
||||||
GlobalData->g_hHookMouse = SetWindowsHookEx(WH_MOUSE, MouseHookProc, g_hInstance, 0);
|
GlobalData->g_hHookMouse = SetWindowsHookEx(WH_MOUSE, MouseHookProc, g_hInstance, 0);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (GlobalData->g_hHookMouse == NULL) return;
|
if (GlobalData->g_hHookMouse == NULL) return;
|
||||||
if (WaitForSingleObject(hSynhroMutex, 0) == WAIT_OBJECT_0) {
|
UnhookWindowsHookEx(GlobalData->g_hHookMouse);
|
||||||
|
wso = WaitForSingleObject(hSynhroMutex, 2*MOUSEOVER_INTERVAL);
|
||||||
|
if (wso == WAIT_OBJECT_0 || wso == WAIT_ABANDONED) {
|
||||||
if (GlobalData->TimerID) {
|
if (GlobalData->TimerID) {
|
||||||
if (KillTimer(0, GlobalData->TimerID))
|
if (KillTimer(0, GlobalData->TimerID))
|
||||||
GlobalData->TimerID=0;
|
GlobalData->TimerID=0;
|
||||||
}
|
}
|
||||||
ReleaseMutex(hSynhroMutex);
|
ReleaseMutex(hSynhroMutex);
|
||||||
}
|
}
|
||||||
UnhookWindowsHookEx(GlobalData->g_hHookMouse);
|
|
||||||
GlobalData->g_hHookMouse = NULL;
|
GlobalData->g_hHookMouse = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,18 +118,32 @@ BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
|
||||||
{
|
{
|
||||||
case DLL_PROCESS_ATTACH:
|
case DLL_PROCESS_ATTACH:
|
||||||
g_hInstance = hInst;
|
g_hInstance = hInst;
|
||||||
|
if(hSynhroMutex==0) {
|
||||||
hSynhroMutex = CreateMutex(NULL, FALSE, "GoldenDictTextOutSpyMutex");
|
hSynhroMutex = CreateMutex(NULL, FALSE, "GoldenDictTextOutSpyMutex");
|
||||||
|
if(hSynhroMutex==0) return(FALSE);
|
||||||
ThTypes_Init();
|
ThTypes_Init();
|
||||||
|
}
|
||||||
|
if(hNewMousePosEvent==0) {
|
||||||
|
hNewMousePosEvent = CreateEvent(NULL, FALSE, FALSE,"GoldenDictTextOutSpyEvent");
|
||||||
|
if(hNewMousePosEvent==0) return(FALSE);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case DLL_PROCESS_DETACH:
|
case DLL_PROCESS_DETACH:
|
||||||
WaitForSingleObject(hSynhroMutex, INFINITE);
|
if(hSynhroMutex) WaitForSingleObject(hSynhroMutex, INFINITE);
|
||||||
if (GlobalData->TimerID) {
|
if (GlobalData->TimerID) {
|
||||||
if (KillTimer(0, GlobalData->TimerID))
|
if (KillTimer(0, GlobalData->TimerID))
|
||||||
GlobalData->TimerID=0;
|
GlobalData->TimerID=0;
|
||||||
}
|
}
|
||||||
|
if(hSynhroMutex) {
|
||||||
ReleaseMutex(hSynhroMutex);
|
ReleaseMutex(hSynhroMutex);
|
||||||
CloseHandle(hSynhroMutex);
|
CloseHandle(hSynhroMutex);
|
||||||
|
hSynhroMutex=0;
|
||||||
|
}
|
||||||
|
if(hNewMousePosEvent) {
|
||||||
|
CloseHandle(hNewMousePosEvent);
|
||||||
|
hNewMousePosEvent=0;
|
||||||
|
}
|
||||||
{
|
{
|
||||||
MSG msg ;
|
MSG msg ;
|
||||||
while (PeekMessage (&msg, 0, WM_TIMER, WM_TIMER, PM_REMOVE)) {}
|
while (PeekMessage (&msg, 0, WM_TIMER, WM_TIMER, PM_REMOVE)) {}
|
||||||
|
|
Loading…
Reference in a new issue