From 13ebffa83ec5bf470421f6a8b31257fb862207cd Mon Sep 17 00:00:00 2001 From: James Tabor Date: Thu, 10 May 2012 06:08:51 +0000 Subject: [PATCH] [Win32SS] - Fix the remaining wine Win tests for FindWindow/Ex/A/W. Check the buffer not the length, buffer could be pointing to a null. Enable the message window handling. Use wine code for FindWindowExA. svn path=/trunk/; revision=56557 --- reactos/win32ss/user/ntuser/window.c | 23 ++++---- reactos/win32ss/user/user32/windows/window.c | 57 ++++++-------------- 2 files changed, 28 insertions(+), 52 deletions(-) diff --git a/reactos/win32ss/user/ntuser/window.c b/reactos/win32ss/user/ntuser/window.c index 63198421a80..1e0a2a3e799 100644 --- a/reactos/win32ss/user/ntuser/window.c +++ b/reactos/win32ss/user/ntuser/window.c @@ -2509,7 +2509,7 @@ IntFindWindow(PWND Parent, ASSERT(Parent); - CheckWindowName = WindowName->Length != 0; + CheckWindowName = WindowName->Buffer != 0; if((List = IntWinListChildren(Parent))) { @@ -2588,6 +2588,7 @@ NtUserFindWindowEx(HWND hwndParent, PWND Parent, ChildAfter; UNICODE_STRING ClassName = {0}, WindowName = {0}; HWND Desktop, Ret = NULL; + BOOL DoMessageWnd = FALSE; RTL_ATOM ClassAtom = (RTL_ATOM)0; DECLARE_RETURN(HWND); @@ -2657,7 +2658,10 @@ NtUserFindWindowEx(HWND hwndParent, Desktop = IntGetCurrentThreadDesktopWindow(); if(hwndParent == NULL) + { hwndParent = Desktop; + DoMessageWnd = TRUE; + } else if(hwndParent == HWND_MESSAGE) { hwndParent = IntGetMessageWindow(); @@ -2698,7 +2702,7 @@ NtUserFindWindowEx(HWND hwndParent, ; } - CheckWindowName = WindowName.Length != 0; + CheckWindowName = WindowName.Buffer != 0; /* search children */ while(*phWnd) @@ -2741,15 +2745,13 @@ NtUserFindWindowEx(HWND hwndParent, } } else - Ret = IntFindWindow(Parent, ChildAfter, ClassAtom, &WindowName); - -#if 0 - - if(Ret == NULL && hwndParent == NULL && hwndChildAfter == NULL) { - /* FIXME: If both hwndParent and hwndChildAfter are NULL, we also should - search the message-only windows. Should this also be done if - Parent is the desktop window??? */ + ERR("FindWindowEx: Not Desktop Parent!\n"); + Ret = IntFindWindow(Parent, ChildAfter, ClassAtom, &WindowName); + } + + if (Ret == NULL && DoMessageWnd) + { PWND MsgWindows; if((MsgWindows = UserGetWindowObject(IntGetMessageWindow()))) @@ -2757,7 +2759,6 @@ NtUserFindWindowEx(HWND hwndParent, Ret = IntFindWindow(MsgWindows, ChildAfter, ClassAtom, &WindowName); } } -#endif } _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER) { diff --git a/reactos/win32ss/user/user32/windows/window.c b/reactos/win32ss/user/user32/windows/window.c index 81b9e3cce73..7d0bceb350e 100644 --- a/reactos/win32ss/user/user32/windows/window.c +++ b/reactos/win32ss/user/user32/windows/window.c @@ -744,54 +744,29 @@ FindWindowExA(HWND hwndParent, LPCSTR lpszClass, LPCSTR lpszWindow) { - UNICODE_STRING ucClassName, *pucClassName = NULL; - UNICODE_STRING ucWindowName, *pucWindowName = NULL; - HWND Result; + LPWSTR titleW = NULL; + HWND hwnd = 0; - if (IS_ATOM(lpszClass)) + if (lpszWindow) { - ucClassName.Buffer = (LPWSTR)lpszClass; - ucClassName.Length = 0; - pucClassName = &ucClassName; - } - else if (lpszClass != NULL) - { - if (!RtlCreateUnicodeStringFromAsciiz(&ucClassName, - (LPSTR)lpszClass)) - { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return NULL; - } - pucClassName = &ucClassName; + DWORD len = MultiByteToWideChar( CP_ACP, 0, lpszWindow, -1, NULL, 0 ); + if (!(titleW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0; + MultiByteToWideChar( CP_ACP, 0, lpszWindow, -1, titleW, len ); } - if (lpszWindow != NULL) + if (!IS_INTRESOURCE(lpszClass)) { - if (!RtlCreateUnicodeStringFromAsciiz(&ucWindowName, - (LPSTR)lpszWindow)) - { - if (!IS_ATOM(lpszClass) && lpszClass != NULL) - RtlFreeUnicodeString(&ucWindowName); - - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return NULL; - } - - pucWindowName = &ucWindowName; + WCHAR classW[256]; + if (MultiByteToWideChar( CP_ACP, 0, lpszClass, -1, classW, sizeof(classW)/sizeof(WCHAR) )) + hwnd = FindWindowExW( hwndParent, hwndChildAfter, classW, titleW ); + } + else + { + hwnd = FindWindowExW( hwndParent, hwndChildAfter, (LPCWSTR)lpszClass, titleW ); } - Result = NtUserFindWindowEx(hwndParent, - hwndChildAfter, - pucClassName, - pucWindowName, - 0); - - if (!IS_ATOM(lpszClass) && lpszClass != NULL) - RtlFreeUnicodeString(&ucClassName); - if (lpszWindow != NULL) - RtlFreeUnicodeString(&ucWindowName); - - return Result; + HeapFree( GetProcessHeap(), 0, titleW ); + return hwnd; }