2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
30 #include "wine/server.h"
31 #include "wine/unicode.h"
33 #include "user_private.h"
36 #include "wine/debug.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(win);
40 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
41 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
43 /**********************************************************************/
45 /* helper for Get/SetWindowLong */
46 static inline LONG_PTR get_win_data( const void *ptr, UINT size )
48 if (size == sizeof(WORD))
51 memcpy( &ret, ptr, sizeof(ret) );
54 else if (size == sizeof(DWORD))
57 memcpy( &ret, ptr, sizeof(ret) );
63 memcpy( &ret, ptr, sizeof(ret) );
68 /* helper for Get/SetWindowLong */
69 static inline void set_win_data( void *ptr, LONG_PTR val, UINT size )
71 if (size == sizeof(WORD))
74 memcpy( ptr, &newval, sizeof(newval) );
76 else if (size == sizeof(DWORD))
79 memcpy( ptr, &newval, sizeof(newval) );
83 memcpy( ptr, &val, sizeof(val) );
88 static void *user_handles[NB_USER_HANDLES];
90 /***********************************************************************
93 HANDLE alloc_user_handle( struct user_object *ptr, enum user_obj_type type )
97 SERVER_START_REQ( alloc_user_handle )
99 if (!wine_server_call_err( req )) handle = wine_server_ptr_handle( reply->handle );
105 UINT index = USER_HANDLE_TO_INDEX( handle );
107 assert( index < NB_USER_HANDLES );
108 ptr->handle = handle;
110 user_handles[index] = ptr;
116 /***********************************************************************
117 * get_user_handle_ptr
119 void *get_user_handle_ptr( HANDLE handle, enum user_obj_type type )
121 struct user_object *ptr;
122 WORD index = USER_HANDLE_TO_INDEX( handle );
124 if (index >= NB_USER_HANDLES) return NULL;
127 if ((ptr = user_handles[index]))
129 if (ptr->type == type &&
130 ((UINT)(UINT_PTR)ptr->handle == (UINT)(UINT_PTR)handle ||
131 !HIWORD(handle) || HIWORD(handle) == 0xffff))
135 else ptr = OBJ_OTHER_PROCESS;
141 /***********************************************************************
142 * release_user_handle_ptr
144 void release_user_handle_ptr( void *ptr )
150 /***********************************************************************
153 void *free_user_handle( HANDLE handle, enum user_obj_type type )
155 struct user_object *ptr;
156 WORD index = USER_HANDLE_TO_INDEX( handle );
158 if ((ptr = get_user_handle_ptr( handle, type )) && ptr != OBJ_OTHER_PROCESS)
160 SERVER_START_REQ( free_user_handle )
162 req->handle = wine_server_user_handle( handle );
163 if (!wine_server_call( req )) user_handles[index] = NULL;
167 release_user_handle_ptr( ptr );
173 /***********************************************************************
174 * create_window_handle
176 * Create a window handle with the server.
178 static WND *create_window_handle( HWND parent, HWND owner, LPCWSTR name,
179 HINSTANCE instance, BOOL unicode )
183 HWND handle = 0, full_parent = 0, full_owner = 0;
184 struct tagCLASS *class = NULL;
187 SERVER_START_REQ( create_window )
189 req->parent = wine_server_user_handle( parent );
190 req->owner = wine_server_user_handle( owner );
191 req->instance = wine_server_client_ptr( instance );
192 if (!(req->atom = get_int_atom_value( name )) && name)
193 wine_server_add_data( req, name, strlenW(name)*sizeof(WCHAR) );
194 if (!wine_server_call_err( req ))
196 handle = wine_server_ptr_handle( reply->handle );
197 full_parent = wine_server_ptr_handle( reply->parent );
198 full_owner = wine_server_ptr_handle( reply->owner );
199 extra_bytes = reply->extra;
200 class = wine_server_get_ptr( reply->class_ptr );
207 WARN( "error %d creating window\n", GetLastError() );
211 if (!(win = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
212 sizeof(WND) + extra_bytes - sizeof(win->wExtra) )))
214 SERVER_START_REQ( destroy_window )
216 req->handle = wine_server_user_handle( handle );
217 wine_server_call( req );
220 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
224 if (!parent) /* if parent is 0 we don't have a desktop window yet */
226 struct user_thread_info *thread_info = get_user_thread_info();
228 if (name == (LPCWSTR)DESKTOP_CLASS_ATOM)
230 if (!thread_info->top_window) thread_info->top_window = full_parent ? full_parent : handle;
231 else assert( full_parent == thread_info->top_window );
232 if (full_parent && !USER_Driver->pCreateDesktopWindow( thread_info->top_window ))
233 ERR( "failed to create desktop window\n" );
235 else /* HWND_MESSAGE parent */
237 if (!thread_info->msg_window && !full_parent) thread_info->msg_window = handle;
243 index = USER_HANDLE_TO_INDEX(handle);
244 assert( index < NB_USER_HANDLES );
245 user_handles[index] = win;
246 win->obj.handle = handle;
247 win->obj.type = USER_WINDOW;
248 win->parent = full_parent;
249 win->owner = full_owner;
251 win->winproc = get_class_winproc( class );
252 win->cbWndExtra = extra_bytes;
253 if (WINPROC_IsUnicode( win->winproc, unicode )) win->flags |= WIN_ISUNICODE;
258 /***********************************************************************
261 * Free a window handle.
263 static void free_window_handle( HWND hwnd )
265 struct user_object *ptr;
266 WORD index = USER_HANDLE_TO_INDEX(hwnd);
268 if ((ptr = get_user_handle_ptr( hwnd, USER_WINDOW )) && ptr != OBJ_OTHER_PROCESS)
270 SERVER_START_REQ( destroy_window )
272 req->handle = wine_server_user_handle( hwnd );
273 if (!wine_server_call_err( req )) user_handles[index] = NULL;
277 release_user_handle_ptr( ptr );
278 HeapFree( GetProcessHeap(), 0, ptr );
283 /*******************************************************************
284 * list_window_children
286 * Build an array of the children of a given window. The array must be
287 * freed with HeapFree. Returns NULL when no windows are found.
289 static HWND *list_window_children( HDESK desktop, HWND hwnd, LPCWSTR class, DWORD tid )
293 ATOM atom = get_int_atom_value( class );
295 /* empty class is not the same as NULL class */
296 if (!atom && class && !class[0]) return NULL;
302 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
304 SERVER_START_REQ( get_window_children )
306 req->desktop = wine_server_obj_handle( desktop );
307 req->parent = wine_server_user_handle( hwnd );
310 if (!atom && class) wine_server_add_data( req, class, strlenW(class)*sizeof(WCHAR) );
311 wine_server_set_reply( req, list, (size-1) * sizeof(user_handle_t) );
312 if (!wine_server_call( req )) count = reply->count;
315 if (count && count < size)
317 /* start from the end since HWND is potentially larger than user_handle_t */
318 for (i = count - 1; i >= 0; i--)
319 list[i] = wine_server_ptr_handle( ((user_handle_t *)list)[i] );
323 HeapFree( GetProcessHeap(), 0, list );
325 size = count + 1; /* restart with a large enough buffer */
331 /*******************************************************************
332 * list_window_parents
334 * Build an array of all parents of a given window, starting with
335 * the immediate parent. The array must be freed with HeapFree.
337 static HWND *list_window_parents( HWND hwnd )
341 int i, pos = 0, size = 16, count = 0;
343 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) return NULL;
348 if (!(win = WIN_GetPtr( current ))) goto empty;
349 if (win == WND_OTHER_PROCESS) break; /* need to do it the hard way */
350 if (win == WND_DESKTOP)
352 if (!pos) goto empty;
356 list[pos] = current = win->parent;
357 WIN_ReleasePtr( win );
358 if (!current) return list;
359 if (++pos == size - 1)
361 /* need to grow the list */
362 HWND *new_list = HeapReAlloc( GetProcessHeap(), 0, list, (size+16) * sizeof(HWND) );
363 if (!new_list) goto empty;
369 /* at least one parent belongs to another process, have to query the server */
374 SERVER_START_REQ( get_window_parents )
376 req->handle = wine_server_user_handle( hwnd );
377 wine_server_set_reply( req, list, (size-1) * sizeof(user_handle_t) );
378 if (!wine_server_call( req )) count = reply->count;
381 if (!count) goto empty;
384 /* start from the end since HWND is potentially larger than user_handle_t */
385 for (i = count - 1; i >= 0; i--)
386 list[i] = wine_server_ptr_handle( ((user_handle_t *)list)[i] );
390 HeapFree( GetProcessHeap(), 0, list );
392 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) return NULL;
396 HeapFree( GetProcessHeap(), 0, list );
401 /*******************************************************************
404 static void send_parent_notify( HWND hwnd, UINT msg )
406 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD &&
407 !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY))
409 HWND parent = GetParent(hwnd);
410 if (parent && parent != GetDesktopWindow())
411 SendMessageW( parent, WM_PARENTNOTIFY,
412 MAKEWPARAM( msg, GetWindowLongPtrW( hwnd, GWLP_ID )), (LPARAM)hwnd );
417 /*******************************************************************
418 * get_server_window_text
420 * Retrieve the window text from the server.
422 static void get_server_window_text( HWND hwnd, LPWSTR text, INT count )
426 SERVER_START_REQ( get_window_text )
428 req->handle = wine_server_user_handle( hwnd );
429 wine_server_set_reply( req, text, (count - 1) * sizeof(WCHAR) );
430 if (!wine_server_call_err( req )) len = wine_server_reply_size(reply);
433 text[len / sizeof(WCHAR)] = 0;
437 /*******************************************************************
438 * get_hwnd_message_parent
440 * Return the parent for HWND_MESSAGE windows.
442 HWND get_hwnd_message_parent(void)
444 struct user_thread_info *thread_info = get_user_thread_info();
446 if (!thread_info->msg_window) GetDesktopWindow(); /* trigger creation */
447 return thread_info->msg_window;
451 /*******************************************************************
454 * Check if window is the desktop or the HWND_MESSAGE top parent.
456 BOOL is_desktop_window( HWND hwnd )
458 struct user_thread_info *thread_info = get_user_thread_info();
460 if (!hwnd) return FALSE;
461 if (hwnd == thread_info->top_window) return TRUE;
462 if (hwnd == thread_info->msg_window) return TRUE;
464 if (!HIWORD(hwnd) || HIWORD(hwnd) == 0xffff)
466 if (LOWORD(thread_info->top_window) == LOWORD(hwnd)) return TRUE;
467 if (LOWORD(thread_info->msg_window) == LOWORD(hwnd)) return TRUE;
473 /***********************************************************************
476 * Return a pointer to the WND structure if local to the process,
477 * or WND_OTHER_PROCESS if handle may be valid in other process.
478 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
480 WND *WIN_GetPtr( HWND hwnd )
484 if ((ptr = get_user_handle_ptr( hwnd, USER_WINDOW )) == WND_OTHER_PROCESS)
486 if (is_desktop_window( hwnd )) ptr = WND_DESKTOP;
492 /***********************************************************************
493 * WIN_IsCurrentProcess
495 * Check whether a given window belongs to the current process (and return the full handle).
497 HWND WIN_IsCurrentProcess( HWND hwnd )
502 if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0;
503 ret = ptr->obj.handle;
504 WIN_ReleasePtr( ptr );
509 /***********************************************************************
510 * WIN_IsCurrentThread
512 * Check whether a given window belongs to the current thread (and return the full handle).
514 HWND WIN_IsCurrentThread( HWND hwnd )
519 if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0;
520 if (ptr->tid == GetCurrentThreadId()) ret = ptr->obj.handle;
521 WIN_ReleasePtr( ptr );
526 /***********************************************************************
529 * Convert a 16-bit window handle to a full 32-bit handle.
531 HWND WIN_Handle32( HWND16 hwnd16 )
534 HWND hwnd = (HWND)(ULONG_PTR)hwnd16;
536 if (hwnd16 <= 1 || hwnd16 == 0xffff) return hwnd;
537 /* do sign extension for -2 and -3 */
538 if (hwnd16 >= (HWND16)-3) return (HWND)(LONG_PTR)(INT16)hwnd16;
540 if (!(ptr = WIN_GetPtr( hwnd ))) return hwnd;
542 if (ptr == WND_DESKTOP)
544 if (LOWORD(hwnd) == LOWORD(GetDesktopWindow())) return GetDesktopWindow();
545 else return get_hwnd_message_parent();
548 if (ptr != WND_OTHER_PROCESS)
550 hwnd = ptr->obj.handle;
551 WIN_ReleasePtr( ptr );
553 else /* may belong to another process */
555 SERVER_START_REQ( get_window_info )
557 req->handle = wine_server_user_handle( hwnd );
558 if (!wine_server_call_err( req )) hwnd = wine_server_ptr_handle( reply->full_handle );
566 /***********************************************************************
569 * Change the owner of a window.
571 HWND WIN_SetOwner( HWND hwnd, HWND owner )
573 WND *win = WIN_GetPtr( hwnd );
576 if (!win || win == WND_DESKTOP) return 0;
577 if (win == WND_OTHER_PROCESS)
579 if (IsWindow(hwnd)) ERR( "cannot set owner %p on other process window %p\n", owner, hwnd );
582 SERVER_START_REQ( set_window_owner )
584 req->handle = wine_server_user_handle( hwnd );
585 req->owner = wine_server_user_handle( owner );
586 if (!wine_server_call( req ))
588 win->owner = wine_server_ptr_handle( reply->full_owner );
589 ret = wine_server_ptr_handle( reply->prev_owner );
593 WIN_ReleasePtr( win );
598 /***********************************************************************
601 * Change the style of a window.
603 ULONG WIN_SetStyle( HWND hwnd, ULONG set_bits, ULONG clear_bits )
607 WND *win = WIN_GetPtr( hwnd );
609 if (!win || win == WND_DESKTOP) return 0;
610 if (win == WND_OTHER_PROCESS)
613 ERR( "cannot set style %x/%x on other process window %p\n",
614 set_bits, clear_bits, hwnd );
617 style.styleOld = win->dwStyle;
618 style.styleNew = (win->dwStyle | set_bits) & ~clear_bits;
619 if (style.styleNew == style.styleOld)
621 WIN_ReleasePtr( win );
622 return style.styleNew;
624 SERVER_START_REQ( set_window_info )
626 req->handle = wine_server_user_handle( hwnd );
627 req->flags = SET_WIN_STYLE;
628 req->style = style.styleNew;
629 req->extra_offset = -1;
630 if ((ok = !wine_server_call( req )))
632 style.styleOld = reply->old_style;
633 win->dwStyle = style.styleNew;
637 WIN_ReleasePtr( win );
640 USER_Driver->pSetWindowStyle( hwnd, GWL_STYLE, &style );
641 if ((style.styleOld ^ style.styleNew) & WS_VISIBLE) invalidate_dce( hwnd, NULL );
643 return style.styleOld;
647 /***********************************************************************
650 * Get the window and client rectangles.
652 BOOL WIN_GetRectangles( HWND hwnd, RECT *rectWindow, RECT *rectClient )
654 WND *win = WIN_GetPtr( hwnd );
659 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
662 if (win == WND_DESKTOP)
665 rect.left = rect.top = 0;
666 if (hwnd == get_hwnd_message_parent())
673 rect.right = GetSystemMetrics(SM_CXSCREEN);
674 rect.bottom = GetSystemMetrics(SM_CYSCREEN);
676 if (rectWindow) *rectWindow = rect;
677 if (rectClient) *rectClient = rect;
679 else if (win == WND_OTHER_PROCESS)
681 SERVER_START_REQ( get_window_rectangles )
683 req->handle = wine_server_user_handle( hwnd );
684 if ((ret = !wine_server_call_err( req )))
688 rectWindow->left = reply->window.left;
689 rectWindow->top = reply->window.top;
690 rectWindow->right = reply->window.right;
691 rectWindow->bottom = reply->window.bottom;
695 rectClient->left = reply->client.left;
696 rectClient->top = reply->client.top;
697 rectClient->right = reply->client.right;
698 rectClient->bottom = reply->client.bottom;
706 if (rectWindow) *rectWindow = win->rectWindow;
707 if (rectClient) *rectClient = win->rectClient;
708 WIN_ReleasePtr( win );
714 /***********************************************************************
717 * Destroy storage associated to a window. "Internals" p.358
719 LRESULT WIN_DestroyWindow( HWND hwnd )
723 HMENU menu = 0, sys_menu;
726 TRACE("%p\n", hwnd );
728 /* free child windows */
729 if ((list = WIN_ListChildren( hwnd )))
732 for (i = 0; list[i]; i++)
734 if (WIN_IsCurrentThread( list[i] )) WIN_DestroyWindow( list[i] );
735 else SendMessageW( list[i], WM_WINE_DESTROYWINDOW, 0, 0 );
737 HeapFree( GetProcessHeap(), 0, list );
740 /* Unlink now so we won't bother with the children later on */
741 SERVER_START_REQ( set_parent )
743 req->handle = wine_server_user_handle( hwnd );
745 wine_server_call( req );
750 * Send the WM_NCDESTROY to the window being destroyed.
752 SendMessageW( hwnd, WM_NCDESTROY, 0, 0 );
754 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
756 /* free resources associated with the window */
758 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
759 if ((wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) != WS_CHILD)
760 menu = (HMENU)wndPtr->wIDmenu;
761 sys_menu = wndPtr->hSysMenu;
762 free_dce( wndPtr->dce, hwnd );
764 icon_title = wndPtr->icon_title;
765 HeapFree( GetProcessHeap(), 0, wndPtr->text );
767 HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
768 wndPtr->pScroll = NULL;
769 WIN_ReleasePtr( wndPtr );
771 if (icon_title) DestroyWindow( icon_title );
772 if (menu) DestroyMenu( menu );
773 if (sys_menu) DestroyMenu( sys_menu );
775 USER_Driver->pDestroyWindow( hwnd );
777 free_window_handle( hwnd );
782 /***********************************************************************
783 * destroy_thread_window
785 * Destroy a window upon exit of its thread.
787 static void destroy_thread_window( HWND hwnd )
791 HMENU menu = 0, sys_menu = 0;
794 /* free child windows */
796 if ((list = WIN_ListChildren( hwnd )))
799 for (i = 0; list[i]; i++)
801 if (WIN_IsCurrentThread( list[i] )) destroy_thread_window( list[i] );
802 else SendMessageW( list[i], WM_WINE_DESTROYWINDOW, 0, 0 );
804 HeapFree( GetProcessHeap(), 0, list );
807 /* destroy the client-side storage */
809 index = USER_HANDLE_TO_INDEX(hwnd);
810 if (index >= NB_USER_HANDLES) return;
812 if ((wndPtr = user_handles[index]))
814 if ((wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) != WS_CHILD) menu = (HMENU)wndPtr->wIDmenu;
815 sys_menu = wndPtr->hSysMenu;
816 free_dce( wndPtr->dce, hwnd );
817 user_handles[index] = NULL;
821 HeapFree( GetProcessHeap(), 0, wndPtr );
822 if (menu) DestroyMenu( menu );
823 if (sys_menu) DestroyMenu( sys_menu );
827 /***********************************************************************
828 * destroy_thread_child_windows
830 * Destroy child windows upon exit of its thread.
832 static void destroy_thread_child_windows( HWND hwnd )
837 if (WIN_IsCurrentThread( hwnd ))
839 destroy_thread_window( hwnd );
841 else if ((list = WIN_ListChildren( hwnd )))
843 for (i = 0; list[i]; i++) destroy_thread_child_windows( list[i] );
844 HeapFree( GetProcessHeap(), 0, list );
849 /***********************************************************************
850 * WIN_DestroyThreadWindows
852 * Destroy all children of 'wnd' owned by the current thread.
854 void WIN_DestroyThreadWindows( HWND hwnd )
859 if (!(list = WIN_ListChildren( hwnd ))) return;
861 /* reset owners of top-level windows */
862 for (i = 0; list[i]; i++)
864 if (!WIN_IsCurrentThread( list[i] ))
866 HWND owner = GetWindow( list[i], GW_OWNER );
867 if (owner && WIN_IsCurrentThread( owner )) WIN_SetOwner( list[i], 0 );
871 for (i = 0; list[i]; i++) destroy_thread_child_windows( list[i] );
872 HeapFree( GetProcessHeap(), 0, list );
876 /***********************************************************************
879 * Fix the coordinates - Helper for WIN_CreateWindowEx.
880 * returns default show mode in sw.
882 static void WIN_FixCoordinates( CREATESTRUCTW *cs, INT *sw)
884 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
887 if (cs->dwExStyle & WS_EX_MDICHILD)
891 MDI_CalcDefaultChildPos(cs->hwndParent, -1, pos, 0, &id);
892 if (!(cs->style & WS_POPUP)) cs->hMenu = ULongToHandle(id);
894 TRACE("MDI child id %04x\n", id);
897 if (cs->style & (WS_CHILD | WS_POPUP))
899 if (cs->dwExStyle & WS_EX_MDICHILD)
901 if (IS_DEFAULT(cs->x))
906 if (IS_DEFAULT(cs->cx) || !cs->cx) cs->cx = pos[1].x;
907 if (IS_DEFAULT(cs->cy) || !cs->cy) cs->cy = pos[1].y;
911 if (IS_DEFAULT(cs->x)) cs->x = cs->y = 0;
912 if (IS_DEFAULT(cs->cx)) cs->cx = cs->cy = 0;
915 else /* overlapped window */
918 MONITORINFO mon_info;
921 if (!IS_DEFAULT(cs->x) && !IS_DEFAULT(cs->cx) && !IS_DEFAULT(cs->cy)) return;
923 monitor = MonitorFromWindow( cs->hwndParent, MONITOR_DEFAULTTOPRIMARY );
924 mon_info.cbSize = sizeof(mon_info);
925 GetMonitorInfoW( monitor, &mon_info );
926 GetStartupInfoW( &info );
928 if (IS_DEFAULT(cs->x))
930 if (!IS_DEFAULT(cs->y)) *sw = cs->y;
931 cs->x = (info.dwFlags & STARTF_USEPOSITION) ? info.dwX : mon_info.rcWork.left;
932 cs->y = (info.dwFlags & STARTF_USEPOSITION) ? info.dwY : mon_info.rcWork.top;
935 if (IS_DEFAULT(cs->cx))
937 if (info.dwFlags & STARTF_USESIZE)
939 cs->cx = info.dwXSize;
940 cs->cy = info.dwYSize;
944 cs->cx = (mon_info.rcWork.right - mon_info.rcWork.left) * 3 / 4 - cs->x;
945 cs->cy = (mon_info.rcWork.bottom - mon_info.rcWork.top) * 3 / 4 - cs->y;
948 /* neither x nor cx are default. Check the y values .
949 * In the trace we see Outlook and Outlook Express using
950 * cy set to CW_USEDEFAULT when opening the address book.
952 else if (IS_DEFAULT(cs->cy))
954 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
955 cs->cy = (mon_info.rcWork.bottom - mon_info.rcWork.top) * 3 / 4 - cs->y;
961 /***********************************************************************
964 static void dump_window_styles( DWORD style, DWORD exstyle )
967 if(style & WS_POPUP) TRACE(" WS_POPUP");
968 if(style & WS_CHILD) TRACE(" WS_CHILD");
969 if(style & WS_MINIMIZE) TRACE(" WS_MINIMIZE");
970 if(style & WS_VISIBLE) TRACE(" WS_VISIBLE");
971 if(style & WS_DISABLED) TRACE(" WS_DISABLED");
972 if(style & WS_CLIPSIBLINGS) TRACE(" WS_CLIPSIBLINGS");
973 if(style & WS_CLIPCHILDREN) TRACE(" WS_CLIPCHILDREN");
974 if(style & WS_MAXIMIZE) TRACE(" WS_MAXIMIZE");
975 if((style & WS_CAPTION) == WS_CAPTION) TRACE(" WS_CAPTION");
978 if(style & WS_BORDER) TRACE(" WS_BORDER");
979 if(style & WS_DLGFRAME) TRACE(" WS_DLGFRAME");
981 if(style & WS_VSCROLL) TRACE(" WS_VSCROLL");
982 if(style & WS_HSCROLL) TRACE(" WS_HSCROLL");
983 if(style & WS_SYSMENU) TRACE(" WS_SYSMENU");
984 if(style & WS_THICKFRAME) TRACE(" WS_THICKFRAME");
985 if (style & WS_CHILD)
987 if(style & WS_GROUP) TRACE(" WS_GROUP");
988 if(style & WS_TABSTOP) TRACE(" WS_TABSTOP");
992 if(style & WS_MINIMIZEBOX) TRACE(" WS_MINIMIZEBOX");
993 if(style & WS_MAXIMIZEBOX) TRACE(" WS_MAXIMIZEBOX");
996 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
997 #define DUMPED_STYLES \
1017 if(style & ~DUMPED_STYLES) TRACE(" %08lx", style & ~DUMPED_STYLES);
1019 #undef DUMPED_STYLES
1021 TRACE( "exstyle:" );
1022 if(exstyle & WS_EX_DLGMODALFRAME) TRACE(" WS_EX_DLGMODALFRAME");
1023 if(exstyle & WS_EX_DRAGDETECT) TRACE(" WS_EX_DRAGDETECT");
1024 if(exstyle & WS_EX_NOPARENTNOTIFY) TRACE(" WS_EX_NOPARENTNOTIFY");
1025 if(exstyle & WS_EX_TOPMOST) TRACE(" WS_EX_TOPMOST");
1026 if(exstyle & WS_EX_ACCEPTFILES) TRACE(" WS_EX_ACCEPTFILES");
1027 if(exstyle & WS_EX_TRANSPARENT) TRACE(" WS_EX_TRANSPARENT");
1028 if(exstyle & WS_EX_MDICHILD) TRACE(" WS_EX_MDICHILD");
1029 if(exstyle & WS_EX_TOOLWINDOW) TRACE(" WS_EX_TOOLWINDOW");
1030 if(exstyle & WS_EX_WINDOWEDGE) TRACE(" WS_EX_WINDOWEDGE");
1031 if(exstyle & WS_EX_CLIENTEDGE) TRACE(" WS_EX_CLIENTEDGE");
1032 if(exstyle & WS_EX_CONTEXTHELP) TRACE(" WS_EX_CONTEXTHELP");
1033 if(exstyle & WS_EX_RIGHT) TRACE(" WS_EX_RIGHT");
1034 if(exstyle & WS_EX_RTLREADING) TRACE(" WS_EX_RTLREADING");
1035 if(exstyle & WS_EX_LEFTSCROLLBAR) TRACE(" WS_EX_LEFTSCROLLBAR");
1036 if(exstyle & WS_EX_CONTROLPARENT) TRACE(" WS_EX_CONTROLPARENT");
1037 if(exstyle & WS_EX_STATICEDGE) TRACE(" WS_EX_STATICEDGE");
1038 if(exstyle & WS_EX_APPWINDOW) TRACE(" WS_EX_APPWINDOW");
1039 if(exstyle & WS_EX_LAYERED) TRACE(" WS_EX_LAYERED");
1041 #define DUMPED_EX_STYLES \
1042 (WS_EX_DLGMODALFRAME | \
1043 WS_EX_DRAGDETECT | \
1044 WS_EX_NOPARENTNOTIFY | \
1046 WS_EX_ACCEPTFILES | \
1047 WS_EX_TRANSPARENT | \
1049 WS_EX_TOOLWINDOW | \
1050 WS_EX_WINDOWEDGE | \
1051 WS_EX_CLIENTEDGE | \
1052 WS_EX_CONTEXTHELP | \
1054 WS_EX_RTLREADING | \
1055 WS_EX_LEFTSCROLLBAR | \
1056 WS_EX_CONTROLPARENT | \
1057 WS_EX_STATICEDGE | \
1061 if(exstyle & ~DUMPED_EX_STYLES) TRACE(" %08lx", exstyle & ~DUMPED_EX_STYLES);
1063 #undef DUMPED_EX_STYLES
1067 /***********************************************************************
1068 * WIN_CreateWindowEx
1070 * Implementation of CreateWindowEx().
1072 HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, UINT flags )
1074 INT cx, cy, style, sw = SW_SHOW;
1078 HWND hwnd, parent, owner, top_child = 0;
1079 BOOL unicode = (flags & WIN_ISUNICODE) != 0;
1080 MDICREATESTRUCTW mdi_cs;
1081 CBT_CREATEWNDW cbtc;
1084 TRACE("%s %s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
1085 unicode ? debugstr_w(cs->lpszName) : debugstr_a((LPCSTR)cs->lpszName),
1086 debugstr_w(className),
1087 cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
1088 cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams );
1089 if(TRACE_ON(win)) dump_window_styles( cs->style, cs->dwExStyle );
1091 /* Fix the styles for MDI children */
1092 if (cs->dwExStyle & WS_EX_MDICHILD)
1096 wndPtr = WIN_GetPtr(cs->hwndParent);
1097 if (wndPtr && wndPtr != WND_OTHER_PROCESS && wndPtr != WND_DESKTOP)
1099 flags = wndPtr->flags;
1100 WIN_ReleasePtr(wndPtr);
1103 if (!(flags & WIN_ISMDICLIENT))
1105 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs->hwndParent);
1109 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
1110 * MDICREATESTRUCT members have the originally passed values.
1112 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
1113 * have the same layout.
1115 mdi_cs.szClass = cs->lpszClass;
1116 mdi_cs.szTitle = cs->lpszName;
1117 mdi_cs.hOwner = cs->hInstance;
1122 mdi_cs.style = cs->style;
1123 mdi_cs.lParam = (LPARAM)cs->lpCreateParams;
1125 cs->lpCreateParams = &mdi_cs;
1127 if (GetWindowLongW(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
1129 if (cs->style & WS_POPUP)
1131 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
1134 cs->style |= WS_CHILD | WS_CLIPSIBLINGS;
1138 cs->style &= ~WS_POPUP;
1139 cs->style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
1140 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
1143 top_child = GetWindow(cs->hwndParent, GW_CHILD);
1147 /* Restore current maximized child */
1148 if((cs->style & WS_VISIBLE) && IsZoomed(top_child))
1150 TRACE("Restoring current maximized child %p\n", top_child);
1151 SendMessageW( top_child, WM_SETREDRAW, FALSE, 0 );
1152 ShowWindow( top_child, SW_SHOWNORMAL );
1153 SendMessageW( top_child, WM_SETREDRAW, TRUE, 0 );
1158 /* Find the parent window */
1160 parent = cs->hwndParent;
1163 if (cs->hwndParent == HWND_MESSAGE)
1165 cs->hwndParent = parent = get_hwnd_message_parent();
1167 else if (cs->hwndParent)
1169 if ((cs->style & (WS_CHILD|WS_POPUP)) != WS_CHILD)
1171 parent = GetDesktopWindow();
1172 owner = cs->hwndParent;
1177 static const WCHAR messageW[] = {'M','e','s','s','a','g','e',0};
1179 if ((cs->style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
1181 WARN("No parent for child window\n" );
1182 SetLastError(ERROR_TLW_WITH_WSCHILD);
1183 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1185 /* are we creating the desktop or HWND_MESSAGE parent itself? */
1186 if (className != (LPCWSTR)DESKTOP_CLASS_ATOM &&
1187 (IS_INTRESOURCE(className) || strcmpiW( className, messageW )))
1188 parent = GetDesktopWindow();
1191 WIN_FixCoordinates(cs, &sw); /* fix default coordinates */
1193 if ((cs->dwExStyle & WS_EX_DLGMODALFRAME) ||
1194 ((!(cs->dwExStyle & WS_EX_STATICEDGE)) &&
1195 (cs->style & (WS_DLGFRAME | WS_THICKFRAME))))
1196 cs->dwExStyle |= WS_EX_WINDOWEDGE;
1198 cs->dwExStyle &= ~WS_EX_WINDOWEDGE;
1200 /* Create the window structure */
1202 if (!(wndPtr = create_window_handle( parent, owner, className, module, unicode )))
1204 hwnd = wndPtr->obj.handle;
1206 /* Fill the window structure */
1208 wndPtr->tid = GetCurrentThreadId();
1209 wndPtr->hInstance = cs->hInstance;
1210 wndPtr->text = NULL;
1211 wndPtr->dwStyle = cs->style & ~WS_VISIBLE;
1212 wndPtr->dwExStyle = cs->dwExStyle;
1213 wndPtr->wIDmenu = 0;
1214 wndPtr->helpContext = 0;
1215 wndPtr->pScroll = NULL;
1216 wndPtr->userdata = 0;
1218 wndPtr->hIconSmall = 0;
1219 wndPtr->hSysMenu = 0;
1220 wndPtr->flags |= (flags & WIN_ISWIN32);
1222 wndPtr->min_pos.x = wndPtr->min_pos.y = -1;
1223 wndPtr->max_pos.x = wndPtr->max_pos.y = -1;
1225 if (wndPtr->dwStyle & WS_SYSMENU) SetSystemMenu( hwnd, 0 );
1228 * Correct the window styles.
1230 * It affects only the style loaded into the WIN structure.
1233 if ((wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) != WS_CHILD)
1235 wndPtr->dwStyle |= WS_CLIPSIBLINGS;
1236 if (!(wndPtr->dwStyle & WS_POPUP))
1237 wndPtr->dwStyle |= WS_CAPTION;
1241 * WS_EX_WINDOWEDGE appears to be enforced based on the other styles, so
1242 * why does the user get to set it?
1245 if ((wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) ||
1246 (wndPtr->dwStyle & (WS_DLGFRAME | WS_THICKFRAME)))
1247 wndPtr->dwExStyle |= WS_EX_WINDOWEDGE;
1249 wndPtr->dwExStyle &= ~WS_EX_WINDOWEDGE;
1251 if (!(wndPtr->dwStyle & (WS_CHILD | WS_POPUP)))
1252 wndPtr->flags |= WIN_NEED_SIZE;
1254 SERVER_START_REQ( set_window_info )
1256 req->handle = wine_server_user_handle( hwnd );
1257 req->flags = SET_WIN_STYLE | SET_WIN_EXSTYLE | SET_WIN_INSTANCE | SET_WIN_UNICODE;
1258 req->style = wndPtr->dwStyle;
1259 req->ex_style = wndPtr->dwExStyle;
1260 req->instance = wine_server_client_ptr( wndPtr->hInstance );
1261 req->is_unicode = (wndPtr->flags & WIN_ISUNICODE) != 0;
1262 req->extra_offset = -1;
1263 wine_server_call( req );
1267 /* Set the window menu */
1269 if ((wndPtr->dwStyle & (WS_CHILD | WS_POPUP)) != WS_CHILD)
1273 if (!MENU_SetMenu(hwnd, cs->hMenu))
1275 WIN_ReleasePtr( wndPtr );
1276 free_window_handle( hwnd );
1282 LPCWSTR menuName = (LPCWSTR)GetClassLongPtrW( hwnd, GCLP_MENUNAME );
1285 cs->hMenu = LoadMenuW( cs->hInstance, menuName );
1286 if (cs->hMenu) MENU_SetMenu( hwnd, cs->hMenu );
1290 else SetWindowLongPtrW( hwnd, GWLP_ID, (ULONG_PTR)cs->hMenu );
1292 /* call the WH_CBT hook */
1294 /* the window style passed to the hook must be the real window style,
1295 * rather than just the window style that the caller to CreateWindowEx
1296 * passed in, so we have to copy the original CREATESTRUCT and get the
1297 * the real style. */
1299 cbcs.style = wndPtr->dwStyle;
1301 cbtc.hwndInsertAfter = HWND_TOP;
1302 WIN_ReleasePtr( wndPtr );
1303 if (HOOK_CallHooks( WH_CBT, HCBT_CREATEWND, (WPARAM)hwnd, (LPARAM)&cbtc, unicode )) goto failed;
1305 /* send the WM_GETMINMAXINFO message and fix the size if needed */
1309 if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
1311 POINT maxSize, maxPos, minTrack, maxTrack;
1312 WINPOS_GetMinMaxInfo( hwnd, &maxSize, &maxPos, &minTrack, &maxTrack);
1313 if (maxTrack.x < cx) cx = maxTrack.x;
1314 if (maxTrack.y < cy) cy = maxTrack.y;
1315 if (minTrack.x > cx) cx = minTrack.x;
1316 if (minTrack.y > cy) cy = minTrack.y;
1321 SetRect( &rect, cs->x, cs->y, cs->x + cx, cs->y + cy );
1322 /* check for wraparound */
1323 if (cs->x + cx < cs->x) rect.right = 0x7fffffff;
1324 if (cs->y + cy < cs->y) rect.bottom = 0x7fffffff;
1325 if (!set_window_pos( hwnd, 0, SWP_NOZORDER | SWP_NOACTIVATE, &rect, &rect, NULL )) goto failed;
1327 /* send WM_NCCREATE */
1329 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd, cs->x, cs->y, cx, cy );
1331 result = SendMessageW( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1333 result = SendMessageA( hwnd, WM_NCCREATE, 0, (LPARAM)cs );
1336 WARN( "%p: aborted by WM_NCCREATE\n", hwnd );
1340 /* send WM_NCCALCSIZE */
1342 if ((wndPtr = WIN_GetPtr(hwnd)))
1344 /* yes, even if the CBT hook was called with HWND_TOP */
1346 HWND insert_after = (wndPtr->dwStyle & WS_CHILD) ? HWND_BOTTOM : HWND_TOP;
1347 RECT window_rect = wndPtr->rectWindow;
1348 RECT client_rect = window_rect;
1349 WIN_ReleasePtr( wndPtr );
1351 /* the rectangle is in screen coords for WM_NCCALCSIZE when wparam is FALSE */
1353 MapWindowPoints( parent, 0, &pt, 1 );
1354 OffsetRect( &client_rect, pt.x, pt.y );
1355 SendMessageW( hwnd, WM_NCCALCSIZE, FALSE, (LPARAM)&client_rect );
1356 OffsetRect( &client_rect, -pt.x, -pt.y );
1357 set_window_pos( hwnd, insert_after, SWP_NOACTIVATE, &window_rect, &client_rect, NULL );
1361 /* send WM_CREATE */
1364 result = SendMessageW( hwnd, WM_CREATE, 0, (LPARAM)cs );
1366 result = SendMessageA( hwnd, WM_CREATE, 0, (LPARAM)cs );
1367 if (result == -1) goto failed;
1369 /* call the driver */
1371 if (!USER_Driver->pCreateWindow( hwnd )) goto failed;
1373 NotifyWinEvent(EVENT_OBJECT_CREATE, hwnd, OBJID_WINDOW, 0);
1375 /* send the size messages */
1377 if (!(wndPtr = WIN_GetPtr( hwnd )) ||
1378 wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return 0;
1379 if (!(wndPtr->flags & WIN_NEED_SIZE))
1381 rect = wndPtr->rectClient;
1382 WIN_ReleasePtr( wndPtr );
1383 SendMessageW( hwnd, WM_SIZE, SIZE_RESTORED,
1384 MAKELONG(rect.right-rect.left, rect.bottom-rect.top));
1385 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG( rect.left, rect.top ) );
1387 else WIN_ReleasePtr( wndPtr );
1389 /* Show the window, maximizing or minimizing if needed */
1391 style = WIN_SetStyle( hwnd, 0, WS_MAXIMIZE | WS_MINIMIZE );
1392 if (style & (WS_MINIMIZE | WS_MAXIMIZE))
1395 UINT swFlag = (style & WS_MINIMIZE) ? SW_MINIMIZE : SW_MAXIMIZE;
1397 swFlag = WINPOS_MinMaximize( hwnd, swFlag, &newPos );
1398 swFlag |= SWP_FRAMECHANGED; /* Frame always gets changed */
1399 if (!(style & WS_VISIBLE) || (style & WS_CHILD) || GetActiveWindow()) swFlag |= SWP_NOACTIVATE;
1400 SetWindowPos( hwnd, 0, newPos.left, newPos.top, newPos.right - newPos.left,
1401 newPos.bottom - newPos.top, swFlag );
1404 /* Notify the parent window only */
1406 send_parent_notify( hwnd, WM_CREATE );
1407 if (!IsWindow( hwnd )) return 0;
1409 if (cs->style & WS_VISIBLE)
1411 if (cs->style & WS_MAXIMIZE)
1413 else if (cs->style & WS_MINIMIZE)
1414 sw = SW_SHOWMINIMIZED;
1416 ShowWindow( hwnd, sw );
1417 if (cs->dwExStyle & WS_EX_MDICHILD)
1419 SendMessageW(cs->hwndParent, WM_MDIREFRESHMENU, 0, 0);
1420 /* ShowWindow won't activate child windows */
1421 SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
1425 /* Call WH_SHELL hook */
1427 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) && !GetWindow( hwnd, GW_OWNER ))
1428 HOOK_CallHooks( WH_SHELL, HSHELL_WINDOWCREATED, (WPARAM)hwnd, 0, TRUE );
1430 TRACE("created window %p\n", hwnd);
1434 WIN_DestroyWindow( hwnd );
1439 /***********************************************************************
1440 * CreateWindowExA (USER32.@)
1442 HWND WINAPI CreateWindowExA( DWORD exStyle, LPCSTR className,
1443 LPCSTR windowName, DWORD style, INT x,
1444 INT y, INT width, INT height,
1445 HWND parent, HMENU menu,
1446 HINSTANCE instance, LPVOID data )
1450 cs.lpCreateParams = data;
1451 cs.hInstance = instance;
1453 cs.hwndParent = parent;
1459 cs.lpszName = windowName;
1460 cs.lpszClass = className;
1461 cs.dwExStyle = exStyle;
1463 if (!IS_INTRESOURCE(className))
1466 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, bufferW, sizeof(bufferW)/sizeof(WCHAR) ))
1468 return wow_handlers.create_window( (CREATESTRUCTW *)&cs, bufferW, instance, WIN_ISWIN32 );
1470 /* Note: we rely on the fact that CREATESTRUCTA and */
1471 /* CREATESTRUCTW have the same layout. */
1472 return wow_handlers.create_window( (CREATESTRUCTW *)&cs, (LPCWSTR)className, instance, WIN_ISWIN32 );
1476 /***********************************************************************
1477 * CreateWindowExW (USER32.@)
1479 HWND WINAPI CreateWindowExW( DWORD exStyle, LPCWSTR className,
1480 LPCWSTR windowName, DWORD style, INT x,
1481 INT y, INT width, INT height,
1482 HWND parent, HMENU menu,
1483 HINSTANCE instance, LPVOID data )
1487 cs.lpCreateParams = data;
1488 cs.hInstance = instance;
1490 cs.hwndParent = parent;
1496 cs.lpszName = windowName;
1497 cs.lpszClass = className;
1498 cs.dwExStyle = exStyle;
1500 return wow_handlers.create_window( &cs, className, instance, WIN_ISWIN32 | WIN_ISUNICODE );
1504 /***********************************************************************
1505 * WIN_SendDestroyMsg
1507 static void WIN_SendDestroyMsg( HWND hwnd )
1511 if (GetGUIThreadInfo( GetCurrentThreadId(), &info ))
1513 if (hwnd == info.hwndCaret) DestroyCaret();
1514 if (hwnd == info.hwndActive) WINPOS_ActivateOtherWindow( hwnd );
1518 * Send the WM_DESTROY to the window.
1520 SendMessageW( hwnd, WM_DESTROY, 0, 0);
1523 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1524 * make sure that the window still exists when we come back.
1531 if (!(pWndArray = WIN_ListChildren( hwnd ))) return;
1533 for (i = 0; pWndArray[i]; i++)
1535 if (IsWindow( pWndArray[i] )) WIN_SendDestroyMsg( pWndArray[i] );
1537 HeapFree( GetProcessHeap(), 0, pWndArray );
1540 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1544 /***********************************************************************
1545 * DestroyWindow (USER32.@)
1547 BOOL WINAPI DestroyWindow( HWND hwnd )
1551 if (!(hwnd = WIN_IsCurrentThread( hwnd )) || is_desktop_window( hwnd ))
1553 SetLastError( ERROR_ACCESS_DENIED );
1557 TRACE("(%p)\n", hwnd);
1561 if (HOOK_CallHooks( WH_CBT, HCBT_DESTROYWND, (WPARAM)hwnd, 0, TRUE )) return FALSE;
1563 if (MENU_IsMenuActive() == hwnd)
1566 is_child = (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) != 0;
1570 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1571 send_parent_notify( hwnd, WM_DESTROY );
1573 else if (!GetWindow( hwnd, GW_OWNER ))
1575 HOOK_CallHooks( WH_SHELL, HSHELL_WINDOWDESTROYED, (WPARAM)hwnd, 0L, TRUE );
1576 /* FIXME: clean up palette - see "Internals" p.352 */
1579 if (!IsWindow(hwnd)) return TRUE;
1581 /* Hide the window */
1582 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
1584 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1586 ShowWindow( hwnd, SW_HIDE );
1588 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1589 SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW );
1592 if (!IsWindow(hwnd)) return TRUE;
1594 /* Recursively destroy owned windows */
1601 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1604 for (i = 0; list[i]; i++)
1606 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1607 if (WIN_IsCurrentThread( list[i] ))
1609 DestroyWindow( list[i] );
1613 WIN_SetOwner( list[i], 0 );
1615 HeapFree( GetProcessHeap(), 0, list );
1617 if (!got_one) break;
1621 /* Send destroy messages */
1623 WIN_SendDestroyMsg( hwnd );
1624 if (!IsWindow( hwnd )) return TRUE;
1626 if (GetClipboardOwner() == hwnd)
1627 CLIPBOARD_ReleaseOwner();
1629 /* Destroy the window storage */
1631 WIN_DestroyWindow( hwnd );
1636 /***********************************************************************
1637 * CloseWindow (USER32.@)
1639 BOOL WINAPI CloseWindow( HWND hwnd )
1641 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) return FALSE;
1642 ShowWindow( hwnd, SW_MINIMIZE );
1647 /***********************************************************************
1648 * OpenIcon (USER32.@)
1650 BOOL WINAPI OpenIcon( HWND hwnd )
1652 if (!IsIconic( hwnd )) return FALSE;
1653 ShowWindow( hwnd, SW_SHOWNORMAL );
1658 /***********************************************************************
1659 * FindWindowExW (USER32.@)
1661 HWND WINAPI FindWindowExW( HWND parent, HWND child, LPCWSTR className, LPCWSTR title )
1666 WCHAR *buffer = NULL;
1668 if (!parent && child) parent = GetDesktopWindow();
1669 else if (parent == HWND_MESSAGE) parent = get_hwnd_message_parent();
1673 len = strlenW(title) + 1; /* one extra char to check for chars beyond the end */
1674 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return 0;
1677 if (!(list = list_window_children( 0, parent, className, 0 ))) goto done;
1681 child = WIN_GetFullHandle( child );
1682 while (list[i] && list[i] != child) i++;
1683 if (!list[i]) goto done;
1684 i++; /* start from next window */
1691 if (GetWindowTextW( list[i], buffer, len + 1 ) && !strcmpiW( buffer, title )) break;
1698 HeapFree( GetProcessHeap(), 0, list );
1699 HeapFree( GetProcessHeap(), 0, buffer );
1705 /***********************************************************************
1706 * FindWindowA (USER32.@)
1708 HWND WINAPI FindWindowA( LPCSTR className, LPCSTR title )
1710 HWND ret = FindWindowExA( 0, 0, className, title );
1711 if (!ret) SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1716 /***********************************************************************
1717 * FindWindowExA (USER32.@)
1719 HWND WINAPI FindWindowExA( HWND parent, HWND child, LPCSTR className, LPCSTR title )
1721 LPWSTR titleW = NULL;
1726 DWORD len = MultiByteToWideChar( CP_ACP, 0, title, -1, NULL, 0 );
1727 if (!(titleW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0;
1728 MultiByteToWideChar( CP_ACP, 0, title, -1, titleW, len );
1731 if (!IS_INTRESOURCE(className))
1734 if (MultiByteToWideChar( CP_ACP, 0, className, -1, classW, sizeof(classW)/sizeof(WCHAR) ))
1735 hwnd = FindWindowExW( parent, child, classW, titleW );
1739 hwnd = FindWindowExW( parent, child, (LPCWSTR)className, titleW );
1742 HeapFree( GetProcessHeap(), 0, titleW );
1747 /***********************************************************************
1748 * FindWindowW (USER32.@)
1750 HWND WINAPI FindWindowW( LPCWSTR className, LPCWSTR title )
1752 return FindWindowExW( 0, 0, className, title );
1756 /**********************************************************************
1757 * GetDesktopWindow (USER32.@)
1759 HWND WINAPI GetDesktopWindow(void)
1761 struct user_thread_info *thread_info = get_user_thread_info();
1763 if (thread_info->top_window) return thread_info->top_window;
1765 SERVER_START_REQ( get_desktop_window )
1768 if (!wine_server_call( req ))
1770 thread_info->top_window = wine_server_ptr_handle( reply->top_window );
1771 thread_info->msg_window = wine_server_ptr_handle( reply->msg_window );
1776 if (!thread_info->top_window)
1778 USEROBJECTFLAGS flags;
1779 if (!GetUserObjectInformationW( GetProcessWindowStation(), UOI_FLAGS, &flags,
1780 sizeof(flags), NULL ) || (flags.dwFlags & WSF_VISIBLE))
1782 static const WCHAR explorer[] = {'\\','e','x','p','l','o','r','e','r','.','e','x','e',0};
1783 static const WCHAR args[] = {' ','/','d','e','s','k','t','o','p',0};
1785 PROCESS_INFORMATION pi;
1786 WCHAR windir[MAX_PATH];
1787 WCHAR app[MAX_PATH + sizeof(explorer)/sizeof(WCHAR)];
1788 WCHAR cmdline[MAX_PATH + (sizeof(explorer) + sizeof(args))/sizeof(WCHAR)];
1790 memset( &si, 0, sizeof(si) );
1792 si.dwFlags = STARTF_USESTDHANDLES;
1795 si.hStdError = GetStdHandle( STD_ERROR_HANDLE );
1797 GetWindowsDirectoryW( windir, MAX_PATH );
1798 strcpyW( app, windir );
1799 strcatW( app, explorer );
1800 strcpyW( cmdline, app );
1801 strcatW( cmdline, args );
1802 if (CreateProcessW( app, cmdline, NULL, NULL, FALSE, DETACHED_PROCESS,
1803 NULL, windir, &si, &pi ))
1805 TRACE( "started explorer pid %04x tid %04x\n", pi.dwProcessId, pi.dwThreadId );
1806 WaitForInputIdle( pi.hProcess, 10000 );
1807 CloseHandle( pi.hThread );
1808 CloseHandle( pi.hProcess );
1810 else WARN( "failed to start explorer, err %d\n", GetLastError() );
1812 else TRACE( "not starting explorer since winstation is not visible\n" );
1814 SERVER_START_REQ( get_desktop_window )
1817 if (!wine_server_call( req ))
1819 thread_info->top_window = wine_server_ptr_handle( reply->top_window );
1820 thread_info->msg_window = wine_server_ptr_handle( reply->msg_window );
1826 if (!thread_info->top_window || !USER_Driver->pCreateDesktopWindow( thread_info->top_window ))
1827 ERR( "failed to create desktop window\n" );
1829 return thread_info->top_window;
1833 /*******************************************************************
1834 * EnableWindow (USER32.@)
1836 BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
1841 if (is_broadcast(hwnd))
1843 SetLastError( ERROR_INVALID_PARAMETER );
1847 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
1848 return SendMessageW( hwnd, WM_WINE_ENABLEWINDOW, enable, 0 );
1852 TRACE("( %p, %d )\n", hwnd, enable);
1854 retvalue = !IsWindowEnabled( hwnd );
1856 if (enable && retvalue)
1858 WIN_SetStyle( hwnd, 0, WS_DISABLED );
1859 SendMessageW( hwnd, WM_ENABLE, TRUE, 0 );
1861 else if (!enable && !retvalue)
1865 SendMessageW( hwnd, WM_CANCELMODE, 0, 0);
1867 WIN_SetStyle( hwnd, WS_DISABLED, 0 );
1869 if (hwnd == GetFocus())
1870 SetFocus( 0 ); /* A disabled window can't have the focus */
1872 capture_wnd = GetCapture();
1873 if (hwnd == capture_wnd || IsChild(hwnd, capture_wnd))
1874 ReleaseCapture(); /* A disabled window can't capture the mouse */
1876 SendMessageW( hwnd, WM_ENABLE, FALSE, 0 );
1882 /***********************************************************************
1883 * IsWindowEnabled (USER32.@)
1885 BOOL WINAPI IsWindowEnabled(HWND hWnd)
1887 return !(GetWindowLongW( hWnd, GWL_STYLE ) & WS_DISABLED);
1891 /***********************************************************************
1892 * IsWindowUnicode (USER32.@)
1894 BOOL WINAPI IsWindowUnicode( HWND hwnd )
1897 BOOL retvalue = FALSE;
1899 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1901 if (wndPtr == WND_DESKTOP) return TRUE;
1903 if (wndPtr != WND_OTHER_PROCESS)
1905 retvalue = (wndPtr->flags & WIN_ISUNICODE) != 0;
1906 WIN_ReleasePtr( wndPtr );
1910 SERVER_START_REQ( get_window_info )
1912 req->handle = wine_server_user_handle( hwnd );
1913 if (!wine_server_call_err( req )) retvalue = reply->is_unicode;
1921 /**********************************************************************
1924 * Helper function for GetWindowLong().
1926 static LONG_PTR WIN_GetWindowLong( HWND hwnd, INT offset, UINT size, BOOL unicode )
1928 LONG_PTR retvalue = 0;
1931 if (offset == GWLP_HWNDPARENT)
1933 HWND parent = GetAncestor( hwnd, GA_PARENT );
1934 if (parent == GetDesktopWindow()) parent = GetWindow( hwnd, GW_OWNER );
1935 return (ULONG_PTR)parent;
1938 if (!(wndPtr = WIN_GetPtr( hwnd )))
1940 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1944 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
1946 if (offset == GWLP_WNDPROC)
1948 SetLastError( ERROR_ACCESS_DENIED );
1951 SERVER_START_REQ( set_window_info )
1953 req->handle = wine_server_user_handle( hwnd );
1954 req->flags = 0; /* don't set anything, just retrieve */
1955 req->extra_offset = (offset >= 0) ? offset : -1;
1956 req->extra_size = (offset >= 0) ? size : 0;
1957 if (!wine_server_call_err( req ))
1961 case GWL_STYLE: retvalue = reply->old_style; break;
1962 case GWL_EXSTYLE: retvalue = reply->old_ex_style; break;
1963 case GWLP_ID: retvalue = reply->old_id; break;
1964 case GWLP_HINSTANCE: retvalue = (ULONG_PTR)wine_server_get_ptr( reply->old_instance ); break;
1965 case GWLP_USERDATA: retvalue = reply->old_user_data; break;
1967 if (offset >= 0) retvalue = get_win_data( &reply->old_extra_value, size );
1968 else SetLastError( ERROR_INVALID_INDEX );
1977 /* now we have a valid wndPtr */
1981 if (offset > (int)(wndPtr->cbWndExtra - size))
1983 WARN("Invalid offset %d\n", offset );
1984 WIN_ReleasePtr( wndPtr );
1985 SetLastError( ERROR_INVALID_INDEX );
1988 retvalue = get_win_data( (char *)wndPtr->wExtra + offset, size );
1990 /* Special case for dialog window procedure */
1991 if ((offset == DWLP_DLGPROC) && (size == sizeof(LONG_PTR)) && (wndPtr->flags & WIN_ISDIALOG))
1992 retvalue = (LONG_PTR)WINPROC_GetProc( (WNDPROC)retvalue, unicode );
1993 WIN_ReleasePtr( wndPtr );
1999 case GWLP_USERDATA: retvalue = wndPtr->userdata; break;
2000 case GWL_STYLE: retvalue = wndPtr->dwStyle; break;
2001 case GWL_EXSTYLE: retvalue = wndPtr->dwExStyle; break;
2002 case GWLP_ID: retvalue = wndPtr->wIDmenu; break;
2003 case GWLP_HINSTANCE: retvalue = (ULONG_PTR)wndPtr->hInstance; break;
2005 /* This looks like a hack only for the edit control (see tests). This makes these controls
2006 * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests
2007 * that the hack is in GetWindowLongPtr[AW], not in winprocs.
2009 if (wndPtr->winproc == BUILTIN_WINPROC(WINPROC_EDIT) && (!unicode != !(wndPtr->flags & WIN_ISUNICODE)))
2010 retvalue = (ULONG_PTR)wndPtr->winproc;
2012 retvalue = (ULONG_PTR)WINPROC_GetProc( wndPtr->winproc, unicode );
2015 WARN("Unknown offset %d\n", offset );
2016 SetLastError( ERROR_INVALID_INDEX );
2019 WIN_ReleasePtr(wndPtr);
2024 /**********************************************************************
2027 * Helper function for SetWindowLong().
2029 * 0 is the failure code. However, in the case of failure SetLastError
2030 * must be set to distinguish between a 0 return value and a failure.
2032 LONG_PTR WIN_SetWindowLong( HWND hwnd, INT offset, UINT size, LONG_PTR newval, BOOL unicode )
2036 LONG_PTR retval = 0;
2039 TRACE( "%p %d %lx %c\n", hwnd, offset, newval, unicode ? 'W' : 'A' );
2041 if (is_broadcast(hwnd))
2043 SetLastError( ERROR_INVALID_PARAMETER );
2047 if (!(wndPtr = WIN_GetPtr( hwnd )))
2049 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2052 if (wndPtr == WND_DESKTOP)
2054 /* can't change anything on the desktop window */
2055 SetLastError( ERROR_ACCESS_DENIED );
2058 if (wndPtr == WND_OTHER_PROCESS)
2060 if (offset == GWLP_WNDPROC)
2062 SetLastError( ERROR_ACCESS_DENIED );
2065 if (offset > 32767 || offset < -32767)
2067 SetLastError( ERROR_INVALID_INDEX );
2070 return SendMessageW( hwnd, WM_WINE_SETWINDOWLONG, MAKEWPARAM( offset, size ), newval );
2073 /* first some special cases */
2079 offset == GWL_STYLE ? wndPtr->dwStyle : wndPtr->dwExStyle;
2080 style.styleNew = newval;
2081 WIN_ReleasePtr( wndPtr );
2082 SendMessageW( hwnd, WM_STYLECHANGING, offset, (LPARAM)&style );
2083 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
2084 newval = style.styleNew;
2086 case GWLP_HWNDPARENT:
2087 if (wndPtr->parent == GetDesktopWindow())
2089 WIN_ReleasePtr( wndPtr );
2090 return (ULONG_PTR)WIN_SetOwner( hwnd, (HWND)newval );
2094 WIN_ReleasePtr( wndPtr );
2095 return (ULONG_PTR)SetParent( hwnd, (HWND)newval );
2100 UINT old_flags = wndPtr->flags;
2101 retval = WIN_GetWindowLong( hwnd, offset, size, unicode );
2102 proc = WINPROC_AllocProc( (WNDPROC)newval, unicode );
2103 if (proc) wndPtr->winproc = proc;
2104 if (WINPROC_IsUnicode( proc, unicode )) wndPtr->flags |= WIN_ISUNICODE;
2105 else wndPtr->flags &= ~WIN_ISUNICODE;
2106 if (!((old_flags ^ wndPtr->flags) & WIN_ISUNICODE))
2108 WIN_ReleasePtr( wndPtr );
2111 /* update is_unicode flag on the server side */
2115 case GWLP_HINSTANCE:
2119 if ((wndPtr->cbWndExtra - sizeof(LONG_PTR) >= DWLP_DLGPROC) &&
2120 (size == sizeof(LONG_PTR)) && (wndPtr->flags & WIN_ISDIALOG))
2122 WNDPROC *ptr = (WNDPROC *)((char *)wndPtr->wExtra + DWLP_DLGPROC);
2123 retval = (ULONG_PTR)WINPROC_GetProc( *ptr, unicode );
2124 *ptr = WINPROC_AllocProc( (WNDPROC)newval, unicode );
2125 WIN_ReleasePtr( wndPtr );
2130 if (offset < 0 || offset > (int)(wndPtr->cbWndExtra - size))
2132 WARN("Invalid offset %d\n", offset );
2133 WIN_ReleasePtr( wndPtr );
2134 SetLastError( ERROR_INVALID_INDEX );
2137 else if (get_win_data( (char *)wndPtr->wExtra + offset, size ) == newval)
2139 /* already set to the same value */
2140 WIN_ReleasePtr( wndPtr );
2146 SERVER_START_REQ( set_window_info )
2148 req->handle = wine_server_user_handle( hwnd );
2149 req->extra_offset = -1;
2153 req->flags = SET_WIN_STYLE;
2154 req->style = newval;
2157 req->flags = SET_WIN_EXSTYLE;
2158 /* WS_EX_TOPMOST can only be changed through SetWindowPos */
2159 newval = (newval & ~WS_EX_TOPMOST) | (wndPtr->dwExStyle & WS_EX_TOPMOST);
2160 req->ex_style = newval;
2163 req->flags = SET_WIN_ID;
2166 case GWLP_HINSTANCE:
2167 req->flags = SET_WIN_INSTANCE;
2168 req->instance = wine_server_client_ptr( (void *)newval );
2171 req->flags = SET_WIN_UNICODE;
2172 req->is_unicode = (wndPtr->flags & WIN_ISUNICODE) != 0;
2175 req->flags = SET_WIN_USERDATA;
2176 req->user_data = newval;
2179 req->flags = SET_WIN_EXTRA;
2180 req->extra_offset = offset;
2181 req->extra_size = size;
2182 set_win_data( &req->extra_value, newval, size );
2184 if ((ok = !wine_server_call_err( req )))
2189 wndPtr->dwStyle = newval;
2190 retval = reply->old_style;
2193 wndPtr->dwExStyle = newval;
2194 retval = reply->old_ex_style;
2197 wndPtr->wIDmenu = newval;
2198 retval = reply->old_id;
2200 case GWLP_HINSTANCE:
2201 wndPtr->hInstance = (HINSTANCE)newval;
2202 retval = (ULONG_PTR)wine_server_get_ptr( reply->old_instance );
2207 wndPtr->userdata = newval;
2208 retval = reply->old_user_data;
2211 retval = get_win_data( (char *)wndPtr->wExtra + offset, size );
2212 set_win_data( (char *)wndPtr->wExtra + offset, newval, size );
2218 WIN_ReleasePtr( wndPtr );
2222 if (offset == GWL_STYLE || offset == GWL_EXSTYLE)
2224 USER_Driver->pSetWindowStyle( hwnd, offset, &style );
2225 SendMessageW( hwnd, WM_STYLECHANGED, offset, (LPARAM)&style );
2232 /**********************************************************************
2233 * GetWindowWord (USER32.@)
2235 WORD WINAPI GetWindowWord( HWND hwnd, INT offset )
2240 case GWLP_HINSTANCE:
2241 case GWLP_HWNDPARENT:
2246 WARN("Invalid offset %d\n", offset );
2247 SetLastError( ERROR_INVALID_INDEX );
2252 return WIN_GetWindowLong( hwnd, offset, sizeof(WORD), FALSE );
2256 /**********************************************************************
2257 * GetWindowLongA (USER32.@)
2259 LONG WINAPI GetWindowLongA( HWND hwnd, INT offset )
2261 return WIN_GetWindowLong( hwnd, offset, sizeof(LONG), FALSE );
2265 /**********************************************************************
2266 * GetWindowLongW (USER32.@)
2268 LONG WINAPI GetWindowLongW( HWND hwnd, INT offset )
2270 return WIN_GetWindowLong( hwnd, offset, sizeof(LONG), TRUE );
2274 /**********************************************************************
2275 * SetWindowWord (USER32.@)
2277 WORD WINAPI SetWindowWord( HWND hwnd, INT offset, WORD newval )
2282 case GWLP_HINSTANCE:
2283 case GWLP_HWNDPARENT:
2288 WARN("Invalid offset %d\n", offset );
2289 SetLastError( ERROR_INVALID_INDEX );
2294 return WIN_SetWindowLong( hwnd, offset, sizeof(WORD), newval, FALSE );
2298 /**********************************************************************
2299 * SetWindowLongA (USER32.@)
2301 * See SetWindowLongW.
2303 LONG WINAPI SetWindowLongA( HWND hwnd, INT offset, LONG newval )
2305 return WIN_SetWindowLong( hwnd, offset, sizeof(LONG), newval, FALSE );
2309 /**********************************************************************
2310 * SetWindowLongW (USER32.@) Set window attribute
2312 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2313 * value in a window's extra memory.
2315 * The _hwnd_ parameter specifies the window. is the handle to a
2316 * window that has extra memory. The _newval_ parameter contains the
2317 * new attribute or extra memory value. If positive, the _offset_
2318 * parameter is the byte-addressed location in the window's extra
2319 * memory to set. If negative, _offset_ specifies the window
2320 * attribute to set, and should be one of the following values:
2322 * GWL_EXSTYLE The window's extended window style
2324 * GWL_STYLE The window's window style.
2326 * GWLP_WNDPROC Pointer to the window's window procedure.
2328 * GWLP_HINSTANCE The window's pplication instance handle.
2330 * GWLP_ID The window's identifier.
2332 * GWLP_USERDATA The window's user-specified data.
2334 * If the window is a dialog box, the _offset_ parameter can be one of
2335 * the following values:
2337 * DWLP_DLGPROC The address of the window's dialog box procedure.
2339 * DWLP_MSGRESULT The return value of a message
2340 * that the dialog box procedure processed.
2342 * DWLP_USER Application specific information.
2346 * If successful, returns the previous value located at _offset_. Otherwise,
2351 * Extra memory for a window class is specified by a nonzero cbWndExtra
2352 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2353 * time of class creation.
2355 * Using GWL_WNDPROC to set a new window procedure effectively creates
2356 * a window subclass. Use CallWindowProc() in the new windows procedure
2357 * to pass messages to the superclass's window procedure.
2359 * The user data is reserved for use by the application which created
2362 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2363 * instead, call the EnableWindow() function to change the window's
2366 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2367 * SetParent() instead.
2370 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2371 * it sends WM_STYLECHANGING before changing the settings
2372 * and WM_STYLECHANGED afterwards.
2373 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2375 LONG WINAPI SetWindowLongW(
2376 HWND hwnd, /* [in] window to alter */
2377 INT offset, /* [in] offset, in bytes, of location to alter */
2378 LONG newval /* [in] new value of location */
2380 return WIN_SetWindowLong( hwnd, offset, sizeof(LONG), newval, TRUE );
2384 /*******************************************************************
2385 * GetWindowTextA (USER32.@)
2387 INT WINAPI GetWindowTextA( HWND hwnd, LPSTR lpString, INT nMaxCount )
2391 if (!lpString) return 0;
2393 if (WIN_IsCurrentProcess( hwnd ))
2394 return (INT)SendMessageA( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
2396 /* when window belongs to other process, don't send a message */
2397 if (nMaxCount <= 0) return 0;
2398 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, nMaxCount * sizeof(WCHAR) ))) return 0;
2399 get_server_window_text( hwnd, buffer, nMaxCount );
2400 if (!WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpString, nMaxCount, NULL, NULL ))
2401 lpString[nMaxCount-1] = 0;
2402 HeapFree( GetProcessHeap(), 0, buffer );
2403 return strlen(lpString);
2407 /*******************************************************************
2408 * InternalGetWindowText (USER32.@)
2410 INT WINAPI InternalGetWindowText(HWND hwnd,LPWSTR lpString,INT nMaxCount )
2414 if (nMaxCount <= 0) return 0;
2415 if (!(win = WIN_GetPtr( hwnd ))) return 0;
2416 if (win == WND_DESKTOP) lpString[0] = 0;
2417 else if (win != WND_OTHER_PROCESS)
2419 if (win->text) lstrcpynW( lpString, win->text, nMaxCount );
2420 else lpString[0] = 0;
2421 WIN_ReleasePtr( win );
2425 get_server_window_text( hwnd, lpString, nMaxCount );
2427 return strlenW(lpString);
2431 /*******************************************************************
2432 * GetWindowTextW (USER32.@)
2434 INT WINAPI GetWindowTextW( HWND hwnd, LPWSTR lpString, INT nMaxCount )
2436 if (!lpString) return 0;
2438 if (WIN_IsCurrentProcess( hwnd ))
2439 return (INT)SendMessageW( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
2441 /* when window belongs to other process, don't send a message */
2442 if (nMaxCount <= 0) return 0;
2443 get_server_window_text( hwnd, lpString, nMaxCount );
2444 return strlenW(lpString);
2448 /*******************************************************************
2449 * SetWindowTextA (USER32.@)
2450 * SetWindowText (USER32.@)
2452 BOOL WINAPI SetWindowTextA( HWND hwnd, LPCSTR lpString )
2454 if (is_broadcast(hwnd))
2456 SetLastError( ERROR_INVALID_PARAMETER );
2459 if (!WIN_IsCurrentProcess( hwnd ))
2460 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2461 debugstr_a(lpString), hwnd );
2462 return (BOOL)SendMessageA( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
2466 /*******************************************************************
2467 * SetWindowTextW (USER32.@)
2469 BOOL WINAPI SetWindowTextW( HWND hwnd, LPCWSTR lpString )
2471 if (is_broadcast(hwnd))
2473 SetLastError( ERROR_INVALID_PARAMETER );
2476 if (!WIN_IsCurrentProcess( hwnd ))
2477 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2478 debugstr_w(lpString), hwnd );
2479 return (BOOL)SendMessageW( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
2483 /*******************************************************************
2484 * GetWindowTextLengthA (USER32.@)
2486 INT WINAPI GetWindowTextLengthA( HWND hwnd )
2488 return SendMessageA( hwnd, WM_GETTEXTLENGTH, 0, 0 );
2491 /*******************************************************************
2492 * GetWindowTextLengthW (USER32.@)
2494 INT WINAPI GetWindowTextLengthW( HWND hwnd )
2496 return SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 );
2500 /*******************************************************************
2501 * IsWindow (USER32.@)
2503 BOOL WINAPI IsWindow( HWND hwnd )
2508 if (!(ptr = WIN_GetPtr( hwnd ))) return FALSE;
2509 if (ptr == WND_DESKTOP) return TRUE;
2511 if (ptr != WND_OTHER_PROCESS)
2513 WIN_ReleasePtr( ptr );
2517 /* check other processes */
2518 SERVER_START_REQ( get_window_info )
2520 req->handle = wine_server_user_handle( hwnd );
2521 ret = !wine_server_call_err( req );
2528 /***********************************************************************
2529 * GetWindowThreadProcessId (USER32.@)
2531 DWORD WINAPI GetWindowThreadProcessId( HWND hwnd, LPDWORD process )
2536 if (!(ptr = WIN_GetPtr( hwnd )))
2538 SetLastError( ERROR_INVALID_WINDOW_HANDLE);
2542 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP)
2544 /* got a valid window */
2546 if (process) *process = GetCurrentProcessId();
2547 WIN_ReleasePtr( ptr );
2551 /* check other processes */
2552 SERVER_START_REQ( get_window_info )
2554 req->handle = wine_server_user_handle( hwnd );
2555 if (!wine_server_call_err( req ))
2557 tid = (DWORD)reply->tid;
2558 if (process) *process = (DWORD)reply->pid;
2566 /*****************************************************************
2567 * GetParent (USER32.@)
2569 HWND WINAPI GetParent( HWND hwnd )
2574 if (!(wndPtr = WIN_GetPtr( hwnd )))
2576 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2579 if (wndPtr == WND_DESKTOP) return 0;
2580 if (wndPtr == WND_OTHER_PROCESS)
2582 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2583 if (style & (WS_POPUP | WS_CHILD))
2585 SERVER_START_REQ( get_window_tree )
2587 req->handle = wine_server_user_handle( hwnd );
2588 if (!wine_server_call_err( req ))
2590 if (style & WS_POPUP) retvalue = wine_server_ptr_handle( reply->owner );
2591 else if (style & WS_CHILD) retvalue = wine_server_ptr_handle( reply->parent );
2599 if (wndPtr->dwStyle & WS_POPUP) retvalue = wndPtr->owner;
2600 else if (wndPtr->dwStyle & WS_CHILD) retvalue = wndPtr->parent;
2601 WIN_ReleasePtr( wndPtr );
2607 /*****************************************************************
2608 * GetAncestor (USER32.@)
2610 HWND WINAPI GetAncestor( HWND hwnd, UINT type )
2613 HWND *list, ret = 0;
2618 if (!(win = WIN_GetPtr( hwnd )))
2620 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2623 if (win == WND_DESKTOP) return 0;
2624 if (win != WND_OTHER_PROCESS)
2627 WIN_ReleasePtr( win );
2629 else /* need to query the server */
2631 SERVER_START_REQ( get_window_tree )
2633 req->handle = wine_server_user_handle( hwnd );
2634 if (!wine_server_call_err( req )) ret = wine_server_ptr_handle( reply->parent );
2641 if (!(list = list_window_parents( hwnd ))) return 0;
2643 if (!list[0] || !list[1]) ret = WIN_GetFullHandle( hwnd ); /* top-level window */
2647 while (list[count]) count++;
2648 ret = list[count - 2]; /* get the one before the desktop */
2650 HeapFree( GetProcessHeap(), 0, list );
2654 if (is_desktop_window( hwnd )) return 0;
2655 ret = WIN_GetFullHandle( hwnd );
2658 HWND parent = GetParent( ret );
2668 /*****************************************************************
2669 * SetParent (USER32.@)
2671 HWND WINAPI SetParent( HWND hwnd, HWND parent )
2674 HWND old_parent = 0;
2679 if (is_broadcast(hwnd) || is_broadcast(parent))
2681 SetLastError(ERROR_INVALID_PARAMETER);
2685 if (!parent) parent = GetDesktopWindow();
2686 else if (parent == HWND_MESSAGE) parent = get_hwnd_message_parent();
2687 else parent = WIN_GetFullHandle( parent );
2689 if (!IsWindow( parent ))
2691 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2695 /* Some applications try to set a child as a parent */
2696 if (IsChild(hwnd, parent))
2698 SetLastError( ERROR_INVALID_PARAMETER );
2702 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
2703 return (HWND)SendMessageW( hwnd, WM_WINE_SETPARENT, (WPARAM)parent, 0 );
2705 /* Windows hides the window first, then shows it again
2706 * including the WM_SHOWWINDOW messages and all */
2707 was_visible = ShowWindow( hwnd, SW_HIDE );
2709 wndPtr = WIN_GetPtr( hwnd );
2710 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return 0;
2712 SERVER_START_REQ( set_parent )
2714 req->handle = wine_server_user_handle( hwnd );
2715 req->parent = wine_server_user_handle( parent );
2716 if ((ret = !wine_server_call( req )))
2718 old_parent = wine_server_ptr_handle( reply->old_parent );
2719 wndPtr->parent = parent = wine_server_ptr_handle( reply->full_parent );
2724 WIN_ReleasePtr( wndPtr );
2727 USER_Driver->pSetParent( full_handle, parent, old_parent );
2729 /* SetParent additionally needs to make hwnd the topmost window
2730 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2731 WM_WINDOWPOSCHANGED notification messages.
2733 SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0,
2734 SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOSIZE | (was_visible ? SWP_SHOWWINDOW : 0) );
2735 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2736 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2742 /*******************************************************************
2743 * IsChild (USER32.@)
2745 BOOL WINAPI IsChild( HWND parent, HWND child )
2747 HWND *list = list_window_parents( child );
2751 if (!list) return FALSE;
2752 parent = WIN_GetFullHandle( parent );
2753 for (i = 0; list[i]; i++) if (list[i] == parent) break;
2754 ret = list[i] && list[i+1];
2755 HeapFree( GetProcessHeap(), 0, list );
2760 /***********************************************************************
2761 * IsWindowVisible (USER32.@)
2763 BOOL WINAPI IsWindowVisible( HWND hwnd )
2769 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) return FALSE;
2770 if (!(list = list_window_parents( hwnd ))) return TRUE;
2773 for (i = 0; list[i+1]; i++)
2774 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) break;
2775 retval = !list[i+1] && (list[i] == GetDesktopWindow()); /* top message window isn't visible */
2777 HeapFree( GetProcessHeap(), 0, list );
2782 /***********************************************************************
2783 * WIN_IsWindowDrawable
2785 * hwnd is drawable when it is visible, all parents are not
2786 * minimized, and it is itself not minimized unless we are
2787 * trying to draw its default class icon.
2789 BOOL WIN_IsWindowDrawable( HWND hwnd, BOOL icon )
2794 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2796 if (!(style & WS_VISIBLE)) return FALSE;
2797 if ((style & WS_MINIMIZE) && icon && GetClassLongPtrW( hwnd, GCLP_HICON )) return FALSE;
2799 if (!(list = list_window_parents( hwnd ))) return TRUE;
2802 for (i = 0; list[i+1]; i++)
2803 if ((GetWindowLongW( list[i], GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != WS_VISIBLE)
2805 retval = !list[i+1] && (list[i] == GetDesktopWindow()); /* top message window isn't visible */
2807 HeapFree( GetProcessHeap(), 0, list );
2812 /*******************************************************************
2813 * GetTopWindow (USER32.@)
2815 HWND WINAPI GetTopWindow( HWND hwnd )
2817 if (!hwnd) hwnd = GetDesktopWindow();
2818 return GetWindow( hwnd, GW_CHILD );
2822 /*******************************************************************
2823 * GetWindow (USER32.@)
2825 HWND WINAPI GetWindow( HWND hwnd, UINT rel )
2829 if (rel == GW_OWNER) /* this one may be available locally */
2831 WND *wndPtr = WIN_GetPtr( hwnd );
2834 SetLastError( ERROR_INVALID_HANDLE );
2837 if (wndPtr == WND_DESKTOP) return 0;
2838 if (wndPtr != WND_OTHER_PROCESS)
2840 retval = wndPtr->owner;
2841 WIN_ReleasePtr( wndPtr );
2844 /* else fall through to server call */
2847 SERVER_START_REQ( get_window_tree )
2849 req->handle = wine_server_user_handle( hwnd );
2850 if (!wine_server_call_err( req ))
2855 retval = wine_server_ptr_handle( reply->first_sibling );
2858 retval = wine_server_ptr_handle( reply->last_sibling );
2861 retval = wine_server_ptr_handle( reply->next_sibling );
2864 retval = wine_server_ptr_handle( reply->prev_sibling );
2867 retval = wine_server_ptr_handle( reply->owner );
2870 retval = wine_server_ptr_handle( reply->first_child );
2880 /*******************************************************************
2881 * ShowOwnedPopups (USER32.@)
2883 BOOL WINAPI ShowOwnedPopups( HWND owner, BOOL fShow )
2887 HWND *win_array = WIN_ListChildren( GetDesktopWindow() );
2889 if (!win_array) return TRUE;
2891 while (win_array[count]) count++;
2892 while (--count >= 0)
2894 if (GetWindow( win_array[count], GW_OWNER ) != owner) continue;
2895 if (!(pWnd = WIN_GetPtr( win_array[count] ))) continue;
2896 if (pWnd == WND_OTHER_PROCESS) continue;
2899 if (pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP)
2901 WIN_ReleasePtr( pWnd );
2902 /* In Windows, ShowOwnedPopups(TRUE) generates
2903 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
2904 * regardless of the state of the owner
2906 SendMessageW(win_array[count], WM_SHOWWINDOW, SW_SHOWNORMAL, SW_PARENTOPENING);
2912 if (pWnd->dwStyle & WS_VISIBLE)
2914 WIN_ReleasePtr( pWnd );
2915 /* In Windows, ShowOwnedPopups(FALSE) generates
2916 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
2917 * regardless of the state of the owner
2919 SendMessageW(win_array[count], WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
2923 WIN_ReleasePtr( pWnd );
2925 HeapFree( GetProcessHeap(), 0, win_array );
2930 /*******************************************************************
2931 * GetLastActivePopup (USER32.@)
2933 HWND WINAPI GetLastActivePopup( HWND hwnd )
2937 SERVER_START_REQ( get_window_info )
2939 req->handle = wine_server_user_handle( hwnd );
2940 if (!wine_server_call_err( req )) retval = wine_server_ptr_handle( reply->last_active );
2947 /*******************************************************************
2950 * Build an array of the children of a given window. The array must be
2951 * freed with HeapFree. Returns NULL when no windows are found.
2953 HWND *WIN_ListChildren( HWND hwnd )
2957 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2960 return list_window_children( 0, hwnd, NULL, 0 );
2964 /*******************************************************************
2965 * EnumWindows (USER32.@)
2967 BOOL WINAPI EnumWindows( WNDENUMPROC lpEnumFunc, LPARAM lParam )
2973 USER_CheckNotLock();
2975 /* We have to build a list of all windows first, to avoid */
2976 /* unpleasant side-effects, for instance if the callback */
2977 /* function changes the Z-order of the windows. */
2979 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return TRUE;
2981 /* Now call the callback function for every window */
2983 for (i = 0; list[i]; i++)
2985 /* Make sure that the window still exists */
2986 if (!IsWindow( list[i] )) continue;
2987 if (!(ret = lpEnumFunc( list[i], lParam ))) break;
2989 HeapFree( GetProcessHeap(), 0, list );
2994 /**********************************************************************
2995 * EnumThreadWindows (USER32.@)
2997 BOOL WINAPI EnumThreadWindows( DWORD id, WNDENUMPROC func, LPARAM lParam )
3003 USER_CheckNotLock();
3005 if (!(list = list_window_children( 0, GetDesktopWindow(), NULL, id ))) return TRUE;
3007 /* Now call the callback function for every window */
3009 for (i = 0; list[i]; i++)
3010 if (!(ret = func( list[i], lParam ))) break;
3011 HeapFree( GetProcessHeap(), 0, list );
3016 /***********************************************************************
3017 * EnumDesktopWindows (USER32.@)
3019 BOOL WINAPI EnumDesktopWindows( HDESK desktop, WNDENUMPROC func, LPARAM lparam )
3024 USER_CheckNotLock();
3026 if (!(list = list_window_children( desktop, 0, NULL, 0 ))) return TRUE;
3028 for (i = 0; list[i]; i++)
3029 if (!func( list[i], lparam )) break;
3030 HeapFree( GetProcessHeap(), 0, list );
3035 /**********************************************************************
3036 * WIN_EnumChildWindows
3038 * Helper function for EnumChildWindows().
3040 static BOOL WIN_EnumChildWindows( HWND *list, WNDENUMPROC func, LPARAM lParam )
3045 for ( ; *list; list++)
3047 /* Make sure that the window still exists */
3048 if (!IsWindow( *list )) continue;
3049 /* Build children list first */
3050 childList = WIN_ListChildren( *list );
3052 ret = func( *list, lParam );
3056 if (ret) ret = WIN_EnumChildWindows( childList, func, lParam );
3057 HeapFree( GetProcessHeap(), 0, childList );
3059 if (!ret) return FALSE;
3065 /**********************************************************************
3066 * EnumChildWindows (USER32.@)
3068 BOOL WINAPI EnumChildWindows( HWND parent, WNDENUMPROC func, LPARAM lParam )
3073 USER_CheckNotLock();
3075 if (!(list = WIN_ListChildren( parent ))) return FALSE;
3076 ret = WIN_EnumChildWindows( list, func, lParam );
3077 HeapFree( GetProcessHeap(), 0, list );
3082 /*******************************************************************
3083 * AnyPopup (USER32.@)
3085 BOOL WINAPI AnyPopup(void)
3089 HWND *list = WIN_ListChildren( GetDesktopWindow() );
3091 if (!list) return FALSE;
3092 for (i = 0; list[i]; i++)
3094 if (IsWindowVisible( list[i] ) && GetWindow( list[i], GW_OWNER )) break;
3096 retvalue = (list[i] != 0);
3097 HeapFree( GetProcessHeap(), 0, list );
3102 /*******************************************************************
3103 * FlashWindow (USER32.@)
3105 BOOL WINAPI FlashWindow( HWND hWnd, BOOL bInvert )
3109 TRACE("%p\n", hWnd);
3111 if (IsIconic( hWnd ))
3113 RedrawWindow( hWnd, 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_FRAME );
3115 wndPtr = WIN_GetPtr(hWnd);
3116 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
3117 if (bInvert && !(wndPtr->flags & WIN_NCACTIVATED))
3119 wndPtr->flags |= WIN_NCACTIVATED;
3123 wndPtr->flags &= ~WIN_NCACTIVATED;
3125 WIN_ReleasePtr( wndPtr );
3132 wndPtr = WIN_GetPtr(hWnd);
3133 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
3134 hWnd = wndPtr->obj.handle; /* make it a full handle */
3136 if (bInvert) wparam = !(wndPtr->flags & WIN_NCACTIVATED);
3137 else wparam = (hWnd == GetForegroundWindow());
3139 WIN_ReleasePtr( wndPtr );
3140 SendMessageW( hWnd, WM_NCACTIVATE, wparam, 0 );
3145 /*******************************************************************
3146 * FlashWindowEx (USER32.@)
3148 BOOL WINAPI FlashWindowEx( PFLASHWINFO pfwi )
3150 FIXME("%p\n", pfwi);
3154 /*******************************************************************
3155 * GetWindowContextHelpId (USER32.@)
3157 DWORD WINAPI GetWindowContextHelpId( HWND hwnd )
3160 WND *wnd = WIN_GetPtr( hwnd );
3161 if (!wnd || wnd == WND_DESKTOP) return 0;
3162 if (wnd == WND_OTHER_PROCESS)
3164 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
3167 retval = wnd->helpContext;
3168 WIN_ReleasePtr( wnd );
3173 /*******************************************************************
3174 * SetWindowContextHelpId (USER32.@)
3176 BOOL WINAPI SetWindowContextHelpId( HWND hwnd, DWORD id )
3178 WND *wnd = WIN_GetPtr( hwnd );
3179 if (!wnd || wnd == WND_DESKTOP) return FALSE;
3180 if (wnd == WND_OTHER_PROCESS)
3182 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
3185 wnd->helpContext = id;
3186 WIN_ReleasePtr( wnd );
3191 /*******************************************************************
3192 * DragDetect (USER32.@)
3194 BOOL WINAPI DragDetect( HWND hWnd, POINT pt )
3198 WORD wDragWidth = GetSystemMetrics(SM_CXDRAG);
3199 WORD wDragHeight= GetSystemMetrics(SM_CYDRAG);
3201 rect.left = pt.x - wDragWidth;
3202 rect.right = pt.x + wDragWidth;
3204 rect.top = pt.y - wDragHeight;
3205 rect.bottom = pt.y + wDragHeight;
3211 while (PeekMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ))
3213 if( msg.message == WM_LBUTTONUP )
3218 if( msg.message == WM_MOUSEMOVE )
3221 tmp.x = (short)LOWORD(msg.lParam);
3222 tmp.y = (short)HIWORD(msg.lParam);
3223 if( !PtInRect( &rect, tmp ))
3235 /******************************************************************************
3236 * GetWindowModuleFileNameA (USER32.@)
3238 UINT WINAPI GetWindowModuleFileNameA( HWND hwnd, LPSTR module, UINT size )
3243 TRACE( "%p, %p, %u\n", hwnd, module, size );
3245 win = WIN_GetPtr( hwnd );
3246 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP)
3248 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3251 hinst = win->hInstance;
3252 WIN_ReleasePtr( win );
3254 return GetModuleFileNameA( hinst, module, size );
3257 /******************************************************************************
3258 * GetWindowModuleFileNameW (USER32.@)
3260 UINT WINAPI GetWindowModuleFileNameW( HWND hwnd, LPWSTR module, UINT size )
3265 TRACE( "%p, %p, %u\n", hwnd, module, size );
3267 win = WIN_GetPtr( hwnd );
3268 if (!win || win == WND_OTHER_PROCESS || win == WND_DESKTOP)
3270 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
3273 hinst = win->hInstance;
3274 WIN_ReleasePtr( win );
3276 return GetModuleFileNameW( hinst, module, size );
3279 /******************************************************************************
3280 * GetWindowInfo (USER32.@)
3282 * Note: tests show that Windows doesn't check cbSize of the structure.
3284 BOOL WINAPI GetWindowInfo( HWND hwnd, PWINDOWINFO pwi)
3286 if (!pwi) return FALSE;
3287 if (!IsWindow(hwnd)) return FALSE;
3289 GetWindowRect(hwnd, &pwi->rcWindow);
3290 GetClientRect(hwnd, &pwi->rcClient);
3291 /* translate to screen coordinates */
3292 MapWindowPoints(hwnd, 0, (LPPOINT)&pwi->rcClient, 2);
3294 pwi->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
3295 pwi->dwExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
3296 pwi->dwWindowStatus = ((GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0);
3298 pwi->cxWindowBorders = pwi->rcClient.left - pwi->rcWindow.left;
3299 pwi->cyWindowBorders = pwi->rcWindow.bottom - pwi->rcClient.bottom;
3301 pwi->atomWindowType = GetClassLongW( hwnd, GCW_ATOM );
3302 pwi->wCreatorVersion = 0x0400;
3307 /******************************************************************************
3308 * SwitchDesktop (USER32.@)
3310 * NOTES: Sets the current input or interactive desktop.
3312 BOOL WINAPI SwitchDesktop( HDESK hDesktop)
3314 FIXME("SwitchDesktop(hwnd %p) stub!\n", hDesktop);
3318 /*****************************************************************************
3319 * SetLayeredWindowAttributes (USER32.@)
3321 BOOL WINAPI SetLayeredWindowAttributes( HWND hwnd, COLORREF key, BYTE alpha, DWORD flags )
3325 TRACE("(%p,%08x,%d,%x): stub!\n", hwnd, key, alpha, flags);
3327 SERVER_START_REQ( set_window_layered_info )
3329 req->handle = wine_server_user_handle( hwnd );
3330 req->color_key = key;
3333 ret = !wine_server_call_err( req );
3337 if (ret) USER_Driver->pSetLayeredWindowAttributes( hwnd, key, alpha, flags );
3343 /*****************************************************************************
3344 * GetLayeredWindowAttributes (USER32.@)
3346 BOOL WINAPI GetLayeredWindowAttributes( HWND hwnd, COLORREF *key, BYTE *alpha, DWORD *flags )
3350 SERVER_START_REQ( get_window_layered_info )
3352 req->handle = wine_server_user_handle( hwnd );
3353 if ((ret = !wine_server_call_err( req )))
3355 if (key) *key = reply->color_key;
3356 if (alpha) *alpha = reply->alpha;
3357 if (flags) *flags = reply->flags;
3366 /*****************************************************************************
3367 * UpdateLayeredWindowIndirect (USER32.@)
3369 BOOL WINAPI UpdateLayeredWindowIndirect( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info )
3373 if (!(info->dwFlags & ULW_EX_NORESIZE) && (info->pptDst || info->psize))
3375 int x = 0, y = 0, cx = 0, cy = 0;
3376 DWORD flags = SWP_NOSIZE | SWP_NOMOVE | SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOREDRAW | SWP_NOSENDCHANGING;
3380 x = info->pptDst->x;
3381 y = info->pptDst->y;
3382 flags &= ~SWP_NOMOVE;
3386 cx = info->psize->cx;
3387 cy = info->psize->cy;
3388 flags &= ~SWP_NOSIZE;
3390 TRACE( "moving window %p pos %d,%d %dx%x\n", hwnd, x, y, cx, cy );
3391 SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
3397 HDC hdc = GetDCEx( hwnd, 0, DCX_CACHE );
3403 GetClientRect( hwnd, &rect );
3406 x = info->pptSrc->x;
3407 y = info->pptSrc->y;
3409 /* FIXME: intersect rect with info->prcDirty */
3410 TRACE( "copying window %p pos %d,%d\n", hwnd, x, y );
3411 BitBlt( hdc, rect.left, rect.top, rect.right, rect.bottom,
3412 info->hdcSrc, rect.left + x, rect.top + y, SRCCOPY );
3413 ReleaseDC( hwnd, hdc );
3417 if (info->pblend && !(info->dwFlags & ULW_OPAQUE)) alpha = info->pblend->SourceConstantAlpha;
3418 TRACE( "setting window %p alpha %u\n", hwnd, alpha );
3419 USER_Driver->pSetLayeredWindowAttributes( hwnd, info->crKey, alpha,
3420 info->dwFlags & (LWA_ALPHA | LWA_COLORKEY) );
3425 /*****************************************************************************
3426 * UpdateLayeredWindow (USER32.@)
3428 BOOL WINAPI UpdateLayeredWindow( HWND hwnd, HDC hdcDst, POINT *pptDst, SIZE *psize,
3429 HDC hdcSrc, POINT *pptSrc, COLORREF crKey, BLENDFUNCTION *pblend,
3432 UPDATELAYEREDWINDOWINFO info;
3434 info.cbSize = sizeof(info);
3435 info.hdcDst = hdcDst;
3436 info.pptDst = pptDst;
3438 info.hdcSrc = hdcSrc;
3439 info.pptSrc = pptSrc;
3441 info.pblend = pblend;
3442 info.dwFlags = dwFlags;
3443 info.prcDirty = NULL;
3444 return UpdateLayeredWindowIndirect( hwnd, &info );
3447 /* 64bit versions */
3449 #ifdef GetWindowLongPtrW
3450 #undef GetWindowLongPtrW
3453 #ifdef GetWindowLongPtrA
3454 #undef GetWindowLongPtrA
3457 #ifdef SetWindowLongPtrW
3458 #undef SetWindowLongPtrW
3461 #ifdef SetWindowLongPtrA
3462 #undef SetWindowLongPtrA
3465 /*****************************************************************************
3466 * GetWindowLongPtrW (USER32.@)
3468 LONG_PTR WINAPI GetWindowLongPtrW( HWND hwnd, INT offset )
3470 return WIN_GetWindowLong( hwnd, offset, sizeof(LONG_PTR), TRUE );
3473 /*****************************************************************************
3474 * GetWindowLongPtrA (USER32.@)
3476 LONG_PTR WINAPI GetWindowLongPtrA( HWND hwnd, INT offset )
3478 return WIN_GetWindowLong( hwnd, offset, sizeof(LONG_PTR), FALSE );
3481 /*****************************************************************************
3482 * SetWindowLongPtrW (USER32.@)
3484 LONG_PTR WINAPI SetWindowLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
3486 return WIN_SetWindowLong( hwnd, offset, sizeof(LONG_PTR), newval, TRUE );
3489 /*****************************************************************************
3490 * SetWindowLongPtrA (USER32.@)
3492 LONG_PTR WINAPI SetWindowLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
3494 return WIN_SetWindowLong( hwnd, offset, sizeof(LONG_PTR), newval, FALSE );