mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
Add interface for other programs to send to GD a word under cursor
This commit is contained in:
parent
e87dce57ad
commit
a523b8e3d7
46
mouseover_win32/GDDataTranfer.h
Normal file
46
mouseover_win32/GDDataTranfer.h
Normal file
|
@ -0,0 +1,46 @@
|
|||
#ifndef __GDDATATRANSFER_H_
|
||||
#define __GDDATATRANSFER_H_
|
||||
|
||||
/*
|
||||
Header for other program to interact with GoldenDict
|
||||
|
||||
When GD needs to retrieve word under mouse cursor it can ask for this a target program
|
||||
by sending a message.
|
||||
|
||||
GD_MESSAGE_NAME - name of the this message
|
||||
Message number must be retrieved through RegisterWindowMessage function
|
||||
|
||||
Message parameters:
|
||||
WPARAM - 0, not used
|
||||
LPARAM - pointer to GDDataStruct structure
|
||||
|
||||
GDDataStruct fields:
|
||||
dwSize - Structure size
|
||||
hWnd - Window with requested word
|
||||
Pt - Request coordinates (in screen coordinates, device units)
|
||||
dwMaxLength - Maximum word length to transfer (buffer size in unicode symbols)
|
||||
cwData - Buffer for requested word in UNICODE
|
||||
|
||||
If program process this message it must fill cwData and return TRUE
|
||||
Otherwise GD will work by old technique
|
||||
*/
|
||||
|
||||
#ifdef UNICODE
|
||||
#define GD_MESSAGE_NAME L"GOLDENDICT_GET_WORD_IN_COORDINATES"
|
||||
#else
|
||||
#define GD_MESSAGE_NAME "GOLDENDICT_GET_WORD_IN_COORDINATES"
|
||||
#endif
|
||||
|
||||
#pragma pack(push,1)
|
||||
|
||||
typedef struct {
|
||||
DWORD dwSize;
|
||||
HWND hWnd;
|
||||
POINT Pt;
|
||||
DWORD dwMaxLength;
|
||||
WCHAR *cwData;
|
||||
} GDDataStruct, *LPGDDataStruct;
|
||||
|
||||
#pragma pack(pop)
|
||||
|
||||
#endif
|
|
@ -1,8 +1,9 @@
|
|||
#include "TextOutSpy.h"
|
||||
#include "ThTypes.h"
|
||||
|
||||
#include "GDDataTranfer.h"
|
||||
|
||||
const int MOUSEOVER_INTERVAL = 300;
|
||||
const int REQUEST_MESSAGE_INTERVAL = 500;
|
||||
const int WM_MY_SHOW_TRANSLATION = WM_USER + 301;
|
||||
|
||||
HINSTANCE g_hInstance = NULL;
|
||||
|
@ -11,19 +12,45 @@ HINSTANCE hGetWordLib = 0;
|
|||
UINT_PTR TimerID = 0;
|
||||
typedef void (*GetWordProc_t)(TCurrentMode *);
|
||||
GetWordProc_t GetWordProc = NULL;
|
||||
GDDataStruct gds;
|
||||
UINT uGdAskMessage;
|
||||
WCHAR Buffer[256];
|
||||
|
||||
static HWND GetWindowFromPoint(POINT pt) {
|
||||
static HWND GetWindowFromPoint(POINT pt)
|
||||
{
|
||||
HWND WndParent,WndChild;
|
||||
WndParent = WindowFromPoint(pt);
|
||||
if(WndParent == NULL) return WndParent;
|
||||
ScreenToClient(WndParent, &pt);
|
||||
WndChild=RealChildWindowFromPoint(WndParent, pt);
|
||||
WndChild = RealChildWindowFromPoint(WndParent, pt);
|
||||
if(WndChild == NULL) return WndParent;
|
||||
return WndChild;
|
||||
};
|
||||
|
||||
static void SendWordToServer()
|
||||
{
|
||||
DWORD SendMsgAnswer;
|
||||
if(uGdAskMessage) {
|
||||
LRESULT lr;
|
||||
int n;
|
||||
gds.dwSize = sizeof(gds);
|
||||
gds.cwData = Buffer;
|
||||
gds.dwMaxLength = sizeof(Buffer) / sizeof(Buffer[0]);
|
||||
Buffer[0] = 0;
|
||||
gds.hWnd = GlobalData->LastWND;
|
||||
gds.Pt = GlobalData->LastPt;
|
||||
lr = SendMessageTimeout(gds.hWnd, uGdAskMessage, 0, (LPARAM)&gds, SMTO_ABORTIFHUNG, REQUEST_MESSAGE_INTERVAL, &SendMsgAnswer);
|
||||
if(lr != 0 && SendMsgAnswer != 0) {
|
||||
n = WideCharToMultiByte(CP_UTF8, 0, gds.cwData, lstrlenW(gds.cwData), GlobalData->CurMod.MatchedWord, sizeof(GlobalData->CurMod.MatchedWord) - 1, 0, 0);
|
||||
GlobalData->CurMod.MatchedWord[n] = 0;
|
||||
GlobalData->CurMod.WordLen = n;
|
||||
GlobalData->CurMod.BeginPos = 0;
|
||||
if(n > 0) {
|
||||
SendMessageTimeout(GlobalData->ServerWND, WM_MY_SHOW_TRANSLATION, 0, 0, SMTO_ABORTIFHUNG, MOUSEOVER_INTERVAL, &SendMsgAnswer);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (hGetWordLib == 0) {
|
||||
hGetWordLib = LoadLibrary(GlobalData->LibName);
|
||||
if (hGetWordLib) {
|
||||
|
@ -38,7 +65,6 @@ static void SendWordToServer()
|
|||
GlobalData->CurMod.Pt = GlobalData->LastPt;
|
||||
GetWordProc(&(GlobalData->CurMod));
|
||||
if (GlobalData->CurMod.WordLen > 0) {
|
||||
DWORD SendMsgAnswer;
|
||||
SendMessageTimeout(GlobalData->ServerWND, WM_MY_SHOW_TRANSLATION, 0, 0, SMTO_ABORTIFHUNG, MOUSEOVER_INTERVAL, &SendMsgAnswer);
|
||||
}
|
||||
}
|
||||
|
@ -142,6 +168,7 @@ BOOL APIENTRY DllMain (HINSTANCE hInst /* Library instance handle. */ ,
|
|||
if(hSynhroMutex==0) return(FALSE);
|
||||
}
|
||||
ThTypes_Init();
|
||||
uGdAskMessage = RegisterWindowMessage(GD_MESSAGE_NAME);
|
||||
break;
|
||||
|
||||
case DLL_PROCESS_DETACH:
|
||||
|
|
Loading…
Reference in a new issue