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 /**********************************************************************/
50 static WORD wDragWidth = 4;
51 static WORD wDragHeight= 3;
53 static void *user_handles[NB_USER_HANDLES];
55 /***********************************************************************
56 * create_window_handle
58 * Create a window handle with the server.
60 static WND *create_window_handle( HWND parent, HWND owner, ATOM atom,
61 HINSTANCE instance, WINDOWPROCTYPE type )
65 struct tagCLASS *class = NULL;
66 user_handle_t handle = 0;
69 /* if 16-bit instance, map to module handle */
70 if (instance && !HIWORD(instance))
71 instance = HINSTANCE_32(GetExePtr(HINSTANCE_16(instance)));
73 SERVER_START_REQ( create_window )
78 req->instance = instance;
79 if (!wine_server_call_err( req ))
81 handle = reply->handle;
82 extra_bytes = reply->extra;
83 class = reply->class_ptr;
90 WARN( "error %ld creating window\n", GetLastError() );
94 if (!(win = HeapAlloc( GetProcessHeap(), 0, sizeof(WND) + extra_bytes - sizeof(win->wExtra) )))
96 SERVER_START_REQ( destroy_window )
99 wine_server_call( req );
102 SetLastError( ERROR_NOT_ENOUGH_MEMORY );
108 index = USER_HANDLE_TO_INDEX(handle);
109 assert( index < NB_USER_HANDLES );
110 user_handles[index] = win;
111 win->hwndSelf = handle;
112 win->dwMagic = WND_MAGIC;
113 win->cbWndExtra = extra_bytes;
114 memset( win->wExtra, 0, extra_bytes );
115 CLASS_AddWindow( class, win, type );
120 /***********************************************************************
123 * Free a window handle.
125 static WND *free_window_handle( HWND hwnd )
128 WORD index = USER_HANDLE_TO_INDEX(hwnd);
130 if (index >= NB_USER_HANDLES) return NULL;
132 if ((ptr = user_handles[index]))
134 SERVER_START_REQ( destroy_window )
137 if (!wine_server_call_err( req ))
139 user_handles[index] = NULL;
148 HeapFree( GetProcessHeap(), 0, ptr );
153 /*******************************************************************
154 * list_window_children
156 * Build an array of the children of a given window. The array must be
157 * freed with HeapFree. Returns NULL when no windows are found.
159 static HWND *list_window_children( HWND hwnd, ATOM atom, DWORD tid )
168 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
170 SERVER_START_REQ( get_window_children )
175 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
176 if (!wine_server_call( req )) count = reply->count;
179 if (count && count < size)
184 HeapFree( GetProcessHeap(), 0, list );
186 size = count + 1; /* restart with a large enough buffer */
192 /*******************************************************************
193 * list_window_parents
195 * Build an array of all parents of a given window, starting with
196 * the immediate parent. The array must be freed with HeapFree.
197 * Returns NULL if window is a top-level window.
199 static HWND *list_window_parents( HWND hwnd )
203 int pos = 0, size = 16, count = 0;
205 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) return NULL;
210 if (!(win = WIN_GetPtr( current ))) goto empty;
211 if (win == WND_OTHER_PROCESS) break; /* need to do it the hard way */
212 if (win == WND_DESKTOP)
214 if (!pos) goto empty;
218 list[pos] = current = win->parent;
219 WIN_ReleasePtr( win );
220 if (++pos == size - 1)
222 /* need to grow the list */
223 HWND *new_list = HeapReAlloc( GetProcessHeap(), 0, list, (size+16) * sizeof(HWND) );
224 if (!new_list) goto empty;
230 /* at least one parent belongs to another process, have to query the server */
235 SERVER_START_REQ( get_window_parents )
238 wine_server_set_reply( req, list, (size-1) * sizeof(HWND) );
239 if (!wine_server_call( req )) count = reply->count;
242 if (!count) goto empty;
248 HeapFree( GetProcessHeap(), 0, list );
250 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) return NULL;
254 HeapFree( GetProcessHeap(), 0, list );
259 /*******************************************************************
262 static void send_parent_notify( HWND hwnd, UINT msg )
264 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD &&
265 !(GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_NOPARENTNOTIFY))
266 SendMessageW( GetParent(hwnd), WM_PARENTNOTIFY,
267 MAKEWPARAM( msg, GetWindowLongPtrW( hwnd, GWLP_ID )), (LPARAM)hwnd );
271 /*******************************************************************
272 * get_server_window_text
274 * Retrieve the window text from the server.
276 static void get_server_window_text( HWND hwnd, LPWSTR text, INT count )
280 SERVER_START_REQ( get_window_text )
283 wine_server_set_reply( req, text, (count - 1) * sizeof(WCHAR) );
284 if (!wine_server_call_err( req )) len = wine_server_reply_size(reply);
287 text[len / sizeof(WCHAR)] = 0;
291 /***********************************************************************
294 * Return a pointer to the WND structure if local to the process,
295 * or WND_OTHER_PROCESS if handle may be valid in other process.
296 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
298 WND *WIN_GetPtr( HWND hwnd )
301 WORD index = USER_HANDLE_TO_INDEX(hwnd);
303 if (index >= NB_USER_HANDLES) return NULL;
306 if ((ptr = user_handles[index]))
308 if (ptr->dwMagic == WND_MAGIC &&
309 (hwnd == ptr->hwndSelf || !HIWORD(hwnd) || HIWORD(hwnd) == 0xffff))
313 else if (index == USER_HANDLE_TO_INDEX(GetDesktopWindow()))
315 if (hwnd == GetDesktopWindow() || !HIWORD(hwnd) || HIWORD(hwnd) == 0xffff) ptr = WND_DESKTOP;
318 else ptr = WND_OTHER_PROCESS;
324 /***********************************************************************
325 * WIN_IsCurrentProcess
327 * Check whether a given window belongs to the current process (and return the full handle).
329 HWND WIN_IsCurrentProcess( HWND hwnd )
334 if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0;
336 WIN_ReleasePtr( ptr );
341 /***********************************************************************
342 * WIN_IsCurrentThread
344 * Check whether a given window belongs to the current thread (and return the full handle).
346 HWND WIN_IsCurrentThread( HWND hwnd )
351 if (!(ptr = WIN_GetPtr( hwnd )) || ptr == WND_OTHER_PROCESS || ptr == WND_DESKTOP) return 0;
352 if (ptr->tid == GetCurrentThreadId()) ret = ptr->hwndSelf;
353 WIN_ReleasePtr( ptr );
358 /***********************************************************************
361 * Convert a 16-bit window handle to a full 32-bit handle.
363 HWND WIN_Handle32( HWND16 hwnd16 )
366 HWND hwnd = (HWND)(ULONG_PTR)hwnd16;
368 if (hwnd16 <= 1 || hwnd16 == 0xffff) return hwnd;
369 /* do sign extension for -2 and -3 */
370 if (hwnd16 >= (HWND16)-3) return (HWND)(LONG_PTR)(INT16)hwnd16;
372 if (!(ptr = WIN_GetPtr( hwnd ))) return hwnd;
374 if (ptr == WND_DESKTOP) return GetDesktopWindow();
376 if (ptr != WND_OTHER_PROCESS)
378 hwnd = ptr->hwndSelf;
379 WIN_ReleasePtr( ptr );
381 else /* may belong to another process */
383 SERVER_START_REQ( get_window_info )
386 if (!wine_server_call_err( req )) hwnd = reply->full_handle;
394 /***********************************************************************
397 * Change the owner of a window.
399 HWND WIN_SetOwner( HWND hwnd, HWND owner )
401 WND *win = WIN_GetPtr( hwnd );
404 if (!win || win == WND_DESKTOP) return 0;
405 if (win == WND_OTHER_PROCESS)
407 if (IsWindow(hwnd)) ERR( "cannot set owner %p on other process window %p\n", owner, hwnd );
410 SERVER_START_REQ( set_window_owner )
414 if (!wine_server_call( req ))
416 win->owner = reply->full_owner;
417 ret = reply->prev_owner;
421 WIN_ReleasePtr( win );
426 /***********************************************************************
429 * Change the style of a window.
431 ULONG WIN_SetStyle( HWND hwnd, ULONG set_bits, ULONG clear_bits )
434 ULONG new_style, old_style = 0;
435 WND *win = WIN_GetPtr( hwnd );
437 if (!win || win == WND_DESKTOP) return 0;
438 if (win == WND_OTHER_PROCESS)
441 ERR( "cannot set style %lx/%lx on other process window %p\n",
442 set_bits, clear_bits, hwnd );
445 new_style = (win->dwStyle | set_bits) & ~clear_bits;
446 if (new_style == win->dwStyle)
448 WIN_ReleasePtr( win );
451 SERVER_START_REQ( set_window_info )
454 req->flags = SET_WIN_STYLE;
455 req->style = new_style;
456 req->extra_offset = -1;
457 if ((ok = !wine_server_call( req )))
459 old_style = reply->old_style;
460 win->dwStyle = new_style;
464 WIN_ReleasePtr( win );
465 if (ok) USER_Driver->pSetWindowStyle( hwnd, old_style );
470 /***********************************************************************
473 * Get the window and client rectangles.
475 BOOL WIN_GetRectangles( HWND hwnd, RECT *rectWindow, RECT *rectClient )
477 WND *win = WIN_GetPtr( hwnd );
480 if (!win) return FALSE;
481 if (win == WND_DESKTOP)
484 rect.left = rect.top = 0;
485 rect.right = GetSystemMetrics(SM_CXSCREEN);
486 rect.bottom = GetSystemMetrics(SM_CYSCREEN);
487 if (rectWindow) *rectWindow = rect;
488 if (rectClient) *rectClient = rect;
490 else if (win == WND_OTHER_PROCESS)
492 SERVER_START_REQ( get_window_rectangles )
495 if ((ret = !wine_server_call( req )))
499 rectWindow->left = reply->window.left;
500 rectWindow->top = reply->window.top;
501 rectWindow->right = reply->window.right;
502 rectWindow->bottom = reply->window.bottom;
506 rectClient->left = reply->client.left;
507 rectClient->top = reply->client.top;
508 rectClient->right = reply->client.right;
509 rectClient->bottom = reply->client.bottom;
517 if (rectWindow) *rectWindow = win->rectWindow;
518 if (rectClient) *rectClient = win->rectClient;
519 WIN_ReleasePtr( win );
525 /***********************************************************************
528 * Destroy storage associated to a window. "Internals" p.358
530 LRESULT WIN_DestroyWindow( HWND hwnd )
534 HMENU menu = 0, sys_menu;
536 TRACE("%p\n", hwnd );
538 /* free child windows */
539 if ((list = WIN_ListChildren( hwnd )))
542 for (i = 0; list[i]; i++)
544 if (WIN_IsCurrentThread( list[i] )) WIN_DestroyWindow( list[i] );
545 else SendMessageW( list[i], WM_WINE_DESTROYWINDOW, 0, 0 );
547 HeapFree( GetProcessHeap(), 0, list );
550 /* Unlink now so we won't bother with the children later on */
551 SERVER_START_REQ( set_parent )
555 wine_server_call( req );
560 * Send the WM_NCDESTROY to the window being destroyed.
562 SendMessageW( hwnd, WM_NCDESTROY, 0, 0 );
564 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
566 WINPOS_CheckInternalPos( hwnd );
568 /* free resources associated with the window */
570 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
571 if (!(wndPtr->dwStyle & WS_CHILD)) menu = (HMENU)wndPtr->wIDmenu;
572 sys_menu = wndPtr->hSysMenu;
573 WIN_ReleasePtr( wndPtr );
575 if (menu) DestroyMenu( menu );
576 if (sys_menu) DestroyMenu( sys_menu );
578 USER_Driver->pDestroyWindow( hwnd );
580 free_window_handle( hwnd );
584 /***********************************************************************
585 * WIN_DestroyThreadWindows
587 * Destroy all children of 'wnd' owned by the current thread.
588 * Return TRUE if something was done.
590 void WIN_DestroyThreadWindows( HWND hwnd )
595 if (!(list = WIN_ListChildren( hwnd ))) return;
596 for (i = 0; list[i]; i++)
598 if (WIN_IsCurrentThread( list[i] ))
599 DestroyWindow( list[i] );
601 WIN_DestroyThreadWindows( list[i] );
603 HeapFree( GetProcessHeap(), 0, list );
607 /***********************************************************************
610 * Fix the coordinates - Helper for WIN_CreateWindowEx.
611 * returns default show mode in sw.
612 * Note: the feature presented as undocumented *is* in the MSDN since 1993.
614 static void WIN_FixCoordinates( CREATESTRUCTA *cs, INT *sw)
618 if (cs->dwExStyle & WS_EX_MDICHILD)
622 MDI_CalcDefaultChildPos(cs->hwndParent, -1, pos, 0, &id);
623 if (!(cs->style & WS_POPUP)) cs->hMenu = (HMENU)id;
625 TRACE("MDI child id %04x\n", id);
628 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16 ||
629 cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
631 if (cs->style & (WS_CHILD | WS_POPUP))
633 if (cs->dwExStyle & WS_EX_MDICHILD)
635 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
640 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16 || !cs->cx)
642 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16 || !cs->cy)
647 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
649 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
653 else /* overlapped window */
657 GetStartupInfoW( &info );
659 if (cs->x == CW_USEDEFAULT || cs->x == CW_USEDEFAULT16)
661 /* Never believe Microsoft's documentation... CreateWindowEx doc says
662 * that if an overlapped window is created with WS_VISIBLE style bit
663 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
664 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
667 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
668 * 2) it does not ignore the y parameter as the docs claim; instead, it
669 * uses it as second parameter to ShowWindow() unless y is either
670 * CW_USEDEFAULT or CW_USEDEFAULT16.
672 * The fact that we didn't do 2) caused bogus windows pop up when wine
673 * was running apps that were using this obscure feature. Example -
674 * calc.exe that comes with Win98 (only Win98, it's different from
675 * the one that comes with Win95 and NT)
677 if (cs->y != CW_USEDEFAULT && cs->y != CW_USEDEFAULT16) *sw = cs->y;
678 cs->x = (info.dwFlags & STARTF_USEPOSITION) ? info.dwX : 0;
679 cs->y = (info.dwFlags & STARTF_USEPOSITION) ? info.dwY : 0;
682 if (cs->cx == CW_USEDEFAULT || cs->cx == CW_USEDEFAULT16)
684 if (info.dwFlags & STARTF_USESIZE)
686 cs->cx = info.dwXSize;
687 cs->cy = info.dwYSize;
689 else /* if no other hint from the app, pick 3/4 of the screen real estate */
692 SystemParametersInfoW( SPI_GETWORKAREA, 0, &r, 0);
693 cs->cx = (((r.right - r.left) * 3) / 4) - cs->x;
694 cs->cy = (((r.bottom - r.top) * 3) / 4) - cs->y;
697 /* Handle case where only the cy values is set to default */
698 else if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16)
701 SystemParametersInfoW( SPI_GETWORKAREA, 0, &r, 0);
702 cs->cy = (((r.bottom - r.top) * 3) / 4) - cs->y;
708 /* neither x nor cx are default. Check the y values .
709 * In the trace we see Outlook and Outlook Express using
710 * cy set to CW_USEDEFAULT when opening the address book.
712 if (cs->cy == CW_USEDEFAULT || cs->cy == CW_USEDEFAULT16) {
714 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
715 SystemParametersInfoW( SPI_GETWORKAREA, 0, &r, 0);
716 cs->cy = (((r.bottom - r.top) * 3) / 4) - cs->y;
721 /***********************************************************************
724 static void dump_window_styles( DWORD style, DWORD exstyle )
727 if(style & WS_POPUP) TRACE(" WS_POPUP");
728 if(style & WS_CHILD) TRACE(" WS_CHILD");
729 if(style & WS_MINIMIZE) TRACE(" WS_MINIMIZE");
730 if(style & WS_VISIBLE) TRACE(" WS_VISIBLE");
731 if(style & WS_DISABLED) TRACE(" WS_DISABLED");
732 if(style & WS_CLIPSIBLINGS) TRACE(" WS_CLIPSIBLINGS");
733 if(style & WS_CLIPCHILDREN) TRACE(" WS_CLIPCHILDREN");
734 if(style & WS_MAXIMIZE) TRACE(" WS_MAXIMIZE");
735 if((style & WS_CAPTION) == WS_CAPTION) TRACE(" WS_CAPTION");
738 if(style & WS_BORDER) TRACE(" WS_BORDER");
739 if(style & WS_DLGFRAME) TRACE(" WS_DLGFRAME");
741 if(style & WS_VSCROLL) TRACE(" WS_VSCROLL");
742 if(style & WS_HSCROLL) TRACE(" WS_HSCROLL");
743 if(style & WS_SYSMENU) TRACE(" WS_SYSMENU");
744 if(style & WS_THICKFRAME) TRACE(" WS_THICKFRAME");
745 if(style & WS_GROUP) TRACE(" WS_GROUP");
746 if(style & WS_TABSTOP) TRACE(" WS_TABSTOP");
747 if(style & WS_MINIMIZEBOX) TRACE(" WS_MINIMIZEBOX");
748 if(style & WS_MAXIMIZEBOX) TRACE(" WS_MAXIMIZEBOX");
750 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
751 #define DUMPED_STYLES \
771 if(style & ~DUMPED_STYLES) TRACE(" %08lx", style & ~DUMPED_STYLES);
776 if(exstyle & WS_EX_DLGMODALFRAME) TRACE(" WS_EX_DLGMODALFRAME");
777 if(exstyle & WS_EX_DRAGDETECT) TRACE(" WS_EX_DRAGDETECT");
778 if(exstyle & WS_EX_NOPARENTNOTIFY) TRACE(" WS_EX_NOPARENTNOTIFY");
779 if(exstyle & WS_EX_TOPMOST) TRACE(" WS_EX_TOPMOST");
780 if(exstyle & WS_EX_ACCEPTFILES) TRACE(" WS_EX_ACCEPTFILES");
781 if(exstyle & WS_EX_TRANSPARENT) TRACE(" WS_EX_TRANSPARENT");
782 if(exstyle & WS_EX_MDICHILD) TRACE(" WS_EX_MDICHILD");
783 if(exstyle & WS_EX_TOOLWINDOW) TRACE(" WS_EX_TOOLWINDOW");
784 if(exstyle & WS_EX_WINDOWEDGE) TRACE(" WS_EX_WINDOWEDGE");
785 if(exstyle & WS_EX_CLIENTEDGE) TRACE(" WS_EX_CLIENTEDGE");
786 if(exstyle & WS_EX_CONTEXTHELP) TRACE(" WS_EX_CONTEXTHELP");
787 if(exstyle & WS_EX_RIGHT) TRACE(" WS_EX_RIGHT");
788 if(exstyle & WS_EX_RTLREADING) TRACE(" WS_EX_RTLREADING");
789 if(exstyle & WS_EX_LEFTSCROLLBAR) TRACE(" WS_EX_LEFTSCROLLBAR");
790 if(exstyle & WS_EX_CONTROLPARENT) TRACE(" WS_EX_CONTROLPARENT");
791 if(exstyle & WS_EX_STATICEDGE) TRACE(" WS_EX_STATICEDGE");
792 if(exstyle & WS_EX_APPWINDOW) TRACE(" WS_EX_APPWINDOW");
793 if(exstyle & WS_EX_LAYERED) TRACE(" WS_EX_LAYERED");
795 #define DUMPED_EX_STYLES \
796 (WS_EX_DLGMODALFRAME | \
798 WS_EX_NOPARENTNOTIFY | \
800 WS_EX_ACCEPTFILES | \
801 WS_EX_TRANSPARENT | \
806 WS_EX_CONTEXTHELP | \
809 WS_EX_LEFTSCROLLBAR | \
810 WS_EX_CONTROLPARENT | \
815 if(exstyle & ~DUMPED_EX_STYLES) TRACE(" %08lx", exstyle & ~DUMPED_EX_STYLES);
817 #undef DUMPED_EX_STYLES
821 /***********************************************************************
824 * Implementation of CreateWindowEx().
826 static HWND WIN_CreateWindowEx( CREATESTRUCTA *cs, ATOM classAtom,
827 WINDOWPROCTYPE type )
831 HWND hwnd, parent, owner, top_child = 0;
832 BOOL unicode = (type == WIN_PROC_32W);
834 TRACE("%s %s ex=%08lx style=%08lx %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
835 (type == WIN_PROC_32W) ? debugstr_w((LPCWSTR)cs->lpszName) : debugstr_a(cs->lpszName),
836 (type == WIN_PROC_32W) ? debugstr_w((LPCWSTR)cs->lpszClass) : debugstr_a(cs->lpszClass),
837 cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
838 cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams );
840 if(TRACE_ON(win)) dump_window_styles( cs->style, cs->dwExStyle );
842 TRACE("winproc type is %d (%s)\n", type, (type == WIN_PROC_16) ? "WIN_PROC_16" :
843 ((type == WIN_PROC_32A) ? "WIN_PROC_32A" : "WIN_PROC_32W") );
845 /* Fix the styles for MDI children */
846 if (cs->dwExStyle & WS_EX_MDICHILD)
848 MDICREATESTRUCTA mdi_cs;
851 wndPtr = WIN_GetPtr(cs->hwndParent);
852 if (wndPtr && wndPtr != WND_OTHER_PROCESS && wndPtr != WND_DESKTOP)
854 flags = wndPtr->flags;
855 WIN_ReleasePtr(wndPtr);
858 if (!(flags & WIN_ISMDICLIENT))
860 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs->hwndParent);
864 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
865 * MDICREATESTRUCT members have the originally passed values.
867 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
868 * have the same layout.
870 mdi_cs.szClass = cs->lpszClass;
871 mdi_cs.szTitle = cs->lpszName;
872 mdi_cs.hOwner = cs->hInstance;
877 mdi_cs.style = cs->style;
878 mdi_cs.lParam = (LPARAM)cs->lpCreateParams;
880 cs->lpCreateParams = (LPVOID)&mdi_cs;
882 if (GetWindowLongW(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
884 if (cs->style & WS_POPUP)
886 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
889 cs->style |= WS_CHILD | WS_CLIPSIBLINGS;
893 cs->style &= ~WS_POPUP;
894 cs->style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
895 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
898 top_child = GetWindow(cs->hwndParent, GW_CHILD);
902 /* Restore current maximized child */
903 if((cs->style & WS_VISIBLE) && IsZoomed(top_child))
905 TRACE("Restoring current maximized child %p\n", top_child);
906 SendMessageW( top_child, WM_SETREDRAW, FALSE, 0 );
907 ShowWindow(top_child, SW_RESTORE);
908 SendMessageW( top_child, WM_SETREDRAW, TRUE, 0 );
913 /* Find the parent window */
915 parent = GetDesktopWindow();
918 if (cs->hwndParent == HWND_MESSAGE)
920 /* native ole32.OleInitialize uses HWND_MESSAGE to create the
921 * message window (style: WS_POPUP|WS_DISABLED)
923 FIXME("Parent is HWND_MESSAGE\n");
925 else if (cs->hwndParent)
927 /* Make sure parent is valid */
928 if (!IsWindow( cs->hwndParent ))
930 WARN("Bad parent %p\n", cs->hwndParent );
933 if ((cs->style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
934 parent = WIN_GetFullHandle(cs->hwndParent);
936 owner = GetAncestor( cs->hwndParent, GA_ROOT );
938 else if ((cs->style & (WS_CHILD|WS_POPUP)) == WS_CHILD)
940 WARN("No parent for child window\n" );
941 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
944 WIN_FixCoordinates(cs, &sw); /* fix default coordinates */
946 if ((cs->dwExStyle & WS_EX_DLGMODALFRAME) ||
947 ((!(cs->dwExStyle & WS_EX_STATICEDGE)) &&
948 (cs->style & (WS_DLGFRAME | WS_THICKFRAME))))
949 cs->dwExStyle |= WS_EX_WINDOWEDGE;
951 cs->dwExStyle &= ~WS_EX_WINDOWEDGE;
953 /* Create the window structure */
955 if (!(wndPtr = create_window_handle( parent, owner, classAtom, cs->hInstance, type )))
957 TRACE("out of memory\n" );
960 hwnd = wndPtr->hwndSelf;
962 /* Fill the window structure */
964 wndPtr->tid = GetCurrentThreadId();
965 wndPtr->owner = owner;
966 wndPtr->parent = parent;
967 wndPtr->hInstance = cs->hInstance;
969 wndPtr->dwStyle = cs->style & ~WS_VISIBLE;
970 wndPtr->dwExStyle = cs->dwExStyle;
972 wndPtr->helpContext = 0;
973 wndPtr->flags = (type == WIN_PROC_16) ? 0 : WIN_ISWIN32;
974 wndPtr->pVScroll = NULL;
975 wndPtr->pHScroll = NULL;
976 wndPtr->userdata = 0;
978 wndPtr->hIconSmall = 0;
979 wndPtr->hSysMenu = 0;
981 if (wndPtr->dwStyle & WS_SYSMENU) SetSystemMenu( hwnd, 0 );
984 * Correct the window styles.
986 * It affects only the style loaded into the WIN structure.
989 if (!(wndPtr->dwStyle & WS_CHILD))
991 wndPtr->dwStyle |= WS_CLIPSIBLINGS;
992 if (!(wndPtr->dwStyle & WS_POPUP))
993 wndPtr->dwStyle |= WS_CAPTION;
997 * WS_EX_WINDOWEDGE appears to be enforced based on the other styles, so
998 * why does the user get to set it?
1001 if ((wndPtr->dwExStyle & WS_EX_DLGMODALFRAME) ||
1002 (wndPtr->dwStyle & (WS_DLGFRAME | WS_THICKFRAME)))
1003 wndPtr->dwExStyle |= WS_EX_WINDOWEDGE;
1005 wndPtr->dwExStyle &= ~WS_EX_WINDOWEDGE;
1007 if (!(wndPtr->dwStyle & (WS_CHILD | WS_POPUP)))
1008 wndPtr->flags |= WIN_NEED_SIZE;
1010 SERVER_START_REQ( set_window_info )
1013 req->flags = SET_WIN_STYLE | SET_WIN_EXSTYLE | SET_WIN_INSTANCE | SET_WIN_UNICODE;
1014 req->style = wndPtr->dwStyle;
1015 req->ex_style = wndPtr->dwExStyle;
1016 req->instance = (void *)wndPtr->hInstance;
1017 req->is_unicode = (type == WIN_PROC_32W);
1018 req->extra_offset = -1;
1019 wine_server_call( req );
1023 /* Set the window menu */
1025 if (((wndPtr->dwStyle & (WS_CAPTION|WS_CHILD)) == WS_CAPTION) ||
1026 (wndPtr->dwExStyle & WS_EX_APPWINDOW))
1030 if (!MENU_SetMenu(hwnd, cs->hMenu))
1032 WIN_ReleasePtr( wndPtr );
1033 free_window_handle( hwnd );
1039 LPCSTR menuName = (LPCSTR)GetClassLongPtrA( hwnd, GCLP_MENUNAME );
1042 if (!cs->hInstance || HIWORD(cs->hInstance))
1043 cs->hMenu = LoadMenuA(cs->hInstance,menuName);
1045 cs->hMenu = HMENU_32(LoadMenu16(HINSTANCE_16(cs->hInstance),menuName));
1047 if (cs->hMenu) MENU_SetMenu( hwnd, cs->hMenu );
1051 else SetWindowLongPtrW( hwnd, GWLP_ID, (ULONG_PTR)cs->hMenu );
1052 WIN_ReleasePtr( wndPtr );
1054 if (!USER_Driver->pCreateWindow( hwnd, cs, unicode))
1056 WIN_DestroyWindow( hwnd );
1060 /* Notify the parent window only */
1062 send_parent_notify( hwnd, WM_CREATE );
1063 if (!IsWindow( hwnd )) return 0;
1065 if (cs->style & WS_VISIBLE)
1067 if (cs->style & WS_MAXIMIZE)
1068 sw = SW_SHOWMAXIMIZED;
1069 else if (cs->style & WS_MINIMIZE)
1070 sw = SW_SHOWMINIMIZED;
1072 ShowWindow( hwnd, sw );
1073 if (cs->dwExStyle & WS_EX_MDICHILD)
1075 SendMessageW(cs->hwndParent, WM_MDIREFRESHMENU, 0, 0);
1076 /* ShowWindow won't activate child windows */
1077 SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE );
1081 /* Call WH_SHELL hook */
1083 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) && !GetWindow( hwnd, GW_OWNER ))
1084 HOOK_CallHooks( WH_SHELL, HSHELL_WINDOWCREATED, (WPARAM)hwnd, 0, TRUE );
1086 TRACE("created window %p\n", hwnd);
1091 /***********************************************************************
1092 * CreateWindow (USER.41)
1094 HWND16 WINAPI CreateWindow16( LPCSTR className, LPCSTR windowName,
1095 DWORD style, INT16 x, INT16 y, INT16 width,
1096 INT16 height, HWND16 parent, HMENU16 menu,
1097 HINSTANCE16 instance, LPVOID data )
1099 return CreateWindowEx16( 0, className, windowName, style,
1100 x, y, width, height, parent, menu, instance, data );
1104 /***********************************************************************
1105 * CreateWindowEx (USER.452)
1107 HWND16 WINAPI CreateWindowEx16( DWORD exStyle, LPCSTR className,
1108 LPCSTR windowName, DWORD style, INT16 x,
1109 INT16 y, INT16 width, INT16 height,
1110 HWND16 parent, HMENU16 menu,
1111 HINSTANCE16 instance, LPVOID data )
1117 /* Find the class atom */
1119 if (HIWORD(className))
1121 if (!(classAtom = GlobalFindAtomA( className )))
1123 ERR( "bad class name %s\n", debugstr_a(className) );
1129 classAtom = LOWORD(className);
1130 if (!GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) ))
1132 ERR( "bad atom %x\n", classAtom);
1138 /* Fix the coordinates */
1140 cs.x = (x == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)x;
1141 cs.y = (y == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)y;
1142 cs.cx = (width == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)width;
1143 cs.cy = (height == CW_USEDEFAULT16) ? CW_USEDEFAULT : (INT)height;
1145 /* Create the window */
1147 cs.lpCreateParams = data;
1148 cs.hInstance = HINSTANCE_32(instance);
1149 cs.hMenu = HMENU_32(menu);
1150 cs.hwndParent = WIN_Handle32( parent );
1152 cs.lpszName = windowName;
1153 cs.lpszClass = className;
1154 cs.dwExStyle = exStyle;
1156 return HWND_16( WIN_CreateWindowEx( &cs, classAtom, WIN_PROC_16 ));
1160 /***********************************************************************
1161 * CreateWindowExA (USER32.@)
1163 HWND WINAPI CreateWindowExA( DWORD exStyle, LPCSTR className,
1164 LPCSTR windowName, DWORD style, INT x,
1165 INT y, INT width, INT height,
1166 HWND parent, HMENU menu,
1167 HINSTANCE instance, LPVOID data )
1173 /* Find the class atom */
1175 if (HIWORD(className))
1177 if (!(classAtom = GlobalFindAtomA( className )))
1179 ERR( "bad class name %s\n", debugstr_a(className) );
1185 classAtom = LOWORD(className);
1186 if (!GlobalGetAtomNameA( classAtom, buffer, sizeof(buffer) ))
1188 ERR( "bad atom %x\n", classAtom);
1194 /* Create the window */
1196 cs.lpCreateParams = data;
1197 cs.hInstance = instance;
1199 cs.hwndParent = parent;
1205 cs.lpszName = windowName;
1206 cs.lpszClass = className;
1207 cs.dwExStyle = exStyle;
1209 return WIN_CreateWindowEx( &cs, classAtom, WIN_PROC_32A );
1213 /***********************************************************************
1214 * CreateWindowExW (USER32.@)
1216 HWND WINAPI CreateWindowExW( DWORD exStyle, LPCWSTR className,
1217 LPCWSTR windowName, DWORD style, INT x,
1218 INT y, INT width, INT height,
1219 HWND parent, HMENU menu,
1220 HINSTANCE instance, LPVOID data )
1226 /* Find the class atom */
1228 if (HIWORD(className))
1230 if (!(classAtom = GlobalFindAtomW( className )))
1232 ERR( "bad class name %s\n", debugstr_w(className) );
1238 classAtom = LOWORD(className);
1239 if (!GlobalGetAtomNameW( classAtom, buffer, sizeof(buffer)/sizeof(WCHAR) ))
1241 ERR( "bad atom %x\n", classAtom);
1247 /* Create the window */
1249 cs.lpCreateParams = data;
1250 cs.hInstance = instance;
1252 cs.hwndParent = parent;
1258 cs.lpszName = windowName;
1259 cs.lpszClass = className;
1260 cs.dwExStyle = exStyle;
1262 /* Note: we rely on the fact that CREATESTRUCTA and */
1263 /* CREATESTRUCTW have the same layout. */
1264 return WIN_CreateWindowEx( (CREATESTRUCTA *)&cs, classAtom, WIN_PROC_32W );
1268 /***********************************************************************
1269 * WIN_SendDestroyMsg
1271 static void WIN_SendDestroyMsg( HWND hwnd )
1275 if (GetGUIThreadInfo( GetCurrentThreadId(), &info ))
1277 if (hwnd == info.hwndCaret) DestroyCaret();
1278 if (hwnd == info.hwndActive) WINPOS_ActivateOtherWindow( hwnd );
1280 USER_Driver->pResetSelectionOwner( hwnd, TRUE );
1283 * Send the WM_DESTROY to the window.
1285 SendMessageW( hwnd, WM_DESTROY, 0, 0);
1288 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1289 * make sure that the window still exists when we come back.
1296 if (!(pWndArray = WIN_ListChildren( hwnd ))) return;
1298 for (i = 0; pWndArray[i]; i++)
1300 if (IsWindow( pWndArray[i] )) WIN_SendDestroyMsg( pWndArray[i] );
1302 HeapFree( GetProcessHeap(), 0, pWndArray );
1305 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1309 /***********************************************************************
1310 * DestroyWindow (USER32.@)
1312 BOOL WINAPI DestroyWindow( HWND hwnd )
1316 if (!(hwnd = WIN_IsCurrentThread( hwnd )) || (hwnd == GetDesktopWindow()))
1318 SetLastError( ERROR_ACCESS_DENIED );
1322 TRACE("(%p)\n", hwnd);
1326 if (HOOK_CallHooks( WH_CBT, HCBT_DESTROYWND, (WPARAM)hwnd, 0, TRUE )) return FALSE;
1328 if (MENU_IsMenuActive() == hwnd)
1331 is_child = (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) != 0;
1335 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1336 send_parent_notify( hwnd, WM_DESTROY );
1338 else if (!GetWindow( hwnd, GW_OWNER ))
1340 HOOK_CallHooks( WH_SHELL, HSHELL_WINDOWDESTROYED, (WPARAM)hwnd, 0L, TRUE );
1341 /* FIXME: clean up palette - see "Internals" p.352 */
1344 if (!IsWindow(hwnd)) return TRUE;
1346 USER_Driver->pResetSelectionOwner( hwnd, FALSE ); /* before the window is unmapped */
1348 /* Hide the window */
1349 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)
1351 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1353 ShowWindow( hwnd, SW_HIDE );
1355 SetWindowPos( hwnd, 0, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE |
1356 SWP_NOZORDER | SWP_NOACTIVATE | SWP_HIDEWINDOW );
1359 if (!IsWindow(hwnd)) return TRUE;
1361 /* Recursively destroy owned windows */
1368 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1371 for (i = 0; list[i]; i++)
1373 if (GetWindow( list[i], GW_OWNER ) != hwnd) continue;
1374 if (WIN_IsCurrentThread( list[i] ))
1376 DestroyWindow( list[i] );
1380 WIN_SetOwner( list[i], 0 );
1382 HeapFree( GetProcessHeap(), 0, list );
1384 if (!got_one) break;
1388 /* Send destroy messages */
1390 WIN_SendDestroyMsg( hwnd );
1391 if (!IsWindow( hwnd )) return TRUE;
1393 if (GetClipboardOwner() == hwnd)
1394 CLIPBOARD_ReleaseOwner();
1396 /* Destroy the window storage */
1398 WIN_DestroyWindow( hwnd );
1403 /***********************************************************************
1404 * CloseWindow (USER32.@)
1406 BOOL WINAPI CloseWindow( HWND hwnd )
1408 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) return FALSE;
1409 ShowWindow( hwnd, SW_MINIMIZE );
1414 /***********************************************************************
1415 * OpenIcon (USER32.@)
1417 BOOL WINAPI OpenIcon( HWND hwnd )
1419 if (!IsIconic( hwnd )) return FALSE;
1420 ShowWindow( hwnd, SW_SHOWNORMAL );
1425 /***********************************************************************
1428 * Implementation of FindWindow() and FindWindowEx().
1430 static HWND WIN_FindWindow( HWND parent, HWND child, ATOM className, LPCWSTR title )
1435 WCHAR *buffer = NULL;
1437 if (!parent) parent = GetDesktopWindow();
1440 len = strlenW(title) + 1; /* one extra char to check for chars beyond the end */
1441 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, (len + 1) * sizeof(WCHAR) ))) return 0;
1444 if (!(list = list_window_children( parent, className, 0 ))) goto done;
1448 child = WIN_GetFullHandle( child );
1449 while (list[i] && list[i] != child) i++;
1450 if (!list[i]) goto done;
1451 i++; /* start from next window */
1458 if (GetWindowTextW( list[i], buffer, len + 1 ) && !strcmpiW( buffer, title )) break;
1465 HeapFree( GetProcessHeap(), 0, list );
1466 HeapFree( GetProcessHeap(), 0, buffer );
1472 /***********************************************************************
1473 * FindWindowA (USER32.@)
1475 HWND WINAPI FindWindowA( LPCSTR className, LPCSTR title )
1477 HWND ret = FindWindowExA( 0, 0, className, title );
1478 if (!ret) SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1483 /***********************************************************************
1484 * FindWindowExA (USER32.@)
1486 HWND WINAPI FindWindowExA( HWND parent, HWND child,
1487 LPCSTR className, LPCSTR title )
1496 /* If the atom doesn't exist, then no class */
1497 /* with this name exists either. */
1498 if (!(atom = GlobalFindAtomA( className )))
1500 SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1504 if (!title) return WIN_FindWindow( parent, child, atom, NULL );
1506 len = MultiByteToWideChar( CP_ACP, 0, title, -1, NULL, 0 );
1507 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0;
1508 MultiByteToWideChar( CP_ACP, 0, title, -1, buffer, len );
1509 hwnd = WIN_FindWindow( parent, child, atom, buffer );
1510 HeapFree( GetProcessHeap(), 0, buffer );
1515 /***********************************************************************
1516 * FindWindowExW (USER32.@)
1518 HWND WINAPI FindWindowExW( HWND parent, HWND child,
1519 LPCWSTR className, LPCWSTR title )
1525 /* If the atom doesn't exist, then no class */
1526 /* with this name exists either. */
1527 if (!(atom = GlobalFindAtomW( className )))
1529 SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
1533 return WIN_FindWindow( parent, child, atom, title );
1537 /***********************************************************************
1538 * FindWindowW (USER32.@)
1540 HWND WINAPI FindWindowW( LPCWSTR className, LPCWSTR title )
1542 return FindWindowExW( 0, 0, className, title );
1546 /**********************************************************************
1547 * GetDesktopWindow (USER32.@)
1549 HWND WINAPI GetDesktopWindow(void)
1551 struct user_thread_info *thread_info = get_user_thread_info();
1553 if (!thread_info->desktop)
1555 SERVER_START_REQ( get_desktop_window )
1557 if (!wine_server_call( req )) thread_info->desktop = reply->handle;
1560 if (!thread_info->desktop || !USER_Driver->pCreateDesktopWindow( thread_info->desktop ))
1561 ERR( "failed to create desktop window\n" );
1563 return thread_info->desktop;
1567 /*******************************************************************
1568 * EnableWindow (USER32.@)
1570 BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
1575 if (is_broadcast(hwnd))
1577 SetLastError( ERROR_INVALID_PARAMETER );
1581 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
1582 return SendMessageW( hwnd, WM_WINE_ENABLEWINDOW, enable, 0 );
1586 TRACE("( %p, %d )\n", hwnd, enable);
1588 retvalue = !IsWindowEnabled( hwnd );
1590 if (enable && retvalue)
1592 WIN_SetStyle( hwnd, 0, WS_DISABLED );
1593 SendMessageW( hwnd, WM_ENABLE, TRUE, 0 );
1595 else if (!enable && !retvalue)
1599 SendMessageW( hwnd, WM_CANCELMODE, 0, 0);
1601 WIN_SetStyle( hwnd, WS_DISABLED, 0 );
1603 if (hwnd == GetFocus())
1604 SetFocus( 0 ); /* A disabled window can't have the focus */
1606 capture_wnd = GetCapture();
1607 if (hwnd == capture_wnd || IsChild(hwnd, capture_wnd))
1608 ReleaseCapture(); /* A disabled window can't capture the mouse */
1610 SendMessageW( hwnd, WM_ENABLE, FALSE, 0 );
1616 /***********************************************************************
1617 * IsWindowEnabled (USER32.@)
1619 BOOL WINAPI IsWindowEnabled(HWND hWnd)
1621 return !(GetWindowLongW( hWnd, GWL_STYLE ) & WS_DISABLED);
1625 /***********************************************************************
1626 * IsWindowUnicode (USER32.@)
1628 BOOL WINAPI IsWindowUnicode( HWND hwnd )
1631 BOOL retvalue = FALSE;
1633 if (!(wndPtr = WIN_GetPtr(hwnd))) return FALSE;
1635 if (wndPtr == WND_DESKTOP) return TRUE;
1637 if (wndPtr != WND_OTHER_PROCESS)
1639 retvalue = (WINPROC_GetProcType( wndPtr->winproc ) == WIN_PROC_32W);
1640 WIN_ReleasePtr( wndPtr );
1644 SERVER_START_REQ( get_window_info )
1647 if (!wine_server_call_err( req )) retvalue = reply->is_unicode;
1655 /**********************************************************************
1656 * GetWindowWord (USER32.@)
1658 WORD WINAPI GetWindowWord( HWND hwnd, INT offset )
1663 WND *wndPtr = WIN_GetPtr( hwnd );
1666 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1669 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
1671 SERVER_START_REQ( set_window_info )
1674 req->flags = 0; /* don't set anything, just retrieve */
1675 req->extra_offset = offset;
1676 req->extra_size = sizeof(retvalue);
1677 if (!wine_server_call_err( req ))
1678 memcpy( &retvalue, &reply->old_extra_value, sizeof(retvalue) );
1683 if (offset > (int)(wndPtr->cbWndExtra - sizeof(WORD)))
1685 WARN("Invalid offset %d\n", offset );
1686 SetLastError( ERROR_INVALID_INDEX );
1688 else memcpy( &retvalue, (char *)wndPtr->wExtra + offset, sizeof(retvalue) );
1689 WIN_ReleasePtr( wndPtr );
1695 case GWLP_HWNDPARENT:
1696 return GetWindowLongPtrW( hwnd, offset );
1698 case GWLP_HINSTANCE:
1700 LONG_PTR ret = GetWindowLongPtrW( hwnd, offset );
1702 WARN("%d: discards high bits of 0x%08lx!\n", offset, ret );
1706 WARN("Invalid offset %d\n", offset );
1712 /**********************************************************************
1713 * SetWindowWord (USER32.@)
1715 WORD WINAPI SetWindowWord( HWND hwnd, INT offset, WORD newval )
1723 case GWLP_HINSTANCE:
1724 case GWLP_HWNDPARENT:
1725 return SetWindowLongPtrW( hwnd, offset, (ULONG_PTR)newval );
1729 WARN("Invalid offset %d\n", offset );
1730 SetLastError( ERROR_INVALID_INDEX );
1735 wndPtr = WIN_GetPtr( hwnd );
1736 if (wndPtr == WND_DESKTOP)
1738 SetLastError( ERROR_ACCESS_DENIED );
1741 if (wndPtr == WND_OTHER_PROCESS)
1744 FIXME( "set %d <- %x not supported yet on other process window %p\n",
1745 offset, newval, hwnd );
1750 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1754 if (offset > (int)(wndPtr->cbWndExtra - sizeof(WORD)))
1756 WARN("Invalid offset %d\n", offset );
1757 WIN_ReleasePtr(wndPtr);
1758 SetLastError( ERROR_INVALID_INDEX );
1762 SERVER_START_REQ( set_window_info )
1765 req->flags = SET_WIN_EXTRA;
1766 req->extra_offset = offset;
1767 req->extra_size = sizeof(newval);
1768 memcpy( &req->extra_value, &newval, sizeof(newval) );
1769 if (!wine_server_call_err( req ))
1771 void *ptr = (char *)wndPtr->wExtra + offset;
1772 memcpy( &retval, ptr, sizeof(retval) );
1773 memcpy( ptr, &newval, sizeof(newval) );
1777 WIN_ReleasePtr( wndPtr );
1782 /**********************************************************************
1785 * Helper function for GetWindowLong().
1787 static LONG_PTR WIN_GetWindowLong( HWND hwnd, INT offset, WINDOWPROCTYPE type )
1789 LONG_PTR retvalue = 0;
1792 if (offset == GWLP_HWNDPARENT)
1794 HWND parent = GetAncestor( hwnd, GA_PARENT );
1795 if (parent == GetDesktopWindow()) parent = GetWindow( hwnd, GW_OWNER );
1796 return (ULONG_PTR)parent;
1799 if (!(wndPtr = WIN_GetPtr( hwnd )))
1801 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1805 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
1807 if (offset == GWLP_WNDPROC)
1809 SetLastError( ERROR_ACCESS_DENIED );
1812 SERVER_START_REQ( set_window_info )
1815 req->flags = 0; /* don't set anything, just retrieve */
1816 req->extra_offset = (offset >= 0) ? offset : -1;
1817 req->extra_size = (offset >= 0) ? sizeof(retvalue) : 0;
1818 if (!wine_server_call_err( req ))
1822 case GWL_STYLE: retvalue = reply->old_style; break;
1823 case GWL_EXSTYLE: retvalue = reply->old_ex_style; break;
1824 case GWLP_ID: retvalue = reply->old_id; break;
1825 case GWLP_HINSTANCE: retvalue = (ULONG_PTR)reply->old_instance; break;
1826 case GWLP_USERDATA: retvalue = (ULONG_PTR)reply->old_user_data; break;
1828 if (offset >= 0) retvalue = reply->old_extra_value;
1829 else SetLastError( ERROR_INVALID_INDEX );
1838 /* now we have a valid wndPtr */
1842 if (offset > (int)(wndPtr->cbWndExtra - sizeof(LONG)))
1845 * Some programs try to access last element from 16 bit
1846 * code using illegal offset value. Hopefully this is
1847 * what those programs really expect.
1849 if (type == WIN_PROC_16 &&
1850 wndPtr->cbWndExtra >= 4 &&
1851 offset == wndPtr->cbWndExtra - sizeof(WORD))
1853 INT offset2 = wndPtr->cbWndExtra - sizeof(LONG);
1855 ERR( "- replaced invalid offset %d with %d\n",
1858 retvalue = *(LONG_PTR *)(((char *)wndPtr->wExtra) + offset2);
1859 WIN_ReleasePtr( wndPtr );
1862 WARN("Invalid offset %d\n", offset );
1863 WIN_ReleasePtr( wndPtr );
1864 SetLastError( ERROR_INVALID_INDEX );
1867 retvalue = *(LONG_PTR *)(((char *)wndPtr->wExtra) + offset);
1868 /* Special case for dialog window procedure */
1869 if ((offset == DWLP_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG))
1870 retvalue = (LONG_PTR)WINPROC_GetProc( (WNDPROC)retvalue, type );
1871 WIN_ReleasePtr( wndPtr );
1877 case GWLP_USERDATA: retvalue = wndPtr->userdata; break;
1878 case GWL_STYLE: retvalue = wndPtr->dwStyle; break;
1879 case GWL_EXSTYLE: retvalue = wndPtr->dwExStyle; break;
1880 case GWLP_ID: retvalue = (ULONG_PTR)wndPtr->wIDmenu; break;
1881 case GWLP_WNDPROC: retvalue = (ULONG_PTR)WINPROC_GetProc( wndPtr->winproc, type ); break;
1882 case GWLP_HINSTANCE: retvalue = (ULONG_PTR)wndPtr->hInstance; break;
1884 WARN("Unknown offset %d\n", offset );
1885 SetLastError( ERROR_INVALID_INDEX );
1888 WIN_ReleasePtr(wndPtr);
1893 /**********************************************************************
1896 * Helper function for SetWindowLong().
1898 * 0 is the failure code. However, in the case of failure SetLastError
1899 * must be set to distinguish between a 0 return value and a failure.
1901 static LONG_PTR WIN_SetWindowLong( HWND hwnd, INT offset, LONG_PTR newval,
1902 WINDOWPROCTYPE type )
1906 LONG_PTR retval = 0;
1909 TRACE( "%p %d %lx %x\n", hwnd, offset, newval, type );
1911 if (is_broadcast(hwnd))
1913 SetLastError( ERROR_INVALID_PARAMETER );
1917 if (!(wndPtr = WIN_GetPtr( hwnd )))
1919 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1922 if (wndPtr == WND_DESKTOP)
1924 /* can't change anything on the desktop window */
1925 SetLastError( ERROR_ACCESS_DENIED );
1928 if (wndPtr == WND_OTHER_PROCESS)
1930 if (offset == GWLP_WNDPROC)
1932 SetLastError( ERROR_ACCESS_DENIED );
1935 return SendMessageW( hwnd, WM_WINE_SETWINDOWLONG, offset, newval );
1938 /* first some special cases */
1944 offset == GWL_STYLE ? wndPtr->dwStyle : wndPtr->dwExStyle;
1945 style.styleNew = newval;
1946 WIN_ReleasePtr( wndPtr );
1947 SendMessageW( hwnd, WM_STYLECHANGING, offset, (LPARAM)&style );
1948 if (!(wndPtr = WIN_GetPtr( hwnd )) || wndPtr == WND_OTHER_PROCESS) return 0;
1949 newval = style.styleNew;
1951 case GWLP_HWNDPARENT:
1952 if (wndPtr->parent == GetDesktopWindow())
1954 WIN_ReleasePtr( wndPtr );
1955 return (ULONG_PTR)WIN_SetOwner( hwnd, (HWND)newval );
1959 WIN_ReleasePtr( wndPtr );
1960 return (ULONG_PTR)SetParent( hwnd, (HWND)newval );
1964 WINDOWPROCTYPE old_type = WINPROC_GetProcType( wndPtr->winproc );
1965 retval = (ULONG_PTR)WINPROC_GetProc( wndPtr->winproc, type );
1966 wndPtr->winproc = WINPROC_AllocProc( (WNDPROC)newval, type );
1967 if (old_type == type)
1969 WIN_ReleasePtr( wndPtr );
1972 /* update is_unicode flag on the server side */
1976 case GWLP_HINSTANCE:
1980 if ((wndPtr->cbWndExtra + sizeof(LONG_PTR) >= DWLP_DLGPROC) && (wndPtr->flags & WIN_ISDIALOG))
1982 WNDPROC *ptr = (WNDPROC *)((char *)wndPtr->wExtra + DWLP_DLGPROC);
1983 retval = (ULONG_PTR)WINPROC_GetProc( *ptr, type );
1984 *ptr = WINPROC_AllocProc( (WNDPROC)newval, type );
1985 WIN_ReleasePtr( wndPtr );
1990 if (offset < 0 || offset > (int)(wndPtr->cbWndExtra - sizeof(LONG_PTR)))
1992 WARN("Invalid offset %d\n", offset );
1993 WIN_ReleasePtr( wndPtr );
1994 SetLastError( ERROR_INVALID_INDEX );
1999 LONG_PTR *ptr = (LONG_PTR *)((char *)wndPtr->wExtra + offset);
2000 if (*ptr == newval) /* already set to the same value */
2002 WIN_ReleasePtr( wndPtr );
2009 SERVER_START_REQ( set_window_info )
2012 req->extra_offset = -1;
2016 req->flags = SET_WIN_STYLE;
2017 req->style = newval;
2020 req->flags = SET_WIN_EXSTYLE;
2021 req->ex_style = newval;
2024 req->flags = SET_WIN_ID;
2027 case GWLP_HINSTANCE:
2028 req->flags = SET_WIN_INSTANCE;
2029 req->instance = (void *)newval;
2032 req->flags = SET_WIN_UNICODE;
2033 req->is_unicode = (type == WIN_PROC_32W);
2036 req->flags = SET_WIN_USERDATA;
2037 req->user_data = (void *)newval;
2040 req->flags = SET_WIN_EXTRA;
2041 req->extra_offset = offset;
2042 req->extra_size = sizeof(newval);
2043 memcpy( &req->extra_value, &newval, sizeof(newval) );
2045 if ((ok = !wine_server_call_err( req )))
2050 wndPtr->dwStyle = newval;
2051 retval = reply->old_style;
2054 wndPtr->dwExStyle = newval;
2055 retval = reply->old_ex_style;
2058 wndPtr->wIDmenu = newval;
2059 retval = reply->old_id;
2061 case GWLP_HINSTANCE:
2062 wndPtr->hInstance = (HINSTANCE)newval;
2063 retval = (ULONG_PTR)reply->old_instance;
2068 wndPtr->userdata = newval;
2069 retval = (ULONG_PTR)reply->old_user_data;
2073 void *ptr = (char *)wndPtr->wExtra + offset;
2074 memcpy( &retval, ptr, sizeof(retval) );
2075 memcpy( ptr, &newval, sizeof(newval) );
2082 WIN_ReleasePtr( wndPtr );
2086 if (offset == GWL_STYLE) USER_Driver->pSetWindowStyle( hwnd, retval );
2088 if (offset == GWL_STYLE || offset == GWL_EXSTYLE)
2089 SendMessageW( hwnd, WM_STYLECHANGED, offset, (LPARAM)&style );
2095 /**********************************************************************
2096 * GetWindowLong (USER.135)
2098 LONG WINAPI GetWindowLong16( HWND16 hwnd, INT16 offset )
2100 return WIN_GetWindowLong( WIN_Handle32(hwnd), offset, WIN_PROC_16 );
2104 /**********************************************************************
2105 * GetWindowLongA (USER32.@)
2107 LONG WINAPI GetWindowLongA( HWND hwnd, INT offset )
2109 return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32A );
2113 /**********************************************************************
2114 * GetWindowLongW (USER32.@)
2116 LONG WINAPI GetWindowLongW( HWND hwnd, INT offset )
2118 return WIN_GetWindowLong( hwnd, offset, WIN_PROC_32W );
2122 /**********************************************************************
2123 * SetWindowLong (USER.136)
2125 LONG WINAPI SetWindowLong16( HWND16 hwnd, INT16 offset, LONG newval )
2127 return WIN_SetWindowLong( WIN_Handle32(hwnd), offset, newval, WIN_PROC_16 );
2131 /**********************************************************************
2132 * SetWindowLongA (USER32.@)
2134 LONG WINAPI SetWindowLongA( HWND hwnd, INT offset, LONG newval )
2136 return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32A );
2140 /**********************************************************************
2141 * SetWindowLongW (USER32.@) Set window attribute
2143 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2144 * value in a window's extra memory.
2146 * The _hwnd_ parameter specifies the window. is the handle to a
2147 * window that has extra memory. The _newval_ parameter contains the
2148 * new attribute or extra memory value. If positive, the _offset_
2149 * parameter is the byte-addressed location in the window's extra
2150 * memory to set. If negative, _offset_ specifies the window
2151 * attribute to set, and should be one of the following values:
2153 * GWL_EXSTYLE The window's extended window style
2155 * GWL_STYLE The window's window style.
2157 * GWLP_WNDPROC Pointer to the window's window procedure.
2159 * GWLP_HINSTANCE The window's pplication instance handle.
2161 * GWLP_ID The window's identifier.
2163 * GWLP_USERDATA The window's user-specified data.
2165 * If the window is a dialog box, the _offset_ parameter can be one of
2166 * the following values:
2168 * DWLP_DLGPROC The address of the window's dialog box procedure.
2170 * DWLP_MSGRESULT The return value of a message
2171 * that the dialog box procedure processed.
2173 * DWLP_USER Application specific information.
2177 * If successful, returns the previous value located at _offset_. Otherwise,
2182 * Extra memory for a window class is specified by a nonzero cbWndExtra
2183 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2184 * time of class creation.
2186 * Using GWL_WNDPROC to set a new window procedure effectively creates
2187 * a window subclass. Use CallWindowProc() in the new windows procedure
2188 * to pass messages to the superclass's window procedure.
2190 * The user data is reserved for use by the application which created
2193 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2194 * instead, call the EnableWindow() function to change the window's
2197 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2198 * SetParent() instead.
2201 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2202 * it sends WM_STYLECHANGING before changing the settings
2203 * and WM_STYLECHANGED afterwards.
2204 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2206 LONG WINAPI SetWindowLongW(
2207 HWND hwnd, /* [in] window to alter */
2208 INT offset, /* [in] offset, in bytes, of location to alter */
2209 LONG newval /* [in] new value of location */
2211 return WIN_SetWindowLong( hwnd, offset, newval, WIN_PROC_32W );
2215 /*******************************************************************
2216 * GetWindowTextA (USER32.@)
2218 INT WINAPI GetWindowTextA( HWND hwnd, LPSTR lpString, INT nMaxCount )
2222 if (!lpString) return 0;
2224 if (WIN_IsCurrentProcess( hwnd ))
2225 return (INT)SendMessageA( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
2227 /* when window belongs to other process, don't send a message */
2228 if (nMaxCount <= 0) return 0;
2229 if (!(buffer = HeapAlloc( GetProcessHeap(), 0, nMaxCount * sizeof(WCHAR) ))) return 0;
2230 get_server_window_text( hwnd, buffer, nMaxCount );
2231 if (!WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpString, nMaxCount, NULL, NULL ))
2232 lpString[nMaxCount-1] = 0;
2233 HeapFree( GetProcessHeap(), 0, buffer );
2234 return strlen(lpString);
2238 /*******************************************************************
2239 * InternalGetWindowText (USER32.@)
2241 INT WINAPI InternalGetWindowText(HWND hwnd,LPWSTR lpString,INT nMaxCount )
2245 if (nMaxCount <= 0) return 0;
2246 if (!(win = WIN_GetPtr( hwnd ))) return 0;
2247 if (win == WND_DESKTOP) lpString[0] = 0;
2248 else if (win != WND_OTHER_PROCESS)
2250 if (win->text) lstrcpynW( lpString, win->text, nMaxCount );
2251 else lpString[0] = 0;
2252 WIN_ReleasePtr( win );
2256 get_server_window_text( hwnd, lpString, nMaxCount );
2258 return strlenW(lpString);
2262 /*******************************************************************
2263 * GetWindowTextW (USER32.@)
2265 INT WINAPI GetWindowTextW( HWND hwnd, LPWSTR lpString, INT nMaxCount )
2267 if (!lpString) return 0;
2269 if (WIN_IsCurrentProcess( hwnd ))
2270 return (INT)SendMessageW( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
2272 /* when window belongs to other process, don't send a message */
2273 if (nMaxCount <= 0) return 0;
2274 get_server_window_text( hwnd, lpString, nMaxCount );
2275 return strlenW(lpString);
2279 /*******************************************************************
2280 * SetWindowText (USER32.@)
2281 * SetWindowTextA (USER32.@)
2283 BOOL WINAPI SetWindowTextA( HWND hwnd, LPCSTR lpString )
2285 if (is_broadcast(hwnd))
2287 SetLastError( ERROR_INVALID_PARAMETER );
2290 if (!WIN_IsCurrentProcess( hwnd ))
2291 FIXME( "setting text %s of other process window %p should not use SendMessage\n",
2292 debugstr_a(lpString), hwnd );
2293 return (BOOL)SendMessageA( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
2297 /*******************************************************************
2298 * SetWindowTextW (USER32.@)
2300 BOOL WINAPI SetWindowTextW( HWND hwnd, LPCWSTR lpString )
2302 if (is_broadcast(hwnd))
2304 SetLastError( ERROR_INVALID_PARAMETER );
2307 if (!WIN_IsCurrentProcess( hwnd ))
2308 FIXME( "setting text %s of other process window %p should not use SendMessage\n",
2309 debugstr_w(lpString), hwnd );
2310 return (BOOL)SendMessageW( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
2314 /*******************************************************************
2315 * GetWindowTextLengthA (USER32.@)
2317 INT WINAPI GetWindowTextLengthA( HWND hwnd )
2319 return SendMessageA( hwnd, WM_GETTEXTLENGTH, 0, 0 );
2322 /*******************************************************************
2323 * GetWindowTextLengthW (USER32.@)
2325 INT WINAPI GetWindowTextLengthW( HWND hwnd )
2327 return SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 );
2331 /*******************************************************************
2332 * IsWindow (USER32.@)
2334 BOOL WINAPI IsWindow( HWND hwnd )
2339 if (!(ptr = WIN_GetPtr( hwnd ))) return FALSE;
2340 if (ptr == WND_DESKTOP) return TRUE;
2342 if (ptr != WND_OTHER_PROCESS)
2344 WIN_ReleasePtr( ptr );
2348 /* check other processes */
2349 SERVER_START_REQ( get_window_info )
2352 ret = !wine_server_call_err( req );
2359 /***********************************************************************
2360 * GetWindowThreadProcessId (USER32.@)
2362 DWORD WINAPI GetWindowThreadProcessId( HWND hwnd, LPDWORD process )
2367 if (!(ptr = WIN_GetPtr( hwnd )))
2369 SetLastError( ERROR_INVALID_WINDOW_HANDLE);
2373 if (ptr != WND_OTHER_PROCESS && ptr != WND_DESKTOP)
2375 /* got a valid window */
2377 if (process) *process = GetCurrentProcessId();
2378 WIN_ReleasePtr( ptr );
2382 /* check other processes */
2383 SERVER_START_REQ( get_window_info )
2386 if (!wine_server_call_err( req ))
2388 tid = (DWORD)reply->tid;
2389 if (process) *process = (DWORD)reply->pid;
2397 /*****************************************************************
2398 * GetParent (USER32.@)
2400 HWND WINAPI GetParent( HWND hwnd )
2405 if (!(wndPtr = WIN_GetPtr( hwnd )))
2407 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2410 if (wndPtr == WND_DESKTOP) return 0;
2411 if (wndPtr == WND_OTHER_PROCESS)
2413 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2414 if (style & (WS_POPUP | WS_CHILD))
2416 SERVER_START_REQ( get_window_tree )
2419 if (!wine_server_call_err( req ))
2421 if (style & WS_POPUP) retvalue = reply->owner;
2422 else if (style & WS_CHILD) retvalue = reply->parent;
2430 if (wndPtr->dwStyle & WS_POPUP) retvalue = wndPtr->owner;
2431 else if (wndPtr->dwStyle & WS_CHILD) retvalue = wndPtr->parent;
2432 WIN_ReleasePtr( wndPtr );
2438 /*****************************************************************
2439 * GetAncestor (USER32.@)
2441 HWND WINAPI GetAncestor( HWND hwnd, UINT type )
2444 HWND *list, ret = 0;
2449 if (!(win = WIN_GetPtr( hwnd )))
2451 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2454 if (win == WND_DESKTOP) return 0;
2455 if (win != WND_OTHER_PROCESS)
2458 WIN_ReleasePtr( win );
2460 else /* need to query the server */
2462 SERVER_START_REQ( get_window_tree )
2465 if (!wine_server_call_err( req )) ret = reply->parent;
2472 if (!(list = list_window_parents( hwnd ))) return 0;
2474 if (!list[0] || !list[1]) ret = WIN_GetFullHandle( hwnd ); /* top-level window */
2478 while (list[count]) count++;
2479 ret = list[count - 2]; /* get the one before the desktop */
2481 HeapFree( GetProcessHeap(), 0, list );
2485 if ((ret = WIN_GetFullHandle( hwnd )) == GetDesktopWindow()) return 0;
2488 HWND parent = GetParent( ret );
2498 /*****************************************************************
2499 * SetParent (USER32.@)
2501 HWND WINAPI SetParent( HWND hwnd, HWND parent )
2505 if (is_broadcast(hwnd) || is_broadcast(parent))
2507 SetLastError(ERROR_INVALID_PARAMETER);
2511 if (!parent) parent = GetDesktopWindow();
2512 else parent = WIN_GetFullHandle( parent );
2514 if (!IsWindow( parent ))
2516 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
2520 /* Some applications try to set a child as a parent */
2521 if (IsChild(hwnd, parent))
2523 SetLastError( ERROR_INVALID_PARAMETER );
2527 if (!(full_handle = WIN_IsCurrentThread( hwnd )))
2528 return (HWND)SendMessageW( hwnd, WM_WINE_SETPARENT, (WPARAM)parent, 0 );
2530 return USER_Driver->pSetParent( full_handle, parent );
2534 /*******************************************************************
2535 * IsChild (USER32.@)
2537 BOOL WINAPI IsChild( HWND parent, HWND child )
2539 HWND *list = list_window_parents( child );
2543 if (!list) return FALSE;
2544 parent = WIN_GetFullHandle( parent );
2545 for (i = 0; list[i]; i++) if (list[i] == parent) break;
2546 ret = (list[i] != 0);
2547 HeapFree( GetProcessHeap(), 0, list );
2552 /***********************************************************************
2553 * IsWindowVisible (USER32.@)
2555 BOOL WINAPI IsWindowVisible( HWND hwnd )
2561 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE)) return FALSE;
2562 if (!(list = list_window_parents( hwnd ))) return TRUE;
2563 for (i = 0; list[i]; i++)
2564 if (!(GetWindowLongW( list[i], GWL_STYLE ) & WS_VISIBLE)) break;
2566 HeapFree( GetProcessHeap(), 0, list );
2571 /***********************************************************************
2572 * WIN_IsWindowDrawable
2574 * hwnd is drawable when it is visible, all parents are not
2575 * minimized, and it is itself not minimized unless we are
2576 * trying to draw its default class icon.
2578 BOOL WIN_IsWindowDrawable( HWND hwnd, BOOL icon )
2583 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
2585 if (!(style & WS_VISIBLE)) return FALSE;
2586 if ((style & WS_MINIMIZE) && icon && GetClassLongPtrW( hwnd, GCLP_HICON )) return FALSE;
2588 if (!(list = list_window_parents( hwnd ))) return TRUE;
2589 for (i = 0; list[i]; i++)
2590 if ((GetWindowLongW( list[i], GWL_STYLE ) & (WS_VISIBLE|WS_MINIMIZE)) != WS_VISIBLE)
2593 HeapFree( GetProcessHeap(), 0, list );
2598 /*******************************************************************
2599 * GetTopWindow (USER32.@)
2601 HWND WINAPI GetTopWindow( HWND hwnd )
2603 if (!hwnd) hwnd = GetDesktopWindow();
2604 return GetWindow( hwnd, GW_CHILD );
2608 /*******************************************************************
2609 * GetWindow (USER32.@)
2611 HWND WINAPI GetWindow( HWND hwnd, UINT rel )
2615 if (rel == GW_OWNER) /* this one may be available locally */
2617 WND *wndPtr = WIN_GetPtr( hwnd );
2620 SetLastError( ERROR_INVALID_HANDLE );
2623 if (wndPtr == WND_DESKTOP) return 0;
2624 if (wndPtr != WND_OTHER_PROCESS)
2626 retval = wndPtr->owner;
2627 WIN_ReleasePtr( wndPtr );
2630 /* else fall through to server call */
2633 SERVER_START_REQ( get_window_tree )
2636 if (!wine_server_call_err( req ))
2641 retval = reply->first_sibling;
2644 retval = reply->last_sibling;
2647 retval = reply->next_sibling;
2650 retval = reply->prev_sibling;
2653 retval = reply->owner;
2656 retval = reply->first_child;
2666 /*******************************************************************
2667 * ShowOwnedPopups (USER32.@)
2669 BOOL WINAPI ShowOwnedPopups( HWND owner, BOOL fShow )
2673 HWND *win_array = WIN_ListChildren( GetDesktopWindow() );
2675 if (!win_array) return TRUE;
2677 while (win_array[count]) count++;
2678 while (--count >= 0)
2680 if (GetWindow( win_array[count], GW_OWNER ) != owner) continue;
2681 if (!(pWnd = WIN_GetPtr( win_array[count] ))) continue;
2682 if (pWnd == WND_OTHER_PROCESS) continue;
2685 if (pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP)
2687 WIN_ReleasePtr( pWnd );
2688 /* In Windows, ShowOwnedPopups(TRUE) generates
2689 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
2690 * regardless of the state of the owner
2692 SendMessageW(win_array[count], WM_SHOWWINDOW, SW_SHOWNORMAL, SW_PARENTOPENING);
2698 if (pWnd->dwStyle & WS_VISIBLE)
2700 WIN_ReleasePtr( pWnd );
2701 /* In Windows, ShowOwnedPopups(FALSE) generates
2702 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
2703 * regardless of the state of the owner
2705 SendMessageW(win_array[count], WM_SHOWWINDOW, SW_HIDE, SW_PARENTCLOSING);
2709 WIN_ReleasePtr( pWnd );
2711 HeapFree( GetProcessHeap(), 0, win_array );
2716 /*******************************************************************
2717 * GetLastActivePopup (USER32.@)
2719 HWND WINAPI GetLastActivePopup( HWND hwnd )
2723 SERVER_START_REQ( get_window_info )
2726 if (!wine_server_call_err( req )) retval = reply->last_active;
2733 /*******************************************************************
2736 * Build an array of the children of a given window. The array must be
2737 * freed with HeapFree. Returns NULL when no windows are found.
2739 HWND *WIN_ListChildren( HWND hwnd )
2741 return list_window_children( hwnd, 0, 0 );
2745 /*******************************************************************
2746 * EnumWindows (USER32.@)
2748 BOOL WINAPI EnumWindows( WNDENUMPROC lpEnumFunc, LPARAM lParam )
2754 USER_CheckNotLock();
2756 /* We have to build a list of all windows first, to avoid */
2757 /* unpleasant side-effects, for instance if the callback */
2758 /* function changes the Z-order of the windows. */
2760 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return TRUE;
2762 /* Now call the callback function for every window */
2764 for (i = 0; list[i]; i++)
2766 /* Make sure that the window still exists */
2767 if (!IsWindow( list[i] )) continue;
2768 if (!(ret = lpEnumFunc( list[i], lParam ))) break;
2770 HeapFree( GetProcessHeap(), 0, list );
2775 /**********************************************************************
2776 * EnumThreadWindows (USER32.@)
2778 BOOL WINAPI EnumThreadWindows( DWORD id, WNDENUMPROC func, LPARAM lParam )
2783 USER_CheckNotLock();
2785 if (!(list = list_window_children( GetDesktopWindow(), 0, id ))) return TRUE;
2787 /* Now call the callback function for every window */
2789 for (i = 0; list[i]; i++)
2790 if (!func( list[i], lParam )) break;
2791 HeapFree( GetProcessHeap(), 0, list );
2796 /**********************************************************************
2797 * WIN_EnumChildWindows
2799 * Helper function for EnumChildWindows().
2801 static BOOL WIN_EnumChildWindows( HWND *list, WNDENUMPROC func, LPARAM lParam )
2806 for ( ; *list; list++)
2808 /* Make sure that the window still exists */
2809 if (!IsWindow( *list )) continue;
2810 /* skip owned windows */
2811 if (GetWindow( *list, GW_OWNER )) continue;
2812 /* Build children list first */
2813 childList = WIN_ListChildren( *list );
2815 ret = func( *list, lParam );
2819 if (ret) ret = WIN_EnumChildWindows( childList, func, lParam );
2820 HeapFree( GetProcessHeap(), 0, childList );
2822 if (!ret) return FALSE;
2828 /**********************************************************************
2829 * EnumChildWindows (USER32.@)
2831 BOOL WINAPI EnumChildWindows( HWND parent, WNDENUMPROC func, LPARAM lParam )
2835 USER_CheckNotLock();
2837 if (!(list = WIN_ListChildren( parent ))) return FALSE;
2838 WIN_EnumChildWindows( list, func, lParam );
2839 HeapFree( GetProcessHeap(), 0, list );
2844 /*******************************************************************
2845 * AnyPopup (USER.52)
2847 BOOL16 WINAPI AnyPopup16(void)
2853 /*******************************************************************
2854 * AnyPopup (USER32.@)
2856 BOOL WINAPI AnyPopup(void)
2860 HWND *list = WIN_ListChildren( GetDesktopWindow() );
2862 if (!list) return FALSE;
2863 for (i = 0; list[i]; i++)
2865 if (IsWindowVisible( list[i] ) && GetWindow( list[i], GW_OWNER )) break;
2867 retvalue = (list[i] != 0);
2868 HeapFree( GetProcessHeap(), 0, list );
2873 /*******************************************************************
2874 * FlashWindow (USER32.@)
2876 BOOL WINAPI FlashWindow( HWND hWnd, BOOL bInvert )
2880 TRACE("%p\n", hWnd);
2882 if (IsIconic( hWnd ))
2884 RedrawWindow( hWnd, 0, 0, RDW_INVALIDATE | RDW_ERASE | RDW_UPDATENOW | RDW_FRAME );
2886 wndPtr = WIN_GetPtr(hWnd);
2887 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
2888 if (bInvert && !(wndPtr->flags & WIN_NCACTIVATED))
2890 wndPtr->flags |= WIN_NCACTIVATED;
2894 wndPtr->flags &= ~WIN_NCACTIVATED;
2896 WIN_ReleasePtr( wndPtr );
2903 wndPtr = WIN_GetPtr(hWnd);
2904 if (!wndPtr || wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
2905 hWnd = wndPtr->hwndSelf; /* make it a full handle */
2907 if (bInvert) wparam = !(wndPtr->flags & WIN_NCACTIVATED);
2908 else wparam = (hWnd == GetForegroundWindow());
2910 WIN_ReleasePtr( wndPtr );
2911 SendMessageW( hWnd, WM_NCACTIVATE, wparam, (LPARAM)0 );
2916 /*******************************************************************
2917 * FlashWindowEx (USER32.@)
2919 BOOL WINAPI FlashWindowEx( PFLASHWINFO pfwi )
2921 FIXME("%p\n", pfwi);
2925 /*******************************************************************
2926 * GetWindowContextHelpId (USER32.@)
2928 DWORD WINAPI GetWindowContextHelpId( HWND hwnd )
2931 WND *wnd = WIN_GetPtr( hwnd );
2932 if (!wnd || wnd == WND_DESKTOP) return 0;
2933 if (wnd == WND_OTHER_PROCESS)
2935 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
2938 retval = wnd->helpContext;
2939 WIN_ReleasePtr( wnd );
2944 /*******************************************************************
2945 * SetWindowContextHelpId (USER32.@)
2947 BOOL WINAPI SetWindowContextHelpId( HWND hwnd, DWORD id )
2949 WND *wnd = WIN_GetPtr( hwnd );
2950 if (!wnd || wnd == WND_DESKTOP) return FALSE;
2951 if (wnd == WND_OTHER_PROCESS)
2953 if (IsWindow( hwnd )) FIXME( "not supported on other process window %p\n", hwnd );
2956 wnd->helpContext = id;
2957 WIN_ReleasePtr( wnd );
2962 /*******************************************************************
2963 * DragDetect (USER32.@)
2965 BOOL WINAPI DragDetect( HWND hWnd, POINT pt )
2970 rect.left = pt.x - wDragWidth;
2971 rect.right = pt.x + wDragWidth;
2973 rect.top = pt.y - wDragHeight;
2974 rect.bottom = pt.y + wDragHeight;
2980 while (PeekMessageW( &msg, 0, WM_MOUSEFIRST, WM_MOUSELAST, PM_REMOVE ))
2982 if( msg.message == WM_LBUTTONUP )
2987 if( msg.message == WM_MOUSEMOVE )
2990 tmp.x = LOWORD(msg.lParam);
2991 tmp.y = HIWORD(msg.lParam);
2992 if( !PtInRect( &rect, tmp ))
3004 /******************************************************************************
3005 * GetWindowModuleFileNameA (USER32.@)
3007 UINT WINAPI GetWindowModuleFileNameA( HWND hwnd, LPSTR lpszFileName, UINT cchFileNameMax)
3009 FIXME("GetWindowModuleFileNameA(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3010 hwnd, lpszFileName, cchFileNameMax);
3014 /******************************************************************************
3015 * GetWindowModuleFileNameW (USER32.@)
3017 UINT WINAPI GetWindowModuleFileNameW( HWND hwnd, LPWSTR lpszFileName, UINT cchFileNameMax)
3019 FIXME("GetWindowModuleFileNameW(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3020 hwnd, lpszFileName, cchFileNameMax);
3024 /******************************************************************************
3025 * GetWindowInfo (USER32.@)
3027 * Note: tests show that Windows doesn't check cbSize of the structure.
3029 BOOL WINAPI GetWindowInfo( HWND hwnd, PWINDOWINFO pwi)
3031 if (!pwi) return FALSE;
3032 if (!IsWindow(hwnd)) return FALSE;
3034 GetWindowRect(hwnd, &pwi->rcWindow);
3035 GetClientRect(hwnd, &pwi->rcClient);
3036 /* translate to screen coordinates */
3037 MapWindowPoints(hwnd, 0, (LPPOINT)&pwi->rcClient, 2);
3039 pwi->dwStyle = GetWindowLongW(hwnd, GWL_STYLE);
3040 pwi->dwExStyle = GetWindowLongW(hwnd, GWL_EXSTYLE);
3041 pwi->dwWindowStatus = ((GetActiveWindow() == hwnd) ? WS_ACTIVECAPTION : 0);
3043 pwi->cxWindowBorders = pwi->rcClient.left - pwi->rcWindow.left;
3044 pwi->cyWindowBorders = pwi->rcWindow.bottom - pwi->rcClient.bottom;
3046 pwi->atomWindowType = GetClassLongW( hwnd, GCW_ATOM );
3047 pwi->wCreatorVersion = 0x0400;
3052 /******************************************************************************
3053 * SwitchDesktop (USER32.@)
3055 * NOTES: Sets the current input or interactive desktop.
3057 BOOL WINAPI SwitchDesktop( HDESK hDesktop)
3059 FIXME("SwitchDesktop(hwnd %p) stub!\n", hDesktop);
3063 /*****************************************************************************
3064 * SetLayeredWindowAttributes (USER32.@)
3066 BOOL WINAPI SetLayeredWindowAttributes( HWND hWnd, COLORREF rgbKey,
3067 BYTE bAlpha, DWORD dwFlags )
3069 FIXME("(%p,0x%.8lx,%d,%ld): stub!\n", hWnd, rgbKey, bAlpha, dwFlags);