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"
36 #include "user_private.h"
39 #include "wine/gdi_driver.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win
);
44 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
45 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
47 static DWORD process_layout
= ~0u;
49 static struct list window_surfaces
= LIST_INIT( window_surfaces
);
51 static CRITICAL_SECTION surfaces_section
;
52 static CRITICAL_SECTION_DEBUG critsect_debug
=
54 0, 0, &surfaces_section
,
55 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
56 0, 0, { (DWORD_PTR
)(__FILE__
": surfaces_section") }
58 static CRITICAL_SECTION surfaces_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
60 /**********************************************************************/
62 /* helper for Get/SetWindowLong */
63 static inline LONG_PTR
get_win_data( const void *ptr
, UINT size
)
65 if (size
== sizeof(WORD
))
68 memcpy( &ret
, ptr
, sizeof(ret
) );
71 else if (size
== sizeof(DWORD
))
74 memcpy( &ret
, ptr
, sizeof(ret
) );
80 memcpy( &ret
, ptr
, sizeof(ret
) );
85 /* helper for Get/SetWindowLong */
86 static inline void set_win_data( void *ptr
, LONG_PTR val
, UINT size
)
88 if (size
== sizeof(WORD
))
91 memcpy( ptr
, &newval
, sizeof(newval
) );
93 else if (size
== sizeof(DWORD
))
96 memcpy( ptr
, &newval
, sizeof(newval
) );
100 memcpy( ptr
, &val
, sizeof(val
) );
105 static void *user_handles
[NB_USER_HANDLES
];
107 /***********************************************************************
110 HANDLE
alloc_user_handle( struct user_object
*ptr
, enum user_obj_type type
)
114 SERVER_START_REQ( alloc_user_handle
)
116 if (!wine_server_call_err( req
)) handle
= wine_server_ptr_handle( reply
->handle
);
122 UINT index
= USER_HANDLE_TO_INDEX( handle
);
124 assert( index
< NB_USER_HANDLES
);
125 ptr
->handle
= handle
;
127 InterlockedExchangePointer( &user_handles
[index
], ptr
);
133 /***********************************************************************
134 * get_user_handle_ptr
136 void *get_user_handle_ptr( HANDLE handle
, enum user_obj_type type
)
138 struct user_object
*ptr
;
139 WORD index
= USER_HANDLE_TO_INDEX( handle
);
141 if (index
>= NB_USER_HANDLES
) return NULL
;
144 if ((ptr
= user_handles
[index
]))
146 if (ptr
->type
== type
&&
147 ((UINT
)(UINT_PTR
)ptr
->handle
== (UINT
)(UINT_PTR
)handle
||
148 !HIWORD(handle
) || HIWORD(handle
) == 0xffff))
152 else ptr
= OBJ_OTHER_PROCESS
;
158 /***********************************************************************
159 * release_user_handle_ptr
161 void release_user_handle_ptr( void *ptr
)
163 assert( ptr
&& ptr
!= OBJ_OTHER_PROCESS
);
168 /***********************************************************************
171 void *free_user_handle( HANDLE handle
, enum user_obj_type type
)
173 struct user_object
*ptr
;
174 WORD index
= USER_HANDLE_TO_INDEX( handle
);
176 if ((ptr
= get_user_handle_ptr( handle
, type
)) && ptr
!= OBJ_OTHER_PROCESS
)
178 SERVER_START_REQ( free_user_handle
)
180 req
->handle
= wine_server_user_handle( handle
);
181 if (wine_server_call( req
)) ptr
= NULL
;
182 else InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
191 /***********************************************************************
192 * create_window_handle
194 * Create a window handle with the server.
196 static WND
*create_window_handle( HWND parent
, HWND owner
, LPCWSTR name
,
197 HINSTANCE instance
, BOOL unicode
)
201 HWND handle
= 0, full_parent
= 0, full_owner
= 0;
202 struct tagCLASS
*class = NULL
;
204 DPI_AWARENESS awareness
= GetAwarenessFromDpiAwarenessContext( GetThreadDpiAwarenessContext() );
207 SERVER_START_REQ( create_window
)
209 req
->parent
= wine_server_user_handle( parent
);
210 req
->owner
= wine_server_user_handle( owner
);
211 req
->instance
= wine_server_client_ptr( instance
);
212 req
->dpi
= GetDpiForSystem();
213 req
->awareness
= awareness
;
214 if (!(req
->atom
= get_int_atom_value( name
)) && name
)
215 wine_server_add_data( req
, name
, strlenW(name
)*sizeof(WCHAR
) );
216 if (!wine_server_call_err( req
))
218 handle
= wine_server_ptr_handle( reply
->handle
);
219 full_parent
= wine_server_ptr_handle( reply
->parent
);
220 full_owner
= wine_server_ptr_handle( reply
->owner
);
221 extra_bytes
= reply
->extra
;
223 awareness
= reply
->awareness
;
224 class = wine_server_get_ptr( reply
->class_ptr
);
231 WARN( "error %d creating window\n", GetLastError() );
235 if (!(win
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
236 sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
238 SERVER_START_REQ( destroy_window
)
240 req
->handle
= wine_server_user_handle( handle
);
241 wine_server_call( req
);
244 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
248 if (!parent
) /* if parent is 0 we don't have a desktop window yet */
250 struct user_thread_info
*thread_info
= get_user_thread_info();
252 if (name
== (LPCWSTR
)DESKTOP_CLASS_ATOM
)
254 if (!thread_info
->top_window
) thread_info
->top_window
= full_parent
? full_parent
: handle
;
255 else assert( full_parent
== thread_info
->top_window
);
256 if (full_parent
&& !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
257 ERR( "failed to create desktop window\n" );
259 else /* HWND_MESSAGE parent */
261 if (!thread_info
->msg_window
&& !full_parent
) thread_info
->msg_window
= handle
;
267 index
= USER_HANDLE_TO_INDEX(handle
);
268 assert( index
< NB_USER_HANDLES
);
269 win
->obj
.handle
= handle
;
270 win
->obj
.type
= USER_WINDOW
;
271 win
->parent
= full_parent
;
272 win
->owner
= full_owner
;
274 win
->winproc
= get_class_winproc( class );
275 win
->cbWndExtra
= extra_bytes
;
277 win
->dpi_awareness
= awareness
;
278 InterlockedExchangePointer( &user_handles
[index
], win
);
279 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
284 /***********************************************************************
287 * Free a window handle.
289 static void free_window_handle( HWND hwnd
)
291 struct user_object
*ptr
;
292 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
294 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) && ptr
!= OBJ_OTHER_PROCESS
)
296 SERVER_START_REQ( destroy_window
)
298 req
->handle
= wine_server_user_handle( hwnd
);
299 wine_server_call( req
);
300 InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
304 HeapFree( GetProcessHeap(), 0, ptr
);
309 /*******************************************************************
310 * list_window_children
312 * Build an array of the children of a given window. The array must be
313 * freed with HeapFree. Returns NULL when no windows are found.
315 static HWND
*list_window_children( HDESK desktop
, HWND hwnd
, LPCWSTR
class, DWORD tid
)
319 ATOM atom
= get_int_atom_value( class );
321 /* empty class is not the same as NULL class */
322 if (!atom
&& class && !class[0]) return NULL
;
328 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
330 SERVER_START_REQ( get_window_children
)
332 req
->desktop
= wine_server_obj_handle( desktop
);
333 req
->parent
= wine_server_user_handle( hwnd
);
336 if (!atom
&& class) wine_server_add_data( req
, class, strlenW(class)*sizeof(WCHAR
) );
337 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
338 if (!wine_server_call( req
)) count
= reply
->count
;
341 if (count
&& count
< size
)
343 /* start from the end since HWND is potentially larger than user_handle_t */
344 for (i
= count
- 1; i
>= 0; i
--)
345 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
349 HeapFree( GetProcessHeap(), 0, list
);
351 size
= count
+ 1; /* restart with a large enough buffer */
357 /*******************************************************************
358 * list_window_parents
360 * Build an array of all parents of a given window, starting with
361 * the immediate parent. The array must be freed with HeapFree.
363 static HWND
*list_window_parents( HWND hwnd
)
367 int i
, pos
= 0, size
= 16, count
;
369 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
374 if (!(win
= WIN_GetPtr( current
))) goto empty
;
375 if (win
== WND_OTHER_PROCESS
) break; /* need to do it the hard way */
376 if (win
== WND_DESKTOP
)
378 if (!pos
) goto empty
;
382 list
[pos
] = current
= win
->parent
;
383 WIN_ReleasePtr( win
);
384 if (!current
) return list
;
385 if (++pos
== size
- 1)
387 /* need to grow the list */
388 HWND
*new_list
= HeapReAlloc( GetProcessHeap(), 0, list
, (size
+16) * sizeof(HWND
) );
389 if (!new_list
) goto empty
;
395 /* at least one parent belongs to another process, have to query the server */
400 SERVER_START_REQ( get_window_parents
)
402 req
->handle
= wine_server_user_handle( hwnd
);
403 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
404 if (!wine_server_call( req
)) count
= reply
->count
;
407 if (!count
) goto empty
;
410 /* start from the end since HWND is potentially larger than user_handle_t */
411 for (i
= count
- 1; i
>= 0; i
--)
412 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
416 HeapFree( GetProcessHeap(), 0, list
);
418 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
422 HeapFree( GetProcessHeap(), 0, list
);
427 /*******************************************************************
430 static void send_parent_notify( HWND hwnd
, UINT msg
)
432 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
433 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
))
435 HWND parent
= GetParent(hwnd
);
436 if (parent
&& parent
!= GetDesktopWindow())
437 SendMessageW( parent
, WM_PARENTNOTIFY
,
438 MAKEWPARAM( msg
, GetWindowLongPtrW( hwnd
, GWLP_ID
)), (LPARAM
)hwnd
);
443 /*******************************************************************
444 * update_window_state
446 * Trigger an update of the window's driver state and surface.
448 void update_window_state( HWND hwnd
)
450 DPI_AWARENESS_CONTEXT context
;
451 RECT window_rect
, client_rect
, valid_rects
[2];
453 if (!WIN_IsCurrentThread( hwnd
))
455 PostMessageW( hwnd
, WM_WINE_UPDATEWINDOWSTATE
, 0, 0 );
459 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
460 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
461 valid_rects
[0] = valid_rects
[1] = client_rect
;
462 set_window_pos( hwnd
, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
|
463 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
,
464 &window_rect
, &client_rect
, valid_rects
);
465 SetThreadDpiAwarenessContext( context
);
469 /*******************************************************************
470 * get_server_window_text
472 * Retrieve the window text from the server.
474 static data_size_t
get_server_window_text( HWND hwnd
, WCHAR
*text
, data_size_t count
)
476 data_size_t len
= 0, needed
= 0;
478 SERVER_START_REQ( get_window_text
)
480 req
->handle
= wine_server_user_handle( hwnd
);
481 if (count
) wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
482 if (!wine_server_call_err( req
))
484 needed
= reply
->length
;
485 len
= wine_server_reply_size(reply
);
489 if (text
) text
[len
/ sizeof(WCHAR
)] = 0;
494 /*******************************************************************
495 * get_hwnd_message_parent
497 * Return the parent for HWND_MESSAGE windows.
499 HWND
get_hwnd_message_parent(void)
501 struct user_thread_info
*thread_info
= get_user_thread_info();
503 if (!thread_info
->msg_window
) GetDesktopWindow(); /* trigger creation */
504 return thread_info
->msg_window
;
508 /*******************************************************************
511 * Check if window is the desktop or the HWND_MESSAGE top parent.
513 BOOL
is_desktop_window( HWND hwnd
)
515 struct user_thread_info
*thread_info
= get_user_thread_info();
517 if (!hwnd
) return FALSE
;
518 if (hwnd
== thread_info
->top_window
) return TRUE
;
519 if (hwnd
== thread_info
->msg_window
) return TRUE
;
521 if (!HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff)
523 if (LOWORD(thread_info
->top_window
) == LOWORD(hwnd
)) return TRUE
;
524 if (LOWORD(thread_info
->msg_window
) == LOWORD(hwnd
)) return TRUE
;
530 /*******************************************************************
531 * Dummy window surface for windows that shouldn't get painted.
534 static void dummy_surface_lock( struct window_surface
*window_surface
)
539 static void dummy_surface_unlock( struct window_surface
*window_surface
)
544 static void *dummy_surface_get_bitmap_info( struct window_surface
*window_surface
, BITMAPINFO
*info
)
546 static DWORD dummy_data
;
548 info
->bmiHeader
.biSize
= sizeof( info
->bmiHeader
);
549 info
->bmiHeader
.biWidth
= dummy_surface
.rect
.right
;
550 info
->bmiHeader
.biHeight
= dummy_surface
.rect
.bottom
;
551 info
->bmiHeader
.biPlanes
= 1;
552 info
->bmiHeader
.biBitCount
= 32;
553 info
->bmiHeader
.biCompression
= BI_RGB
;
554 info
->bmiHeader
.biSizeImage
= 0;
555 info
->bmiHeader
.biXPelsPerMeter
= 0;
556 info
->bmiHeader
.biYPelsPerMeter
= 0;
557 info
->bmiHeader
.biClrUsed
= 0;
558 info
->bmiHeader
.biClrImportant
= 0;
562 static RECT
*dummy_surface_get_bounds( struct window_surface
*window_surface
)
564 static RECT dummy_bounds
;
565 return &dummy_bounds
;
568 static void dummy_surface_set_region( struct window_surface
*window_surface
, HRGN region
)
573 static void dummy_surface_flush( struct window_surface
*window_surface
)
578 static void dummy_surface_destroy( struct window_surface
*window_surface
)
583 static const struct window_surface_funcs dummy_surface_funcs
=
586 dummy_surface_unlock
,
587 dummy_surface_get_bitmap_info
,
588 dummy_surface_get_bounds
,
589 dummy_surface_set_region
,
591 dummy_surface_destroy
594 struct window_surface dummy_surface
= { &dummy_surface_funcs
, { NULL
, NULL
}, 1, { 0, 0, 1, 1 } };
597 /*******************************************************************
598 * register_window_surface
600 * Register a window surface in the global list, possibly replacing another one.
602 void register_window_surface( struct window_surface
*old
, struct window_surface
*new )
604 if (old
== new) return;
605 EnterCriticalSection( &surfaces_section
);
606 if (old
&& old
!= &dummy_surface
) list_remove( &old
->entry
);
607 if (new && new != &dummy_surface
) list_add_tail( &window_surfaces
, &new->entry
);
608 LeaveCriticalSection( &surfaces_section
);
612 /*******************************************************************
613 * flush_window_surfaces
615 * Flush pending output from all window surfaces.
617 void flush_window_surfaces( BOOL idle
)
619 static DWORD last_idle
;
621 struct window_surface
*surface
;
623 EnterCriticalSection( &surfaces_section
);
624 now
= GetTickCount();
625 if (idle
) last_idle
= now
;
626 /* if not idle, we only flush if there's evidence that the app never goes idle */
627 else if ((int)(now
- last_idle
) < 50) goto done
;
629 LIST_FOR_EACH_ENTRY( surface
, &window_surfaces
, struct window_surface
, entry
)
630 surface
->funcs
->flush( surface
);
632 LeaveCriticalSection( &surfaces_section
);
636 /***********************************************************************
639 * Return a pointer to the WND structure if local to the process,
640 * or WND_OTHER_PROCESS if handle may be valid in other process.
641 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
643 WND
*WIN_GetPtr( HWND hwnd
)
647 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) == WND_OTHER_PROCESS
)
649 if (is_desktop_window( hwnd
)) ptr
= WND_DESKTOP
;
655 /***********************************************************************
656 * WIN_IsCurrentProcess
658 * Check whether a given window belongs to the current process (and return the full handle).
660 HWND
WIN_IsCurrentProcess( HWND hwnd
)
665 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
666 ret
= ptr
->obj
.handle
;
667 WIN_ReleasePtr( ptr
);
672 /***********************************************************************
673 * WIN_IsCurrentThread
675 * Check whether a given window belongs to the current thread (and return the full handle).
677 HWND
WIN_IsCurrentThread( HWND hwnd
)
682 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
683 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->obj
.handle
;
684 WIN_ReleasePtr( ptr
);
689 /***********************************************************************
692 * Set the flags of a window and return the previous value.
694 UINT
win_set_flags( HWND hwnd
, UINT set_mask
, UINT clear_mask
)
697 WND
*ptr
= WIN_GetPtr( hwnd
);
699 if (!ptr
|| ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
701 ptr
->flags
= (ret
& ~clear_mask
) | set_mask
;
702 WIN_ReleasePtr( ptr
);
707 /***********************************************************************
710 * Convert a possibly truncated window handle to a full 32-bit handle.
712 HWND
WIN_GetFullHandle( HWND hwnd
)
716 if (!hwnd
|| (ULONG_PTR
)hwnd
>> 16) return hwnd
;
717 if (LOWORD(hwnd
) <= 1 || LOWORD(hwnd
) == 0xffff) return hwnd
;
718 /* do sign extension for -2 and -3 */
719 if (LOWORD(hwnd
) >= (WORD
)-3) return (HWND
)(LONG_PTR
)(INT16
)LOWORD(hwnd
);
721 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
723 if (ptr
== WND_DESKTOP
)
725 if (LOWORD(hwnd
) == LOWORD(GetDesktopWindow())) return GetDesktopWindow();
726 else return get_hwnd_message_parent();
729 if (ptr
!= WND_OTHER_PROCESS
)
731 hwnd
= ptr
->obj
.handle
;
732 WIN_ReleasePtr( ptr
);
734 else /* may belong to another process */
736 SERVER_START_REQ( get_window_info
)
738 req
->handle
= wine_server_user_handle( hwnd
);
739 if (!wine_server_call_err( req
)) hwnd
= wine_server_ptr_handle( reply
->full_handle
);
747 /***********************************************************************
750 * Change the owner of a window.
752 static HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
754 WND
*win
= WIN_GetPtr( hwnd
);
757 if (!win
|| win
== WND_DESKTOP
) return 0;
758 if (win
== WND_OTHER_PROCESS
)
760 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
763 SERVER_START_REQ( set_window_owner
)
765 req
->handle
= wine_server_user_handle( hwnd
);
766 req
->owner
= wine_server_user_handle( owner
);
767 if (!wine_server_call( req
))
769 win
->owner
= wine_server_ptr_handle( reply
->full_owner
);
770 ret
= wine_server_ptr_handle( reply
->prev_owner
);
774 WIN_ReleasePtr( win
);
779 /***********************************************************************
782 * Change the style of a window.
784 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
786 BOOL ok
, made_visible
= FALSE
;
788 WND
*win
= WIN_GetPtr( hwnd
);
790 if (!win
|| win
== WND_DESKTOP
) return 0;
791 if (win
== WND_OTHER_PROCESS
)
794 return SendMessageW(hwnd
, WM_WINE_SETSTYLE
, set_bits
, clear_bits
);
797 style
.styleOld
= win
->dwStyle
;
798 style
.styleNew
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
799 if (style
.styleNew
== style
.styleOld
)
801 WIN_ReleasePtr( win
);
802 return style
.styleNew
;
804 SERVER_START_REQ( set_window_info
)
806 req
->handle
= wine_server_user_handle( hwnd
);
807 req
->flags
= SET_WIN_STYLE
;
808 req
->style
= style
.styleNew
;
809 req
->extra_offset
= -1;
810 if ((ok
= !wine_server_call( req
)))
812 style
.styleOld
= reply
->old_style
;
813 win
->dwStyle
= style
.styleNew
;
818 if (ok
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
))
820 made_visible
= (style
.styleNew
& WS_VISIBLE
) != 0;
821 invalidate_dce( win
, NULL
);
823 WIN_ReleasePtr( win
);
827 USER_Driver
->pSetWindowStyle( hwnd
, GWL_STYLE
, &style
);
828 if (made_visible
) update_window_state( hwnd
);
830 return style
.styleOld
;
834 /***********************************************************************
837 * Get the window and client rectangles.
839 BOOL
WIN_GetRectangles( HWND hwnd
, enum coords_relative relative
, RECT
*rectWindow
, RECT
*rectClient
)
841 WND
*win
= WIN_GetPtr( hwnd
);
846 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
849 if (win
== WND_DESKTOP
)
852 rect
.left
= rect
.top
= 0;
853 if (hwnd
== get_hwnd_message_parent())
857 rect
= rect_win_to_thread_dpi( hwnd
, rect
);
861 rect
.right
= GetSystemMetrics(SM_CXSCREEN
);
862 rect
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
864 if (rectWindow
) *rectWindow
= rect
;
865 if (rectClient
) *rectClient
= rect
;
868 if (win
!= WND_OTHER_PROCESS
)
870 RECT window_rect
= win
->window_rect
, client_rect
= win
->client_rect
;
875 OffsetRect( &window_rect
, -win
->client_rect
.left
, -win
->client_rect
.top
);
876 OffsetRect( &client_rect
, -win
->client_rect
.left
, -win
->client_rect
.top
);
877 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
878 mirror_rect( &win
->client_rect
, &window_rect
);
881 OffsetRect( &window_rect
, -win
->window_rect
.left
, -win
->window_rect
.top
);
882 OffsetRect( &client_rect
, -win
->window_rect
.left
, -win
->window_rect
.top
);
883 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
884 mirror_rect( &win
->window_rect
, &client_rect
);
889 WND
*parent
= WIN_GetPtr( win
->parent
);
890 if (parent
== WND_DESKTOP
) break;
891 if (!parent
|| parent
== WND_OTHER_PROCESS
)
893 WIN_ReleasePtr( win
);
896 if (parent
->flags
& WIN_CHILDREN_MOVED
)
898 WIN_ReleasePtr( parent
);
899 WIN_ReleasePtr( win
);
902 if (parent
->dwExStyle
& WS_EX_LAYOUTRTL
)
904 mirror_rect( &parent
->client_rect
, &window_rect
);
905 mirror_rect( &parent
->client_rect
, &client_rect
);
907 WIN_ReleasePtr( parent
);
913 WND
*parent
= WIN_GetPtr( win
->parent
);
914 if (parent
== WND_DESKTOP
) break;
915 if (!parent
|| parent
== WND_OTHER_PROCESS
)
917 WIN_ReleasePtr( win
);
920 WIN_ReleasePtr( win
);
921 if (parent
->flags
& WIN_CHILDREN_MOVED
)
923 WIN_ReleasePtr( parent
);
929 OffsetRect( &window_rect
, win
->client_rect
.left
, win
->client_rect
.top
);
930 OffsetRect( &client_rect
, win
->client_rect
.left
, win
->client_rect
.top
);
935 if (rectWindow
) *rectWindow
= rect_win_to_thread_dpi( hwnd
, window_rect
);
936 if (rectClient
) *rectClient
= rect_win_to_thread_dpi( hwnd
, client_rect
);
937 WIN_ReleasePtr( win
);
942 SERVER_START_REQ( get_window_rectangles
)
944 req
->handle
= wine_server_user_handle( hwnd
);
945 req
->relative
= relative
;
946 req
->dpi
= get_thread_dpi();
947 if ((ret
= !wine_server_call_err( req
)))
951 rectWindow
->left
= reply
->window
.left
;
952 rectWindow
->top
= reply
->window
.top
;
953 rectWindow
->right
= reply
->window
.right
;
954 rectWindow
->bottom
= reply
->window
.bottom
;
958 rectClient
->left
= reply
->client
.left
;
959 rectClient
->top
= reply
->client
.top
;
960 rectClient
->right
= reply
->client
.right
;
961 rectClient
->bottom
= reply
->client
.bottom
;
970 /***********************************************************************
973 * Destroy storage associated to a window. "Internals" p.358
975 LRESULT
WIN_DestroyWindow( HWND hwnd
)
979 HMENU menu
= 0, sys_menu
;
980 struct window_surface
*surface
;
982 TRACE("%p\n", hwnd
);
984 /* destroy default IME window */
985 if (win_set_flags( hwnd
, 0, WIN_HAS_IME_WIN
) & WIN_HAS_IME_WIN
)
987 TRACE("unregister IME window for %p\n", hwnd
);
988 imm_unregister_window( hwnd
);
991 /* free child windows */
992 if ((list
= WIN_ListChildren( hwnd
)))
995 for (i
= 0; list
[i
]; i
++)
997 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
998 else SendNotifyMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
1000 HeapFree( GetProcessHeap(), 0, list
);
1003 /* Unlink now so we won't bother with the children later on */
1004 SERVER_START_REQ( set_parent
)
1006 req
->handle
= wine_server_user_handle( hwnd
);
1008 wine_server_call( req
);
1013 * Send the WM_NCDESTROY to the window being destroyed.
1015 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
1017 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
1019 /* free resources associated with the window */
1021 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1022 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1023 menu
= (HMENU
)wndPtr
->wIDmenu
;
1024 sys_menu
= wndPtr
->hSysMenu
;
1025 free_dce( wndPtr
->dce
, hwnd
);
1027 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
1028 wndPtr
->text
= NULL
;
1029 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
1030 wndPtr
->pScroll
= NULL
;
1031 DestroyIcon( wndPtr
->hIconSmall2
);
1032 surface
= wndPtr
->surface
;
1033 wndPtr
->surface
= NULL
;
1034 WIN_ReleasePtr( wndPtr
);
1036 if (menu
) DestroyMenu( menu
);
1037 if (sys_menu
) DestroyMenu( sys_menu
);
1040 register_window_surface( surface
, NULL
);
1041 window_surface_release( surface
);
1044 USER_Driver
->pDestroyWindow( hwnd
);
1046 free_window_handle( hwnd
);
1051 /***********************************************************************
1052 * next_thread_window
1054 static WND
*next_thread_window( HWND
*hwnd
)
1056 struct user_object
*ptr
;
1058 WORD index
= *hwnd
? USER_HANDLE_TO_INDEX( *hwnd
) + 1 : 0;
1061 while (index
< NB_USER_HANDLES
)
1063 if (!(ptr
= user_handles
[index
++])) continue;
1064 if (ptr
->type
!= USER_WINDOW
) continue;
1066 if (win
->tid
!= GetCurrentThreadId()) continue;
1067 *hwnd
= ptr
->handle
;
1075 /***********************************************************************
1076 * destroy_thread_windows
1078 * Destroy all window owned by the current thread.
1080 void destroy_thread_windows(void)
1083 HWND hwnd
= 0, *list
;
1084 HMENU menu
, sys_menu
;
1085 struct window_surface
*surface
;
1088 while ((wndPtr
= next_thread_window( &hwnd
)))
1090 /* destroy the client-side storage */
1092 list
= WIN_ListChildren( hwnd
);
1093 menu
= ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
) ? (HMENU
)wndPtr
->wIDmenu
: 0;
1094 sys_menu
= wndPtr
->hSysMenu
;
1095 free_dce( wndPtr
->dce
, hwnd
);
1096 surface
= wndPtr
->surface
;
1097 InterlockedCompareExchangePointer( &user_handles
[USER_HANDLE_TO_INDEX(hwnd
)], NULL
, wndPtr
);
1098 WIN_ReleasePtr( wndPtr
);
1099 HeapFree( GetProcessHeap(), 0, wndPtr
);
1100 if (menu
) DestroyMenu( menu
);
1101 if (sys_menu
) DestroyMenu( sys_menu
);
1104 register_window_surface( surface
, NULL
);
1105 window_surface_release( surface
);
1108 /* free child windows */
1110 if (!list
) continue;
1111 for (i
= 0; list
[i
]; i
++)
1112 if (!WIN_IsCurrentThread( list
[i
] ))
1113 SendNotifyMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
1114 HeapFree( GetProcessHeap(), 0, list
);
1119 /***********************************************************************
1120 * WIN_FixCoordinates
1122 * Fix the coordinates - Helper for WIN_CreateWindowEx.
1123 * returns default show mode in sw.
1125 static void WIN_FixCoordinates( CREATESTRUCTW
*cs
, INT
*sw
)
1127 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1130 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1134 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
1135 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= ULongToHandle(id
);
1137 TRACE("MDI child id %04x\n", id
);
1140 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
1142 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1144 if (IS_DEFAULT(cs
->x
))
1149 if (IS_DEFAULT(cs
->cx
) || !cs
->cx
) cs
->cx
= pos
[1].x
;
1150 if (IS_DEFAULT(cs
->cy
) || !cs
->cy
) cs
->cy
= pos
[1].y
;
1154 if (IS_DEFAULT(cs
->x
)) cs
->x
= cs
->y
= 0;
1155 if (IS_DEFAULT(cs
->cx
)) cs
->cx
= cs
->cy
= 0;
1158 else /* overlapped window */
1161 MONITORINFO mon_info
;
1164 if (!IS_DEFAULT(cs
->x
) && !IS_DEFAULT(cs
->cx
) && !IS_DEFAULT(cs
->cy
)) return;
1166 monitor
= MonitorFromWindow( cs
->hwndParent
, MONITOR_DEFAULTTOPRIMARY
);
1167 mon_info
.cbSize
= sizeof(mon_info
);
1168 GetMonitorInfoW( monitor
, &mon_info
);
1169 GetStartupInfoW( &info
);
1171 if (IS_DEFAULT(cs
->x
))
1173 if (!IS_DEFAULT(cs
->y
)) *sw
= cs
->y
;
1174 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: mon_info
.rcWork
.left
;
1175 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: mon_info
.rcWork
.top
;
1178 if (IS_DEFAULT(cs
->cx
))
1180 if (info
.dwFlags
& STARTF_USESIZE
)
1182 cs
->cx
= info
.dwXSize
;
1183 cs
->cy
= info
.dwYSize
;
1187 cs
->cx
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) * 3 / 4 - cs
->x
;
1188 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1191 /* neither x nor cx are default. Check the y values .
1192 * In the trace we see Outlook and Outlook Express using
1193 * cy set to CW_USEDEFAULT when opening the address book.
1195 else if (IS_DEFAULT(cs
->cy
))
1197 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
1198 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1204 /***********************************************************************
1205 * dump_window_styles
1207 static void dump_window_styles( DWORD style
, DWORD exstyle
)
1210 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
1211 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
1212 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
1213 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
1214 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
1215 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
1216 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
1217 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
1218 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
1221 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
1222 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
1224 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
1225 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
1226 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
1227 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
1228 if (style
& WS_CHILD
)
1230 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
1231 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
1235 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
1236 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
1239 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
1240 #define DUMPED_STYLES \
1241 ((DWORD)(WS_POPUP | \
1260 if(style
& ~DUMPED_STYLES
) TRACE(" %08x", style
& ~DUMPED_STYLES
);
1262 #undef DUMPED_STYLES
1264 TRACE( "exstyle:" );
1265 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
1266 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
1267 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
1268 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
1269 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
1270 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
1271 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
1272 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
1273 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
1274 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
1275 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
1276 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
1277 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
1278 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
1279 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
1280 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
1281 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
1282 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
1283 if(exstyle
& WS_EX_NOINHERITLAYOUT
) TRACE(" WS_EX_NOINHERITLAYOUT");
1284 if(exstyle
& WS_EX_LAYOUTRTL
) TRACE(" WS_EX_LAYOUTRTL");
1285 if(exstyle
& WS_EX_COMPOSITED
) TRACE(" WS_EX_COMPOSITED");
1286 if(exstyle
& WS_EX_NOACTIVATE
) TRACE(" WS_EX_NOACTIVATE");
1288 #define DUMPED_EX_STYLES \
1289 ((DWORD)(WS_EX_DLGMODALFRAME | \
1290 WS_EX_DRAGDETECT | \
1291 WS_EX_NOPARENTNOTIFY | \
1293 WS_EX_ACCEPTFILES | \
1294 WS_EX_TRANSPARENT | \
1296 WS_EX_TOOLWINDOW | \
1297 WS_EX_WINDOWEDGE | \
1298 WS_EX_CLIENTEDGE | \
1299 WS_EX_CONTEXTHELP | \
1301 WS_EX_RTLREADING | \
1302 WS_EX_LEFTSCROLLBAR | \
1303 WS_EX_CONTROLPARENT | \
1304 WS_EX_STATICEDGE | \
1307 WS_EX_NOINHERITLAYOUT | \
1312 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08x", exstyle
& ~DUMPED_EX_STYLES
);
1314 #undef DUMPED_EX_STYLES
1317 /***********************************************************************
1318 * map_dpi_create_struct
1320 static void map_dpi_create_struct( CREATESTRUCTW
*cs
, UINT dpi_from
, UINT dpi_to
)
1322 if (!dpi_from
&& !dpi_to
) return;
1323 if (!dpi_from
|| !dpi_to
)
1325 POINT pt
= { cs
->x
, cs
->y
};
1326 UINT mon_dpi
= get_monitor_dpi( MonitorFromPoint( pt
, MONITOR_DEFAULTTONEAREST
));
1327 if (!dpi_from
) dpi_from
= mon_dpi
;
1328 else dpi_to
= mon_dpi
;
1330 if (dpi_from
== dpi_to
) return;
1331 cs
->x
= MulDiv( cs
->x
, dpi_to
, dpi_from
);
1332 cs
->y
= MulDiv( cs
->y
, dpi_to
, dpi_from
);
1333 cs
->cx
= MulDiv( cs
->cx
, dpi_to
, dpi_from
);
1334 cs
->cy
= MulDiv( cs
->cy
, dpi_to
, dpi_from
);
1337 /***********************************************************************
1338 * WIN_CreateWindowEx
1340 * Implementation of CreateWindowEx().
1342 HWND
WIN_CreateWindowEx( CREATESTRUCTW
*cs
, LPCWSTR className
, HINSTANCE module
, BOOL unicode
)
1344 INT cx
, cy
, style
, sw
= SW_SHOW
;
1348 HWND hwnd
, parent
, owner
, top_child
= 0;
1349 const WCHAR
*p
= className
;
1350 UINT win_dpi
, thread_dpi
= get_thread_dpi();
1351 DPI_AWARENESS_CONTEXT context
;
1352 MDICREATESTRUCTW mdi_cs
;
1353 CBT_CREATEWNDW cbtc
;
1356 className
= CLASS_GetVersionedName(className
, NULL
, NULL
, TRUE
);
1358 TRACE("%s %s%s%s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
1359 unicode
? debugstr_w(cs
->lpszName
) : debugstr_a((LPCSTR
)cs
->lpszName
),
1360 debugstr_w(p
), p
!= className
? "->" : "", p
!= className
? debugstr_w(className
) : "",
1361 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
1362 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
1363 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
1365 /* Fix the styles for MDI children */
1366 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1368 if (!(win_get_flags( cs
->hwndParent
) & WIN_ISMDICLIENT
))
1370 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
1374 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
1375 * MDICREATESTRUCT members have the originally passed values.
1377 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
1378 * have the same layout.
1380 mdi_cs
.szClass
= cs
->lpszClass
;
1381 mdi_cs
.szTitle
= cs
->lpszName
;
1382 mdi_cs
.hOwner
= cs
->hInstance
;
1387 mdi_cs
.style
= cs
->style
;
1388 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
1390 cs
->lpCreateParams
= &mdi_cs
;
1392 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1394 if (cs
->style
& WS_POPUP
)
1396 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
1399 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
1403 cs
->style
&= ~WS_POPUP
;
1404 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1405 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1408 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
1412 /* Restore current maximized child */
1413 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
1415 TRACE("Restoring current maximized child %p\n", top_child
);
1416 if (cs
->style
& WS_MAXIMIZE
)
1418 /* if the new window is maximized don't bother repainting */
1419 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
1420 ShowWindow( top_child
, SW_SHOWNORMAL
);
1421 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
1423 else ShowWindow( top_child
, SW_SHOWNORMAL
);
1428 /* Find the parent window */
1430 parent
= cs
->hwndParent
;
1433 if (cs
->hwndParent
== HWND_MESSAGE
)
1435 cs
->hwndParent
= parent
= get_hwnd_message_parent();
1437 else if (cs
->hwndParent
)
1439 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1441 parent
= GetDesktopWindow();
1442 owner
= cs
->hwndParent
;
1446 DWORD parent_style
= GetWindowLongW( parent
, GWL_EXSTYLE
);
1447 if ((parent_style
& WS_EX_LAYOUTRTL
) && !(parent_style
& WS_EX_NOINHERITLAYOUT
))
1448 cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1453 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
1455 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1457 WARN("No parent for child window\n" );
1458 SetLastError(ERROR_TLW_WITH_WSCHILD
);
1459 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1462 /* are we creating the desktop or HWND_MESSAGE parent itself? */
1463 if (className
!= (LPCWSTR
)DESKTOP_CLASS_ATOM
&&
1464 (IS_INTRESOURCE(className
) || strcmpiW( className
, messageW
)))
1467 GetProcessDefaultLayout( &layout
);
1468 if (layout
& LAYOUT_RTL
) cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1469 parent
= GetDesktopWindow();
1473 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
1475 if ((cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1476 ((!(cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1477 (cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1478 cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1480 cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1482 /* Create the window structure */
1484 if (!(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1487 /* if it's a comctl32 class, GetClassInfo will load it, then we can retry */
1488 if (GetLastError() != ERROR_INVALID_HANDLE
||
1489 !GetClassInfoW( 0, className
, &wc
) ||
1490 !(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1493 hwnd
= wndPtr
->obj
.handle
;
1495 /* Fill the window structure */
1497 wndPtr
->tid
= GetCurrentThreadId();
1498 wndPtr
->hInstance
= cs
->hInstance
;
1499 wndPtr
->text
= NULL
;
1500 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
1501 wndPtr
->dwExStyle
= cs
->dwExStyle
;
1502 wndPtr
->wIDmenu
= 0;
1503 wndPtr
->helpContext
= 0;
1504 wndPtr
->pScroll
= NULL
;
1505 wndPtr
->userdata
= 0;
1507 wndPtr
->hIconSmall
= 0;
1508 wndPtr
->hIconSmall2
= 0;
1509 wndPtr
->hSysMenu
= 0;
1511 wndPtr
->min_pos
.x
= wndPtr
->min_pos
.y
= -1;
1512 wndPtr
->max_pos
.x
= wndPtr
->max_pos
.y
= -1;
1513 SetRect( &wndPtr
->normal_rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1515 if (wndPtr
->dwStyle
& WS_SYSMENU
) SetSystemMenu( hwnd
, 0 );
1518 * Correct the window styles.
1520 * It affects only the style loaded into the WIN structure.
1523 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1525 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1526 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1527 wndPtr
->dwStyle
|= WS_CAPTION
;
1530 /* WS_EX_WINDOWEDGE depends on some other styles */
1531 if (wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
)
1532 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1533 else if (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))
1535 if (!((wndPtr
->dwExStyle
& WS_EX_STATICEDGE
) &&
1536 (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
))))
1537 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1540 wndPtr
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1542 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1543 wndPtr
->flags
|= WIN_NEED_SIZE
;
1545 SERVER_START_REQ( set_window_info
)
1547 req
->handle
= wine_server_user_handle( hwnd
);
1548 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
| SET_WIN_UNICODE
;
1549 req
->style
= wndPtr
->dwStyle
;
1550 req
->ex_style
= wndPtr
->dwExStyle
;
1551 req
->instance
= wine_server_client_ptr( wndPtr
->hInstance
);
1552 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1553 req
->extra_offset
= -1;
1554 wine_server_call( req
);
1558 /* Set the window menu */
1560 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1564 if (!MENU_SetMenu(hwnd
, cs
->hMenu
))
1566 WIN_ReleasePtr( wndPtr
);
1567 free_window_handle( hwnd
);
1573 LPCWSTR menuName
= (LPCWSTR
)GetClassLongPtrW( hwnd
, GCLP_MENUNAME
);
1576 cs
->hMenu
= LoadMenuW( cs
->hInstance
, menuName
);
1577 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1581 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1583 style
= wndPtr
->dwStyle
;
1584 win_dpi
= wndPtr
->dpi
;
1585 WIN_ReleasePtr( wndPtr
);
1587 if (parent
) map_dpi_create_struct( cs
, thread_dpi
, win_dpi
);
1589 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
1591 /* call the WH_CBT hook */
1593 /* the window style passed to the hook must be the real window style,
1594 * rather than just the window style that the caller to CreateWindowEx
1595 * passed in, so we have to copy the original CREATESTRUCT and get the
1596 * the real style. */
1600 cbtc
.hwndInsertAfter
= HWND_TOP
;
1601 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
)) goto failed
;
1603 /* send the WM_GETMINMAXINFO message and fix the size if needed */
1607 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1609 MINMAXINFO info
= WINPOS_GetMinMaxInfo( hwnd
);
1610 cx
= max( min( cx
, info
.ptMaxTrackSize
.x
), info
.ptMinTrackSize
.x
);
1611 cy
= max( min( cy
, info
.ptMaxTrackSize
.y
), info
.ptMinTrackSize
.y
);
1616 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cx
, cs
->y
+ cy
);
1617 /* check for wraparound */
1618 if (cs
->x
> 0x7fffffff - cx
) rect
.right
= 0x7fffffff;
1619 if (cs
->y
> 0x7fffffff - cy
) rect
.bottom
= 0x7fffffff;
1620 if (!set_window_pos( hwnd
, 0, SWP_NOZORDER
| SWP_NOACTIVATE
, &rect
, &rect
, NULL
)) goto failed
;
1622 /* send WM_NCCREATE */
1624 TRACE( "hwnd %p cs %d,%d %dx%d %s\n", hwnd
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, wine_dbgstr_rect(&rect
) );
1626 result
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1628 result
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1631 WARN( "%p: aborted by WM_NCCREATE\n", hwnd
);
1635 /* create default IME window */
1637 if (imm_register_window
&& !is_desktop_window( hwnd
) &&
1638 parent
!= get_hwnd_message_parent() && imm_register_window( hwnd
))
1640 TRACE("register IME window for %p\n", hwnd
);
1641 win_set_flags( hwnd
, WIN_HAS_IME_WIN
, 0 );
1644 /* send WM_NCCALCSIZE */
1646 if (WIN_GetRectangles( hwnd
, COORDS_PARENT
, &rect
, NULL
))
1648 /* yes, even if the CBT hook was called with HWND_TOP */
1649 HWND insert_after
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1650 RECT client_rect
= rect
;
1652 /* the rectangle is in screen coords for WM_NCCALCSIZE when wparam is FALSE */
1653 MapWindowPoints( parent
, 0, (POINT
*)&client_rect
, 2 );
1654 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&client_rect
);
1655 MapWindowPoints( 0, parent
, (POINT
*)&client_rect
, 2 );
1656 set_window_pos( hwnd
, insert_after
, SWP_NOACTIVATE
, &rect
, &client_rect
, NULL
);
1660 /* send WM_CREATE */
1663 result
= SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1665 result
= SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1666 if (result
== -1) goto failed
;
1668 /* call the driver */
1670 if (!USER_Driver
->pCreateWindow( hwnd
)) goto failed
;
1672 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1674 /* send the size messages */
1676 if (!(win_get_flags( hwnd
) & WIN_NEED_SIZE
))
1678 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &rect
);
1679 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1680 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1681 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1684 /* Show the window, maximizing or minimizing if needed */
1686 style
= WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1687 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1690 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1692 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1693 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1694 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1695 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
, newPos
.right
- newPos
.left
,
1696 newPos
.bottom
- newPos
.top
, swFlag
);
1699 /* Notify the parent window only */
1701 send_parent_notify( hwnd
, WM_CREATE
);
1702 if (!IsWindow( hwnd
))
1704 SetThreadDpiAwarenessContext( context
);
1708 if (parent
== GetDesktopWindow())
1709 PostMessageW( parent
, WM_PARENTNOTIFY
, WM_CREATE
, (LPARAM
)hwnd
);
1711 if (cs
->style
& WS_VISIBLE
)
1713 if (cs
->style
& WS_MAXIMIZE
)
1715 else if (cs
->style
& WS_MINIMIZE
)
1716 sw
= SW_SHOWMINIMIZED
;
1718 ShowWindow( hwnd
, sw
);
1719 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1721 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1722 /* ShowWindow won't activate child windows */
1723 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1727 /* Call WH_SHELL hook */
1729 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1730 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1732 TRACE("created window %p\n", hwnd
);
1733 SetThreadDpiAwarenessContext( context
);
1737 WIN_DestroyWindow( hwnd
);
1738 SetThreadDpiAwarenessContext( context
);
1743 /***********************************************************************
1744 * CreateWindowExA (USER32.@)
1746 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1747 LPCSTR windowName
, DWORD style
, INT x
,
1748 INT y
, INT width
, INT height
,
1749 HWND parent
, HMENU menu
,
1750 HINSTANCE instance
, LPVOID data
)
1754 cs
.lpCreateParams
= data
;
1755 cs
.hInstance
= instance
;
1757 cs
.hwndParent
= parent
;
1763 cs
.lpszName
= windowName
;
1764 cs
.lpszClass
= className
;
1765 cs
.dwExStyle
= exStyle
;
1767 if (!IS_INTRESOURCE(className
))
1770 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, bufferW
, ARRAY_SIZE( bufferW
)))
1772 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, bufferW
, instance
, FALSE
);
1774 /* Note: we rely on the fact that CREATESTRUCTA and */
1775 /* CREATESTRUCTW have the same layout. */
1776 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, (LPCWSTR
)className
, instance
, FALSE
);
1780 /***********************************************************************
1781 * CreateWindowExW (USER32.@)
1783 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1784 LPCWSTR windowName
, DWORD style
, INT x
,
1785 INT y
, INT width
, INT height
,
1786 HWND parent
, HMENU menu
,
1787 HINSTANCE instance
, LPVOID data
)
1791 cs
.lpCreateParams
= data
;
1792 cs
.hInstance
= instance
;
1794 cs
.hwndParent
= parent
;
1800 cs
.lpszName
= windowName
;
1801 cs
.lpszClass
= className
;
1802 cs
.dwExStyle
= exStyle
;
1804 return wow_handlers
.create_window( &cs
, className
, instance
, TRUE
);
1808 /***********************************************************************
1809 * WIN_SendDestroyMsg
1811 static void WIN_SendDestroyMsg( HWND hwnd
)
1815 info
.cbSize
= sizeof(info
);
1816 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1818 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1819 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1822 if (hwnd
== GetClipboardOwner()) CLIPBOARD_ReleaseOwner( hwnd
);
1825 * Send the WM_DESTROY to the window.
1827 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1830 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1831 * make sure that the window still exists when we come back.
1838 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1840 for (i
= 0; pWndArray
[i
]; i
++)
1842 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1844 HeapFree( GetProcessHeap(), 0, pWndArray
);
1847 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1851 /***********************************************************************
1852 * DestroyWindow (USER32.@)
1854 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1858 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || is_desktop_window( hwnd
))
1860 SetLastError( ERROR_ACCESS_DENIED
);
1864 TRACE("(%p)\n", hwnd
);
1868 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
1870 if (MENU_IsMenuActive() == hwnd
)
1873 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
1877 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1878 send_parent_notify( hwnd
, WM_DESTROY
);
1880 else if (!GetWindow( hwnd
, GW_OWNER
))
1882 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1883 /* FIXME: clean up palette - see "Internals" p.352 */
1886 if (!IsWindow(hwnd
)) return TRUE
;
1888 /* Hide the window */
1889 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
1891 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1893 ShowWindow( hwnd
, SW_HIDE
);
1895 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1896 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1899 if (!IsWindow(hwnd
)) return TRUE
;
1901 /* Recursively destroy owned windows */
1908 BOOL got_one
= FALSE
;
1909 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1912 for (i
= 0; list
[i
]; i
++)
1914 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1915 if (WIN_IsCurrentThread( list
[i
] ))
1917 DestroyWindow( list
[i
] );
1921 WIN_SetOwner( list
[i
], 0 );
1923 HeapFree( GetProcessHeap(), 0, list
);
1925 if (!got_one
) break;
1929 /* Send destroy messages */
1931 WIN_SendDestroyMsg( hwnd
);
1932 if (!IsWindow( hwnd
)) return TRUE
;
1934 /* Destroy the window storage */
1936 WIN_DestroyWindow( hwnd
);
1941 /***********************************************************************
1942 * CloseWindow (USER32.@)
1944 BOOL WINAPI
CloseWindow( HWND hwnd
)
1946 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
1947 ShowWindow( hwnd
, SW_MINIMIZE
);
1952 /***********************************************************************
1953 * OpenIcon (USER32.@)
1955 BOOL WINAPI
OpenIcon( HWND hwnd
)
1957 if (!IsIconic( hwnd
)) return FALSE
;
1958 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1963 /***********************************************************************
1964 * FindWindowExW (USER32.@)
1966 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
, LPCWSTR className
, LPCWSTR title
)
1971 WCHAR
*buffer
= NULL
;
1973 if (!parent
&& child
) parent
= GetDesktopWindow();
1974 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
1978 len
= strlenW(title
) + 1; /* one extra char to check for chars beyond the end */
1979 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
1982 if (!(list
= list_window_children( 0, parent
, className
, 0 ))) goto done
;
1986 child
= WIN_GetFullHandle( child
);
1987 while (list
[i
] && list
[i
] != child
) i
++;
1988 if (!list
[i
]) goto done
;
1989 i
++; /* start from next window */
1996 if (InternalGetWindowText( list
[i
], buffer
, len
+ 1 ))
1998 if (!strcmpiW( buffer
, title
)) break;
2002 if (!title
[0]) break;
2010 HeapFree( GetProcessHeap(), 0, list
);
2011 HeapFree( GetProcessHeap(), 0, buffer
);
2017 /***********************************************************************
2018 * FindWindowA (USER32.@)
2020 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
2022 HWND ret
= FindWindowExA( 0, 0, className
, title
);
2023 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
2028 /***********************************************************************
2029 * FindWindowExA (USER32.@)
2031 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
, LPCSTR className
, LPCSTR title
)
2033 LPWSTR titleW
= NULL
;
2038 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
2039 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
2040 MultiByteToWideChar( CP_ACP
, 0, title
, -1, titleW
, len
);
2043 if (!IS_INTRESOURCE(className
))
2046 if (MultiByteToWideChar( CP_ACP
, 0, className
, -1, classW
, ARRAY_SIZE( classW
)))
2047 hwnd
= FindWindowExW( parent
, child
, classW
, titleW
);
2051 hwnd
= FindWindowExW( parent
, child
, (LPCWSTR
)className
, titleW
);
2054 HeapFree( GetProcessHeap(), 0, titleW
);
2059 /***********************************************************************
2060 * FindWindowW (USER32.@)
2062 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
2064 return FindWindowExW( 0, 0, className
, title
);
2068 /**********************************************************************
2069 * GetDesktopWindow (USER32.@)
2071 HWND WINAPI
GetDesktopWindow(void)
2073 struct user_thread_info
*thread_info
= get_user_thread_info();
2075 if (thread_info
->top_window
) return thread_info
->top_window
;
2077 SERVER_START_REQ( get_desktop_window
)
2080 if (!wine_server_call( req
))
2082 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2083 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2088 if (!thread_info
->top_window
)
2090 static const WCHAR explorer
[] = {'\\','e','x','p','l','o','r','e','r','.','e','x','e',0};
2091 static const WCHAR args
[] = {' ','/','d','e','s','k','t','o','p',0};
2093 PROCESS_INFORMATION pi
;
2094 WCHAR windir
[MAX_PATH
];
2095 WCHAR app
[MAX_PATH
+ ARRAY_SIZE( explorer
)];
2096 WCHAR cmdline
[MAX_PATH
+ ARRAY_SIZE( explorer
) + ARRAY_SIZE( args
)];
2097 WCHAR desktop
[MAX_PATH
];
2100 SERVER_START_REQ( set_user_object_info
)
2102 req
->handle
= wine_server_obj_handle( GetThreadDesktop(GetCurrentThreadId()) );
2103 req
->flags
= SET_USER_OBJECT_GET_FULL_NAME
;
2104 wine_server_set_reply( req
, desktop
, sizeof(desktop
) - sizeof(WCHAR
) );
2105 if (!wine_server_call( req
))
2107 size_t size
= wine_server_reply_size( reply
);
2108 desktop
[size
/ sizeof(WCHAR
)] = 0;
2109 TRACE( "starting explorer for desktop %s\n", debugstr_w(desktop
) );
2116 memset( &si
, 0, sizeof(si
) );
2118 si
.lpDesktop
= *desktop
? desktop
: NULL
;
2119 si
.dwFlags
= STARTF_USESTDHANDLES
;
2122 si
.hStdError
= GetStdHandle( STD_ERROR_HANDLE
);
2124 GetSystemDirectoryW( windir
, MAX_PATH
);
2125 strcpyW( app
, windir
);
2126 strcatW( app
, explorer
);
2127 strcpyW( cmdline
, app
);
2128 strcatW( cmdline
, args
);
2130 Wow64DisableWow64FsRedirection( &redir
);
2131 if (CreateProcessW( app
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
,
2132 NULL
, windir
, &si
, &pi
))
2134 TRACE( "started explorer pid %04x tid %04x\n", pi
.dwProcessId
, pi
.dwThreadId
);
2135 WaitForInputIdle( pi
.hProcess
, 10000 );
2136 CloseHandle( pi
.hThread
);
2137 CloseHandle( pi
.hProcess
);
2139 else WARN( "failed to start explorer, err %d\n", GetLastError() );
2140 Wow64RevertWow64FsRedirection( redir
);
2142 SERVER_START_REQ( get_desktop_window
)
2145 if (!wine_server_call( req
))
2147 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2148 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2154 if (!thread_info
->top_window
|| !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
2155 ERR( "failed to create desktop window\n" );
2157 return thread_info
->top_window
;
2161 /*******************************************************************
2162 * EnableWindow (USER32.@)
2164 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
2168 if (is_broadcast(hwnd
))
2170 SetLastError( ERROR_INVALID_PARAMETER
);
2174 TRACE("( %p, %d )\n", hwnd
, enable
);
2178 retvalue
= (WIN_SetStyle( hwnd
, 0, WS_DISABLED
) & WS_DISABLED
) != 0;
2179 if (retvalue
) SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
2183 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0 );
2185 retvalue
= (WIN_SetStyle( hwnd
, WS_DISABLED
, 0 ) & WS_DISABLED
) != 0;
2188 if (hwnd
== GetFocus())
2189 SetFocus( 0 ); /* A disabled window can't have the focus */
2191 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
2198 /***********************************************************************
2199 * IsWindowEnabled (USER32.@)
2201 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
2205 SetLastError(NO_ERROR
);
2206 ret
= GetWindowLongW( hWnd
, GWL_STYLE
);
2207 if (!ret
&& GetLastError() != NO_ERROR
) return FALSE
;
2208 return !(ret
& WS_DISABLED
);
2211 /***********************************************************************
2212 * IsWindowUnicode (USER32.@)
2214 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
2217 BOOL retvalue
= FALSE
;
2219 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
2221 if (wndPtr
== WND_DESKTOP
) return TRUE
;
2223 if (wndPtr
!= WND_OTHER_PROCESS
)
2225 retvalue
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2226 WIN_ReleasePtr( wndPtr
);
2230 SERVER_START_REQ( get_window_info
)
2232 req
->handle
= wine_server_user_handle( hwnd
);
2233 if (!wine_server_call_err( req
)) retvalue
= reply
->is_unicode
;
2241 /***********************************************************************
2242 * GetWindowDpiAwarenessContext (USER32.@)
2244 DPI_AWARENESS_CONTEXT WINAPI
GetWindowDpiAwarenessContext( HWND hwnd
)
2247 DPI_AWARENESS_CONTEXT ret
= 0;
2249 if (!(win
= WIN_GetPtr( hwnd
)))
2251 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2254 if (win
== WND_DESKTOP
) return DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
;
2255 if (win
!= WND_OTHER_PROCESS
)
2257 ret
= ULongToHandle( win
->dpi_awareness
| 0x10 );
2258 WIN_ReleasePtr( win
);
2262 SERVER_START_REQ( get_window_info
)
2264 req
->handle
= wine_server_user_handle( hwnd
);
2265 if (!wine_server_call_err( req
)) ret
= ULongToHandle( reply
->awareness
| 0x10 );
2273 /***********************************************************************
2274 * GetDpiForWindow (USER32.@)
2276 UINT WINAPI
GetDpiForWindow( HWND hwnd
)
2281 if (!(win
= WIN_GetPtr( hwnd
)))
2283 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2286 if (win
== WND_DESKTOP
)
2288 POINT pt
= { 0, 0 };
2289 return get_monitor_dpi( MonitorFromPoint( pt
, MONITOR_DEFAULTTOPRIMARY
));
2291 if (win
!= WND_OTHER_PROCESS
)
2294 if (!ret
) ret
= get_win_monitor_dpi( hwnd
);
2295 WIN_ReleasePtr( win
);
2299 SERVER_START_REQ( get_window_info
)
2301 req
->handle
= wine_server_user_handle( hwnd
);
2302 if (!wine_server_call_err( req
)) ret
= reply
->dpi
;
2310 /**********************************************************************
2313 * Helper function for GetWindowLong().
2315 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
2317 LONG_PTR retvalue
= 0;
2320 if (offset
== GWLP_HWNDPARENT
)
2322 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
2323 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
2324 return (ULONG_PTR
)parent
;
2327 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2329 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2333 if (wndPtr
== WND_DESKTOP
)
2338 retvalue
= WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
; /* message parent is not visible */
2339 if (WIN_GetFullHandle( hwnd
) == GetDesktopWindow())
2340 retvalue
|= WS_VISIBLE
;
2345 case GWLP_HINSTANCE
:
2348 SetLastError( ERROR_ACCESS_DENIED
);
2351 SetLastError( ERROR_INVALID_INDEX
);
2355 if (wndPtr
== WND_OTHER_PROCESS
)
2357 if (offset
== GWLP_WNDPROC
)
2359 SetLastError( ERROR_ACCESS_DENIED
);
2362 SERVER_START_REQ( set_window_info
)
2364 req
->handle
= wine_server_user_handle( hwnd
);
2365 req
->flags
= 0; /* don't set anything, just retrieve */
2366 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
2367 req
->extra_size
= (offset
>= 0) ? size
: 0;
2368 if (!wine_server_call_err( req
))
2372 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
2373 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
2374 case GWLP_ID
: retvalue
= reply
->old_id
; break;
2375 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
); break;
2376 case GWLP_USERDATA
: retvalue
= reply
->old_user_data
; break;
2378 if (offset
>= 0) retvalue
= get_win_data( &reply
->old_extra_value
, size
);
2379 else SetLastError( ERROR_INVALID_INDEX
);
2388 /* now we have a valid wndPtr */
2392 if (offset
> (int)(wndPtr
->cbWndExtra
- size
))
2394 WARN("Invalid offset %d\n", offset
);
2395 WIN_ReleasePtr( wndPtr
);
2396 SetLastError( ERROR_INVALID_INDEX
);
2399 retvalue
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2401 /* Special case for dialog window procedure */
2402 if ((offset
== DWLP_DLGPROC
) && (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2403 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, unicode
);
2404 WIN_ReleasePtr( wndPtr
);
2410 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
2411 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
2412 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
2413 case GWLP_ID
: retvalue
= wndPtr
->wIDmenu
; break;
2414 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
2416 /* This looks like a hack only for the edit control (see tests). This makes these controls
2417 * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests
2418 * that the hack is in GetWindowLongPtr[AW], not in winprocs.
2420 if (wndPtr
->winproc
== BUILTIN_WINPROC(WINPROC_EDIT
) && (!unicode
!= !(wndPtr
->flags
& WIN_ISUNICODE
)))
2421 retvalue
= (ULONG_PTR
)wndPtr
->winproc
;
2423 retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
);
2426 WARN("Unknown offset %d\n", offset
);
2427 SetLastError( ERROR_INVALID_INDEX
);
2430 WIN_ReleasePtr(wndPtr
);
2435 /**********************************************************************
2438 * Helper function for SetWindowLong().
2440 * 0 is the failure code. However, in the case of failure SetLastError
2441 * must be set to distinguish between a 0 return value and a failure.
2443 LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, UINT size
, LONG_PTR newval
, BOOL unicode
)
2446 BOOL ok
, made_visible
= FALSE
;
2447 LONG_PTR retval
= 0;
2450 TRACE( "%p %d %lx %c\n", hwnd
, offset
, newval
, unicode
? 'W' : 'A' );
2452 if (is_broadcast(hwnd
))
2454 SetLastError( ERROR_INVALID_PARAMETER
);
2458 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2460 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2463 if (wndPtr
== WND_DESKTOP
)
2465 /* can't change anything on the desktop window */
2466 SetLastError( ERROR_ACCESS_DENIED
);
2469 if (wndPtr
== WND_OTHER_PROCESS
)
2471 if (offset
== GWLP_WNDPROC
)
2473 SetLastError( ERROR_ACCESS_DENIED
);
2476 if (offset
> 32767 || offset
< -32767)
2478 SetLastError( ERROR_INVALID_INDEX
);
2481 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, MAKEWPARAM( offset
, size
), newval
);
2484 /* first some special cases */
2488 style
.styleOld
= wndPtr
->dwStyle
;
2489 style
.styleNew
= newval
;
2490 WIN_ReleasePtr( wndPtr
);
2491 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
)&style
);
2492 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2493 newval
= style
.styleNew
;
2494 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
2495 if (wndPtr
->parent
== GetDesktopWindow()) newval
|= WS_CLIPSIBLINGS
;
2496 /* WS_MINIMIZE can't be reset */
2497 if (wndPtr
->dwStyle
& WS_MINIMIZE
) newval
|= WS_MINIMIZE
;
2498 /* FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change
2499 WS_EX_WINDOWEDGE too */
2502 style
.styleOld
= wndPtr
->dwExStyle
;
2503 style
.styleNew
= newval
;
2504 WIN_ReleasePtr( wndPtr
);
2505 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
)&style
);
2506 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2507 /* WS_EX_TOPMOST can only be changed through SetWindowPos */
2508 newval
= (style
.styleNew
& ~WS_EX_TOPMOST
) | (wndPtr
->dwExStyle
& WS_EX_TOPMOST
);
2509 /* WS_EX_WINDOWEDGE depends on some other styles */
2510 if (newval
& WS_EX_DLGMODALFRAME
)
2511 newval
|= WS_EX_WINDOWEDGE
;
2512 else if (!(newval
& WS_EX_STATICEDGE
) && (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)))
2513 newval
|= WS_EX_WINDOWEDGE
;
2515 newval
&= ~WS_EX_WINDOWEDGE
;
2517 case GWLP_HWNDPARENT
:
2518 if (wndPtr
->parent
== GetDesktopWindow())
2520 WIN_ReleasePtr( wndPtr
);
2521 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
2525 WIN_ReleasePtr( wndPtr
);
2526 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
2531 UINT old_flags
= wndPtr
->flags
;
2532 retval
= WIN_GetWindowLong( hwnd
, offset
, size
, unicode
);
2533 proc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2534 if (proc
) wndPtr
->winproc
= proc
;
2535 if (WINPROC_IsUnicode( proc
, unicode
)) wndPtr
->flags
|= WIN_ISUNICODE
;
2536 else wndPtr
->flags
&= ~WIN_ISUNICODE
;
2537 if (!((old_flags
^ wndPtr
->flags
) & WIN_ISUNICODE
))
2539 WIN_ReleasePtr( wndPtr
);
2542 /* update is_unicode flag on the server side */
2546 case GWLP_HINSTANCE
:
2550 if ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2551 (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2553 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
2554 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, unicode
);
2555 *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2556 WIN_ReleasePtr( wndPtr
);
2561 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- size
))
2563 WARN("Invalid offset %d\n", offset
);
2564 WIN_ReleasePtr( wndPtr
);
2565 SetLastError( ERROR_INVALID_INDEX
);
2568 else if (get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
) == newval
)
2570 /* already set to the same value */
2571 WIN_ReleasePtr( wndPtr
);
2577 SERVER_START_REQ( set_window_info
)
2579 req
->handle
= wine_server_user_handle( hwnd
);
2580 req
->extra_offset
= -1;
2584 req
->flags
= SET_WIN_STYLE
;
2585 req
->style
= newval
;
2588 req
->flags
= SET_WIN_EXSTYLE
;
2589 req
->ex_style
= newval
;
2592 req
->flags
= SET_WIN_ID
;
2595 case GWLP_HINSTANCE
:
2596 req
->flags
= SET_WIN_INSTANCE
;
2597 req
->instance
= wine_server_client_ptr( (void *)newval
);
2600 req
->flags
= SET_WIN_UNICODE
;
2601 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2604 req
->flags
= SET_WIN_USERDATA
;
2605 req
->user_data
= newval
;
2608 req
->flags
= SET_WIN_EXTRA
;
2609 req
->extra_offset
= offset
;
2610 req
->extra_size
= size
;
2611 set_win_data( &req
->extra_value
, newval
, size
);
2613 if ((ok
= !wine_server_call_err( req
)))
2618 wndPtr
->dwStyle
= newval
;
2619 retval
= reply
->old_style
;
2622 wndPtr
->dwExStyle
= newval
;
2623 retval
= reply
->old_ex_style
;
2626 wndPtr
->wIDmenu
= newval
;
2627 retval
= reply
->old_id
;
2629 case GWLP_HINSTANCE
:
2630 wndPtr
->hInstance
= (HINSTANCE
)newval
;
2631 retval
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
2636 wndPtr
->userdata
= newval
;
2637 retval
= reply
->old_user_data
;
2640 retval
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2641 set_win_data( (char *)wndPtr
->wExtra
+ offset
, newval
, size
);
2648 if ((offset
== GWL_STYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
)) ||
2649 (offset
== GWL_EXSTYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_EX_LAYERED
)))
2651 made_visible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
2652 invalidate_dce( wndPtr
, NULL
);
2654 WIN_ReleasePtr( wndPtr
);
2658 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2660 style
.styleOld
= retval
;
2661 style
.styleNew
= newval
;
2662 USER_Driver
->pSetWindowStyle( hwnd
, offset
, &style
);
2663 if (made_visible
) update_window_state( hwnd
);
2664 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2671 /**********************************************************************
2672 * GetWindowWord (USER32.@)
2674 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
2679 case GWLP_HINSTANCE
:
2680 case GWLP_HWNDPARENT
:
2685 WARN("Invalid offset %d\n", offset
);
2686 SetLastError( ERROR_INVALID_INDEX
);
2691 return WIN_GetWindowLong( hwnd
, offset
, sizeof(WORD
), FALSE
);
2695 /**********************************************************************
2696 * GetWindowLongA (USER32.@)
2698 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2704 case GWLP_HINSTANCE
:
2705 case GWLP_HWNDPARENT
:
2706 WARN( "Invalid offset %d\n", offset
);
2707 SetLastError( ERROR_INVALID_INDEX
);
2711 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), FALSE
);
2716 /**********************************************************************
2717 * GetWindowLongW (USER32.@)
2719 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2725 case GWLP_HINSTANCE
:
2726 case GWLP_HWNDPARENT
:
2727 WARN( "Invalid offset %d\n", offset
);
2728 SetLastError( ERROR_INVALID_INDEX
);
2732 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), TRUE
);
2737 /**********************************************************************
2738 * SetWindowWord (USER32.@)
2740 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
2745 case GWLP_HINSTANCE
:
2746 case GWLP_HWNDPARENT
:
2751 WARN("Invalid offset %d\n", offset
);
2752 SetLastError( ERROR_INVALID_INDEX
);
2757 return WIN_SetWindowLong( hwnd
, offset
, sizeof(WORD
), newval
, FALSE
);
2761 /**********************************************************************
2762 * SetWindowLongA (USER32.@)
2764 * See SetWindowLongW.
2766 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2772 case GWLP_HINSTANCE
:
2773 case GWLP_HWNDPARENT
:
2774 WARN( "Invalid offset %d\n", offset
);
2775 SetLastError( ERROR_INVALID_INDEX
);
2779 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, FALSE
);
2784 /**********************************************************************
2785 * SetWindowLongW (USER32.@) Set window attribute
2787 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2788 * value in a window's extra memory.
2790 * The _hwnd_ parameter specifies the handle to a window that
2791 * has extra memory. The _newval_ parameter contains the new
2792 * attribute or extra memory value. If positive, the _offset_
2793 * parameter is the byte-addressed location in the window's extra
2794 * memory to set. If negative, _offset_ specifies the window
2795 * attribute to set, and should be one of the following values:
2797 * GWL_EXSTYLE The window's extended window style
2799 * GWL_STYLE The window's window style.
2801 * GWLP_WNDPROC Pointer to the window's window procedure.
2803 * GWLP_HINSTANCE The window's application instance handle.
2805 * GWLP_ID The window's identifier.
2807 * GWLP_USERDATA The window's user-specified data.
2809 * If the window is a dialog box, the _offset_ parameter can be one of
2810 * the following values:
2812 * DWLP_DLGPROC The address of the window's dialog box procedure.
2814 * DWLP_MSGRESULT The return value of a message
2815 * that the dialog box procedure processed.
2817 * DWLP_USER Application specific information.
2821 * If successful, returns the previous value located at _offset_. Otherwise,
2826 * Extra memory for a window class is specified by a nonzero cbWndExtra
2827 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2828 * time of class creation.
2830 * Using GWL_WNDPROC to set a new window procedure effectively creates
2831 * a window subclass. Use CallWindowProc() in the new windows procedure
2832 * to pass messages to the superclass's window procedure.
2834 * The user data is reserved for use by the application which created
2837 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2838 * instead, call the EnableWindow() function to change the window's
2841 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2842 * SetParent() instead.
2845 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2846 * it sends WM_STYLECHANGING before changing the settings
2847 * and WM_STYLECHANGED afterwards.
2848 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2850 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongW(
2851 HWND hwnd
, /* [in] window to alter */
2852 INT offset
, /* [in] offset, in bytes, of location to alter */
2853 LONG newval
/* [in] new value of location */
2860 case GWLP_HINSTANCE
:
2861 case GWLP_HWNDPARENT
:
2862 WARN("Invalid offset %d\n", offset
);
2863 SetLastError( ERROR_INVALID_INDEX
);
2867 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, TRUE
);
2872 /*******************************************************************
2873 * GetWindowTextA (USER32.@)
2875 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2879 if (!lpString
|| nMaxCount
<= 0) return 0;
2881 if (WIN_IsCurrentProcess( hwnd
))
2884 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2887 /* when window belongs to other process, don't send a message */
2888 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) ))) return 0;
2889 get_server_window_text( hwnd
, buffer
, nMaxCount
);
2890 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
2891 lpString
[nMaxCount
-1] = 0;
2892 HeapFree( GetProcessHeap(), 0, buffer
);
2893 return strlen(lpString
);
2897 /*******************************************************************
2898 * InternalGetWindowText (USER32.@)
2900 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2904 if (nMaxCount
<= 0) return 0;
2905 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
2906 if (win
== WND_DESKTOP
) lpString
[0] = 0;
2907 else if (win
!= WND_OTHER_PROCESS
)
2909 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
2910 else lpString
[0] = 0;
2911 WIN_ReleasePtr( win
);
2915 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2917 return strlenW(lpString
);
2921 /*******************************************************************
2922 * GetWindowTextW (USER32.@)
2924 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2926 if (!lpString
|| nMaxCount
<= 0) return 0;
2928 if (WIN_IsCurrentProcess( hwnd
))
2931 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2934 /* when window belongs to other process, don't send a message */
2935 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2936 return strlenW(lpString
);
2940 /*******************************************************************
2941 * SetWindowTextA (USER32.@)
2942 * SetWindowText (USER32.@)
2944 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2946 if (is_broadcast(hwnd
))
2948 SetLastError( ERROR_INVALID_PARAMETER
);
2951 if (!WIN_IsCurrentProcess( hwnd
))
2952 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2953 debugstr_a(lpString
), hwnd
);
2954 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2958 /*******************************************************************
2959 * SetWindowTextW (USER32.@)
2961 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2963 if (is_broadcast(hwnd
))
2965 SetLastError( ERROR_INVALID_PARAMETER
);
2968 if (!WIN_IsCurrentProcess( hwnd
))
2969 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2970 debugstr_w(lpString
), hwnd
);
2971 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2975 /*******************************************************************
2976 * GetWindowTextLengthA (USER32.@)
2978 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2982 if (WIN_IsCurrentProcess( hwnd
)) return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2984 /* when window belongs to other process, don't send a message */
2985 GetCPInfo( CP_ACP
, &info
);
2986 return get_server_window_text( hwnd
, NULL
, 0 ) * info
.MaxCharSize
;
2989 /*******************************************************************
2990 * GetWindowTextLengthW (USER32.@)
2992 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2994 if (WIN_IsCurrentProcess( hwnd
)) return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2996 /* when window belongs to other process, don't send a message */
2997 return get_server_window_text( hwnd
, NULL
, 0 );
3001 /*******************************************************************
3002 * IsWindow (USER32.@)
3004 BOOL WINAPI
IsWindow( HWND hwnd
)
3009 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
3010 if (ptr
== WND_DESKTOP
) return TRUE
;
3012 if (ptr
!= WND_OTHER_PROCESS
)
3014 WIN_ReleasePtr( ptr
);
3018 /* check other processes */
3019 SERVER_START_REQ( get_window_info
)
3021 req
->handle
= wine_server_user_handle( hwnd
);
3022 ret
= !wine_server_call_err( req
);
3029 /***********************************************************************
3030 * GetWindowThreadProcessId (USER32.@)
3032 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
3037 if (!(ptr
= WIN_GetPtr( hwnd
)))
3039 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3043 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
3045 /* got a valid window */
3047 if (process
) *process
= GetCurrentProcessId();
3048 WIN_ReleasePtr( ptr
);
3052 /* check other processes */
3053 SERVER_START_REQ( get_window_info
)
3055 req
->handle
= wine_server_user_handle( hwnd
);
3056 if (!wine_server_call_err( req
))
3058 tid
= (DWORD
)reply
->tid
;
3059 if (process
) *process
= (DWORD
)reply
->pid
;
3067 /*****************************************************************
3068 * GetParent (USER32.@)
3070 HWND WINAPI
GetParent( HWND hwnd
)
3075 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
3077 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3080 if (wndPtr
== WND_DESKTOP
) return 0;
3081 if (wndPtr
== WND_OTHER_PROCESS
)
3083 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3084 if (style
& (WS_POPUP
| WS_CHILD
))
3086 SERVER_START_REQ( get_window_tree
)
3088 req
->handle
= wine_server_user_handle( hwnd
);
3089 if (!wine_server_call_err( req
))
3091 if (style
& WS_POPUP
) retvalue
= wine_server_ptr_handle( reply
->owner
);
3092 else if (style
& WS_CHILD
) retvalue
= wine_server_ptr_handle( reply
->parent
);
3100 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
3101 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
3102 WIN_ReleasePtr( wndPtr
);
3108 /*****************************************************************
3109 * GetAncestor (USER32.@)
3111 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
3114 HWND
*list
, ret
= 0;
3119 if (!(win
= WIN_GetPtr( hwnd
)))
3121 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3124 if (win
== WND_DESKTOP
) return 0;
3125 if (win
!= WND_OTHER_PROCESS
)
3128 WIN_ReleasePtr( win
);
3130 else /* need to query the server */
3132 SERVER_START_REQ( get_window_tree
)
3134 req
->handle
= wine_server_user_handle( hwnd
);
3135 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->parent
);
3142 if (!(list
= list_window_parents( hwnd
))) return 0;
3144 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
3148 while (list
[count
]) count
++;
3149 ret
= list
[count
- 2]; /* get the one before the desktop */
3151 HeapFree( GetProcessHeap(), 0, list
);
3155 if (is_desktop_window( hwnd
)) return 0;
3156 ret
= WIN_GetFullHandle( hwnd
);
3159 HWND parent
= GetParent( ret
);
3169 /*****************************************************************
3170 * SetParent (USER32.@)
3172 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
3176 HWND old_parent
= 0;
3180 DPI_AWARENESS_CONTEXT context
;
3181 RECT window_rect
, old_screen_rect
, new_screen_rect
;
3183 TRACE("(%p %p)\n", hwnd
, parent
);
3185 if (is_broadcast(hwnd
) || is_broadcast(parent
))
3187 SetLastError(ERROR_INVALID_PARAMETER
);
3191 if (!parent
) parent
= GetDesktopWindow();
3192 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
3193 else parent
= WIN_GetFullHandle( parent
);
3195 if (!IsWindow( parent
))
3197 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3201 /* Some applications try to set a child as a parent */
3202 if (IsChild(hwnd
, parent
))
3204 SetLastError( ERROR_INVALID_PARAMETER
);
3208 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
3209 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
3211 if (full_handle
== parent
)
3213 SetLastError( ERROR_INVALID_PARAMETER
);
3217 /* Windows hides the window first, then shows it again
3218 * including the WM_SHOWWINDOW messages and all */
3219 was_visible
= ShowWindow( hwnd
, SW_HIDE
);
3221 wndPtr
= WIN_GetPtr( hwnd
);
3222 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
3224 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
3225 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, NULL
);
3226 SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
3227 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &old_screen_rect
, NULL
);
3228 SetThreadDpiAwarenessContext( context
);
3230 SERVER_START_REQ( set_parent
)
3232 req
->handle
= wine_server_user_handle( hwnd
);
3233 req
->parent
= wine_server_user_handle( parent
);
3234 if ((ret
= !wine_server_call( req
)))
3236 old_parent
= wine_server_ptr_handle( reply
->old_parent
);
3237 wndPtr
->parent
= parent
= wine_server_ptr_handle( reply
->full_parent
);
3238 wndPtr
->dpi
= reply
->dpi
;
3239 wndPtr
->dpi_awareness
= reply
->awareness
;
3244 WIN_ReleasePtr( wndPtr
);
3247 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
3248 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &new_screen_rect
, NULL
);
3249 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
3251 USER_Driver
->pSetParent( full_handle
, parent
, old_parent
);
3254 winpos
.hwndInsertAfter
= HWND_TOP
;
3255 winpos
.x
= window_rect
.left
;
3256 winpos
.y
= window_rect
.top
;
3259 winpos
.flags
= SWP_NOSIZE
;
3261 USER_SetWindowPos( &winpos
, new_screen_rect
.left
- old_screen_rect
.left
,
3262 new_screen_rect
.top
- old_screen_rect
.top
);
3264 if (was_visible
) ShowWindow( hwnd
, SW_SHOW
);
3266 SetThreadDpiAwarenessContext( context
);
3271 /*******************************************************************
3272 * IsChild (USER32.@)
3274 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
3280 if (!(GetWindowLongW( child
, GWL_STYLE
) & WS_CHILD
)) return FALSE
;
3281 if (!(list
= list_window_parents( child
))) return FALSE
;
3282 parent
= WIN_GetFullHandle( parent
);
3283 for (i
= 0; list
[i
]; i
++)
3285 if (list
[i
] == parent
)
3287 ret
= list
[i
] && list
[i
+1];
3290 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_CHILD
)) break;
3292 HeapFree( GetProcessHeap(), 0, list
);
3297 /***********************************************************************
3298 * IsWindowVisible (USER32.@)
3300 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
3306 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
3307 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3310 for (i
= 0; list
[i
+1]; i
++)
3311 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
3312 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3314 HeapFree( GetProcessHeap(), 0, list
);
3319 /***********************************************************************
3320 * WIN_IsWindowDrawable
3322 * hwnd is drawable when it is visible, all parents are not
3323 * minimized, and it is itself not minimized unless we are
3324 * trying to draw its default class icon.
3326 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
3331 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3333 if (!(style
& WS_VISIBLE
)) return FALSE
;
3334 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
3336 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3339 for (i
= 0; list
[i
+1]; i
++)
3340 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
3342 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3344 HeapFree( GetProcessHeap(), 0, list
);
3349 /*******************************************************************
3350 * GetTopWindow (USER32.@)
3352 HWND WINAPI
GetTopWindow( HWND hwnd
)
3354 if (!hwnd
) hwnd
= GetDesktopWindow();
3355 return GetWindow( hwnd
, GW_CHILD
);
3359 /*******************************************************************
3360 * GetWindow (USER32.@)
3362 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
3366 if (rel
== GW_OWNER
) /* this one may be available locally */
3368 WND
*wndPtr
= WIN_GetPtr( hwnd
);
3371 SetLastError( ERROR_INVALID_HANDLE
);
3374 if (wndPtr
== WND_DESKTOP
) return 0;
3375 if (wndPtr
!= WND_OTHER_PROCESS
)
3377 retval
= wndPtr
->owner
;
3378 WIN_ReleasePtr( wndPtr
);
3381 /* else fall through to server call */
3384 SERVER_START_REQ( get_window_tree
)
3386 req
->handle
= wine_server_user_handle( hwnd
);
3387 if (!wine_server_call_err( req
))
3392 retval
= wine_server_ptr_handle( reply
->first_sibling
);
3395 retval
= wine_server_ptr_handle( reply
->last_sibling
);
3398 retval
= wine_server_ptr_handle( reply
->next_sibling
);
3401 retval
= wine_server_ptr_handle( reply
->prev_sibling
);
3404 retval
= wine_server_ptr_handle( reply
->owner
);
3407 retval
= wine_server_ptr_handle( reply
->first_child
);
3417 /*******************************************************************
3418 * ShowOwnedPopups (USER32.@)
3420 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
3423 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
3425 if (!win_array
) return TRUE
;
3427 while (win_array
[count
]) count
++;
3428 while (--count
>= 0)
3430 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
3433 if (win_get_flags( win_array
[count
] ) & WIN_NEEDS_SHOW_OWNEDPOPUP
)
3434 /* In Windows, ShowOwnedPopups(TRUE) generates
3435 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
3436 * regardless of the state of the owner
3438 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
3442 if (GetWindowLongW( win_array
[count
], GWL_STYLE
) & WS_VISIBLE
)
3443 /* In Windows, ShowOwnedPopups(FALSE) generates
3444 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
3445 * regardless of the state of the owner
3447 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
3450 HeapFree( GetProcessHeap(), 0, win_array
);
3455 /*******************************************************************
3456 * GetLastActivePopup (USER32.@)
3458 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
3462 SERVER_START_REQ( get_window_info
)
3464 req
->handle
= wine_server_user_handle( hwnd
);
3465 if (!wine_server_call_err( req
)) retval
= wine_server_ptr_handle( reply
->last_active
);
3472 /*******************************************************************
3475 * Build an array of the children of a given window. The array must be
3476 * freed with HeapFree. Returns NULL when no windows are found.
3478 HWND
*WIN_ListChildren( HWND hwnd
)
3482 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3485 return list_window_children( 0, hwnd
, NULL
, 0 );
3489 /*******************************************************************
3490 * EnumWindows (USER32.@)
3492 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
3498 USER_CheckNotLock();
3500 /* We have to build a list of all windows first, to avoid */
3501 /* unpleasant side-effects, for instance if the callback */
3502 /* function changes the Z-order of the windows. */
3504 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
3506 /* Now call the callback function for every window */
3508 for (i
= 0; list
[i
]; i
++)
3510 /* Make sure that the window still exists */
3511 if (!IsWindow( list
[i
] )) continue;
3512 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
3514 HeapFree( GetProcessHeap(), 0, list
);
3519 /**********************************************************************
3520 * EnumThreadWindows (USER32.@)
3522 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
3528 USER_CheckNotLock();
3530 if (!(list
= list_window_children( 0, GetDesktopWindow(), NULL
, id
))) return TRUE
;
3532 /* Now call the callback function for every window */
3534 for (i
= 0; list
[i
]; i
++)
3535 if (!(ret
= func( list
[i
], lParam
))) break;
3536 HeapFree( GetProcessHeap(), 0, list
);
3541 /***********************************************************************
3542 * EnumDesktopWindows (USER32.@)
3544 BOOL WINAPI
EnumDesktopWindows( HDESK desktop
, WNDENUMPROC func
, LPARAM lparam
)
3549 USER_CheckNotLock();
3551 if (!(list
= list_window_children( desktop
, 0, NULL
, 0 ))) return TRUE
;
3553 for (i
= 0; list
[i
]; i
++)
3554 if (!func( list
[i
], lparam
)) break;
3555 HeapFree( GetProcessHeap(), 0, list
);
3561 /* Some apps pass a non-stdcall proc to EnumChildWindows,
3562 * so we need a small assembly wrapper to call the proc.
3564 extern LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
);
3565 __ASM_GLOBAL_FUNC( enum_callback_wrapper
,
3567 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
3568 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
3569 "movl %esp,%ebp\n\t"
3570 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
3571 "pushl 16(%ebp)\n\t"
3572 "pushl 12(%ebp)\n\t"
3575 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
3576 __ASM_CFI(".cfi_same_value %ebp\n\t")
3579 static inline LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
)
3581 return proc( hwnd
, lparam
);
3583 #endif /* __i386__ */
3585 /**********************************************************************
3586 * WIN_EnumChildWindows
3588 * Helper function for EnumChildWindows().
3590 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
3595 for ( ; *list
; list
++)
3597 /* Make sure that the window still exists */
3598 if (!IsWindow( *list
)) continue;
3599 /* Build children list first */
3600 childList
= WIN_ListChildren( *list
);
3602 ret
= enum_callback_wrapper( func
, *list
, lParam
);
3606 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
3607 HeapFree( GetProcessHeap(), 0, childList
);
3609 if (!ret
) return FALSE
;
3615 /**********************************************************************
3616 * EnumChildWindows (USER32.@)
3618 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
3623 USER_CheckNotLock();
3625 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
3626 ret
= WIN_EnumChildWindows( list
, func
, lParam
);
3627 HeapFree( GetProcessHeap(), 0, list
);
3632 /*******************************************************************
3633 * AnyPopup (USER32.@)
3635 BOOL WINAPI
AnyPopup(void)
3639 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
3641 if (!list
) return FALSE
;
3642 for (i
= 0; list
[i
]; i
++)
3644 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
3646 retvalue
= (list
[i
] != 0);
3647 HeapFree( GetProcessHeap(), 0, list
);
3652 /*******************************************************************
3653 * FlashWindow (USER32.@)
3655 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
3659 finfo
.cbSize
= sizeof(FLASHWINFO
);
3660 finfo
.dwFlags
= bInvert
? FLASHW_ALL
: FLASHW_STOP
;
3662 finfo
.dwTimeout
= 0;
3664 return FlashWindowEx( &finfo
);
3667 /*******************************************************************
3668 * FlashWindowEx (USER32.@)
3670 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfinfo
)
3674 TRACE( "%p\n", pfinfo
);
3678 SetLastError( ERROR_NOACCESS
);
3682 if (!pfinfo
->hwnd
|| pfinfo
->cbSize
!= sizeof(FLASHWINFO
) || !IsWindow( pfinfo
->hwnd
))
3684 SetLastError( ERROR_INVALID_PARAMETER
);
3687 FIXME( "%p - semi-stub\n", pfinfo
);
3689 if (IsIconic( pfinfo
->hwnd
))
3691 RedrawWindow( pfinfo
->hwnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
3693 wndPtr
= WIN_GetPtr( pfinfo
->hwnd
);
3694 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3695 if (pfinfo
->dwFlags
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
3697 wndPtr
->flags
|= WIN_NCACTIVATED
;
3701 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
3703 WIN_ReleasePtr( wndPtr
);
3704 USER_Driver
->pFlashWindowEx( pfinfo
);
3710 HWND hwnd
= pfinfo
->hwnd
;
3712 wndPtr
= WIN_GetPtr( hwnd
);
3713 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3714 hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
3716 if (pfinfo
->dwFlags
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
3717 else wparam
= (hwnd
== GetForegroundWindow());
3719 WIN_ReleasePtr( wndPtr
);
3720 SendMessageW( hwnd
, WM_NCACTIVATE
, wparam
, 0 );
3721 USER_Driver
->pFlashWindowEx( pfinfo
);
3726 /*******************************************************************
3727 * GetWindowContextHelpId (USER32.@)
3729 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
3732 WND
*wnd
= WIN_GetPtr( hwnd
);
3733 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
3734 if (wnd
== WND_OTHER_PROCESS
)
3736 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3739 retval
= wnd
->helpContext
;
3740 WIN_ReleasePtr( wnd
);
3745 /*******************************************************************
3746 * SetWindowContextHelpId (USER32.@)
3748 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
3750 WND
*wnd
= WIN_GetPtr( hwnd
);
3751 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
3752 if (wnd
== WND_OTHER_PROCESS
)
3754 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3757 wnd
->helpContext
= id
;
3758 WIN_ReleasePtr( wnd
);
3763 /*******************************************************************
3764 * DragDetect (USER32.@)
3766 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3770 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3771 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3773 SetRect(&rect
, pt
.x
- wDragWidth
, pt
.y
- wDragHeight
, pt
.x
+ wDragWidth
, pt
.y
+ wDragHeight
);
3779 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
3781 if( msg
.message
== WM_LBUTTONUP
)
3786 if( msg
.message
== WM_MOUSEMOVE
)
3789 tmp
.x
= (short)LOWORD(msg
.lParam
);
3790 tmp
.y
= (short)HIWORD(msg
.lParam
);
3791 if( !PtInRect( &rect
, tmp
))
3803 /******************************************************************************
3804 * GetWindowModuleFileNameA (USER32.@)
3806 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR module
, UINT size
)
3811 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3813 win
= WIN_GetPtr( hwnd
);
3814 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3816 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3819 hinst
= win
->hInstance
;
3820 WIN_ReleasePtr( win
);
3822 return GetModuleFileNameA( hinst
, module
, size
);
3825 /******************************************************************************
3826 * GetWindowModuleFileNameW (USER32.@)
3828 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR module
, UINT size
)
3833 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3835 win
= WIN_GetPtr( hwnd
);
3836 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3838 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3841 hinst
= win
->hInstance
;
3842 WIN_ReleasePtr( win
);
3844 return GetModuleFileNameW( hinst
, module
, size
);
3847 /******************************************************************************
3848 * GetWindowInfo (USER32.@)
3850 * Note: tests show that Windows doesn't check cbSize of the structure.
3852 BOOL WINAPI DECLSPEC_HOTPATCH
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
3854 RECT rcWindow
, rcClient
;
3856 if (!WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &rcWindow
, &rcClient
)) return FALSE
;
3857 if (!pwi
) return FALSE
;
3859 pwi
->rcWindow
= rcWindow
;
3860 pwi
->rcClient
= rcClient
;
3861 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3862 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3863 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
3865 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
3866 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
3868 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
3869 pwi
->wCreatorVersion
= 0x0400;
3874 /******************************************************************************
3875 * SwitchDesktop (USER32.@)
3877 * NOTES: Sets the current input or interactive desktop.
3879 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
3881 FIXME("(hwnd %p) stub!\n", hDesktop
);
3886 /***********************************************************************
3887 * __wine_set_pixel_format
3889 BOOL CDECL
__wine_set_pixel_format( HWND hwnd
, int format
)
3891 WND
*win
= WIN_GetPtr( hwnd
);
3893 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
3895 WARN( "setting format %d on win %p not supported\n", format
, hwnd
);
3898 win
->pixel_format
= format
;
3899 WIN_ReleasePtr( win
);
3901 update_window_state( hwnd
);
3906 /*****************************************************************************
3907 * SetLayeredWindowAttributes (USER32.@)
3909 BOOL WINAPI
SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
3913 TRACE("(%p,%08x,%d,%x)\n", hwnd
, key
, alpha
, flags
);
3915 SERVER_START_REQ( set_window_layered_info
)
3917 req
->handle
= wine_server_user_handle( hwnd
);
3918 req
->color_key
= key
;
3921 ret
= !wine_server_call_err( req
);
3927 USER_Driver
->pSetLayeredWindowAttributes( hwnd
, key
, alpha
, flags
);
3928 update_window_state( hwnd
);
3935 /*****************************************************************************
3936 * GetLayeredWindowAttributes (USER32.@)
3938 BOOL WINAPI
GetLayeredWindowAttributes( HWND hwnd
, COLORREF
*key
, BYTE
*alpha
, DWORD
*flags
)
3942 SERVER_START_REQ( get_window_layered_info
)
3944 req
->handle
= wine_server_user_handle( hwnd
);
3945 if ((ret
= !wine_server_call_err( req
)))
3947 if (key
) *key
= reply
->color_key
;
3948 if (alpha
) *alpha
= reply
->alpha
;
3949 if (flags
) *flags
= reply
->flags
;
3958 /*****************************************************************************
3959 * UpdateLayeredWindowIndirect (USER32.@)
3961 BOOL WINAPI
UpdateLayeredWindowIndirect( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
)
3963 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
;
3964 RECT window_rect
, client_rect
;
3968 info
->cbSize
!= sizeof(*info
) ||
3969 info
->dwFlags
& ~(ULW_COLORKEY
| ULW_ALPHA
| ULW_OPAQUE
| ULW_EX_NORESIZE
) ||
3970 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) ||
3971 GetLayeredWindowAttributes( hwnd
, NULL
, NULL
, NULL
))
3973 SetLastError( ERROR_INVALID_PARAMETER
);
3977 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
3981 offset
.cx
= info
->pptDst
->x
- window_rect
.left
;
3982 offset
.cy
= info
->pptDst
->y
- window_rect
.top
;
3983 OffsetRect( &client_rect
, offset
.cx
, offset
.cy
);
3984 OffsetRect( &window_rect
, offset
.cx
, offset
.cy
);
3985 flags
&= ~SWP_NOMOVE
;
3989 offset
.cx
= info
->psize
->cx
- (window_rect
.right
- window_rect
.left
);
3990 offset
.cy
= info
->psize
->cy
- (window_rect
.bottom
- window_rect
.top
);
3991 if (info
->psize
->cx
<= 0 || info
->psize
->cy
<= 0)
3993 SetLastError( ERROR_INVALID_PARAMETER
);
3996 if ((info
->dwFlags
& ULW_EX_NORESIZE
) && (offset
.cx
|| offset
.cy
))
3998 SetLastError( ERROR_INCORRECT_SIZE
);
4001 client_rect
.right
+= offset
.cx
;
4002 client_rect
.bottom
+= offset
.cy
;
4003 window_rect
.right
+= offset
.cx
;
4004 window_rect
.bottom
+= offset
.cy
;
4005 flags
&= ~SWP_NOSIZE
;
4008 TRACE( "window %p win %s client %s\n", hwnd
,
4009 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
) );
4011 if (!USER_Driver
->pUpdateLayeredWindow( hwnd
, info
, &window_rect
)) return FALSE
;
4013 set_window_pos( hwnd
, 0, flags
, &window_rect
, &client_rect
, NULL
);
4018 /*****************************************************************************
4019 * UpdateLayeredWindow (USER32.@)
4021 BOOL WINAPI
UpdateLayeredWindow( HWND hwnd
, HDC hdcDst
, POINT
*pptDst
, SIZE
*psize
,
4022 HDC hdcSrc
, POINT
*pptSrc
, COLORREF crKey
, BLENDFUNCTION
*pblend
,
4025 UPDATELAYEREDWINDOWINFO info
;
4027 if (flags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
4029 SetLastError( ERROR_INVALID_PARAMETER
);
4032 info
.cbSize
= sizeof(info
);
4033 info
.hdcDst
= hdcDst
;
4034 info
.pptDst
= pptDst
;
4036 info
.hdcSrc
= hdcSrc
;
4037 info
.pptSrc
= pptSrc
;
4039 info
.pblend
= pblend
;
4040 info
.dwFlags
= flags
;
4041 info
.prcDirty
= NULL
;
4042 return UpdateLayeredWindowIndirect( hwnd
, &info
);
4046 /******************************************************************************
4047 * GetProcessDefaultLayout [USER32.@]
4049 * Gets the default layout for parentless windows.
4051 BOOL WINAPI
GetProcessDefaultLayout( DWORD
*layout
)
4055 SetLastError( ERROR_NOACCESS
);
4058 if (process_layout
== ~0u)
4060 static const WCHAR translationW
[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
4061 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
4062 static const WCHAR filedescW
[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
4063 '\\','%','0','4','x','%','0','4','x',
4064 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0 };
4065 WCHAR
*str
, buffer
[MAX_PATH
];
4066 DWORD i
, len
, version_layout
= 0;
4067 DWORD user_lang
= GetUserDefaultLangID();
4071 GetModuleFileNameW( 0, buffer
, MAX_PATH
);
4072 if (!(len
= GetFileVersionInfoSizeW( buffer
, NULL
))) goto done
;
4073 if (!(data
= HeapAlloc( GetProcessHeap(), 0, len
))) goto done
;
4074 if (!GetFileVersionInfoW( buffer
, 0, len
, data
)) goto done
;
4075 if (!VerQueryValueW( data
, translationW
, (void **)&languages
, &len
) || !len
) goto done
;
4077 len
/= sizeof(DWORD
);
4078 for (i
= 0; i
< len
; i
++) if (LOWORD(languages
[i
]) == user_lang
) break;
4079 if (i
== len
) /* try neutral language */
4080 for (i
= 0; i
< len
; i
++)
4081 if (LOWORD(languages
[i
]) == MAKELANGID( PRIMARYLANGID(user_lang
), SUBLANG_NEUTRAL
)) break;
4082 if (i
== len
) i
= 0; /* default to the first one */
4084 sprintfW( buffer
, filedescW
, LOWORD(languages
[i
]), HIWORD(languages
[i
]) );
4085 if (!VerQueryValueW( data
, buffer
, (void **)&str
, &len
)) goto done
;
4086 TRACE( "found description %s\n", debugstr_w( str
));
4087 if (str
[0] == 0x200e && str
[1] == 0x200e) version_layout
= LAYOUT_RTL
;
4090 HeapFree( GetProcessHeap(), 0, data
);
4091 process_layout
= version_layout
;
4093 *layout
= process_layout
;
4098 /******************************************************************************
4099 * SetProcessDefaultLayout [USER32.@]
4101 * Sets the default layout for parentless windows.
4103 BOOL WINAPI
SetProcessDefaultLayout( DWORD layout
)
4105 process_layout
= layout
;
4110 /* 64bit versions */
4112 #ifdef GetWindowLongPtrW
4113 #undef GetWindowLongPtrW
4116 #ifdef GetWindowLongPtrA
4117 #undef GetWindowLongPtrA
4120 #ifdef SetWindowLongPtrW
4121 #undef SetWindowLongPtrW
4124 #ifdef SetWindowLongPtrA
4125 #undef SetWindowLongPtrA
4128 /*****************************************************************************
4129 * GetWindowLongPtrW (USER32.@)
4131 LONG_PTR WINAPI
GetWindowLongPtrW( HWND hwnd
, INT offset
)
4133 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), TRUE
);
4136 /*****************************************************************************
4137 * GetWindowLongPtrA (USER32.@)
4139 LONG_PTR WINAPI
GetWindowLongPtrA( HWND hwnd
, INT offset
)
4141 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), FALSE
);
4144 /*****************************************************************************
4145 * SetWindowLongPtrW (USER32.@)
4147 LONG_PTR WINAPI
SetWindowLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
4149 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, TRUE
);
4152 /*****************************************************************************
4153 * SetWindowLongPtrA (USER32.@)
4155 LONG_PTR WINAPI
SetWindowLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
4157 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, FALSE
);
4160 /*****************************************************************************
4161 * RegisterTouchWindow (USER32.@)
4163 BOOL WINAPI
RegisterTouchWindow(HWND hwnd
, ULONG flags
)
4165 FIXME("(%p %08x): stub\n", hwnd
, flags
);
4166 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4170 /*****************************************************************************
4171 * UnregisterTouchWindow (USER32.@)
4173 BOOL WINAPI
UnregisterTouchWindow(HWND hwnd
)
4175 FIXME("(%p): stub\n", hwnd
);
4176 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4180 /*****************************************************************************
4181 * CloseTouchInputHandle (USER32.@)
4183 BOOL WINAPI
CloseTouchInputHandle(HTOUCHINPUT handle
)
4185 FIXME("(%p): stub\n", handle
);
4186 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4190 /*****************************************************************************
4191 * GetTouchInputInfo (USER32.@)
4193 BOOL WINAPI
GetTouchInputInfo(HTOUCHINPUT handle
, UINT count
, TOUCHINPUT
*ptr
, int size
)
4195 FIXME("(%p %u %p %u): stub\n", handle
, count
, ptr
, size
);
4196 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4200 /*****************************************************************************
4201 * GetGestureInfo (USER32.@)
4203 BOOL WINAPI
GetGestureInfo(HGESTUREINFO handle
, PGESTUREINFO ptr
)
4205 FIXME("(%p %p): stub\n", handle
, ptr
);
4206 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4210 /*****************************************************************************
4211 * GetWindowDisplayAffinity (USER32.@)
4213 BOOL WINAPI
GetWindowDisplayAffinity(HWND hwnd
, DWORD
*affinity
)
4215 FIXME("(%p, %p): stub\n", hwnd
, affinity
);
4217 if (!hwnd
|| !affinity
)
4219 SetLastError(hwnd
? ERROR_NOACCESS
: ERROR_INVALID_WINDOW_HANDLE
);
4223 *affinity
= WDA_NONE
;
4227 /*****************************************************************************
4228 * SetWindowDisplayAffinity (USER32.@)
4230 BOOL WINAPI
SetWindowDisplayAffinity(HWND hwnd
, DWORD affinity
)
4232 FIXME("(%p, %u): stub\n", hwnd
, affinity
);
4236 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
4240 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4244 /**********************************************************************
4245 * SetWindowCompositionAttribute (USER32.@)
4247 BOOL WINAPI
SetWindowCompositionAttribute(HWND hwnd
, void *data
)
4249 FIXME("(%p, %p): stub\n", hwnd
, data
);
4250 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);