From 90c13be9dde8ea32cbe4958e2ba3bc0bf1669a2f Mon Sep 17 00:00:00 2001 From: Jacek Caban Date: Tue, 8 Mar 2022 14:23:37 +0100 Subject: [PATCH] win32u: Move NtUserInternalGetWindowText implementation from user32. Signed-off-by: Jacek Caban Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/user32/button.c | 2 +- dlls/user32/mdi.c | 4 ++-- dlls/user32/spy.c | 2 +- dlls/user32/static.c | 2 +- dlls/user32/tests/win.c | 5 +++++ dlls/user32/user32.spec | 2 +- dlls/user32/win.c | 26 +------------------------ dlls/win32u/syscall.c | 1 + dlls/win32u/win32u.spec | 2 +- dlls/win32u/window.c | 43 +++++++++++++++++++++++++++++++++++++++++ dlls/wow64win/syscall.h | 1 + dlls/wow64win/user.c | 9 +++++++++ include/ntuser.h | 1 + 13 files changed, 68 insertions(+), 32 deletions(-) diff --git a/dlls/user32/button.c b/dlls/user32/button.c index e3af68e0e54..5fdf4803c18 100644 --- a/dlls/user32/button.c +++ b/dlls/user32/button.c @@ -173,7 +173,7 @@ static inline WCHAR *get_button_text( HWND hwnd ) { static const INT len = 512; WCHAR *buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ); - if (buffer) InternalGetWindowText( hwnd, buffer, len + 1 ); + if (buffer) NtUserInternalGetWindowText( hwnd, buffer, len + 1 ); return buffer; } diff --git a/dlls/user32/mdi.c b/dlls/user32/mdi.c index 66f258bb3f3..4b8e0bcd7fd 100644 --- a/dlls/user32/mdi.c +++ b/dlls/user32/mdi.c @@ -452,7 +452,7 @@ static LRESULT MDI_RefreshMenu(MDICLIENTINFO *ci) buf[0] = '&'; buf[1] = '0' + visible; buf[2] = ' '; - InternalGetWindowText(ci->child[i], buf + 3, ARRAY_SIZE(buf) - 3); + NtUserInternalGetWindowText(ci->child[i], buf + 3, ARRAY_SIZE(buf) - 3); TRACE("Adding %p, id %u %s\n", ci->child[i], id, debugstr_w(buf)); AppendMenuW(ci->hWindowMenu, MF_STRING, id, buf); @@ -1911,7 +1911,7 @@ static INT_PTR WINAPI MDI_MoreWindowsDlgProc (HWND hDlg, UINT iMsg, WPARAM wPara { WCHAR buffer[MDI_MAXTITLELENGTH]; - if (!InternalGetWindowText(ci->child[i], buffer, ARRAY_SIZE(buffer))) + if (!NtUserInternalGetWindowText(ci->child[i], buffer, ARRAY_SIZE(buffer))) continue; SendMessageW(hListBox, LB_ADDSTRING, 0, (LPARAM)buffer ); SendMessageW(hListBox, LB_SETITEMDATA, i, (LPARAM)ci->child[i] ); diff --git a/dlls/user32/spy.c b/dlls/user32/spy.c index 8093799ed6b..dc8e0b2a708 100644 --- a/dlls/user32/spy.c +++ b/dlls/user32/spy.c @@ -2186,7 +2186,7 @@ static void SPY_GetWndName( SPY_INSTANCE *sp_e ) SPY_GetClassName( sp_e ); - len = InternalGetWindowText(sp_e->msg_hwnd, sp_e->wnd_name, ARRAY_SIZE(sp_e->wnd_name)); + len = NtUserInternalGetWindowText( sp_e->msg_hwnd, sp_e->wnd_name, ARRAY_SIZE(sp_e->wnd_name) ); if(!len) /* get class name */ { LPWSTR dst = sp_e->wnd_name; diff --git a/dlls/user32/static.c b/dlls/user32/static.c index 8de216269c1..d19df22dcb9 100644 --- a/dlls/user32/static.c +++ b/dlls/user32/static.c @@ -635,7 +635,7 @@ static void STATIC_PaintTextfn( HWND hwnd, HDC hdc, HBRUSH hbrush, DWORD style ) if (!(text = HeapAlloc( GetProcessHeap(), 0, buf_size * sizeof(WCHAR) ))) goto no_TextOut; - while ((len = InternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1) + while ((len = NtUserInternalGetWindowText( hwnd, text, buf_size )) == buf_size - 1) { buf_size *= 2; if (!(text = HeapReAlloc( GetProcessHeap(), 0, text, buf_size * sizeof(WCHAR) ))) diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index d6087873f21..cfcec5cc78f 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -8308,6 +8308,11 @@ static void test_gettext(void) ok( !strcmp(buf, "blah"), "got %s\n", buf ); ok( num_gettext_msgs == 0, "got %u WM_GETTEXT messages\n", num_gettext_msgs ); + bufW[0] = 0xcc; + buf_len = InternalGetWindowText( hwnd, bufW, ARRAYSIZE(bufW) ); + ok( buf_len == ARRAYSIZE("caption") - 1, "expected a nonempty window text\n" ); + ok( !lstrcmpW( bufW, L"caption" ), "got %s\n", debugstr_w(bufW) ); + g_wm_gettext_override.enabled = FALSE; /* same for W window */ diff --git a/dlls/user32/user32.spec b/dlls/user32/user32.spec index 88f73206943..cdd8815f67c 100644 --- a/dlls/user32/user32.spec +++ b/dlls/user32/user32.spec @@ -446,7 +446,7 @@ @ stdcall InsertMenuItemW(long long long ptr) @ stdcall InsertMenuW(long long long long ptr) @ stdcall InternalGetWindowIcon(ptr long) -@ stdcall InternalGetWindowText(long ptr long) +@ stdcall InternalGetWindowText(long ptr long) NtUserInternalGetWindowText @ stdcall IntersectRect(ptr ptr ptr) @ stdcall InvalidateRect(long ptr long) @ stdcall InvalidateRgn(long long long) diff --git a/dlls/user32/win.c b/dlls/user32/win.c index a71753bd148..fc31e0cc01d 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -2037,7 +2037,7 @@ HWND WINAPI FindWindowExW( HWND parent, HWND child, LPCWSTR className, LPCWSTR t { while (list[i]) { - if (InternalGetWindowText( list[i], buffer, len + 1 )) + if (NtUserInternalGetWindowText( list[i], buffer, len + 1 )) { if (!wcsicmp( buffer, title )) break; } @@ -2944,30 +2944,6 @@ INT WINAPI GetWindowTextA( HWND hwnd, LPSTR lpString, INT nMaxCount ) } -/******************************************************************* - * InternalGetWindowText (USER32.@) - */ -INT WINAPI InternalGetWindowText(HWND hwnd,LPWSTR lpString,INT nMaxCount ) -{ - WND *win; - - if (nMaxCount <= 0) return 0; - if (!(win = WIN_GetPtr( hwnd ))) return 0; - if (win == WND_DESKTOP) lpString[0] = 0; - else if (win != WND_OTHER_PROCESS) - { - if (win->text) lstrcpynW( lpString, win->text, nMaxCount ); - else lpString[0] = 0; - WIN_ReleasePtr( win ); - } - else - { - get_server_window_text( hwnd, lpString, nMaxCount ); - } - return lstrlenW(lpString); -} - - /******************************************************************* * GetWindowTextW (USER32.@) */ diff --git a/dlls/win32u/syscall.c b/dlls/win32u/syscall.c index 95cb2452f9c..19c03b277b1 100644 --- a/dlls/win32u/syscall.c +++ b/dlls/win32u/syscall.c @@ -139,6 +139,7 @@ static void * const syscalls[] = NtUserGetSystemDpiForProcess, NtUserGetThreadDesktop, NtUserInitializeClientPfnArrays, + NtUserInternalGetWindowText, NtUserNotifyWinEvent, NtUserOpenDesktop, NtUserOpenInputDesktop, diff --git a/dlls/win32u/win32u.spec b/dlls/win32u/win32u.spec index d0561ad8e58..e3e7b31b4a2 100644 --- a/dlls/win32u/win32u.spec +++ b/dlls/win32u/win32u.spec @@ -1045,7 +1045,7 @@ @ stub NtUserInjectTouchInput @ stub NtUserInteractiveControlQueryUsage @ stub NtUserInternalGetWindowIcon -@ stub NtUserInternalGetWindowText +@ stdcall -syscall NtUserInternalGetWindowText(long ptr long) @ stub NtUserInternalToUnicode @ stub NtUserInvalidateRect @ stub NtUserInvalidateRgn diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index b0aab45d28d..93ee0ffd164 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -425,6 +425,49 @@ NTSTATUS WINAPI NtUserBuildHwndList( HDESK desktop, ULONG unk2, ULONG unk3, ULON return STATUS_SUCCESS; } +/* Retrieve the window text from the server. */ +static data_size_t get_server_window_text( HWND hwnd, WCHAR *text, data_size_t count ) +{ + data_size_t len = 0, needed = 0; + + SERVER_START_REQ( get_window_text ) + { + req->handle = wine_server_user_handle( hwnd ); + if (count) wine_server_set_reply( req, text, (count - 1) * sizeof(WCHAR) ); + if (!wine_server_call_err( req )) + { + needed = reply->length; + len = wine_server_reply_size(reply); + } + } + SERVER_END_REQ; + if (text) text[len / sizeof(WCHAR)] = 0; + return needed; +} + +/******************************************************************* + * NtUserInternalGetWindowText (win32u.@) + */ +INT WINAPI NtUserInternalGetWindowText( HWND hwnd, WCHAR *text, INT count ) +{ + WND *win; + + if (count <= 0) return 0; + if (!(win = get_win_ptr( hwnd ))) return 0; + if (win == WND_DESKTOP) text[0] = 0; + else if (win != WND_OTHER_PROCESS) + { + if (win->text) lstrcpynW( text, win->text, count ); + else text[0] = 0; + release_win_ptr( win ); + } + else + { + get_server_window_text( hwnd, text, count ); + } + return lstrlenW(text); +} + /***************************************************************************** * NtUserCallHwnd (win32u.@) */ diff --git a/dlls/wow64win/syscall.h b/dlls/wow64win/syscall.h index 6ca0daee71a..78ba09645b2 100644 --- a/dlls/wow64win/syscall.h +++ b/dlls/wow64win/syscall.h @@ -124,6 +124,7 @@ SYSCALL_ENTRY( NtUserGetSystemDpiForProcess ) \ SYSCALL_ENTRY( NtUserGetThreadDesktop ) \ SYSCALL_ENTRY( NtUserInitializeClientPfnArrays ) \ + SYSCALL_ENTRY( NtUserInternalGetWindowText ) \ SYSCALL_ENTRY( NtUserNotifyWinEvent ) \ SYSCALL_ENTRY( NtUserOpenDesktop ) \ SYSCALL_ENTRY( NtUserOpenInputDesktop ) \ diff --git a/dlls/wow64win/user.c b/dlls/wow64win/user.c index 51879956a7c..a72b0307cc5 100644 --- a/dlls/wow64win/user.c +++ b/dlls/wow64win/user.c @@ -214,6 +214,15 @@ NTSTATUS WINAPI wow64_NtUserBuildHwndList( UINT *args ) return status; } +NTSTATUS WINAPI wow64_NtUserInternalGetWindowText( UINT *args ) +{ + HWND hwnd = get_handle( &args ); + WCHAR *text = get_ptr( &args ); + INT count = get_ulong( &args ); + + return NtUserInternalGetWindowText( hwnd, text, count ); +} + NTSTATUS WINAPI wow64_NtUserGetLayeredWindowAttributes( UINT *args ) { HWND hwnd = get_handle( &args ); diff --git a/include/ntuser.h b/include/ntuser.h index 6111d227476..34d75f4f726 100644 --- a/include/ntuser.h +++ b/include/ntuser.h @@ -312,6 +312,7 @@ BOOL WINAPI NtUserGetUpdatedClipboardFormats( UINT *formats, UINT size, UINT NTSTATUS WINAPI NtUserInitializeClientPfnArrays( const struct user_client_procs *client_procsA, const struct user_client_procs *client_procsW, const void *client_workers, HINSTANCE user_module ); +INT WINAPI NtUserInternalGetWindowText( HWND hwnd, WCHAR *text, INT count ); BOOL WINAPI NtUserIsClipboardFormatAvailable( UINT format ); UINT WINAPI NtUserMapVirtualKeyEx( UINT code, UINT type, HKL layout ); void WINAPI NtUserNotifyWinEvent( DWORD event, HWND hwnd, LONG object_id, LONG child_id );