From d0af123a415bb564811eb72650d8dda88699e993 Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 19 May 2003 19:00:02 +0000 Subject: [PATCH] Catch broadcast window handles in functions that are implemented using SendMessage. --- dlls/user/message.c | 6 ------ include/win.h | 6 ++++++ windows/win.c | 27 +++++++++++++++++++++++++++ windows/winpos.c | 23 ++++++++++++++++++++++- 4 files changed, 55 insertions(+), 7 deletions(-) diff --git a/dlls/user/message.c b/dlls/user/message.c index d7b3f11105a..315a99f2830 100644 --- a/dlls/user/message.c +++ b/dlls/user/message.c @@ -274,12 +274,6 @@ inline static BOOL listbox_has_strings( HWND hwnd ) return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS)); } -/* check if hwnd is a broadcast magic handle */ -inline static BOOL is_broadcast( HWND hwnd ) -{ - return (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST); -} - /*********************************************************************** * broadcast_message_callback diff --git a/include/win.h b/include/win.h index d73fbdca6f6..07340d59b8e 100644 --- a/include/win.h +++ b/include/win.h @@ -136,4 +136,10 @@ extern HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType ); /* windows/defwnd.c extern BOOL FOCUS_MouseActivate( HWND hwnd ); +/* check if hwnd is a broadcast magic handle */ +inline static BOOL is_broadcast( HWND hwnd ) +{ + return (hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST); +} + #endif /* __WINE_WIN_H */ diff --git a/windows/win.c b/windows/win.c index 9d6058bfc76..1ed1104df87 100644 --- a/windows/win.c +++ b/windows/win.c @@ -1691,6 +1691,12 @@ BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable ) LONG style; HWND full_handle; + if (is_broadcast(hwnd)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + if (!(full_handle = WIN_IsCurrentThread( hwnd ))) return SendMessageW( hwnd, WM_WINE_ENABLEWINDOW, enable, 0 ); @@ -1983,6 +1989,11 @@ static LONG WIN_SetWindowLong( HWND hwnd, INT offset, LONG newval, TRACE( "%p %d %lx %x\n", hwnd, offset, newval, type ); + if (is_broadcast(hwnd)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } if (!WIN_IsCurrentProcess( hwnd )) { if (offset == GWL_WNDPROC) @@ -2322,6 +2333,11 @@ INT WINAPI GetWindowTextW( HWND hwnd, LPWSTR lpString, INT nMaxCount ) */ BOOL WINAPI SetWindowTextA( HWND hwnd, LPCSTR lpString ) { + if (is_broadcast(hwnd)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } if (!WIN_IsCurrentProcess( hwnd )) { FIXME( "cannot set text %s of other process window %p\n", debugstr_a(lpString), hwnd ); @@ -2337,6 +2353,11 @@ BOOL WINAPI SetWindowTextA( HWND hwnd, LPCSTR lpString ) */ BOOL WINAPI SetWindowTextW( HWND hwnd, LPCWSTR lpString ) { + if (is_broadcast(hwnd)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } if (!WIN_IsCurrentProcess( hwnd )) { FIXME( "cannot set text %s of other process window %p\n", debugstr_w(lpString), hwnd ); @@ -2537,6 +2558,12 @@ HWND WINAPI SetParent( HWND hwnd, HWND parent ) HWND retvalue, full_handle; BOOL was_visible; + if (is_broadcast(hwnd) || is_broadcast(parent)) + { + SetLastError(ERROR_INVALID_PARAMETER); + return 0; + } + if (!parent) parent = GetDesktopWindow(); else parent = WIN_GetFullHandle( parent ); diff --git a/windows/winpos.c b/windows/winpos.c index 98871797ed5..666055227f5 100644 --- a/windows/winpos.c +++ b/windows/winpos.c @@ -834,6 +834,12 @@ BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd ) { HWND full_handle; + if (is_broadcast(hwnd)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + if ((full_handle = WIN_IsCurrentThread( hwnd ))) return USER_Driver.pShowWindow( full_handle, cmd ); return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 ); @@ -847,8 +853,17 @@ BOOL WINAPI ShowWindow( HWND hwnd, INT cmd ) { HWND full_handle; + if (is_broadcast(hwnd)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } if ((full_handle = WIN_IsCurrentThread( hwnd ))) - return USER_Driver.pShowWindow( full_handle, cmd ); + { + if (USER_Driver.pShowWindow) + return USER_Driver.pShowWindow( full_handle, cmd ); + return FALSE; + } return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 ); } @@ -1173,6 +1188,12 @@ BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter, hwnd, hwndInsertAfter, x, y, cx, cy, flags); if(TRACE_ON(win)) dump_winpos_flags(flags); + if (is_broadcast(hwnd)) + { + SetLastError( ERROR_INVALID_PARAMETER ); + return FALSE; + } + winpos.hwnd = WIN_GetFullHandle(hwnd); winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter); winpos.x = x;