- 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;
}
//
// Ansi to Unicode -> callout
//
static BOOL FASTCALL
MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
{
@ -579,7 +582,8 @@ MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
{
LPWSTR Buffer;
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;
UnicodeMsg->lParam = (LPARAM)Buffer;
break;
@ -587,32 +591,32 @@ MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
case LB_GETTEXT:
{
DWORD Size;
DWORD Size = 1024 * sizeof(WCHAR);
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)
{
ERR("LB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR);
}
Size = (Size + 1) * sizeof(WCHAR);
UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size);
Size = (Size + 1) * sizeof(WCHAR);*/
UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!UnicodeMsg->lParam) return FALSE;
break;
}
case CB_GETLBTEXT:
{
DWORD Size;
DWORD Size = 1024 * sizeof(WCHAR);
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)
{
ERR("CB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR);
}
Size = (Size + 1) * sizeof(WCHAR);
UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size);
Size = (Size + 1) * sizeof(WCHAR);*/
UnicodeMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!UnicodeMsg->lParam) return FALSE;
break;
}
@ -747,6 +751,10 @@ MsgiAnsiToUnicodeMessage(HWND hwnd, LPMSG UnicodeMsg, LPMSG AnsiMsg)
case WM_IME_CHAR:
UnicodeMsg->wParam = map_wparam_AtoW( AnsiMsg->message, AnsiMsg->wParam );
break;
case EM_GETLINE:
ERR("FIXME EM_GETLINE A2U\n");
break;
}
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
MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg, LPMSG AnsiMsg, LRESULT *Result)
@ -877,9 +885,10 @@ MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg, LPMSG AnsiMsg, LRESULT *Result)
if (UnicodeMsg->wParam)
{
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;
*Result = len;
//ERR("WM_GETTEXT U2A Result %d Size %d\n",*Result,AnsiMsg->wParam);
}
break;
}
@ -912,6 +921,9 @@ MsgiAnsiToUnicodeReply(LPMSG UnicodeMsg, LPMSG AnsiMsg, LRESULT *Result)
return TRUE;
}
//
// Unicode to Ansi callout ->
//
static BOOL FASTCALL
MsgiUnicodeToAnsiMessage(HWND hwnd, LPMSG AnsiMsg, LPMSG UnicodeMsg)
{
@ -979,40 +991,40 @@ MsgiUnicodeToAnsiMessage(HWND hwnd, LPMSG AnsiMsg, LPMSG UnicodeMsg)
{
if (!UnicodeMsg->lParam) break;
/* Ansi string might contain MBCS chars so we need 2 * the number of chars */
AnsiMsg->wParam = UnicodeMsg->wParam * 2;
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, AnsiMsg->wParam);
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, UnicodeMsg->wParam * 2);
//ERR("WM_GETTEXT U2A Size %d\n",AnsiMsg->wParam);
if (!AnsiMsg->lParam) return FALSE;
break;
}
case LB_GETTEXT:
{
DWORD Size;
DWORD Size = 1024;
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)
{
ERR("LB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR);
}
Size = (Size + 1) * sizeof(WCHAR);
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size);
Size = (Size + 1) * sizeof(WCHAR);*/
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!AnsiMsg->lParam) return FALSE;
break;
}
case CB_GETLBTEXT:
{
DWORD Size;
DWORD Size = 1024;
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)
{
ERR("CB_GETTEXT LB_ERR\n");
Size = sizeof(ULONG_PTR);
}
Size = (Size + 1) * sizeof(WCHAR);
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), 0, Size);
Size = (Size + 1) * sizeof(WCHAR);*/
AnsiMsg->lParam = (LPARAM) RtlAllocateHeap(GetProcessHeap(), HEAP_ZERO_MEMORY, Size);
if (!AnsiMsg->lParam) return FALSE;
break;
}
@ -1168,6 +1180,9 @@ MsgiUnicodeToAnsiMessage(HWND hwnd, LPMSG AnsiMsg, LPMSG UnicodeMsg)
case WM_IME_CHAR:
AnsiMsg->wParam = map_wparam_char_WtoA(UnicodeMsg->wParam,2);
break;
case EM_GETLINE:
ERR("FIXME EM_GETLINE U2A\n");
break;
}
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
MsgiUnicodeToAnsiReply(LPMSG AnsiMsg, LPMSG UnicodeMsg, LRESULT *Result)
@ -1286,13 +1301,14 @@ MsgiUnicodeToAnsiReply(LPMSG AnsiMsg, LPMSG UnicodeMsg, LRESULT *Result)
case WM_GETTEXT:
case WM_ASKCBFORMATNAME:
{
DWORD len = AnsiMsg->wParam * 2;
DWORD len = AnsiMsg->wParam;// * 2;
if (len)
{
if (*Result)
{
RtlMultiByteToUnicodeN( UBuffer, AnsiMsg->wParam*sizeof(WCHAR), &len, Buffer, strlen(Buffer)+1 );
*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;
}
@ -2377,7 +2393,8 @@ SendMessageW(HWND Wnd,
if ( Window != NULL &&
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) )
{
/* 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 &&
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) )
{
/* NOTE: We can directly send messages to the window procedure

View file

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