msxml4/tests: Copy namespaces as attributes tests.
[wine.git] / dlls / user32 / win.c
blob6459ddf9f2800520cc9e8dd7c19f7397e2cf91fa
1 /*
2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include "user_private.h"
22 #include "controls.h"
23 #include "winver.h"
24 #include "wine/server.h"
25 #include "wine/asm.h"
26 #include "wine/exception.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(win);
32 /*******************************************************************
33 * list_window_children
35 * Build an array of the children of a given window. The array must be
36 * freed with HeapFree. Returns NULL when no windows are found.
38 static HWND *list_window_children( HDESK desktop, HWND hwnd, UNICODE_STRING *class, DWORD tid )
40 HWND *list;
41 int i, size = 128;
42 ATOM atom = class ? get_int_atom_value( class ) : 0;
44 /* empty class is not the same as NULL class */
45 if (!atom && class && !class->Length) return NULL;
47 for (;;)
49 int count = 0;
51 if (!(list = HeapAlloc( GetProcessHeap(), 0, size * sizeof(HWND) ))) break;
53 SERVER_START_REQ( get_window_children )
55 req->desktop = wine_server_obj_handle( desktop );
56 req->parent = wine_server_user_handle( hwnd );
57 req->tid = tid;
58 req->atom = atom;
59 if (!atom && class) wine_server_add_data( req, class->Buffer, class->Length );
60 wine_server_set_reply( req, list, (size-1) * sizeof(user_handle_t) );
61 if (!wine_server_call( req )) count = reply->count;
63 SERVER_END_REQ;
64 if (count && count < size)
66 /* start from the end since HWND is potentially larger than user_handle_t */
67 for (i = count - 1; i >= 0; i--)
68 list[i] = wine_server_ptr_handle( ((user_handle_t *)list)[i] );
69 list[count] = 0;
70 return list;
72 HeapFree( GetProcessHeap(), 0, list );
73 if (!count) break;
74 size = count + 1; /* restart with a large enough buffer */
76 return NULL;
80 /*******************************************************************
81 * is_desktop_window
83 * Check if window is the desktop or the HWND_MESSAGE top parent.
85 BOOL is_desktop_window( HWND hwnd )
87 struct ntuser_thread_info *thread_info = NtUserGetThreadInfo();
89 if (!hwnd) return FALSE;
90 if (hwnd == UlongToHandle( thread_info->top_window )) return TRUE;
91 if (hwnd == UlongToHandle( thread_info->msg_window )) return TRUE;
93 if (!HIWORD(hwnd) || HIWORD(hwnd) == 0xffff)
95 if (LOWORD(thread_info->top_window) == LOWORD(hwnd)) return TRUE;
96 if (LOWORD(thread_info->msg_window) == LOWORD(hwnd)) return TRUE;
98 return FALSE;
102 /* check if hwnd is a broadcast magic handle */
103 static inline BOOL is_broadcast( HWND hwnd )
105 return hwnd == HWND_BROADCAST || hwnd == HWND_TOPMOST;
109 /***********************************************************************
110 * WIN_IsCurrentProcess
112 * Check whether a given window belongs to the current process (and return the full handle).
114 HWND WIN_IsCurrentProcess( HWND hwnd )
116 return UlongToHandle( NtUserCallHwnd( hwnd, NtUserIsCurrentProcessWindow ));
120 /***********************************************************************
121 * WIN_IsCurrentThread
123 * Check whether a given window belongs to the current thread (and return the full handle).
125 HWND WIN_IsCurrentThread( HWND hwnd )
127 return UlongToHandle( NtUserCallHwnd( hwnd, NtUserIsCurrentThreadWindow ));
131 /***********************************************************************
132 * WIN_GetFullHandle
134 * Convert a possibly truncated window handle to a full 32-bit handle.
136 HWND WIN_GetFullHandle( HWND hwnd )
138 return UlongToHandle( NtUserCallHwnd( hwnd, NtUserGetFullWindowHandle ));
142 /***********************************************************************
143 * WIN_SetStyle
145 * Change the style of a window.
147 ULONG WIN_SetStyle( HWND hwnd, ULONG set_bits, ULONG clear_bits )
149 /* FIXME: Use SetWindowLong or move callers to win32u instead.
150 * We use STYLESTRUCT to pass params, but meaning of its field does not match our usage. */
151 STYLESTRUCT style = { .styleNew = set_bits, .styleOld = clear_bits };
152 return NtUserCallHwndParam( hwnd, (UINT_PTR)&style, NtUserSetWindowStyle );
156 /***********************************************************************
157 * dump_window_styles
159 static void dump_window_styles( DWORD style, DWORD exstyle )
161 TRACE( "style:" );
162 if(style & WS_POPUP) TRACE(" WS_POPUP");
163 if(style & WS_CHILD) TRACE(" WS_CHILD");
164 if(style & WS_MINIMIZE) TRACE(" WS_MINIMIZE");
165 if(style & WS_VISIBLE) TRACE(" WS_VISIBLE");
166 if(style & WS_DISABLED) TRACE(" WS_DISABLED");
167 if(style & WS_CLIPSIBLINGS) TRACE(" WS_CLIPSIBLINGS");
168 if(style & WS_CLIPCHILDREN) TRACE(" WS_CLIPCHILDREN");
169 if(style & WS_MAXIMIZE) TRACE(" WS_MAXIMIZE");
170 if((style & WS_CAPTION) == WS_CAPTION) TRACE(" WS_CAPTION");
171 else
173 if(style & WS_BORDER) TRACE(" WS_BORDER");
174 if(style & WS_DLGFRAME) TRACE(" WS_DLGFRAME");
176 if(style & WS_VSCROLL) TRACE(" WS_VSCROLL");
177 if(style & WS_HSCROLL) TRACE(" WS_HSCROLL");
178 if(style & WS_SYSMENU) TRACE(" WS_SYSMENU");
179 if(style & WS_THICKFRAME) TRACE(" WS_THICKFRAME");
180 if (style & WS_CHILD)
182 if(style & WS_GROUP) TRACE(" WS_GROUP");
183 if(style & WS_TABSTOP) TRACE(" WS_TABSTOP");
185 else
187 if(style & WS_MINIMIZEBOX) TRACE(" WS_MINIMIZEBOX");
188 if(style & WS_MAXIMIZEBOX) TRACE(" WS_MAXIMIZEBOX");
191 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
192 #define DUMPED_STYLES \
193 ((DWORD)(WS_POPUP | \
194 WS_CHILD | \
195 WS_MINIMIZE | \
196 WS_VISIBLE | \
197 WS_DISABLED | \
198 WS_CLIPSIBLINGS | \
199 WS_CLIPCHILDREN | \
200 WS_MAXIMIZE | \
201 WS_BORDER | \
202 WS_DLGFRAME | \
203 WS_VSCROLL | \
204 WS_HSCROLL | \
205 WS_SYSMENU | \
206 WS_THICKFRAME | \
207 WS_GROUP | \
208 WS_TABSTOP | \
209 WS_MINIMIZEBOX | \
210 WS_MAXIMIZEBOX))
212 if(style & ~DUMPED_STYLES) TRACE(" %08lx", style & ~DUMPED_STYLES);
213 TRACE("\n");
214 #undef DUMPED_STYLES
216 TRACE( "exstyle:" );
217 if(exstyle & WS_EX_DLGMODALFRAME) TRACE(" WS_EX_DLGMODALFRAME");
218 if(exstyle & WS_EX_DRAGDETECT) TRACE(" WS_EX_DRAGDETECT");
219 if(exstyle & WS_EX_NOPARENTNOTIFY) TRACE(" WS_EX_NOPARENTNOTIFY");
220 if(exstyle & WS_EX_TOPMOST) TRACE(" WS_EX_TOPMOST");
221 if(exstyle & WS_EX_ACCEPTFILES) TRACE(" WS_EX_ACCEPTFILES");
222 if(exstyle & WS_EX_TRANSPARENT) TRACE(" WS_EX_TRANSPARENT");
223 if(exstyle & WS_EX_MDICHILD) TRACE(" WS_EX_MDICHILD");
224 if(exstyle & WS_EX_TOOLWINDOW) TRACE(" WS_EX_TOOLWINDOW");
225 if(exstyle & WS_EX_WINDOWEDGE) TRACE(" WS_EX_WINDOWEDGE");
226 if(exstyle & WS_EX_CLIENTEDGE) TRACE(" WS_EX_CLIENTEDGE");
227 if(exstyle & WS_EX_CONTEXTHELP) TRACE(" WS_EX_CONTEXTHELP");
228 if(exstyle & WS_EX_RIGHT) TRACE(" WS_EX_RIGHT");
229 if(exstyle & WS_EX_RTLREADING) TRACE(" WS_EX_RTLREADING");
230 if(exstyle & WS_EX_LEFTSCROLLBAR) TRACE(" WS_EX_LEFTSCROLLBAR");
231 if(exstyle & WS_EX_CONTROLPARENT) TRACE(" WS_EX_CONTROLPARENT");
232 if(exstyle & WS_EX_STATICEDGE) TRACE(" WS_EX_STATICEDGE");
233 if(exstyle & WS_EX_APPWINDOW) TRACE(" WS_EX_APPWINDOW");
234 if(exstyle & WS_EX_LAYERED) TRACE(" WS_EX_LAYERED");
235 if(exstyle & WS_EX_NOINHERITLAYOUT) TRACE(" WS_EX_NOINHERITLAYOUT");
236 if(exstyle & WS_EX_LAYOUTRTL) TRACE(" WS_EX_LAYOUTRTL");
237 if(exstyle & WS_EX_COMPOSITED) TRACE(" WS_EX_COMPOSITED");
238 if(exstyle & WS_EX_NOACTIVATE) TRACE(" WS_EX_NOACTIVATE");
240 #define DUMPED_EX_STYLES \
241 ((DWORD)(WS_EX_DLGMODALFRAME | \
242 WS_EX_DRAGDETECT | \
243 WS_EX_NOPARENTNOTIFY | \
244 WS_EX_TOPMOST | \
245 WS_EX_ACCEPTFILES | \
246 WS_EX_TRANSPARENT | \
247 WS_EX_MDICHILD | \
248 WS_EX_TOOLWINDOW | \
249 WS_EX_WINDOWEDGE | \
250 WS_EX_CLIENTEDGE | \
251 WS_EX_CONTEXTHELP | \
252 WS_EX_RIGHT | \
253 WS_EX_RTLREADING | \
254 WS_EX_LEFTSCROLLBAR | \
255 WS_EX_CONTROLPARENT | \
256 WS_EX_STATICEDGE | \
257 WS_EX_APPWINDOW | \
258 WS_EX_LAYERED | \
259 WS_EX_NOINHERITLAYOUT | \
260 WS_EX_LAYOUTRTL | \
261 WS_EX_COMPOSITED |\
262 WS_EX_NOACTIVATE))
264 if(exstyle & ~DUMPED_EX_STYLES) TRACE(" %08lx", exstyle & ~DUMPED_EX_STYLES);
265 TRACE("\n");
266 #undef DUMPED_EX_STYLES
269 static BOOL is_default_coord( int x )
271 return x == CW_USEDEFAULT || x == 0x8000;
274 /***********************************************************************
275 * WIN_CreateWindowEx
277 * Implementation of CreateWindowEx().
279 HWND WIN_CreateWindowEx( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE module, BOOL unicode )
281 UNICODE_STRING class, window_name = {0};
282 HWND hwnd, top_child = 0;
283 MDICREATESTRUCTW mdi_cs;
284 WNDCLASSEXW info;
285 WCHAR name_buf[8];
286 HMENU menu;
288 if (!get_class_info( module, className, &info, &class, FALSE )) return FALSE;
290 TRACE("%s %s%s%s ex=%08lx style=%08lx %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
291 unicode ? debugstr_w(cs->lpszName) : debugstr_a((LPCSTR)cs->lpszName),
292 debugstr_w(className), class.Buffer != className ? "->" : "",
293 class.Buffer != className ? debugstr_wn(class.Buffer, class.Length / sizeof(WCHAR)) : "",
294 cs->dwExStyle, cs->style, cs->x, cs->y, cs->cx, cs->cy,
295 cs->hwndParent, cs->hMenu, cs->hInstance, cs->lpCreateParams );
296 if(TRACE_ON(win)) dump_window_styles( cs->style, cs->dwExStyle );
298 /* Fix the styles for MDI children */
299 if (cs->dwExStyle & WS_EX_MDICHILD)
301 POINT pos[2];
302 UINT id = 0;
304 if (!NtUserGetMDIClientInfo( cs->hwndParent ))
306 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs->hwndParent);
307 return 0;
310 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
311 * MDICREATESTRUCT members have the originally passed values.
313 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
314 * have the same layout.
316 mdi_cs.szClass = cs->lpszClass;
317 mdi_cs.szTitle = cs->lpszName;
318 mdi_cs.hOwner = cs->hInstance;
319 mdi_cs.x = cs->x;
320 mdi_cs.y = cs->y;
321 mdi_cs.cx = cs->cx;
322 mdi_cs.cy = cs->cy;
323 mdi_cs.style = cs->style;
324 mdi_cs.lParam = (LPARAM)cs->lpCreateParams;
326 cs->lpCreateParams = &mdi_cs;
328 if (GetWindowLongW(cs->hwndParent, GWL_STYLE) & MDIS_ALLCHILDSTYLES)
330 if (cs->style & WS_POPUP)
332 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
333 return 0;
335 cs->style |= WS_CHILD | WS_CLIPSIBLINGS;
337 else
339 cs->style &= ~WS_POPUP;
340 cs->style |= WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CAPTION |
341 WS_SYSMENU | WS_THICKFRAME | WS_MINIMIZEBOX | WS_MAXIMIZEBOX;
344 top_child = GetWindow(cs->hwndParent, GW_CHILD);
346 if (top_child)
348 /* Restore current maximized child */
349 if((cs->style & WS_VISIBLE) && IsZoomed(top_child))
351 TRACE("Restoring current maximized child %p\n", top_child);
352 if (cs->style & WS_MAXIMIZE)
354 /* if the new window is maximized don't bother repainting */
355 SendMessageW( top_child, WM_SETREDRAW, FALSE, 0 );
356 NtUserShowWindow( top_child, SW_SHOWNORMAL );
357 SendMessageW( top_child, WM_SETREDRAW, TRUE, 0 );
359 else NtUserShowWindow( top_child, SW_SHOWNORMAL );
363 MDI_CalcDefaultChildPos( cs->hwndParent, -1, pos, 0, &id );
364 if (!(cs->style & WS_POPUP)) cs->hMenu = ULongToHandle(id);
366 TRACE( "MDI child id %04x\n", id );
368 if (cs->style & (WS_CHILD | WS_POPUP))
370 if (is_default_coord( cs->x ))
372 cs->x = pos[0].x;
373 cs->y = pos[0].y;
375 if (is_default_coord( cs->cx ) || !cs->cx) cs->cx = pos[1].x;
376 if (is_default_coord( cs->cy ) || !cs->cy) cs->cy = pos[1].y;
380 if (!unicode && cs->lpszName)
382 const char *nameA = (const char *)cs->lpszName;
383 /* resource ID string is a special case */
384 if (nameA[0] == '\xff')
386 name_buf[0] = 0xffff;
387 name_buf[1] = MAKEWORD( nameA[1], nameA[2] );
388 name_buf[2] = 0;
389 RtlInitUnicodeString( &window_name, name_buf );
391 else if (!RtlCreateUnicodeStringFromAsciiz( &window_name, (const char *)cs->lpszName ))
392 return 0;
394 else RtlInitUnicodeString( &window_name, cs->lpszName );
396 menu = cs->hMenu;
397 if (!menu && info.lpszMenuName && (cs->style & (WS_CHILD | WS_POPUP)) != WS_CHILD)
398 menu = LoadMenuW( cs->hInstance, info.lpszMenuName );
400 hwnd = NtUserCreateWindowEx( cs->dwExStyle, &class, NULL, &window_name, cs->style,
401 cs->x, cs->y, cs->cx, cs->cy, cs->hwndParent, menu, module,
402 cs->lpCreateParams, 0, cs->hInstance, 0, !unicode );
403 if (!hwnd && menu && menu != cs->hMenu) NtUserDestroyMenu( menu );
404 if (!unicode && window_name.Buffer != name_buf) RtlFreeUnicodeString( &window_name );
405 return hwnd;
409 /***********************************************************************
410 * CreateWindowExA (USER32.@)
412 HWND WINAPI DECLSPEC_HOTPATCH CreateWindowExA( DWORD exStyle, LPCSTR className,
413 LPCSTR windowName, DWORD style, INT x,
414 INT y, INT width, INT height,
415 HWND parent, HMENU menu,
416 HINSTANCE instance, LPVOID data )
418 CREATESTRUCTA cs;
420 cs.lpCreateParams = data;
421 cs.hInstance = instance;
422 cs.hMenu = menu;
423 cs.hwndParent = parent;
424 cs.x = x;
425 cs.y = y;
426 cs.cx = width;
427 cs.cy = height;
428 cs.style = style;
429 cs.lpszName = windowName;
430 cs.lpszClass = className;
431 cs.dwExStyle = exStyle;
433 if (!IS_INTRESOURCE(className))
435 WCHAR bufferW[256];
436 if (!MultiByteToWideChar( CP_ACP, 0, className, -1, bufferW, ARRAY_SIZE( bufferW )))
437 return 0;
438 return wow_handlers.create_window( (CREATESTRUCTW *)&cs, bufferW, instance, FALSE );
440 /* Note: we rely on the fact that CREATESTRUCTA and */
441 /* CREATESTRUCTW have the same layout. */
442 return wow_handlers.create_window( (CREATESTRUCTW *)&cs, (LPCWSTR)className, instance, FALSE );
446 /***********************************************************************
447 * CreateWindowExW (USER32.@)
449 HWND WINAPI DECLSPEC_HOTPATCH CreateWindowExW( DWORD exStyle, LPCWSTR className,
450 LPCWSTR windowName, DWORD style, INT x,
451 INT y, INT width, INT height,
452 HWND parent, HMENU menu,
453 HINSTANCE instance, LPVOID data )
455 CREATESTRUCTW cs;
457 cs.lpCreateParams = data;
458 cs.hInstance = instance;
459 cs.hMenu = menu;
460 cs.hwndParent = parent;
461 cs.x = x;
462 cs.y = y;
463 cs.cx = width;
464 cs.cy = height;
465 cs.style = style;
466 cs.lpszName = windowName;
467 cs.lpszClass = className;
468 cs.dwExStyle = exStyle;
470 return wow_handlers.create_window( &cs, className, instance, TRUE );
474 /***********************************************************************
475 * CloseWindow (USER32.@)
477 BOOL WINAPI CloseWindow( HWND hwnd )
479 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD) return FALSE;
480 NtUserShowWindow( hwnd, SW_MINIMIZE );
481 return TRUE;
485 /***********************************************************************
486 * OpenIcon (USER32.@)
488 BOOL WINAPI OpenIcon( HWND hwnd )
490 if (!IsIconic( hwnd )) return FALSE;
491 NtUserShowWindow( hwnd, SW_SHOWNORMAL );
492 return TRUE;
496 /***********************************************************************
497 * FindWindowExW (USER32.@)
499 HWND WINAPI FindWindowExW( HWND parent, HWND child, const WCHAR *class, const WCHAR *title )
501 UNICODE_STRING class_str, title_str;
503 if (title) RtlInitUnicodeString( &title_str, title );
505 if (class)
507 if (IS_INTRESOURCE(class))
509 class_str.Buffer = (WCHAR *)class;
510 class_str.Length = class_str.MaximumLength = 0;
512 else RtlInitUnicodeString( &class_str, class );
515 return NtUserFindWindowEx( parent, child, class ? &class_str : NULL,
516 title ? &title_str : NULL, 0 );
521 /***********************************************************************
522 * FindWindowA (USER32.@)
524 HWND WINAPI FindWindowA( LPCSTR className, LPCSTR title )
526 HWND ret = FindWindowExA( 0, 0, className, title );
527 if (!ret) SetLastError (ERROR_CANNOT_FIND_WND_CLASS);
528 return ret;
532 /***********************************************************************
533 * FindWindowExA (USER32.@)
535 HWND WINAPI FindWindowExA( HWND parent, HWND child, LPCSTR className, LPCSTR title )
537 LPWSTR titleW = NULL;
538 HWND hwnd = 0;
540 if (title)
542 DWORD len = MultiByteToWideChar( CP_ACP, 0, title, -1, NULL, 0 );
543 if (!(titleW = HeapAlloc( GetProcessHeap(), 0, len * sizeof(WCHAR) ))) return 0;
544 MultiByteToWideChar( CP_ACP, 0, title, -1, titleW, len );
547 if (!IS_INTRESOURCE(className))
549 WCHAR classW[256];
550 if (MultiByteToWideChar( CP_ACP, 0, className, -1, classW, ARRAY_SIZE( classW )))
551 hwnd = FindWindowExW( parent, child, classW, titleW );
553 else
555 hwnd = FindWindowExW( parent, child, (LPCWSTR)className, titleW );
558 HeapFree( GetProcessHeap(), 0, titleW );
559 return hwnd;
563 /***********************************************************************
564 * FindWindowW (USER32.@)
566 HWND WINAPI FindWindowW( LPCWSTR className, LPCWSTR title )
568 return FindWindowExW( 0, 0, className, title );
572 /**********************************************************************
573 * GetDesktopWindow (USER32.@)
575 HWND WINAPI GetDesktopWindow(void)
577 struct ntuser_thread_info *thread_info = NtUserGetThreadInfo();
579 if (thread_info->top_window) return UlongToHandle( thread_info->top_window );
580 return NtUserGetDesktopWindow();
584 /*******************************************************************
585 * EnableWindow (USER32.@)
587 BOOL WINAPI EnableWindow( HWND hwnd, BOOL enable )
589 return NtUserEnableWindow( hwnd, enable );
593 /***********************************************************************
594 * IsWindowEnabled (USER32.@)
596 BOOL WINAPI IsWindowEnabled( HWND hwnd )
598 return NtUserIsWindowEnabled( hwnd );
601 /***********************************************************************
602 * IsWindowUnicode (USER32.@)
604 BOOL WINAPI IsWindowUnicode( HWND hwnd )
606 return NtUserIsWindowUnicode( hwnd );
610 /***********************************************************************
611 * GetWindowDpiAwarenessContext (USER32.@)
613 DPI_AWARENESS_CONTEXT WINAPI GetWindowDpiAwarenessContext( HWND hwnd )
615 return NtUserGetWindowDpiAwarenessContext( hwnd );
619 static LONG_PTR get_window_long_ptr( HWND hwnd, int offset, LONG_PTR ret, BOOL ansi )
621 if (offset == DWLP_DLGPROC && NtUserGetDialogInfo( hwnd ))
623 DLGPROC proc = NtUserGetDialogProc( (DLGPROC)ret, ansi );
624 if (proc && proc != WINPROC_PROC16) return (LONG_PTR)proc;
626 return ret;
630 static LONG_PTR set_dialog_proc( HWND hwnd, LONG_PTR newval, BOOL ansi )
632 DLGPROC proc;
633 LONG_PTR ret;
634 newval = NtUserCallTwoParam( newval, ansi, NtUserAllocWinProc );
635 ret = NtUserSetWindowLongPtr( hwnd, DWLP_DLGPROC, newval, ansi );
636 proc = NtUserGetDialogProc( (DLGPROC)ret, ansi );
637 if (proc) ret = (UINT_PTR)proc;
638 return ret;
642 /***********************************************************************
643 * GetDpiForWindow (USER32.@)
645 UINT WINAPI GetDpiForWindow( HWND hwnd )
647 return NtUserGetDpiForWindow( hwnd );
651 /***********************************************************************
652 * SwitchToThisWindow (USER32.@)
654 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL alt_tab )
656 if (IsIconic( hwnd )) NtUserShowWindow( hwnd, SW_RESTORE );
657 else BringWindowToTop( hwnd );
661 /***********************************************************************
662 * GetWindowRect (USER32.@)
664 BOOL WINAPI GetWindowRect( HWND hwnd, RECT *rect )
666 BOOL ret = NtUserGetWindowRect( hwnd, rect );
667 if (ret) TRACE( "hwnd %p %s\n", hwnd, wine_dbgstr_rect(rect) );
668 return ret;
672 /***********************************************************************
673 * GetWindowRgn (USER32.@)
675 int WINAPI GetWindowRgn( HWND hwnd, HRGN hrgn )
677 return NtUserGetWindowRgnEx( hwnd, hrgn, 0 );
681 /***********************************************************************
682 * GetWindowRgnBox (USER32.@)
684 int WINAPI GetWindowRgnBox( HWND hwnd, RECT *rect )
686 int ret = ERROR;
687 HRGN hrgn;
689 if (!rect)
690 return ERROR;
692 if ((hrgn = CreateRectRgn( 0, 0, 0, 0 )))
694 if ((ret = GetWindowRgn( hwnd, hrgn )) != ERROR )
695 ret = GetRgnBox( hrgn, rect );
696 DeleteObject( hrgn );
699 return ret;
703 /***********************************************************************
704 * GetClientRect (USER32.@)
706 BOOL WINAPI GetClientRect( HWND hwnd, RECT *rect )
708 return NtUserGetClientRect( hwnd, rect );
712 /*******************************************************************
713 * WindowFromPoint (USER32.@)
715 HWND WINAPI WindowFromPoint( POINT pt )
717 return NtUserWindowFromPoint( pt.x, pt.y );
721 /*******************************************************************
722 * ChildWindowFromPoint (USER32.@)
724 HWND WINAPI ChildWindowFromPoint( HWND parent, POINT pt )
726 return NtUserChildWindowFromPointEx( parent, pt.x, pt.y, CWP_ALL );
729 /*******************************************************************
730 * RealChildWindowFromPoint (USER32.@)
732 HWND WINAPI RealChildWindowFromPoint( HWND parent, POINT pt )
734 return NtUserRealChildWindowFromPoint( parent, pt.x, pt.y );
737 /*******************************************************************
738 * ChildWindowFromPointEx (USER32.@)
740 HWND WINAPI ChildWindowFromPointEx( HWND parent, POINT pt, UINT flags )
742 return NtUserChildWindowFromPointEx( parent, pt.x, pt.y, flags );
746 /*******************************************************************
747 * MapWindowPoints (USER32.@)
749 INT WINAPI MapWindowPoints( HWND hwnd_from, HWND hwnd_to, POINT *points, UINT count )
751 return NtUserMapWindowPoints( hwnd_from, hwnd_to, points, count );
755 /*******************************************************************
756 * ClientToScreen (USER32.@)
758 BOOL WINAPI ClientToScreen( HWND hwnd, POINT *pt )
760 return NtUserClientToScreen( hwnd, pt );
764 /*******************************************************************
765 * ScreenToClient (USER32.@)
767 BOOL WINAPI ScreenToClient( HWND hwnd, POINT *pt )
769 return NtUserScreenToClient( hwnd, pt );
773 /***********************************************************************
774 * IsIconic (USER32.@)
776 BOOL WINAPI IsIconic( HWND hwnd )
778 return (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
782 /***********************************************************************
783 * IsZoomed (USER32.@)
785 BOOL WINAPI IsZoomed( HWND hwnd )
787 return (GetWindowLongW( hwnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
791 /*******************************************************************
792 * AllowSetForegroundWindow (USER32.@)
794 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
796 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
797 * implemented, then fix this function. */
798 return TRUE;
802 /*******************************************************************
803 * LockSetForegroundWindow (USER32.@)
805 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
807 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
808 * implemented, then fix this function. */
809 return TRUE;
813 /***********************************************************************
814 * BringWindowToTop (USER32.@)
816 BOOL WINAPI BringWindowToTop( HWND hwnd )
818 return NtUserSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
822 /***********************************************************************
823 * AnimateWindow (USER32.@)
825 BOOL WINAPI AnimateWindow( HWND hwnd, DWORD time, DWORD flags )
827 FIXME( "partial stub\n" );
829 /* If trying to show/hide and it's already shown/hidden or invalid window,
830 * fail with invalid parameter. */
831 if (!IsWindow( hwnd ) || (!(flags & AW_HIDE)) == IsWindowVisible( hwnd ))
833 SetLastError(ERROR_INVALID_PARAMETER);
834 return FALSE;
837 NtUserShowWindow( hwnd, (flags & AW_HIDE) ? SW_HIDE : ((flags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA) );
838 return TRUE;
842 /***********************************************************************
843 * BeginDeferWindowPos (USER32.@)
845 HDWP WINAPI BeginDeferWindowPos( INT count )
847 return NtUserBeginDeferWindowPos( count );
851 /***********************************************************************
852 * DeferWindowPos (USER32.@)
854 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND after, INT x, INT y,
855 INT cx, INT cy, UINT flags )
857 return NtUserDeferWindowPosAndBand( hdwp, hwnd, after, x, y, cx, cy, flags, 0, 0 );
861 /***********************************************************************
862 * EndDeferWindowPos (USER32.@)
864 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
866 return NtUserEndDeferWindowPosEx( hdwp, FALSE );
870 /***********************************************************************
871 * ArrangeIconicWindows (USER32.@)
873 UINT WINAPI ArrangeIconicWindows( HWND parent )
875 return NtUserArrangeIconicWindows( parent );
879 /**********************************************************************
880 * GetWindowWord (USER32.@)
882 WORD WINAPI GetWindowWord( HWND hwnd, INT offset )
884 return NtUserGetWindowWord( hwnd, offset );
888 /**********************************************************************
889 * GetWindowLongA (USER32.@)
892 #ifdef __i386__
894 /* This wrapper is here to workaround a ntlea quirk. First of all, ntlea
895 * checks whether GetWindowLongA starts with the Win32 hotpatchable prologue,
896 * if it can find that, it will use a hooking strategy more difficult for us
897 * to deal with. Secondly, it assumes what follows the prologue is a `pushl $-2`,
898 * and will try to skip over this instruction when calling `GetWindowLongA`,
899 * (i.e. it tries to jump to `GetWindowLongA + 7`, 5 bytes for the prologue, 2
900 * bytes for the `pushl`.). We have to anticipate that and make sure the result
901 * of doing this won't be a messed up stack, or a desynced PC.
903 __ASM_STDCALL_FUNC( GetWindowLongA, 8,
904 ".byte 0x8b, 0xff, 0x55, 0x8b, 0xec\n" /* Win32 hotpatchable prologue. */
905 "pushl $-2\n"
906 "addl $4, %esp\n"
907 "popl %ebp\n"
908 "jmp " __ASM_STDCALL("get_window_longA", 8) )
909 LONG WINAPI get_window_longA( HWND hwnd, INT offset )
910 #else
911 LONG WINAPI DECLSPEC_HOTPATCH GetWindowLongA( HWND hwnd, INT offset )
912 #endif
914 switch (offset)
916 #ifdef _WIN64
917 case GWLP_WNDPROC:
918 case GWLP_HINSTANCE:
919 case GWLP_HWNDPARENT:
920 WARN( "Invalid offset %d\n", offset );
921 SetLastError( ERROR_INVALID_INDEX );
922 return 0;
923 #endif
924 default:
925 if (sizeof(void *) == sizeof(LONG))
927 LONG_PTR ret = NtUserGetWindowLongA( hwnd, offset );
928 return get_window_long_ptr( hwnd, offset, ret, TRUE );
930 return NtUserGetWindowLongA( hwnd, offset );
935 /**********************************************************************
936 * GetWindowLongW (USER32.@)
938 LONG WINAPI GetWindowLongW( HWND hwnd, INT offset )
940 switch (offset)
942 #ifdef _WIN64
943 case GWLP_WNDPROC:
944 case GWLP_HINSTANCE:
945 case GWLP_HWNDPARENT:
946 WARN( "Invalid offset %d\n", offset );
947 SetLastError( ERROR_INVALID_INDEX );
948 return 0;
949 #endif
950 default:
951 if (sizeof(void *) == sizeof(LONG))
953 LONG_PTR ret = NtUserGetWindowLongW( hwnd, offset );
954 return get_window_long_ptr( hwnd, offset, ret, FALSE );
956 return NtUserGetWindowLongW( hwnd, offset );
961 /**********************************************************************
962 * SetWindowLongA (USER32.@)
964 * See SetWindowLongW.
966 LONG WINAPI DECLSPEC_HOTPATCH SetWindowLongA( HWND hwnd, INT offset, LONG newval )
968 switch (offset)
970 #ifdef _WIN64
971 case GWLP_WNDPROC:
972 case GWLP_HINSTANCE:
973 case GWLP_HWNDPARENT:
974 WARN( "Invalid offset %d\n", offset );
975 SetLastError( ERROR_INVALID_INDEX );
976 return 0;
977 #else
978 case DWLP_DLGPROC:
979 if (NtUserGetDialogInfo( hwnd )) return set_dialog_proc( hwnd, newval, TRUE );
980 /* fall through */
981 #endif
982 default:
983 return NtUserSetWindowLong( hwnd, offset, newval, TRUE );
988 /**********************************************************************
989 * SetWindowLongW (USER32.@) Set window attribute
991 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
992 * value in a window's extra memory.
994 * The _hwnd_ parameter specifies the handle to a window that
995 * has extra memory. The _newval_ parameter contains the new
996 * attribute or extra memory value. If positive, the _offset_
997 * parameter is the byte-addressed location in the window's extra
998 * memory to set. If negative, _offset_ specifies the window
999 * attribute to set, and should be one of the following values:
1001 * GWL_EXSTYLE The window's extended window style
1003 * GWL_STYLE The window's window style.
1005 * GWLP_WNDPROC Pointer to the window's window procedure.
1007 * GWLP_HINSTANCE The window's application instance handle.
1009 * GWLP_ID The window's identifier.
1011 * GWLP_USERDATA The window's user-specified data.
1013 * If the window is a dialog box, the _offset_ parameter can be one of
1014 * the following values:
1016 * DWLP_DLGPROC The address of the window's dialog box procedure.
1018 * DWLP_MSGRESULT The return value of a message
1019 * that the dialog box procedure processed.
1021 * DWLP_USER Application specific information.
1023 * RETURNS
1025 * If successful, returns the previous value located at _offset_. Otherwise,
1026 * returns 0.
1028 * NOTES
1030 * Extra memory for a window class is specified by a nonzero cbWndExtra
1031 * parameter of the WNDCLASS structure passed to RegisterClass() at the
1032 * time of class creation.
1034 * Using GWL_WNDPROC to set a new window procedure effectively creates
1035 * a window subclass. Use CallWindowProc() in the new windows procedure
1036 * to pass messages to the superclass's window procedure.
1038 * The user data is reserved for use by the application which created
1039 * the window.
1041 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
1042 * instead, call the EnableWindow() function to change the window's
1043 * disabled state.
1045 * Do not use GWL_HWNDPARENT to reset the window's parent, use
1046 * SetParent() instead.
1048 * Win95:
1049 * When offset is GWL_STYLE and the calling app's ver is 4.0,
1050 * it sends WM_STYLECHANGING before changing the settings
1051 * and WM_STYLECHANGED afterwards.
1052 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
1054 LONG WINAPI DECLSPEC_HOTPATCH SetWindowLongW(
1055 HWND hwnd, /* [in] window to alter */
1056 INT offset, /* [in] offset, in bytes, of location to alter */
1057 LONG newval /* [in] new value of location */
1060 switch (offset)
1062 #ifdef _WIN64
1063 case GWLP_WNDPROC:
1064 case GWLP_HINSTANCE:
1065 case GWLP_HWNDPARENT:
1066 WARN("Invalid offset %d\n", offset );
1067 SetLastError( ERROR_INVALID_INDEX );
1068 return 0;
1069 #else
1070 case DWLP_DLGPROC:
1071 if (NtUserGetDialogInfo( hwnd )) return set_dialog_proc( hwnd, newval, FALSE );
1072 /* fall through */
1073 #endif
1074 default:
1075 return NtUserSetWindowLong( hwnd, offset, newval, FALSE );
1080 /*******************************************************************
1081 * GetWindowTextA (USER32.@)
1083 INT WINAPI GetWindowTextA( HWND hwnd, LPSTR lpString, INT nMaxCount )
1085 WCHAR *buffer;
1086 int ret = 0;
1088 if (!lpString || nMaxCount <= 0) return 0;
1090 __TRY
1092 lpString[0] = 0;
1094 if (WIN_IsCurrentProcess( hwnd ))
1096 ret = (INT)SendMessageA( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
1098 else if ((buffer = HeapAlloc( GetProcessHeap(), 0, nMaxCount * sizeof(WCHAR) )))
1100 /* when window belongs to other process, don't send a message */
1101 NtUserInternalGetWindowText( hwnd, buffer, nMaxCount );
1102 if (!WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpString, nMaxCount, NULL, NULL ))
1103 lpString[nMaxCount-1] = 0;
1104 HeapFree( GetProcessHeap(), 0, buffer );
1105 ret = strlen(lpString);
1108 __EXCEPT_PAGE_FAULT
1110 ret = 0;
1112 __ENDTRY
1114 return ret;
1118 /*******************************************************************
1119 * GetWindowTextW (USER32.@)
1121 INT WINAPI GetWindowTextW( HWND hwnd, LPWSTR lpString, INT nMaxCount )
1123 int ret;
1125 if (!lpString || nMaxCount <= 0) return 0;
1127 __TRY
1129 lpString[0] = 0;
1131 if (WIN_IsCurrentProcess( hwnd ))
1133 ret = (INT)SendMessageW( hwnd, WM_GETTEXT, nMaxCount, (LPARAM)lpString );
1135 else
1137 /* when window belongs to other process, don't send a message */
1138 ret = NtUserInternalGetWindowText( hwnd, lpString, nMaxCount );
1141 __EXCEPT_PAGE_FAULT
1143 ret = 0;
1145 __ENDTRY
1147 return ret;
1151 /*******************************************************************
1152 * SetWindowTextA (USER32.@)
1153 * SetWindowText (USER32.@)
1155 BOOL WINAPI DECLSPEC_HOTPATCH SetWindowTextA( HWND hwnd, LPCSTR lpString )
1157 if (is_broadcast(hwnd))
1159 SetLastError( ERROR_INVALID_PARAMETER );
1160 return FALSE;
1162 if (!WIN_IsCurrentProcess( hwnd ))
1163 WARN( "setting text %s of other process window %p should not use SendMessage\n",
1164 debugstr_a(lpString), hwnd );
1165 return (BOOL)SendMessageA( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
1169 /*******************************************************************
1170 * SetWindowTextW (USER32.@)
1172 BOOL WINAPI DECLSPEC_HOTPATCH SetWindowTextW( HWND hwnd, LPCWSTR lpString )
1174 if (is_broadcast(hwnd))
1176 SetLastError( ERROR_INVALID_PARAMETER );
1177 return FALSE;
1179 if (!WIN_IsCurrentProcess( hwnd ))
1180 WARN( "setting text %s of other process window %p should not use SendMessage\n",
1181 debugstr_w(lpString), hwnd );
1182 return (BOOL)SendMessageW( hwnd, WM_SETTEXT, 0, (LPARAM)lpString );
1186 /*******************************************************************
1187 * GetWindowTextLengthA (USER32.@)
1189 INT WINAPI GetWindowTextLengthA( HWND hwnd )
1191 CPINFO info;
1193 if (WIN_IsCurrentProcess( hwnd )) return SendMessageA( hwnd, WM_GETTEXTLENGTH, 0, 0 );
1195 /* when window belongs to other process, don't send a message */
1196 GetCPInfo( CP_ACP, &info );
1197 return NtUserGetWindowTextLength( hwnd ) * info.MaxCharSize;
1200 /*******************************************************************
1201 * GetWindowTextLengthW (USER32.@)
1203 INT WINAPI GetWindowTextLengthW( HWND hwnd )
1205 if (WIN_IsCurrentProcess( hwnd )) return SendMessageW( hwnd, WM_GETTEXTLENGTH, 0, 0 );
1207 /* when window belongs to other process, don't send a message */
1208 return NtUserGetWindowTextLength( hwnd );
1212 /*******************************************************************
1213 * IsWindow (USER32.@)
1215 BOOL WINAPI IsWindow( HWND hwnd )
1217 return NtUserIsWindow( hwnd );
1221 /***********************************************************************
1222 * GetWindowThreadProcessId (USER32.@)
1224 DWORD WINAPI GetWindowThreadProcessId( HWND hwnd, LPDWORD process )
1226 return NtUserGetWindowThread( hwnd, process );
1230 /*****************************************************************
1231 * GetParent (USER32.@)
1233 HWND WINAPI GetParent( HWND hwnd )
1235 return NtUserGetParent( hwnd );
1239 /*******************************************************************
1240 * IsChild (USER32.@)
1242 BOOL WINAPI IsChild( HWND parent, HWND child )
1244 return NtUserIsChild( parent, child );
1248 /***********************************************************************
1249 * IsWindowVisible (USER32.@)
1251 BOOL WINAPI IsWindowVisible( HWND hwnd )
1253 return NtUserIsWindowVisible( hwnd );
1257 /*******************************************************************
1258 * GetTopWindow (USER32.@)
1260 HWND WINAPI GetTopWindow( HWND hwnd )
1262 if (!hwnd) hwnd = GetDesktopWindow();
1263 return GetWindow( hwnd, GW_CHILD );
1267 /*******************************************************************
1268 * GetWindow (USER32.@)
1270 HWND WINAPI GetWindow( HWND hwnd, UINT rel )
1272 return NtUserGetWindowRelative( hwnd, rel );
1276 /*******************************************************************
1277 * ShowOwnedPopups (USER32.@)
1279 BOOL WINAPI ShowOwnedPopups( HWND owner, BOOL show )
1281 return NtUserShowOwnedPopups( owner, show );
1285 /*******************************************************************
1286 * GetLastActivePopup (USER32.@)
1288 HWND WINAPI GetLastActivePopup( HWND hwnd )
1290 HWND retval = hwnd;
1292 SERVER_START_REQ( get_window_info )
1294 req->handle = wine_server_user_handle( hwnd );
1295 if (!wine_server_call_err( req )) retval = wine_server_ptr_handle( reply->last_active );
1297 SERVER_END_REQ;
1298 return retval;
1302 /*******************************************************************
1303 * WIN_ListChildren
1305 * Build an array of the children of a given window. The array must be
1306 * freed with HeapFree. Returns NULL when no windows are found.
1308 HWND *WIN_ListChildren( HWND hwnd )
1310 if (!hwnd)
1312 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1313 return NULL;
1315 return list_window_children( 0, hwnd, NULL, 0 );
1319 /*******************************************************************
1320 * EnumWindows (USER32.@)
1322 BOOL WINAPI EnumWindows( WNDENUMPROC lpEnumFunc, LPARAM lParam )
1324 HWND *list;
1325 BOOL ret = TRUE;
1326 int i;
1328 /* We have to build a list of all windows first, to avoid */
1329 /* unpleasant side-effects, for instance if the callback */
1330 /* function changes the Z-order of the windows. */
1332 if (!(list = WIN_ListChildren( GetDesktopWindow() ))) return TRUE;
1334 /* Now call the callback function for every window */
1336 for (i = 0; list[i]; i++)
1338 /* Make sure that the window still exists */
1339 if (!IsWindow( list[i] )) continue;
1340 if (!(ret = lpEnumFunc( list[i], lParam ))) break;
1342 HeapFree( GetProcessHeap(), 0, list );
1343 return ret;
1347 /**********************************************************************
1348 * EnumThreadWindows (USER32.@)
1350 BOOL WINAPI EnumThreadWindows( DWORD id, WNDENUMPROC func, LPARAM lParam )
1352 HWND *list;
1353 int i;
1354 BOOL ret = TRUE;
1356 if (!(list = list_window_children( 0, GetDesktopWindow(), NULL, id ))) return TRUE;
1358 /* Now call the callback function for every window */
1360 for (i = 0; list[i]; i++)
1361 if (!(ret = func( list[i], lParam ))) break;
1362 HeapFree( GetProcessHeap(), 0, list );
1363 return ret;
1367 /***********************************************************************
1368 * EnumDesktopWindows (USER32.@)
1370 BOOL WINAPI EnumDesktopWindows( HDESK desktop, WNDENUMPROC func, LPARAM lparam )
1372 HWND *list;
1373 int i;
1375 if (!(list = list_window_children( desktop, 0, NULL, 0 ))) return TRUE;
1377 for (i = 0; list[i]; i++)
1378 if (!func( list[i], lparam )) break;
1379 HeapFree( GetProcessHeap(), 0, list );
1380 return TRUE;
1384 #ifdef __i386__
1385 /* Some apps pass a non-stdcall proc to EnumChildWindows,
1386 * so we need a small assembly wrapper to call the proc.
1388 extern LRESULT enum_callback_wrapper( WNDENUMPROC proc, HWND hwnd, LPARAM lparam );
1389 __ASM_GLOBAL_FUNC( enum_callback_wrapper,
1390 "pushl %ebp\n\t"
1391 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
1392 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
1393 "movl %esp,%ebp\n\t"
1394 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
1395 "pushl 16(%ebp)\n\t"
1396 "pushl 12(%ebp)\n\t"
1397 "call *8(%ebp)\n\t"
1398 "leave\n\t"
1399 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
1400 __ASM_CFI(".cfi_same_value %ebp\n\t")
1401 "ret" )
1402 #else
1403 static inline LRESULT enum_callback_wrapper( WNDENUMPROC proc, HWND hwnd, LPARAM lparam )
1405 return proc( hwnd, lparam );
1407 #endif /* __i386__ */
1409 /**********************************************************************
1410 * WIN_EnumChildWindows
1412 * Helper function for EnumChildWindows().
1414 static BOOL WIN_EnumChildWindows( HWND *list, WNDENUMPROC func, LPARAM lParam )
1416 HWND *childList;
1417 BOOL ret = FALSE;
1419 for ( ; *list; list++)
1421 /* Make sure that the window still exists */
1422 if (!IsWindow( *list )) continue;
1423 /* Build children list first */
1424 childList = WIN_ListChildren( *list );
1426 ret = enum_callback_wrapper( func, *list, lParam );
1428 if (childList)
1430 if (ret) ret = WIN_EnumChildWindows( childList, func, lParam );
1431 HeapFree( GetProcessHeap(), 0, childList );
1433 if (!ret) return FALSE;
1435 return TRUE;
1439 /**********************************************************************
1440 * EnumChildWindows (USER32.@)
1442 BOOL WINAPI EnumChildWindows( HWND parent, WNDENUMPROC func, LPARAM lParam )
1444 HWND *list;
1445 BOOL ret;
1447 if (!(list = WIN_ListChildren( parent ))) return FALSE;
1448 ret = WIN_EnumChildWindows( list, func, lParam );
1449 HeapFree( GetProcessHeap(), 0, list );
1450 return ret;
1454 /*******************************************************************
1455 * AnyPopup (USER32.@)
1457 BOOL WINAPI AnyPopup(void)
1459 int i;
1460 BOOL retvalue;
1461 HWND *list = WIN_ListChildren( GetDesktopWindow() );
1463 if (!list) return FALSE;
1464 for (i = 0; list[i]; i++)
1466 if (IsWindowVisible( list[i] ) && GetWindow( list[i], GW_OWNER )) break;
1468 retvalue = (list[i] != 0);
1469 HeapFree( GetProcessHeap(), 0, list );
1470 return retvalue;
1474 /*******************************************************************
1475 * FlashWindow (USER32.@)
1477 BOOL WINAPI FlashWindow( HWND hWnd, BOOL bInvert )
1479 FLASHWINFO finfo;
1481 finfo.cbSize = sizeof(FLASHWINFO);
1482 finfo.dwFlags = bInvert ? FLASHW_ALL : FLASHW_STOP;
1483 finfo.uCount = 1;
1484 finfo.dwTimeout = 0;
1485 finfo.hwnd = hWnd;
1486 return NtUserFlashWindowEx( &finfo );
1490 /*******************************************************************
1491 * GetWindowContextHelpId (USER32.@)
1493 DWORD WINAPI GetWindowContextHelpId( HWND hwnd )
1495 return NtUserGetWindowContextHelpId( hwnd );
1499 /*******************************************************************
1500 * SetWindowContextHelpId (USER32.@)
1502 BOOL WINAPI SetWindowContextHelpId( HWND hwnd, DWORD id )
1504 return NtUserSetWindowContextHelpId( hwnd, id );
1508 /*******************************************************************
1509 * DragDetect (USER32.@)
1511 BOOL WINAPI DragDetect( HWND hwnd, POINT pt )
1513 return NtUserDragDetect( hwnd, pt.x, pt.y );
1516 /******************************************************************************
1517 * GetWindowModuleFileNameA (USER32.@)
1519 UINT WINAPI GetWindowModuleFileNameA( HWND hwnd, LPSTR module, UINT size )
1521 HINSTANCE hinst;
1523 TRACE( "%p, %p, %u\n", hwnd, module, size );
1525 if (!WIN_IsCurrentProcess( hwnd ))
1527 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1528 return 0;
1531 hinst = (HINSTANCE)GetWindowLongPtrA( hwnd, GWLP_HINSTANCE );
1532 return GetModuleFileNameA( hinst, module, size );
1535 /******************************************************************************
1536 * GetWindowModuleFileNameW (USER32.@)
1538 UINT WINAPI GetWindowModuleFileNameW( HWND hwnd, LPWSTR module, UINT size )
1540 HINSTANCE hinst;
1542 TRACE( "%p, %p, %u\n", hwnd, module, size );
1544 if (!WIN_IsCurrentProcess( hwnd ))
1546 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1547 return 0;
1550 hinst = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
1551 return GetModuleFileNameW( hinst, module, size );
1554 /******************************************************************************
1555 * GetWindowInfo (USER32.@)
1557 * Note: tests show that Windows doesn't check cbSize of the structure.
1559 BOOL WINAPI DECLSPEC_HOTPATCH GetWindowInfo( HWND hwnd, WINDOWINFO *info )
1561 return NtUserGetWindowInfo( hwnd, info );
1564 /******************************************************************************
1565 * SwitchDesktop (USER32.@)
1567 * NOTES: Sets the current input or interactive desktop.
1569 BOOL WINAPI SwitchDesktop( HDESK hDesktop)
1571 FIXME("(hwnd %p) stub!\n", hDesktop);
1572 return TRUE;
1576 /*****************************************************************************
1577 * UpdateLayeredWindowIndirect (USER32.@)
1579 BOOL WINAPI UpdateLayeredWindowIndirect( HWND hwnd, const UPDATELAYEREDWINDOWINFO *info )
1581 if (!info || info->cbSize != sizeof(*info))
1583 SetLastError( ERROR_INVALID_PARAMETER );
1584 return FALSE;
1587 return NtUserUpdateLayeredWindow( hwnd, info->hdcDst, info->pptDst, info->psize,
1588 info->hdcSrc, info->pptSrc, info->crKey,
1589 info->pblend, info->dwFlags, info->prcDirty );
1593 /*****************************************************************************
1594 * UpdateLayeredWindow (USER32.@)
1596 BOOL WINAPI UpdateLayeredWindow( HWND hwnd, HDC hdcDst, POINT *pptDst, SIZE *psize,
1597 HDC hdcSrc, POINT *pptSrc, COLORREF crKey, BLENDFUNCTION *pblend,
1598 DWORD flags)
1600 UPDATELAYEREDWINDOWINFO info;
1602 if (flags & ULW_EX_NORESIZE) /* only valid for UpdateLayeredWindowIndirect */
1604 SetLastError( ERROR_INVALID_PARAMETER );
1605 return FALSE;
1607 info.cbSize = sizeof(info);
1608 info.hdcDst = hdcDst;
1609 info.pptDst = pptDst;
1610 info.psize = psize;
1611 info.hdcSrc = hdcSrc;
1612 info.pptSrc = pptSrc;
1613 info.crKey = crKey;
1614 info.pblend = pblend;
1615 info.dwFlags = flags;
1616 info.prcDirty = NULL;
1617 return UpdateLayeredWindowIndirect( hwnd, &info );
1621 /******************************************************************************
1622 * GetProcessDefaultLayout [USER32.@]
1624 * Gets the default layout for parentless windows.
1626 BOOL WINAPI GetProcessDefaultLayout( DWORD *layout )
1628 if (!layout)
1630 SetLastError( ERROR_NOACCESS );
1631 return FALSE;
1633 *layout = NtUserGetProcessDefaultLayout();
1634 if (*layout == ~0u)
1636 WCHAR *str, buffer[MAX_PATH];
1637 DWORD i, version_layout = 0;
1638 UINT len;
1639 DWORD user_lang = GetUserDefaultLangID();
1640 DWORD *languages;
1641 void *data = NULL;
1643 GetModuleFileNameW( 0, buffer, MAX_PATH );
1644 if (!(len = GetFileVersionInfoSizeW( buffer, NULL ))) goto done;
1645 if (!(data = HeapAlloc( GetProcessHeap(), 0, len ))) goto done;
1646 if (!GetFileVersionInfoW( buffer, 0, len, data )) goto done;
1647 if (!VerQueryValueW( data, L"\\VarFileInfo\\Translation", (void **)&languages, &len ) || !len) goto done;
1649 len /= sizeof(DWORD);
1650 for (i = 0; i < len; i++) if (LOWORD(languages[i]) == user_lang) break;
1651 if (i == len) /* try neutral language */
1652 for (i = 0; i < len; i++)
1653 if (LOWORD(languages[i]) == MAKELANGID( PRIMARYLANGID(user_lang), SUBLANG_NEUTRAL )) break;
1654 if (i == len) i = 0; /* default to the first one */
1656 swprintf( buffer, ARRAY_SIZE(buffer), L"\\StringFileInfo\\%04x%04x\\FileDescription",
1657 LOWORD(languages[i]), HIWORD(languages[i]) );
1658 if (!VerQueryValueW( data, buffer, (void **)&str, &len )) goto done;
1659 TRACE( "found description %s\n", debugstr_w( str ));
1660 if (str[0] == 0x200e && str[1] == 0x200e) version_layout = LAYOUT_RTL;
1662 done:
1663 HeapFree( GetProcessHeap(), 0, data );
1664 NtUserSetProcessDefaultLayout( *layout = version_layout );
1666 return TRUE;
1670 /******************************************************************************
1671 * SetProcessDefaultLayout [USER32.@]
1673 * Sets the default layout for parentless windows.
1675 BOOL WINAPI SetProcessDefaultLayout( DWORD layout )
1677 return NtUserSetProcessDefaultLayout( layout );
1681 /***********************************************************************
1682 * UpdateWindow (USER32.@)
1684 BOOL WINAPI UpdateWindow( HWND hwnd )
1686 if (!hwnd)
1688 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1689 return FALSE;
1692 return NtUserRedrawWindow( hwnd, NULL, 0, RDW_UPDATENOW | RDW_ALLCHILDREN );
1696 /***********************************************************************
1697 * ValidateRgn (USER32.@)
1699 BOOL WINAPI ValidateRgn( HWND hwnd, HRGN hrgn )
1701 if (!hwnd)
1703 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1704 return FALSE;
1707 return NtUserRedrawWindow( hwnd, NULL, hrgn, RDW_VALIDATE );
1711 /*************************************************************************
1712 * ScrollWindow (USER32.@)
1714 BOOL WINAPI ScrollWindow( HWND hwnd, INT dx, INT dy, const RECT *rect, const RECT *clip_rect )
1716 UINT flags = SW_INVALIDATE | SW_ERASE | (rect ? 0 : SW_SCROLLCHILDREN) | SW_NODCCACHE;
1717 return NtUserScrollWindowEx( hwnd, dx, dy, rect, clip_rect, 0, NULL, flags );
1720 #ifdef _WIN64
1722 /* 64bit versions */
1724 #undef GetWindowLongPtrW
1725 #undef GetWindowLongPtrA
1726 #undef SetWindowLongPtrW
1727 #undef SetWindowLongPtrA
1729 /*****************************************************************************
1730 * GetWindowLongPtrW (USER32.@)
1732 LONG_PTR WINAPI GetWindowLongPtrW( HWND hwnd, INT offset )
1734 LONG_PTR ret = NtUserGetWindowLongPtrW( hwnd, offset );
1735 return get_window_long_ptr( hwnd, offset, ret, FALSE );
1738 /*****************************************************************************
1739 * GetWindowLongPtrA (USER32.@)
1741 LONG_PTR WINAPI GetWindowLongPtrA( HWND hwnd, INT offset )
1743 LONG_PTR ret = NtUserGetWindowLongPtrA( hwnd, offset );
1744 return get_window_long_ptr( hwnd, offset, ret, TRUE );
1747 /*****************************************************************************
1748 * SetWindowLongPtrW (USER32.@)
1750 LONG_PTR WINAPI SetWindowLongPtrW( HWND hwnd, INT offset, LONG_PTR newval )
1752 if (offset == DWLP_DLGPROC && NtUserGetDialogInfo( hwnd ))
1753 return set_dialog_proc( hwnd, newval, FALSE );
1755 return NtUserSetWindowLongPtr( hwnd, offset, newval, FALSE );
1758 /*****************************************************************************
1759 * SetWindowLongPtrA (USER32.@)
1761 LONG_PTR WINAPI SetWindowLongPtrA( HWND hwnd, INT offset, LONG_PTR newval )
1763 if (offset == DWLP_DLGPROC && NtUserGetDialogInfo( hwnd ))
1764 return set_dialog_proc( hwnd, newval, TRUE );
1766 return NtUserSetWindowLongPtr( hwnd, offset, newval, TRUE );
1769 #endif /* _WIN64 */
1771 /*****************************************************************************
1772 * GetWindowDisplayAffinity (USER32.@)
1774 BOOL WINAPI GetWindowDisplayAffinity(HWND hwnd, DWORD *affinity)
1776 FIXME("(%p, %p): stub\n", hwnd, affinity);
1778 if (!hwnd || !affinity)
1780 SetLastError(hwnd ? ERROR_NOACCESS : ERROR_INVALID_WINDOW_HANDLE);
1781 return FALSE;
1784 *affinity = WDA_NONE;
1785 return TRUE;
1788 /*****************************************************************************
1789 * SetWindowDisplayAffinity (USER32.@)
1791 BOOL WINAPI SetWindowDisplayAffinity(HWND hwnd, DWORD affinity)
1793 FIXME("(%p, %lu): stub\n", hwnd, affinity);
1795 if (!hwnd)
1797 SetLastError(ERROR_INVALID_WINDOW_HANDLE);
1798 return FALSE;
1801 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
1802 return FALSE;
1805 /**********************************************************************
1806 * SetWindowCompositionAttribute (USER32.@)
1808 BOOL WINAPI SetWindowCompositionAttribute(HWND hwnd, void *data)
1810 FIXME("(%p, %p): stub\n", hwnd, data);
1811 SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
1812 return FALSE;