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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "wine/port.h"
30 #include "wine/winbase16.h"
31 #include "wine/winuser16.h"
33 #include "wine/server.h"
34 #include "wine/unicode.h"
36 #include "user_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win);
43 WINE_DECLARE_DEBUG_CHANNEL(msg);
45 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
46 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
48 /**********************************************************************/
51 static HWND hwndDesktop;
53 static WORD wDragWidth = 4;
54 static WORD wDragHeight= 3;
56 static void *user_handles[NB_USER_HANDLES];
58 /***********************************************************************
59 * create_window_handle
61 * Create a window handle with the server.
63 static WND *create_window_handle( HWND parent, HWND owner, ATOM atom,
64 HINSTANCE instance, WINDOWPROCTYPE type )
68 struct tagCLASS *class = NULL;
69 user_handle_t handle = 0;
72 /* if 16-bit instance, map to module handle */
73 if (instance && !HIWORD(instance))
74 instance = HINSTANCE_32(GetExePtr(HINSTANCE_16(instance)));
76 SERVER_START_REQ( create_window )
81 req->instance = instance;
82 if (!wine_server_call_err( req ))
84 handle = reply->handle;
85 extra_bytes = reply->extra;
86 class = reply->class_ptr;
93 WARN( "error %ld creating window\n", GetLastError() );
97 if (!(win = HeapAlloc( GetProcessHeap(), 0, sizeof(WND) + extra_bytes - sizeof(win->wExtra) )))
99 SERVER_START_REQ( destroy_window )
101 req->handle = handle;
102 wine_server_call( req );
105 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
111 index = USER_HANDLE_TO_INDEX(handle);
112 assert( index < NB_USER_HANDLES );
113 user_handles[index] = win;
114 win->hwndSelf = handle;
115 win->dwMagic = WND_MAGIC;
116 win->cbWndExtra = extra_bytes;
117 memset( win->wExtra, 0, extra_bytes );
118 CLASS_AddWindow( class, win, type );
123 /***********************************************************************
126 * Free a window handle.
128 static WND *free_window_handle( HWND hwnd )
131 WORD index = USER_HANDLE_TO_INDEX(hwnd);
133 if (index >= NB_USER_HANDLES) return NULL;
135 if ((ptr = user_handles[index]))
137 SERVER_START_REQ( destroy_window )
140 if (!wine_server_call_err( req ))
142 user_handles[index] = NULL;
151 HeapFree( GetProcessHeap(), 0, ptr );
156 /*******************************************************************
157 * list_window_children
159 * Build an array of the children of a given window. The array must be
160 * freed with HeapFree. Returns NULL when no windows are found.
162 static HWND *list_window_children( HWND hwnd, ATOM atom, DWORD tid )
171 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
173 SERVER_START_REQ( get_window_children )
178 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
179 if (!wine_server_call( req )) count = reply->count;
182 if (count && count < size)
187 HeapFree( GetProcessHeap(), 0, list );
189 size = count + 1; /* restart with a large enough buffer */
195 /*******************************************************************
196 * list_window_parents
198 * Build an array of all parents of a given window, starting with
199 * the immediate parent. The array must be freed with HeapFree.
200 * Returns NULL if window is a top-level window.
202 static HWND *list_window_parents( HWND hwnd )
206 int pos = 0, size = 16, count = 0;
208 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) return NULL;
213 if (!(win = WIN_GetPtr( current ))) goto empty;
214 if (win == WND_OTHER_PROCESS) break; /* need to do it the hard way */
215 if (win == WND_DESKTOP)
217 if (!pos) goto empty;
221 list[pos] = current = win->parent;
222 WIN_ReleasePtr( win );
223 if (++pos == size - 1)
225 /* need to grow the list */
226 HWND *new_list = HeapReAlloc( GetProcessHeap(), 0, list, (size+16) * sizeof(HWND) );
227 if (!new_list) goto empty;
233 /* at least one parent belongs to another process, have to query the server */
238 SERVER_START_REQ( get_window_parents )
241 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
242 if (!wine_server_call( req )) count = reply->count;
245 if (!count) goto empty;
251 HeapFree( GetProcessHeap(), 0, list );
253 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) return NULL;
257 HeapFree( GetProcessHeap(), 0, list );
262 /*******************************************************************
265 static void send_parent_notify( HWND hwnd, UINT msg )
267 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD &&
268 !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY))
269 SendMessageW( GetParent(hwnd), WM_PARENTNOTIFY,
270 MAKEWPARAM( msg, GetWindowLongPtrW( hwnd, GWLP_ID )), (LPARAM)hwnd );
274 /*******************************************************************
275 * get_server_window_text
277 * Retrieve the window text from the server.
279 static void get_server_window_text( HWND hwnd, LPWSTR text, INT count )
283 SERVER_START_REQ( get_window_text )
286 wine_server_set_reply( req, text, (count - 1) * sizeof(WCHAR) );
287 if (!wine_server_call_err( req )) len = wine_server_reply_size(reply);
290 text[len / sizeof(WCHAR)] = 0;
294 /***********************************************************************
297 * Return a pointer to the WND structure if local to the process,
298 * or WND_OTHER_PROCESS if handle may be valid in other process.
299 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
301 WND *WIN_GetPtr( HWND hwnd )
304 WORD index = USER_HANDLE_TO_INDEX(hwnd);
306 if (index >= NB_USER_HANDLES) return NULL;
309 if ((ptr = user_handles[index]))
311 if (ptr->dwMagic == WND_MAGIC &&
312 (hwnd == ptr->hwndSelf || !HIWORD(hwnd) || HIWORD(hwnd) == 0xffff))
316 else if (index == USER_HANDLE_TO_INDEX(hwndDesktop))
318 if (hwnd == GetDesktopWindow() || !HIWORD(hwnd) || HIWORD(hwnd) == 0xffff) ptr = WND_DESKTOP;
321 else ptr = WND_OTHER_PROCESS;
327 /***********************************************************************
328 * WIN_IsCurrentProcess
330 * Check whether a given window belongs to the current process (and return the full handle).
332 HWND WIN_IsCurrentProcess( HWND hwnd )
337 if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0;
339 WIN_ReleasePtr( ptr );
344 /***********************************************************************
345 * WIN_IsCurrentThread
347 * Check whether a given window belongs to the current thread (and return the full handle).
349 HWND WIN_IsCurrentThread( HWND hwnd )
354 if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0;
355 if (ptr->tid == GetCurrentThreadId()) ret = ptr->hwndSelf;
356 WIN_ReleasePtr( ptr );
361 /***********************************************************************
364 * Convert a 16-bit window handle to a full 32-bit handle.
366 HWND WIN_Handle32( HWND16 hwnd16 )
369 HWND hwnd = (HWND)(ULONG_PTR)hwnd16;
371 if (hwnd16 <= 1 || hwnd16 == 0xffff) return hwnd;
372 /* do sign extension for -2 and -3 */
373 if (hwnd16 >= (HWND16)-3) return (HWND)(LONG_PTR)(INT16)hwnd16;
375 if (!(ptr = WIN_GetPtr( hwnd ))) return hwnd;
377 if (ptr == WND_DESKTOP) return GetDesktopWindow();
379 if (ptr != WND_OTHER_PROCESS)
381 hwnd = ptr->hwndSelf;
382 WIN_ReleasePtr( ptr );
384 else /* may belong to another process */
386 SERVER_START_REQ( get_window_info )
389 if (!wine_server_call_err( req )) hwnd = reply->full_handle;
397 /***********************************************************************
400 * Change the owner of a window.
402 HWND WIN_SetOwner( HWND hwnd, HWND owner )
404 WND *win = WIN_GetPtr( hwnd );
407 if (!win || win == WND_DESKTOP) return 0;
408 if (win == WND_OTHER_PROCESS)
410 if (IsWindow(hwnd)) ERR( "cannot set owner %p on other process window %p\n", owner, hwnd );
413 SERVER_START_REQ( set_window_owner )
417 if (!wine_server_call( req ))
419 win->owner = reply->full_owner;
420 ret = reply->prev_owner;
424 WIN_ReleasePtr( win );
429 /***********************************************************************
432 * Change the style of a window.
434 ULONG WIN_SetStyle( HWND hwnd, ULONG set_bits, ULONG clear_bits )
437 ULONG new_style, old_style = 0;
438 WND *win = WIN_GetPtr( hwnd );
440 if (!win || win == WND_DESKTOP) return 0;
441 if (win == WND_OTHER_PROCESS)
444 ERR( "cannot set style %lx/%lx on other process window %p\n",
445 set_bits, clear_bits, hwnd );
448 new_style = (win->dwStyle | set_bits) & ~clear_bits;
449 if (new_style == win->dwStyle)
451 WIN_ReleasePtr( win );
454 SERVER_START_REQ( set_window_info )
457 req->flags = SET_WIN_STYLE;
458 req->style = new_style;
459 req->extra_offset = -1;
460 if ((ok = !wine_server_call( req )))
462 old_style = reply->old_style;
463 win->dwStyle = new_style;
467 WIN_ReleasePtr( win );
468 if (ok && USER_Driver.pSetWindowStyle) USER_Driver.pSetWindowStyle( hwnd, old_style );
473 /***********************************************************************
476 * Get the window and client rectangles.
478 BOOL WIN_GetRectangles( HWND hwnd, RECT *rectWindow, RECT *rectClient )
480 WND *win = WIN_GetPtr( hwnd );
483 if (!win) return FALSE;
484 if (win == WND_DESKTOP)
487 rect.left = rect.top = 0;
488 rect.right = GetSystemMetrics(SM_CXSCREEN);
489 rect.bottom = GetSystemMetrics(SM_CYSCREEN);
490 if (rectWindow) *rectWindow = rect;
491 if (rectClient) *rectClient = rect;
493 else if (win == WND_OTHER_PROCESS)
495 SERVER_START_REQ( get_window_rectangles )
498 if ((ret = !wine_server_call( req )))
502 rectWindow->left = reply->window.left;
503 rectWindow->top = reply->window.top;
504 rectWindow->right = reply->window.right;
505 rectWindow->bottom = reply->window.bottom;
509 rectClient->left = reply->client.left;
510 rectClient->top = reply->client.top;
511 rectClient->right = reply->client.right;
512 rectClient->bottom = reply->client.bottom;
520 if (rectWindow) *rectWindow = win->rectWindow;
521 if (rectClient) *rectClient = win->rectClient;
522 WIN_ReleasePtr( win );
528 /***********************************************************************
531 * Destroy storage associated to a window. "Internals" p.358
533 LRESULT WIN_DestroyWindow( HWND hwnd )
537 HMENU menu = 0, sys_menu;
539 TRACE("%p\n", hwnd );
541 /* free child windows */
542 if ((list = WIN_ListChildren( hwnd )))
545 for (i = 0; list[i]; i++)
547 if (WIN_IsCurrentThread( list[i] )) WIN_DestroyWindow( list[i] );
548 else SendMessageW( list[i], WM_WINE_DESTROYWINDOW, 0, 0 );
550 HeapFree( GetProcessHeap(), 0, list );
553 /* Unlink now so we won't bother with the children later on */
554 SERVER_START_REQ( set_parent )
558 wine_server_call( req );
563 * Send the WM_NCDESTROY to the window being destroyed.
565 SendMessageW( hwnd, WM_NCDESTROY, 0, 0 );
567 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
569 WINPOS_CheckInternalPos( hwnd );
571 /* free resources associated with the window */
573 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
574 if (!(wndPtr->dwStyle & WS_CHILD)) menu = (HMENU)wndPtr->wIDmenu;
575 sys_menu = wndPtr->hSysMenu;
576 WIN_ReleasePtr( wndPtr );
578 if (menu) DestroyMenu( menu );
579 if (sys_menu) DestroyMenu( sys_menu );
581 if (USER_Driver.pDestroyWindow) USER_Driver.pDestroyWindow( hwnd );
583 free_window_handle( hwnd );
587 /***********************************************************************
588 * WIN_DestroyThreadWindows
590 * Destroy all children of 'wnd' owned by the current thread.
591 * Return TRUE if something was done.
593 void WIN_DestroyThreadWindows( HWND hwnd )
598 if (!(list = WIN_ListChildren( hwnd ))) return;
599 for (i = 0; list[i]; i++)
601 if (WIN_IsCurrentThread( list[i] ))
602 DestroyWindow( list[i] );
604 WIN_DestroyThreadWindows( list[i] );
606 HeapFree( GetProcessHeap(), 0, list );
609 /***********************************************************************
610 * WIN_CreateDesktopWindow
612 * Create the desktop window.
614 BOOL WIN_CreateDesktopWindow(void)
618 TRACE("Creating desktop window\n");
620 if (!WINPOS_CreateInternalPosAtom()) return FALSE;
622 SERVER_START_REQ( create_window )
626 req->atom = LOWORD(DESKTOP_CLASS_ATOM);
628 if (!wine_server_call_err( req )) hwndDesktop = reply->handle;
634 ERR( "error %ld creating desktop window\n", GetLastError() );
638 cs.lpCreateParams = NULL;
644 cs.cx = GetSystemMetrics( SM_CXSCREEN );
645 cs.cy = GetSystemMetrics( SM_CYSCREEN );
646 cs.style = WS_POPUP | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
649 cs.lpszClass = DESKTOP_CLASS_ATOM;
651 return USER_Driver.pCreateWindow( hwndDesktop, &cs, TRUE );
655 /***********************************************************************
658 * Fix the coordinates - Helper for WIN_CreateWindowEx.
659 * returns default show mode in sw.
660 * Note: the feature presented as undocumented *is* in the MSDN since 1993.
662 static void WIN_FixCoordinates( CREATESTRUCTA *cs, INT *sw)
666 if (cs->dwExStyle & WS_EX_MDICHILD)
670 MDI_CalcDefaultChildPos(cs->hwndParent, -1, pos, 0, &id);
671 if (!(cs->style & WS_POPUP)) cs->hMenu = (HMENU)id;
673 TRACE("MDI child id %04x\n", id);
676 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16 ||
677 cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
679 if (cs->style & (WS_CHILD | WS_POPUP))
681 if (cs->dwExStyle & WS_EX_MDICHILD)
683 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
688 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16 || !cs->cx)
690 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16 || !cs->cy)
695 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
697 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
701 else /* overlapped window */
705 GetStartupInfoW( &info );
707 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
709 /* Never believe Microsoft's documentation... CreateWindowEx doc says
710 * that if an overlapped window is created with WS_VISIBLE style bit
711 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
712 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
715 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
716 * 2) it does not ignore the y parameter as the docs claim; instead, it
717 * uses it as second parameter to ShowWindow() unless y is either
718 * CW_USEDEFAULT or CW_USEDEFAULT16.
720 * The fact that we didn't do 2) caused bogus windows pop up when wine
721 * was running apps that were using this obscure feature. Example -
722 * calc.exe that comes with Win98 (only Win98, it's different from
723 * the one that comes with Win95 and NT)
725 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) *sw = cs->y;
726 cs->x = (info.dwFlags & STARTF_USEPOSITION) ? info.dwX : 0;
727 cs->y = (info.dwFlags & STARTF_USEPOSITION) ? info.dwY : 0;
730 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
732 if (info.dwFlags & STARTF_USESIZE)
734 cs->cx = info.dwXSize;
735 cs->cy = info.dwYSize;
737 else /* if no other hint from the app, pick 3/4 of the screen real estate */
740 SystemParametersInfoW( SPI_GETWORKAREA, 0, &r, 0);
741 cs->cx = (((r.right - r.left) * 3) / 4) - cs->x;
742 cs->cy = (((r.bottom - r.top) * 3) / 4) - cs->y;
745 /* Handle case where only the cy values is set to default */
746 else if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16)
749 SystemParametersInfoW( SPI_GETWORKAREA, 0, &r, 0);
750 cs->cy = (((r.bottom - r.top) * 3) / 4) - cs->y;
756 /* neither x nor cx are default. Check the y values .
757 * In the trace we see Outlook and Outlook Express using
758 * cy set to CW_USEDEFAULT when opening the address book.
760 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16) {
762 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
763 SystemParametersInfoW( SPI_GETWORKAREA, 0, &r, 0);
764 cs->cy = (((r.bottom - r.top) * 3) / 4) - cs->y;
769 /***********************************************************************
772 static void dump_window_styles( DWORD style, DWORD exstyle )
775 if(style & WS_POPUP) TRACE(" WS_POPUP");
776 if(style & WS_CHILD) TRACE(" WS_CHILD");
777 if(style & WS_MINIMIZE) TRACE(" WS_MINIMIZE");
778 if(style & WS_VISIBLE) TRACE(" WS_VISIBLE");
779 if(style & WS_DISABLED) TRACE(" WS_DISABLED");
780 if(style & WS_CLIPSIBLINGS) TRACE(" WS_CLIPSIBLINGS");
781 if(style & WS_CLIPCHILDREN) TRACE(" WS_CLIPCHILDREN");
782 if(style & WS_MAXIMIZE) TRACE(" WS_MAXIMIZE");
783 if((style & WS_CAPTION) == WS_CAPTION) TRACE(" WS_CAPTION");
786 if(style & WS_BORDER) TRACE(" WS_BORDER");
787 if(style & WS_DLGFRAME) TRACE(" WS_DLGFRAME");
789 if(style & WS_VSCROLL) TRACE(" WS_VSCROLL");
790 if(style & WS_HSCROLL) TRACE(" WS_HSCROLL");
791 if(style & WS_SYSMENU) TRACE(" WS_SYSMENU");
792 if(style & WS_THICKFRAME) TRACE(" WS_THICKFRAME");
793 if(style & WS_GROUP) TRACE(" WS_GROUP");
794 if(style & WS_TABSTOP) TRACE(" WS_TABSTOP");
795 if(style & WS_MINIMIZEBOX) TRACE(" WS_MINIMIZEBOX");
796 if(style & WS_MAXIMIZEBOX) TRACE(" WS_MAXIMIZEBOX");
798 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
799 #define DUMPED_STYLES \
819 if(style & ~DUMPED_STYLES) TRACE(" %08lx", style & ~DUMPED_STYLES);
824 if(exstyle & WS_EX_DLGMODALFRAME) TRACE(" WS_EX_DLGMODALFRAME");
825 if(exstyle & WS_EX_DRAGDETECT) TRACE(" WS_EX_DRAGDETECT");
826 if(exstyle & WS_EX_NOPARENTNOTIFY) TRACE(" WS_EX_NOPARENTNOTIFY");
827 if(exstyle & WS_EX_TOPMOST) TRACE(" WS_EX_TOPMOST");
828 if(exstyle & WS_EX_ACCEPTFILES) TRACE(" WS_EX_ACCEPTFILES");
829 if(exstyle & WS_EX_TRANSPARENT) TRACE(" WS_EX_TRANSPARENT");
830 if(exstyle & WS_EX_MDICHILD) TRACE(" WS_EX_MDICHILD");
831 if(exstyle & WS_EX_TOOLWINDOW) TRACE(" WS_EX_TOOLWINDOW");
832 if(exstyle & WS_EX_WINDOWEDGE) TRACE(" WS_EX_WINDOWEDGE");
833 if(exstyle & WS_EX_CLIENTEDGE) TRACE(" WS_EX_CLIENTEDGE");
834 if(exstyle & WS_EX_CONTEXTHELP) TRACE(" WS_EX_CONTEXTHELP");
835 if(exstyle & WS_EX_RIGHT) TRACE(" WS_EX_RIGHT");
836 if(exstyle & WS_EX_RTLREADING) TRACE(" WS_EX_RTLREADING");
837 if(exstyle & WS_EX_LEFTSCROLLBAR) TRACE(" WS_EX_LEFTSCROLLBAR");
838 if(exstyle & WS_EX_CONTROLPARENT) TRACE(" WS_EX_CONTROLPARENT");
839 if(exstyle & WS_EX_STATICEDGE) TRACE(" WS_EX_STATICEDGE");
840 if(exstyle & WS_EX_APPWINDOW) TRACE(" WS_EX_APPWINDOW");
841 if(exstyle & WS_EX_LAYERED) TRACE(" WS_EX_LAYERED");
843 #define DUMPED_EX_STYLES \
844 (WS_EX_DLGMODALFRAME | \
846 WS_EX_NOPARENTNOTIFY | \
848 WS_EX_ACCEPTFILES | \
849 WS_EX_TRANSPARENT | \
854 WS_EX_CONTEXTHELP | \
857 WS_EX_LEFTSCROLLBAR | \
858 WS_EX_CONTROLPARENT | \
863 if(exstyle & ~DUMPED_EX_STYLES) TRACE(" %08lx", exstyle & ~DUMPED_EX_STYLES);
865 #undef DUMPED_EX_STYLES
869 /***********************************************************************
872 * Implementation of CreateWindowEx().
874 static HWND WIN_CreateWindowEx( CREATESTRUCTA *cs, ATOM classAtom,
875 WINDOWPROCTYPE type )
879 HWND hwnd, parent, owner, top_child = 0;
880 BOOL unicode = (type == WIN_PROC_32W);
882 TRACE("%s %s ex=%08lx style=%08lx %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
883 (type == WIN_PROC_32W) ? debugstr_w((LPWSTR)cs->lpszName) : debugstr_a(cs->lpszName),
884 (type == WIN_PROC_32W) ? debugstr_w((LPWSTR)cs->lpszClass) : debugstr_a(cs->lpszClass),
885 cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
886 cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams );
888 if(TRACE_ON(win)) dump_window_styles( cs->style, cs->dwExStyle );
890 TRACE("winproc type is %d (%s)\n", type, (type == WIN_PROC_16) ? "WIN_PROC_16" :
891 ((type == WIN_PROC_32A) ? "WIN_PROC_32A" : "WIN_PROC_32W") );
893 /* Fix the styles for MDI children */
894 if (cs->dwExStyle & WS_EX_MDICHILD)
896 MDICREATESTRUCTA mdi_cs;
899 wndPtr = WIN_GetPtr(cs->hwndParent);
900 if (wndPtr && wndPtr != WND_OTHER_PROCESS && wndPtr != WND_DESKTOP)
902 flags = wndPtr->flags;
903 WIN_ReleasePtr(wndPtr);
906 if (!(flags & WIN_ISMDICLIENT))
908 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs->hwndParent);
912 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
913 * MDICREATESTRUCT members have the originally passed values.
915 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
916 * have the same layout.
918 mdi_cs.szClass = cs->lpszClass;
919 mdi_cs.szTitle = cs->lpszName;
920 mdi_cs.hOwner = cs->hInstance;
925 mdi_cs.style = cs->style;
926 mdi_cs.lParam = (LPARAM)cs->lpCreateParams;
928 cs->lpCreateParams = (LPVOID)&mdi_cs;
930 if (GetWindowLongW(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
932 if (cs->style & WS_POPUP)
934 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
937 cs->style |= WS_CHILD | WS_CLIPSIBLINGS;
941 cs->style &= ~WS_POPUP;
942 cs->style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
943 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
946 top_child = GetWindow(cs->hwndParent, GW_CHILD);
950 /* Restore current maximized child */
951 if((cs->style & WS_VISIBLE) && IsZoomed(top_child))
953 TRACE("Restoring current maximized child %p\n", top_child);
954 SendMessageW( top_child, WM_SETREDRAW, FALSE, 0 );
955 ShowWindow(top_child, SW_RESTORE);
956 SendMessageW( top_child, WM_SETREDRAW, TRUE, 0 );
961 /* Find the parent window */
963 parent = GetDesktopWindow();
966 if (cs->hwndParent == HWND_MESSAGE)
968 /* native ole32.OleInitialize uses HWND_MESSAGE to create the
969 * message window (style: WS_POPUP|WS_DISABLED)
971 FIXME("Parent is HWND_MESSAGE\n");
973 else if (cs->hwndParent)
975 /* Make sure parent is valid */
976 if (!IsWindow( cs->hwndParent ))
978 WARN("Bad parent %p\n", cs->hwndParent );
981 if ((cs->style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
982 parent = WIN_GetFullHandle(cs->hwndParent);
984 owner = GetAncestor( cs->hwndParent, GA_ROOT );
986 else if ((cs->style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
988 WARN("No parent for child window\n" );
989 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
992 WIN_FixCoordinates(cs, &sw); /* fix default coordinates */
994 if ((cs->dwExStyle & WS_EX_DLGMODALFRAME) ||
995 ((!(cs->dwExStyle & WS_EX_STATICEDGE)) &&
996 (cs->style & (WS_DLGFRAME | WS_THICKFRAME))))
997 cs->dwExStyle |= WS_EX_WINDOWEDGE;
999 cs->dwExStyle &= ~WS_EX_WINDOWEDGE;
1001 /* Create the window structure */
1003 if (!(wndPtr = create_window_handle( parent, owner, classAtom, cs->hInstance, type )))
1005 TRACE("out of memory\n" );
1008 hwnd = wndPtr->hwndSelf;
1010 /* Fill the window structure */
1012 wndPtr->tid = GetCurrentThreadId();
1013 wndPtr->owner = owner;
1014 wndPtr->parent = parent;
1015 wndPtr->hInstance = cs->hInstance;
1016 wndPtr->text = NULL;
1017 wndPtr->dwStyle = cs->style & ~WS_VISIBLE;
1018 wndPtr->dwExStyle = cs->dwExStyle;
1019 wndPtr->wIDmenu = 0;
1020 wndPtr->helpContext = 0;
1021 wndPtr->flags = (type == WIN_PROC_16) ? 0 : WIN_ISWIN32;
1022 wndPtr->pVScroll = NULL;
1023 wndPtr->pHScroll = NULL;
1024 wndPtr->userdata = 0;
1026 wndPtr->hIconSmall = 0;
1027 wndPtr->hSysMenu = (wndPtr->dwStyle & WS_SYSMENU) ? MENU_GetSysMenu( hwnd, (HMENU)-1 ) : 0;
1030 * Correct the window styles.
1032 * It affects only the style loaded into the WIN structure.
1035 if (!(wndPtr->dwStyle & WS_CHILD))
1037 wndPtr->dwStyle |= WS_CLIPSIBLINGS;
1038 if (!(wndPtr->dwStyle & WS_POPUP))
1039 wndPtr->dwStyle |= WS_CAPTION;
1043 * WS_EX_WINDOWEDGE appears to be enforced based on the other styles, so
1044 * why does the user get to set it?
1047 if ((wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) ||
1048 (wndPtr->dwStyle & (WS_DLGFRAME | WS_THICKFRAME)))
1049 wndPtr->dwExStyle |= WS_EX_WINDOWEDGE;
1051 wndPtr->dwExStyle &= ~WS_EX_WINDOWEDGE;
1053 if (!(wndPtr->dwStyle & (WS_CHILD | WS_POPUP)))
1054 wndPtr->flags |= WIN_NEED_SIZE;
1056 SERVER_START_REQ( set_window_info )
1059 req->flags = SET_WIN_STYLE | SET_WIN_EXSTYLE | SET_WIN_INSTANCE;
1060 req->style = wndPtr->dwStyle;
1061 req->ex_style = wndPtr->dwExStyle;
1062 req->instance = (void *)wndPtr->hInstance;
1063 req->extra_offset = -1;
1064 wine_server_call( req );
1068 /* Set the window menu */
1070 if (((wndPtr->dwStyle & (WS_CAPTION|WS_CHILD)) == WS_CAPTION) ||
1071 (wndPtr->dwExStyle & WS_EX_APPWINDOW))
1073 if (cs->hMenu) MENU_SetMenu(hwnd, cs->hMenu);
1076 LPCSTR menuName = (LPCSTR)GetClassLongPtrA( hwnd, GCLP_MENUNAME );
1079 if (HIWORD(cs->hInstance))
1080 cs->hMenu = LoadMenuA(cs->hInstance,menuName);
1082 cs->hMenu = HMENU_32(LoadMenu16(HINSTANCE_16(cs->hInstance),menuName));
1084 if (cs->hMenu) MENU_SetMenu( hwnd, cs->hMenu );
1088 else SetWindowLongPtrW( hwnd, GWLP_ID, (ULONG_PTR)cs->hMenu );
1089 WIN_ReleasePtr( wndPtr );
1091 if (!USER_Driver.pCreateWindow || !USER_Driver.pCreateWindow( hwnd, cs, unicode))
1093 WIN_DestroyWindow( hwnd );
1097 /* Notify the parent window only */
1099 send_parent_notify( hwnd, WM_CREATE );
1100 if (!IsWindow( hwnd )) return 0;
1102 if (cs->style & WS_VISIBLE)
1104 if (cs->style & WS_MAXIMIZE)
1105 sw = SW_SHOWMAXIMIZED;
1106 else if (cs->style & WS_MINIMIZE)
1107 sw = SW_SHOWMINIMIZED;
1109 ShowWindow( hwnd, sw );
1110 if (cs->dwExStyle & WS_EX_MDICHILD)
1112 SendMessageW(cs->hwndParent, WM_MDIREFRESHMENU, 0, 0);
1113 /* ShowWindow won't activate child windows */
1114 SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
1118 /* Call WH_SHELL hook */
1120 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) && !GetWindow( hwnd, GW_OWNER ))
1121 HOOK_CallHooks( WH_SHELL, HSHELL_WINDOWCREATED, (WPARAM)hwnd, 0, TRUE );
1123 TRACE("created window %p\n", hwnd);
1128 /***********************************************************************
1129 * CreateWindow (USER.41)
1131 HWND16 WINAPI CreateWindow16( LPCSTR className, LPCSTR windowName,
1132 DWORD style, INT16 x, INT16 y, INT16 width,
1133 INT16 height, HWND16 parent, HMENU16 menu,
1134 HINSTANCE16 instance, LPVOID data )
1136 return CreateWindowEx16( 0, className, windowName, style,
1137 x, y, width, height, parent, menu, instance, data );
1141 /***********************************************************************
1142 * CreateWindowEx (USER.452)
1144 HWND16 WINAPI CreateWindowEx16( DWORD exStyle, LPCSTR className,
1145 LPCSTR windowName, DWORD style, INT16 x,
1146 INT16 y, INT16 width, INT16 height,
1147 HWND16 parent, HMENU16 menu,
1148 HINSTANCE16 instance, LPVOID data )
1154 /* Find the class atom */
1156 if (HIWORD(className))
1158 if (!(classAtom = GlobalFindAtomA( className )))
1160 ERR( "bad class name %s\n", debugstr_a(className) );
1166 classAtom = LOWORD(className);
1167 if (!GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) ))
1169 ERR( "bad atom %x\n", classAtom);
1175 /* Fix the coordinates */
1177 cs.x = (x == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)x;
1178 cs.y = (y == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)y;
1179 cs.cx = (width == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)width;
1180 cs.cy = (height == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)height;
1182 /* Create the window */
1184 cs.lpCreateParams = data;
1185 cs.hInstance = HINSTANCE_32(instance);
1186 cs.hMenu = HMENU_32(menu);
1187 cs.hwndParent = WIN_Handle32( parent );
1189 cs.lpszName = windowName;
1190 cs.lpszClass = className;
1191 cs.dwExStyle = exStyle;
1193 return HWND_16( WIN_CreateWindowEx( &cs, classAtom, WIN_PROC_16 ));
1197 /***********************************************************************
1198 * CreateWindowExA (USER32.@)
1200 HWND WINAPI CreateWindowExA( DWORD exStyle, LPCSTR className,
1201 LPCSTR windowName, DWORD style, INT x,
1202 INT y, INT width, INT height,
1203 HWND parent, HMENU menu,
1204 HINSTANCE instance, LPVOID data )
1210 /* Find the class atom */
1212 if (HIWORD(className))
1214 if (!(classAtom = GlobalFindAtomA( className )))
1216 ERR( "bad class name %s\n", debugstr_a(className) );
1222 classAtom = LOWORD(className);
1223 if (!GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) ))
1225 ERR( "bad atom %x\n", classAtom);
1231 /* Create the window */
1233 cs.lpCreateParams = data;
1234 cs.hInstance = instance;
1236 cs.hwndParent = parent;
1242 cs.lpszName = windowName;
1243 cs.lpszClass = className;
1244 cs.dwExStyle = exStyle;
1246 return WIN_CreateWindowEx( &cs, classAtom, WIN_PROC_32A );
1250 /***********************************************************************
1251 * CreateWindowExW (USER32.@)
1253 HWND WINAPI CreateWindowExW( DWORD exStyle, LPCWSTR className,
1254 LPCWSTR windowName, DWORD style, INT x,
1255 INT y, INT width, INT height,
1256 HWND parent, HMENU menu,
1257 HINSTANCE instance, LPVOID data )
1263 /* Find the class atom */
1265 if (HIWORD(className))
1267 if (!(classAtom = GlobalFindAtomW( className )))
1269 ERR( "bad class name %s\n", debugstr_w(className) );
1275 classAtom = LOWORD(className);
1276 if (!GlobalGetAtomNameW( classAtom, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1278 ERR( "bad atom %x\n", classAtom);
1284 /* Create the window */
1286 cs.lpCreateParams = data;
1287 cs.hInstance = instance;
1289 cs.hwndParent = parent;
1295 cs.lpszName = windowName;
1296 cs.lpszClass = className;
1297 cs.dwExStyle = exStyle;
1299 /* Note: we rely on the fact that CREATESTRUCTA and */
1300 /* CREATESTRUCTW have the same layout. */
1301 return WIN_CreateWindowEx( (CREATESTRUCTA *)&cs, classAtom, WIN_PROC_32W );
1305 /***********************************************************************
1306 * WIN_SendDestroyMsg
1308 static void WIN_SendDestroyMsg( HWND hwnd )
1312 if (GetGUIThreadInfo( GetCurrentThreadId(), &info ))
1314 if (hwnd == info.hwndCaret) DestroyCaret();
1315 if (hwnd == info.hwndActive) WINPOS_ActivateOtherWindow( hwnd );
1317 if (USER_Driver.pResetSelectionOwner)
1318 USER_Driver.pResetSelectionOwner( hwnd, TRUE );
1321 * Send the WM_DESTROY to the window.
1323 SendMessageW( hwnd, WM_DESTROY, 0, 0);
1326 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1327 * make sure that the window still exists when we come back.
1334 if (!(pWndArray = WIN_ListChildren( hwnd ))) return;
1336 for (i = 0; pWndArray[i]; i++)
1338 if (IsWindow( pWndArray[i] )) WIN_SendDestroyMsg( pWndArray[i] );
1340 HeapFree( GetProcessHeap(), 0, pWndArray );
1343 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1347 /***********************************************************************
1348 * DestroyWindow (USER32.@)
1350 BOOL WINAPI DestroyWindow( HWND hwnd )
1354 if (!(hwnd = WIN_IsCurrentThread( hwnd )) || (hwnd == GetDesktopWindow()))
1356 SetLastError( ERROR_ACCESS_DENIED );
1360 TRACE("(%p)\n", hwnd);
1364 if (HOOK_CallHooks( WH_CBT, HCBT_DESTROYWND, (WPARAM)hwnd, 0, TRUE )) return FALSE;
1366 if (MENU_IsMenuActive() == hwnd)
1369 is_child = (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) != 0;
1373 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1374 send_parent_notify( hwnd, WM_DESTROY );
1376 else if (!GetWindow( hwnd, GW_OWNER ))
1378 HOOK_CallHooks( WH_SHELL, HSHELL_WINDOWDESTROYED, (WPARAM)hwnd, 0L, TRUE );
1379 /* FIXME: clean up palette - see "Internals" p.352 */
1382 if (!IsWindow(hwnd)) return TRUE;
1384 if (USER_Driver.pResetSelectionOwner)
1385 USER_Driver.pResetSelectionOwner( hwnd, FALSE ); /* before the window is unmapped */
1387 /* Hide the window */
1388 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
1390 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1392 ShowWindow( hwnd, SW_HIDE );
1394 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1395 SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW );
1398 if (!IsWindow(hwnd)) return TRUE;
1400 /* Recursively destroy owned windows */
1407 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1410 for (i = 0; list[i]; i++)
1412 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1413 if (WIN_IsCurrentThread( list[i] ))
1415 DestroyWindow( list[i] );
1419 WIN_SetOwner( list[i], 0 );
1421 HeapFree( GetProcessHeap(), 0, list );
1423 if (!got_one) break;
1427 /* Send destroy messages */
1429 WIN_SendDestroyMsg( hwnd );
1430 if (!IsWindow( hwnd )) return TRUE;
1432 if (GetClipboardOwner() == hwnd)
1433 CLIPBOARD_ReleaseOwner();
1435 /* Destroy the window storage */
1437 WIN_DestroyWindow( hwnd );
1442 /***********************************************************************
1443 * CloseWindow (USER32.@)
1445 BOOL WINAPI CloseWindow( HWND hwnd )
1447 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) return FALSE;
1448 ShowWindow( hwnd, SW_MINIMIZE );
1453 /***********************************************************************
1454 * OpenIcon (USER32.@)
1456 BOOL WINAPI OpenIcon( HWND hwnd )
1458 if (!IsIconic( hwnd )) return FALSE;
1459 ShowWindow( hwnd, SW_SHOWNORMAL );
1464 /***********************************************************************
1467 * Implementation of FindWindow() and FindWindowEx().
1469 static HWND WIN_FindWindow( HWND parent, HWND child, ATOM className, LPCWSTR title )
1474 WCHAR *buffer = NULL;
1476 if (!parent) parent = GetDesktopWindow();
1479 len = strlenW(title) + 1; /* one extra char to check for chars beyond the end */
1480 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return 0;
1483 if (!(list = list_window_children( parent, className, 0 ))) goto done;
1487 child = WIN_GetFullHandle( child );
1488 while (list[i] && list[i] != child) i++;
1489 if (!list[i]) goto done;
1490 i++; /* start from next window */
1497 if (GetWindowTextW( list[i], buffer, len + 1 ) && !strcmpiW( buffer, title )) break;
1504 HeapFree( GetProcessHeap(), 0, list );
1505 HeapFree( GetProcessHeap(), 0, buffer );
1511 /***********************************************************************
1512 * FindWindowA (USER32.@)
1514 HWND WINAPI FindWindowA( LPCSTR className, LPCSTR title )
1516 HWND ret = FindWindowExA( 0, 0, className, title );
1517 if (!ret) SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1522 /***********************************************************************
1523 * FindWindowExA (USER32.@)
1525 HWND WINAPI FindWindowExA( HWND parent, HWND child,
1526 LPCSTR className, LPCSTR title )
1535 /* If the atom doesn't exist, then no class */
1536 /* with this name exists either. */
1537 if (!(atom = GlobalFindAtomA( className )))
1539 SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1543 if (!title) return WIN_FindWindow( parent, child, atom, NULL );
1545 len = MultiByteToWideChar( CP_ACP, 0, title, -1, NULL, 0 );
1546 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0;
1547 MultiByteToWideChar( CP_ACP, 0, title, -1, buffer, len );
1548 hwnd = WIN_FindWindow( parent, child, atom, buffer );
1549 HeapFree( GetProcessHeap(), 0, buffer );
1554 /***********************************************************************
1555 * FindWindowExW (USER32.@)
1557 HWND WINAPI FindWindowExW( HWND parent, HWND child,
1558 LPCWSTR className, LPCWSTR title )
1564 /* If the atom doesn't exist, then no class */
1565 /* with this name exists either. */
1566 if (!(atom = GlobalFindAtomW( className )))
1568 SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1572 return WIN_FindWindow( parent, child, atom, title );
1576 /***********************************************************************
1577 * FindWindowW (USER32.@)
1579 HWND WINAPI FindWindowW( LPCWSTR className, LPCWSTR title )
1581 return FindWindowExW( 0, 0, className, title );
1585 /**********************************************************************
1586 * GetDesktopWindow (USER32.@)
1588 HWND WINAPI GetDesktopWindow(void)
1590 if (hwndDesktop) return hwndDesktop;
1591 ERR( "Wine init error: either you're trying to use an invalid native USER.EXE config, or some graphics/GUI libraries or DLLs didn't initialize properly. Aborting.\n" );
1597 /*******************************************************************
1598 * EnableWindow (USER32.@)
1600 BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
1605 if (is_broadcast(hwnd))
1607 SetLastError( ERROR_INVALID_PARAMETER );
1611 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
1612 return SendMessageW( hwnd, WM_WINE_ENABLEWINDOW, enable, 0 );
1616 TRACE("( %p, %d )\n", hwnd, enable);
1618 retvalue = !IsWindowEnabled( hwnd );
1620 if (enable && retvalue)
1622 WIN_SetStyle( hwnd, 0, WS_DISABLED );
1623 SendMessageW( hwnd, WM_ENABLE, TRUE, 0 );
1625 else if (!enable && !retvalue)
1629 SendMessageW( hwnd, WM_CANCELMODE, 0, 0);
1631 WIN_SetStyle( hwnd, WS_DISABLED, 0 );
1633 if (hwnd == GetFocus())
1634 SetFocus( 0 ); /* A disabled window can't have the focus */
1636 capture_wnd = GetCapture();
1637 if (hwnd == capture_wnd || IsChild(hwnd, capture_wnd))
1638 ReleaseCapture(); /* A disabled window can't capture the mouse */
1640 SendMessageW( hwnd, WM_ENABLE, FALSE, 0 );
1646 /***********************************************************************
1647 * IsWindowEnabled (USER32.@)
1649 BOOL WINAPI IsWindowEnabled(HWND hWnd)
1651 return !(GetWindowLongW( hWnd, GWL_STYLE ) & WS_DISABLED);
1655 /***********************************************************************
1656 * IsWindowUnicode (USER32.@)
1658 BOOL WINAPI IsWindowUnicode( HWND hwnd )
1663 if (!(wndPtr = WIN_GetPtr(hwnd)) || wndPtr == WND_OTHER_PROCESS) return FALSE;
1664 if (wndPtr == WND_DESKTOP) return TRUE;
1665 retvalue = (WINPROC_GetProcType( wndPtr->winproc ) == WIN_PROC_32W);
1666 WIN_ReleasePtr( wndPtr );
1671 /**********************************************************************
1672 * GetWindowWord (USER32.@)
1674 WORD WINAPI GetWindowWord( HWND hwnd, INT offset )
1679 WND *wndPtr = WIN_GetPtr( hwnd );
1682 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1685 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
1687 SERVER_START_REQ( set_window_info )
1690 req->flags = 0; /* don't set anything, just retrieve */
1691 req->extra_offset = offset;
1692 req->extra_size = sizeof(retvalue);
1693 if (!wine_server_call_err( req ))
1694 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
1699 if (offset > (int)(wndPtr->cbWndExtra - sizeof(WORD)))
1701 WARN("Invalid offset %d\n", offset );
1702 SetLastError( ERROR_INVALID_INDEX );
1704 else memcpy( &retvalue, (char *)wndPtr->wExtra + offset, sizeof(retvalue) );
1705 WIN_ReleasePtr( wndPtr );
1711 case GWLP_HWNDPARENT:
1712 return GetWindowLongPtrW( hwnd, offset );
1714 case GWLP_HINSTANCE:
1716 LONG_PTR ret = GetWindowLongPtrW( hwnd, offset );
1718 WARN("%d: discards high bits of 0x%08lx!\n", offset, ret );
1722 WARN("Invalid offset %d\n", offset );
1728 /**********************************************************************
1729 * SetWindowWord (USER32.@)
1731 WORD WINAPI SetWindowWord( HWND hwnd, INT offset, WORD newval )
1739 case GWLP_HINSTANCE:
1740 case GWLP_HWNDPARENT:
1741 return SetWindowLongPtrW( hwnd, offset, (ULONG_PTR)newval );
1745 WARN("Invalid offset %d\n", offset );
1746 SetLastError( ERROR_INVALID_INDEX );
1751 wndPtr = WIN_GetPtr( hwnd );
1752 if (wndPtr == WND_DESKTOP)
1754 SetLastError( ERROR_ACCESS_DENIED );
1757 if (wndPtr == WND_OTHER_PROCESS)
1760 FIXME( "set %d <- %x not supported yet on other process window %p\n",
1761 offset, newval, hwnd );
1766 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1770 if (offset > (int)(wndPtr->cbWndExtra - sizeof(WORD)))
1772 WARN("Invalid offset %d\n", offset );
1773 WIN_ReleasePtr(wndPtr);
1774 SetLastError( ERROR_INVALID_INDEX );
1778 SERVER_START_REQ( set_window_info )
1781 req->flags = SET_WIN_EXTRA;
1782 req->extra_offset = offset;
1783 req->extra_size = sizeof(newval);
1784 memcpy( &req->extra_value, &newval, sizeof(newval) );
1785 if (!wine_server_call_err( req ))
1787 void *ptr = (char *)wndPtr->wExtra + offset;
1788 memcpy( &retval, ptr, sizeof(retval) );
1789 memcpy( ptr, &newval, sizeof(newval) );
1793 WIN_ReleasePtr( wndPtr );
1798 /**********************************************************************
1801 * Helper function for GetWindowLong().
1803 static LONG_PTR WIN_GetWindowLong( HWND hwnd, INT offset, WINDOWPROCTYPE type )
1805 LONG_PTR retvalue = 0;
1808 if (offset == GWLP_HWNDPARENT)
1810 HWND parent = GetAncestor( hwnd, GA_PARENT );
1811 if (parent == GetDesktopWindow()) parent = GetWindow( hwnd, GW_OWNER );
1812 return (ULONG_PTR)parent;
1815 if (!(wndPtr = WIN_GetPtr( hwnd )))
1817 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1821 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
1823 if (offset == GWLP_WNDPROC)
1825 SetLastError( ERROR_ACCESS_DENIED );
1828 SERVER_START_REQ( set_window_info )
1831 req->flags = 0; /* don't set anything, just retrieve */
1832 req->extra_offset = (offset >= 0) ? offset : -1;
1833 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
1834 if (!wine_server_call_err( req ))
1838 case GWL_STYLE: retvalue = reply->old_style; break;
1839 case GWL_EXSTYLE: retvalue = reply->old_ex_style; break;
1840 case GWLP_ID: retvalue = reply->old_id; break;
1841 case GWLP_HINSTANCE: retvalue = (ULONG_PTR)reply->old_instance; break;
1842 case GWLP_USERDATA: retvalue = (ULONG_PTR)reply->old_user_data; break;
1844 if (offset >= 0) retvalue = reply->old_extra_value;
1845 else SetLastError( ERROR_INVALID_INDEX );
1854 /* now we have a valid wndPtr */
1858 if (offset > (int)(wndPtr->cbWndExtra - sizeof(LONG)))
1861 * Some programs try to access last element from 16 bit
1862 * code using illegal offset value. Hopefully this is
1863 * what those programs really expect.
1865 if (type == WIN_PROC_16 &&
1866 wndPtr->cbWndExtra >= 4 &&
1867 offset == wndPtr->cbWndExtra - sizeof(WORD))
1869 INT offset2 = wndPtr->cbWndExtra - sizeof(LONG);
1871 ERR( "- replaced invalid offset %d with %d\n",
1874 retvalue = *(LONG_PTR *)(((char *)wndPtr->wExtra) + offset2);
1875 WIN_ReleasePtr( wndPtr );
1878 WARN("Invalid offset %d\n", offset );
1879 WIN_ReleasePtr( wndPtr );
1880 SetLastError( ERROR_INVALID_INDEX );
1883 retvalue = *(LONG_PTR *)(((char *)wndPtr->wExtra) + offset);
1884 /* Special case for dialog window procedure */
1885 if ((offset == DWLP_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG))
1886 retvalue = (LONG_PTR)WINPROC_GetProc( (WNDPROC)retvalue, type );
1887 WIN_ReleasePtr( wndPtr );
1893 case GWLP_USERDATA: retvalue = wndPtr->userdata; break;
1894 case GWL_STYLE: retvalue = wndPtr->dwStyle; break;
1895 case GWL_EXSTYLE: retvalue = wndPtr->dwExStyle; break;
1896 case GWLP_ID: retvalue = (ULONG_PTR)wndPtr->wIDmenu; break;
1897 case GWLP_WNDPROC: retvalue = (ULONG_PTR)WINPROC_GetProc( wndPtr->winproc, type ); break;
1898 case GWLP_HINSTANCE: retvalue = (ULONG_PTR)wndPtr->hInstance; break;
1900 WARN("Unknown offset %d\n", offset );
1901 SetLastError( ERROR_INVALID_INDEX );
1904 WIN_ReleasePtr(wndPtr);
1909 /**********************************************************************
1912 * Helper function for SetWindowLong().
1914 * 0 is the failure code. However, in the case of failure SetLastError
1915 * must be set to distinguish between a 0 return value and a failure.
1917 static LONG_PTR WIN_SetWindowLong( HWND hwnd, INT offset, LONG_PTR newval,
1918 WINDOWPROCTYPE type )
1922 LONG_PTR retval = 0;
1925 TRACE( "%p %d %lx %x\n", hwnd, offset, newval, type );
1927 if (is_broadcast(hwnd))
1929 SetLastError( ERROR_INVALID_PARAMETER );
1933 if (!(wndPtr = WIN_GetPtr( hwnd )))
1935 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1938 if (wndPtr == WND_DESKTOP)
1940 /* can't change anything on the desktop window */
1941 SetLastError( ERROR_ACCESS_DENIED );
1944 if (wndPtr == WND_OTHER_PROCESS)
1946 if (offset == GWLP_WNDPROC)
1948 SetLastError( ERROR_ACCESS_DENIED );
1951 return SendMessageW( hwnd, WM_WINE_SETWINDOWLONG, offset, newval );
1954 /* first some special cases */
1960 offset == GWL_STYLE ? wndPtr->dwStyle : wndPtr->dwExStyle;
1961 style.styleNew = newval;
1962 WIN_ReleasePtr( wndPtr );
1963 SendMessageW( hwnd, WM_STYLECHANGING, offset, (LPARAM)&style );
1964 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1965 newval = style.styleNew;
1967 case GWLP_HWNDPARENT:
1968 if (wndPtr->parent == GetDesktopWindow())
1970 WIN_ReleasePtr( wndPtr );
1971 return (ULONG_PTR)WIN_SetOwner( hwnd, (HWND)newval );
1975 WIN_ReleasePtr( wndPtr );
1976 return (ULONG_PTR)SetParent( hwnd, (HWND)newval );
1979 retval = (ULONG_PTR)WINPROC_GetProc( wndPtr->winproc, type );
1980 wndPtr->winproc = WINPROC_AllocProc( (WNDPROC)newval, type );
1981 WIN_ReleasePtr( wndPtr );
1984 case GWLP_HINSTANCE:
1988 if ((wndPtr->cbWndExtra + sizeof(LONG_PTR) >= DWLP_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG))
1990 WNDPROC *ptr = (WNDPROC *)((char *)wndPtr->wExtra + DWLP_DLGPROC);
1991 retval = (ULONG_PTR)WINPROC_GetProc( *ptr, type );
1992 *ptr = WINPROC_AllocProc( (WNDPROC)newval, type );
1993 WIN_ReleasePtr( wndPtr );
1998 if (offset < 0 || offset > (int)(wndPtr->cbWndExtra - sizeof(LONG_PTR)))
2000 WARN("Invalid offset %d\n", offset );
2001 WIN_ReleasePtr( wndPtr );
2002 SetLastError( ERROR_INVALID_INDEX );
2007 LONG_PTR *ptr = (LONG_PTR *)((char *)wndPtr->wExtra + offset);
2008 if (*ptr == newval) /* already set to the same value */
2010 WIN_ReleasePtr( wndPtr );
2017 SERVER_START_REQ( set_window_info )
2020 req->extra_offset = -1;
2024 req->flags = SET_WIN_STYLE;
2025 req->style = newval;
2028 req->flags = SET_WIN_EXSTYLE;
2029 req->ex_style = newval;
2032 req->flags = SET_WIN_ID;
2035 case GWLP_HINSTANCE:
2036 req->flags = SET_WIN_INSTANCE;
2037 req->instance = (void *)newval;
2040 req->flags = SET_WIN_USERDATA;
2041 req->user_data = (void *)newval;
2044 req->flags = SET_WIN_EXTRA;
2045 req->extra_offset = offset;
2046 req->extra_size = sizeof(newval);
2047 memcpy( &req->extra_value, &newval, sizeof(newval) );
2049 if ((ok = !wine_server_call_err( req )))
2054 wndPtr->dwStyle = newval;
2055 retval = reply->old_style;
2058 wndPtr->dwExStyle = newval;
2059 retval = reply->old_ex_style;
2062 wndPtr->wIDmenu = newval;
2063 retval = reply->old_id;
2065 case GWLP_HINSTANCE:
2066 wndPtr->hInstance = (HINSTANCE)newval;
2067 retval = (ULONG_PTR)reply->old_instance;
2070 wndPtr->userdata = newval;
2071 retval = (ULONG_PTR)reply->old_user_data;
2075 void *ptr = (char *)wndPtr->wExtra + offset;
2076 memcpy( &retval, ptr, sizeof(retval) );
2077 memcpy( ptr, &newval, sizeof(newval) );
2084 WIN_ReleasePtr( wndPtr );
2088 if (offset == GWL_STYLE && USER_Driver.pSetWindowStyle)
2089 USER_Driver.pSetWindowStyle( hwnd, retval );
2091 if (offset == GWL_STYLE || offset == GWL_EXSTYLE)
2092 SendMessageW( hwnd, WM_STYLECHANGED, offset, (LPARAM)&style );
2098 /**********************************************************************
2099 * GetWindowLong (USER.135)
2101 LONG WINAPI GetWindowLong16( HWND16 hwnd, INT16 offset )
2103 return WIN_GetWindowLong( WIN_Handle32(hwnd), offset, WIN_PROC_16 );
2107 /**********************************************************************
2108 * GetWindowLongA (USER32.@)
2110 LONG WINAPI GetWindowLongA( HWND hwnd, INT offset )
2112 return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32A );
2116 /**********************************************************************
2117 * GetWindowLongW (USER32.@)
2119 LONG WINAPI GetWindowLongW( HWND hwnd, INT offset )
2121 return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32W );
2125 /**********************************************************************
2126 * SetWindowLong (USER.136)
2128 LONG WINAPI SetWindowLong16( HWND16 hwnd, INT16 offset, LONG newval )
2130 return WIN_SetWindowLong( WIN_Handle32(hwnd), offset, newval, WIN_PROC_16 );
2134 /**********************************************************************
2135 * SetWindowLongA (USER32.@)
2137 LONG WINAPI SetWindowLongA( HWND hwnd, INT offset, LONG newval )
2139 return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32A );
2143 /**********************************************************************
2144 * SetWindowLongW (USER32.@) Set window attribute
2146 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2147 * value in a window's extra memory.
2149 * The _hwnd_ parameter specifies the window. is the handle to a
2150 * window that has extra memory. The _newval_ parameter contains the
2151 * new attribute or extra memory value. If positive, the _offset_
2152 * parameter is the byte-addressed location in the window's extra
2153 * memory to set. If negative, _offset_ specifies the window
2154 * attribute to set, and should be one of the following values:
2156 * GWL_EXSTYLE The window's extended window style
2158 * GWL_STYLE The window's window style.
2160 * GWLP_WNDPROC Pointer to the window's window procedure.
2162 * GWLP_HINSTANCE The window's pplication instance handle.
2164 * GWLP_ID The window's identifier.
2166 * GWLP_USERDATA The window's user-specified data.
2168 * If the window is a dialog box, the _offset_ parameter can be one of
2169 * the following values:
2171 * DWLP_DLGPROC The address of the window's dialog box procedure.
2173 * DWLP_MSGRESULT The return value of a message
2174 * that the dialog box procedure processed.
2176 * DWLP_USER Application specific information.
2180 * If successful, returns the previous value located at _offset_. Otherwise,
2185 * Extra memory for a window class is specified by a nonzero cbWndExtra
2186 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2187 * time of class creation.
2189 * Using GWL_WNDPROC to set a new window procedure effectively creates
2190 * a window subclass. Use CallWindowProc() in the new windows procedure
2191 * to pass messages to the superclass's window procedure.
2193 * The user data is reserved for use by the application which created
2196 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2197 * instead, call the EnableWindow() function to change the window's
2200 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2201 * SetParent() instead.
2204 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2205 * it sends WM_STYLECHANGING before changing the settings
2206 * and WM_STYLECHANGED afterwards.
2207 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2209 LONG WINAPI SetWindowLongW(
2210 HWND hwnd, /* [in] window to alter */
2211 INT offset, /* [in] offset, in bytes, of location to alter */
2212 LONG newval /* [in] new value of location */
2214 return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32W );
2218 /*******************************************************************
2219 * GetWindowTextA (USER32.@)
2221 INT WINAPI GetWindowTextA( HWND hwnd, LPSTR lpString, INT nMaxCount )
2225 if (!lpString) return 0;
2227 if (WIN_IsCurrentProcess( hwnd ))
2228 return (INT)SendMessageA( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
2230 /* when window belongs to other process, don't send a message */
2231 if (nMaxCount <= 0) return 0;
2232 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, nMaxCount * sizeof(WCHAR) ))) return 0;
2233 get_server_window_text( hwnd, buffer, nMaxCount );
2234 if (!WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpString, nMaxCount, NULL, NULL ))
2235 lpString[nMaxCount-1] = 0;
2236 HeapFree( GetProcessHeap(), 0, buffer );
2237 return strlen(lpString);
2241 /*******************************************************************
2242 * InternalGetWindowText (USER32.@)
2244 INT WINAPI InternalGetWindowText(HWND hwnd,LPWSTR lpString,INT nMaxCount )
2248 if (nMaxCount <= 0) return 0;
2249 if (!(win = WIN_GetPtr( hwnd ))) return 0;
2250 if (win == WND_DESKTOP) lpString[0] = 0;
2251 else if (win != WND_OTHER_PROCESS)
2253 if (win->text) lstrcpynW( lpString, win->text, nMaxCount );
2254 else lpString[0] = 0;
2255 WIN_ReleasePtr( win );
2259 get_server_window_text( hwnd, lpString, nMaxCount );
2261 return strlenW(lpString);
2265 /*******************************************************************
2266 * GetWindowTextW (USER32.@)
2268 INT WINAPI GetWindowTextW( HWND hwnd, LPWSTR lpString, INT nMaxCount )
2270 if (!lpString) return 0;
2272 if (WIN_IsCurrentProcess( hwnd ))
2273 return (INT)SendMessageW( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
2275 /* when window belongs to other process, don't send a message */
2276 if (nMaxCount <= 0) return 0;
2277 get_server_window_text( hwnd, lpString, nMaxCount );
2278 return strlenW(lpString);
2282 /*******************************************************************
2283 * SetWindowText (USER32.@)
2284 * SetWindowTextA (USER32.@)
2286 BOOL WINAPI SetWindowTextA( HWND hwnd, LPCSTR lpString )
2288 if (is_broadcast(hwnd))
2290 SetLastError( ERROR_INVALID_PARAMETER );
2293 if (!WIN_IsCurrentProcess( hwnd ))
2294 FIXME( "setting text %s of other process window %p should not use SendMessage\n",
2295 debugstr_a(lpString), hwnd );
2296 return (BOOL)SendMessageA( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
2300 /*******************************************************************
2301 * SetWindowTextW (USER32.@)
2303 BOOL WINAPI SetWindowTextW( HWND hwnd, LPCWSTR lpString )
2305 if (is_broadcast(hwnd))
2307 SetLastError( ERROR_INVALID_PARAMETER );
2310 if (!WIN_IsCurrentProcess( hwnd ))
2311 FIXME( "setting text %s of other process window %p should not use SendMessage\n",
2312 debugstr_w(lpString), hwnd );
2313 return (BOOL)SendMessageW( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
2317 /*******************************************************************
2318 * GetWindowTextLengthA (USER32.@)
2320 INT WINAPI GetWindowTextLengthA( HWND hwnd )
2322 return SendMessageA( hwnd, WM_GETTEXTLENGTH, 0, 0 );
2325 /*******************************************************************
2326 * GetWindowTextLengthW (USER32.@)
2328 INT WINAPI GetWindowTextLengthW( HWND hwnd )
2330 return SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 );
2334 /*******************************************************************
2335 * IsWindow (USER32.@)
2337 BOOL WINAPI IsWindow( HWND hwnd )
2342 if (!(ptr = WIN_GetPtr( hwnd ))) return FALSE;
2343 if (ptr == WND_DESKTOP) return TRUE;
2345 if (ptr != WND_OTHER_PROCESS)
2347 WIN_ReleasePtr( ptr );
2351 /* check other processes */
2352 SERVER_START_REQ( get_window_info )
2355 ret = !wine_server_call_err( req );
2362 /***********************************************************************
2363 * GetWindowThreadProcessId (USER32.@)
2365 DWORD WINAPI GetWindowThreadProcessId( HWND hwnd, LPDWORD process )
2370 if (!(ptr = WIN_GetPtr( hwnd )))
2372 SetLastError( ERROR_INVALID_WINDOW_HANDLE);
2376 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP)
2378 /* got a valid window */
2380 if (process) *process = GetCurrentProcessId();
2381 WIN_ReleasePtr( ptr );
2385 /* check other processes */
2386 SERVER_START_REQ( get_window_info )
2389 if (!wine_server_call_err( req ))
2391 tid = (DWORD)reply->tid;
2392 if (process) *process = (DWORD)reply->pid;
2400 /*****************************************************************
2401 * GetParent (USER32.@)
2403 HWND WINAPI GetParent( HWND hwnd )
2408 if (!(wndPtr = WIN_GetPtr( hwnd )))
2410 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2413 if (wndPtr == WND_DESKTOP) return 0;
2414 if (wndPtr == WND_OTHER_PROCESS)
2416 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2417 if (style & (WS_POPUP | WS_CHILD))
2419 SERVER_START_REQ( get_window_tree )
2422 if (!wine_server_call_err( req ))
2424 if (style & WS_POPUP) retvalue = reply->owner;
2425 else if (style & WS_CHILD) retvalue = reply->parent;
2433 if (wndPtr->dwStyle & WS_POPUP) retvalue = wndPtr->owner;
2434 else if (wndPtr->dwStyle & WS_CHILD) retvalue = wndPtr->parent;
2435 WIN_ReleasePtr( wndPtr );
2441 /*****************************************************************
2442 * GetAncestor (USER32.@)
2444 HWND WINAPI GetAncestor( HWND hwnd, UINT type )
2447 HWND *list, ret = 0;
2452 if (!(win = WIN_GetPtr( hwnd )))
2454 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2457 if (win == WND_DESKTOP) return 0;
2458 if (win != WND_OTHER_PROCESS)
2461 WIN_ReleasePtr( win );
2463 else /* need to query the server */
2465 SERVER_START_REQ( get_window_tree )
2468 if (!wine_server_call_err( req )) ret = reply->parent;
2475 if (!(list = list_window_parents( hwnd ))) return 0;
2477 if (!list[0] || !list[1]) ret = WIN_GetFullHandle( hwnd ); /* top-level window */
2481 while (list[count]) count++;
2482 ret = list[count - 2]; /* get the one before the desktop */
2484 HeapFree( GetProcessHeap(), 0, list );
2488 if ((ret = WIN_GetFullHandle( hwnd )) == GetDesktopWindow()) return 0;
2491 HWND parent = GetParent( ret );
2501 /*****************************************************************
2502 * SetParent (USER32.@)
2504 HWND WINAPI SetParent( HWND hwnd, HWND parent )
2508 if (is_broadcast(hwnd) || is_broadcast(parent))
2510 SetLastError(ERROR_INVALID_PARAMETER);
2514 if (!parent) parent = GetDesktopWindow();
2515 else parent = WIN_GetFullHandle( parent );
2517 if (!IsWindow( parent ))
2519 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2523 /* Some applications try to set a child as a parent */
2524 if (IsChild(hwnd, parent))
2526 SetLastError( ERROR_INVALID_PARAMETER );
2530 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
2531 return (HWND)SendMessageW( hwnd, WM_WINE_SETPARENT, (WPARAM)parent, 0 );
2533 if (USER_Driver.pSetParent)
2534 return USER_Driver.pSetParent( full_handle, parent );
2540 /*******************************************************************
2541 * IsChild (USER32.@)
2543 BOOL WINAPI IsChild( HWND parent, HWND child )
2545 HWND *list = list_window_parents( child );
2549 if (!list) return FALSE;
2550 parent = WIN_GetFullHandle( parent );
2551 for (i = 0; list[i]; i++) if (list[i] == parent) break;
2552 ret = (list[i] != 0);
2553 HeapFree( GetProcessHeap(), 0, list );
2558 /***********************************************************************
2559 * IsWindowVisible (USER32.@)
2561 BOOL WINAPI IsWindowVisible( HWND hwnd )
2567 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) return FALSE;
2568 if (!(list = list_window_parents( hwnd ))) return TRUE;
2569 for (i = 0; list[i]; i++)
2570 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) break;
2572 HeapFree( GetProcessHeap(), 0, list );
2577 /***********************************************************************
2578 * WIN_IsWindowDrawable
2580 * hwnd is drawable when it is visible, all parents are not
2581 * minimized, and it is itself not minimized unless we are
2582 * trying to draw its default class icon.
2584 BOOL WIN_IsWindowDrawable( HWND hwnd, BOOL icon )
2589 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2591 if (!(style & WS_VISIBLE)) return FALSE;
2592 if ((style & WS_MINIMIZE) && icon && GetClassLongPtrW( hwnd, GCLP_HICON )) return FALSE;
2594 if (!(list = list_window_parents( hwnd ))) return TRUE;
2595 for (i = 0; list[i]; i++)
2596 if ((GetWindowLongW( list[i], GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != WS_VISIBLE)
2599 HeapFree( GetProcessHeap(), 0, list );
2604 /*******************************************************************
2605 * GetTopWindow (USER32.@)
2607 HWND WINAPI GetTopWindow( HWND hwnd )
2609 if (!hwnd) hwnd = GetDesktopWindow();
2610 return GetWindow( hwnd, GW_CHILD );
2614 /*******************************************************************
2615 * GetWindow (USER32.@)
2617 HWND WINAPI GetWindow( HWND hwnd, UINT rel )
2621 if (rel == GW_OWNER) /* this one may be available locally */
2623 WND *wndPtr = WIN_GetPtr( hwnd );
2626 SetLastError( ERROR_INVALID_HANDLE );
2629 if (wndPtr == WND_DESKTOP) return 0;
2630 if (wndPtr != WND_OTHER_PROCESS)
2632 retval = wndPtr->owner;
2633 WIN_ReleasePtr( wndPtr );
2636 /* else fall through to server call */
2639 SERVER_START_REQ( get_window_tree )
2642 if (!wine_server_call_err( req ))
2647 retval = reply->first_sibling;
2650 retval = reply->last_sibling;
2653 retval = reply->next_sibling;
2656 retval = reply->prev_sibling;
2659 retval = reply->owner;
2662 retval = reply->first_child;
2672 /*******************************************************************
2673 * ShowOwnedPopups (USER32.@)
2675 BOOL WINAPI ShowOwnedPopups( HWND owner, BOOL fShow )
2679 HWND *win_array = WIN_ListChildren( GetDesktopWindow() );
2681 if (!win_array) return TRUE;
2683 while (win_array[count]) count++;
2684 while (--count >= 0)
2686 if (GetWindow( win_array[count], GW_OWNER ) != owner) continue;
2687 if (!(pWnd = WIN_GetPtr( win_array[count] ))) continue;
2688 if (pWnd == WND_OTHER_PROCESS) continue;
2691 if (pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP)
2693 WIN_ReleasePtr( pWnd );
2694 /* In Windows, ShowOwnedPopups(TRUE) generates
2695 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
2696 * regardless of the state of the owner
2698 SendMessageW(win_array[count], WM_SHOWWINDOW, SW_SHOWNORMAL, SW_PARENTOPENING);
2704 if (pWnd->dwStyle & WS_VISIBLE)
2706 WIN_ReleasePtr( pWnd );
2707 /* In Windows, ShowOwnedPopups(FALSE) generates
2708 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
2709 * regardless of the state of the owner
2711 SendMessageW(win_array[count], WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
2715 WIN_ReleasePtr( pWnd );
2717 HeapFree( GetProcessHeap(), 0, win_array );
2722 /*******************************************************************
2723 * GetLastActivePopup (USER32.@)
2725 HWND WINAPI GetLastActivePopup( HWND hwnd )
2729 SERVER_START_REQ( get_window_info )
2732 if (!wine_server_call_err( req )) retval = reply->last_active;
2739 /*******************************************************************
2742 * Build an array of the children of a given window. The array must be
2743 * freed with HeapFree. Returns NULL when no windows are found.
2745 HWND *WIN_ListChildren( HWND hwnd )
2747 return list_window_children( hwnd, 0, 0 );
2751 /*******************************************************************
2752 * EnumWindows (USER32.@)
2754 BOOL WINAPI EnumWindows( WNDENUMPROC lpEnumFunc, LPARAM lParam )
2760 USER_CheckNotLock();
2762 /* We have to build a list of all windows first, to avoid */
2763 /* unpleasant side-effects, for instance if the callback */
2764 /* function changes the Z-order of the windows. */
2766 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return TRUE;
2768 /* Now call the callback function for every window */
2770 for (i = 0; list[i]; i++)
2772 /* Make sure that the window still exists */
2773 if (!IsWindow( list[i] )) continue;
2774 if (!(ret = lpEnumFunc( list[i], lParam ))) break;
2776 HeapFree( GetProcessHeap(), 0, list );
2781 /**********************************************************************
2782 * EnumThreadWindows (USER32.@)
2784 BOOL WINAPI EnumThreadWindows( DWORD id, WNDENUMPROC func, LPARAM lParam )
2789 USER_CheckNotLock();
2791 if (!(list = list_window_children( GetDesktopWindow(), 0, id ))) return TRUE;
2793 /* Now call the callback function for every window */
2795 for (i = 0; list[i]; i++)
2796 if (!func( list[i], lParam )) break;
2797 HeapFree( GetProcessHeap(), 0, list );
2802 /**********************************************************************
2803 * WIN_EnumChildWindows
2805 * Helper function for EnumChildWindows().
2807 static BOOL WIN_EnumChildWindows( HWND *list, WNDENUMPROC func, LPARAM lParam )
2812 for ( ; *list; list++)
2814 /* Make sure that the window still exists */
2815 if (!IsWindow( *list )) continue;
2816 /* skip owned windows */
2817 if (GetWindow( *list, GW_OWNER )) continue;
2818 /* Build children list first */
2819 childList = WIN_ListChildren( *list );
2821 ret = func( *list, lParam );
2825 if (ret) ret = WIN_EnumChildWindows( childList, func, lParam );
2826 HeapFree( GetProcessHeap(), 0, childList );
2828 if (!ret) return FALSE;
2834 /**********************************************************************
2835 * EnumChildWindows (USER32.@)
2837 BOOL WINAPI EnumChildWindows( HWND parent, WNDENUMPROC func, LPARAM lParam )
2841 USER_CheckNotLock();
2843 if (!(list = WIN_ListChildren( parent ))) return FALSE;
2844 WIN_EnumChildWindows( list, func, lParam );
2845 HeapFree( GetProcessHeap(), 0, list );
2850 /*******************************************************************
2851 * AnyPopup (USER.52)
2853 BOOL16 WINAPI AnyPopup16(void)
2859 /*******************************************************************
2860 * AnyPopup (USER32.@)
2862 BOOL WINAPI AnyPopup(void)
2866 HWND *list = WIN_ListChildren( GetDesktopWindow() );
2868 if (!list) return FALSE;
2869 for (i = 0; list[i]; i++)
2871 if (IsWindowVisible( list[i] ) && GetWindow( list[i], GW_OWNER )) break;
2873 retvalue = (list[i] != 0);
2874 HeapFree( GetProcessHeap(), 0, list );
2879 /*******************************************************************
2880 * FlashWindow (USER32.@)
2882 BOOL WINAPI FlashWindow( HWND hWnd, BOOL bInvert )
2886 TRACE("%p\n", hWnd);
2888 if (IsIconic( hWnd ))
2890 RedrawWindow( hWnd, 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_FRAME );
2892 wndPtr = WIN_GetPtr(hWnd);
2893 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
2894 if (bInvert && !(wndPtr->flags & WIN_NCACTIVATED))
2896 wndPtr->flags |= WIN_NCACTIVATED;
2900 wndPtr->flags &= ~WIN_NCACTIVATED;
2902 WIN_ReleasePtr( wndPtr );
2909 wndPtr = WIN_GetPtr(hWnd);
2910 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
2911 hWnd = wndPtr->hwndSelf; /* make it a full handle */
2913 if (bInvert) wparam = !(wndPtr->flags & WIN_NCACTIVATED);
2914 else wparam = (hWnd == GetForegroundWindow());
2916 WIN_ReleasePtr( wndPtr );
2917 SendMessageW( hWnd, WM_NCACTIVATE, wparam, (LPARAM)0 );
2922 /*******************************************************************
2923 * FlashWindowEx (USER32.@)
2925 BOOL WINAPI FlashWindowEx( PFLASHWINFO pfwi )
2927 FIXME("%p\n", pfwi);
2931 /*******************************************************************
2932 * GetWindowContextHelpId (USER32.@)
2934 DWORD WINAPI GetWindowContextHelpId( HWND hwnd )
2937 WND *wnd = WIN_GetPtr( hwnd );
2938 if (!wnd || wnd == WND_DESKTOP) return 0;
2939 if (wnd == WND_OTHER_PROCESS)
2941 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
2944 retval = wnd->helpContext;
2945 WIN_ReleasePtr( wnd );
2950 /*******************************************************************
2951 * SetWindowContextHelpId (USER32.@)
2953 BOOL WINAPI SetWindowContextHelpId( HWND hwnd, DWORD id )
2955 WND *wnd = WIN_GetPtr( hwnd );
2956 if (!wnd || wnd == WND_DESKTOP) return FALSE;
2957 if (wnd == WND_OTHER_PROCESS)
2959 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
2962 wnd->helpContext = id;
2963 WIN_ReleasePtr( wnd );
2968 /*******************************************************************
2969 * DragDetect (USER32.@)
2971 BOOL WINAPI DragDetect( HWND hWnd, POINT pt )
2976 rect.left = pt.x - wDragWidth;
2977 rect.right = pt.x + wDragWidth;
2979 rect.top = pt.y - wDragHeight;
2980 rect.bottom = pt.y + wDragHeight;
2986 while (PeekMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ))
2988 if( msg.message == WM_LBUTTONUP )
2993 if( msg.message == WM_MOUSEMOVE )
2996 tmp.x = LOWORD(msg.lParam);
2997 tmp.y = HIWORD(msg.lParam);
2998 if( !PtInRect( &rect, tmp ))
3010 /******************************************************************************
3011 * GetWindowModuleFileNameA (USER32.@)
3013 UINT WINAPI GetWindowModuleFileNameA( HWND hwnd, LPSTR lpszFileName, UINT cchFileNameMax)
3015 FIXME("GetWindowModuleFileNameA(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3016 hwnd, lpszFileName, cchFileNameMax);
3020 /******************************************************************************
3021 * GetWindowModuleFileNameW (USER32.@)
3023 UINT WINAPI GetWindowModuleFileNameW( HWND hwnd, LPWSTR lpszFileName, UINT cchFileNameMax)
3025 FIXME("GetWindowModuleFileNameW(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3026 hwnd, lpszFileName, cchFileNameMax);
3030 /******************************************************************************
3031 * GetWindowInfo (USER32.@)
3033 * Note: tests show that Windows doesn't check cbSize of the structure.
3035 BOOL WINAPI GetWindowInfo( HWND hwnd, PWINDOWINFO pwi)
3037 if (!pwi) return FALSE;
3038 if (!IsWindow(hwnd)) return FALSE;
3040 GetWindowRect(hwnd, &pwi->rcWindow);
3041 GetClientRect(hwnd, &pwi->rcClient);
3042 /* translate to screen coordinates */
3043 MapWindowPoints(hwnd, 0, (LPPOINT)&pwi->rcClient, 2);
3045 pwi->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
3046 pwi->dwExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
3047 pwi->dwWindowStatus = ((GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0);
3049 pwi->cxWindowBorders = pwi->rcClient.left - pwi->rcWindow.left;
3050 pwi->cyWindowBorders = pwi->rcWindow.bottom - pwi->rcClient.bottom;
3052 pwi->atomWindowType = GetClassLongW( hwnd, GCW_ATOM );
3053 pwi->wCreatorVersion = 0x0400;
3058 /******************************************************************************
3059 * SwitchDesktop (USER32.@)
3061 * NOTES: Sets the current input or interactive desktop.
3063 BOOL WINAPI SwitchDesktop( HDESK hDesktop)
3065 FIXME("SwitchDesktop(hwnd %p) stub!\n", hDesktop);