2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
31 #include "wine/server.h"
32 #include "wine/unicode.h"
34 #include "user_private.h"
37 #include "wine/gdi_driver.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win
);
42 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
43 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
45 static DWORD process_layout
= ~0u;
47 static struct list window_surfaces
= LIST_INIT( window_surfaces
);
49 static CRITICAL_SECTION surfaces_section
;
50 static CRITICAL_SECTION_DEBUG critsect_debug
=
52 0, 0, &surfaces_section
,
53 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
54 0, 0, { (DWORD_PTR
)(__FILE__
": surfaces_section") }
56 static CRITICAL_SECTION surfaces_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
58 /**********************************************************************/
60 /* helper for Get/SetWindowLong */
61 static inline LONG_PTR
get_win_data( const void *ptr
, UINT size
)
63 if (size
== sizeof(WORD
))
66 memcpy( &ret
, ptr
, sizeof(ret
) );
69 else if (size
== sizeof(DWORD
))
72 memcpy( &ret
, ptr
, sizeof(ret
) );
78 memcpy( &ret
, ptr
, sizeof(ret
) );
83 /* helper for Get/SetWindowLong */
84 static inline void set_win_data( void *ptr
, LONG_PTR val
, UINT size
)
86 if (size
== sizeof(WORD
))
89 memcpy( ptr
, &newval
, sizeof(newval
) );
91 else if (size
== sizeof(DWORD
))
94 memcpy( ptr
, &newval
, sizeof(newval
) );
98 memcpy( ptr
, &val
, sizeof(val
) );
103 static void *user_handles
[NB_USER_HANDLES
];
105 /***********************************************************************
108 HANDLE
alloc_user_handle( struct user_object
*ptr
, enum user_obj_type type
)
112 SERVER_START_REQ( alloc_user_handle
)
114 if (!wine_server_call_err( req
)) handle
= wine_server_ptr_handle( reply
->handle
);
120 UINT index
= USER_HANDLE_TO_INDEX( handle
);
122 assert( index
< NB_USER_HANDLES
);
123 ptr
->handle
= handle
;
125 InterlockedExchangePointer( &user_handles
[index
], ptr
);
131 /***********************************************************************
132 * get_user_handle_ptr
134 void *get_user_handle_ptr( HANDLE handle
, enum user_obj_type type
)
136 struct user_object
*ptr
;
137 WORD index
= USER_HANDLE_TO_INDEX( handle
);
139 if (index
>= NB_USER_HANDLES
) return NULL
;
142 if ((ptr
= user_handles
[index
]))
144 if (ptr
->type
== type
&&
145 ((UINT
)(UINT_PTR
)ptr
->handle
== (UINT
)(UINT_PTR
)handle
||
146 !HIWORD(handle
) || HIWORD(handle
) == 0xffff))
150 else ptr
= OBJ_OTHER_PROCESS
;
156 /***********************************************************************
157 * release_user_handle_ptr
159 void release_user_handle_ptr( void *ptr
)
161 assert( ptr
&& ptr
!= OBJ_OTHER_PROCESS
);
166 /***********************************************************************
169 void *free_user_handle( HANDLE handle
, enum user_obj_type type
)
171 struct user_object
*ptr
;
172 WORD index
= USER_HANDLE_TO_INDEX( handle
);
174 if ((ptr
= get_user_handle_ptr( handle
, type
)) && ptr
!= OBJ_OTHER_PROCESS
)
176 SERVER_START_REQ( free_user_handle
)
178 req
->handle
= wine_server_user_handle( handle
);
179 if (wine_server_call( req
)) ptr
= NULL
;
180 else InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
189 /***********************************************************************
190 * create_window_handle
192 * Create a window handle with the server.
194 static WND
*create_window_handle( HWND parent
, HWND owner
, LPCWSTR name
,
195 HINSTANCE instance
, BOOL unicode
)
199 HWND handle
= 0, full_parent
= 0, full_owner
= 0;
200 struct tagCLASS
*class = NULL
;
203 SERVER_START_REQ( create_window
)
205 req
->parent
= wine_server_user_handle( parent
);
206 req
->owner
= wine_server_user_handle( owner
);
207 req
->instance
= wine_server_client_ptr( instance
);
208 if (!(req
->atom
= get_int_atom_value( name
)) && name
)
209 wine_server_add_data( req
, name
, strlenW(name
)*sizeof(WCHAR
) );
210 if (!wine_server_call_err( req
))
212 handle
= wine_server_ptr_handle( reply
->handle
);
213 full_parent
= wine_server_ptr_handle( reply
->parent
);
214 full_owner
= wine_server_ptr_handle( reply
->owner
);
215 extra_bytes
= reply
->extra
;
216 class = wine_server_get_ptr( reply
->class_ptr
);
223 WARN( "error %d creating window\n", GetLastError() );
227 if (!(win
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
228 sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
230 SERVER_START_REQ( destroy_window
)
232 req
->handle
= wine_server_user_handle( handle
);
233 wine_server_call( req
);
236 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
240 if (!parent
) /* if parent is 0 we don't have a desktop window yet */
242 struct user_thread_info
*thread_info
= get_user_thread_info();
244 if (name
== (LPCWSTR
)DESKTOP_CLASS_ATOM
)
246 if (!thread_info
->top_window
) thread_info
->top_window
= full_parent
? full_parent
: handle
;
247 else assert( full_parent
== thread_info
->top_window
);
248 if (full_parent
&& !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
249 ERR( "failed to create desktop window\n" );
251 else /* HWND_MESSAGE parent */
253 if (!thread_info
->msg_window
&& !full_parent
) thread_info
->msg_window
= handle
;
259 index
= USER_HANDLE_TO_INDEX(handle
);
260 assert( index
< NB_USER_HANDLES
);
261 win
->obj
.handle
= handle
;
262 win
->obj
.type
= USER_WINDOW
;
263 win
->parent
= full_parent
;
264 win
->owner
= full_owner
;
266 win
->winproc
= get_class_winproc( class );
267 win
->cbWndExtra
= extra_bytes
;
268 InterlockedExchangePointer( &user_handles
[index
], win
);
269 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
274 /***********************************************************************
277 * Free a window handle.
279 static void free_window_handle( HWND hwnd
)
281 struct user_object
*ptr
;
282 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
284 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) && ptr
!= OBJ_OTHER_PROCESS
)
286 SERVER_START_REQ( destroy_window
)
288 req
->handle
= wine_server_user_handle( hwnd
);
289 if (wine_server_call_err( req
)) ptr
= NULL
;
290 else InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
294 HeapFree( GetProcessHeap(), 0, ptr
);
299 /*******************************************************************
300 * list_window_children
302 * Build an array of the children of a given window. The array must be
303 * freed with HeapFree. Returns NULL when no windows are found.
305 static HWND
*list_window_children( HDESK desktop
, HWND hwnd
, LPCWSTR
class, DWORD tid
)
309 ATOM atom
= get_int_atom_value( class );
311 /* empty class is not the same as NULL class */
312 if (!atom
&& class && !class[0]) return NULL
;
318 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
320 SERVER_START_REQ( get_window_children
)
322 req
->desktop
= wine_server_obj_handle( desktop
);
323 req
->parent
= wine_server_user_handle( hwnd
);
326 if (!atom
&& class) wine_server_add_data( req
, class, strlenW(class)*sizeof(WCHAR
) );
327 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
328 if (!wine_server_call( req
)) count
= reply
->count
;
331 if (count
&& count
< size
)
333 /* start from the end since HWND is potentially larger than user_handle_t */
334 for (i
= count
- 1; i
>= 0; i
--)
335 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
339 HeapFree( GetProcessHeap(), 0, list
);
341 size
= count
+ 1; /* restart with a large enough buffer */
347 /*******************************************************************
348 * list_window_parents
350 * Build an array of all parents of a given window, starting with
351 * the immediate parent. The array must be freed with HeapFree.
353 static HWND
*list_window_parents( HWND hwnd
)
357 int i
, pos
= 0, size
= 16, count
= 0;
359 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
364 if (!(win
= WIN_GetPtr( current
))) goto empty
;
365 if (win
== WND_OTHER_PROCESS
) break; /* need to do it the hard way */
366 if (win
== WND_DESKTOP
)
368 if (!pos
) goto empty
;
372 list
[pos
] = current
= win
->parent
;
373 WIN_ReleasePtr( win
);
374 if (!current
) return list
;
375 if (++pos
== size
- 1)
377 /* need to grow the list */
378 HWND
*new_list
= HeapReAlloc( GetProcessHeap(), 0, list
, (size
+16) * sizeof(HWND
) );
379 if (!new_list
) goto empty
;
385 /* at least one parent belongs to another process, have to query the server */
390 SERVER_START_REQ( get_window_parents
)
392 req
->handle
= wine_server_user_handle( hwnd
);
393 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
394 if (!wine_server_call( req
)) count
= reply
->count
;
397 if (!count
) goto empty
;
400 /* start from the end since HWND is potentially larger than user_handle_t */
401 for (i
= count
- 1; i
>= 0; i
--)
402 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
406 HeapFree( GetProcessHeap(), 0, list
);
408 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
412 HeapFree( GetProcessHeap(), 0, list
);
417 /*******************************************************************
420 static void send_parent_notify( HWND hwnd
, UINT msg
)
422 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
423 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
))
425 HWND parent
= GetParent(hwnd
);
426 if (parent
&& parent
!= GetDesktopWindow())
427 SendMessageW( parent
, WM_PARENTNOTIFY
,
428 MAKEWPARAM( msg
, GetWindowLongPtrW( hwnd
, GWLP_ID
)), (LPARAM
)hwnd
);
433 /*******************************************************************
434 * update_window_state
436 * Trigger an update of the window's driver state and surface.
438 static void update_window_state( HWND hwnd
)
440 RECT window_rect
, client_rect
;
442 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
443 set_window_pos( hwnd
, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
|
444 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
, &window_rect
, &client_rect
, NULL
);
448 /*******************************************************************
449 * get_server_window_text
451 * Retrieve the window text from the server.
453 static void get_server_window_text( HWND hwnd
, LPWSTR text
, INT count
)
457 SERVER_START_REQ( get_window_text
)
459 req
->handle
= wine_server_user_handle( hwnd
);
460 wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
461 if (!wine_server_call_err( req
)) len
= wine_server_reply_size(reply
);
464 text
[len
/ sizeof(WCHAR
)] = 0;
468 /*******************************************************************
469 * get_hwnd_message_parent
471 * Return the parent for HWND_MESSAGE windows.
473 HWND
get_hwnd_message_parent(void)
475 struct user_thread_info
*thread_info
= get_user_thread_info();
477 if (!thread_info
->msg_window
) GetDesktopWindow(); /* trigger creation */
478 return thread_info
->msg_window
;
482 /*******************************************************************
485 * Check if window is the desktop or the HWND_MESSAGE top parent.
487 BOOL
is_desktop_window( HWND hwnd
)
489 struct user_thread_info
*thread_info
= get_user_thread_info();
491 if (!hwnd
) return FALSE
;
492 if (hwnd
== thread_info
->top_window
) return TRUE
;
493 if (hwnd
== thread_info
->msg_window
) return TRUE
;
495 if (!HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff)
497 if (LOWORD(thread_info
->top_window
) == LOWORD(hwnd
)) return TRUE
;
498 if (LOWORD(thread_info
->msg_window
) == LOWORD(hwnd
)) return TRUE
;
504 /*******************************************************************
505 * Dummy window surface for windows that shouldn't get painted.
508 static void dummy_surface_lock( struct window_surface
*window_surface
)
513 static void dummy_surface_unlock( struct window_surface
*window_surface
)
518 static void *dummy_surface_get_bitmap_info( struct window_surface
*window_surface
, BITMAPINFO
*info
)
520 static DWORD dummy_data
;
522 info
->bmiHeader
.biSize
= sizeof( info
->bmiHeader
);
523 info
->bmiHeader
.biWidth
= dummy_surface
.rect
.right
;
524 info
->bmiHeader
.biHeight
= dummy_surface
.rect
.bottom
;
525 info
->bmiHeader
.biPlanes
= 1;
526 info
->bmiHeader
.biBitCount
= 32;
527 info
->bmiHeader
.biCompression
= BI_RGB
;
528 info
->bmiHeader
.biSizeImage
= 0;
529 info
->bmiHeader
.biXPelsPerMeter
= 0;
530 info
->bmiHeader
.biYPelsPerMeter
= 0;
531 info
->bmiHeader
.biClrUsed
= 0;
532 info
->bmiHeader
.biClrImportant
= 0;
536 static RECT
*dummy_surface_get_bounds( struct window_surface
*window_surface
)
538 static RECT dummy_bounds
;
539 return &dummy_bounds
;
542 static void dummy_surface_set_region( struct window_surface
*window_surface
, HRGN region
)
547 static void dummy_surface_flush( struct window_surface
*window_surface
)
552 static void dummy_surface_destroy( struct window_surface
*window_surface
)
557 static const struct window_surface_funcs dummy_surface_funcs
=
560 dummy_surface_unlock
,
561 dummy_surface_get_bitmap_info
,
562 dummy_surface_get_bounds
,
563 dummy_surface_set_region
,
565 dummy_surface_destroy
568 struct window_surface dummy_surface
= { &dummy_surface_funcs
, { NULL
, NULL
}, 1, { 0, 0, 1, 1 } };
571 /*******************************************************************
572 * register_window_surface
574 * Register a window surface in the global list, possibly replacing another one.
576 void register_window_surface( struct window_surface
*old
, struct window_surface
*new )
578 if (old
== new) return;
579 EnterCriticalSection( &surfaces_section
);
580 if (old
&& old
!= &dummy_surface
) list_remove( &old
->entry
);
581 if (new && new != &dummy_surface
) list_add_tail( &window_surfaces
, &new->entry
);
582 LeaveCriticalSection( &surfaces_section
);
586 /*******************************************************************
587 * flush_window_surfaces
589 * Flush pending output from all window surfaces.
591 void flush_window_surfaces( BOOL idle
)
593 static DWORD last_idle
;
595 struct window_surface
*surface
;
597 EnterCriticalSection( &surfaces_section
);
598 now
= GetTickCount();
599 if (idle
) last_idle
= now
;
600 /* if not idle, we only flush if there's evidence that the app never goes idle */
601 else if ((int)(now
- last_idle
) < 1000) goto done
;
603 LIST_FOR_EACH_ENTRY( surface
, &window_surfaces
, struct window_surface
, entry
)
604 surface
->funcs
->flush( surface
);
606 LeaveCriticalSection( &surfaces_section
);
610 /***********************************************************************
613 * Return a pointer to the WND structure if local to the process,
614 * or WND_OTHER_PROCESS if handle may be valid in other process.
615 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
617 WND
*WIN_GetPtr( HWND hwnd
)
621 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) == WND_OTHER_PROCESS
)
623 if (is_desktop_window( hwnd
)) ptr
= WND_DESKTOP
;
629 /***********************************************************************
630 * WIN_IsCurrentProcess
632 * Check whether a given window belongs to the current process (and return the full handle).
634 HWND
WIN_IsCurrentProcess( HWND hwnd
)
639 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
640 ret
= ptr
->obj
.handle
;
641 WIN_ReleasePtr( ptr
);
646 /***********************************************************************
647 * WIN_IsCurrentThread
649 * Check whether a given window belongs to the current thread (and return the full handle).
651 HWND
WIN_IsCurrentThread( HWND hwnd
)
656 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
657 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->obj
.handle
;
658 WIN_ReleasePtr( ptr
);
663 /***********************************************************************
666 * Convert a possibly truncated window handle to a full 32-bit handle.
668 HWND
WIN_GetFullHandle( HWND hwnd
)
672 if (!hwnd
|| (ULONG_PTR
)hwnd
>> 16) return hwnd
;
673 if (LOWORD(hwnd
) <= 1 || LOWORD(hwnd
) == 0xffff) return hwnd
;
674 /* do sign extension for -2 and -3 */
675 if (LOWORD(hwnd
) >= (WORD
)-3) return (HWND
)(LONG_PTR
)(INT16
)LOWORD(hwnd
);
677 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
679 if (ptr
== WND_DESKTOP
)
681 if (LOWORD(hwnd
) == LOWORD(GetDesktopWindow())) return GetDesktopWindow();
682 else return get_hwnd_message_parent();
685 if (ptr
!= WND_OTHER_PROCESS
)
687 hwnd
= ptr
->obj
.handle
;
688 WIN_ReleasePtr( ptr
);
690 else /* may belong to another process */
692 SERVER_START_REQ( get_window_info
)
694 req
->handle
= wine_server_user_handle( hwnd
);
695 if (!wine_server_call_err( req
)) hwnd
= wine_server_ptr_handle( reply
->full_handle
);
703 /***********************************************************************
706 * Change the owner of a window.
708 HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
710 WND
*win
= WIN_GetPtr( hwnd
);
713 if (!win
|| win
== WND_DESKTOP
) return 0;
714 if (win
== WND_OTHER_PROCESS
)
716 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
719 SERVER_START_REQ( set_window_owner
)
721 req
->handle
= wine_server_user_handle( hwnd
);
722 req
->owner
= wine_server_user_handle( owner
);
723 if (!wine_server_call( req
))
725 win
->owner
= wine_server_ptr_handle( reply
->full_owner
);
726 ret
= wine_server_ptr_handle( reply
->prev_owner
);
730 WIN_ReleasePtr( win
);
735 /***********************************************************************
738 * Change the style of a window.
740 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
742 BOOL ok
, made_visible
= FALSE
;
744 WND
*win
= WIN_GetPtr( hwnd
);
746 if (!win
|| win
== WND_DESKTOP
) return 0;
747 if (win
== WND_OTHER_PROCESS
)
750 ERR( "cannot set style %x/%x on other process window %p\n",
751 set_bits
, clear_bits
, hwnd
);
754 style
.styleOld
= win
->dwStyle
;
755 style
.styleNew
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
756 if (style
.styleNew
== style
.styleOld
)
758 WIN_ReleasePtr( win
);
759 return style
.styleNew
;
761 SERVER_START_REQ( set_window_info
)
763 req
->handle
= wine_server_user_handle( hwnd
);
764 req
->flags
= SET_WIN_STYLE
;
765 req
->style
= style
.styleNew
;
766 req
->extra_offset
= -1;
767 if ((ok
= !wine_server_call( req
)))
769 style
.styleOld
= reply
->old_style
;
770 win
->dwStyle
= style
.styleNew
;
775 if (ok
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
))
777 made_visible
= (style
.styleNew
& WS_VISIBLE
) != 0;
778 invalidate_dce( win
, NULL
);
780 WIN_ReleasePtr( win
);
784 USER_Driver
->pSetWindowStyle( hwnd
, GWL_STYLE
, &style
);
785 if (made_visible
) update_window_state( hwnd
);
787 return style
.styleOld
;
791 /***********************************************************************
794 * Get the window and client rectangles.
796 BOOL
WIN_GetRectangles( HWND hwnd
, enum coords_relative relative
, RECT
*rectWindow
, RECT
*rectClient
)
798 WND
*win
= WIN_GetPtr( hwnd
);
803 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
806 if (win
== WND_DESKTOP
)
809 rect
.left
= rect
.top
= 0;
810 if (hwnd
== get_hwnd_message_parent())
817 rect
.right
= GetSystemMetrics(SM_CXSCREEN
);
818 rect
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
820 if (rectWindow
) *rectWindow
= rect
;
821 if (rectClient
) *rectClient
= rect
;
824 if (win
!= WND_OTHER_PROCESS
)
826 RECT window_rect
= win
->rectWindow
, client_rect
= win
->rectClient
;
831 OffsetRect( &window_rect
, -win
->rectClient
.left
, -win
->rectClient
.top
);
832 OffsetRect( &client_rect
, -win
->rectClient
.left
, -win
->rectClient
.top
);
833 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
834 mirror_rect( &win
->rectClient
, &window_rect
);
837 OffsetRect( &window_rect
, -win
->rectWindow
.left
, -win
->rectWindow
.top
);
838 OffsetRect( &client_rect
, -win
->rectWindow
.left
, -win
->rectWindow
.top
);
839 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
840 mirror_rect( &win
->rectWindow
, &client_rect
);
845 WND
*parent
= WIN_GetPtr( win
->parent
);
846 if (parent
== WND_DESKTOP
) break;
847 if (!parent
|| parent
== WND_OTHER_PROCESS
)
849 WIN_ReleasePtr( win
);
852 if (parent
->flags
& WIN_CHILDREN_MOVED
)
854 WIN_ReleasePtr( parent
);
855 WIN_ReleasePtr( win
);
858 if (parent
->dwExStyle
& WS_EX_LAYOUTRTL
)
860 mirror_rect( &parent
->rectClient
, &window_rect
);
861 mirror_rect( &parent
->rectClient
, &client_rect
);
863 WIN_ReleasePtr( parent
);
869 WND
*parent
= WIN_GetPtr( win
->parent
);
870 if (parent
== WND_DESKTOP
) break;
871 if (!parent
|| parent
== WND_OTHER_PROCESS
)
873 WIN_ReleasePtr( win
);
876 WIN_ReleasePtr( win
);
877 if (parent
->flags
& WIN_CHILDREN_MOVED
)
879 WIN_ReleasePtr( parent
);
885 OffsetRect( &window_rect
, win
->rectClient
.left
, win
->rectClient
.top
);
886 OffsetRect( &client_rect
, win
->rectClient
.left
, win
->rectClient
.top
);
891 if (rectWindow
) *rectWindow
= window_rect
;
892 if (rectClient
) *rectClient
= client_rect
;
893 WIN_ReleasePtr( win
);
898 SERVER_START_REQ( get_window_rectangles
)
900 req
->handle
= wine_server_user_handle( hwnd
);
901 req
->relative
= relative
;
902 if ((ret
= !wine_server_call_err( req
)))
906 rectWindow
->left
= reply
->window
.left
;
907 rectWindow
->top
= reply
->window
.top
;
908 rectWindow
->right
= reply
->window
.right
;
909 rectWindow
->bottom
= reply
->window
.bottom
;
913 rectClient
->left
= reply
->client
.left
;
914 rectClient
->top
= reply
->client
.top
;
915 rectClient
->right
= reply
->client
.right
;
916 rectClient
->bottom
= reply
->client
.bottom
;
925 /***********************************************************************
928 * Destroy storage associated to a window. "Internals" p.358
930 LRESULT
WIN_DestroyWindow( HWND hwnd
)
934 HMENU menu
= 0, sys_menu
;
936 struct window_surface
*surface
;
938 TRACE("%p\n", hwnd
);
940 /* free child windows */
941 if ((list
= WIN_ListChildren( hwnd
)))
944 for (i
= 0; list
[i
]; i
++)
946 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
947 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
949 HeapFree( GetProcessHeap(), 0, list
);
952 /* Unlink now so we won't bother with the children later on */
953 SERVER_START_REQ( set_parent
)
955 req
->handle
= wine_server_user_handle( hwnd
);
957 wine_server_call( req
);
962 * Send the WM_NCDESTROY to the window being destroyed.
964 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
966 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
968 /* free resources associated with the window */
970 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
971 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
972 menu
= (HMENU
)wndPtr
->wIDmenu
;
973 sys_menu
= wndPtr
->hSysMenu
;
974 free_dce( wndPtr
->dce
, hwnd
);
976 icon_title
= wndPtr
->icon_title
;
977 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
979 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
980 wndPtr
->pScroll
= NULL
;
981 DestroyIcon( wndPtr
->hIconSmall2
);
982 surface
= wndPtr
->surface
;
983 wndPtr
->surface
= NULL
;
984 WIN_ReleasePtr( wndPtr
);
986 if (icon_title
) DestroyWindow( icon_title
);
987 if (menu
) DestroyMenu( menu
);
988 if (sys_menu
) DestroyMenu( sys_menu
);
991 register_window_surface( surface
, NULL
);
992 window_surface_release( surface
);
995 USER_Driver
->pDestroyWindow( hwnd
);
997 free_window_handle( hwnd
);
1002 /***********************************************************************
1003 * destroy_thread_window
1005 * Destroy a window upon exit of its thread.
1007 static void destroy_thread_window( HWND hwnd
)
1011 HMENU menu
= 0, sys_menu
= 0;
1012 struct window_surface
*surface
= NULL
;
1015 /* free child windows */
1017 if ((list
= WIN_ListChildren( hwnd
)))
1020 for (i
= 0; list
[i
]; i
++)
1022 if (WIN_IsCurrentThread( list
[i
] )) destroy_thread_window( list
[i
] );
1023 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
1025 HeapFree( GetProcessHeap(), 0, list
);
1028 /* destroy the client-side storage */
1030 index
= USER_HANDLE_TO_INDEX(hwnd
);
1031 if (index
>= NB_USER_HANDLES
) return;
1033 if ((wndPtr
= user_handles
[index
]))
1035 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
) menu
= (HMENU
)wndPtr
->wIDmenu
;
1036 sys_menu
= wndPtr
->hSysMenu
;
1037 free_dce( wndPtr
->dce
, hwnd
);
1038 surface
= wndPtr
->surface
;
1039 wndPtr
->surface
= NULL
;
1040 InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, wndPtr
);
1044 HeapFree( GetProcessHeap(), 0, wndPtr
);
1045 if (menu
) DestroyMenu( menu
);
1046 if (sys_menu
) DestroyMenu( sys_menu
);
1049 register_window_surface( surface
, NULL
);
1050 window_surface_release( surface
);
1055 /***********************************************************************
1056 * destroy_thread_child_windows
1058 * Destroy child windows upon exit of its thread.
1060 static void destroy_thread_child_windows( HWND hwnd
)
1065 if (WIN_IsCurrentThread( hwnd
))
1067 destroy_thread_window( hwnd
);
1069 else if ((list
= WIN_ListChildren( hwnd
)))
1071 for (i
= 0; list
[i
]; i
++) destroy_thread_child_windows( list
[i
] );
1072 HeapFree( GetProcessHeap(), 0, list
);
1077 /***********************************************************************
1078 * WIN_DestroyThreadWindows
1080 * Destroy all children of 'wnd' owned by the current thread.
1082 void WIN_DestroyThreadWindows( HWND hwnd
)
1087 if (!(list
= WIN_ListChildren( hwnd
))) return;
1089 /* reset owners of top-level windows */
1090 for (i
= 0; list
[i
]; i
++)
1092 if (!WIN_IsCurrentThread( list
[i
] ))
1094 HWND owner
= GetWindow( list
[i
], GW_OWNER
);
1095 if (owner
&& WIN_IsCurrentThread( owner
)) WIN_SetOwner( list
[i
], 0 );
1099 for (i
= 0; list
[i
]; i
++) destroy_thread_child_windows( list
[i
] );
1100 HeapFree( GetProcessHeap(), 0, list
);
1104 /***********************************************************************
1105 * WIN_FixCoordinates
1107 * Fix the coordinates - Helper for WIN_CreateWindowEx.
1108 * returns default show mode in sw.
1110 static void WIN_FixCoordinates( CREATESTRUCTW
*cs
, INT
*sw
)
1112 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1115 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1119 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
1120 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= ULongToHandle(id
);
1122 TRACE("MDI child id %04x\n", id
);
1125 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
1127 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1129 if (IS_DEFAULT(cs
->x
))
1134 if (IS_DEFAULT(cs
->cx
) || !cs
->cx
) cs
->cx
= pos
[1].x
;
1135 if (IS_DEFAULT(cs
->cy
) || !cs
->cy
) cs
->cy
= pos
[1].y
;
1139 if (IS_DEFAULT(cs
->x
)) cs
->x
= cs
->y
= 0;
1140 if (IS_DEFAULT(cs
->cx
)) cs
->cx
= cs
->cy
= 0;
1143 else /* overlapped window */
1146 MONITORINFO mon_info
;
1149 if (!IS_DEFAULT(cs
->x
) && !IS_DEFAULT(cs
->cx
) && !IS_DEFAULT(cs
->cy
)) return;
1151 monitor
= MonitorFromWindow( cs
->hwndParent
, MONITOR_DEFAULTTOPRIMARY
);
1152 mon_info
.cbSize
= sizeof(mon_info
);
1153 GetMonitorInfoW( monitor
, &mon_info
);
1154 GetStartupInfoW( &info
);
1156 if (IS_DEFAULT(cs
->x
))
1158 if (!IS_DEFAULT(cs
->y
)) *sw
= cs
->y
;
1159 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: mon_info
.rcWork
.left
;
1160 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: mon_info
.rcWork
.top
;
1163 if (IS_DEFAULT(cs
->cx
))
1165 if (info
.dwFlags
& STARTF_USESIZE
)
1167 cs
->cx
= info
.dwXSize
;
1168 cs
->cy
= info
.dwYSize
;
1172 cs
->cx
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) * 3 / 4 - cs
->x
;
1173 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1176 /* neither x nor cx are default. Check the y values .
1177 * In the trace we see Outlook and Outlook Express using
1178 * cy set to CW_USEDEFAULT when opening the address book.
1180 else if (IS_DEFAULT(cs
->cy
))
1182 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
1183 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1189 /***********************************************************************
1190 * dump_window_styles
1192 static void dump_window_styles( DWORD style
, DWORD exstyle
)
1195 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
1196 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
1197 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
1198 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
1199 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
1200 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
1201 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
1202 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
1203 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
1206 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
1207 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
1209 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
1210 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
1211 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
1212 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
1213 if (style
& WS_CHILD
)
1215 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
1216 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
1220 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
1221 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
1224 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
1225 #define DUMPED_STYLES \
1226 ((DWORD)(WS_POPUP | \
1245 if(style
& ~DUMPED_STYLES
) TRACE(" %08x", style
& ~DUMPED_STYLES
);
1247 #undef DUMPED_STYLES
1249 TRACE( "exstyle:" );
1250 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
1251 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
1252 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
1253 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
1254 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
1255 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
1256 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
1257 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
1258 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
1259 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
1260 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
1261 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
1262 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
1263 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
1264 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
1265 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
1266 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
1267 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
1268 if(exstyle
& WS_EX_LAYOUTRTL
) TRACE(" WS_EX_LAYOUTRTL");
1270 #define DUMPED_EX_STYLES \
1271 ((DWORD)(WS_EX_DLGMODALFRAME | \
1272 WS_EX_DRAGDETECT | \
1273 WS_EX_NOPARENTNOTIFY | \
1275 WS_EX_ACCEPTFILES | \
1276 WS_EX_TRANSPARENT | \
1278 WS_EX_TOOLWINDOW | \
1279 WS_EX_WINDOWEDGE | \
1280 WS_EX_CLIENTEDGE | \
1281 WS_EX_CONTEXTHELP | \
1283 WS_EX_RTLREADING | \
1284 WS_EX_LEFTSCROLLBAR | \
1285 WS_EX_CONTROLPARENT | \
1286 WS_EX_STATICEDGE | \
1291 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08x", exstyle
& ~DUMPED_EX_STYLES
);
1293 #undef DUMPED_EX_STYLES
1297 /***********************************************************************
1298 * WIN_CreateWindowEx
1300 * Implementation of CreateWindowEx().
1302 HWND
WIN_CreateWindowEx( CREATESTRUCTW
*cs
, LPCWSTR className
, HINSTANCE module
, BOOL unicode
)
1304 INT cx
, cy
, style
, sw
= SW_SHOW
;
1308 HWND hwnd
, parent
, owner
, top_child
= 0;
1309 MDICREATESTRUCTW mdi_cs
;
1310 CBT_CREATEWNDW cbtc
;
1313 TRACE("%s %s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
1314 unicode
? debugstr_w(cs
->lpszName
) : debugstr_a((LPCSTR
)cs
->lpszName
),
1315 debugstr_w(className
),
1316 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
1317 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
1318 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
1320 /* Fix the styles for MDI children */
1321 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1325 wndPtr
= WIN_GetPtr(cs
->hwndParent
);
1326 if (wndPtr
&& wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
1328 flags
= wndPtr
->flags
;
1329 WIN_ReleasePtr(wndPtr
);
1332 if (!(flags
& WIN_ISMDICLIENT
))
1334 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
1338 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
1339 * MDICREATESTRUCT members have the originally passed values.
1341 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
1342 * have the same layout.
1344 mdi_cs
.szClass
= cs
->lpszClass
;
1345 mdi_cs
.szTitle
= cs
->lpszName
;
1346 mdi_cs
.hOwner
= cs
->hInstance
;
1351 mdi_cs
.style
= cs
->style
;
1352 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
1354 cs
->lpCreateParams
= &mdi_cs
;
1356 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1358 if (cs
->style
& WS_POPUP
)
1360 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
1363 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
1367 cs
->style
&= ~WS_POPUP
;
1368 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1369 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1372 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
1376 /* Restore current maximized child */
1377 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
1379 TRACE("Restoring current maximized child %p\n", top_child
);
1380 if (cs
->style
& WS_MAXIMIZE
)
1382 /* if the new window is maximized don't bother repainting */
1383 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
1384 ShowWindow( top_child
, SW_SHOWNORMAL
);
1385 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
1387 else ShowWindow( top_child
, SW_SHOWNORMAL
);
1392 /* Find the parent window */
1394 parent
= cs
->hwndParent
;
1397 if (cs
->hwndParent
== HWND_MESSAGE
)
1399 cs
->hwndParent
= parent
= get_hwnd_message_parent();
1401 else if (cs
->hwndParent
)
1403 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1405 parent
= GetDesktopWindow();
1406 owner
= cs
->hwndParent
;
1410 DWORD parent_style
= GetWindowLongW( parent
, GWL_EXSTYLE
);
1411 if ((parent_style
& WS_EX_LAYOUTRTL
) && !(parent_style
& WS_EX_NOINHERITLAYOUT
))
1412 cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1417 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
1419 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1421 WARN("No parent for child window\n" );
1422 SetLastError(ERROR_TLW_WITH_WSCHILD
);
1423 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1426 /* are we creating the desktop or HWND_MESSAGE parent itself? */
1427 if (className
!= (LPCWSTR
)DESKTOP_CLASS_ATOM
&&
1428 (IS_INTRESOURCE(className
) || strcmpiW( className
, messageW
)))
1431 GetProcessDefaultLayout( &layout
);
1432 if (layout
& LAYOUT_RTL
) cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1433 parent
= GetDesktopWindow();
1437 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
1439 if ((cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1440 ((!(cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1441 (cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1442 cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1444 cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1446 /* Create the window structure */
1448 if (!(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1451 /* if it's a comctl32 class, GetClassInfo will load it, then we can retry */
1452 if (GetLastError() != ERROR_INVALID_HANDLE
||
1453 !GetClassInfoW( 0, className
, &wc
) ||
1454 !(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1457 hwnd
= wndPtr
->obj
.handle
;
1459 /* Fill the window structure */
1461 wndPtr
->tid
= GetCurrentThreadId();
1462 wndPtr
->hInstance
= cs
->hInstance
;
1463 wndPtr
->text
= NULL
;
1464 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
1465 wndPtr
->dwExStyle
= cs
->dwExStyle
;
1466 wndPtr
->wIDmenu
= 0;
1467 wndPtr
->helpContext
= 0;
1468 wndPtr
->pScroll
= NULL
;
1469 wndPtr
->userdata
= 0;
1471 wndPtr
->hIconSmall
= 0;
1472 wndPtr
->hIconSmall2
= 0;
1473 wndPtr
->hSysMenu
= 0;
1475 wndPtr
->min_pos
.x
= wndPtr
->min_pos
.y
= -1;
1476 wndPtr
->max_pos
.x
= wndPtr
->max_pos
.y
= -1;
1477 SetRect( &wndPtr
->normal_rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1479 if (wndPtr
->dwStyle
& WS_SYSMENU
) SetSystemMenu( hwnd
, 0 );
1482 * Correct the window styles.
1484 * It affects only the style loaded into the WIN structure.
1487 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1489 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1490 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1491 wndPtr
->dwStyle
|= WS_CAPTION
;
1494 /* WS_EX_WINDOWEDGE depends on some other styles */
1495 if (wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
)
1496 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1497 else if (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))
1499 if (!((wndPtr
->dwExStyle
& WS_EX_STATICEDGE
) &&
1500 (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
))))
1501 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1504 wndPtr
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1506 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1507 wndPtr
->flags
|= WIN_NEED_SIZE
;
1509 SERVER_START_REQ( set_window_info
)
1511 req
->handle
= wine_server_user_handle( hwnd
);
1512 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
| SET_WIN_UNICODE
;
1513 req
->style
= wndPtr
->dwStyle
;
1514 req
->ex_style
= wndPtr
->dwExStyle
;
1515 req
->instance
= wine_server_client_ptr( wndPtr
->hInstance
);
1516 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1517 req
->extra_offset
= -1;
1518 wine_server_call( req
);
1522 /* Set the window menu */
1524 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1528 if (!MENU_SetMenu(hwnd
, cs
->hMenu
))
1530 WIN_ReleasePtr( wndPtr
);
1531 free_window_handle( hwnd
);
1537 LPCWSTR menuName
= (LPCWSTR
)GetClassLongPtrW( hwnd
, GCLP_MENUNAME
);
1540 cs
->hMenu
= LoadMenuW( cs
->hInstance
, menuName
);
1541 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1545 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1547 /* call the WH_CBT hook */
1549 /* the window style passed to the hook must be the real window style,
1550 * rather than just the window style that the caller to CreateWindowEx
1551 * passed in, so we have to copy the original CREATESTRUCT and get the
1552 * the real style. */
1554 cbcs
.style
= wndPtr
->dwStyle
;
1556 cbtc
.hwndInsertAfter
= HWND_TOP
;
1557 WIN_ReleasePtr( wndPtr
);
1558 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
)) goto failed
;
1560 /* send the WM_GETMINMAXINFO message and fix the size if needed */
1564 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1566 POINT maxSize
, maxPos
, minTrack
, maxTrack
;
1567 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
1568 if (maxTrack
.x
< cx
) cx
= maxTrack
.x
;
1569 if (maxTrack
.y
< cy
) cy
= maxTrack
.y
;
1570 if (minTrack
.x
> cx
) cx
= minTrack
.x
;
1571 if (minTrack
.y
> cy
) cy
= minTrack
.y
;
1576 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cx
, cs
->y
+ cy
);
1577 /* check for wraparound */
1578 if (cs
->x
+ cx
< cs
->x
) rect
.right
= 0x7fffffff;
1579 if (cs
->y
+ cy
< cs
->y
) rect
.bottom
= 0x7fffffff;
1580 if (!set_window_pos( hwnd
, 0, SWP_NOZORDER
| SWP_NOACTIVATE
, &rect
, &rect
, NULL
)) goto failed
;
1582 /* send WM_NCCREATE */
1584 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd
, cs
->x
, cs
->y
, cx
, cy
);
1586 result
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1588 result
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1591 WARN( "%p: aborted by WM_NCCREATE\n", hwnd
);
1595 /* send WM_NCCALCSIZE */
1597 if (WIN_GetRectangles( hwnd
, COORDS_PARENT
, &rect
, NULL
))
1599 /* yes, even if the CBT hook was called with HWND_TOP */
1600 HWND insert_after
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1601 RECT client_rect
= rect
;
1603 /* the rectangle is in screen coords for WM_NCCALCSIZE when wparam is FALSE */
1604 MapWindowPoints( parent
, 0, (POINT
*)&client_rect
, 2 );
1605 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&client_rect
);
1606 MapWindowPoints( 0, parent
, (POINT
*)&client_rect
, 2 );
1607 set_window_pos( hwnd
, insert_after
, SWP_NOACTIVATE
, &rect
, &client_rect
, NULL
);
1611 /* send WM_CREATE */
1614 result
= SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1616 result
= SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1617 if (result
== -1) goto failed
;
1619 /* call the driver */
1621 if (!USER_Driver
->pCreateWindow( hwnd
)) goto failed
;
1623 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1625 /* send the size messages */
1627 if (!(wndPtr
= WIN_GetPtr( hwnd
)) ||
1628 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
1629 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
1631 WIN_ReleasePtr( wndPtr
);
1632 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &rect
);
1633 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1634 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1635 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1637 else WIN_ReleasePtr( wndPtr
);
1639 /* Show the window, maximizing or minimizing if needed */
1641 style
= WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1642 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1645 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1647 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1648 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1649 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1650 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
, newPos
.right
- newPos
.left
,
1651 newPos
.bottom
- newPos
.top
, swFlag
);
1654 /* Notify the parent window only */
1656 send_parent_notify( hwnd
, WM_CREATE
);
1657 if (!IsWindow( hwnd
)) return 0;
1659 if (cs
->style
& WS_VISIBLE
)
1661 if (cs
->style
& WS_MAXIMIZE
)
1663 else if (cs
->style
& WS_MINIMIZE
)
1664 sw
= SW_SHOWMINIMIZED
;
1666 ShowWindow( hwnd
, sw
);
1667 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1669 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1670 /* ShowWindow won't activate child windows */
1671 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1675 /* Call WH_SHELL hook */
1677 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1678 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1680 TRACE("created window %p\n", hwnd
);
1684 WIN_DestroyWindow( hwnd
);
1689 /***********************************************************************
1690 * CreateWindowExA (USER32.@)
1692 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1693 LPCSTR windowName
, DWORD style
, INT x
,
1694 INT y
, INT width
, INT height
,
1695 HWND parent
, HMENU menu
,
1696 HINSTANCE instance
, LPVOID data
)
1700 cs
.lpCreateParams
= data
;
1701 cs
.hInstance
= instance
;
1703 cs
.hwndParent
= parent
;
1709 cs
.lpszName
= windowName
;
1710 cs
.lpszClass
= className
;
1711 cs
.dwExStyle
= exStyle
;
1713 if (!IS_INTRESOURCE(className
))
1716 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) ))
1718 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, bufferW
, instance
, FALSE
);
1720 /* Note: we rely on the fact that CREATESTRUCTA and */
1721 /* CREATESTRUCTW have the same layout. */
1722 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, (LPCWSTR
)className
, instance
, FALSE
);
1726 /***********************************************************************
1727 * CreateWindowExW (USER32.@)
1729 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1730 LPCWSTR windowName
, DWORD style
, INT x
,
1731 INT y
, INT width
, INT height
,
1732 HWND parent
, HMENU menu
,
1733 HINSTANCE instance
, LPVOID data
)
1737 cs
.lpCreateParams
= data
;
1738 cs
.hInstance
= instance
;
1740 cs
.hwndParent
= parent
;
1746 cs
.lpszName
= windowName
;
1747 cs
.lpszClass
= className
;
1748 cs
.dwExStyle
= exStyle
;
1750 return wow_handlers
.create_window( &cs
, className
, instance
, TRUE
);
1754 /***********************************************************************
1755 * WIN_SendDestroyMsg
1757 static void WIN_SendDestroyMsg( HWND hwnd
)
1761 info
.cbSize
= sizeof(info
);
1762 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1764 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1765 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1769 * Send the WM_DESTROY to the window.
1771 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1774 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1775 * make sure that the window still exists when we come back.
1782 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1784 for (i
= 0; pWndArray
[i
]; i
++)
1786 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1788 HeapFree( GetProcessHeap(), 0, pWndArray
);
1791 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1795 /***********************************************************************
1796 * DestroyWindow (USER32.@)
1798 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1802 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || is_desktop_window( hwnd
))
1804 SetLastError( ERROR_ACCESS_DENIED
);
1808 TRACE("(%p)\n", hwnd
);
1812 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
1814 if (MENU_IsMenuActive() == hwnd
)
1817 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
1821 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1822 send_parent_notify( hwnd
, WM_DESTROY
);
1824 else if (!GetWindow( hwnd
, GW_OWNER
))
1826 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1827 /* FIXME: clean up palette - see "Internals" p.352 */
1830 if (!IsWindow(hwnd
)) return TRUE
;
1832 /* Hide the window */
1833 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
1835 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1837 ShowWindow( hwnd
, SW_HIDE
);
1839 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1840 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1843 if (!IsWindow(hwnd
)) return TRUE
;
1845 /* Recursively destroy owned windows */
1852 BOOL got_one
= FALSE
;
1853 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1856 for (i
= 0; list
[i
]; i
++)
1858 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1859 if (WIN_IsCurrentThread( list
[i
] ))
1861 DestroyWindow( list
[i
] );
1865 WIN_SetOwner( list
[i
], 0 );
1867 HeapFree( GetProcessHeap(), 0, list
);
1869 if (!got_one
) break;
1873 /* Send destroy messages */
1875 WIN_SendDestroyMsg( hwnd
);
1876 if (!IsWindow( hwnd
)) return TRUE
;
1878 CLIPBOARD_ReleaseOwner( hwnd
);
1880 /* Destroy the window storage */
1882 WIN_DestroyWindow( hwnd
);
1887 /***********************************************************************
1888 * CloseWindow (USER32.@)
1890 BOOL WINAPI
CloseWindow( HWND hwnd
)
1892 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
1893 ShowWindow( hwnd
, SW_MINIMIZE
);
1898 /***********************************************************************
1899 * OpenIcon (USER32.@)
1901 BOOL WINAPI
OpenIcon( HWND hwnd
)
1903 if (!IsIconic( hwnd
)) return FALSE
;
1904 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1909 /***********************************************************************
1910 * FindWindowExW (USER32.@)
1912 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
, LPCWSTR className
, LPCWSTR title
)
1917 WCHAR
*buffer
= NULL
;
1919 if (!parent
&& child
) parent
= GetDesktopWindow();
1920 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
1924 len
= strlenW(title
) + 1; /* one extra char to check for chars beyond the end */
1925 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
1928 if (!(list
= list_window_children( 0, parent
, className
, 0 ))) goto done
;
1932 child
= WIN_GetFullHandle( child
);
1933 while (list
[i
] && list
[i
] != child
) i
++;
1934 if (!list
[i
]) goto done
;
1935 i
++; /* start from next window */
1942 if (InternalGetWindowText( list
[i
], buffer
, len
+ 1 ))
1944 if (!strcmpiW( buffer
, title
)) break;
1948 if (!title
[0]) break;
1956 HeapFree( GetProcessHeap(), 0, list
);
1957 HeapFree( GetProcessHeap(), 0, buffer
);
1963 /***********************************************************************
1964 * FindWindowA (USER32.@)
1966 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
1968 HWND ret
= FindWindowExA( 0, 0, className
, title
);
1969 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1974 /***********************************************************************
1975 * FindWindowExA (USER32.@)
1977 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
, LPCSTR className
, LPCSTR title
)
1979 LPWSTR titleW
= NULL
;
1984 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
1985 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
1986 MultiByteToWideChar( CP_ACP
, 0, title
, -1, titleW
, len
);
1989 if (!IS_INTRESOURCE(className
))
1992 if (MultiByteToWideChar( CP_ACP
, 0, className
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
1993 hwnd
= FindWindowExW( parent
, child
, classW
, titleW
);
1997 hwnd
= FindWindowExW( parent
, child
, (LPCWSTR
)className
, titleW
);
2000 HeapFree( GetProcessHeap(), 0, titleW
);
2005 /***********************************************************************
2006 * FindWindowW (USER32.@)
2008 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
2010 return FindWindowExW( 0, 0, className
, title
);
2014 /**********************************************************************
2015 * GetDesktopWindow (USER32.@)
2017 HWND WINAPI
GetDesktopWindow(void)
2019 struct user_thread_info
*thread_info
= get_user_thread_info();
2021 if (thread_info
->top_window
) return thread_info
->top_window
;
2023 SERVER_START_REQ( get_desktop_window
)
2026 if (!wine_server_call( req
))
2028 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2029 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2034 if (!thread_info
->top_window
)
2036 USEROBJECTFLAGS flags
;
2037 if (!GetUserObjectInformationW( GetProcessWindowStation(), UOI_FLAGS
, &flags
,
2038 sizeof(flags
), NULL
) || (flags
.dwFlags
& WSF_VISIBLE
))
2040 static const WCHAR explorer
[] = {'\\','e','x','p','l','o','r','e','r','.','e','x','e',0};
2041 static const WCHAR args
[] = {' ','/','d','e','s','k','t','o','p',0};
2043 PROCESS_INFORMATION pi
;
2044 WCHAR windir
[MAX_PATH
];
2045 WCHAR app
[MAX_PATH
+ sizeof(explorer
)/sizeof(WCHAR
)];
2046 WCHAR cmdline
[MAX_PATH
+ (sizeof(explorer
) + sizeof(args
))/sizeof(WCHAR
)];
2049 memset( &si
, 0, sizeof(si
) );
2051 si
.dwFlags
= STARTF_USESTDHANDLES
;
2054 si
.hStdError
= GetStdHandle( STD_ERROR_HANDLE
);
2056 GetSystemDirectoryW( windir
, MAX_PATH
);
2057 strcpyW( app
, windir
);
2058 strcatW( app
, explorer
);
2059 strcpyW( cmdline
, app
);
2060 strcatW( cmdline
, args
);
2062 Wow64DisableWow64FsRedirection( &redir
);
2063 if (CreateProcessW( app
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
,
2064 NULL
, windir
, &si
, &pi
))
2066 TRACE( "started explorer pid %04x tid %04x\n", pi
.dwProcessId
, pi
.dwThreadId
);
2067 WaitForInputIdle( pi
.hProcess
, 10000 );
2068 CloseHandle( pi
.hThread
);
2069 CloseHandle( pi
.hProcess
);
2071 else WARN( "failed to start explorer, err %d\n", GetLastError() );
2072 Wow64RevertWow64FsRedirection( redir
);
2074 else TRACE( "not starting explorer since winstation is not visible\n" );
2076 SERVER_START_REQ( get_desktop_window
)
2079 if (!wine_server_call( req
))
2081 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2082 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2088 if (!thread_info
->top_window
|| !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
2089 ERR( "failed to create desktop window\n" );
2091 return thread_info
->top_window
;
2095 /*******************************************************************
2096 * EnableWindow (USER32.@)
2098 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
2103 if (is_broadcast(hwnd
))
2105 SetLastError( ERROR_INVALID_PARAMETER
);
2109 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
2110 return SendMessageW( hwnd
, WM_WINE_ENABLEWINDOW
, enable
, 0 );
2114 TRACE("( %p, %d )\n", hwnd
, enable
);
2116 retvalue
= !IsWindowEnabled( hwnd
);
2118 if (enable
&& retvalue
)
2120 WIN_SetStyle( hwnd
, 0, WS_DISABLED
);
2121 SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
2123 else if (!enable
&& !retvalue
)
2127 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0);
2129 WIN_SetStyle( hwnd
, WS_DISABLED
, 0 );
2131 if (hwnd
== GetFocus())
2132 SetFocus( 0 ); /* A disabled window can't have the focus */
2134 capture_wnd
= GetCapture();
2135 if (hwnd
== capture_wnd
|| IsChild(hwnd
, capture_wnd
))
2136 ReleaseCapture(); /* A disabled window can't capture the mouse */
2138 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
2144 /***********************************************************************
2145 * IsWindowEnabled (USER32.@)
2147 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
2149 return !(GetWindowLongW( hWnd
, GWL_STYLE
) & WS_DISABLED
);
2153 /***********************************************************************
2154 * IsWindowUnicode (USER32.@)
2156 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
2159 BOOL retvalue
= FALSE
;
2161 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
2163 if (wndPtr
== WND_DESKTOP
) return TRUE
;
2165 if (wndPtr
!= WND_OTHER_PROCESS
)
2167 retvalue
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2168 WIN_ReleasePtr( wndPtr
);
2172 SERVER_START_REQ( get_window_info
)
2174 req
->handle
= wine_server_user_handle( hwnd
);
2175 if (!wine_server_call_err( req
)) retvalue
= reply
->is_unicode
;
2183 /**********************************************************************
2186 * Helper function for GetWindowLong().
2188 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
2190 LONG_PTR retvalue
= 0;
2193 if (offset
== GWLP_HWNDPARENT
)
2195 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
2196 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
2197 return (ULONG_PTR
)parent
;
2200 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2202 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2206 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2208 if (offset
== GWLP_WNDPROC
)
2210 SetLastError( ERROR_ACCESS_DENIED
);
2213 SERVER_START_REQ( set_window_info
)
2215 req
->handle
= wine_server_user_handle( hwnd
);
2216 req
->flags
= 0; /* don't set anything, just retrieve */
2217 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
2218 req
->extra_size
= (offset
>= 0) ? size
: 0;
2219 if (!wine_server_call_err( req
))
2223 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
2224 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
2225 case GWLP_ID
: retvalue
= reply
->old_id
; break;
2226 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
); break;
2227 case GWLP_USERDATA
: retvalue
= reply
->old_user_data
; break;
2229 if (offset
>= 0) retvalue
= get_win_data( &reply
->old_extra_value
, size
);
2230 else SetLastError( ERROR_INVALID_INDEX
);
2239 /* now we have a valid wndPtr */
2243 if (offset
> (int)(wndPtr
->cbWndExtra
- size
))
2245 WARN("Invalid offset %d\n", offset
);
2246 WIN_ReleasePtr( wndPtr
);
2247 SetLastError( ERROR_INVALID_INDEX
);
2250 retvalue
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2252 /* Special case for dialog window procedure */
2253 if ((offset
== DWLP_DLGPROC
) && (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2254 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, unicode
);
2255 WIN_ReleasePtr( wndPtr
);
2261 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
2262 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
2263 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
2264 case GWLP_ID
: retvalue
= wndPtr
->wIDmenu
; break;
2265 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
2267 /* This looks like a hack only for the edit control (see tests). This makes these controls
2268 * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests
2269 * that the hack is in GetWindowLongPtr[AW], not in winprocs.
2271 if (wndPtr
->winproc
== BUILTIN_WINPROC(WINPROC_EDIT
) && (!unicode
!= !(wndPtr
->flags
& WIN_ISUNICODE
)))
2272 retvalue
= (ULONG_PTR
)wndPtr
->winproc
;
2274 retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
);
2277 WARN("Unknown offset %d\n", offset
);
2278 SetLastError( ERROR_INVALID_INDEX
);
2281 WIN_ReleasePtr(wndPtr
);
2286 /**********************************************************************
2289 * Helper function for SetWindowLong().
2291 * 0 is the failure code. However, in the case of failure SetLastError
2292 * must be set to distinguish between a 0 return value and a failure.
2294 LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, UINT size
, LONG_PTR newval
, BOOL unicode
)
2297 BOOL ok
, made_visible
= FALSE
;
2298 LONG_PTR retval
= 0;
2301 TRACE( "%p %d %lx %c\n", hwnd
, offset
, newval
, unicode
? 'W' : 'A' );
2303 if (is_broadcast(hwnd
))
2305 SetLastError( ERROR_INVALID_PARAMETER
);
2309 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2311 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2314 if (wndPtr
== WND_DESKTOP
)
2316 /* can't change anything on the desktop window */
2317 SetLastError( ERROR_ACCESS_DENIED
);
2320 if (wndPtr
== WND_OTHER_PROCESS
)
2322 if (offset
== GWLP_WNDPROC
)
2324 SetLastError( ERROR_ACCESS_DENIED
);
2327 if (offset
> 32767 || offset
< -32767)
2329 SetLastError( ERROR_INVALID_INDEX
);
2332 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, MAKEWPARAM( offset
, size
), newval
);
2335 /* first some special cases */
2339 style
.styleOld
= wndPtr
->dwStyle
;
2340 style
.styleNew
= newval
;
2341 WIN_ReleasePtr( wndPtr
);
2342 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
)&style
);
2343 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2344 newval
= style
.styleNew
;
2345 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
2346 if (wndPtr
->parent
== GetDesktopWindow()) newval
|= WS_CLIPSIBLINGS
;
2347 /* FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change
2348 WS_EX_WINDOWEDGE too */
2351 style
.styleOld
= wndPtr
->dwExStyle
;
2352 style
.styleNew
= newval
;
2353 WIN_ReleasePtr( wndPtr
);
2354 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
)&style
);
2355 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2356 /* WS_EX_TOPMOST can only be changed through SetWindowPos */
2357 newval
= (style
.styleNew
& ~WS_EX_TOPMOST
) | (wndPtr
->dwExStyle
& WS_EX_TOPMOST
);
2358 /* WS_EX_WINDOWEDGE depends on some other styles */
2359 if (newval
& WS_EX_DLGMODALFRAME
)
2360 newval
|= WS_EX_WINDOWEDGE
;
2361 else if (!(newval
& WS_EX_STATICEDGE
) && (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)))
2362 newval
|= WS_EX_WINDOWEDGE
;
2364 newval
&= ~WS_EX_WINDOWEDGE
;
2366 case GWLP_HWNDPARENT
:
2367 if (wndPtr
->parent
== GetDesktopWindow())
2369 WIN_ReleasePtr( wndPtr
);
2370 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
2374 WIN_ReleasePtr( wndPtr
);
2375 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
2380 UINT old_flags
= wndPtr
->flags
;
2381 retval
= WIN_GetWindowLong( hwnd
, offset
, size
, unicode
);
2382 proc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2383 if (proc
) wndPtr
->winproc
= proc
;
2384 if (WINPROC_IsUnicode( proc
, unicode
)) wndPtr
->flags
|= WIN_ISUNICODE
;
2385 else wndPtr
->flags
&= ~WIN_ISUNICODE
;
2386 if (!((old_flags
^ wndPtr
->flags
) & WIN_ISUNICODE
))
2388 WIN_ReleasePtr( wndPtr
);
2391 /* update is_unicode flag on the server side */
2395 case GWLP_HINSTANCE
:
2399 if ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2400 (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2402 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
2403 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, unicode
);
2404 *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2405 WIN_ReleasePtr( wndPtr
);
2410 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- size
))
2412 WARN("Invalid offset %d\n", offset
);
2413 WIN_ReleasePtr( wndPtr
);
2414 SetLastError( ERROR_INVALID_INDEX
);
2417 else if (get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
) == newval
)
2419 /* already set to the same value */
2420 WIN_ReleasePtr( wndPtr
);
2426 SERVER_START_REQ( set_window_info
)
2428 req
->handle
= wine_server_user_handle( hwnd
);
2429 req
->extra_offset
= -1;
2433 req
->flags
= SET_WIN_STYLE
;
2434 req
->style
= newval
;
2437 req
->flags
= SET_WIN_EXSTYLE
;
2438 req
->ex_style
= newval
;
2441 req
->flags
= SET_WIN_ID
;
2444 case GWLP_HINSTANCE
:
2445 req
->flags
= SET_WIN_INSTANCE
;
2446 req
->instance
= wine_server_client_ptr( (void *)newval
);
2449 req
->flags
= SET_WIN_UNICODE
;
2450 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2453 req
->flags
= SET_WIN_USERDATA
;
2454 req
->user_data
= newval
;
2457 req
->flags
= SET_WIN_EXTRA
;
2458 req
->extra_offset
= offset
;
2459 req
->extra_size
= size
;
2460 set_win_data( &req
->extra_value
, newval
, size
);
2462 if ((ok
= !wine_server_call_err( req
)))
2467 wndPtr
->dwStyle
= newval
;
2468 retval
= reply
->old_style
;
2471 wndPtr
->dwExStyle
= newval
;
2472 retval
= reply
->old_ex_style
;
2475 wndPtr
->wIDmenu
= newval
;
2476 retval
= reply
->old_id
;
2478 case GWLP_HINSTANCE
:
2479 wndPtr
->hInstance
= (HINSTANCE
)newval
;
2480 retval
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
2485 wndPtr
->userdata
= newval
;
2486 retval
= reply
->old_user_data
;
2489 retval
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2490 set_win_data( (char *)wndPtr
->wExtra
+ offset
, newval
, size
);
2497 if ((offset
== GWL_STYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
)) ||
2498 (offset
== GWL_EXSTYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_EX_LAYERED
)))
2500 made_visible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
2501 invalidate_dce( wndPtr
, NULL
);
2503 WIN_ReleasePtr( wndPtr
);
2507 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2509 style
.styleOld
= retval
;
2510 style
.styleNew
= newval
;
2511 USER_Driver
->pSetWindowStyle( hwnd
, offset
, &style
);
2512 if (made_visible
) update_window_state( hwnd
);
2513 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2520 /**********************************************************************
2521 * GetWindowWord (USER32.@)
2523 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
2528 case GWLP_HINSTANCE
:
2529 case GWLP_HWNDPARENT
:
2534 WARN("Invalid offset %d\n", offset
);
2535 SetLastError( ERROR_INVALID_INDEX
);
2540 return WIN_GetWindowLong( hwnd
, offset
, sizeof(WORD
), FALSE
);
2544 /**********************************************************************
2545 * GetWindowLongA (USER32.@)
2547 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2549 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), FALSE
);
2553 /**********************************************************************
2554 * GetWindowLongW (USER32.@)
2556 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2558 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), TRUE
);
2562 /**********************************************************************
2563 * SetWindowWord (USER32.@)
2565 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
2570 case GWLP_HINSTANCE
:
2571 case GWLP_HWNDPARENT
:
2576 WARN("Invalid offset %d\n", offset
);
2577 SetLastError( ERROR_INVALID_INDEX
);
2582 return WIN_SetWindowLong( hwnd
, offset
, sizeof(WORD
), newval
, FALSE
);
2586 /**********************************************************************
2587 * SetWindowLongA (USER32.@)
2589 * See SetWindowLongW.
2591 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2593 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, FALSE
);
2597 /**********************************************************************
2598 * SetWindowLongW (USER32.@) Set window attribute
2600 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2601 * value in a window's extra memory.
2603 * The _hwnd_ parameter specifies the handle to a window that
2604 * has extra memory. The _newval_ parameter contains the new
2605 * attribute or extra memory value. If positive, the _offset_
2606 * parameter is the byte-addressed location in the window's extra
2607 * memory to set. If negative, _offset_ specifies the window
2608 * attribute to set, and should be one of the following values:
2610 * GWL_EXSTYLE The window's extended window style
2612 * GWL_STYLE The window's window style.
2614 * GWLP_WNDPROC Pointer to the window's window procedure.
2616 * GWLP_HINSTANCE The window's application instance handle.
2618 * GWLP_ID The window's identifier.
2620 * GWLP_USERDATA The window's user-specified data.
2622 * If the window is a dialog box, the _offset_ parameter can be one of
2623 * the following values:
2625 * DWLP_DLGPROC The address of the window's dialog box procedure.
2627 * DWLP_MSGRESULT The return value of a message
2628 * that the dialog box procedure processed.
2630 * DWLP_USER Application specific information.
2634 * If successful, returns the previous value located at _offset_. Otherwise,
2639 * Extra memory for a window class is specified by a nonzero cbWndExtra
2640 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2641 * time of class creation.
2643 * Using GWL_WNDPROC to set a new window procedure effectively creates
2644 * a window subclass. Use CallWindowProc() in the new windows procedure
2645 * to pass messages to the superclass's window procedure.
2647 * The user data is reserved for use by the application which created
2650 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2651 * instead, call the EnableWindow() function to change the window's
2654 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2655 * SetParent() instead.
2658 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2659 * it sends WM_STYLECHANGING before changing the settings
2660 * and WM_STYLECHANGED afterwards.
2661 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2663 LONG WINAPI
SetWindowLongW(
2664 HWND hwnd
, /* [in] window to alter */
2665 INT offset
, /* [in] offset, in bytes, of location to alter */
2666 LONG newval
/* [in] new value of location */
2668 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, TRUE
);
2672 /*******************************************************************
2673 * GetWindowTextA (USER32.@)
2675 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2679 if (!lpString
) return 0;
2681 if (WIN_IsCurrentProcess( hwnd
))
2682 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2684 /* when window belongs to other process, don't send a message */
2685 if (nMaxCount
<= 0) return 0;
2686 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) ))) return 0;
2687 get_server_window_text( hwnd
, buffer
, nMaxCount
);
2688 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
2689 lpString
[nMaxCount
-1] = 0;
2690 HeapFree( GetProcessHeap(), 0, buffer
);
2691 return strlen(lpString
);
2695 /*******************************************************************
2696 * InternalGetWindowText (USER32.@)
2698 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2702 if (nMaxCount
<= 0) return 0;
2703 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
2704 if (win
== WND_DESKTOP
) lpString
[0] = 0;
2705 else if (win
!= WND_OTHER_PROCESS
)
2707 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
2708 else lpString
[0] = 0;
2709 WIN_ReleasePtr( win
);
2713 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2715 return strlenW(lpString
);
2719 /*******************************************************************
2720 * GetWindowTextW (USER32.@)
2722 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2724 if (!lpString
) return 0;
2726 if (WIN_IsCurrentProcess( hwnd
))
2727 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2729 /* when window belongs to other process, don't send a message */
2730 if (nMaxCount
<= 0) return 0;
2731 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2732 return strlenW(lpString
);
2736 /*******************************************************************
2737 * SetWindowTextA (USER32.@)
2738 * SetWindowText (USER32.@)
2740 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2742 if (is_broadcast(hwnd
))
2744 SetLastError( ERROR_INVALID_PARAMETER
);
2747 if (!WIN_IsCurrentProcess( hwnd
))
2748 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2749 debugstr_a(lpString
), hwnd
);
2750 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2754 /*******************************************************************
2755 * SetWindowTextW (USER32.@)
2757 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2759 if (is_broadcast(hwnd
))
2761 SetLastError( ERROR_INVALID_PARAMETER
);
2764 if (!WIN_IsCurrentProcess( hwnd
))
2765 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2766 debugstr_w(lpString
), hwnd
);
2767 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2771 /*******************************************************************
2772 * GetWindowTextLengthA (USER32.@)
2774 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2776 return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2779 /*******************************************************************
2780 * GetWindowTextLengthW (USER32.@)
2782 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2784 return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2788 /*******************************************************************
2789 * IsWindow (USER32.@)
2791 BOOL WINAPI
IsWindow( HWND hwnd
)
2796 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
2797 if (ptr
== WND_DESKTOP
) return TRUE
;
2799 if (ptr
!= WND_OTHER_PROCESS
)
2801 WIN_ReleasePtr( ptr
);
2805 /* check other processes */
2806 SERVER_START_REQ( get_window_info
)
2808 req
->handle
= wine_server_user_handle( hwnd
);
2809 ret
= !wine_server_call_err( req
);
2816 /***********************************************************************
2817 * GetWindowThreadProcessId (USER32.@)
2819 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
2824 if (!(ptr
= WIN_GetPtr( hwnd
)))
2826 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2830 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
2832 /* got a valid window */
2834 if (process
) *process
= GetCurrentProcessId();
2835 WIN_ReleasePtr( ptr
);
2839 /* check other processes */
2840 SERVER_START_REQ( get_window_info
)
2842 req
->handle
= wine_server_user_handle( hwnd
);
2843 if (!wine_server_call_err( req
))
2845 tid
= (DWORD
)reply
->tid
;
2846 if (process
) *process
= (DWORD
)reply
->pid
;
2854 /*****************************************************************
2855 * GetParent (USER32.@)
2857 HWND WINAPI
GetParent( HWND hwnd
)
2862 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2864 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2867 if (wndPtr
== WND_DESKTOP
) return 0;
2868 if (wndPtr
== WND_OTHER_PROCESS
)
2870 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2871 if (style
& (WS_POPUP
| WS_CHILD
))
2873 SERVER_START_REQ( get_window_tree
)
2875 req
->handle
= wine_server_user_handle( hwnd
);
2876 if (!wine_server_call_err( req
))
2878 if (style
& WS_POPUP
) retvalue
= wine_server_ptr_handle( reply
->owner
);
2879 else if (style
& WS_CHILD
) retvalue
= wine_server_ptr_handle( reply
->parent
);
2887 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
2888 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
2889 WIN_ReleasePtr( wndPtr
);
2895 /*****************************************************************
2896 * GetAncestor (USER32.@)
2898 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
2901 HWND
*list
, ret
= 0;
2906 if (!(win
= WIN_GetPtr( hwnd
)))
2908 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2911 if (win
== WND_DESKTOP
) return 0;
2912 if (win
!= WND_OTHER_PROCESS
)
2915 WIN_ReleasePtr( win
);
2917 else /* need to query the server */
2919 SERVER_START_REQ( get_window_tree
)
2921 req
->handle
= wine_server_user_handle( hwnd
);
2922 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->parent
);
2929 if (!(list
= list_window_parents( hwnd
))) return 0;
2931 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
2935 while (list
[count
]) count
++;
2936 ret
= list
[count
- 2]; /* get the one before the desktop */
2938 HeapFree( GetProcessHeap(), 0, list
);
2942 if (is_desktop_window( hwnd
)) return 0;
2943 ret
= WIN_GetFullHandle( hwnd
);
2946 HWND parent
= GetParent( ret
);
2956 /*****************************************************************
2957 * SetParent (USER32.@)
2959 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
2962 HWND old_parent
= 0;
2968 if (is_broadcast(hwnd
) || is_broadcast(parent
))
2970 SetLastError(ERROR_INVALID_PARAMETER
);
2974 if (!parent
) parent
= GetDesktopWindow();
2975 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
2976 else parent
= WIN_GetFullHandle( parent
);
2978 if (!IsWindow( parent
))
2980 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2984 /* Some applications try to set a child as a parent */
2985 if (IsChild(hwnd
, parent
))
2987 SetLastError( ERROR_INVALID_PARAMETER
);
2991 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
2992 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
2994 if (full_handle
== parent
)
2996 SetLastError( ERROR_INVALID_PARAMETER
);
3000 /* Windows hides the window first, then shows it again
3001 * including the WM_SHOWWINDOW messages and all */
3002 was_visible
= ShowWindow( hwnd
, SW_HIDE
);
3004 wndPtr
= WIN_GetPtr( hwnd
);
3005 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
3007 pt
.x
= wndPtr
->rectWindow
.left
;
3008 pt
.y
= wndPtr
->rectWindow
.top
;
3010 SERVER_START_REQ( set_parent
)
3012 req
->handle
= wine_server_user_handle( hwnd
);
3013 req
->parent
= wine_server_user_handle( parent
);
3014 if ((ret
= !wine_server_call( req
)))
3016 old_parent
= wine_server_ptr_handle( reply
->old_parent
);
3017 wndPtr
->parent
= parent
= wine_server_ptr_handle( reply
->full_parent
);
3022 WIN_ReleasePtr( wndPtr
);
3025 USER_Driver
->pSetParent( full_handle
, parent
, old_parent
);
3027 /* SetParent additionally needs to make hwnd the topmost window
3028 in the x-order and send the expected WM_WINDOWPOSCHANGING and
3029 WM_WINDOWPOSCHANGED notification messages.
3031 SetWindowPos( hwnd
, HWND_TOP
, pt
.x
, pt
.y
, 0, 0, SWP_NOSIZE
);
3033 if (was_visible
) ShowWindow( hwnd
, SW_SHOW
);
3039 /*******************************************************************
3040 * IsChild (USER32.@)
3042 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
3048 if (!(GetWindowLongW( child
, GWL_STYLE
) & WS_CHILD
)) return FALSE
;
3049 if (!(list
= list_window_parents( child
))) return FALSE
;
3050 parent
= WIN_GetFullHandle( parent
);
3051 for (i
= 0; list
[i
]; i
++)
3053 if (list
[i
] == parent
)
3055 ret
= list
[i
] && list
[i
+1];
3058 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_CHILD
)) break;
3060 HeapFree( GetProcessHeap(), 0, list
);
3065 /***********************************************************************
3066 * IsWindowVisible (USER32.@)
3068 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
3074 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
3075 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3078 for (i
= 0; list
[i
+1]; i
++)
3079 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
3080 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3082 HeapFree( GetProcessHeap(), 0, list
);
3087 /***********************************************************************
3088 * WIN_IsWindowDrawable
3090 * hwnd is drawable when it is visible, all parents are not
3091 * minimized, and it is itself not minimized unless we are
3092 * trying to draw its default class icon.
3094 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
3099 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3101 if (!(style
& WS_VISIBLE
)) return FALSE
;
3102 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
3104 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3107 for (i
= 0; list
[i
+1]; i
++)
3108 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
3110 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3112 HeapFree( GetProcessHeap(), 0, list
);
3117 /*******************************************************************
3118 * GetTopWindow (USER32.@)
3120 HWND WINAPI
GetTopWindow( HWND hwnd
)
3122 if (!hwnd
) hwnd
= GetDesktopWindow();
3123 return GetWindow( hwnd
, GW_CHILD
);
3127 /*******************************************************************
3128 * GetWindow (USER32.@)
3130 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
3134 if (rel
== GW_OWNER
) /* this one may be available locally */
3136 WND
*wndPtr
= WIN_GetPtr( hwnd
);
3139 SetLastError( ERROR_INVALID_HANDLE
);
3142 if (wndPtr
== WND_DESKTOP
) return 0;
3143 if (wndPtr
!= WND_OTHER_PROCESS
)
3145 retval
= wndPtr
->owner
;
3146 WIN_ReleasePtr( wndPtr
);
3149 /* else fall through to server call */
3152 SERVER_START_REQ( get_window_tree
)
3154 req
->handle
= wine_server_user_handle( hwnd
);
3155 if (!wine_server_call_err( req
))
3160 retval
= wine_server_ptr_handle( reply
->first_sibling
);
3163 retval
= wine_server_ptr_handle( reply
->last_sibling
);
3166 retval
= wine_server_ptr_handle( reply
->next_sibling
);
3169 retval
= wine_server_ptr_handle( reply
->prev_sibling
);
3172 retval
= wine_server_ptr_handle( reply
->owner
);
3175 retval
= wine_server_ptr_handle( reply
->first_child
);
3185 /*******************************************************************
3186 * ShowOwnedPopups (USER32.@)
3188 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
3192 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
3194 if (!win_array
) return TRUE
;
3196 while (win_array
[count
]) count
++;
3197 while (--count
>= 0)
3199 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
3200 if (!(pWnd
= WIN_GetPtr( win_array
[count
] ))) continue;
3201 if (pWnd
== WND_OTHER_PROCESS
) continue;
3204 if (pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
3206 WIN_ReleasePtr( pWnd
);
3207 /* In Windows, ShowOwnedPopups(TRUE) generates
3208 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
3209 * regardless of the state of the owner
3211 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
3217 if (pWnd
->dwStyle
& WS_VISIBLE
)
3219 WIN_ReleasePtr( pWnd
);
3220 /* In Windows, ShowOwnedPopups(FALSE) generates
3221 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
3222 * regardless of the state of the owner
3224 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
3228 WIN_ReleasePtr( pWnd
);
3230 HeapFree( GetProcessHeap(), 0, win_array
);
3235 /*******************************************************************
3236 * GetLastActivePopup (USER32.@)
3238 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
3242 SERVER_START_REQ( get_window_info
)
3244 req
->handle
= wine_server_user_handle( hwnd
);
3245 if (!wine_server_call_err( req
)) retval
= wine_server_ptr_handle( reply
->last_active
);
3252 /*******************************************************************
3255 * Build an array of the children of a given window. The array must be
3256 * freed with HeapFree. Returns NULL when no windows are found.
3258 HWND
*WIN_ListChildren( HWND hwnd
)
3262 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3265 return list_window_children( 0, hwnd
, NULL
, 0 );
3269 /*******************************************************************
3270 * EnumWindows (USER32.@)
3272 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
3278 USER_CheckNotLock();
3280 /* We have to build a list of all windows first, to avoid */
3281 /* unpleasant side-effects, for instance if the callback */
3282 /* function changes the Z-order of the windows. */
3284 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
3286 /* Now call the callback function for every window */
3288 for (i
= 0; list
[i
]; i
++)
3290 /* Make sure that the window still exists */
3291 if (!IsWindow( list
[i
] )) continue;
3292 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
3294 HeapFree( GetProcessHeap(), 0, list
);
3299 /**********************************************************************
3300 * EnumThreadWindows (USER32.@)
3302 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
3308 USER_CheckNotLock();
3310 if (!(list
= list_window_children( 0, GetDesktopWindow(), NULL
, id
))) return TRUE
;
3312 /* Now call the callback function for every window */
3314 for (i
= 0; list
[i
]; i
++)
3315 if (!(ret
= func( list
[i
], lParam
))) break;
3316 HeapFree( GetProcessHeap(), 0, list
);
3321 /***********************************************************************
3322 * EnumDesktopWindows (USER32.@)
3324 BOOL WINAPI
EnumDesktopWindows( HDESK desktop
, WNDENUMPROC func
, LPARAM lparam
)
3329 USER_CheckNotLock();
3331 if (!(list
= list_window_children( desktop
, 0, NULL
, 0 ))) return TRUE
;
3333 for (i
= 0; list
[i
]; i
++)
3334 if (!func( list
[i
], lparam
)) break;
3335 HeapFree( GetProcessHeap(), 0, list
);
3340 /**********************************************************************
3341 * WIN_EnumChildWindows
3343 * Helper function for EnumChildWindows().
3345 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
3350 for ( ; *list
; list
++)
3352 /* Make sure that the window still exists */
3353 if (!IsWindow( *list
)) continue;
3354 /* Build children list first */
3355 childList
= WIN_ListChildren( *list
);
3357 ret
= func( *list
, lParam
);
3361 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
3362 HeapFree( GetProcessHeap(), 0, childList
);
3364 if (!ret
) return FALSE
;
3370 /**********************************************************************
3371 * EnumChildWindows (USER32.@)
3373 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
3378 USER_CheckNotLock();
3380 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
3381 ret
= WIN_EnumChildWindows( list
, func
, lParam
);
3382 HeapFree( GetProcessHeap(), 0, list
);
3387 /*******************************************************************
3388 * AnyPopup (USER32.@)
3390 BOOL WINAPI
AnyPopup(void)
3394 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
3396 if (!list
) return FALSE
;
3397 for (i
= 0; list
[i
]; i
++)
3399 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
3401 retvalue
= (list
[i
] != 0);
3402 HeapFree( GetProcessHeap(), 0, list
);
3407 /*******************************************************************
3408 * FlashWindow (USER32.@)
3410 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
3414 TRACE("%p\n", hWnd
);
3416 if (IsIconic( hWnd
))
3418 RedrawWindow( hWnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
3420 wndPtr
= WIN_GetPtr(hWnd
);
3421 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3422 if (bInvert
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
3424 wndPtr
->flags
|= WIN_NCACTIVATED
;
3428 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
3430 WIN_ReleasePtr( wndPtr
);
3437 wndPtr
= WIN_GetPtr(hWnd
);
3438 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3439 hWnd
= wndPtr
->obj
.handle
; /* make it a full handle */
3441 if (bInvert
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
3442 else wparam
= (hWnd
== GetForegroundWindow());
3444 WIN_ReleasePtr( wndPtr
);
3445 SendMessageW( hWnd
, WM_NCACTIVATE
, wparam
, 0 );
3450 /*******************************************************************
3451 * FlashWindowEx (USER32.@)
3453 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfwi
)
3455 FIXME("%p\n", pfwi
);
3459 /*******************************************************************
3460 * GetWindowContextHelpId (USER32.@)
3462 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
3465 WND
*wnd
= WIN_GetPtr( hwnd
);
3466 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
3467 if (wnd
== WND_OTHER_PROCESS
)
3469 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3472 retval
= wnd
->helpContext
;
3473 WIN_ReleasePtr( wnd
);
3478 /*******************************************************************
3479 * SetWindowContextHelpId (USER32.@)
3481 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
3483 WND
*wnd
= WIN_GetPtr( hwnd
);
3484 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
3485 if (wnd
== WND_OTHER_PROCESS
)
3487 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3490 wnd
->helpContext
= id
;
3491 WIN_ReleasePtr( wnd
);
3496 /*******************************************************************
3497 * DragDetect (USER32.@)
3499 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3503 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3504 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3506 rect
.left
= pt
.x
- wDragWidth
;
3507 rect
.right
= pt
.x
+ wDragWidth
;
3509 rect
.top
= pt
.y
- wDragHeight
;
3510 rect
.bottom
= pt
.y
+ wDragHeight
;
3516 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
3518 if( msg
.message
== WM_LBUTTONUP
)
3523 if( msg
.message
== WM_MOUSEMOVE
)
3526 tmp
.x
= (short)LOWORD(msg
.lParam
);
3527 tmp
.y
= (short)HIWORD(msg
.lParam
);
3528 if( !PtInRect( &rect
, tmp
))
3540 /******************************************************************************
3541 * GetWindowModuleFileNameA (USER32.@)
3543 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR module
, UINT size
)
3548 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3550 win
= WIN_GetPtr( hwnd
);
3551 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3553 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3556 hinst
= win
->hInstance
;
3557 WIN_ReleasePtr( win
);
3559 return GetModuleFileNameA( hinst
, module
, size
);
3562 /******************************************************************************
3563 * GetWindowModuleFileNameW (USER32.@)
3565 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR module
, UINT size
)
3570 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3572 win
= WIN_GetPtr( hwnd
);
3573 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3575 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3578 hinst
= win
->hInstance
;
3579 WIN_ReleasePtr( win
);
3581 return GetModuleFileNameW( hinst
, module
, size
);
3584 /******************************************************************************
3585 * GetWindowInfo (USER32.@)
3587 * Note: tests show that Windows doesn't check cbSize of the structure.
3589 BOOL WINAPI DECLSPEC_HOTPATCH
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
3591 if (!pwi
) return FALSE
;
3592 if (!WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &pwi
->rcWindow
, &pwi
->rcClient
)) return FALSE
;
3594 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3595 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3596 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
3598 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
3599 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
3601 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
3602 pwi
->wCreatorVersion
= 0x0400;
3607 /******************************************************************************
3608 * SwitchDesktop (USER32.@)
3610 * NOTES: Sets the current input or interactive desktop.
3612 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
3614 FIXME("(hwnd %p) stub!\n", hDesktop
);
3619 /***********************************************************************
3620 * __wine_set_pixel_format
3622 BOOL CDECL
__wine_set_pixel_format( HWND hwnd
, int format
)
3624 WND
*win
= WIN_GetPtr( hwnd
);
3626 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
3628 WARN( "setting format %d on win %p not supported\n", format
, hwnd
);
3631 win
->pixel_format
= format
;
3632 WIN_ReleasePtr( win
);
3634 update_window_state( hwnd
);
3639 /*****************************************************************************
3640 * SetLayeredWindowAttributes (USER32.@)
3642 BOOL WINAPI
SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
3646 TRACE("(%p,%08x,%d,%x): stub!\n", hwnd
, key
, alpha
, flags
);
3648 SERVER_START_REQ( set_window_layered_info
)
3650 req
->handle
= wine_server_user_handle( hwnd
);
3651 req
->color_key
= key
;
3654 ret
= !wine_server_call_err( req
);
3658 if (ret
) USER_Driver
->pSetLayeredWindowAttributes( hwnd
, key
, alpha
, flags
);
3664 /*****************************************************************************
3665 * GetLayeredWindowAttributes (USER32.@)
3667 BOOL WINAPI
GetLayeredWindowAttributes( HWND hwnd
, COLORREF
*key
, BYTE
*alpha
, DWORD
*flags
)
3671 SERVER_START_REQ( get_window_layered_info
)
3673 req
->handle
= wine_server_user_handle( hwnd
);
3674 if ((ret
= !wine_server_call_err( req
)))
3676 if (key
) *key
= reply
->color_key
;
3677 if (alpha
) *alpha
= reply
->alpha
;
3678 if (flags
) *flags
= reply
->flags
;
3687 /*****************************************************************************
3688 * UpdateLayeredWindowIndirect (USER32.@)
3690 BOOL WINAPI
UpdateLayeredWindowIndirect( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
)
3692 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
;
3693 RECT window_rect
, client_rect
;
3697 info
->cbSize
!= sizeof(*info
) ||
3698 info
->dwFlags
& ~(ULW_COLORKEY
| ULW_ALPHA
| ULW_OPAQUE
| ULW_EX_NORESIZE
) ||
3699 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) ||
3700 GetLayeredWindowAttributes( hwnd
, NULL
, NULL
, NULL
))
3702 SetLastError( ERROR_INVALID_PARAMETER
);
3706 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
3710 offset
.cx
= info
->pptDst
->x
- window_rect
.left
;
3711 offset
.cy
= info
->pptDst
->y
- window_rect
.top
;
3712 OffsetRect( &client_rect
, offset
.cx
, offset
.cy
);
3713 OffsetRect( &window_rect
, offset
.cx
, offset
.cy
);
3714 flags
&= ~SWP_NOMOVE
;
3718 offset
.cx
= info
->psize
->cx
- (window_rect
.right
- window_rect
.left
);
3719 offset
.cy
= info
->psize
->cy
- (window_rect
.bottom
- window_rect
.top
);
3720 if (info
->psize
->cx
<= 0 || info
->psize
->cy
<= 0)
3722 SetLastError( ERROR_INVALID_PARAMETER
);
3725 if ((info
->dwFlags
& ULW_EX_NORESIZE
) && (offset
.cx
|| offset
.cy
))
3727 SetLastError( ERROR_INCORRECT_SIZE
);
3730 client_rect
.right
+= offset
.cx
;
3731 client_rect
.bottom
+= offset
.cy
;
3732 window_rect
.right
+= offset
.cx
;
3733 window_rect
.bottom
+= offset
.cy
;
3734 flags
&= ~SWP_NOSIZE
;
3737 TRACE( "window %p win %s client %s\n", hwnd
,
3738 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
) );
3740 if (!USER_Driver
->pUpdateLayeredWindow( hwnd
, info
, &window_rect
)) return FALSE
;
3742 set_window_pos( hwnd
, 0, flags
, &window_rect
, &client_rect
, NULL
);
3747 /*****************************************************************************
3748 * UpdateLayeredWindow (USER32.@)
3750 BOOL WINAPI
UpdateLayeredWindow( HWND hwnd
, HDC hdcDst
, POINT
*pptDst
, SIZE
*psize
,
3751 HDC hdcSrc
, POINT
*pptSrc
, COLORREF crKey
, BLENDFUNCTION
*pblend
,
3754 UPDATELAYEREDWINDOWINFO info
;
3756 if (flags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
3758 SetLastError( ERROR_INVALID_PARAMETER
);
3761 info
.cbSize
= sizeof(info
);
3762 info
.hdcDst
= hdcDst
;
3763 info
.pptDst
= pptDst
;
3765 info
.hdcSrc
= hdcSrc
;
3766 info
.pptSrc
= pptSrc
;
3768 info
.pblend
= pblend
;
3769 info
.dwFlags
= flags
;
3770 info
.prcDirty
= NULL
;
3771 return UpdateLayeredWindowIndirect( hwnd
, &info
);
3775 /******************************************************************************
3776 * GetProcessDefaultLayout [USER32.@]
3778 * Gets the default layout for parentless windows.
3780 BOOL WINAPI
GetProcessDefaultLayout( DWORD
*layout
)
3784 SetLastError( ERROR_NOACCESS
);
3787 if (process_layout
== ~0u)
3789 static const WCHAR translationW
[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
3790 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
3791 static const WCHAR filedescW
[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
3792 '\\','%','0','4','x','%','0','4','x',
3793 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0 };
3794 WCHAR
*str
, buffer
[MAX_PATH
];
3795 DWORD i
, len
, version_layout
= 0;
3796 DWORD user_lang
= GetUserDefaultLangID();
3800 GetModuleFileNameW( 0, buffer
, MAX_PATH
);
3801 if (!(len
= GetFileVersionInfoSizeW( buffer
, NULL
))) goto done
;
3802 if (!(data
= HeapAlloc( GetProcessHeap(), 0, len
))) goto done
;
3803 if (!GetFileVersionInfoW( buffer
, 0, len
, data
)) goto done
;
3804 if (!VerQueryValueW( data
, translationW
, (void **)&languages
, &len
) || !len
) goto done
;
3806 len
/= sizeof(DWORD
);
3807 for (i
= 0; i
< len
; i
++) if (LOWORD(languages
[i
]) == user_lang
) break;
3808 if (i
== len
) /* try neutral language */
3809 for (i
= 0; i
< len
; i
++)
3810 if (LOWORD(languages
[i
]) == MAKELANGID( PRIMARYLANGID(user_lang
), SUBLANG_NEUTRAL
)) break;
3811 if (i
== len
) i
= 0; /* default to the first one */
3813 sprintfW( buffer
, filedescW
, LOWORD(languages
[i
]), HIWORD(languages
[i
]) );
3814 if (!VerQueryValueW( data
, buffer
, (void **)&str
, &len
)) goto done
;
3815 TRACE( "found description %s\n", debugstr_w( str
));
3816 if (str
[0] == 0x200e && str
[1] == 0x200e) version_layout
= LAYOUT_RTL
;
3819 HeapFree( GetProcessHeap(), 0, data
);
3820 process_layout
= version_layout
;
3822 *layout
= process_layout
;
3827 /******************************************************************************
3828 * SetProcessDefaultLayout [USER32.@]
3830 * Sets the default layout for parentless windows.
3832 BOOL WINAPI
SetProcessDefaultLayout( DWORD layout
)
3834 process_layout
= layout
;
3839 /* 64bit versions */
3841 #ifdef GetWindowLongPtrW
3842 #undef GetWindowLongPtrW
3845 #ifdef GetWindowLongPtrA
3846 #undef GetWindowLongPtrA
3849 #ifdef SetWindowLongPtrW
3850 #undef SetWindowLongPtrW
3853 #ifdef SetWindowLongPtrA
3854 #undef SetWindowLongPtrA
3857 /*****************************************************************************
3858 * GetWindowLongPtrW (USER32.@)
3860 LONG_PTR WINAPI
GetWindowLongPtrW( HWND hwnd
, INT offset
)
3862 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), TRUE
);
3865 /*****************************************************************************
3866 * GetWindowLongPtrA (USER32.@)
3868 LONG_PTR WINAPI
GetWindowLongPtrA( HWND hwnd
, INT offset
)
3870 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), FALSE
);
3873 /*****************************************************************************
3874 * SetWindowLongPtrW (USER32.@)
3876 LONG_PTR WINAPI
SetWindowLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
3878 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, TRUE
);
3881 /*****************************************************************************
3882 * SetWindowLongPtrA (USER32.@)
3884 LONG_PTR WINAPI
SetWindowLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
3886 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, FALSE
);
3889 /*****************************************************************************
3890 * RegisterTouchWindow (USER32.@)
3892 BOOL WINAPI
RegisterTouchWindow(HWND hwnd
, ULONG flags
)
3894 FIXME("(%p %08x): stub\n", hwnd
, flags
);
3895 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);