From fd60414fce64fb97c4ac66267f84b9c577d7473b Mon Sep 17 00:00:00 2001 From: Piotr Caban Date: Thu, 7 Oct 2021 16:34:11 +0200 Subject: [PATCH] user32: Fix window style while CBT_CREATEWND hook is called. Signed-off-by: Piotr Caban Signed-off-by: Alexandre Julliard --- dlls/user32/tests/win.c | 17 ++++++--------- dlls/user32/win.c | 40 +++++++++++++++++++++++----------- include/wine/server_protocol.h | 4 +++- server/protocol.def | 2 ++ server/request.h | 4 +++- server/trace.c | 2 ++ server/window.c | 2 ++ 7 files changed, 46 insertions(+), 25 deletions(-) diff --git a/dlls/user32/tests/win.c b/dlls/user32/tests/win.c index 6715a26b631..6b13d93be14 100644 --- a/dlls/user32/tests/win.c +++ b/dlls/user32/tests/win.c @@ -1222,10 +1222,9 @@ static LRESULT CALLBACK cbt_hook_proc(int nCode, WPARAM wParam, LPARAM lParam) /* WS_VISIBLE should be turned off yet */ style = createwnd->lpcs->style & ~WS_VISIBLE; - todo_wine_if(!(style & WS_CLIPSIBLINGS) && (!(style & WS_CHILD) || (style & WS_POPUP))) - ok(style == GetWindowLongA(hwnd, GWL_STYLE), - "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n", - GetWindowLongA(hwnd, GWL_STYLE), style); + ok(style == GetWindowLongA(hwnd, GWL_STYLE), + "style of hwnd and style in the CREATESTRUCT do not match: %08x != %08x\n", + GetWindowLongA(hwnd, GWL_STYLE), style); if (0) { @@ -4451,13 +4450,11 @@ static LRESULT WINAPI cbt_proc(int ncode, WPARAM wparam, LPARAM lparam) c->lpcs->dwExStyle, ts->cs_exstyle); style = GetWindowLongW(hwnd, GWL_STYLE); - todo_wine_if(!(ts->cs_style & WS_CHILD) || (ts->cs_style & WS_POPUP)) - ok(style == ts->cs_style, "style = 0x%08x, expected 0x%08x\n", - style, ts->cs_style); + ok(style == ts->cs_style, "style = 0x%08x, expected 0x%08x\n", + style, ts->cs_style); style = GetWindowLongW(hwnd, GWL_EXSTYLE); - todo_wine_if(ts->exstyle != ts->cs_exstyle) - ok(style == (ts->cs_exstyle & ~WS_EX_LAYERED), - "exstyle = 0x%08x, expected 0x%08x\n", style, ts->cs_exstyle); + ok(style == (ts->cs_exstyle & ~WS_EX_LAYERED), + "exstyle = 0x%08x, expected 0x%08x\n", style, ts->cs_exstyle); return CallNextHookEx(NULL, ncode, wparam, lparam); } diff --git a/dlls/user32/win.c b/dlls/user32/win.c index 081d21a95d0..5e89f4c2c97 100644 --- a/dlls/user32/win.c +++ b/dlls/user32/win.c @@ -192,7 +192,8 @@ void *free_user_handle( HANDLE handle, enum user_obj_type type ) * Create a window handle with the server. */ static WND *create_window_handle( HWND parent, HWND owner, LPCWSTR name, - HINSTANCE instance, BOOL unicode ) + HINSTANCE instance, BOOL unicode, + DWORD style, DWORD ex_style ) { WORD index; WND *win; @@ -209,6 +210,8 @@ static WND *create_window_handle( HWND parent, HWND owner, LPCWSTR name, req->instance = wine_server_client_ptr( instance ); req->dpi = GetDpiForSystem(); req->awareness = awareness; + req->style = style; + req->ex_style = ex_style; if (!(req->atom = get_int_atom_value( name )) && name) wine_server_add_data( req, name, lstrlenW(name)*sizeof(WCHAR) ); if (!wine_server_call_err( req )) @@ -1482,7 +1485,7 @@ static DWORD fix_exstyle( DWORD style, DWORD exstyle ) */ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, BOOL unicode ) { - INT cx, cy, style, sw = SW_SHOW; + INT cx, cy, style, ex_style, sw = SW_SHOW; LRESULT result; RECT rect; WND *wndPtr; @@ -1614,13 +1617,17 @@ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, /* Create the window structure */ - if (!(wndPtr = create_window_handle( parent, owner, className, module, unicode ))) + style = cs->style & ~WS_VISIBLE; + ex_style = cs->dwExStyle & ~WS_EX_LAYERED; + if (!(wndPtr = create_window_handle( parent, owner, className, module, + unicode, style, ex_style ))) { WNDCLASSW wc; /* if it's a comctl32 class, GetClassInfo will load it, then we can retry */ if (GetLastError() != ERROR_INVALID_HANDLE || !GetClassInfoW( 0, className, &wc ) || - !(wndPtr = create_window_handle( parent, owner, className, module, unicode ))) + !(wndPtr = create_window_handle( parent, owner, className, module, + unicode, style, ex_style ))) return 0; } hwnd = wndPtr->obj.handle; @@ -1630,8 +1637,8 @@ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, wndPtr->tid = GetCurrentThreadId(); wndPtr->hInstance = cs->hInstance; wndPtr->text = NULL; - wndPtr->dwStyle = cs->style & ~WS_VISIBLE; - wndPtr->dwExStyle = cs->dwExStyle; + wndPtr->dwStyle = style; + wndPtr->dwExStyle = ex_style; wndPtr->wIDmenu = 0; wndPtr->helpContext = 0; wndPtr->pScroll = NULL; @@ -1647,6 +1654,19 @@ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, if (wndPtr->dwStyle & WS_SYSMENU) SetSystemMenu( hwnd, 0 ); + /* call the WH_CBT hook */ + + WIN_ReleasePtr( wndPtr ); + cbcs = *cs; + cbtc.lpcs = &cbcs; + cbtc.hwndInsertAfter = HWND_TOP; + if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode ) || + !(wndPtr = WIN_GetPtr( hwnd ))) + { + free_window_handle( hwnd ); + return 0; + } + /* * Correct the window styles. * @@ -1660,6 +1680,7 @@ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, wndPtr->dwStyle |= WS_CAPTION; } + wndPtr->dwExStyle = cs->dwExStyle; /* WS_EX_WINDOWEDGE depends on some other styles */ if ((wndPtr->dwStyle & (WS_DLGFRAME | WS_THICKFRAME)) && !(wndPtr->dwStyle & (WS_CHILD | WS_POPUP))) @@ -1713,13 +1734,6 @@ HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, context = SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd )); - /* call the WH_CBT hook */ - - cbcs = *cs; - cbtc.lpcs = &cbcs; - cbtc.hwndInsertAfter = HWND_TOP; - if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode )) goto failed; - /* send the WM_GETMINMAXINFO message and fix the size if needed */ cx = cs->cx; diff --git a/include/wine/server_protocol.h b/include/wine/server_protocol.h index 02c90ea9011..8a85e0bc4ff 100644 --- a/include/wine/server_protocol.h +++ b/include/wine/server_protocol.h @@ -3021,6 +3021,8 @@ struct create_window_request mod_handle_t instance; int dpi; int awareness; + unsigned int style; + unsigned int ex_style; /* VARARG(class,unicode_str); */ }; struct create_window_reply @@ -6257,7 +6259,7 @@ union generic_reply /* ### protocol_version begin ### */ -#define SERVER_PROTOCOL_VERSION 732 +#define SERVER_PROTOCOL_VERSION 733 /* ### protocol_version end ### */ diff --git a/server/protocol.def b/server/protocol.def index a7a4b7cc957..0f58dc7c85a 100644 --- a/server/protocol.def +++ b/server/protocol.def @@ -2241,6 +2241,8 @@ enum message_type mod_handle_t instance; /* module instance */ int dpi; /* system DPI */ int awareness; /* thread DPI awareness */ + unsigned int style; /* window style */ + unsigned int ex_style; /* window extended style */ VARARG(class,unicode_str); /* class name */ @REPLY user_handle_t handle; /* created window */ diff --git a/server/request.h b/server/request.h index ff1744c1a80..778e7272bf5 100644 --- a/server/request.h +++ b/server/request.h @@ -1441,7 +1441,9 @@ C_ASSERT( FIELD_OFFSET(struct create_window_request, atom) == 20 ); C_ASSERT( FIELD_OFFSET(struct create_window_request, instance) == 24 ); C_ASSERT( FIELD_OFFSET(struct create_window_request, dpi) == 32 ); C_ASSERT( FIELD_OFFSET(struct create_window_request, awareness) == 36 ); -C_ASSERT( sizeof(struct create_window_request) == 40 ); +C_ASSERT( FIELD_OFFSET(struct create_window_request, style) == 40 ); +C_ASSERT( FIELD_OFFSET(struct create_window_request, ex_style) == 44 ); +C_ASSERT( sizeof(struct create_window_request) == 48 ); C_ASSERT( FIELD_OFFSET(struct create_window_reply, handle) == 8 ); C_ASSERT( FIELD_OFFSET(struct create_window_reply, parent) == 12 ); C_ASSERT( FIELD_OFFSET(struct create_window_reply, owner) == 16 ); diff --git a/server/trace.c b/server/trace.c index a007cb280f0..5a2afac504a 100644 --- a/server/trace.c +++ b/server/trace.c @@ -2929,6 +2929,8 @@ static void dump_create_window_request( const struct create_window_request *req dump_uint64( ", instance=", &req->instance ); fprintf( stderr, ", dpi=%d", req->dpi ); fprintf( stderr, ", awareness=%d", req->awareness ); + fprintf( stderr, ", style=%08x", req->style ); + fprintf( stderr, ", ex_style=%08x", req->ex_style ); dump_varargs_unicode_str( ", class=", cur_size ); } diff --git a/server/window.c b/server/window.c index c94c745bd3c..7ea91d2a7dc 100644 --- a/server/window.c +++ b/server/window.c @@ -1964,6 +1964,8 @@ DECL_HANDLER(create_window) win->dpi_awareness = req->awareness; win->dpi = req->dpi; } + win->style = req->style; + win->ex_style = req->ex_style; reply->handle = win->handle; reply->parent = win->parent ? win->parent->handle : 0;