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"
32 #include "wine/server.h"
33 #include "wine/unicode.h"
35 #include "user_private.h"
38 #include "wine/gdi_driver.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win
);
43 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
44 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
46 static DWORD process_layout
= ~0u;
48 static struct list window_surfaces
= LIST_INIT( window_surfaces
);
50 static CRITICAL_SECTION surfaces_section
;
51 static CRITICAL_SECTION_DEBUG critsect_debug
=
53 0, 0, &surfaces_section
,
54 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
55 0, 0, { (DWORD_PTR
)(__FILE__
": surfaces_section") }
57 static CRITICAL_SECTION surfaces_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
59 /**********************************************************************/
61 /* helper for Get/SetWindowLong */
62 static inline LONG_PTR
get_win_data( const void *ptr
, UINT size
)
64 if (size
== sizeof(WORD
))
67 memcpy( &ret
, ptr
, sizeof(ret
) );
70 else if (size
== sizeof(DWORD
))
73 memcpy( &ret
, ptr
, sizeof(ret
) );
79 memcpy( &ret
, ptr
, sizeof(ret
) );
84 /* helper for Get/SetWindowLong */
85 static inline void set_win_data( void *ptr
, LONG_PTR val
, UINT size
)
87 if (size
== sizeof(WORD
))
90 memcpy( ptr
, &newval
, sizeof(newval
) );
92 else if (size
== sizeof(DWORD
))
95 memcpy( ptr
, &newval
, sizeof(newval
) );
99 memcpy( ptr
, &val
, sizeof(val
) );
104 static void *user_handles
[NB_USER_HANDLES
];
106 /***********************************************************************
109 HANDLE
alloc_user_handle( struct user_object
*ptr
, enum user_obj_type type
)
113 SERVER_START_REQ( alloc_user_handle
)
115 if (!wine_server_call_err( req
)) handle
= wine_server_ptr_handle( reply
->handle
);
121 UINT index
= USER_HANDLE_TO_INDEX( handle
);
123 assert( index
< NB_USER_HANDLES
);
124 ptr
->handle
= handle
;
126 InterlockedExchangePointer( &user_handles
[index
], ptr
);
132 /***********************************************************************
133 * get_user_handle_ptr
135 void *get_user_handle_ptr( HANDLE handle
, enum user_obj_type type
)
137 struct user_object
*ptr
;
138 WORD index
= USER_HANDLE_TO_INDEX( handle
);
140 if (index
>= NB_USER_HANDLES
) return NULL
;
143 if ((ptr
= user_handles
[index
]))
145 if (ptr
->type
== type
&&
146 ((UINT
)(UINT_PTR
)ptr
->handle
== (UINT
)(UINT_PTR
)handle
||
147 !HIWORD(handle
) || HIWORD(handle
) == 0xffff))
151 else ptr
= OBJ_OTHER_PROCESS
;
157 /***********************************************************************
158 * release_user_handle_ptr
160 void release_user_handle_ptr( void *ptr
)
162 assert( ptr
&& ptr
!= OBJ_OTHER_PROCESS
);
167 /***********************************************************************
170 void *free_user_handle( HANDLE handle
, enum user_obj_type type
)
172 struct user_object
*ptr
;
173 WORD index
= USER_HANDLE_TO_INDEX( handle
);
175 if ((ptr
= get_user_handle_ptr( handle
, type
)) && ptr
!= OBJ_OTHER_PROCESS
)
177 SERVER_START_REQ( free_user_handle
)
179 req
->handle
= wine_server_user_handle( handle
);
180 if (wine_server_call( req
)) ptr
= NULL
;
181 else InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
190 /***********************************************************************
191 * create_window_handle
193 * Create a window handle with the server.
195 static WND
*create_window_handle( HWND parent
, HWND owner
, LPCWSTR name
,
196 HINSTANCE instance
, BOOL unicode
)
200 HWND handle
= 0, full_parent
= 0, full_owner
= 0;
201 struct tagCLASS
*class = NULL
;
204 SERVER_START_REQ( create_window
)
206 req
->parent
= wine_server_user_handle( parent
);
207 req
->owner
= wine_server_user_handle( owner
);
208 req
->instance
= wine_server_client_ptr( instance
);
209 if (!(req
->atom
= get_int_atom_value( name
)) && name
)
210 wine_server_add_data( req
, name
, strlenW(name
)*sizeof(WCHAR
) );
211 if (!wine_server_call_err( req
))
213 handle
= wine_server_ptr_handle( reply
->handle
);
214 full_parent
= wine_server_ptr_handle( reply
->parent
);
215 full_owner
= wine_server_ptr_handle( reply
->owner
);
216 extra_bytes
= reply
->extra
;
217 class = wine_server_get_ptr( reply
->class_ptr
);
224 WARN( "error %d creating window\n", GetLastError() );
228 if (!(win
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
229 sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
231 SERVER_START_REQ( destroy_window
)
233 req
->handle
= wine_server_user_handle( handle
);
234 wine_server_call( req
);
237 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
241 if (!parent
) /* if parent is 0 we don't have a desktop window yet */
243 struct user_thread_info
*thread_info
= get_user_thread_info();
245 if (name
== (LPCWSTR
)DESKTOP_CLASS_ATOM
)
247 if (!thread_info
->top_window
) thread_info
->top_window
= full_parent
? full_parent
: handle
;
248 else assert( full_parent
== thread_info
->top_window
);
249 if (full_parent
&& !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
250 ERR( "failed to create desktop window\n" );
252 else /* HWND_MESSAGE parent */
254 if (!thread_info
->msg_window
&& !full_parent
) thread_info
->msg_window
= handle
;
260 index
= USER_HANDLE_TO_INDEX(handle
);
261 assert( index
< NB_USER_HANDLES
);
262 win
->obj
.handle
= handle
;
263 win
->obj
.type
= USER_WINDOW
;
264 win
->parent
= full_parent
;
265 win
->owner
= full_owner
;
267 win
->winproc
= get_class_winproc( class );
268 win
->cbWndExtra
= extra_bytes
;
269 InterlockedExchangePointer( &user_handles
[index
], win
);
270 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
275 /***********************************************************************
278 * Free a window handle.
280 static void free_window_handle( HWND hwnd
)
282 struct user_object
*ptr
;
283 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
285 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) && ptr
!= OBJ_OTHER_PROCESS
)
287 SERVER_START_REQ( destroy_window
)
289 req
->handle
= wine_server_user_handle( hwnd
);
290 if (wine_server_call_err( req
)) ptr
= NULL
;
291 else InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
295 HeapFree( GetProcessHeap(), 0, ptr
);
300 /*******************************************************************
301 * list_window_children
303 * Build an array of the children of a given window. The array must be
304 * freed with HeapFree. Returns NULL when no windows are found.
306 static HWND
*list_window_children( HDESK desktop
, HWND hwnd
, LPCWSTR
class, DWORD tid
)
310 ATOM atom
= get_int_atom_value( class );
312 /* empty class is not the same as NULL class */
313 if (!atom
&& class && !class[0]) return NULL
;
319 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
321 SERVER_START_REQ( get_window_children
)
323 req
->desktop
= wine_server_obj_handle( desktop
);
324 req
->parent
= wine_server_user_handle( hwnd
);
327 if (!atom
&& class) wine_server_add_data( req
, class, strlenW(class)*sizeof(WCHAR
) );
328 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
329 if (!wine_server_call( req
)) count
= reply
->count
;
332 if (count
&& count
< size
)
334 /* start from the end since HWND is potentially larger than user_handle_t */
335 for (i
= count
- 1; i
>= 0; i
--)
336 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
340 HeapFree( GetProcessHeap(), 0, list
);
342 size
= count
+ 1; /* restart with a large enough buffer */
348 /*******************************************************************
349 * list_window_parents
351 * Build an array of all parents of a given window, starting with
352 * the immediate parent. The array must be freed with HeapFree.
354 static HWND
*list_window_parents( HWND hwnd
)
358 int i
, pos
= 0, size
= 16, count
;
360 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
365 if (!(win
= WIN_GetPtr( current
))) goto empty
;
366 if (win
== WND_OTHER_PROCESS
) break; /* need to do it the hard way */
367 if (win
== WND_DESKTOP
)
369 if (!pos
) goto empty
;
373 list
[pos
] = current
= win
->parent
;
374 WIN_ReleasePtr( win
);
375 if (!current
) return list
;
376 if (++pos
== size
- 1)
378 /* need to grow the list */
379 HWND
*new_list
= HeapReAlloc( GetProcessHeap(), 0, list
, (size
+16) * sizeof(HWND
) );
380 if (!new_list
) goto empty
;
386 /* at least one parent belongs to another process, have to query the server */
391 SERVER_START_REQ( get_window_parents
)
393 req
->handle
= wine_server_user_handle( hwnd
);
394 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
395 if (!wine_server_call( req
)) count
= reply
->count
;
398 if (!count
) goto empty
;
401 /* start from the end since HWND is potentially larger than user_handle_t */
402 for (i
= count
- 1; i
>= 0; i
--)
403 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
407 HeapFree( GetProcessHeap(), 0, list
);
409 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
413 HeapFree( GetProcessHeap(), 0, list
);
418 /*******************************************************************
421 static void send_parent_notify( HWND hwnd
, UINT msg
)
423 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
424 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
))
426 HWND parent
= GetParent(hwnd
);
427 if (parent
&& parent
!= GetDesktopWindow())
428 SendMessageW( parent
, WM_PARENTNOTIFY
,
429 MAKEWPARAM( msg
, GetWindowLongPtrW( hwnd
, GWLP_ID
)), (LPARAM
)hwnd
);
434 /*******************************************************************
435 * update_window_state
437 * Trigger an update of the window's driver state and surface.
439 static void update_window_state( HWND hwnd
)
441 RECT window_rect
, client_rect
, valid_rects
[2];
443 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
444 valid_rects
[0] = valid_rects
[1] = client_rect
;
445 set_window_pos( hwnd
, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
|
446 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
,
447 &window_rect
, &client_rect
, valid_rects
);
451 /*******************************************************************
452 * get_server_window_text
454 * Retrieve the window text from the server.
456 static void get_server_window_text( HWND hwnd
, LPWSTR text
, INT count
)
460 SERVER_START_REQ( get_window_text
)
462 req
->handle
= wine_server_user_handle( hwnd
);
463 wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
464 if (!wine_server_call_err( req
)) len
= wine_server_reply_size(reply
);
467 text
[len
/ sizeof(WCHAR
)] = 0;
471 /*******************************************************************
472 * get_hwnd_message_parent
474 * Return the parent for HWND_MESSAGE windows.
476 HWND
get_hwnd_message_parent(void)
478 struct user_thread_info
*thread_info
= get_user_thread_info();
480 if (!thread_info
->msg_window
) GetDesktopWindow(); /* trigger creation */
481 return thread_info
->msg_window
;
485 /*******************************************************************
488 * Check if window is the desktop or the HWND_MESSAGE top parent.
490 BOOL
is_desktop_window( HWND hwnd
)
492 struct user_thread_info
*thread_info
= get_user_thread_info();
494 if (!hwnd
) return FALSE
;
495 if (hwnd
== thread_info
->top_window
) return TRUE
;
496 if (hwnd
== thread_info
->msg_window
) return TRUE
;
498 if (!HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff)
500 if (LOWORD(thread_info
->top_window
) == LOWORD(hwnd
)) return TRUE
;
501 if (LOWORD(thread_info
->msg_window
) == LOWORD(hwnd
)) return TRUE
;
507 /*******************************************************************
508 * Dummy window surface for windows that shouldn't get painted.
511 static void dummy_surface_lock( struct window_surface
*window_surface
)
516 static void dummy_surface_unlock( struct window_surface
*window_surface
)
521 static void *dummy_surface_get_bitmap_info( struct window_surface
*window_surface
, BITMAPINFO
*info
)
523 static DWORD dummy_data
;
525 info
->bmiHeader
.biSize
= sizeof( info
->bmiHeader
);
526 info
->bmiHeader
.biWidth
= dummy_surface
.rect
.right
;
527 info
->bmiHeader
.biHeight
= dummy_surface
.rect
.bottom
;
528 info
->bmiHeader
.biPlanes
= 1;
529 info
->bmiHeader
.biBitCount
= 32;
530 info
->bmiHeader
.biCompression
= BI_RGB
;
531 info
->bmiHeader
.biSizeImage
= 0;
532 info
->bmiHeader
.biXPelsPerMeter
= 0;
533 info
->bmiHeader
.biYPelsPerMeter
= 0;
534 info
->bmiHeader
.biClrUsed
= 0;
535 info
->bmiHeader
.biClrImportant
= 0;
539 static RECT
*dummy_surface_get_bounds( struct window_surface
*window_surface
)
541 static RECT dummy_bounds
;
542 return &dummy_bounds
;
545 static void dummy_surface_set_region( struct window_surface
*window_surface
, HRGN region
)
550 static void dummy_surface_flush( struct window_surface
*window_surface
)
555 static void dummy_surface_destroy( struct window_surface
*window_surface
)
560 static const struct window_surface_funcs dummy_surface_funcs
=
563 dummy_surface_unlock
,
564 dummy_surface_get_bitmap_info
,
565 dummy_surface_get_bounds
,
566 dummy_surface_set_region
,
568 dummy_surface_destroy
571 struct window_surface dummy_surface
= { &dummy_surface_funcs
, { NULL
, NULL
}, 1, { 0, 0, 1, 1 } };
574 /*******************************************************************
575 * register_window_surface
577 * Register a window surface in the global list, possibly replacing another one.
579 void register_window_surface( struct window_surface
*old
, struct window_surface
*new )
581 if (old
== new) return;
582 EnterCriticalSection( &surfaces_section
);
583 if (old
&& old
!= &dummy_surface
) list_remove( &old
->entry
);
584 if (new && new != &dummy_surface
) list_add_tail( &window_surfaces
, &new->entry
);
585 LeaveCriticalSection( &surfaces_section
);
589 /*******************************************************************
590 * flush_window_surfaces
592 * Flush pending output from all window surfaces.
594 void flush_window_surfaces( BOOL idle
)
596 static DWORD last_idle
;
598 struct window_surface
*surface
;
600 EnterCriticalSection( &surfaces_section
);
601 now
= GetTickCount();
602 if (idle
) last_idle
= now
;
603 /* if not idle, we only flush if there's evidence that the app never goes idle */
604 else if ((int)(now
- last_idle
) < 50) goto done
;
606 LIST_FOR_EACH_ENTRY( surface
, &window_surfaces
, struct window_surface
, entry
)
607 surface
->funcs
->flush( surface
);
609 LeaveCriticalSection( &surfaces_section
);
613 /***********************************************************************
616 * Return a pointer to the WND structure if local to the process,
617 * or WND_OTHER_PROCESS if handle may be valid in other process.
618 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
620 WND
*WIN_GetPtr( HWND hwnd
)
624 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) == WND_OTHER_PROCESS
)
626 if (is_desktop_window( hwnd
)) ptr
= WND_DESKTOP
;
632 /***********************************************************************
633 * WIN_IsCurrentProcess
635 * Check whether a given window belongs to the current process (and return the full handle).
637 HWND
WIN_IsCurrentProcess( HWND hwnd
)
642 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
643 ret
= ptr
->obj
.handle
;
644 WIN_ReleasePtr( ptr
);
649 /***********************************************************************
650 * WIN_IsCurrentThread
652 * Check whether a given window belongs to the current thread (and return the full handle).
654 HWND
WIN_IsCurrentThread( HWND hwnd
)
659 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
660 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->obj
.handle
;
661 WIN_ReleasePtr( ptr
);
666 /***********************************************************************
669 * Convert a possibly truncated window handle to a full 32-bit handle.
671 HWND
WIN_GetFullHandle( HWND hwnd
)
675 if (!hwnd
|| (ULONG_PTR
)hwnd
>> 16) return hwnd
;
676 if (LOWORD(hwnd
) <= 1 || LOWORD(hwnd
) == 0xffff) return hwnd
;
677 /* do sign extension for -2 and -3 */
678 if (LOWORD(hwnd
) >= (WORD
)-3) return (HWND
)(LONG_PTR
)(INT16
)LOWORD(hwnd
);
680 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
682 if (ptr
== WND_DESKTOP
)
684 if (LOWORD(hwnd
) == LOWORD(GetDesktopWindow())) return GetDesktopWindow();
685 else return get_hwnd_message_parent();
688 if (ptr
!= WND_OTHER_PROCESS
)
690 hwnd
= ptr
->obj
.handle
;
691 WIN_ReleasePtr( ptr
);
693 else /* may belong to another process */
695 SERVER_START_REQ( get_window_info
)
697 req
->handle
= wine_server_user_handle( hwnd
);
698 if (!wine_server_call_err( req
)) hwnd
= wine_server_ptr_handle( reply
->full_handle
);
706 /***********************************************************************
709 * Change the owner of a window.
711 HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
713 WND
*win
= WIN_GetPtr( hwnd
);
716 if (!win
|| win
== WND_DESKTOP
) return 0;
717 if (win
== WND_OTHER_PROCESS
)
719 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
722 SERVER_START_REQ( set_window_owner
)
724 req
->handle
= wine_server_user_handle( hwnd
);
725 req
->owner
= wine_server_user_handle( owner
);
726 if (!wine_server_call( req
))
728 win
->owner
= wine_server_ptr_handle( reply
->full_owner
);
729 ret
= wine_server_ptr_handle( reply
->prev_owner
);
733 WIN_ReleasePtr( win
);
738 /***********************************************************************
741 * Change the style of a window.
743 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
745 BOOL ok
, made_visible
= FALSE
;
747 WND
*win
= WIN_GetPtr( hwnd
);
749 if (!win
|| win
== WND_DESKTOP
) return 0;
750 if (win
== WND_OTHER_PROCESS
)
753 ERR( "cannot set style %x/%x on other process window %p\n",
754 set_bits
, clear_bits
, hwnd
);
757 style
.styleOld
= win
->dwStyle
;
758 style
.styleNew
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
759 if (style
.styleNew
== style
.styleOld
)
761 WIN_ReleasePtr( win
);
762 return style
.styleNew
;
764 SERVER_START_REQ( set_window_info
)
766 req
->handle
= wine_server_user_handle( hwnd
);
767 req
->flags
= SET_WIN_STYLE
;
768 req
->style
= style
.styleNew
;
769 req
->extra_offset
= -1;
770 if ((ok
= !wine_server_call( req
)))
772 style
.styleOld
= reply
->old_style
;
773 win
->dwStyle
= style
.styleNew
;
778 if (ok
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
))
780 made_visible
= (style
.styleNew
& WS_VISIBLE
) != 0;
781 invalidate_dce( win
, NULL
);
783 WIN_ReleasePtr( win
);
787 USER_Driver
->pSetWindowStyle( hwnd
, GWL_STYLE
, &style
);
788 if (made_visible
) update_window_state( hwnd
);
790 return style
.styleOld
;
794 /***********************************************************************
797 * Get the window and client rectangles.
799 BOOL
WIN_GetRectangles( HWND hwnd
, enum coords_relative relative
, RECT
*rectWindow
, RECT
*rectClient
)
801 WND
*win
= WIN_GetPtr( hwnd
);
806 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
809 if (win
== WND_DESKTOP
)
812 rect
.left
= rect
.top
= 0;
813 if (hwnd
== get_hwnd_message_parent())
820 rect
.right
= GetSystemMetrics(SM_CXSCREEN
);
821 rect
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
823 if (rectWindow
) *rectWindow
= rect
;
824 if (rectClient
) *rectClient
= rect
;
827 if (win
!= WND_OTHER_PROCESS
)
829 RECT window_rect
= win
->rectWindow
, client_rect
= win
->rectClient
;
834 OffsetRect( &window_rect
, -win
->rectClient
.left
, -win
->rectClient
.top
);
835 OffsetRect( &client_rect
, -win
->rectClient
.left
, -win
->rectClient
.top
);
836 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
837 mirror_rect( &win
->rectClient
, &window_rect
);
840 OffsetRect( &window_rect
, -win
->rectWindow
.left
, -win
->rectWindow
.top
);
841 OffsetRect( &client_rect
, -win
->rectWindow
.left
, -win
->rectWindow
.top
);
842 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
843 mirror_rect( &win
->rectWindow
, &client_rect
);
848 WND
*parent
= WIN_GetPtr( win
->parent
);
849 if (parent
== WND_DESKTOP
) break;
850 if (!parent
|| parent
== WND_OTHER_PROCESS
)
852 WIN_ReleasePtr( win
);
855 if (parent
->flags
& WIN_CHILDREN_MOVED
)
857 WIN_ReleasePtr( parent
);
858 WIN_ReleasePtr( win
);
861 if (parent
->dwExStyle
& WS_EX_LAYOUTRTL
)
863 mirror_rect( &parent
->rectClient
, &window_rect
);
864 mirror_rect( &parent
->rectClient
, &client_rect
);
866 WIN_ReleasePtr( parent
);
872 WND
*parent
= WIN_GetPtr( win
->parent
);
873 if (parent
== WND_DESKTOP
) break;
874 if (!parent
|| parent
== WND_OTHER_PROCESS
)
876 WIN_ReleasePtr( win
);
879 WIN_ReleasePtr( win
);
880 if (parent
->flags
& WIN_CHILDREN_MOVED
)
882 WIN_ReleasePtr( parent
);
888 OffsetRect( &window_rect
, win
->rectClient
.left
, win
->rectClient
.top
);
889 OffsetRect( &client_rect
, win
->rectClient
.left
, win
->rectClient
.top
);
894 if (rectWindow
) *rectWindow
= window_rect
;
895 if (rectClient
) *rectClient
= client_rect
;
896 WIN_ReleasePtr( win
);
901 SERVER_START_REQ( get_window_rectangles
)
903 req
->handle
= wine_server_user_handle( hwnd
);
904 req
->relative
= relative
;
905 if ((ret
= !wine_server_call_err( req
)))
909 rectWindow
->left
= reply
->window
.left
;
910 rectWindow
->top
= reply
->window
.top
;
911 rectWindow
->right
= reply
->window
.right
;
912 rectWindow
->bottom
= reply
->window
.bottom
;
916 rectClient
->left
= reply
->client
.left
;
917 rectClient
->top
= reply
->client
.top
;
918 rectClient
->right
= reply
->client
.right
;
919 rectClient
->bottom
= reply
->client
.bottom
;
928 /***********************************************************************
931 * Destroy storage associated to a window. "Internals" p.358
933 LRESULT
WIN_DestroyWindow( HWND hwnd
)
937 HMENU menu
= 0, sys_menu
;
939 struct window_surface
*surface
;
941 TRACE("%p\n", hwnd
);
943 /* free child windows */
944 if ((list
= WIN_ListChildren( hwnd
)))
947 for (i
= 0; list
[i
]; i
++)
949 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
950 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
952 HeapFree( GetProcessHeap(), 0, list
);
955 /* Unlink now so we won't bother with the children later on */
956 SERVER_START_REQ( set_parent
)
958 req
->handle
= wine_server_user_handle( hwnd
);
960 wine_server_call( req
);
965 * Send the WM_NCDESTROY to the window being destroyed.
967 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
969 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
971 /* free resources associated with the window */
973 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
974 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
975 menu
= (HMENU
)wndPtr
->wIDmenu
;
976 sys_menu
= wndPtr
->hSysMenu
;
977 free_dce( wndPtr
->dce
, hwnd
);
979 icon_title
= wndPtr
->icon_title
;
980 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
982 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
983 wndPtr
->pScroll
= NULL
;
984 DestroyIcon( wndPtr
->hIconSmall2
);
985 surface
= wndPtr
->surface
;
986 wndPtr
->surface
= NULL
;
987 WIN_ReleasePtr( wndPtr
);
989 if (icon_title
) DestroyWindow( icon_title
);
990 if (menu
) DestroyMenu( menu
);
991 if (sys_menu
) DestroyMenu( sys_menu
);
994 register_window_surface( surface
, NULL
);
995 window_surface_release( surface
);
998 USER_Driver
->pDestroyWindow( hwnd
);
1000 free_window_handle( hwnd
);
1005 /***********************************************************************
1006 * destroy_thread_window
1008 * Destroy a window upon exit of its thread.
1010 static void destroy_thread_window( HWND hwnd
)
1014 HMENU menu
= 0, sys_menu
= 0;
1015 struct window_surface
*surface
= NULL
;
1018 /* free child windows */
1020 if ((list
= WIN_ListChildren( hwnd
)))
1023 for (i
= 0; list
[i
]; i
++)
1025 if (WIN_IsCurrentThread( list
[i
] )) destroy_thread_window( list
[i
] );
1026 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
1028 HeapFree( GetProcessHeap(), 0, list
);
1031 /* destroy the client-side storage */
1033 index
= USER_HANDLE_TO_INDEX(hwnd
);
1034 if (index
>= NB_USER_HANDLES
) return;
1036 if ((wndPtr
= user_handles
[index
]))
1038 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
) menu
= (HMENU
)wndPtr
->wIDmenu
;
1039 sys_menu
= wndPtr
->hSysMenu
;
1040 free_dce( wndPtr
->dce
, hwnd
);
1041 surface
= wndPtr
->surface
;
1042 wndPtr
->surface
= NULL
;
1043 InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, wndPtr
);
1047 HeapFree( GetProcessHeap(), 0, wndPtr
);
1048 if (menu
) DestroyMenu( menu
);
1049 if (sys_menu
) DestroyMenu( sys_menu
);
1052 register_window_surface( surface
, NULL
);
1053 window_surface_release( surface
);
1058 /***********************************************************************
1059 * destroy_thread_child_windows
1061 * Destroy child windows upon exit of its thread.
1063 static void destroy_thread_child_windows( HWND hwnd
)
1068 if (WIN_IsCurrentThread( hwnd
))
1070 destroy_thread_window( hwnd
);
1072 else if ((list
= WIN_ListChildren( hwnd
)))
1074 for (i
= 0; list
[i
]; i
++) destroy_thread_child_windows( list
[i
] );
1075 HeapFree( GetProcessHeap(), 0, list
);
1080 /***********************************************************************
1081 * WIN_DestroyThreadWindows
1083 * Destroy all children of 'wnd' owned by the current thread.
1085 void WIN_DestroyThreadWindows( HWND hwnd
)
1090 if (!(list
= WIN_ListChildren( hwnd
))) return;
1092 /* reset owners of top-level windows */
1093 for (i
= 0; list
[i
]; i
++)
1095 if (!WIN_IsCurrentThread( list
[i
] ))
1097 HWND owner
= GetWindow( list
[i
], GW_OWNER
);
1098 if (owner
&& WIN_IsCurrentThread( owner
)) WIN_SetOwner( list
[i
], 0 );
1102 for (i
= 0; list
[i
]; i
++) destroy_thread_child_windows( list
[i
] );
1103 HeapFree( GetProcessHeap(), 0, list
);
1107 /***********************************************************************
1108 * WIN_FixCoordinates
1110 * Fix the coordinates - Helper for WIN_CreateWindowEx.
1111 * returns default show mode in sw.
1113 static void WIN_FixCoordinates( CREATESTRUCTW
*cs
, INT
*sw
)
1115 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1118 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1122 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
1123 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= ULongToHandle(id
);
1125 TRACE("MDI child id %04x\n", id
);
1128 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
1130 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1132 if (IS_DEFAULT(cs
->x
))
1137 if (IS_DEFAULT(cs
->cx
) || !cs
->cx
) cs
->cx
= pos
[1].x
;
1138 if (IS_DEFAULT(cs
->cy
) || !cs
->cy
) cs
->cy
= pos
[1].y
;
1142 if (IS_DEFAULT(cs
->x
)) cs
->x
= cs
->y
= 0;
1143 if (IS_DEFAULT(cs
->cx
)) cs
->cx
= cs
->cy
= 0;
1146 else /* overlapped window */
1149 MONITORINFO mon_info
;
1152 if (!IS_DEFAULT(cs
->x
) && !IS_DEFAULT(cs
->cx
) && !IS_DEFAULT(cs
->cy
)) return;
1154 monitor
= MonitorFromWindow( cs
->hwndParent
, MONITOR_DEFAULTTOPRIMARY
);
1155 mon_info
.cbSize
= sizeof(mon_info
);
1156 GetMonitorInfoW( monitor
, &mon_info
);
1157 GetStartupInfoW( &info
);
1159 if (IS_DEFAULT(cs
->x
))
1161 if (!IS_DEFAULT(cs
->y
)) *sw
= cs
->y
;
1162 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: mon_info
.rcWork
.left
;
1163 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: mon_info
.rcWork
.top
;
1166 if (IS_DEFAULT(cs
->cx
))
1168 if (info
.dwFlags
& STARTF_USESIZE
)
1170 cs
->cx
= info
.dwXSize
;
1171 cs
->cy
= info
.dwYSize
;
1175 cs
->cx
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) * 3 / 4 - cs
->x
;
1176 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1179 /* neither x nor cx are default. Check the y values .
1180 * In the trace we see Outlook and Outlook Express using
1181 * cy set to CW_USEDEFAULT when opening the address book.
1183 else if (IS_DEFAULT(cs
->cy
))
1185 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
1186 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1192 /***********************************************************************
1193 * dump_window_styles
1195 static void dump_window_styles( DWORD style
, DWORD exstyle
)
1198 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
1199 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
1200 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
1201 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
1202 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
1203 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
1204 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
1205 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
1206 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
1209 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
1210 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
1212 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
1213 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
1214 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
1215 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
1216 if (style
& WS_CHILD
)
1218 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
1219 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
1223 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
1224 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
1227 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
1228 #define DUMPED_STYLES \
1229 ((DWORD)(WS_POPUP | \
1248 if(style
& ~DUMPED_STYLES
) TRACE(" %08x", style
& ~DUMPED_STYLES
);
1250 #undef DUMPED_STYLES
1252 TRACE( "exstyle:" );
1253 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
1254 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
1255 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
1256 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
1257 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
1258 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
1259 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
1260 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
1261 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
1262 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
1263 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
1264 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
1265 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
1266 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
1267 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
1268 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
1269 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
1270 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
1271 if(exstyle
& WS_EX_LAYOUTRTL
) TRACE(" WS_EX_LAYOUTRTL");
1273 #define DUMPED_EX_STYLES \
1274 ((DWORD)(WS_EX_DLGMODALFRAME | \
1275 WS_EX_DRAGDETECT | \
1276 WS_EX_NOPARENTNOTIFY | \
1278 WS_EX_ACCEPTFILES | \
1279 WS_EX_TRANSPARENT | \
1281 WS_EX_TOOLWINDOW | \
1282 WS_EX_WINDOWEDGE | \
1283 WS_EX_CLIENTEDGE | \
1284 WS_EX_CONTEXTHELP | \
1286 WS_EX_RTLREADING | \
1287 WS_EX_LEFTSCROLLBAR | \
1288 WS_EX_CONTROLPARENT | \
1289 WS_EX_STATICEDGE | \
1294 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08x", exstyle
& ~DUMPED_EX_STYLES
);
1296 #undef DUMPED_EX_STYLES
1300 /***********************************************************************
1301 * WIN_CreateWindowEx
1303 * Implementation of CreateWindowEx().
1305 HWND
WIN_CreateWindowEx( CREATESTRUCTW
*cs
, LPCWSTR className
, HINSTANCE module
, BOOL unicode
)
1307 INT cx
, cy
, style
, sw
= SW_SHOW
;
1311 HWND hwnd
, parent
, owner
, top_child
= 0;
1312 MDICREATESTRUCTW mdi_cs
;
1313 CBT_CREATEWNDW cbtc
;
1316 TRACE("%s %s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
1317 unicode
? debugstr_w(cs
->lpszName
) : debugstr_a((LPCSTR
)cs
->lpszName
),
1318 debugstr_w(className
),
1319 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
1320 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
1321 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
1323 /* Fix the styles for MDI children */
1324 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1328 wndPtr
= WIN_GetPtr(cs
->hwndParent
);
1329 if (wndPtr
&& wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
1331 flags
= wndPtr
->flags
;
1332 WIN_ReleasePtr(wndPtr
);
1335 if (!(flags
& WIN_ISMDICLIENT
))
1337 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
1341 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
1342 * MDICREATESTRUCT members have the originally passed values.
1344 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
1345 * have the same layout.
1347 mdi_cs
.szClass
= cs
->lpszClass
;
1348 mdi_cs
.szTitle
= cs
->lpszName
;
1349 mdi_cs
.hOwner
= cs
->hInstance
;
1354 mdi_cs
.style
= cs
->style
;
1355 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
1357 cs
->lpCreateParams
= &mdi_cs
;
1359 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1361 if (cs
->style
& WS_POPUP
)
1363 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
1366 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
1370 cs
->style
&= ~WS_POPUP
;
1371 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1372 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1375 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
1379 /* Restore current maximized child */
1380 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
1382 TRACE("Restoring current maximized child %p\n", top_child
);
1383 if (cs
->style
& WS_MAXIMIZE
)
1385 /* if the new window is maximized don't bother repainting */
1386 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
1387 ShowWindow( top_child
, SW_SHOWNORMAL
);
1388 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
1390 else ShowWindow( top_child
, SW_SHOWNORMAL
);
1395 /* Find the parent window */
1397 parent
= cs
->hwndParent
;
1400 if (cs
->hwndParent
== HWND_MESSAGE
)
1402 cs
->hwndParent
= parent
= get_hwnd_message_parent();
1404 else if (cs
->hwndParent
)
1406 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1408 parent
= GetDesktopWindow();
1409 owner
= cs
->hwndParent
;
1413 DWORD parent_style
= GetWindowLongW( parent
, GWL_EXSTYLE
);
1414 if ((parent_style
& WS_EX_LAYOUTRTL
) && !(parent_style
& WS_EX_NOINHERITLAYOUT
))
1415 cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1420 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
1422 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1424 WARN("No parent for child window\n" );
1425 SetLastError(ERROR_TLW_WITH_WSCHILD
);
1426 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1429 /* are we creating the desktop or HWND_MESSAGE parent itself? */
1430 if (className
!= (LPCWSTR
)DESKTOP_CLASS_ATOM
&&
1431 (IS_INTRESOURCE(className
) || strcmpiW( className
, messageW
)))
1434 GetProcessDefaultLayout( &layout
);
1435 if (layout
& LAYOUT_RTL
) cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1436 parent
= GetDesktopWindow();
1440 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
1442 if ((cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1443 ((!(cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1444 (cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1445 cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1447 cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1449 /* Create the window structure */
1451 if (!(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1454 /* if it's a comctl32 class, GetClassInfo will load it, then we can retry */
1455 if (GetLastError() != ERROR_INVALID_HANDLE
||
1456 !GetClassInfoW( 0, className
, &wc
) ||
1457 !(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1460 hwnd
= wndPtr
->obj
.handle
;
1462 /* Fill the window structure */
1464 wndPtr
->tid
= GetCurrentThreadId();
1465 wndPtr
->hInstance
= cs
->hInstance
;
1466 wndPtr
->text
= NULL
;
1467 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
1468 wndPtr
->dwExStyle
= cs
->dwExStyle
;
1469 wndPtr
->wIDmenu
= 0;
1470 wndPtr
->helpContext
= 0;
1471 wndPtr
->pScroll
= NULL
;
1472 wndPtr
->userdata
= 0;
1474 wndPtr
->hIconSmall
= 0;
1475 wndPtr
->hIconSmall2
= 0;
1476 wndPtr
->hSysMenu
= 0;
1478 wndPtr
->min_pos
.x
= wndPtr
->min_pos
.y
= -1;
1479 wndPtr
->max_pos
.x
= wndPtr
->max_pos
.y
= -1;
1480 SetRect( &wndPtr
->normal_rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1482 if (wndPtr
->dwStyle
& WS_SYSMENU
) SetSystemMenu( hwnd
, 0 );
1485 * Correct the window styles.
1487 * It affects only the style loaded into the WIN structure.
1490 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1492 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1493 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1494 wndPtr
->dwStyle
|= WS_CAPTION
;
1497 /* WS_EX_WINDOWEDGE depends on some other styles */
1498 if (wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
)
1499 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1500 else if (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))
1502 if (!((wndPtr
->dwExStyle
& WS_EX_STATICEDGE
) &&
1503 (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
))))
1504 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1507 wndPtr
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1509 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1510 wndPtr
->flags
|= WIN_NEED_SIZE
;
1512 SERVER_START_REQ( set_window_info
)
1514 req
->handle
= wine_server_user_handle( hwnd
);
1515 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
| SET_WIN_UNICODE
;
1516 req
->style
= wndPtr
->dwStyle
;
1517 req
->ex_style
= wndPtr
->dwExStyle
;
1518 req
->instance
= wine_server_client_ptr( wndPtr
->hInstance
);
1519 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1520 req
->extra_offset
= -1;
1521 wine_server_call( req
);
1525 /* Set the window menu */
1527 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1531 if (!MENU_SetMenu(hwnd
, cs
->hMenu
))
1533 WIN_ReleasePtr( wndPtr
);
1534 free_window_handle( hwnd
);
1540 LPCWSTR menuName
= (LPCWSTR
)GetClassLongPtrW( hwnd
, GCLP_MENUNAME
);
1543 cs
->hMenu
= LoadMenuW( cs
->hInstance
, menuName
);
1544 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1548 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1550 /* call the WH_CBT hook */
1552 /* the window style passed to the hook must be the real window style,
1553 * rather than just the window style that the caller to CreateWindowEx
1554 * passed in, so we have to copy the original CREATESTRUCT and get the
1555 * the real style. */
1557 cbcs
.style
= wndPtr
->dwStyle
;
1559 cbtc
.hwndInsertAfter
= HWND_TOP
;
1560 WIN_ReleasePtr( wndPtr
);
1561 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
)) goto failed
;
1563 /* send the WM_GETMINMAXINFO message and fix the size if needed */
1567 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1569 POINT maxSize
, maxPos
, minTrack
, maxTrack
;
1570 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
1571 if (maxTrack
.x
< cx
) cx
= maxTrack
.x
;
1572 if (maxTrack
.y
< cy
) cy
= maxTrack
.y
;
1573 if (minTrack
.x
> cx
) cx
= minTrack
.x
;
1574 if (minTrack
.y
> cy
) cy
= minTrack
.y
;
1579 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cx
, cs
->y
+ cy
);
1580 /* check for wraparound */
1581 if (cs
->x
+ cx
< cs
->x
) rect
.right
= 0x7fffffff;
1582 if (cs
->y
+ cy
< cs
->y
) rect
.bottom
= 0x7fffffff;
1583 if (!set_window_pos( hwnd
, 0, SWP_NOZORDER
| SWP_NOACTIVATE
, &rect
, &rect
, NULL
)) goto failed
;
1585 /* send WM_NCCREATE */
1587 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd
, cs
->x
, cs
->y
, cx
, cy
);
1589 result
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1591 result
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1594 WARN( "%p: aborted by WM_NCCREATE\n", hwnd
);
1598 /* send WM_NCCALCSIZE */
1600 if (WIN_GetRectangles( hwnd
, COORDS_PARENT
, &rect
, NULL
))
1602 /* yes, even if the CBT hook was called with HWND_TOP */
1603 HWND insert_after
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1604 RECT client_rect
= rect
;
1606 /* the rectangle is in screen coords for WM_NCCALCSIZE when wparam is FALSE */
1607 MapWindowPoints( parent
, 0, (POINT
*)&client_rect
, 2 );
1608 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&client_rect
);
1609 MapWindowPoints( 0, parent
, (POINT
*)&client_rect
, 2 );
1610 set_window_pos( hwnd
, insert_after
, SWP_NOACTIVATE
, &rect
, &client_rect
, NULL
);
1614 /* send WM_CREATE */
1617 result
= SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1619 result
= SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1620 if (result
== -1) goto failed
;
1622 /* call the driver */
1624 if (!USER_Driver
->pCreateWindow( hwnd
)) goto failed
;
1626 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1628 /* send the size messages */
1630 if (!(wndPtr
= WIN_GetPtr( hwnd
)) ||
1631 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
1632 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
1634 WIN_ReleasePtr( wndPtr
);
1635 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &rect
);
1636 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1637 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1638 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1640 else WIN_ReleasePtr( wndPtr
);
1642 /* Show the window, maximizing or minimizing if needed */
1644 style
= WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1645 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1648 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1650 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1651 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1652 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1653 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
, newPos
.right
- newPos
.left
,
1654 newPos
.bottom
- newPos
.top
, swFlag
);
1657 /* Notify the parent window only */
1659 send_parent_notify( hwnd
, WM_CREATE
);
1660 if (!IsWindow( hwnd
)) return 0;
1662 if (cs
->style
& WS_VISIBLE
)
1664 if (cs
->style
& WS_MAXIMIZE
)
1666 else if (cs
->style
& WS_MINIMIZE
)
1667 sw
= SW_SHOWMINIMIZED
;
1669 ShowWindow( hwnd
, sw
);
1670 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1672 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1673 /* ShowWindow won't activate child windows */
1674 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1678 /* Call WH_SHELL hook */
1680 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1681 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1683 TRACE("created window %p\n", hwnd
);
1687 WIN_DestroyWindow( hwnd
);
1692 /***********************************************************************
1693 * CreateWindowExA (USER32.@)
1695 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1696 LPCSTR windowName
, DWORD style
, INT x
,
1697 INT y
, INT width
, INT height
,
1698 HWND parent
, HMENU menu
,
1699 HINSTANCE instance
, LPVOID data
)
1703 cs
.lpCreateParams
= data
;
1704 cs
.hInstance
= instance
;
1706 cs
.hwndParent
= parent
;
1712 cs
.lpszName
= windowName
;
1713 cs
.lpszClass
= className
;
1714 cs
.dwExStyle
= exStyle
;
1716 if (!IS_INTRESOURCE(className
))
1719 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) ))
1721 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, bufferW
, instance
, FALSE
);
1723 /* Note: we rely on the fact that CREATESTRUCTA and */
1724 /* CREATESTRUCTW have the same layout. */
1725 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, (LPCWSTR
)className
, instance
, FALSE
);
1729 /***********************************************************************
1730 * CreateWindowExW (USER32.@)
1732 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1733 LPCWSTR windowName
, DWORD style
, INT x
,
1734 INT y
, INT width
, INT height
,
1735 HWND parent
, HMENU menu
,
1736 HINSTANCE instance
, LPVOID data
)
1740 cs
.lpCreateParams
= data
;
1741 cs
.hInstance
= instance
;
1743 cs
.hwndParent
= parent
;
1749 cs
.lpszName
= windowName
;
1750 cs
.lpszClass
= className
;
1751 cs
.dwExStyle
= exStyle
;
1753 return wow_handlers
.create_window( &cs
, className
, instance
, TRUE
);
1757 /***********************************************************************
1758 * WIN_SendDestroyMsg
1760 static void WIN_SendDestroyMsg( HWND hwnd
)
1764 info
.cbSize
= sizeof(info
);
1765 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1767 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1768 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1772 * Send the WM_DESTROY to the window.
1774 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1777 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1778 * make sure that the window still exists when we come back.
1785 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1787 for (i
= 0; pWndArray
[i
]; i
++)
1789 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1791 HeapFree( GetProcessHeap(), 0, pWndArray
);
1794 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1798 /***********************************************************************
1799 * DestroyWindow (USER32.@)
1801 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1805 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || is_desktop_window( hwnd
))
1807 SetLastError( ERROR_ACCESS_DENIED
);
1811 TRACE("(%p)\n", hwnd
);
1815 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
1817 if (MENU_IsMenuActive() == hwnd
)
1820 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
1824 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1825 send_parent_notify( hwnd
, WM_DESTROY
);
1827 else if (!GetWindow( hwnd
, GW_OWNER
))
1829 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1830 /* FIXME: clean up palette - see "Internals" p.352 */
1833 if (!IsWindow(hwnd
)) return TRUE
;
1835 /* Hide the window */
1836 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
1838 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1840 ShowWindow( hwnd
, SW_HIDE
);
1842 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1843 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1846 if (!IsWindow(hwnd
)) return TRUE
;
1848 /* Recursively destroy owned windows */
1855 BOOL got_one
= FALSE
;
1856 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1859 for (i
= 0; list
[i
]; i
++)
1861 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1862 if (WIN_IsCurrentThread( list
[i
] ))
1864 DestroyWindow( list
[i
] );
1868 WIN_SetOwner( list
[i
], 0 );
1870 HeapFree( GetProcessHeap(), 0, list
);
1872 if (!got_one
) break;
1876 /* Send destroy messages */
1878 WIN_SendDestroyMsg( hwnd
);
1879 if (!IsWindow( hwnd
)) return TRUE
;
1881 CLIPBOARD_ReleaseOwner( hwnd
);
1883 /* Destroy the window storage */
1885 WIN_DestroyWindow( hwnd
);
1890 /***********************************************************************
1891 * CloseWindow (USER32.@)
1893 BOOL WINAPI
CloseWindow( HWND hwnd
)
1895 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
1896 ShowWindow( hwnd
, SW_MINIMIZE
);
1901 /***********************************************************************
1902 * OpenIcon (USER32.@)
1904 BOOL WINAPI
OpenIcon( HWND hwnd
)
1906 if (!IsIconic( hwnd
)) return FALSE
;
1907 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1912 /***********************************************************************
1913 * FindWindowExW (USER32.@)
1915 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
, LPCWSTR className
, LPCWSTR title
)
1920 WCHAR
*buffer
= NULL
;
1922 if (!parent
&& child
) parent
= GetDesktopWindow();
1923 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
1927 len
= strlenW(title
) + 1; /* one extra char to check for chars beyond the end */
1928 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
1931 if (!(list
= list_window_children( 0, parent
, className
, 0 ))) goto done
;
1935 child
= WIN_GetFullHandle( child
);
1936 while (list
[i
] && list
[i
] != child
) i
++;
1937 if (!list
[i
]) goto done
;
1938 i
++; /* start from next window */
1945 if (InternalGetWindowText( list
[i
], buffer
, len
+ 1 ))
1947 if (!strcmpiW( buffer
, title
)) break;
1951 if (!title
[0]) break;
1959 HeapFree( GetProcessHeap(), 0, list
);
1960 HeapFree( GetProcessHeap(), 0, buffer
);
1966 /***********************************************************************
1967 * FindWindowA (USER32.@)
1969 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
1971 HWND ret
= FindWindowExA( 0, 0, className
, title
);
1972 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1977 /***********************************************************************
1978 * FindWindowExA (USER32.@)
1980 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
, LPCSTR className
, LPCSTR title
)
1982 LPWSTR titleW
= NULL
;
1987 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
1988 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
1989 MultiByteToWideChar( CP_ACP
, 0, title
, -1, titleW
, len
);
1992 if (!IS_INTRESOURCE(className
))
1995 if (MultiByteToWideChar( CP_ACP
, 0, className
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
1996 hwnd
= FindWindowExW( parent
, child
, classW
, titleW
);
2000 hwnd
= FindWindowExW( parent
, child
, (LPCWSTR
)className
, titleW
);
2003 HeapFree( GetProcessHeap(), 0, titleW
);
2008 /***********************************************************************
2009 * FindWindowW (USER32.@)
2011 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
2013 return FindWindowExW( 0, 0, className
, title
);
2017 /**********************************************************************
2018 * GetDesktopWindow (USER32.@)
2020 HWND WINAPI
GetDesktopWindow(void)
2022 struct user_thread_info
*thread_info
= get_user_thread_info();
2024 if (thread_info
->top_window
) return thread_info
->top_window
;
2026 SERVER_START_REQ( get_desktop_window
)
2029 if (!wine_server_call( req
))
2031 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2032 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2037 if (!thread_info
->top_window
)
2039 static const WCHAR explorer
[] = {'\\','e','x','p','l','o','r','e','r','.','e','x','e',0};
2040 static const WCHAR args
[] = {' ','/','d','e','s','k','t','o','p',0};
2042 PROCESS_INFORMATION pi
;
2043 WCHAR windir
[MAX_PATH
];
2044 WCHAR app
[MAX_PATH
+ sizeof(explorer
)/sizeof(WCHAR
)];
2045 WCHAR cmdline
[MAX_PATH
+ (sizeof(explorer
) + sizeof(args
))/sizeof(WCHAR
)];
2046 WCHAR desktop
[MAX_PATH
];
2049 SERVER_START_REQ( set_user_object_info
)
2051 req
->handle
= wine_server_obj_handle( GetThreadDesktop(GetCurrentThreadId()) );
2052 req
->flags
= SET_USER_OBJECT_GET_FULL_NAME
;
2053 wine_server_set_reply( req
, desktop
, sizeof(desktop
) - sizeof(WCHAR
) );
2054 if (!wine_server_call( req
))
2056 size_t size
= wine_server_reply_size( reply
);
2057 desktop
[size
/ sizeof(WCHAR
)] = 0;
2058 TRACE( "starting explorer for desktop %s\n", debugstr_w(desktop
) );
2065 memset( &si
, 0, sizeof(si
) );
2067 si
.lpDesktop
= *desktop
? desktop
: NULL
;
2068 si
.dwFlags
= STARTF_USESTDHANDLES
;
2071 si
.hStdError
= GetStdHandle( STD_ERROR_HANDLE
);
2073 GetSystemDirectoryW( windir
, MAX_PATH
);
2074 strcpyW( app
, windir
);
2075 strcatW( app
, explorer
);
2076 strcpyW( cmdline
, app
);
2077 strcatW( cmdline
, args
);
2079 Wow64DisableWow64FsRedirection( &redir
);
2080 if (CreateProcessW( app
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
,
2081 NULL
, windir
, &si
, &pi
))
2083 TRACE( "started explorer pid %04x tid %04x\n", pi
.dwProcessId
, pi
.dwThreadId
);
2084 WaitForInputIdle( pi
.hProcess
, 10000 );
2085 CloseHandle( pi
.hThread
);
2086 CloseHandle( pi
.hProcess
);
2088 else WARN( "failed to start explorer, err %d\n", GetLastError() );
2089 Wow64RevertWow64FsRedirection( redir
);
2091 SERVER_START_REQ( get_desktop_window
)
2094 if (!wine_server_call( req
))
2096 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2097 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2103 if (!thread_info
->top_window
|| !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
2104 ERR( "failed to create desktop window\n" );
2106 return thread_info
->top_window
;
2110 /*******************************************************************
2111 * EnableWindow (USER32.@)
2113 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
2118 if (is_broadcast(hwnd
))
2120 SetLastError( ERROR_INVALID_PARAMETER
);
2124 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
2125 return SendMessageW( hwnd
, WM_WINE_ENABLEWINDOW
, enable
, 0 );
2129 TRACE("( %p, %d )\n", hwnd
, enable
);
2131 retvalue
= !IsWindowEnabled( hwnd
);
2133 if (enable
&& retvalue
)
2135 WIN_SetStyle( hwnd
, 0, WS_DISABLED
);
2136 SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
2138 else if (!enable
&& !retvalue
)
2142 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0);
2144 WIN_SetStyle( hwnd
, WS_DISABLED
, 0 );
2146 if (hwnd
== GetFocus())
2147 SetFocus( 0 ); /* A disabled window can't have the focus */
2149 capture_wnd
= GetCapture();
2150 if (hwnd
== capture_wnd
|| IsChild(hwnd
, capture_wnd
))
2151 ReleaseCapture(); /* A disabled window can't capture the mouse */
2153 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
2159 /***********************************************************************
2160 * IsWindowEnabled (USER32.@)
2162 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
2164 return !(GetWindowLongW( hWnd
, GWL_STYLE
) & WS_DISABLED
);
2168 /***********************************************************************
2169 * IsWindowUnicode (USER32.@)
2171 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
2174 BOOL retvalue
= FALSE
;
2176 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
2178 if (wndPtr
== WND_DESKTOP
) return TRUE
;
2180 if (wndPtr
!= WND_OTHER_PROCESS
)
2182 retvalue
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2183 WIN_ReleasePtr( wndPtr
);
2187 SERVER_START_REQ( get_window_info
)
2189 req
->handle
= wine_server_user_handle( hwnd
);
2190 if (!wine_server_call_err( req
)) retvalue
= reply
->is_unicode
;
2198 /**********************************************************************
2201 * Helper function for GetWindowLong().
2203 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
2205 LONG_PTR retvalue
= 0;
2208 if (offset
== GWLP_HWNDPARENT
)
2210 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
2211 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
2212 return (ULONG_PTR
)parent
;
2215 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2217 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2221 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2223 if (offset
== GWLP_WNDPROC
)
2225 SetLastError( ERROR_ACCESS_DENIED
);
2228 SERVER_START_REQ( set_window_info
)
2230 req
->handle
= wine_server_user_handle( hwnd
);
2231 req
->flags
= 0; /* don't set anything, just retrieve */
2232 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
2233 req
->extra_size
= (offset
>= 0) ? size
: 0;
2234 if (!wine_server_call_err( req
))
2238 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
2239 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
2240 case GWLP_ID
: retvalue
= reply
->old_id
; break;
2241 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
); break;
2242 case GWLP_USERDATA
: retvalue
= reply
->old_user_data
; break;
2244 if (offset
>= 0) retvalue
= get_win_data( &reply
->old_extra_value
, size
);
2245 else SetLastError( ERROR_INVALID_INDEX
);
2254 /* now we have a valid wndPtr */
2258 if (offset
> (int)(wndPtr
->cbWndExtra
- size
))
2260 WARN("Invalid offset %d\n", offset
);
2261 WIN_ReleasePtr( wndPtr
);
2262 SetLastError( ERROR_INVALID_INDEX
);
2265 retvalue
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2267 /* Special case for dialog window procedure */
2268 if ((offset
== DWLP_DLGPROC
) && (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2269 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, unicode
);
2270 WIN_ReleasePtr( wndPtr
);
2276 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
2277 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
2278 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
2279 case GWLP_ID
: retvalue
= wndPtr
->wIDmenu
; break;
2280 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
2282 /* This looks like a hack only for the edit control (see tests). This makes these controls
2283 * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests
2284 * that the hack is in GetWindowLongPtr[AW], not in winprocs.
2286 if (wndPtr
->winproc
== BUILTIN_WINPROC(WINPROC_EDIT
) && (!unicode
!= !(wndPtr
->flags
& WIN_ISUNICODE
)))
2287 retvalue
= (ULONG_PTR
)wndPtr
->winproc
;
2289 retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
);
2292 WARN("Unknown offset %d\n", offset
);
2293 SetLastError( ERROR_INVALID_INDEX
);
2296 WIN_ReleasePtr(wndPtr
);
2301 /**********************************************************************
2304 * Helper function for SetWindowLong().
2306 * 0 is the failure code. However, in the case of failure SetLastError
2307 * must be set to distinguish between a 0 return value and a failure.
2309 LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, UINT size
, LONG_PTR newval
, BOOL unicode
)
2312 BOOL ok
, made_visible
= FALSE
;
2313 LONG_PTR retval
= 0;
2316 TRACE( "%p %d %lx %c\n", hwnd
, offset
, newval
, unicode
? 'W' : 'A' );
2318 if (is_broadcast(hwnd
))
2320 SetLastError( ERROR_INVALID_PARAMETER
);
2324 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2326 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2329 if (wndPtr
== WND_DESKTOP
)
2331 /* can't change anything on the desktop window */
2332 SetLastError( ERROR_ACCESS_DENIED
);
2335 if (wndPtr
== WND_OTHER_PROCESS
)
2337 if (offset
== GWLP_WNDPROC
)
2339 SetLastError( ERROR_ACCESS_DENIED
);
2342 if (offset
> 32767 || offset
< -32767)
2344 SetLastError( ERROR_INVALID_INDEX
);
2347 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, MAKEWPARAM( offset
, size
), newval
);
2350 /* first some special cases */
2354 style
.styleOld
= wndPtr
->dwStyle
;
2355 style
.styleNew
= newval
;
2356 WIN_ReleasePtr( wndPtr
);
2357 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
)&style
);
2358 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2359 newval
= style
.styleNew
;
2360 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
2361 if (wndPtr
->parent
== GetDesktopWindow()) newval
|= WS_CLIPSIBLINGS
;
2362 /* FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change
2363 WS_EX_WINDOWEDGE too */
2366 style
.styleOld
= wndPtr
->dwExStyle
;
2367 style
.styleNew
= newval
;
2368 WIN_ReleasePtr( wndPtr
);
2369 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
)&style
);
2370 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2371 /* WS_EX_TOPMOST can only be changed through SetWindowPos */
2372 newval
= (style
.styleNew
& ~WS_EX_TOPMOST
) | (wndPtr
->dwExStyle
& WS_EX_TOPMOST
);
2373 /* WS_EX_WINDOWEDGE depends on some other styles */
2374 if (newval
& WS_EX_DLGMODALFRAME
)
2375 newval
|= WS_EX_WINDOWEDGE
;
2376 else if (!(newval
& WS_EX_STATICEDGE
) && (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)))
2377 newval
|= WS_EX_WINDOWEDGE
;
2379 newval
&= ~WS_EX_WINDOWEDGE
;
2381 case GWLP_HWNDPARENT
:
2382 if (wndPtr
->parent
== GetDesktopWindow())
2384 WIN_ReleasePtr( wndPtr
);
2385 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
2389 WIN_ReleasePtr( wndPtr
);
2390 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
2395 UINT old_flags
= wndPtr
->flags
;
2396 retval
= WIN_GetWindowLong( hwnd
, offset
, size
, unicode
);
2397 proc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2398 if (proc
) wndPtr
->winproc
= proc
;
2399 if (WINPROC_IsUnicode( proc
, unicode
)) wndPtr
->flags
|= WIN_ISUNICODE
;
2400 else wndPtr
->flags
&= ~WIN_ISUNICODE
;
2401 if (!((old_flags
^ wndPtr
->flags
) & WIN_ISUNICODE
))
2403 WIN_ReleasePtr( wndPtr
);
2406 /* update is_unicode flag on the server side */
2410 case GWLP_HINSTANCE
:
2414 if ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2415 (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2417 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
2418 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, unicode
);
2419 *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2420 WIN_ReleasePtr( wndPtr
);
2425 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- size
))
2427 WARN("Invalid offset %d\n", offset
);
2428 WIN_ReleasePtr( wndPtr
);
2429 SetLastError( ERROR_INVALID_INDEX
);
2432 else if (get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
) == newval
)
2434 /* already set to the same value */
2435 WIN_ReleasePtr( wndPtr
);
2441 SERVER_START_REQ( set_window_info
)
2443 req
->handle
= wine_server_user_handle( hwnd
);
2444 req
->extra_offset
= -1;
2448 req
->flags
= SET_WIN_STYLE
;
2449 req
->style
= newval
;
2452 req
->flags
= SET_WIN_EXSTYLE
;
2453 req
->ex_style
= newval
;
2456 req
->flags
= SET_WIN_ID
;
2459 case GWLP_HINSTANCE
:
2460 req
->flags
= SET_WIN_INSTANCE
;
2461 req
->instance
= wine_server_client_ptr( (void *)newval
);
2464 req
->flags
= SET_WIN_UNICODE
;
2465 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2468 req
->flags
= SET_WIN_USERDATA
;
2469 req
->user_data
= newval
;
2472 req
->flags
= SET_WIN_EXTRA
;
2473 req
->extra_offset
= offset
;
2474 req
->extra_size
= size
;
2475 set_win_data( &req
->extra_value
, newval
, size
);
2477 if ((ok
= !wine_server_call_err( req
)))
2482 wndPtr
->dwStyle
= newval
;
2483 retval
= reply
->old_style
;
2486 wndPtr
->dwExStyle
= newval
;
2487 retval
= reply
->old_ex_style
;
2490 wndPtr
->wIDmenu
= newval
;
2491 retval
= reply
->old_id
;
2493 case GWLP_HINSTANCE
:
2494 wndPtr
->hInstance
= (HINSTANCE
)newval
;
2495 retval
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
2500 wndPtr
->userdata
= newval
;
2501 retval
= reply
->old_user_data
;
2504 retval
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2505 set_win_data( (char *)wndPtr
->wExtra
+ offset
, newval
, size
);
2512 if ((offset
== GWL_STYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
)) ||
2513 (offset
== GWL_EXSTYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_EX_LAYERED
)))
2515 made_visible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
2516 invalidate_dce( wndPtr
, NULL
);
2518 WIN_ReleasePtr( wndPtr
);
2522 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2524 style
.styleOld
= retval
;
2525 style
.styleNew
= newval
;
2526 USER_Driver
->pSetWindowStyle( hwnd
, offset
, &style
);
2527 if (made_visible
) update_window_state( hwnd
);
2528 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2535 /**********************************************************************
2536 * GetWindowWord (USER32.@)
2538 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
2543 case GWLP_HINSTANCE
:
2544 case GWLP_HWNDPARENT
:
2549 WARN("Invalid offset %d\n", offset
);
2550 SetLastError( ERROR_INVALID_INDEX
);
2555 return WIN_GetWindowLong( hwnd
, offset
, sizeof(WORD
), FALSE
);
2559 /**********************************************************************
2560 * GetWindowLongA (USER32.@)
2562 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2564 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), FALSE
);
2568 /**********************************************************************
2569 * GetWindowLongW (USER32.@)
2571 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2573 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), TRUE
);
2577 /**********************************************************************
2578 * SetWindowWord (USER32.@)
2580 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
2585 case GWLP_HINSTANCE
:
2586 case GWLP_HWNDPARENT
:
2591 WARN("Invalid offset %d\n", offset
);
2592 SetLastError( ERROR_INVALID_INDEX
);
2597 return WIN_SetWindowLong( hwnd
, offset
, sizeof(WORD
), newval
, FALSE
);
2601 /**********************************************************************
2602 * SetWindowLongA (USER32.@)
2604 * See SetWindowLongW.
2606 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2608 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, FALSE
);
2612 /**********************************************************************
2613 * SetWindowLongW (USER32.@) Set window attribute
2615 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2616 * value in a window's extra memory.
2618 * The _hwnd_ parameter specifies the handle to a window that
2619 * has extra memory. The _newval_ parameter contains the new
2620 * attribute or extra memory value. If positive, the _offset_
2621 * parameter is the byte-addressed location in the window's extra
2622 * memory to set. If negative, _offset_ specifies the window
2623 * attribute to set, and should be one of the following values:
2625 * GWL_EXSTYLE The window's extended window style
2627 * GWL_STYLE The window's window style.
2629 * GWLP_WNDPROC Pointer to the window's window procedure.
2631 * GWLP_HINSTANCE The window's application instance handle.
2633 * GWLP_ID The window's identifier.
2635 * GWLP_USERDATA The window's user-specified data.
2637 * If the window is a dialog box, the _offset_ parameter can be one of
2638 * the following values:
2640 * DWLP_DLGPROC The address of the window's dialog box procedure.
2642 * DWLP_MSGRESULT The return value of a message
2643 * that the dialog box procedure processed.
2645 * DWLP_USER Application specific information.
2649 * If successful, returns the previous value located at _offset_. Otherwise,
2654 * Extra memory for a window class is specified by a nonzero cbWndExtra
2655 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2656 * time of class creation.
2658 * Using GWL_WNDPROC to set a new window procedure effectively creates
2659 * a window subclass. Use CallWindowProc() in the new windows procedure
2660 * to pass messages to the superclass's window procedure.
2662 * The user data is reserved for use by the application which created
2665 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2666 * instead, call the EnableWindow() function to change the window's
2669 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2670 * SetParent() instead.
2673 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2674 * it sends WM_STYLECHANGING before changing the settings
2675 * and WM_STYLECHANGED afterwards.
2676 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2678 LONG WINAPI
SetWindowLongW(
2679 HWND hwnd
, /* [in] window to alter */
2680 INT offset
, /* [in] offset, in bytes, of location to alter */
2681 LONG newval
/* [in] new value of location */
2683 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, TRUE
);
2687 /*******************************************************************
2688 * GetWindowTextA (USER32.@)
2690 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2694 if (!lpString
|| nMaxCount
<= 0) return 0;
2696 if (WIN_IsCurrentProcess( hwnd
))
2699 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2702 /* when window belongs to other process, don't send a message */
2703 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) ))) return 0;
2704 get_server_window_text( hwnd
, buffer
, nMaxCount
);
2705 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
2706 lpString
[nMaxCount
-1] = 0;
2707 HeapFree( GetProcessHeap(), 0, buffer
);
2708 return strlen(lpString
);
2712 /*******************************************************************
2713 * InternalGetWindowText (USER32.@)
2715 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2719 if (nMaxCount
<= 0) return 0;
2720 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
2721 if (win
== WND_DESKTOP
) lpString
[0] = 0;
2722 else if (win
!= WND_OTHER_PROCESS
)
2724 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
2725 else lpString
[0] = 0;
2726 WIN_ReleasePtr( win
);
2730 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2732 return strlenW(lpString
);
2736 /*******************************************************************
2737 * GetWindowTextW (USER32.@)
2739 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2741 if (!lpString
|| nMaxCount
<= 0) return 0;
2743 if (WIN_IsCurrentProcess( hwnd
))
2746 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2749 /* when window belongs to other process, don't send a message */
2750 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2751 return strlenW(lpString
);
2755 /*******************************************************************
2756 * SetWindowTextA (USER32.@)
2757 * SetWindowText (USER32.@)
2759 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2761 if (is_broadcast(hwnd
))
2763 SetLastError( ERROR_INVALID_PARAMETER
);
2766 if (!WIN_IsCurrentProcess( hwnd
))
2767 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2768 debugstr_a(lpString
), hwnd
);
2769 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2773 /*******************************************************************
2774 * SetWindowTextW (USER32.@)
2776 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2778 if (is_broadcast(hwnd
))
2780 SetLastError( ERROR_INVALID_PARAMETER
);
2783 if (!WIN_IsCurrentProcess( hwnd
))
2784 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2785 debugstr_w(lpString
), hwnd
);
2786 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2790 /*******************************************************************
2791 * GetWindowTextLengthA (USER32.@)
2793 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2795 return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2798 /*******************************************************************
2799 * GetWindowTextLengthW (USER32.@)
2801 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2803 return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2807 /*******************************************************************
2808 * IsWindow (USER32.@)
2810 BOOL WINAPI
IsWindow( HWND hwnd
)
2815 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
2816 if (ptr
== WND_DESKTOP
) return TRUE
;
2818 if (ptr
!= WND_OTHER_PROCESS
)
2820 WIN_ReleasePtr( ptr
);
2824 /* check other processes */
2825 SERVER_START_REQ( get_window_info
)
2827 req
->handle
= wine_server_user_handle( hwnd
);
2828 ret
= !wine_server_call_err( req
);
2835 /***********************************************************************
2836 * GetWindowThreadProcessId (USER32.@)
2838 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
2843 if (!(ptr
= WIN_GetPtr( hwnd
)))
2845 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2849 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
2851 /* got a valid window */
2853 if (process
) *process
= GetCurrentProcessId();
2854 WIN_ReleasePtr( ptr
);
2858 /* check other processes */
2859 SERVER_START_REQ( get_window_info
)
2861 req
->handle
= wine_server_user_handle( hwnd
);
2862 if (!wine_server_call_err( req
))
2864 tid
= (DWORD
)reply
->tid
;
2865 if (process
) *process
= (DWORD
)reply
->pid
;
2873 /*****************************************************************
2874 * GetParent (USER32.@)
2876 HWND WINAPI
GetParent( HWND hwnd
)
2881 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2883 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2886 if (wndPtr
== WND_DESKTOP
) return 0;
2887 if (wndPtr
== WND_OTHER_PROCESS
)
2889 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2890 if (style
& (WS_POPUP
| WS_CHILD
))
2892 SERVER_START_REQ( get_window_tree
)
2894 req
->handle
= wine_server_user_handle( hwnd
);
2895 if (!wine_server_call_err( req
))
2897 if (style
& WS_POPUP
) retvalue
= wine_server_ptr_handle( reply
->owner
);
2898 else if (style
& WS_CHILD
) retvalue
= wine_server_ptr_handle( reply
->parent
);
2906 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
2907 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
2908 WIN_ReleasePtr( wndPtr
);
2914 /*****************************************************************
2915 * GetAncestor (USER32.@)
2917 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
2920 HWND
*list
, ret
= 0;
2925 if (!(win
= WIN_GetPtr( hwnd
)))
2927 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2930 if (win
== WND_DESKTOP
) return 0;
2931 if (win
!= WND_OTHER_PROCESS
)
2934 WIN_ReleasePtr( win
);
2936 else /* need to query the server */
2938 SERVER_START_REQ( get_window_tree
)
2940 req
->handle
= wine_server_user_handle( hwnd
);
2941 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->parent
);
2948 if (!(list
= list_window_parents( hwnd
))) return 0;
2950 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
2954 while (list
[count
]) count
++;
2955 ret
= list
[count
- 2]; /* get the one before the desktop */
2957 HeapFree( GetProcessHeap(), 0, list
);
2961 if (is_desktop_window( hwnd
)) return 0;
2962 ret
= WIN_GetFullHandle( hwnd
);
2965 HWND parent
= GetParent( ret
);
2975 /*****************************************************************
2976 * SetParent (USER32.@)
2978 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
2981 HWND old_parent
= 0;
2987 TRACE("(%p %p)\n", hwnd
, parent
);
2989 if (is_broadcast(hwnd
) || is_broadcast(parent
))
2991 SetLastError(ERROR_INVALID_PARAMETER
);
2995 if (!parent
) parent
= GetDesktopWindow();
2996 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
2997 else parent
= WIN_GetFullHandle( parent
);
2999 if (!IsWindow( parent
))
3001 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3005 /* Some applications try to set a child as a parent */
3006 if (IsChild(hwnd
, parent
))
3008 SetLastError( ERROR_INVALID_PARAMETER
);
3012 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
3013 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
3015 if (full_handle
== parent
)
3017 SetLastError( ERROR_INVALID_PARAMETER
);
3021 /* Windows hides the window first, then shows it again
3022 * including the WM_SHOWWINDOW messages and all */
3023 was_visible
= ShowWindow( hwnd
, SW_HIDE
);
3025 wndPtr
= WIN_GetPtr( hwnd
);
3026 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
3028 pt
.x
= wndPtr
->rectWindow
.left
;
3029 pt
.y
= wndPtr
->rectWindow
.top
;
3031 SERVER_START_REQ( set_parent
)
3033 req
->handle
= wine_server_user_handle( hwnd
);
3034 req
->parent
= wine_server_user_handle( parent
);
3035 if ((ret
= !wine_server_call( req
)))
3037 old_parent
= wine_server_ptr_handle( reply
->old_parent
);
3038 wndPtr
->parent
= parent
= wine_server_ptr_handle( reply
->full_parent
);
3043 WIN_ReleasePtr( wndPtr
);
3046 USER_Driver
->pSetParent( full_handle
, parent
, old_parent
);
3048 /* SetParent additionally needs to make hwnd the topmost window
3049 in the x-order and send the expected WM_WINDOWPOSCHANGING and
3050 WM_WINDOWPOSCHANGED notification messages.
3052 SetWindowPos( hwnd
, HWND_TOP
, pt
.x
, pt
.y
, 0, 0, SWP_NOSIZE
);
3054 if (was_visible
) ShowWindow( hwnd
, SW_SHOW
);
3060 /*******************************************************************
3061 * IsChild (USER32.@)
3063 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
3069 if (!(GetWindowLongW( child
, GWL_STYLE
) & WS_CHILD
)) return FALSE
;
3070 if (!(list
= list_window_parents( child
))) return FALSE
;
3071 parent
= WIN_GetFullHandle( parent
);
3072 for (i
= 0; list
[i
]; i
++)
3074 if (list
[i
] == parent
)
3076 ret
= list
[i
] && list
[i
+1];
3079 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_CHILD
)) break;
3081 HeapFree( GetProcessHeap(), 0, list
);
3086 /***********************************************************************
3087 * IsWindowVisible (USER32.@)
3089 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
3095 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
3096 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3099 for (i
= 0; list
[i
+1]; i
++)
3100 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
3101 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3103 HeapFree( GetProcessHeap(), 0, list
);
3108 /***********************************************************************
3109 * WIN_IsWindowDrawable
3111 * hwnd is drawable when it is visible, all parents are not
3112 * minimized, and it is itself not minimized unless we are
3113 * trying to draw its default class icon.
3115 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
3120 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3122 if (!(style
& WS_VISIBLE
)) return FALSE
;
3123 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
3125 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3128 for (i
= 0; list
[i
+1]; i
++)
3129 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
3131 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3133 HeapFree( GetProcessHeap(), 0, list
);
3138 /*******************************************************************
3139 * GetTopWindow (USER32.@)
3141 HWND WINAPI
GetTopWindow( HWND hwnd
)
3143 if (!hwnd
) hwnd
= GetDesktopWindow();
3144 return GetWindow( hwnd
, GW_CHILD
);
3148 /*******************************************************************
3149 * GetWindow (USER32.@)
3151 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
3155 if (rel
== GW_OWNER
) /* this one may be available locally */
3157 WND
*wndPtr
= WIN_GetPtr( hwnd
);
3160 SetLastError( ERROR_INVALID_HANDLE
);
3163 if (wndPtr
== WND_DESKTOP
) return 0;
3164 if (wndPtr
!= WND_OTHER_PROCESS
)
3166 retval
= wndPtr
->owner
;
3167 WIN_ReleasePtr( wndPtr
);
3170 /* else fall through to server call */
3173 SERVER_START_REQ( get_window_tree
)
3175 req
->handle
= wine_server_user_handle( hwnd
);
3176 if (!wine_server_call_err( req
))
3181 retval
= wine_server_ptr_handle( reply
->first_sibling
);
3184 retval
= wine_server_ptr_handle( reply
->last_sibling
);
3187 retval
= wine_server_ptr_handle( reply
->next_sibling
);
3190 retval
= wine_server_ptr_handle( reply
->prev_sibling
);
3193 retval
= wine_server_ptr_handle( reply
->owner
);
3196 retval
= wine_server_ptr_handle( reply
->first_child
);
3206 /*******************************************************************
3207 * ShowOwnedPopups (USER32.@)
3209 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
3213 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
3215 if (!win_array
) return TRUE
;
3217 while (win_array
[count
]) count
++;
3218 while (--count
>= 0)
3220 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
3221 if (!(pWnd
= WIN_GetPtr( win_array
[count
] ))) continue;
3222 if (pWnd
== WND_OTHER_PROCESS
) continue;
3225 if (pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
3227 WIN_ReleasePtr( pWnd
);
3228 /* In Windows, ShowOwnedPopups(TRUE) generates
3229 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
3230 * regardless of the state of the owner
3232 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
3238 if (pWnd
->dwStyle
& WS_VISIBLE
)
3240 WIN_ReleasePtr( pWnd
);
3241 /* In Windows, ShowOwnedPopups(FALSE) generates
3242 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
3243 * regardless of the state of the owner
3245 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
3249 WIN_ReleasePtr( pWnd
);
3251 HeapFree( GetProcessHeap(), 0, win_array
);
3256 /*******************************************************************
3257 * GetLastActivePopup (USER32.@)
3259 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
3263 SERVER_START_REQ( get_window_info
)
3265 req
->handle
= wine_server_user_handle( hwnd
);
3266 if (!wine_server_call_err( req
)) retval
= wine_server_ptr_handle( reply
->last_active
);
3273 /*******************************************************************
3276 * Build an array of the children of a given window. The array must be
3277 * freed with HeapFree. Returns NULL when no windows are found.
3279 HWND
*WIN_ListChildren( HWND hwnd
)
3283 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3286 return list_window_children( 0, hwnd
, NULL
, 0 );
3290 /*******************************************************************
3291 * EnumWindows (USER32.@)
3293 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
3299 USER_CheckNotLock();
3301 /* We have to build a list of all windows first, to avoid */
3302 /* unpleasant side-effects, for instance if the callback */
3303 /* function changes the Z-order of the windows. */
3305 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
3307 /* Now call the callback function for every window */
3309 for (i
= 0; list
[i
]; i
++)
3311 /* Make sure that the window still exists */
3312 if (!IsWindow( list
[i
] )) continue;
3313 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
3315 HeapFree( GetProcessHeap(), 0, list
);
3320 /**********************************************************************
3321 * EnumThreadWindows (USER32.@)
3323 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
3329 USER_CheckNotLock();
3331 if (!(list
= list_window_children( 0, GetDesktopWindow(), NULL
, id
))) return TRUE
;
3333 /* Now call the callback function for every window */
3335 for (i
= 0; list
[i
]; i
++)
3336 if (!(ret
= func( list
[i
], lParam
))) break;
3337 HeapFree( GetProcessHeap(), 0, list
);
3342 /***********************************************************************
3343 * EnumDesktopWindows (USER32.@)
3345 BOOL WINAPI
EnumDesktopWindows( HDESK desktop
, WNDENUMPROC func
, LPARAM lparam
)
3350 USER_CheckNotLock();
3352 if (!(list
= list_window_children( desktop
, 0, NULL
, 0 ))) return TRUE
;
3354 for (i
= 0; list
[i
]; i
++)
3355 if (!func( list
[i
], lparam
)) break;
3356 HeapFree( GetProcessHeap(), 0, list
);
3362 /* Some apps pass a non-stdcall proc to EnumChildWindows,
3363 * so we need a small assembly wrapper to call the proc.
3365 extern LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
);
3366 __ASM_GLOBAL_FUNC( enum_callback_wrapper
,
3368 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
3369 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
3370 "movl %esp,%ebp\n\t"
3371 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
3372 "pushl 16(%ebp)\n\t"
3373 "pushl 12(%ebp)\n\t"
3376 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
3377 __ASM_CFI(".cfi_same_value %ebp\n\t")
3380 static inline LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
)
3382 return proc( hwnd
, lparam
);
3384 #endif /* __i386__ */
3386 /**********************************************************************
3387 * WIN_EnumChildWindows
3389 * Helper function for EnumChildWindows().
3391 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
3396 for ( ; *list
; list
++)
3398 /* Make sure that the window still exists */
3399 if (!IsWindow( *list
)) continue;
3400 /* Build children list first */
3401 childList
= WIN_ListChildren( *list
);
3403 ret
= enum_callback_wrapper( func
, *list
, lParam
);
3407 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
3408 HeapFree( GetProcessHeap(), 0, childList
);
3410 if (!ret
) return FALSE
;
3416 /**********************************************************************
3417 * EnumChildWindows (USER32.@)
3419 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
3424 USER_CheckNotLock();
3426 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
3427 ret
= WIN_EnumChildWindows( list
, func
, lParam
);
3428 HeapFree( GetProcessHeap(), 0, list
);
3433 /*******************************************************************
3434 * AnyPopup (USER32.@)
3436 BOOL WINAPI
AnyPopup(void)
3440 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
3442 if (!list
) return FALSE
;
3443 for (i
= 0; list
[i
]; i
++)
3445 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
3447 retvalue
= (list
[i
] != 0);
3448 HeapFree( GetProcessHeap(), 0, list
);
3453 /*******************************************************************
3454 * FlashWindow (USER32.@)
3456 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
3460 finfo
.cbSize
= sizeof(FLASHWINFO
);
3461 finfo
.dwFlags
= bInvert
? FLASHW_ALL
: FLASHW_STOP
;
3463 finfo
.dwTimeout
= 0;
3465 return FlashWindowEx( &finfo
);
3468 /*******************************************************************
3469 * FlashWindowEx (USER32.@)
3471 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfinfo
)
3475 TRACE( "%p\n", pfinfo
->hwnd
);
3479 SetLastError( ERROR_NOACCESS
);
3483 if (!pfinfo
->hwnd
|| pfinfo
->cbSize
!= sizeof(FLASHWINFO
) || !IsWindow( pfinfo
->hwnd
))
3485 SetLastError( ERROR_INVALID_PARAMETER
);
3488 FIXME( "%p - semi-stub\n", pfinfo
);
3490 if (IsIconic( pfinfo
->hwnd
))
3492 RedrawWindow( pfinfo
->hwnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
3494 wndPtr
= WIN_GetPtr( pfinfo
->hwnd
);
3495 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3496 if (pfinfo
->dwFlags
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
3498 wndPtr
->flags
|= WIN_NCACTIVATED
;
3502 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
3504 WIN_ReleasePtr( wndPtr
);
3505 USER_Driver
->pFlashWindowEx( pfinfo
);
3511 HWND hwnd
= pfinfo
->hwnd
;
3513 wndPtr
= WIN_GetPtr( hwnd
);
3514 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3515 hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
3517 if (pfinfo
->dwFlags
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
3518 else wparam
= (hwnd
== GetForegroundWindow());
3520 WIN_ReleasePtr( wndPtr
);
3521 SendMessageW( hwnd
, WM_NCACTIVATE
, wparam
, 0 );
3522 USER_Driver
->pFlashWindowEx( pfinfo
);
3527 /*******************************************************************
3528 * GetWindowContextHelpId (USER32.@)
3530 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
3533 WND
*wnd
= WIN_GetPtr( hwnd
);
3534 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
3535 if (wnd
== WND_OTHER_PROCESS
)
3537 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3540 retval
= wnd
->helpContext
;
3541 WIN_ReleasePtr( wnd
);
3546 /*******************************************************************
3547 * SetWindowContextHelpId (USER32.@)
3549 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
3551 WND
*wnd
= WIN_GetPtr( hwnd
);
3552 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
3553 if (wnd
== WND_OTHER_PROCESS
)
3555 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3558 wnd
->helpContext
= id
;
3559 WIN_ReleasePtr( wnd
);
3564 /*******************************************************************
3565 * DragDetect (USER32.@)
3567 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3571 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3572 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3574 rect
.left
= pt
.x
- wDragWidth
;
3575 rect
.right
= pt
.x
+ wDragWidth
;
3577 rect
.top
= pt
.y
- wDragHeight
;
3578 rect
.bottom
= pt
.y
+ wDragHeight
;
3584 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
3586 if( msg
.message
== WM_LBUTTONUP
)
3591 if( msg
.message
== WM_MOUSEMOVE
)
3594 tmp
.x
= (short)LOWORD(msg
.lParam
);
3595 tmp
.y
= (short)HIWORD(msg
.lParam
);
3596 if( !PtInRect( &rect
, tmp
))
3608 /******************************************************************************
3609 * GetWindowModuleFileNameA (USER32.@)
3611 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR module
, UINT size
)
3616 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3618 win
= WIN_GetPtr( hwnd
);
3619 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3621 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3624 hinst
= win
->hInstance
;
3625 WIN_ReleasePtr( win
);
3627 return GetModuleFileNameA( hinst
, module
, size
);
3630 /******************************************************************************
3631 * GetWindowModuleFileNameW (USER32.@)
3633 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR module
, UINT size
)
3638 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3640 win
= WIN_GetPtr( hwnd
);
3641 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3643 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3646 hinst
= win
->hInstance
;
3647 WIN_ReleasePtr( win
);
3649 return GetModuleFileNameW( hinst
, module
, size
);
3652 /******************************************************************************
3653 * GetWindowInfo (USER32.@)
3655 * Note: tests show that Windows doesn't check cbSize of the structure.
3657 BOOL WINAPI DECLSPEC_HOTPATCH
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
3659 if (!pwi
) return FALSE
;
3660 if (!WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &pwi
->rcWindow
, &pwi
->rcClient
)) return FALSE
;
3662 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3663 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3664 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
3666 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
3667 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
3669 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
3670 pwi
->wCreatorVersion
= 0x0400;
3675 /******************************************************************************
3676 * SwitchDesktop (USER32.@)
3678 * NOTES: Sets the current input or interactive desktop.
3680 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
3682 FIXME("(hwnd %p) stub!\n", hDesktop
);
3687 /***********************************************************************
3688 * __wine_set_pixel_format
3690 BOOL CDECL
__wine_set_pixel_format( HWND hwnd
, int format
)
3692 WND
*win
= WIN_GetPtr( hwnd
);
3694 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
3696 WARN( "setting format %d on win %p not supported\n", format
, hwnd
);
3699 win
->pixel_format
= format
;
3700 WIN_ReleasePtr( win
);
3702 update_window_state( hwnd
);
3707 /*****************************************************************************
3708 * SetLayeredWindowAttributes (USER32.@)
3710 BOOL WINAPI
SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
3714 TRACE("(%p,%08x,%d,%x)\n", hwnd
, key
, alpha
, flags
);
3716 SERVER_START_REQ( set_window_layered_info
)
3718 req
->handle
= wine_server_user_handle( hwnd
);
3719 req
->color_key
= key
;
3722 ret
= !wine_server_call_err( req
);
3726 if (ret
) USER_Driver
->pSetLayeredWindowAttributes( hwnd
, key
, alpha
, flags
);
3732 /*****************************************************************************
3733 * GetLayeredWindowAttributes (USER32.@)
3735 BOOL WINAPI
GetLayeredWindowAttributes( HWND hwnd
, COLORREF
*key
, BYTE
*alpha
, DWORD
*flags
)
3739 SERVER_START_REQ( get_window_layered_info
)
3741 req
->handle
= wine_server_user_handle( hwnd
);
3742 if ((ret
= !wine_server_call_err( req
)))
3744 if (key
) *key
= reply
->color_key
;
3745 if (alpha
) *alpha
= reply
->alpha
;
3746 if (flags
) *flags
= reply
->flags
;
3755 /*****************************************************************************
3756 * UpdateLayeredWindowIndirect (USER32.@)
3758 BOOL WINAPI
UpdateLayeredWindowIndirect( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
)
3760 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
;
3761 RECT window_rect
, client_rect
;
3765 info
->cbSize
!= sizeof(*info
) ||
3766 info
->dwFlags
& ~(ULW_COLORKEY
| ULW_ALPHA
| ULW_OPAQUE
| ULW_EX_NORESIZE
) ||
3767 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) ||
3768 GetLayeredWindowAttributes( hwnd
, NULL
, NULL
, NULL
))
3770 SetLastError( ERROR_INVALID_PARAMETER
);
3774 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
3778 offset
.cx
= info
->pptDst
->x
- window_rect
.left
;
3779 offset
.cy
= info
->pptDst
->y
- window_rect
.top
;
3780 OffsetRect( &client_rect
, offset
.cx
, offset
.cy
);
3781 OffsetRect( &window_rect
, offset
.cx
, offset
.cy
);
3782 flags
&= ~SWP_NOMOVE
;
3786 offset
.cx
= info
->psize
->cx
- (window_rect
.right
- window_rect
.left
);
3787 offset
.cy
= info
->psize
->cy
- (window_rect
.bottom
- window_rect
.top
);
3788 if (info
->psize
->cx
<= 0 || info
->psize
->cy
<= 0)
3790 SetLastError( ERROR_INVALID_PARAMETER
);
3793 if ((info
->dwFlags
& ULW_EX_NORESIZE
) && (offset
.cx
|| offset
.cy
))
3795 SetLastError( ERROR_INCORRECT_SIZE
);
3798 client_rect
.right
+= offset
.cx
;
3799 client_rect
.bottom
+= offset
.cy
;
3800 window_rect
.right
+= offset
.cx
;
3801 window_rect
.bottom
+= offset
.cy
;
3802 flags
&= ~SWP_NOSIZE
;
3805 TRACE( "window %p win %s client %s\n", hwnd
,
3806 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
) );
3808 if (!USER_Driver
->pUpdateLayeredWindow( hwnd
, info
, &window_rect
)) return FALSE
;
3810 set_window_pos( hwnd
, 0, flags
, &window_rect
, &client_rect
, NULL
);
3815 /*****************************************************************************
3816 * UpdateLayeredWindow (USER32.@)
3818 BOOL WINAPI
UpdateLayeredWindow( HWND hwnd
, HDC hdcDst
, POINT
*pptDst
, SIZE
*psize
,
3819 HDC hdcSrc
, POINT
*pptSrc
, COLORREF crKey
, BLENDFUNCTION
*pblend
,
3822 UPDATELAYEREDWINDOWINFO info
;
3824 if (flags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
3826 SetLastError( ERROR_INVALID_PARAMETER
);
3829 info
.cbSize
= sizeof(info
);
3830 info
.hdcDst
= hdcDst
;
3831 info
.pptDst
= pptDst
;
3833 info
.hdcSrc
= hdcSrc
;
3834 info
.pptSrc
= pptSrc
;
3836 info
.pblend
= pblend
;
3837 info
.dwFlags
= flags
;
3838 info
.prcDirty
= NULL
;
3839 return UpdateLayeredWindowIndirect( hwnd
, &info
);
3843 /******************************************************************************
3844 * GetProcessDefaultLayout [USER32.@]
3846 * Gets the default layout for parentless windows.
3848 BOOL WINAPI
GetProcessDefaultLayout( DWORD
*layout
)
3852 SetLastError( ERROR_NOACCESS
);
3855 if (process_layout
== ~0u)
3857 static const WCHAR translationW
[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
3858 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
3859 static const WCHAR filedescW
[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
3860 '\\','%','0','4','x','%','0','4','x',
3861 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0 };
3862 WCHAR
*str
, buffer
[MAX_PATH
];
3863 DWORD i
, len
, version_layout
= 0;
3864 DWORD user_lang
= GetUserDefaultLangID();
3868 GetModuleFileNameW( 0, buffer
, MAX_PATH
);
3869 if (!(len
= GetFileVersionInfoSizeW( buffer
, NULL
))) goto done
;
3870 if (!(data
= HeapAlloc( GetProcessHeap(), 0, len
))) goto done
;
3871 if (!GetFileVersionInfoW( buffer
, 0, len
, data
)) goto done
;
3872 if (!VerQueryValueW( data
, translationW
, (void **)&languages
, &len
) || !len
) goto done
;
3874 len
/= sizeof(DWORD
);
3875 for (i
= 0; i
< len
; i
++) if (LOWORD(languages
[i
]) == user_lang
) break;
3876 if (i
== len
) /* try neutral language */
3877 for (i
= 0; i
< len
; i
++)
3878 if (LOWORD(languages
[i
]) == MAKELANGID( PRIMARYLANGID(user_lang
), SUBLANG_NEUTRAL
)) break;
3879 if (i
== len
) i
= 0; /* default to the first one */
3881 sprintfW( buffer
, filedescW
, LOWORD(languages
[i
]), HIWORD(languages
[i
]) );
3882 if (!VerQueryValueW( data
, buffer
, (void **)&str
, &len
)) goto done
;
3883 TRACE( "found description %s\n", debugstr_w( str
));
3884 if (str
[0] == 0x200e && str
[1] == 0x200e) version_layout
= LAYOUT_RTL
;
3887 HeapFree( GetProcessHeap(), 0, data
);
3888 process_layout
= version_layout
;
3890 *layout
= process_layout
;
3895 /******************************************************************************
3896 * SetProcessDefaultLayout [USER32.@]
3898 * Sets the default layout for parentless windows.
3900 BOOL WINAPI
SetProcessDefaultLayout( DWORD layout
)
3902 process_layout
= layout
;
3907 /* 64bit versions */
3909 #ifdef GetWindowLongPtrW
3910 #undef GetWindowLongPtrW
3913 #ifdef GetWindowLongPtrA
3914 #undef GetWindowLongPtrA
3917 #ifdef SetWindowLongPtrW
3918 #undef SetWindowLongPtrW
3921 #ifdef SetWindowLongPtrA
3922 #undef SetWindowLongPtrA
3925 /*****************************************************************************
3926 * GetWindowLongPtrW (USER32.@)
3928 LONG_PTR WINAPI
GetWindowLongPtrW( HWND hwnd
, INT offset
)
3930 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), TRUE
);
3933 /*****************************************************************************
3934 * GetWindowLongPtrA (USER32.@)
3936 LONG_PTR WINAPI
GetWindowLongPtrA( HWND hwnd
, INT offset
)
3938 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), FALSE
);
3941 /*****************************************************************************
3942 * SetWindowLongPtrW (USER32.@)
3944 LONG_PTR WINAPI
SetWindowLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
3946 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, TRUE
);
3949 /*****************************************************************************
3950 * SetWindowLongPtrA (USER32.@)
3952 LONG_PTR WINAPI
SetWindowLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
3954 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, FALSE
);
3957 /*****************************************************************************
3958 * RegisterTouchWindow (USER32.@)
3960 BOOL WINAPI
RegisterTouchWindow(HWND hwnd
, ULONG flags
)
3962 FIXME("(%p %08x): stub\n", hwnd
, flags
);
3963 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);