From: Rémi Bernon rbernon@codeweavers.com
--- server/protocol.def | 1 - server/window.c | 1 - 2 files changed, 2 deletions(-)
diff --git a/server/protocol.def b/server/protocol.def index a0af063a88e..4d2907bd31e 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -2586,7 +2586,6 @@ enum message_type user_handle_t last_active; /* last active popup */ process_id_t pid; /* process owning the window */ thread_id_t tid; /* thread owning the window */ - atom_t atom; /* class atom */ int is_unicode; /* ANSI or unicode */ unsigned int dpi_context; /* window DPI context */ @END diff --git a/server/window.c b/server/window.c index 1eb815dfe3e..b0fb032d562 100644 --- a/server/window.c +++ b/server/window.c @@ -2331,7 +2331,6 @@ DECL_HANDLER(get_window_info) { reply->tid = get_thread_id( win->thread ); reply->pid = get_process_id( win->thread->process ); - reply->atom = win->class ? get_class_atom( win->class ) : DESKTOP_ATOM; } }
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/window.c | 28 ++++------------------------ server/protocol.def | 1 - server/window.c | 1 - 3 files changed, 4 insertions(+), 26 deletions(-)
diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 64fc0be3dfd..8374f061d6d 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -229,36 +229,16 @@ HWND get_hwnd_message_parent(void) */ HWND get_full_window_handle( HWND hwnd ) { - WND *win; + struct user_entry entry; + HANDLE handle;
if (!hwnd || (ULONG_PTR)hwnd >> 16) return hwnd; if (LOWORD(hwnd) <= 1 || LOWORD(hwnd) == 0xffff) return hwnd; /* do sign extension for -2 and -3 */ if (LOWORD(hwnd) >= (WORD)-3) return (HWND)(LONG_PTR)(INT16)LOWORD(hwnd);
- if (!(win = get_win_ptr( hwnd ))) return hwnd; - - if (win == WND_DESKTOP) - { - if (LOWORD(hwnd) == LOWORD(get_desktop_window())) return get_desktop_window(); - else return get_hwnd_message_parent(); - } - - if (win != WND_OTHER_PROCESS) - { - hwnd = win->obj.handle; - release_win_ptr( win ); - } - else /* may belong to another process */ - { - SERVER_START_REQ( get_window_info ) - { - req->handle = wine_server_user_handle( hwnd ); - if (!wine_server_call_err( req )) hwnd = wine_server_ptr_handle( reply->full_handle ); - } - SERVER_END_REQ; - } - return hwnd; + if (!get_user_entry( hwnd, NTUSER_OBJ_WINDOW, &entry, &handle )) return 0; + return handle; }
/******************************************************************* diff --git a/server/protocol.def b/server/protocol.def index 4d2907bd31e..516dc1a7a95 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -2582,7 +2582,6 @@ enum message_type @REQ(get_window_info) user_handle_t handle; /* handle to the window */ @REPLY - user_handle_t full_handle; /* full 32-bit handle */ user_handle_t last_active; /* last active popup */ process_id_t pid; /* process owning the window */ thread_id_t tid; /* thread owning the window */ diff --git a/server/window.c b/server/window.c index b0fb032d562..8cbe55077bf 100644 --- a/server/window.c +++ b/server/window.c @@ -2321,7 +2321,6 @@ DECL_HANDLER(get_window_info)
if (!win) return;
- reply->full_handle = win->handle; reply->last_active = win->handle; reply->is_unicode = win->is_unicode; reply->dpi_context = win->dpi_context;
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/window.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-)
diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 8374f061d6d..7eb7d20a35b 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -287,14 +287,12 @@ WND *get_win_ptr( HWND hwnd ) */ HWND is_current_thread_window( HWND hwnd ) { - WND *win; - HWND ret = 0; + struct user_entry entry; + HANDLE handle;
- if (!(win = get_win_ptr( hwnd )) || win == WND_OTHER_PROCESS || win == WND_DESKTOP) - return 0; - if (win->tid == GetCurrentThreadId()) ret = win->obj.handle; - release_win_ptr( win ); - return ret; + if (!get_user_entry( hwnd, NTUSER_OBJ_WINDOW, &entry, &handle )) return 0; + if (entry.tid != GetCurrentThreadId()) return 0; + return handle; }
/***********************************************************************
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/window.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 7eb7d20a35b..3461093ec1f 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -302,13 +302,12 @@ HWND is_current_thread_window( HWND hwnd ) */ HWND is_current_process_window( HWND hwnd ) { - WND *ptr; - HWND ret; + struct user_entry entry; + HANDLE handle;
- if (!(ptr = get_win_ptr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0; - ret = ptr->obj.handle; - release_win_ptr( ptr ); - return ret; + if (!get_user_entry( hwnd, NTUSER_OBJ_WINDOW, &entry, &handle )) return 0; + if (entry.pid != GetCurrentProcessId()) return 0; + return handle; }
/* see IsWindow */
From: Rémi Bernon rbernon@codeweavers.com
--- dlls/win32u/window.c | 33 +++++++-------------------------- server/protocol.def | 2 -- server/window.c | 5 ----- 3 files changed, 7 insertions(+), 33 deletions(-)
diff --git a/dlls/win32u/window.c b/dlls/win32u/window.c index 3461093ec1f..8bd6e7b9aa1 100644 --- a/dlls/win32u/window.c +++ b/dlls/win32u/window.c @@ -325,36 +325,17 @@ BOOL is_window( HWND hwnd ) /* see GetWindowThreadProcessId */ DWORD get_window_thread( HWND hwnd, DWORD *process ) { - WND *ptr; - DWORD tid = 0; + struct user_entry entry; + HANDLE handle;
- if (!(ptr = get_win_ptr( hwnd ))) + if (!get_user_entry( hwnd, NTUSER_OBJ_WINDOW, &entry, &handle )) { - RtlSetLastWin32Error( ERROR_INVALID_WINDOW_HANDLE); + RtlSetLastWin32Error( ERROR_INVALID_WINDOW_HANDLE ); return 0; }
- if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP) - { - /* got a valid window */ - tid = ptr->tid; - if (process) *process = GetCurrentProcessId(); - release_win_ptr( ptr ); - return tid; - } - - /* check other processes */ - SERVER_START_REQ( get_window_info ) - { - req->handle = wine_server_user_handle( hwnd ); - if (!wine_server_call_err( req )) - { - tid = (DWORD)reply->tid; - if (process) *process = (DWORD)reply->pid; - } - } - SERVER_END_REQ; - return tid; + if (process) *process = entry.pid; + return entry.tid; }
/* see GetParent */ @@ -6078,7 +6059,7 @@ HANDLE WINAPI NtUserQueryWindow( HWND hwnd, WINDOWINFOCLASS cls ) { case WindowProcess: case WindowProcess2: - get_window_thread( hwnd, &pid ); + if (!get_window_thread( hwnd, &pid )) return NULL; return UlongToHandle( pid );
case WindowThread: diff --git a/server/protocol.def b/server/protocol.def index 516dc1a7a95..26c411d0c62 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -2583,8 +2583,6 @@ enum message_type user_handle_t handle; /* handle to the window */ @REPLY user_handle_t last_active; /* last active popup */ - process_id_t pid; /* process owning the window */ - thread_id_t tid; /* thread owning the window */ int is_unicode; /* ANSI or unicode */ unsigned int dpi_context; /* window DPI context */ @END diff --git a/server/window.c b/server/window.c index 8cbe55077bf..914d376a44a 100644 --- a/server/window.c +++ b/server/window.c @@ -2326,11 +2326,6 @@ DECL_HANDLER(get_window_info) reply->dpi_context = win->dpi_context;
if (get_user_object( win->last_active, NTUSER_OBJ_WINDOW )) reply->last_active = win->last_active; - if (win->thread) - { - reply->tid = get_thread_id( win->thread ); - reply->pid = get_process_id( win->thread->process ); - } }
Jacek Caban (@jacek) commented about dlls/win32u/window.c:
*/ HWND is_current_thread_window( HWND hwnd ) {
- WND *win;
- HWND ret = 0;
- struct user_entry entry;
- HANDLE handle;
- if (!(win = get_win_ptr( hwnd )) || win == WND_OTHER_PROCESS || win == WND_DESKTOP)
return 0;
- if (win->tid == GetCurrentThreadId()) ret = win->obj.handle;
- release_win_ptr( win );
- return ret;
- if (!get_user_entry( hwnd, NTUSER_OBJ_WINDOW, &entry, &handle )) return 0;
- if (entry.tid != GetCurrentThreadId()) return 0;
Not a big deal, but since `get_window_thread` is optimized later in the series, we could just use it here to simplify the code a bit. Same goes for `is_current_process_window`.
On Tue May 13 09:39:16 2025 +0000, Jacek Caban wrote:
Not a big deal, but since `get_window_thread` is optimized later in the series, we could just use it here to simplify the code a bit. Same goes for `is_current_process_window`.
Both `is_current_thread_window` and `is_current_process_window` are supposed to return the full window handle, while `get_window_thread` doesn't.
Also, `get_window_thread` sets last error, which these functions were not setting.
On Tue May 13 10:00:30 2025 +0000, Rémi Bernon wrote:
Both `is_current_thread_window` and `is_current_process_window` are supposed to return the full window handle, while `get_window_thread` doesn't. Also, `get_window_thread` sets last error, which these functions were not setting.
Ah, right. FWIW, I think full window handling would ideally be moved out of win32u, probably into 16-bit modules. With a shared handle table, that should be feasible without introducing extra server calls. Anyway, definitely out of scope here.
This merge request was approved by Jacek Caban.