- Fixes TC 8 and GetWindowText issues. See CORE-7447 and CORE-7695.

svn path=/trunk/; revision=61292
This commit is contained in:
James Tabor 2013-12-19 03:35:27 +00:00
parent 1f430a2e98
commit ea4d6f444e
2 changed files with 76 additions and 121 deletions

View file

@ -565,6 +565,9 @@ MsgiKMToUMReply(PMSG KMMsg, PMSG UMMsg, LRESULT *Result)
return TRUE; return TRUE;
} }
//
// Ansi to Unicode -> callout
//
static BOOL FASTCALL static BOOL FASTCALL
MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg) MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
{ {
@ -579,7 +582,8 @@ MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
{ {
LPWSTR Buffer; LPWSTR Buffer;
if (!AnsiMsg->lParam) break; if (!AnsiMsg->lParam) break;
Buffer = RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg->wParam * sizeof(WCHAR)); Buffer = RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, AnsiMsg->wParam * sizeof(WCHAR));
//ERR("WM_GETTEXT A2U Size %d\n",AnsiMsg->wParam);
if (!Buffer) return FALSE; if (!Buffer) return FALSE;
UnicodeMsg->lParam = (LPARAM)Buffer; UnicodeMsg->lParam = (LPARAM)Buffer;
break; break;
@ -587,32 +591,32 @@ MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
case LB_GETTEXT: case LB_GETTEXT:
{ {
DWORD Size; DWORD Size = 1024 * sizeof(WCHAR);
if (!AnsiMsg->lParam || !listbox_has_strings( AnsiMsg->hwnd )) break; if (!AnsiMsg->lParam || !listbox_has_strings( AnsiMsg->hwnd )) break;
Size = SendMessageW( AnsiMsg->hwnd, LB_GETTEXTLEN, AnsiMsg->wParam, 0 ); /*Size = SendMessageW( AnsiMsg->hwnd, LB_GETTEXTLEN, AnsiMsg->wParam, 0 );
if (Size == LB_ERR) if (Size == LB_ERR)
{ {
ERR("LB_GETTEXT LB_ERR\n"); ERR("LB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR); Size = sizeof(ULONG_PTR);
} }
Size = (Size + 1) * sizeof(WCHAR); Size = (Size + 1) * sizeof(WCHAR);*/
UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size); UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!UnicodeMsg->lParam) return FALSE; if (!UnicodeMsg->lParam) return FALSE;
break; break;
} }
case CB_GETLBTEXT: case CB_GETLBTEXT:
{ {
DWORD Size; DWORD Size = 1024 * sizeof(WCHAR);
if (!AnsiMsg->lParam || !combobox_has_strings( AnsiMsg->hwnd )) break; if (!AnsiMsg->lParam || !combobox_has_strings( AnsiMsg->hwnd )) break;
Size = SendMessageW( AnsiMsg->hwnd, CB_GETLBTEXTLEN, AnsiMsg->wParam, 0 ); /*Size = SendMessageW( AnsiMsg->hwnd, CB_GETLBTEXTLEN, AnsiMsg->wParam, 0 );
if (Size == LB_ERR) if (Size == LB_ERR)
{ {
ERR("CB_GETTEXT LB_ERR\n"); ERR("CB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR); Size = sizeof(ULONG_PTR);
} }
Size = (Size + 1) * sizeof(WCHAR); Size = (Size + 1) * sizeof(WCHAR);*/
UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size); UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!UnicodeMsg->lParam) return FALSE; if (!UnicodeMsg->lParam) return FALSE;
break; break;
} }
@ -747,6 +751,10 @@ MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
case WM_IME_CHAR: case WM_IME_CHAR:
UnicodeMsg->wParam = map_wparam_AtoW( AnsiMsg->message, AnsiMsg->wParam ); UnicodeMsg->wParam = map_wparam_AtoW( AnsiMsg->message, AnsiMsg->wParam );
break; break;
case EM_GETLINE:
ERR("FIXME EM_GETLINE A2U\n");
break;
} }
return TRUE; return TRUE;
@ -861,7 +869,7 @@ MsgiAnsiToUnicodeCleanup(LPMSG UnicodeMsg, LPMSG AnsiMsg)
} }
/* /*
* Unicode Result to Ansi Result * callout return -> Unicode Result to Ansi Result
*/ */
static BOOL FASTCALL static BOOL FASTCALL
MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg, LPMSG AnsiMsg, LRESULT *Result) MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg, LPMSG AnsiMsg, LRESULT *Result)
@ -877,9 +885,10 @@ MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg, LPMSG AnsiMsg, LRESULT *Result)
if (UnicodeMsg->wParam) if (UnicodeMsg->wParam)
{ {
DWORD len = 0; DWORD len = 0;
if (*Result) RtlUnicodeToMultiByteN( AnsiBuffer, UnicodeMsg->wParam - 1, &len, Buffer, strlenW(Buffer) * sizeof(WCHAR) ); if (*Result) RtlUnicodeToMultiByteN( AnsiBuffer, UnicodeMsg->wParam - 1, &len, Buffer, strlenW(Buffer) * sizeof(WCHAR));
AnsiBuffer[len] = 0; AnsiBuffer[len] = 0;
*Result = len; *Result = len;
//ERR("WM_GETTEXT U2A Result %d Size %d\n",*Result,AnsiMsg->wParam);
} }
break; break;
} }
@ -912,6 +921,9 @@ MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg, LPMSG AnsiMsg, LRESULT *Result)
return TRUE; return TRUE;
} }
//
// Unicode to Ansi callout ->
//
static BOOL FASTCALL static BOOL FASTCALL
MsgiUnicodeToAnsiMessage(HWND hwnd, LPMSG AnsiMsg, LPMSG UnicodeMsg) MsgiUnicodeToAnsiMessage(HWND hwnd, LPMSG AnsiMsg, LPMSG UnicodeMsg)
{ {
@ -979,40 +991,40 @@ MsgiUnicodeToAnsiMessage(HWND hwnd, LPMSG AnsiMsg, LPMSG UnicodeMsg)
{ {
if (!UnicodeMsg->lParam) break; if (!UnicodeMsg->lParam) break;
/* Ansi string might contain MBCS chars so we need 2 * the number of chars */ /* Ansi string might contain MBCS chars so we need 2 * the number of chars */
AnsiMsg->wParam = UnicodeMsg->wParam * 2; AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, UnicodeMsg->wParam * 2);
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg->wParam); //ERR("WM_GETTEXT U2A Size %d\n",AnsiMsg->wParam);
if (!AnsiMsg->lParam) return FALSE; if (!AnsiMsg->lParam) return FALSE;
break; break;
} }
case LB_GETTEXT: case LB_GETTEXT:
{ {
DWORD Size; DWORD Size = 1024;
if (!UnicodeMsg->lParam || !listbox_has_strings( UnicodeMsg->hwnd )) break; if (!UnicodeMsg->lParam || !listbox_has_strings( UnicodeMsg->hwnd )) break;
Size = SendMessageA( UnicodeMsg->hwnd, LB_GETTEXTLEN, UnicodeMsg->wParam, 0 ); /*Size = SendMessageA( UnicodeMsg->hwnd, LB_GETTEXTLEN, UnicodeMsg->wParam, 0 );
if (Size == LB_ERR) if (Size == LB_ERR)
{ {
ERR("LB_GETTEXT LB_ERR\n"); ERR("LB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR); Size = sizeof(ULONG_PTR);
} }
Size = (Size + 1) * sizeof(WCHAR); Size = (Size + 1) * sizeof(WCHAR);*/
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size); AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!AnsiMsg->lParam) return FALSE; if (!AnsiMsg->lParam) return FALSE;
break; break;
} }
case CB_GETLBTEXT: case CB_GETLBTEXT:
{ {
DWORD Size; DWORD Size = 1024;
if (!UnicodeMsg->lParam || !combobox_has_strings( UnicodeMsg->hwnd )) break; if (!UnicodeMsg->lParam || !combobox_has_strings( UnicodeMsg->hwnd )) break;
Size = SendMessageA( UnicodeMsg->hwnd, CB_GETLBTEXTLEN, UnicodeMsg->wParam, 0 ); /*Size = SendMessageA( UnicodeMsg->hwnd, CB_GETLBTEXTLEN, UnicodeMsg->wParam, 0 );
if (Size == LB_ERR) if (Size == LB_ERR)
{ {
ERR("CB_GETTEXT LB_ERR\n"); ERR("CB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR); Size = sizeof(ULONG_PTR);
} }
Size = (Size + 1) * sizeof(WCHAR); Size = (Size + 1) * sizeof(WCHAR);*/
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size); AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!AnsiMsg->lParam) return FALSE; if (!AnsiMsg->lParam) return FALSE;
break; break;
} }
@ -1168,6 +1180,9 @@ MsgiUnicodeToAnsiMessage(HWND hwnd, LPMSG AnsiMsg, LPMSG UnicodeMsg)
case WM_IME_CHAR: case WM_IME_CHAR:
AnsiMsg->wParam = map_wparam_char_WtoA(UnicodeMsg->wParam,2); AnsiMsg->wParam = map_wparam_char_WtoA(UnicodeMsg->wParam,2);
break; break;
case EM_GETLINE:
ERR("FIXME EM_GETLINE U2A\n");
break;
} }
return TRUE; return TRUE;
} }
@ -1273,7 +1288,7 @@ MsgiUnicodeToAnsiCleanup(LPMSG AnsiMsg, LPMSG UnicodeMsg)
} }
/* /*
* Ansi Result to Unicode Result * callout return -> Ansi Result to Unicode Result
*/ */
static BOOL FASTCALL static BOOL FASTCALL
MsgiUnicodeToAnsiReply(LPMSG AnsiMsg, LPMSG UnicodeMsg, LRESULT *Result) MsgiUnicodeToAnsiReply(LPMSG AnsiMsg, LPMSG UnicodeMsg, LRESULT *Result)
@ -1286,13 +1301,14 @@ MsgiUnicodeToAnsiReply(LPMSG AnsiMsg, LPMSG UnicodeMsg, LRESULT *Result)
case WM_GETTEXT: case WM_GETTEXT:
case WM_ASKCBFORMATNAME: case WM_ASKCBFORMATNAME:
{ {
DWORD len = AnsiMsg->wParam * 2; DWORD len = AnsiMsg->wParam;// * 2;
if (len) if (len)
{ {
if (*Result) if (*Result)
{ {
RtlMultiByteToUnicodeN( UBuffer, AnsiMsg->wParam*sizeof(WCHAR), &len, Buffer, strlen(Buffer)+1 ); RtlMultiByteToUnicodeN( UBuffer, AnsiMsg->wParam*sizeof(WCHAR), &len, Buffer, strlen(Buffer)+1 );
*Result = len/sizeof(WCHAR) - 1; /* do not count terminating null */ *Result = len/sizeof(WCHAR) - 1; /* do not count terminating null */
//ERR("WM_GETTEXT U2A Result %d Size %d\n",*Result,AnsiMsg->wParam);
} }
UBuffer[*Result] = 0; UBuffer[*Result] = 0;
} }
@ -2377,7 +2393,8 @@ SendMessageW(HWND Wnd,
if ( Window != NULL && if ( Window != NULL &&
Window->head.pti == ti && Window->head.pti == ti &&
!IsThreadHooked(GetWin32ClientInfo()) && // This is why HOOKs are bad! They slow the system down! !ISITHOOKED(WH_CALLWNDPROC) &&
!ISITHOOKED(WH_CALLWNDPROCRET) &&
!(Window->state & WNDS_SERVERSIDEWINDOWPROC) ) !(Window->state & WNDS_SERVERSIDEWINDOWPROC) )
{ {
/* NOTE: We can directly send messages to the window procedure /* NOTE: We can directly send messages to the window procedure
@ -2440,7 +2457,8 @@ SendMessageA(HWND Wnd, UINT Msg, WPARAM wParam, LPARAM lParam)
if ( Window != NULL && if ( Window != NULL &&
Window->head.pti == ti && Window->head.pti == ti &&
!IsThreadHooked(GetWin32ClientInfo()) && // This is why HOOKs are bad! They slow the system down! !ISITHOOKED(WH_CALLWNDPROC) &&
!ISITHOOKED(WH_CALLWNDPROCRET) &&
!(Window->state & WNDS_SERVERSIDEWINDOWPROC) ) !(Window->state & WNDS_SERVERSIDEWINDOWPROC) )
{ {
/* NOTE: We can directly send messages to the window procedure /* NOTE: We can directly send messages to the window procedure

View file

@ -1171,7 +1171,7 @@ GetWindowInfo(HWND hWnd,
pwi->cxWindowBorders = Size.cx; pwi->cxWindowBorders = Size.cx;
pwi->cyWindowBorders = Size.cy; pwi->cyWindowBorders = Size.cy;
pwi->dwWindowStatus = 0; pwi->dwWindowStatus = 0;
if (pWnd->state & WNDS_ACTIVEFRAME) if (pWnd->state & WNDS_ACTIVEFRAME || (GetActiveWindow() == hWnd))
pwi->dwWindowStatus = WS_ACTIVECAPTION; pwi->dwWindowStatus = WS_ACTIVECAPTION;
pwi->atomWindowType = (pCls ? pCls->atomClassName : 0 ); pwi->atomWindowType = (pCls ? pCls->atomClassName : 0 );
@ -1237,7 +1237,6 @@ GetWindowModuleFileNameW(HWND hwnd,
return GetModuleFileNameW( Wnd->hModule, lpszFileName, cchFileNameMax ); return GetModuleFileNameW( Wnd->hModule, lpszFileName, cchFileNameMax );
} }
/* /*
* @implemented * @implemented
*/ */
@ -1264,7 +1263,6 @@ GetWindowRect(HWND hWnd,
return TRUE; return TRUE;
} }
/* /*
* @implemented * @implemented
*/ */
@ -1272,69 +1270,35 @@ int WINAPI
GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount) GetWindowTextA(HWND hWnd, LPSTR lpString, int nMaxCount)
{ {
PWND Wnd; PWND Wnd;
PCWSTR Buffer;
INT Length = 0; INT Length = 0;
if (lpString == NULL) if (lpString == NULL || nMaxCount == 0)
return 0; return 0;
Wnd = ValidateHwnd(hWnd); Wnd = ValidateHwnd(hWnd);
if (!Wnd) if (!Wnd)
return 0; return 0;
_SEH2_TRY lpString[0] = '\0';
if (!TestWindowProcess( Wnd))
{ {
if (!TestWindowProcess( Wnd)) _SEH2_TRY
{ {
if (nMaxCount > 0) Length = DefWindowProcA(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
{ }
/* do not send WM_GETTEXT messages to other processes */ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
Length = Wnd->strName.Length / sizeof(WCHAR); {
if (Length != 0) Length = 0;
{ }
Buffer = DesktopPtrToUser(Wnd->strName.Buffer); _SEH2_END;
if (Buffer != NULL)
{
if (!WideCharToMultiByte(CP_ACP,
0,
Buffer,
Length + 1,
lpString,
nMaxCount,
NULL,
NULL))
{
lpString[nMaxCount - 1] = '\0';
}
}
else
{
Length = 0;
lpString[0] = '\0';
}
}
else
lpString[0] = '\0';
}
Wnd = NULL; /* Don't send a message */
}
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) else
{ Length = SendMessageA(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
lpString[0] = '\0'; //ERR("GWTA Len %d : %s\n",Length,lpString);
Length = 0;
Wnd = NULL; /* Don't send a message */
}
_SEH2_END;
if (Wnd != NULL)
Length = SendMessageA(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
return Length; return Length;
} }
/* /*
* @implemented * @implemented
*/ */
@ -1344,7 +1308,6 @@ GetWindowTextLengthA(HWND hWnd)
return(SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0)); return(SendMessageA(hWnd, WM_GETTEXTLENGTH, 0, 0));
} }
/* /*
* @implemented * @implemented
*/ */
@ -1354,7 +1317,6 @@ GetWindowTextLengthW(HWND hWnd)
return(SendMessageW(hWnd, WM_GETTEXTLENGTH, 0, 0)); return(SendMessageW(hWnd, WM_GETTEXTLENGTH, 0, 0));
} }
/* /*
* @implemented * @implemented
*/ */
@ -1362,57 +1324,32 @@ int WINAPI
GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount) GetWindowTextW(HWND hWnd, LPWSTR lpString, int nMaxCount)
{ {
PWND Wnd; PWND Wnd;
PCWSTR Buffer;
INT Length = 0; INT Length = 0;
if (lpString == NULL) if (lpString == NULL || nMaxCount == 0)
return 0; return 0;
Wnd = ValidateHwnd(hWnd); Wnd = ValidateHwnd(hWnd);
if (!Wnd) if (!Wnd)
return 0; return 0;
_SEH2_TRY lpString[0] = L'\0';
if (!TestWindowProcess( Wnd))
{ {
if (!TestWindowProcess( Wnd)) _SEH2_TRY
{ {
if (nMaxCount > 0) Length = DefWindowProcW(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
{ }
/* do not send WM_GETTEXT messages to other processes */ _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER)
Length = Wnd->strName.Length / sizeof(WCHAR); {
if (Length != 0) Length = 0;
{ }
Buffer = DesktopPtrToUser(Wnd->strName.Buffer); _SEH2_END;
if (Buffer != NULL)
{
RtlCopyMemory(lpString,
Buffer,
(Length + 1) * sizeof(WCHAR));
}
else
{
Length = 0;
lpString[0] = '\0';
}
}
else
lpString[0] = '\0';
}
Wnd = NULL; /* Don't send a message */
}
} }
_SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) else
{ Length = SendMessageW(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
lpString[0] = '\0'; //ERR("GWTW Len %d : %S\n",Length,lpString);
Length = 0;
Wnd = NULL; /* Don't send a message */
}
_SEH2_END;
if (Wnd != NULL)
Length = SendMessageW(hWnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString);
return Length; return Length;
} }