mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-24 04:24:09 +00:00
Win-specific: ScanPopup: Fix console windows scanning under Windows 8.1
This commit is contained in:
parent
3495ba1816
commit
16691e2029
|
@ -80,14 +80,19 @@ typedef struct TConsoleParams {
|
|||
int BeginPos;
|
||||
} TConsoleParams;
|
||||
|
||||
static int GetWordFromConsolePack(TConsoleParams *params)
|
||||
static int GetWordFromConsolePack(TConsoleParams *params, BOOL *pInvalidConsole)
|
||||
{
|
||||
int WordLen=0;
|
||||
|
||||
*pInvalidConsole = TRUE;
|
||||
|
||||
HANDLE hStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
|
||||
if (hStdOut != INVALID_HANDLE_VALUE) {
|
||||
if (hStdOut != INVALID_HANDLE_VALUE && hStdOut != 0) {
|
||||
CONSOLE_SCREEN_BUFFER_INFO csbi;
|
||||
if (GetConsoleScreenBufferInfo(hStdOut, &csbi)) {
|
||||
|
||||
*pInvalidConsole = FALSE;
|
||||
|
||||
COORD CurPos;
|
||||
CurPos.X = csbi.srWindow.Left + (SHORT)(params->Pt.x * (csbi.srWindow.Right - csbi.srWindow.Left + 1) / params->ClientRect.right);
|
||||
CurPos.Y = csbi.srWindow.Top + (SHORT)(params->Pt.y * (csbi.srWindow.Bottom - csbi.srWindow.Top + 1) / params->ClientRect.bottom);
|
||||
|
@ -129,6 +134,7 @@ static char* GetWordFromConsole(HWND WND, POINT Pt, DWORD *BeginPos)
|
|||
DWORD pid;
|
||||
DWORD WordSize;
|
||||
char *Result;
|
||||
BOOL invalidConsole;
|
||||
|
||||
*BeginPos=0;
|
||||
if((TP = malloc(sizeof(TConsoleParams))) == NULL)
|
||||
|
@ -145,7 +151,7 @@ static char* GetWordFromConsole(HWND WND, POINT Pt, DWORD *BeginPos)
|
|||
if (pid != GetCurrentProcessId()) {
|
||||
if(Is_XP_And_Later()) {
|
||||
if(AttachConsole(pid)) {
|
||||
WordSize = GetWordFromConsolePack(TP);
|
||||
WordSize = GetWordFromConsolePack(TP, &invalidConsole);
|
||||
FreeConsole();
|
||||
} else {
|
||||
WordSize = 0;
|
||||
|
@ -154,7 +160,25 @@ static char* GetWordFromConsole(HWND WND, POINT Pt, DWORD *BeginPos)
|
|||
WordSize = 0;
|
||||
}
|
||||
} else {
|
||||
WordSize = GetWordFromConsolePack(TP);
|
||||
WordSize = GetWordFromConsolePack(TP, &invalidConsole);
|
||||
if( invalidConsole ) {
|
||||
/*
|
||||
Under Win 8.1 GetWindowThreadProcessId return current "conhost" process ID
|
||||
instead of target window process ID.
|
||||
We try to attach console to parent process.
|
||||
*/
|
||||
|
||||
if(Is_XP_And_Later()) {
|
||||
if(AttachConsole( (DWORD)-1 )) {
|
||||
WordSize = GetWordFromConsolePack(TP, &invalidConsole);
|
||||
FreeConsole();
|
||||
} else {
|
||||
WordSize = 0;
|
||||
}
|
||||
} else {
|
||||
WordSize = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (WordSize > 0 && WordSize <= 255) {
|
||||
|
|
Loading…
Reference in a new issue