2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
32 #include "wine/server.h"
33 #include "wine/unicode.h"
35 #include "user_private.h"
38 #include "wine/gdi_driver.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win
);
43 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
44 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
46 static DWORD process_layout
= ~0u;
48 static struct list window_surfaces
= LIST_INIT( window_surfaces
);
50 static CRITICAL_SECTION surfaces_section
;
51 static CRITICAL_SECTION_DEBUG critsect_debug
=
53 0, 0, &surfaces_section
,
54 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
55 0, 0, { (DWORD_PTR
)(__FILE__
": surfaces_section") }
57 static CRITICAL_SECTION surfaces_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
59 /**********************************************************************/
61 /* helper for Get/SetWindowLong */
62 static inline LONG_PTR
get_win_data( const void *ptr
, UINT size
)
64 if (size
== sizeof(WORD
))
67 memcpy( &ret
, ptr
, sizeof(ret
) );
70 else if (size
== sizeof(DWORD
))
73 memcpy( &ret
, ptr
, sizeof(ret
) );
79 memcpy( &ret
, ptr
, sizeof(ret
) );
84 /* helper for Get/SetWindowLong */
85 static inline void set_win_data( void *ptr
, LONG_PTR val
, UINT size
)
87 if (size
== sizeof(WORD
))
90 memcpy( ptr
, &newval
, sizeof(newval
) );
92 else if (size
== sizeof(DWORD
))
95 memcpy( ptr
, &newval
, sizeof(newval
) );
99 memcpy( ptr
, &val
, sizeof(val
) );
104 static void *user_handles
[NB_USER_HANDLES
];
106 /***********************************************************************
109 HANDLE
alloc_user_handle( struct user_object
*ptr
, enum user_obj_type type
)
113 SERVER_START_REQ( alloc_user_handle
)
115 if (!wine_server_call_err( req
)) handle
= wine_server_ptr_handle( reply
->handle
);
121 UINT index
= USER_HANDLE_TO_INDEX( handle
);
123 assert( index
< NB_USER_HANDLES
);
124 ptr
->handle
= handle
;
126 InterlockedExchangePointer( &user_handles
[index
], ptr
);
132 /***********************************************************************
133 * get_user_handle_ptr
135 void *get_user_handle_ptr( HANDLE handle
, enum user_obj_type type
)
137 struct user_object
*ptr
;
138 WORD index
= USER_HANDLE_TO_INDEX( handle
);
140 if (index
>= NB_USER_HANDLES
) return NULL
;
143 if ((ptr
= user_handles
[index
]))
145 if (ptr
->type
== type
&&
146 ((UINT
)(UINT_PTR
)ptr
->handle
== (UINT
)(UINT_PTR
)handle
||
147 !HIWORD(handle
) || HIWORD(handle
) == 0xffff))
151 else ptr
= OBJ_OTHER_PROCESS
;
157 /***********************************************************************
158 * release_user_handle_ptr
160 void release_user_handle_ptr( void *ptr
)
162 assert( ptr
&& ptr
!= OBJ_OTHER_PROCESS
);
167 /***********************************************************************
170 void *free_user_handle( HANDLE handle
, enum user_obj_type type
)
172 struct user_object
*ptr
;
173 WORD index
= USER_HANDLE_TO_INDEX( handle
);
175 if ((ptr
= get_user_handle_ptr( handle
, type
)) && ptr
!= OBJ_OTHER_PROCESS
)
177 SERVER_START_REQ( free_user_handle
)
179 req
->handle
= wine_server_user_handle( handle
);
180 if (wine_server_call( req
)) ptr
= NULL
;
181 else InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
190 /***********************************************************************
191 * create_window_handle
193 * Create a window handle with the server.
195 static WND
*create_window_handle( HWND parent
, HWND owner
, LPCWSTR name
,
196 HINSTANCE instance
, BOOL unicode
)
200 HWND handle
= 0, full_parent
= 0, full_owner
= 0;
201 struct tagCLASS
*class = NULL
;
203 DPI_AWARENESS awareness
= GetAwarenessFromDpiAwarenessContext( GetThreadDpiAwarenessContext() );
206 SERVER_START_REQ( create_window
)
208 req
->parent
= wine_server_user_handle( parent
);
209 req
->owner
= wine_server_user_handle( owner
);
210 req
->instance
= wine_server_client_ptr( instance
);
211 req
->dpi
= GetDpiForSystem();
212 req
->awareness
= awareness
;
213 if (!(req
->atom
= get_int_atom_value( name
)) && name
)
214 wine_server_add_data( req
, name
, strlenW(name
)*sizeof(WCHAR
) );
215 if (!wine_server_call_err( req
))
217 handle
= wine_server_ptr_handle( reply
->handle
);
218 full_parent
= wine_server_ptr_handle( reply
->parent
);
219 full_owner
= wine_server_ptr_handle( reply
->owner
);
220 extra_bytes
= reply
->extra
;
222 awareness
= reply
->awareness
;
223 class = wine_server_get_ptr( reply
->class_ptr
);
230 WARN( "error %d creating window\n", GetLastError() );
234 if (!(win
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
235 sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
237 SERVER_START_REQ( destroy_window
)
239 req
->handle
= wine_server_user_handle( handle
);
240 wine_server_call( req
);
243 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
247 if (!parent
) /* if parent is 0 we don't have a desktop window yet */
249 struct user_thread_info
*thread_info
= get_user_thread_info();
251 if (name
== (LPCWSTR
)DESKTOP_CLASS_ATOM
)
253 if (!thread_info
->top_window
) thread_info
->top_window
= full_parent
? full_parent
: handle
;
254 else assert( full_parent
== thread_info
->top_window
);
255 if (full_parent
&& !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
256 ERR( "failed to create desktop window\n" );
258 else /* HWND_MESSAGE parent */
260 if (!thread_info
->msg_window
&& !full_parent
) thread_info
->msg_window
= handle
;
266 index
= USER_HANDLE_TO_INDEX(handle
);
267 assert( index
< NB_USER_HANDLES
);
268 win
->obj
.handle
= handle
;
269 win
->obj
.type
= USER_WINDOW
;
270 win
->parent
= full_parent
;
271 win
->owner
= full_owner
;
273 win
->winproc
= get_class_winproc( class );
274 win
->cbWndExtra
= extra_bytes
;
276 win
->dpi_awareness
= awareness
;
277 InterlockedExchangePointer( &user_handles
[index
], win
);
278 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
283 /***********************************************************************
286 * Free a window handle.
288 static void free_window_handle( HWND hwnd
)
290 struct user_object
*ptr
;
291 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
293 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) && ptr
!= OBJ_OTHER_PROCESS
)
295 SERVER_START_REQ( destroy_window
)
297 req
->handle
= wine_server_user_handle( hwnd
);
298 wine_server_call( req
);
299 InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
303 HeapFree( GetProcessHeap(), 0, ptr
);
308 /*******************************************************************
309 * list_window_children
311 * Build an array of the children of a given window. The array must be
312 * freed with HeapFree. Returns NULL when no windows are found.
314 static HWND
*list_window_children( HDESK desktop
, HWND hwnd
, LPCWSTR
class, DWORD tid
)
318 ATOM atom
= get_int_atom_value( class );
320 /* empty class is not the same as NULL class */
321 if (!atom
&& class && !class[0]) return NULL
;
327 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
329 SERVER_START_REQ( get_window_children
)
331 req
->desktop
= wine_server_obj_handle( desktop
);
332 req
->parent
= wine_server_user_handle( hwnd
);
335 if (!atom
&& class) wine_server_add_data( req
, class, strlenW(class)*sizeof(WCHAR
) );
336 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
337 if (!wine_server_call( req
)) count
= reply
->count
;
340 if (count
&& count
< size
)
342 /* start from the end since HWND is potentially larger than user_handle_t */
343 for (i
= count
- 1; i
>= 0; i
--)
344 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
348 HeapFree( GetProcessHeap(), 0, list
);
350 size
= count
+ 1; /* restart with a large enough buffer */
356 /*******************************************************************
357 * list_window_parents
359 * Build an array of all parents of a given window, starting with
360 * the immediate parent. The array must be freed with HeapFree.
362 static HWND
*list_window_parents( HWND hwnd
)
366 int i
, pos
= 0, size
= 16, count
;
368 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
373 if (!(win
= WIN_GetPtr( current
))) goto empty
;
374 if (win
== WND_OTHER_PROCESS
) break; /* need to do it the hard way */
375 if (win
== WND_DESKTOP
)
377 if (!pos
) goto empty
;
381 list
[pos
] = current
= win
->parent
;
382 WIN_ReleasePtr( win
);
383 if (!current
) return list
;
384 if (++pos
== size
- 1)
386 /* need to grow the list */
387 HWND
*new_list
= HeapReAlloc( GetProcessHeap(), 0, list
, (size
+16) * sizeof(HWND
) );
388 if (!new_list
) goto empty
;
394 /* at least one parent belongs to another process, have to query the server */
399 SERVER_START_REQ( get_window_parents
)
401 req
->handle
= wine_server_user_handle( hwnd
);
402 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
403 if (!wine_server_call( req
)) count
= reply
->count
;
406 if (!count
) goto empty
;
409 /* start from the end since HWND is potentially larger than user_handle_t */
410 for (i
= count
- 1; i
>= 0; i
--)
411 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
415 HeapFree( GetProcessHeap(), 0, list
);
417 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
421 HeapFree( GetProcessHeap(), 0, list
);
426 /*******************************************************************
429 static void send_parent_notify( HWND hwnd
, UINT msg
)
431 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
432 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
))
434 HWND parent
= GetParent(hwnd
);
435 if (parent
&& parent
!= GetDesktopWindow())
436 SendMessageW( parent
, WM_PARENTNOTIFY
,
437 MAKEWPARAM( msg
, GetWindowLongPtrW( hwnd
, GWLP_ID
)), (LPARAM
)hwnd
);
442 /*******************************************************************
443 * update_window_state
445 * Trigger an update of the window's driver state and surface.
447 static void update_window_state( HWND hwnd
)
449 DPI_AWARENESS_CONTEXT context
;
450 RECT window_rect
, client_rect
, valid_rects
[2];
452 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
453 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
454 valid_rects
[0] = valid_rects
[1] = client_rect
;
455 set_window_pos( hwnd
, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
|
456 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
,
457 &window_rect
, &client_rect
, valid_rects
);
458 SetThreadDpiAwarenessContext( context
);
462 /*******************************************************************
463 * get_server_window_text
465 * Retrieve the window text from the server.
467 static data_size_t
get_server_window_text( HWND hwnd
, WCHAR
*text
, data_size_t count
)
469 data_size_t len
= 0, needed
= 0;
471 SERVER_START_REQ( get_window_text
)
473 req
->handle
= wine_server_user_handle( hwnd
);
474 if (count
) wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
475 if (!wine_server_call_err( req
))
477 needed
= reply
->length
;
478 len
= wine_server_reply_size(reply
);
482 if (text
) text
[len
/ sizeof(WCHAR
)] = 0;
487 /*******************************************************************
488 * get_hwnd_message_parent
490 * Return the parent for HWND_MESSAGE windows.
492 HWND
get_hwnd_message_parent(void)
494 struct user_thread_info
*thread_info
= get_user_thread_info();
496 if (!thread_info
->msg_window
) GetDesktopWindow(); /* trigger creation */
497 return thread_info
->msg_window
;
501 /*******************************************************************
504 * Check if window is the desktop or the HWND_MESSAGE top parent.
506 BOOL
is_desktop_window( HWND hwnd
)
508 struct user_thread_info
*thread_info
= get_user_thread_info();
510 if (!hwnd
) return FALSE
;
511 if (hwnd
== thread_info
->top_window
) return TRUE
;
512 if (hwnd
== thread_info
->msg_window
) return TRUE
;
514 if (!HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff)
516 if (LOWORD(thread_info
->top_window
) == LOWORD(hwnd
)) return TRUE
;
517 if (LOWORD(thread_info
->msg_window
) == LOWORD(hwnd
)) return TRUE
;
523 /*******************************************************************
524 * Dummy window surface for windows that shouldn't get painted.
527 static void dummy_surface_lock( struct window_surface
*window_surface
)
532 static void dummy_surface_unlock( struct window_surface
*window_surface
)
537 static void *dummy_surface_get_bitmap_info( struct window_surface
*window_surface
, BITMAPINFO
*info
)
539 static DWORD dummy_data
;
541 info
->bmiHeader
.biSize
= sizeof( info
->bmiHeader
);
542 info
->bmiHeader
.biWidth
= dummy_surface
.rect
.right
;
543 info
->bmiHeader
.biHeight
= dummy_surface
.rect
.bottom
;
544 info
->bmiHeader
.biPlanes
= 1;
545 info
->bmiHeader
.biBitCount
= 32;
546 info
->bmiHeader
.biCompression
= BI_RGB
;
547 info
->bmiHeader
.biSizeImage
= 0;
548 info
->bmiHeader
.biXPelsPerMeter
= 0;
549 info
->bmiHeader
.biYPelsPerMeter
= 0;
550 info
->bmiHeader
.biClrUsed
= 0;
551 info
->bmiHeader
.biClrImportant
= 0;
555 static RECT
*dummy_surface_get_bounds( struct window_surface
*window_surface
)
557 static RECT dummy_bounds
;
558 return &dummy_bounds
;
561 static void dummy_surface_set_region( struct window_surface
*window_surface
, HRGN region
)
566 static void dummy_surface_flush( struct window_surface
*window_surface
)
571 static void dummy_surface_destroy( struct window_surface
*window_surface
)
576 static const struct window_surface_funcs dummy_surface_funcs
=
579 dummy_surface_unlock
,
580 dummy_surface_get_bitmap_info
,
581 dummy_surface_get_bounds
,
582 dummy_surface_set_region
,
584 dummy_surface_destroy
587 struct window_surface dummy_surface
= { &dummy_surface_funcs
, { NULL
, NULL
}, 1, { 0, 0, 1, 1 } };
590 /*******************************************************************
591 * register_window_surface
593 * Register a window surface in the global list, possibly replacing another one.
595 void register_window_surface( struct window_surface
*old
, struct window_surface
*new )
597 if (old
== new) return;
598 EnterCriticalSection( &surfaces_section
);
599 if (old
&& old
!= &dummy_surface
) list_remove( &old
->entry
);
600 if (new && new != &dummy_surface
) list_add_tail( &window_surfaces
, &new->entry
);
601 LeaveCriticalSection( &surfaces_section
);
605 /*******************************************************************
606 * flush_window_surfaces
608 * Flush pending output from all window surfaces.
610 void flush_window_surfaces( BOOL idle
)
612 static DWORD last_idle
;
614 struct window_surface
*surface
;
616 EnterCriticalSection( &surfaces_section
);
617 now
= GetTickCount();
618 if (idle
) last_idle
= now
;
619 /* if not idle, we only flush if there's evidence that the app never goes idle */
620 else if ((int)(now
- last_idle
) < 50) goto done
;
622 LIST_FOR_EACH_ENTRY( surface
, &window_surfaces
, struct window_surface
, entry
)
623 surface
->funcs
->flush( surface
);
625 LeaveCriticalSection( &surfaces_section
);
629 /***********************************************************************
632 * Return a pointer to the WND structure if local to the process,
633 * or WND_OTHER_PROCESS if handle may be valid in other process.
634 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
636 WND
*WIN_GetPtr( HWND hwnd
)
640 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) == WND_OTHER_PROCESS
)
642 if (is_desktop_window( hwnd
)) ptr
= WND_DESKTOP
;
648 /***********************************************************************
649 * WIN_IsCurrentProcess
651 * Check whether a given window belongs to the current process (and return the full handle).
653 HWND
WIN_IsCurrentProcess( HWND hwnd
)
658 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
659 ret
= ptr
->obj
.handle
;
660 WIN_ReleasePtr( ptr
);
665 /***********************************************************************
666 * WIN_IsCurrentThread
668 * Check whether a given window belongs to the current thread (and return the full handle).
670 HWND
WIN_IsCurrentThread( HWND hwnd
)
675 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
676 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->obj
.handle
;
677 WIN_ReleasePtr( ptr
);
682 /***********************************************************************
685 * Set the flags of a window and return the previous value.
687 UINT
win_set_flags( HWND hwnd
, UINT set_mask
, UINT clear_mask
)
690 WND
*ptr
= WIN_GetPtr( hwnd
);
692 if (!ptr
|| ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
694 ptr
->flags
= (ret
& ~clear_mask
) | set_mask
;
695 WIN_ReleasePtr( ptr
);
700 /***********************************************************************
703 * Convert a possibly truncated window handle to a full 32-bit handle.
705 HWND
WIN_GetFullHandle( HWND hwnd
)
709 if (!hwnd
|| (ULONG_PTR
)hwnd
>> 16) return hwnd
;
710 if (LOWORD(hwnd
) <= 1 || LOWORD(hwnd
) == 0xffff) return hwnd
;
711 /* do sign extension for -2 and -3 */
712 if (LOWORD(hwnd
) >= (WORD
)-3) return (HWND
)(LONG_PTR
)(INT16
)LOWORD(hwnd
);
714 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
716 if (ptr
== WND_DESKTOP
)
718 if (LOWORD(hwnd
) == LOWORD(GetDesktopWindow())) return GetDesktopWindow();
719 else return get_hwnd_message_parent();
722 if (ptr
!= WND_OTHER_PROCESS
)
724 hwnd
= ptr
->obj
.handle
;
725 WIN_ReleasePtr( ptr
);
727 else /* may belong to another process */
729 SERVER_START_REQ( get_window_info
)
731 req
->handle
= wine_server_user_handle( hwnd
);
732 if (!wine_server_call_err( req
)) hwnd
= wine_server_ptr_handle( reply
->full_handle
);
740 /***********************************************************************
743 * Change the owner of a window.
745 HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
747 WND
*win
= WIN_GetPtr( hwnd
);
750 if (!win
|| win
== WND_DESKTOP
) return 0;
751 if (win
== WND_OTHER_PROCESS
)
753 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
756 SERVER_START_REQ( set_window_owner
)
758 req
->handle
= wine_server_user_handle( hwnd
);
759 req
->owner
= wine_server_user_handle( owner
);
760 if (!wine_server_call( req
))
762 win
->owner
= wine_server_ptr_handle( reply
->full_owner
);
763 ret
= wine_server_ptr_handle( reply
->prev_owner
);
767 WIN_ReleasePtr( win
);
772 /***********************************************************************
775 * Change the style of a window.
777 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
779 BOOL ok
, made_visible
= FALSE
;
781 WND
*win
= WIN_GetPtr( hwnd
);
783 if (!win
|| win
== WND_DESKTOP
) return 0;
784 if (win
== WND_OTHER_PROCESS
)
787 return SendMessageW(hwnd
, WM_WINE_SETSTYLE
, set_bits
, clear_bits
);
790 style
.styleOld
= win
->dwStyle
;
791 style
.styleNew
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
792 if (style
.styleNew
== style
.styleOld
)
794 WIN_ReleasePtr( win
);
795 return style
.styleNew
;
797 SERVER_START_REQ( set_window_info
)
799 req
->handle
= wine_server_user_handle( hwnd
);
800 req
->flags
= SET_WIN_STYLE
;
801 req
->style
= style
.styleNew
;
802 req
->extra_offset
= -1;
803 if ((ok
= !wine_server_call( req
)))
805 style
.styleOld
= reply
->old_style
;
806 win
->dwStyle
= style
.styleNew
;
811 if (ok
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
))
813 made_visible
= (style
.styleNew
& WS_VISIBLE
) != 0;
814 invalidate_dce( win
, NULL
);
816 WIN_ReleasePtr( win
);
820 USER_Driver
->pSetWindowStyle( hwnd
, GWL_STYLE
, &style
);
821 if (made_visible
) update_window_state( hwnd
);
823 return style
.styleOld
;
827 /***********************************************************************
830 * Get the window and client rectangles.
832 BOOL
WIN_GetRectangles( HWND hwnd
, enum coords_relative relative
, RECT
*rectWindow
, RECT
*rectClient
)
834 WND
*win
= WIN_GetPtr( hwnd
);
839 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
842 if (win
== WND_DESKTOP
)
845 rect
.left
= rect
.top
= 0;
846 if (hwnd
== get_hwnd_message_parent())
850 rect
= rect_win_to_thread_dpi( hwnd
, rect
);
854 rect
.right
= GetSystemMetrics(SM_CXSCREEN
);
855 rect
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
857 if (rectWindow
) *rectWindow
= rect
;
858 if (rectClient
) *rectClient
= rect
;
861 if (win
!= WND_OTHER_PROCESS
)
863 RECT window_rect
= win
->window_rect
, client_rect
= win
->client_rect
;
868 OffsetRect( &window_rect
, -win
->client_rect
.left
, -win
->client_rect
.top
);
869 OffsetRect( &client_rect
, -win
->client_rect
.left
, -win
->client_rect
.top
);
870 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
871 mirror_rect( &win
->client_rect
, &window_rect
);
874 OffsetRect( &window_rect
, -win
->window_rect
.left
, -win
->window_rect
.top
);
875 OffsetRect( &client_rect
, -win
->window_rect
.left
, -win
->window_rect
.top
);
876 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
877 mirror_rect( &win
->window_rect
, &client_rect
);
882 WND
*parent
= WIN_GetPtr( win
->parent
);
883 if (parent
== WND_DESKTOP
) break;
884 if (!parent
|| parent
== WND_OTHER_PROCESS
)
886 WIN_ReleasePtr( win
);
889 if (parent
->flags
& WIN_CHILDREN_MOVED
)
891 WIN_ReleasePtr( parent
);
892 WIN_ReleasePtr( win
);
895 if (parent
->dwExStyle
& WS_EX_LAYOUTRTL
)
897 mirror_rect( &parent
->client_rect
, &window_rect
);
898 mirror_rect( &parent
->client_rect
, &client_rect
);
900 WIN_ReleasePtr( parent
);
906 WND
*parent
= WIN_GetPtr( win
->parent
);
907 if (parent
== WND_DESKTOP
) break;
908 if (!parent
|| parent
== WND_OTHER_PROCESS
)
910 WIN_ReleasePtr( win
);
913 WIN_ReleasePtr( win
);
914 if (parent
->flags
& WIN_CHILDREN_MOVED
)
916 WIN_ReleasePtr( parent
);
922 OffsetRect( &window_rect
, win
->client_rect
.left
, win
->client_rect
.top
);
923 OffsetRect( &client_rect
, win
->client_rect
.left
, win
->client_rect
.top
);
928 if (rectWindow
) *rectWindow
= rect_win_to_thread_dpi( hwnd
, window_rect
);
929 if (rectClient
) *rectClient
= rect_win_to_thread_dpi( hwnd
, client_rect
);
930 WIN_ReleasePtr( win
);
935 SERVER_START_REQ( get_window_rectangles
)
937 req
->handle
= wine_server_user_handle( hwnd
);
938 req
->relative
= relative
;
939 req
->dpi
= get_thread_dpi();
940 if ((ret
= !wine_server_call_err( req
)))
944 rectWindow
->left
= reply
->window
.left
;
945 rectWindow
->top
= reply
->window
.top
;
946 rectWindow
->right
= reply
->window
.right
;
947 rectWindow
->bottom
= reply
->window
.bottom
;
951 rectClient
->left
= reply
->client
.left
;
952 rectClient
->top
= reply
->client
.top
;
953 rectClient
->right
= reply
->client
.right
;
954 rectClient
->bottom
= reply
->client
.bottom
;
963 /***********************************************************************
966 * Destroy storage associated to a window. "Internals" p.358
968 LRESULT
WIN_DestroyWindow( HWND hwnd
)
972 HMENU menu
= 0, sys_menu
;
974 struct window_surface
*surface
;
976 TRACE("%p\n", hwnd
);
978 /* destroy default IME window */
979 if (win_set_flags( hwnd
, 0, WIN_HAS_IME_WIN
) & WIN_HAS_IME_WIN
)
981 TRACE("unregister IME window for %p\n", hwnd
);
982 imm_unregister_window( hwnd
);
985 /* free child windows */
986 if ((list
= WIN_ListChildren( hwnd
)))
989 for (i
= 0; list
[i
]; i
++)
991 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
992 else SendNotifyMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
994 HeapFree( GetProcessHeap(), 0, list
);
997 /* Unlink now so we won't bother with the children later on */
998 SERVER_START_REQ( set_parent
)
1000 req
->handle
= wine_server_user_handle( hwnd
);
1002 wine_server_call( req
);
1007 * Send the WM_NCDESTROY to the window being destroyed.
1009 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
1011 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
1013 /* free resources associated with the window */
1015 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1016 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1017 menu
= (HMENU
)wndPtr
->wIDmenu
;
1018 sys_menu
= wndPtr
->hSysMenu
;
1019 free_dce( wndPtr
->dce
, hwnd
);
1021 icon_title
= wndPtr
->icon_title
;
1022 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
1023 wndPtr
->text
= NULL
;
1024 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
1025 wndPtr
->pScroll
= NULL
;
1026 DestroyIcon( wndPtr
->hIconSmall2
);
1027 surface
= wndPtr
->surface
;
1028 wndPtr
->surface
= NULL
;
1029 WIN_ReleasePtr( wndPtr
);
1031 if (icon_title
) DestroyWindow( icon_title
);
1032 if (menu
) DestroyMenu( menu
);
1033 if (sys_menu
) DestroyMenu( sys_menu
);
1036 register_window_surface( surface
, NULL
);
1037 window_surface_release( surface
);
1040 USER_Driver
->pDestroyWindow( hwnd
);
1042 free_window_handle( hwnd
);
1047 /***********************************************************************
1048 * next_thread_window
1050 static WND
*next_thread_window( HWND
*hwnd
)
1052 struct user_object
*ptr
;
1054 WORD index
= *hwnd
? USER_HANDLE_TO_INDEX( *hwnd
) + 1 : 0;
1057 while (index
< NB_USER_HANDLES
)
1059 if (!(ptr
= user_handles
[index
++])) continue;
1060 if (ptr
->type
!= USER_WINDOW
) continue;
1062 if (win
->tid
!= GetCurrentThreadId()) continue;
1063 *hwnd
= ptr
->handle
;
1071 /***********************************************************************
1072 * destroy_thread_windows
1074 * Destroy all window owned by the current thread.
1076 void destroy_thread_windows(void)
1079 HWND hwnd
= 0, *list
;
1080 HMENU menu
, sys_menu
;
1081 struct window_surface
*surface
;
1084 while ((wndPtr
= next_thread_window( &hwnd
)))
1086 /* destroy the client-side storage */
1088 list
= WIN_ListChildren( hwnd
);
1089 menu
= ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
) ? (HMENU
)wndPtr
->wIDmenu
: 0;
1090 sys_menu
= wndPtr
->hSysMenu
;
1091 free_dce( wndPtr
->dce
, hwnd
);
1092 surface
= wndPtr
->surface
;
1093 InterlockedCompareExchangePointer( &user_handles
[USER_HANDLE_TO_INDEX(hwnd
)], NULL
, wndPtr
);
1094 WIN_ReleasePtr( wndPtr
);
1095 HeapFree( GetProcessHeap(), 0, wndPtr
);
1096 if (menu
) DestroyMenu( menu
);
1097 if (sys_menu
) DestroyMenu( sys_menu
);
1100 register_window_surface( surface
, NULL
);
1101 window_surface_release( surface
);
1104 /* free child windows */
1106 if (!list
) continue;
1107 for (i
= 0; list
[i
]; i
++)
1108 if (!WIN_IsCurrentThread( list
[i
] ))
1109 SendNotifyMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
1110 HeapFree( GetProcessHeap(), 0, list
);
1115 /***********************************************************************
1116 * WIN_FixCoordinates
1118 * Fix the coordinates - Helper for WIN_CreateWindowEx.
1119 * returns default show mode in sw.
1121 static void WIN_FixCoordinates( CREATESTRUCTW
*cs
, INT
*sw
)
1123 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1126 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1130 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
1131 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= ULongToHandle(id
);
1133 TRACE("MDI child id %04x\n", id
);
1136 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
1138 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1140 if (IS_DEFAULT(cs
->x
))
1145 if (IS_DEFAULT(cs
->cx
) || !cs
->cx
) cs
->cx
= pos
[1].x
;
1146 if (IS_DEFAULT(cs
->cy
) || !cs
->cy
) cs
->cy
= pos
[1].y
;
1150 if (IS_DEFAULT(cs
->x
)) cs
->x
= cs
->y
= 0;
1151 if (IS_DEFAULT(cs
->cx
)) cs
->cx
= cs
->cy
= 0;
1154 else /* overlapped window */
1157 MONITORINFO mon_info
;
1160 if (!IS_DEFAULT(cs
->x
) && !IS_DEFAULT(cs
->cx
) && !IS_DEFAULT(cs
->cy
)) return;
1162 monitor
= MonitorFromWindow( cs
->hwndParent
, MONITOR_DEFAULTTOPRIMARY
);
1163 mon_info
.cbSize
= sizeof(mon_info
);
1164 GetMonitorInfoW( monitor
, &mon_info
);
1165 GetStartupInfoW( &info
);
1167 if (IS_DEFAULT(cs
->x
))
1169 if (!IS_DEFAULT(cs
->y
)) *sw
= cs
->y
;
1170 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: mon_info
.rcWork
.left
;
1171 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: mon_info
.rcWork
.top
;
1174 if (IS_DEFAULT(cs
->cx
))
1176 if (info
.dwFlags
& STARTF_USESIZE
)
1178 cs
->cx
= info
.dwXSize
;
1179 cs
->cy
= info
.dwYSize
;
1183 cs
->cx
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) * 3 / 4 - cs
->x
;
1184 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1187 /* neither x nor cx are default. Check the y values .
1188 * In the trace we see Outlook and Outlook Express using
1189 * cy set to CW_USEDEFAULT when opening the address book.
1191 else if (IS_DEFAULT(cs
->cy
))
1193 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
1194 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1200 /***********************************************************************
1201 * dump_window_styles
1203 static void dump_window_styles( DWORD style
, DWORD exstyle
)
1206 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
1207 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
1208 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
1209 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
1210 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
1211 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
1212 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
1213 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
1214 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
1217 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
1218 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
1220 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
1221 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
1222 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
1223 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
1224 if (style
& WS_CHILD
)
1226 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
1227 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
1231 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
1232 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
1235 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
1236 #define DUMPED_STYLES \
1237 ((DWORD)(WS_POPUP | \
1256 if(style
& ~DUMPED_STYLES
) TRACE(" %08x", style
& ~DUMPED_STYLES
);
1258 #undef DUMPED_STYLES
1260 TRACE( "exstyle:" );
1261 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
1262 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
1263 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
1264 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
1265 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
1266 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
1267 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
1268 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
1269 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
1270 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
1271 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
1272 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
1273 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
1274 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
1275 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
1276 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
1277 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
1278 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
1279 if(exstyle
& WS_EX_NOINHERITLAYOUT
) TRACE(" WS_EX_NOINHERITLAYOUT");
1280 if(exstyle
& WS_EX_LAYOUTRTL
) TRACE(" WS_EX_LAYOUTRTL");
1281 if(exstyle
& WS_EX_COMPOSITED
) TRACE(" WS_EX_COMPOSITED");
1282 if(exstyle
& WS_EX_NOACTIVATE
) TRACE(" WS_EX_NOACTIVATE");
1284 #define DUMPED_EX_STYLES \
1285 ((DWORD)(WS_EX_DLGMODALFRAME | \
1286 WS_EX_DRAGDETECT | \
1287 WS_EX_NOPARENTNOTIFY | \
1289 WS_EX_ACCEPTFILES | \
1290 WS_EX_TRANSPARENT | \
1292 WS_EX_TOOLWINDOW | \
1293 WS_EX_WINDOWEDGE | \
1294 WS_EX_CLIENTEDGE | \
1295 WS_EX_CONTEXTHELP | \
1297 WS_EX_RTLREADING | \
1298 WS_EX_LEFTSCROLLBAR | \
1299 WS_EX_CONTROLPARENT | \
1300 WS_EX_STATICEDGE | \
1303 WS_EX_NOINHERITLAYOUT | \
1308 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08x", exstyle
& ~DUMPED_EX_STYLES
);
1310 #undef DUMPED_EX_STYLES
1313 /***********************************************************************
1314 * map_dpi_create_struct
1316 static void map_dpi_create_struct( CREATESTRUCTW
*cs
, UINT dpi_from
, UINT dpi_to
)
1318 if (!dpi_from
&& !dpi_to
) return;
1319 if (!dpi_from
|| !dpi_to
)
1321 POINT pt
= { cs
->x
, cs
->y
};
1322 UINT mon_dpi
= get_monitor_dpi( MonitorFromPoint( pt
, MONITOR_DEFAULTTONEAREST
));
1323 if (!dpi_from
) dpi_from
= mon_dpi
;
1324 else dpi_to
= mon_dpi
;
1326 if (dpi_from
== dpi_to
) return;
1327 cs
->x
= MulDiv( cs
->x
, dpi_to
, dpi_from
);
1328 cs
->y
= MulDiv( cs
->y
, dpi_to
, dpi_from
);
1329 cs
->cx
= MulDiv( cs
->cx
, dpi_to
, dpi_from
);
1330 cs
->cy
= MulDiv( cs
->cy
, dpi_to
, dpi_from
);
1333 /***********************************************************************
1334 * WIN_CreateWindowEx
1336 * Implementation of CreateWindowEx().
1338 HWND
WIN_CreateWindowEx( CREATESTRUCTW
*cs
, LPCWSTR className
, HINSTANCE module
, BOOL unicode
)
1340 INT cx
, cy
, style
, sw
= SW_SHOW
;
1344 HWND hwnd
, parent
, owner
, top_child
= 0;
1345 const WCHAR
*p
= className
;
1346 UINT win_dpi
, thread_dpi
= get_thread_dpi();
1347 DPI_AWARENESS_CONTEXT context
;
1348 MDICREATESTRUCTW mdi_cs
;
1349 CBT_CREATEWNDW cbtc
;
1352 className
= CLASS_GetVersionedName(className
, NULL
, NULL
, TRUE
);
1354 TRACE("%s %s%s%s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
1355 unicode
? debugstr_w(cs
->lpszName
) : debugstr_a((LPCSTR
)cs
->lpszName
),
1356 debugstr_w(p
), p
!= className
? "->" : "", p
!= className
? debugstr_w(className
) : "",
1357 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
1358 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
1359 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
1361 /* Fix the styles for MDI children */
1362 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1364 if (!(win_get_flags( cs
->hwndParent
) & WIN_ISMDICLIENT
))
1366 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
1370 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
1371 * MDICREATESTRUCT members have the originally passed values.
1373 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
1374 * have the same layout.
1376 mdi_cs
.szClass
= cs
->lpszClass
;
1377 mdi_cs
.szTitle
= cs
->lpszName
;
1378 mdi_cs
.hOwner
= cs
->hInstance
;
1383 mdi_cs
.style
= cs
->style
;
1384 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
1386 cs
->lpCreateParams
= &mdi_cs
;
1388 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1390 if (cs
->style
& WS_POPUP
)
1392 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
1395 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
1399 cs
->style
&= ~WS_POPUP
;
1400 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1401 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1404 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
1408 /* Restore current maximized child */
1409 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
1411 TRACE("Restoring current maximized child %p\n", top_child
);
1412 if (cs
->style
& WS_MAXIMIZE
)
1414 /* if the new window is maximized don't bother repainting */
1415 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
1416 ShowWindow( top_child
, SW_SHOWNORMAL
);
1417 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
1419 else ShowWindow( top_child
, SW_SHOWNORMAL
);
1424 /* Find the parent window */
1426 parent
= cs
->hwndParent
;
1429 if (cs
->hwndParent
== HWND_MESSAGE
)
1431 cs
->hwndParent
= parent
= get_hwnd_message_parent();
1433 else if (cs
->hwndParent
)
1435 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1437 parent
= GetDesktopWindow();
1438 owner
= cs
->hwndParent
;
1442 DWORD parent_style
= GetWindowLongW( parent
, GWL_EXSTYLE
);
1443 if ((parent_style
& WS_EX_LAYOUTRTL
) && !(parent_style
& WS_EX_NOINHERITLAYOUT
))
1444 cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1449 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
1451 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1453 WARN("No parent for child window\n" );
1454 SetLastError(ERROR_TLW_WITH_WSCHILD
);
1455 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1458 /* are we creating the desktop or HWND_MESSAGE parent itself? */
1459 if (className
!= (LPCWSTR
)DESKTOP_CLASS_ATOM
&&
1460 (IS_INTRESOURCE(className
) || strcmpiW( className
, messageW
)))
1463 GetProcessDefaultLayout( &layout
);
1464 if (layout
& LAYOUT_RTL
) cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1465 parent
= GetDesktopWindow();
1469 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
1471 if ((cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1472 ((!(cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1473 (cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1474 cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1476 cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1478 /* Create the window structure */
1480 if (!(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1483 /* if it's a comctl32 class, GetClassInfo will load it, then we can retry */
1484 if (GetLastError() != ERROR_INVALID_HANDLE
||
1485 !GetClassInfoW( 0, className
, &wc
) ||
1486 !(wndPtr
= create_window_handle( parent
, owner
, className
, module
, unicode
)))
1489 hwnd
= wndPtr
->obj
.handle
;
1491 /* Fill the window structure */
1493 wndPtr
->tid
= GetCurrentThreadId();
1494 wndPtr
->hInstance
= cs
->hInstance
;
1495 wndPtr
->text
= NULL
;
1496 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
1497 wndPtr
->dwExStyle
= cs
->dwExStyle
;
1498 wndPtr
->wIDmenu
= 0;
1499 wndPtr
->helpContext
= 0;
1500 wndPtr
->pScroll
= NULL
;
1501 wndPtr
->userdata
= 0;
1503 wndPtr
->hIconSmall
= 0;
1504 wndPtr
->hIconSmall2
= 0;
1505 wndPtr
->hSysMenu
= 0;
1507 wndPtr
->min_pos
.x
= wndPtr
->min_pos
.y
= -1;
1508 wndPtr
->max_pos
.x
= wndPtr
->max_pos
.y
= -1;
1509 SetRect( &wndPtr
->normal_rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1511 if (wndPtr
->dwStyle
& WS_SYSMENU
) SetSystemMenu( hwnd
, 0 );
1514 * Correct the window styles.
1516 * It affects only the style loaded into the WIN structure.
1519 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1521 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1522 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1523 wndPtr
->dwStyle
|= WS_CAPTION
;
1526 /* WS_EX_WINDOWEDGE depends on some other styles */
1527 if (wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
)
1528 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1529 else if (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
))
1531 if (!((wndPtr
->dwExStyle
& WS_EX_STATICEDGE
) &&
1532 (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
))))
1533 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1536 wndPtr
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1538 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1539 wndPtr
->flags
|= WIN_NEED_SIZE
;
1541 SERVER_START_REQ( set_window_info
)
1543 req
->handle
= wine_server_user_handle( hwnd
);
1544 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
| SET_WIN_UNICODE
;
1545 req
->style
= wndPtr
->dwStyle
;
1546 req
->ex_style
= wndPtr
->dwExStyle
;
1547 req
->instance
= wine_server_client_ptr( wndPtr
->hInstance
);
1548 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1549 req
->extra_offset
= -1;
1550 wine_server_call( req
);
1554 /* Set the window menu */
1556 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1560 if (!MENU_SetMenu(hwnd
, cs
->hMenu
))
1562 WIN_ReleasePtr( wndPtr
);
1563 free_window_handle( hwnd
);
1569 LPCWSTR menuName
= (LPCWSTR
)GetClassLongPtrW( hwnd
, GCLP_MENUNAME
);
1572 cs
->hMenu
= LoadMenuW( cs
->hInstance
, menuName
);
1573 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1577 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1579 style
= wndPtr
->dwStyle
;
1580 win_dpi
= wndPtr
->dpi
;
1581 WIN_ReleasePtr( wndPtr
);
1583 if (parent
) map_dpi_create_struct( cs
, thread_dpi
, win_dpi
);
1585 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
1587 /* call the WH_CBT hook */
1589 /* the window style passed to the hook must be the real window style,
1590 * rather than just the window style that the caller to CreateWindowEx
1591 * passed in, so we have to copy the original CREATESTRUCT and get the
1592 * the real style. */
1596 cbtc
.hwndInsertAfter
= HWND_TOP
;
1597 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
)) goto failed
;
1599 /* send the WM_GETMINMAXINFO message and fix the size if needed */
1603 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1605 MINMAXINFO info
= WINPOS_GetMinMaxInfo( hwnd
);
1606 cx
= max( min( cx
, info
.ptMaxTrackSize
.x
), info
.ptMinTrackSize
.x
);
1607 cy
= max( min( cy
, info
.ptMaxTrackSize
.y
), info
.ptMinTrackSize
.y
);
1612 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cx
, cs
->y
+ cy
);
1613 /* check for wraparound */
1614 if (cs
->x
+ cx
< cs
->x
) rect
.right
= 0x7fffffff;
1615 if (cs
->y
+ cy
< cs
->y
) rect
.bottom
= 0x7fffffff;
1616 if (!set_window_pos( hwnd
, 0, SWP_NOZORDER
| SWP_NOACTIVATE
, &rect
, &rect
, NULL
)) goto failed
;
1618 /* send WM_NCCREATE */
1620 TRACE( "hwnd %p cs %d,%d %dx%d %s\n", hwnd
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, wine_dbgstr_rect(&rect
) );
1622 result
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1624 result
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1627 WARN( "%p: aborted by WM_NCCREATE\n", hwnd
);
1631 /* create default IME window */
1633 if (imm_register_window
&& !is_desktop_window( hwnd
) &&
1634 parent
!= get_hwnd_message_parent() && imm_register_window( hwnd
))
1636 TRACE("register IME window for %p\n", hwnd
);
1637 win_set_flags( hwnd
, WIN_HAS_IME_WIN
, 0 );
1640 /* send WM_NCCALCSIZE */
1642 if (WIN_GetRectangles( hwnd
, COORDS_PARENT
, &rect
, NULL
))
1644 /* yes, even if the CBT hook was called with HWND_TOP */
1645 HWND insert_after
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1646 RECT client_rect
= rect
;
1648 /* the rectangle is in screen coords for WM_NCCALCSIZE when wparam is FALSE */
1649 MapWindowPoints( parent
, 0, (POINT
*)&client_rect
, 2 );
1650 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&client_rect
);
1651 MapWindowPoints( 0, parent
, (POINT
*)&client_rect
, 2 );
1652 set_window_pos( hwnd
, insert_after
, SWP_NOACTIVATE
, &rect
, &client_rect
, NULL
);
1656 /* send WM_CREATE */
1659 result
= SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1661 result
= SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1662 if (result
== -1) goto failed
;
1664 /* call the driver */
1666 if (!USER_Driver
->pCreateWindow( hwnd
)) goto failed
;
1668 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1670 /* send the size messages */
1672 if (!(win_get_flags( hwnd
) & WIN_NEED_SIZE
))
1674 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &rect
);
1675 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1676 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1677 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1680 /* Show the window, maximizing or minimizing if needed */
1682 style
= WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1683 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1686 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1688 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1689 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1690 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1691 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
, newPos
.right
- newPos
.left
,
1692 newPos
.bottom
- newPos
.top
, swFlag
);
1695 /* Notify the parent window only */
1697 send_parent_notify( hwnd
, WM_CREATE
);
1698 if (!IsWindow( hwnd
))
1700 SetThreadDpiAwarenessContext( context
);
1704 if (parent
== GetDesktopWindow())
1705 PostMessageW( parent
, WM_PARENTNOTIFY
, WM_CREATE
, (LPARAM
)hwnd
);
1707 if (cs
->style
& WS_VISIBLE
)
1709 if (cs
->style
& WS_MAXIMIZE
)
1711 else if (cs
->style
& WS_MINIMIZE
)
1712 sw
= SW_SHOWMINIMIZED
;
1714 ShowWindow( hwnd
, sw
);
1715 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1717 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1718 /* ShowWindow won't activate child windows */
1719 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1723 /* Call WH_SHELL hook */
1725 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1726 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1728 TRACE("created window %p\n", hwnd
);
1729 SetThreadDpiAwarenessContext( context
);
1733 WIN_DestroyWindow( hwnd
);
1734 SetThreadDpiAwarenessContext( context
);
1739 /***********************************************************************
1740 * CreateWindowExA (USER32.@)
1742 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1743 LPCSTR windowName
, DWORD style
, INT x
,
1744 INT y
, INT width
, INT height
,
1745 HWND parent
, HMENU menu
,
1746 HINSTANCE instance
, LPVOID data
)
1750 cs
.lpCreateParams
= data
;
1751 cs
.hInstance
= instance
;
1753 cs
.hwndParent
= parent
;
1759 cs
.lpszName
= windowName
;
1760 cs
.lpszClass
= className
;
1761 cs
.dwExStyle
= exStyle
;
1763 if (!IS_INTRESOURCE(className
))
1766 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, bufferW
, ARRAY_SIZE( bufferW
)))
1768 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, bufferW
, instance
, FALSE
);
1770 /* Note: we rely on the fact that CREATESTRUCTA and */
1771 /* CREATESTRUCTW have the same layout. */
1772 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, (LPCWSTR
)className
, instance
, FALSE
);
1776 /***********************************************************************
1777 * CreateWindowExW (USER32.@)
1779 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1780 LPCWSTR windowName
, DWORD style
, INT x
,
1781 INT y
, INT width
, INT height
,
1782 HWND parent
, HMENU menu
,
1783 HINSTANCE instance
, LPVOID data
)
1787 cs
.lpCreateParams
= data
;
1788 cs
.hInstance
= instance
;
1790 cs
.hwndParent
= parent
;
1796 cs
.lpszName
= windowName
;
1797 cs
.lpszClass
= className
;
1798 cs
.dwExStyle
= exStyle
;
1800 return wow_handlers
.create_window( &cs
, className
, instance
, TRUE
);
1804 /***********************************************************************
1805 * WIN_SendDestroyMsg
1807 static void WIN_SendDestroyMsg( HWND hwnd
)
1811 info
.cbSize
= sizeof(info
);
1812 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1814 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1815 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1818 if (hwnd
== GetClipboardOwner()) CLIPBOARD_ReleaseOwner( hwnd
);
1821 * Send the WM_DESTROY to the window.
1823 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1826 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1827 * make sure that the window still exists when we come back.
1834 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1836 for (i
= 0; pWndArray
[i
]; i
++)
1838 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1840 HeapFree( GetProcessHeap(), 0, pWndArray
);
1843 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1847 /***********************************************************************
1848 * DestroyWindow (USER32.@)
1850 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1854 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || is_desktop_window( hwnd
))
1856 SetLastError( ERROR_ACCESS_DENIED
);
1860 TRACE("(%p)\n", hwnd
);
1864 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
1866 if (MENU_IsMenuActive() == hwnd
)
1869 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
1873 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1874 send_parent_notify( hwnd
, WM_DESTROY
);
1876 else if (!GetWindow( hwnd
, GW_OWNER
))
1878 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1879 /* FIXME: clean up palette - see "Internals" p.352 */
1882 if (!IsWindow(hwnd
)) return TRUE
;
1884 /* Hide the window */
1885 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
1887 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1889 ShowWindow( hwnd
, SW_HIDE
);
1891 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1892 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1895 if (!IsWindow(hwnd
)) return TRUE
;
1897 /* Recursively destroy owned windows */
1904 BOOL got_one
= FALSE
;
1905 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1908 for (i
= 0; list
[i
]; i
++)
1910 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1911 if (WIN_IsCurrentThread( list
[i
] ))
1913 DestroyWindow( list
[i
] );
1917 WIN_SetOwner( list
[i
], 0 );
1919 HeapFree( GetProcessHeap(), 0, list
);
1921 if (!got_one
) break;
1925 /* Send destroy messages */
1927 WIN_SendDestroyMsg( hwnd
);
1928 if (!IsWindow( hwnd
)) return TRUE
;
1930 /* Destroy the window storage */
1932 WIN_DestroyWindow( hwnd
);
1937 /***********************************************************************
1938 * CloseWindow (USER32.@)
1940 BOOL WINAPI
CloseWindow( HWND hwnd
)
1942 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
1943 ShowWindow( hwnd
, SW_MINIMIZE
);
1948 /***********************************************************************
1949 * OpenIcon (USER32.@)
1951 BOOL WINAPI
OpenIcon( HWND hwnd
)
1953 if (!IsIconic( hwnd
)) return FALSE
;
1954 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1959 /***********************************************************************
1960 * FindWindowExW (USER32.@)
1962 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
, LPCWSTR className
, LPCWSTR title
)
1967 WCHAR
*buffer
= NULL
;
1969 if (!parent
&& child
) parent
= GetDesktopWindow();
1970 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
1974 len
= strlenW(title
) + 1; /* one extra char to check for chars beyond the end */
1975 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
1978 if (!(list
= list_window_children( 0, parent
, className
, 0 ))) goto done
;
1982 child
= WIN_GetFullHandle( child
);
1983 while (list
[i
] && list
[i
] != child
) i
++;
1984 if (!list
[i
]) goto done
;
1985 i
++; /* start from next window */
1992 if (InternalGetWindowText( list
[i
], buffer
, len
+ 1 ))
1994 if (!strcmpiW( buffer
, title
)) break;
1998 if (!title
[0]) break;
2006 HeapFree( GetProcessHeap(), 0, list
);
2007 HeapFree( GetProcessHeap(), 0, buffer
);
2013 /***********************************************************************
2014 * FindWindowA (USER32.@)
2016 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
2018 HWND ret
= FindWindowExA( 0, 0, className
, title
);
2019 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
2024 /***********************************************************************
2025 * FindWindowExA (USER32.@)
2027 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
, LPCSTR className
, LPCSTR title
)
2029 LPWSTR titleW
= NULL
;
2034 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
2035 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
2036 MultiByteToWideChar( CP_ACP
, 0, title
, -1, titleW
, len
);
2039 if (!IS_INTRESOURCE(className
))
2042 if (MultiByteToWideChar( CP_ACP
, 0, className
, -1, classW
, ARRAY_SIZE( classW
)))
2043 hwnd
= FindWindowExW( parent
, child
, classW
, titleW
);
2047 hwnd
= FindWindowExW( parent
, child
, (LPCWSTR
)className
, titleW
);
2050 HeapFree( GetProcessHeap(), 0, titleW
);
2055 /***********************************************************************
2056 * FindWindowW (USER32.@)
2058 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
2060 return FindWindowExW( 0, 0, className
, title
);
2064 /**********************************************************************
2065 * GetDesktopWindow (USER32.@)
2067 HWND WINAPI
GetDesktopWindow(void)
2069 struct user_thread_info
*thread_info
= get_user_thread_info();
2071 if (thread_info
->top_window
) return thread_info
->top_window
;
2073 SERVER_START_REQ( get_desktop_window
)
2076 if (!wine_server_call( req
))
2078 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2079 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2084 if (!thread_info
->top_window
)
2086 static const WCHAR explorer
[] = {'\\','e','x','p','l','o','r','e','r','.','e','x','e',0};
2087 static const WCHAR args
[] = {' ','/','d','e','s','k','t','o','p',0};
2089 PROCESS_INFORMATION pi
;
2090 WCHAR windir
[MAX_PATH
];
2091 WCHAR app
[MAX_PATH
+ ARRAY_SIZE( explorer
)];
2092 WCHAR cmdline
[MAX_PATH
+ ARRAY_SIZE( explorer
) + ARRAY_SIZE( args
)];
2093 WCHAR desktop
[MAX_PATH
];
2096 SERVER_START_REQ( set_user_object_info
)
2098 req
->handle
= wine_server_obj_handle( GetThreadDesktop(GetCurrentThreadId()) );
2099 req
->flags
= SET_USER_OBJECT_GET_FULL_NAME
;
2100 wine_server_set_reply( req
, desktop
, sizeof(desktop
) - sizeof(WCHAR
) );
2101 if (!wine_server_call( req
))
2103 size_t size
= wine_server_reply_size( reply
);
2104 desktop
[size
/ sizeof(WCHAR
)] = 0;
2105 TRACE( "starting explorer for desktop %s\n", debugstr_w(desktop
) );
2112 memset( &si
, 0, sizeof(si
) );
2114 si
.lpDesktop
= *desktop
? desktop
: NULL
;
2115 si
.dwFlags
= STARTF_USESTDHANDLES
;
2118 si
.hStdError
= GetStdHandle( STD_ERROR_HANDLE
);
2120 GetSystemDirectoryW( windir
, MAX_PATH
);
2121 strcpyW( app
, windir
);
2122 strcatW( app
, explorer
);
2123 strcpyW( cmdline
, app
);
2124 strcatW( cmdline
, args
);
2126 Wow64DisableWow64FsRedirection( &redir
);
2127 if (CreateProcessW( app
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
,
2128 NULL
, windir
, &si
, &pi
))
2130 TRACE( "started explorer pid %04x tid %04x\n", pi
.dwProcessId
, pi
.dwThreadId
);
2131 WaitForInputIdle( pi
.hProcess
, 10000 );
2132 CloseHandle( pi
.hThread
);
2133 CloseHandle( pi
.hProcess
);
2135 else WARN( "failed to start explorer, err %d\n", GetLastError() );
2136 Wow64RevertWow64FsRedirection( redir
);
2138 SERVER_START_REQ( get_desktop_window
)
2141 if (!wine_server_call( req
))
2143 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2144 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2150 if (!thread_info
->top_window
|| !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
2151 ERR( "failed to create desktop window\n" );
2153 return thread_info
->top_window
;
2157 /*******************************************************************
2158 * EnableWindow (USER32.@)
2160 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
2164 if (is_broadcast(hwnd
))
2166 SetLastError( ERROR_INVALID_PARAMETER
);
2170 TRACE("( %p, %d )\n", hwnd
, enable
);
2174 retvalue
= (WIN_SetStyle( hwnd
, 0, WS_DISABLED
) & WS_DISABLED
) != 0;
2175 if (retvalue
) SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
2179 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0 );
2181 retvalue
= (WIN_SetStyle( hwnd
, WS_DISABLED
, 0 ) & WS_DISABLED
) != 0;
2184 if (hwnd
== GetFocus())
2185 SetFocus( 0 ); /* A disabled window can't have the focus */
2187 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
2194 /***********************************************************************
2195 * IsWindowEnabled (USER32.@)
2197 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
2201 SetLastError(NO_ERROR
);
2202 ret
= GetWindowLongW( hWnd
, GWL_STYLE
);
2203 if (!ret
&& GetLastError() != NO_ERROR
) return FALSE
;
2204 return !(ret
& WS_DISABLED
);
2207 /***********************************************************************
2208 * IsWindowUnicode (USER32.@)
2210 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
2213 BOOL retvalue
= FALSE
;
2215 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
2217 if (wndPtr
== WND_DESKTOP
) return TRUE
;
2219 if (wndPtr
!= WND_OTHER_PROCESS
)
2221 retvalue
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2222 WIN_ReleasePtr( wndPtr
);
2226 SERVER_START_REQ( get_window_info
)
2228 req
->handle
= wine_server_user_handle( hwnd
);
2229 if (!wine_server_call_err( req
)) retvalue
= reply
->is_unicode
;
2237 /***********************************************************************
2238 * GetWindowDpiAwarenessContext (USER32.@)
2240 DPI_AWARENESS_CONTEXT WINAPI
GetWindowDpiAwarenessContext( HWND hwnd
)
2243 DPI_AWARENESS_CONTEXT ret
= 0;
2245 if (!(win
= WIN_GetPtr( hwnd
)))
2247 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2250 if (win
== WND_DESKTOP
) return DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
;
2251 if (win
!= WND_OTHER_PROCESS
)
2253 ret
= ULongToHandle( win
->dpi_awareness
| 0x10 );
2254 WIN_ReleasePtr( win
);
2258 SERVER_START_REQ( get_window_info
)
2260 req
->handle
= wine_server_user_handle( hwnd
);
2261 if (!wine_server_call_err( req
)) ret
= ULongToHandle( reply
->awareness
| 0x10 );
2269 /***********************************************************************
2270 * GetDpiForWindow (USER32.@)
2272 UINT WINAPI
GetDpiForWindow( HWND hwnd
)
2277 if (!(win
= WIN_GetPtr( hwnd
)))
2279 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2282 if (win
== WND_DESKTOP
)
2284 POINT pt
= { 0, 0 };
2285 return get_monitor_dpi( MonitorFromPoint( pt
, MONITOR_DEFAULTTOPRIMARY
));
2287 if (win
!= WND_OTHER_PROCESS
)
2290 if (!ret
) ret
= get_win_monitor_dpi( hwnd
);
2291 WIN_ReleasePtr( win
);
2295 SERVER_START_REQ( get_window_info
)
2297 req
->handle
= wine_server_user_handle( hwnd
);
2298 if (!wine_server_call_err( req
)) ret
= reply
->dpi
;
2306 /**********************************************************************
2309 * Helper function for GetWindowLong().
2311 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
2313 LONG_PTR retvalue
= 0;
2316 if (offset
== GWLP_HWNDPARENT
)
2318 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
2319 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
2320 return (ULONG_PTR
)parent
;
2323 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2325 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2329 if (wndPtr
== WND_DESKTOP
)
2334 retvalue
= WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
; /* message parent is not visible */
2335 if (WIN_GetFullHandle( hwnd
) == GetDesktopWindow())
2336 retvalue
|= WS_VISIBLE
;
2341 case GWLP_HINSTANCE
:
2344 SetLastError( ERROR_ACCESS_DENIED
);
2347 SetLastError( ERROR_INVALID_INDEX
);
2351 if (wndPtr
== WND_OTHER_PROCESS
)
2353 if (offset
== GWLP_WNDPROC
)
2355 SetLastError( ERROR_ACCESS_DENIED
);
2358 SERVER_START_REQ( set_window_info
)
2360 req
->handle
= wine_server_user_handle( hwnd
);
2361 req
->flags
= 0; /* don't set anything, just retrieve */
2362 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
2363 req
->extra_size
= (offset
>= 0) ? size
: 0;
2364 if (!wine_server_call_err( req
))
2368 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
2369 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
2370 case GWLP_ID
: retvalue
= reply
->old_id
; break;
2371 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
); break;
2372 case GWLP_USERDATA
: retvalue
= reply
->old_user_data
; break;
2374 if (offset
>= 0) retvalue
= get_win_data( &reply
->old_extra_value
, size
);
2375 else SetLastError( ERROR_INVALID_INDEX
);
2384 /* now we have a valid wndPtr */
2388 if (offset
> (int)(wndPtr
->cbWndExtra
- size
))
2390 WARN("Invalid offset %d\n", offset
);
2391 WIN_ReleasePtr( wndPtr
);
2392 SetLastError( ERROR_INVALID_INDEX
);
2395 retvalue
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2397 /* Special case for dialog window procedure */
2398 if ((offset
== DWLP_DLGPROC
) && (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2399 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, unicode
);
2400 WIN_ReleasePtr( wndPtr
);
2406 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
2407 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
2408 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
2409 case GWLP_ID
: retvalue
= wndPtr
->wIDmenu
; break;
2410 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
2412 /* This looks like a hack only for the edit control (see tests). This makes these controls
2413 * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests
2414 * that the hack is in GetWindowLongPtr[AW], not in winprocs.
2416 if (wndPtr
->winproc
== BUILTIN_WINPROC(WINPROC_EDIT
) && (!unicode
!= !(wndPtr
->flags
& WIN_ISUNICODE
)))
2417 retvalue
= (ULONG_PTR
)wndPtr
->winproc
;
2419 retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
);
2422 WARN("Unknown offset %d\n", offset
);
2423 SetLastError( ERROR_INVALID_INDEX
);
2426 WIN_ReleasePtr(wndPtr
);
2431 /**********************************************************************
2434 * Helper function for SetWindowLong().
2436 * 0 is the failure code. However, in the case of failure SetLastError
2437 * must be set to distinguish between a 0 return value and a failure.
2439 LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, UINT size
, LONG_PTR newval
, BOOL unicode
)
2442 BOOL ok
, made_visible
= FALSE
;
2443 LONG_PTR retval
= 0;
2446 TRACE( "%p %d %lx %c\n", hwnd
, offset
, newval
, unicode
? 'W' : 'A' );
2448 if (is_broadcast(hwnd
))
2450 SetLastError( ERROR_INVALID_PARAMETER
);
2454 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2456 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2459 if (wndPtr
== WND_DESKTOP
)
2461 /* can't change anything on the desktop window */
2462 SetLastError( ERROR_ACCESS_DENIED
);
2465 if (wndPtr
== WND_OTHER_PROCESS
)
2467 if (offset
== GWLP_WNDPROC
)
2469 SetLastError( ERROR_ACCESS_DENIED
);
2472 if (offset
> 32767 || offset
< -32767)
2474 SetLastError( ERROR_INVALID_INDEX
);
2477 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, MAKEWPARAM( offset
, size
), newval
);
2480 /* first some special cases */
2484 style
.styleOld
= wndPtr
->dwStyle
;
2485 style
.styleNew
= newval
;
2486 WIN_ReleasePtr( wndPtr
);
2487 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
)&style
);
2488 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2489 newval
= style
.styleNew
;
2490 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
2491 if (wndPtr
->parent
== GetDesktopWindow()) newval
|= WS_CLIPSIBLINGS
;
2492 /* WS_MINIMIZE can't be reset */
2493 if (wndPtr
->dwStyle
& WS_MINIMIZE
) newval
|= WS_MINIMIZE
;
2494 /* FIXME: changing WS_DLGFRAME | WS_THICKFRAME is supposed to change
2495 WS_EX_WINDOWEDGE too */
2498 style
.styleOld
= wndPtr
->dwExStyle
;
2499 style
.styleNew
= newval
;
2500 WIN_ReleasePtr( wndPtr
);
2501 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
)&style
);
2502 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2503 /* WS_EX_TOPMOST can only be changed through SetWindowPos */
2504 newval
= (style
.styleNew
& ~WS_EX_TOPMOST
) | (wndPtr
->dwExStyle
& WS_EX_TOPMOST
);
2505 /* WS_EX_WINDOWEDGE depends on some other styles */
2506 if (newval
& WS_EX_DLGMODALFRAME
)
2507 newval
|= WS_EX_WINDOWEDGE
;
2508 else if (!(newval
& WS_EX_STATICEDGE
) && (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)))
2509 newval
|= WS_EX_WINDOWEDGE
;
2511 newval
&= ~WS_EX_WINDOWEDGE
;
2513 case GWLP_HWNDPARENT
:
2514 if (wndPtr
->parent
== GetDesktopWindow())
2516 WIN_ReleasePtr( wndPtr
);
2517 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
2521 WIN_ReleasePtr( wndPtr
);
2522 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
2527 UINT old_flags
= wndPtr
->flags
;
2528 retval
= WIN_GetWindowLong( hwnd
, offset
, size
, unicode
);
2529 proc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2530 if (proc
) wndPtr
->winproc
= proc
;
2531 if (WINPROC_IsUnicode( proc
, unicode
)) wndPtr
->flags
|= WIN_ISUNICODE
;
2532 else wndPtr
->flags
&= ~WIN_ISUNICODE
;
2533 if (!((old_flags
^ wndPtr
->flags
) & WIN_ISUNICODE
))
2535 WIN_ReleasePtr( wndPtr
);
2538 /* update is_unicode flag on the server side */
2542 case GWLP_HINSTANCE
:
2546 if ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2547 (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2549 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
2550 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, unicode
);
2551 *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2552 WIN_ReleasePtr( wndPtr
);
2557 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- size
))
2559 WARN("Invalid offset %d\n", offset
);
2560 WIN_ReleasePtr( wndPtr
);
2561 SetLastError( ERROR_INVALID_INDEX
);
2564 else if (get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
) == newval
)
2566 /* already set to the same value */
2567 WIN_ReleasePtr( wndPtr
);
2573 SERVER_START_REQ( set_window_info
)
2575 req
->handle
= wine_server_user_handle( hwnd
);
2576 req
->extra_offset
= -1;
2580 req
->flags
= SET_WIN_STYLE
;
2581 req
->style
= newval
;
2584 req
->flags
= SET_WIN_EXSTYLE
;
2585 req
->ex_style
= newval
;
2588 req
->flags
= SET_WIN_ID
;
2591 case GWLP_HINSTANCE
:
2592 req
->flags
= SET_WIN_INSTANCE
;
2593 req
->instance
= wine_server_client_ptr( (void *)newval
);
2596 req
->flags
= SET_WIN_UNICODE
;
2597 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2600 req
->flags
= SET_WIN_USERDATA
;
2601 req
->user_data
= newval
;
2604 req
->flags
= SET_WIN_EXTRA
;
2605 req
->extra_offset
= offset
;
2606 req
->extra_size
= size
;
2607 set_win_data( &req
->extra_value
, newval
, size
);
2609 if ((ok
= !wine_server_call_err( req
)))
2614 wndPtr
->dwStyle
= newval
;
2615 retval
= reply
->old_style
;
2618 wndPtr
->dwExStyle
= newval
;
2619 retval
= reply
->old_ex_style
;
2622 wndPtr
->wIDmenu
= newval
;
2623 retval
= reply
->old_id
;
2625 case GWLP_HINSTANCE
:
2626 wndPtr
->hInstance
= (HINSTANCE
)newval
;
2627 retval
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
2632 wndPtr
->userdata
= newval
;
2633 retval
= reply
->old_user_data
;
2636 retval
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2637 set_win_data( (char *)wndPtr
->wExtra
+ offset
, newval
, size
);
2644 if ((offset
== GWL_STYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
)) ||
2645 (offset
== GWL_EXSTYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_EX_LAYERED
)))
2647 made_visible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
2648 invalidate_dce( wndPtr
, NULL
);
2650 WIN_ReleasePtr( wndPtr
);
2654 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2656 style
.styleOld
= retval
;
2657 style
.styleNew
= newval
;
2658 USER_Driver
->pSetWindowStyle( hwnd
, offset
, &style
);
2659 if (made_visible
) update_window_state( hwnd
);
2660 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2667 /**********************************************************************
2668 * GetWindowWord (USER32.@)
2670 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
2675 case GWLP_HINSTANCE
:
2676 case GWLP_HWNDPARENT
:
2681 WARN("Invalid offset %d\n", offset
);
2682 SetLastError( ERROR_INVALID_INDEX
);
2687 return WIN_GetWindowLong( hwnd
, offset
, sizeof(WORD
), FALSE
);
2691 /**********************************************************************
2692 * GetWindowLongA (USER32.@)
2694 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2696 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), FALSE
);
2700 /**********************************************************************
2701 * GetWindowLongW (USER32.@)
2703 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2705 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), TRUE
);
2709 /**********************************************************************
2710 * SetWindowWord (USER32.@)
2712 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
2717 case GWLP_HINSTANCE
:
2718 case GWLP_HWNDPARENT
:
2723 WARN("Invalid offset %d\n", offset
);
2724 SetLastError( ERROR_INVALID_INDEX
);
2729 return WIN_SetWindowLong( hwnd
, offset
, sizeof(WORD
), newval
, FALSE
);
2733 /**********************************************************************
2734 * SetWindowLongA (USER32.@)
2736 * See SetWindowLongW.
2738 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2740 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, FALSE
);
2744 /**********************************************************************
2745 * SetWindowLongW (USER32.@) Set window attribute
2747 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2748 * value in a window's extra memory.
2750 * The _hwnd_ parameter specifies the handle to a window that
2751 * has extra memory. The _newval_ parameter contains the new
2752 * attribute or extra memory value. If positive, the _offset_
2753 * parameter is the byte-addressed location in the window's extra
2754 * memory to set. If negative, _offset_ specifies the window
2755 * attribute to set, and should be one of the following values:
2757 * GWL_EXSTYLE The window's extended window style
2759 * GWL_STYLE The window's window style.
2761 * GWLP_WNDPROC Pointer to the window's window procedure.
2763 * GWLP_HINSTANCE The window's application instance handle.
2765 * GWLP_ID The window's identifier.
2767 * GWLP_USERDATA The window's user-specified data.
2769 * If the window is a dialog box, the _offset_ parameter can be one of
2770 * the following values:
2772 * DWLP_DLGPROC The address of the window's dialog box procedure.
2774 * DWLP_MSGRESULT The return value of a message
2775 * that the dialog box procedure processed.
2777 * DWLP_USER Application specific information.
2781 * If successful, returns the previous value located at _offset_. Otherwise,
2786 * Extra memory for a window class is specified by a nonzero cbWndExtra
2787 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2788 * time of class creation.
2790 * Using GWL_WNDPROC to set a new window procedure effectively creates
2791 * a window subclass. Use CallWindowProc() in the new windows procedure
2792 * to pass messages to the superclass's window procedure.
2794 * The user data is reserved for use by the application which created
2797 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2798 * instead, call the EnableWindow() function to change the window's
2801 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2802 * SetParent() instead.
2805 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2806 * it sends WM_STYLECHANGING before changing the settings
2807 * and WM_STYLECHANGED afterwards.
2808 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2810 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongW(
2811 HWND hwnd
, /* [in] window to alter */
2812 INT offset
, /* [in] offset, in bytes, of location to alter */
2813 LONG newval
/* [in] new value of location */
2815 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, TRUE
);
2819 /*******************************************************************
2820 * GetWindowTextA (USER32.@)
2822 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2826 if (!lpString
|| nMaxCount
<= 0) return 0;
2828 if (WIN_IsCurrentProcess( hwnd
))
2831 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2834 /* when window belongs to other process, don't send a message */
2835 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) ))) return 0;
2836 get_server_window_text( hwnd
, buffer
, nMaxCount
);
2837 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
2838 lpString
[nMaxCount
-1] = 0;
2839 HeapFree( GetProcessHeap(), 0, buffer
);
2840 return strlen(lpString
);
2844 /*******************************************************************
2845 * InternalGetWindowText (USER32.@)
2847 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2851 if (nMaxCount
<= 0) return 0;
2852 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
2853 if (win
== WND_DESKTOP
) lpString
[0] = 0;
2854 else if (win
!= WND_OTHER_PROCESS
)
2856 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
2857 else lpString
[0] = 0;
2858 WIN_ReleasePtr( win
);
2862 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2864 return strlenW(lpString
);
2868 /*******************************************************************
2869 * GetWindowTextW (USER32.@)
2871 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2873 if (!lpString
|| nMaxCount
<= 0) return 0;
2875 if (WIN_IsCurrentProcess( hwnd
))
2878 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2881 /* when window belongs to other process, don't send a message */
2882 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2883 return strlenW(lpString
);
2887 /*******************************************************************
2888 * SetWindowTextA (USER32.@)
2889 * SetWindowText (USER32.@)
2891 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2893 if (is_broadcast(hwnd
))
2895 SetLastError( ERROR_INVALID_PARAMETER
);
2898 if (!WIN_IsCurrentProcess( hwnd
))
2899 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2900 debugstr_a(lpString
), hwnd
);
2901 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2905 /*******************************************************************
2906 * SetWindowTextW (USER32.@)
2908 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2910 if (is_broadcast(hwnd
))
2912 SetLastError( ERROR_INVALID_PARAMETER
);
2915 if (!WIN_IsCurrentProcess( hwnd
))
2916 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2917 debugstr_w(lpString
), hwnd
);
2918 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2922 /*******************************************************************
2923 * GetWindowTextLengthA (USER32.@)
2925 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2929 if (WIN_IsCurrentProcess( hwnd
)) return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2931 /* when window belongs to other process, don't send a message */
2932 GetCPInfo( CP_ACP
, &info
);
2933 return get_server_window_text( hwnd
, NULL
, 0 ) * info
.MaxCharSize
;
2936 /*******************************************************************
2937 * GetWindowTextLengthW (USER32.@)
2939 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2941 if (WIN_IsCurrentProcess( hwnd
)) return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2943 /* when window belongs to other process, don't send a message */
2944 return get_server_window_text( hwnd
, NULL
, 0 );
2948 /*******************************************************************
2949 * IsWindow (USER32.@)
2951 BOOL WINAPI
IsWindow( HWND hwnd
)
2956 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
2957 if (ptr
== WND_DESKTOP
) return TRUE
;
2959 if (ptr
!= WND_OTHER_PROCESS
)
2961 WIN_ReleasePtr( ptr
);
2965 /* check other processes */
2966 SERVER_START_REQ( get_window_info
)
2968 req
->handle
= wine_server_user_handle( hwnd
);
2969 ret
= !wine_server_call_err( req
);
2976 /***********************************************************************
2977 * GetWindowThreadProcessId (USER32.@)
2979 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
2984 if (!(ptr
= WIN_GetPtr( hwnd
)))
2986 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2990 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
2992 /* got a valid window */
2994 if (process
) *process
= GetCurrentProcessId();
2995 WIN_ReleasePtr( ptr
);
2999 /* check other processes */
3000 SERVER_START_REQ( get_window_info
)
3002 req
->handle
= wine_server_user_handle( hwnd
);
3003 if (!wine_server_call_err( req
))
3005 tid
= (DWORD
)reply
->tid
;
3006 if (process
) *process
= (DWORD
)reply
->pid
;
3014 /*****************************************************************
3015 * GetParent (USER32.@)
3017 HWND WINAPI
GetParent( HWND hwnd
)
3022 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
3024 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3027 if (wndPtr
== WND_DESKTOP
) return 0;
3028 if (wndPtr
== WND_OTHER_PROCESS
)
3030 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3031 if (style
& (WS_POPUP
| WS_CHILD
))
3033 SERVER_START_REQ( get_window_tree
)
3035 req
->handle
= wine_server_user_handle( hwnd
);
3036 if (!wine_server_call_err( req
))
3038 if (style
& WS_POPUP
) retvalue
= wine_server_ptr_handle( reply
->owner
);
3039 else if (style
& WS_CHILD
) retvalue
= wine_server_ptr_handle( reply
->parent
);
3047 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
3048 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
3049 WIN_ReleasePtr( wndPtr
);
3055 /*****************************************************************
3056 * GetAncestor (USER32.@)
3058 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
3061 HWND
*list
, ret
= 0;
3066 if (!(win
= WIN_GetPtr( hwnd
)))
3068 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3071 if (win
== WND_DESKTOP
) return 0;
3072 if (win
!= WND_OTHER_PROCESS
)
3075 WIN_ReleasePtr( win
);
3077 else /* need to query the server */
3079 SERVER_START_REQ( get_window_tree
)
3081 req
->handle
= wine_server_user_handle( hwnd
);
3082 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->parent
);
3089 if (!(list
= list_window_parents( hwnd
))) return 0;
3091 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
3095 while (list
[count
]) count
++;
3096 ret
= list
[count
- 2]; /* get the one before the desktop */
3098 HeapFree( GetProcessHeap(), 0, list
);
3102 if (is_desktop_window( hwnd
)) return 0;
3103 ret
= WIN_GetFullHandle( hwnd
);
3106 HWND parent
= GetParent( ret
);
3116 /*****************************************************************
3117 * SetParent (USER32.@)
3119 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
3123 HWND old_parent
= 0;
3127 DPI_AWARENESS_CONTEXT context
;
3128 RECT window_rect
, old_screen_rect
, new_screen_rect
;
3130 TRACE("(%p %p)\n", hwnd
, parent
);
3132 if (is_broadcast(hwnd
) || is_broadcast(parent
))
3134 SetLastError(ERROR_INVALID_PARAMETER
);
3138 if (!parent
) parent
= GetDesktopWindow();
3139 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
3140 else parent
= WIN_GetFullHandle( parent
);
3142 if (!IsWindow( parent
))
3144 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3148 /* Some applications try to set a child as a parent */
3149 if (IsChild(hwnd
, parent
))
3151 SetLastError( ERROR_INVALID_PARAMETER
);
3155 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
3156 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
3158 if (full_handle
== parent
)
3160 SetLastError( ERROR_INVALID_PARAMETER
);
3164 /* Windows hides the window first, then shows it again
3165 * including the WM_SHOWWINDOW messages and all */
3166 was_visible
= ShowWindow( hwnd
, SW_HIDE
);
3168 wndPtr
= WIN_GetPtr( hwnd
);
3169 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
3171 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
3172 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, NULL
);
3173 SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
3174 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &old_screen_rect
, NULL
);
3175 SetThreadDpiAwarenessContext( context
);
3177 SERVER_START_REQ( set_parent
)
3179 req
->handle
= wine_server_user_handle( hwnd
);
3180 req
->parent
= wine_server_user_handle( parent
);
3181 if ((ret
= !wine_server_call( req
)))
3183 old_parent
= wine_server_ptr_handle( reply
->old_parent
);
3184 wndPtr
->parent
= parent
= wine_server_ptr_handle( reply
->full_parent
);
3185 wndPtr
->dpi
= reply
->dpi
;
3186 wndPtr
->dpi_awareness
= reply
->awareness
;
3191 WIN_ReleasePtr( wndPtr
);
3194 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
3195 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &new_screen_rect
, NULL
);
3196 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
3198 USER_Driver
->pSetParent( full_handle
, parent
, old_parent
);
3201 winpos
.hwndInsertAfter
= HWND_TOP
;
3202 winpos
.x
= window_rect
.left
;
3203 winpos
.y
= window_rect
.top
;
3206 winpos
.flags
= SWP_NOSIZE
;
3208 USER_SetWindowPos( &winpos
, new_screen_rect
.left
- old_screen_rect
.left
,
3209 new_screen_rect
.top
- old_screen_rect
.top
);
3211 if (was_visible
) ShowWindow( hwnd
, SW_SHOW
);
3213 SetThreadDpiAwarenessContext( context
);
3218 /*******************************************************************
3219 * IsChild (USER32.@)
3221 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
3227 if (!(GetWindowLongW( child
, GWL_STYLE
) & WS_CHILD
)) return FALSE
;
3228 if (!(list
= list_window_parents( child
))) return FALSE
;
3229 parent
= WIN_GetFullHandle( parent
);
3230 for (i
= 0; list
[i
]; i
++)
3232 if (list
[i
] == parent
)
3234 ret
= list
[i
] && list
[i
+1];
3237 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_CHILD
)) break;
3239 HeapFree( GetProcessHeap(), 0, list
);
3244 /***********************************************************************
3245 * IsWindowVisible (USER32.@)
3247 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
3253 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
3254 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3257 for (i
= 0; list
[i
+1]; i
++)
3258 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
3259 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3261 HeapFree( GetProcessHeap(), 0, list
);
3266 /***********************************************************************
3267 * WIN_IsWindowDrawable
3269 * hwnd is drawable when it is visible, all parents are not
3270 * minimized, and it is itself not minimized unless we are
3271 * trying to draw its default class icon.
3273 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
3278 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3280 if (!(style
& WS_VISIBLE
)) return FALSE
;
3281 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
3283 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3286 for (i
= 0; list
[i
+1]; i
++)
3287 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
3289 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3291 HeapFree( GetProcessHeap(), 0, list
);
3296 /*******************************************************************
3297 * GetTopWindow (USER32.@)
3299 HWND WINAPI
GetTopWindow( HWND hwnd
)
3301 if (!hwnd
) hwnd
= GetDesktopWindow();
3302 return GetWindow( hwnd
, GW_CHILD
);
3306 /*******************************************************************
3307 * GetWindow (USER32.@)
3309 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
3313 if (rel
== GW_OWNER
) /* this one may be available locally */
3315 WND
*wndPtr
= WIN_GetPtr( hwnd
);
3318 SetLastError( ERROR_INVALID_HANDLE
);
3321 if (wndPtr
== WND_DESKTOP
) return 0;
3322 if (wndPtr
!= WND_OTHER_PROCESS
)
3324 retval
= wndPtr
->owner
;
3325 WIN_ReleasePtr( wndPtr
);
3328 /* else fall through to server call */
3331 SERVER_START_REQ( get_window_tree
)
3333 req
->handle
= wine_server_user_handle( hwnd
);
3334 if (!wine_server_call_err( req
))
3339 retval
= wine_server_ptr_handle( reply
->first_sibling
);
3342 retval
= wine_server_ptr_handle( reply
->last_sibling
);
3345 retval
= wine_server_ptr_handle( reply
->next_sibling
);
3348 retval
= wine_server_ptr_handle( reply
->prev_sibling
);
3351 retval
= wine_server_ptr_handle( reply
->owner
);
3354 retval
= wine_server_ptr_handle( reply
->first_child
);
3364 /*******************************************************************
3365 * ShowOwnedPopups (USER32.@)
3367 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
3370 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
3372 if (!win_array
) return TRUE
;
3374 while (win_array
[count
]) count
++;
3375 while (--count
>= 0)
3377 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
3380 if (win_get_flags( win_array
[count
] ) & WIN_NEEDS_SHOW_OWNEDPOPUP
)
3381 /* In Windows, ShowOwnedPopups(TRUE) generates
3382 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
3383 * regardless of the state of the owner
3385 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
3389 if (GetWindowLongW( win_array
[count
], GWL_STYLE
) & WS_VISIBLE
)
3390 /* In Windows, ShowOwnedPopups(FALSE) generates
3391 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
3392 * regardless of the state of the owner
3394 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
3397 HeapFree( GetProcessHeap(), 0, win_array
);
3402 /*******************************************************************
3403 * GetLastActivePopup (USER32.@)
3405 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
3409 SERVER_START_REQ( get_window_info
)
3411 req
->handle
= wine_server_user_handle( hwnd
);
3412 if (!wine_server_call_err( req
)) retval
= wine_server_ptr_handle( reply
->last_active
);
3419 /*******************************************************************
3422 * Build an array of the children of a given window. The array must be
3423 * freed with HeapFree. Returns NULL when no windows are found.
3425 HWND
*WIN_ListChildren( HWND hwnd
)
3429 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3432 return list_window_children( 0, hwnd
, NULL
, 0 );
3436 /*******************************************************************
3437 * EnumWindows (USER32.@)
3439 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
3445 USER_CheckNotLock();
3447 /* We have to build a list of all windows first, to avoid */
3448 /* unpleasant side-effects, for instance if the callback */
3449 /* function changes the Z-order of the windows. */
3451 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
3453 /* Now call the callback function for every window */
3455 for (i
= 0; list
[i
]; i
++)
3457 /* Make sure that the window still exists */
3458 if (!IsWindow( list
[i
] )) continue;
3459 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
3461 HeapFree( GetProcessHeap(), 0, list
);
3466 /**********************************************************************
3467 * EnumThreadWindows (USER32.@)
3469 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
3475 USER_CheckNotLock();
3477 if (!(list
= list_window_children( 0, GetDesktopWindow(), NULL
, id
))) return TRUE
;
3479 /* Now call the callback function for every window */
3481 for (i
= 0; list
[i
]; i
++)
3482 if (!(ret
= func( list
[i
], lParam
))) break;
3483 HeapFree( GetProcessHeap(), 0, list
);
3488 /***********************************************************************
3489 * EnumDesktopWindows (USER32.@)
3491 BOOL WINAPI
EnumDesktopWindows( HDESK desktop
, WNDENUMPROC func
, LPARAM lparam
)
3496 USER_CheckNotLock();
3498 if (!(list
= list_window_children( desktop
, 0, NULL
, 0 ))) return TRUE
;
3500 for (i
= 0; list
[i
]; i
++)
3501 if (!func( list
[i
], lparam
)) break;
3502 HeapFree( GetProcessHeap(), 0, list
);
3508 /* Some apps pass a non-stdcall proc to EnumChildWindows,
3509 * so we need a small assembly wrapper to call the proc.
3511 extern LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
);
3512 __ASM_GLOBAL_FUNC( enum_callback_wrapper
,
3514 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
3515 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
3516 "movl %esp,%ebp\n\t"
3517 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
3518 "pushl 16(%ebp)\n\t"
3519 "pushl 12(%ebp)\n\t"
3522 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
3523 __ASM_CFI(".cfi_same_value %ebp\n\t")
3526 static inline LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
)
3528 return proc( hwnd
, lparam
);
3530 #endif /* __i386__ */
3532 /**********************************************************************
3533 * WIN_EnumChildWindows
3535 * Helper function for EnumChildWindows().
3537 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
3542 for ( ; *list
; list
++)
3544 /* Make sure that the window still exists */
3545 if (!IsWindow( *list
)) continue;
3546 /* Build children list first */
3547 childList
= WIN_ListChildren( *list
);
3549 ret
= enum_callback_wrapper( func
, *list
, lParam
);
3553 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
3554 HeapFree( GetProcessHeap(), 0, childList
);
3556 if (!ret
) return FALSE
;
3562 /**********************************************************************
3563 * EnumChildWindows (USER32.@)
3565 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
3570 USER_CheckNotLock();
3572 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
3573 ret
= WIN_EnumChildWindows( list
, func
, lParam
);
3574 HeapFree( GetProcessHeap(), 0, list
);
3579 /*******************************************************************
3580 * AnyPopup (USER32.@)
3582 BOOL WINAPI
AnyPopup(void)
3586 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
3588 if (!list
) return FALSE
;
3589 for (i
= 0; list
[i
]; i
++)
3591 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
3593 retvalue
= (list
[i
] != 0);
3594 HeapFree( GetProcessHeap(), 0, list
);
3599 /*******************************************************************
3600 * FlashWindow (USER32.@)
3602 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
3606 finfo
.cbSize
= sizeof(FLASHWINFO
);
3607 finfo
.dwFlags
= bInvert
? FLASHW_ALL
: FLASHW_STOP
;
3609 finfo
.dwTimeout
= 0;
3611 return FlashWindowEx( &finfo
);
3614 /*******************************************************************
3615 * FlashWindowEx (USER32.@)
3617 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfinfo
)
3621 TRACE( "%p\n", pfinfo
);
3625 SetLastError( ERROR_NOACCESS
);
3629 if (!pfinfo
->hwnd
|| pfinfo
->cbSize
!= sizeof(FLASHWINFO
) || !IsWindow( pfinfo
->hwnd
))
3631 SetLastError( ERROR_INVALID_PARAMETER
);
3634 FIXME( "%p - semi-stub\n", pfinfo
);
3636 if (IsIconic( pfinfo
->hwnd
))
3638 RedrawWindow( pfinfo
->hwnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
3640 wndPtr
= WIN_GetPtr( pfinfo
->hwnd
);
3641 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3642 if (pfinfo
->dwFlags
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
3644 wndPtr
->flags
|= WIN_NCACTIVATED
;
3648 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
3650 WIN_ReleasePtr( wndPtr
);
3651 USER_Driver
->pFlashWindowEx( pfinfo
);
3657 HWND hwnd
= pfinfo
->hwnd
;
3659 wndPtr
= WIN_GetPtr( hwnd
);
3660 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3661 hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
3663 if (pfinfo
->dwFlags
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
3664 else wparam
= (hwnd
== GetForegroundWindow());
3666 WIN_ReleasePtr( wndPtr
);
3667 SendMessageW( hwnd
, WM_NCACTIVATE
, wparam
, 0 );
3668 USER_Driver
->pFlashWindowEx( pfinfo
);
3673 /*******************************************************************
3674 * GetWindowContextHelpId (USER32.@)
3676 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
3679 WND
*wnd
= WIN_GetPtr( hwnd
);
3680 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
3681 if (wnd
== WND_OTHER_PROCESS
)
3683 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3686 retval
= wnd
->helpContext
;
3687 WIN_ReleasePtr( wnd
);
3692 /*******************************************************************
3693 * SetWindowContextHelpId (USER32.@)
3695 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
3697 WND
*wnd
= WIN_GetPtr( hwnd
);
3698 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
3699 if (wnd
== WND_OTHER_PROCESS
)
3701 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3704 wnd
->helpContext
= id
;
3705 WIN_ReleasePtr( wnd
);
3710 /*******************************************************************
3711 * DragDetect (USER32.@)
3713 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3717 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3718 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3720 SetRect(&rect
, pt
.x
- wDragWidth
, pt
.y
- wDragHeight
, pt
.x
+ wDragWidth
, pt
.y
+ wDragHeight
);
3726 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
3728 if( msg
.message
== WM_LBUTTONUP
)
3733 if( msg
.message
== WM_MOUSEMOVE
)
3736 tmp
.x
= (short)LOWORD(msg
.lParam
);
3737 tmp
.y
= (short)HIWORD(msg
.lParam
);
3738 if( !PtInRect( &rect
, tmp
))
3750 /******************************************************************************
3751 * GetWindowModuleFileNameA (USER32.@)
3753 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR module
, UINT size
)
3758 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3760 win
= WIN_GetPtr( hwnd
);
3761 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3763 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3766 hinst
= win
->hInstance
;
3767 WIN_ReleasePtr( win
);
3769 return GetModuleFileNameA( hinst
, module
, size
);
3772 /******************************************************************************
3773 * GetWindowModuleFileNameW (USER32.@)
3775 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR module
, UINT size
)
3780 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3782 win
= WIN_GetPtr( hwnd
);
3783 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3785 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3788 hinst
= win
->hInstance
;
3789 WIN_ReleasePtr( win
);
3791 return GetModuleFileNameW( hinst
, module
, size
);
3794 /******************************************************************************
3795 * GetWindowInfo (USER32.@)
3797 * Note: tests show that Windows doesn't check cbSize of the structure.
3799 BOOL WINAPI DECLSPEC_HOTPATCH
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
3801 if (!pwi
) return FALSE
;
3802 if (!WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &pwi
->rcWindow
, &pwi
->rcClient
)) return FALSE
;
3804 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3805 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3806 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
3808 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
3809 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
3811 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
3812 pwi
->wCreatorVersion
= 0x0400;
3817 /******************************************************************************
3818 * SwitchDesktop (USER32.@)
3820 * NOTES: Sets the current input or interactive desktop.
3822 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
3824 FIXME("(hwnd %p) stub!\n", hDesktop
);
3829 /***********************************************************************
3830 * __wine_set_pixel_format
3832 BOOL CDECL
__wine_set_pixel_format( HWND hwnd
, int format
)
3834 WND
*win
= WIN_GetPtr( hwnd
);
3836 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
3838 WARN( "setting format %d on win %p not supported\n", format
, hwnd
);
3841 win
->pixel_format
= format
;
3842 WIN_ReleasePtr( win
);
3844 update_window_state( hwnd
);
3849 /*****************************************************************************
3850 * SetLayeredWindowAttributes (USER32.@)
3852 BOOL WINAPI
SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
3856 TRACE("(%p,%08x,%d,%x)\n", hwnd
, key
, alpha
, flags
);
3858 SERVER_START_REQ( set_window_layered_info
)
3860 req
->handle
= wine_server_user_handle( hwnd
);
3861 req
->color_key
= key
;
3864 ret
= !wine_server_call_err( req
);
3870 USER_Driver
->pSetLayeredWindowAttributes( hwnd
, key
, alpha
, flags
);
3871 update_window_state( hwnd
);
3878 /*****************************************************************************
3879 * GetLayeredWindowAttributes (USER32.@)
3881 BOOL WINAPI
GetLayeredWindowAttributes( HWND hwnd
, COLORREF
*key
, BYTE
*alpha
, DWORD
*flags
)
3885 SERVER_START_REQ( get_window_layered_info
)
3887 req
->handle
= wine_server_user_handle( hwnd
);
3888 if ((ret
= !wine_server_call_err( req
)))
3890 if (key
) *key
= reply
->color_key
;
3891 if (alpha
) *alpha
= reply
->alpha
;
3892 if (flags
) *flags
= reply
->flags
;
3901 /*****************************************************************************
3902 * UpdateLayeredWindowIndirect (USER32.@)
3904 BOOL WINAPI
UpdateLayeredWindowIndirect( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
)
3906 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
;
3907 RECT window_rect
, client_rect
;
3911 info
->cbSize
!= sizeof(*info
) ||
3912 info
->dwFlags
& ~(ULW_COLORKEY
| ULW_ALPHA
| ULW_OPAQUE
| ULW_EX_NORESIZE
) ||
3913 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) ||
3914 GetLayeredWindowAttributes( hwnd
, NULL
, NULL
, NULL
))
3916 SetLastError( ERROR_INVALID_PARAMETER
);
3920 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
3924 offset
.cx
= info
->pptDst
->x
- window_rect
.left
;
3925 offset
.cy
= info
->pptDst
->y
- window_rect
.top
;
3926 OffsetRect( &client_rect
, offset
.cx
, offset
.cy
);
3927 OffsetRect( &window_rect
, offset
.cx
, offset
.cy
);
3928 flags
&= ~SWP_NOMOVE
;
3932 offset
.cx
= info
->psize
->cx
- (window_rect
.right
- window_rect
.left
);
3933 offset
.cy
= info
->psize
->cy
- (window_rect
.bottom
- window_rect
.top
);
3934 if (info
->psize
->cx
<= 0 || info
->psize
->cy
<= 0)
3936 SetLastError( ERROR_INVALID_PARAMETER
);
3939 if ((info
->dwFlags
& ULW_EX_NORESIZE
) && (offset
.cx
|| offset
.cy
))
3941 SetLastError( ERROR_INCORRECT_SIZE
);
3944 client_rect
.right
+= offset
.cx
;
3945 client_rect
.bottom
+= offset
.cy
;
3946 window_rect
.right
+= offset
.cx
;
3947 window_rect
.bottom
+= offset
.cy
;
3948 flags
&= ~SWP_NOSIZE
;
3951 TRACE( "window %p win %s client %s\n", hwnd
,
3952 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
) );
3954 if (!USER_Driver
->pUpdateLayeredWindow( hwnd
, info
, &window_rect
)) return FALSE
;
3956 set_window_pos( hwnd
, 0, flags
, &window_rect
, &client_rect
, NULL
);
3961 /*****************************************************************************
3962 * UpdateLayeredWindow (USER32.@)
3964 BOOL WINAPI
UpdateLayeredWindow( HWND hwnd
, HDC hdcDst
, POINT
*pptDst
, SIZE
*psize
,
3965 HDC hdcSrc
, POINT
*pptSrc
, COLORREF crKey
, BLENDFUNCTION
*pblend
,
3968 UPDATELAYEREDWINDOWINFO info
;
3970 if (flags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
3972 SetLastError( ERROR_INVALID_PARAMETER
);
3975 info
.cbSize
= sizeof(info
);
3976 info
.hdcDst
= hdcDst
;
3977 info
.pptDst
= pptDst
;
3979 info
.hdcSrc
= hdcSrc
;
3980 info
.pptSrc
= pptSrc
;
3982 info
.pblend
= pblend
;
3983 info
.dwFlags
= flags
;
3984 info
.prcDirty
= NULL
;
3985 return UpdateLayeredWindowIndirect( hwnd
, &info
);
3989 /******************************************************************************
3990 * GetProcessDefaultLayout [USER32.@]
3992 * Gets the default layout for parentless windows.
3994 BOOL WINAPI
GetProcessDefaultLayout( DWORD
*layout
)
3998 SetLastError( ERROR_NOACCESS
);
4001 if (process_layout
== ~0u)
4003 static const WCHAR translationW
[] = { '\\','V','a','r','F','i','l','e','I','n','f','o',
4004 '\\','T','r','a','n','s','l','a','t','i','o','n', 0 };
4005 static const WCHAR filedescW
[] = { '\\','S','t','r','i','n','g','F','i','l','e','I','n','f','o',
4006 '\\','%','0','4','x','%','0','4','x',
4007 '\\','F','i','l','e','D','e','s','c','r','i','p','t','i','o','n',0 };
4008 WCHAR
*str
, buffer
[MAX_PATH
];
4009 DWORD i
, len
, version_layout
= 0;
4010 DWORD user_lang
= GetUserDefaultLangID();
4014 GetModuleFileNameW( 0, buffer
, MAX_PATH
);
4015 if (!(len
= GetFileVersionInfoSizeW( buffer
, NULL
))) goto done
;
4016 if (!(data
= HeapAlloc( GetProcessHeap(), 0, len
))) goto done
;
4017 if (!GetFileVersionInfoW( buffer
, 0, len
, data
)) goto done
;
4018 if (!VerQueryValueW( data
, translationW
, (void **)&languages
, &len
) || !len
) goto done
;
4020 len
/= sizeof(DWORD
);
4021 for (i
= 0; i
< len
; i
++) if (LOWORD(languages
[i
]) == user_lang
) break;
4022 if (i
== len
) /* try neutral language */
4023 for (i
= 0; i
< len
; i
++)
4024 if (LOWORD(languages
[i
]) == MAKELANGID( PRIMARYLANGID(user_lang
), SUBLANG_NEUTRAL
)) break;
4025 if (i
== len
) i
= 0; /* default to the first one */
4027 sprintfW( buffer
, filedescW
, LOWORD(languages
[i
]), HIWORD(languages
[i
]) );
4028 if (!VerQueryValueW( data
, buffer
, (void **)&str
, &len
)) goto done
;
4029 TRACE( "found description %s\n", debugstr_w( str
));
4030 if (str
[0] == 0x200e && str
[1] == 0x200e) version_layout
= LAYOUT_RTL
;
4033 HeapFree( GetProcessHeap(), 0, data
);
4034 process_layout
= version_layout
;
4036 *layout
= process_layout
;
4041 /******************************************************************************
4042 * SetProcessDefaultLayout [USER32.@]
4044 * Sets the default layout for parentless windows.
4046 BOOL WINAPI
SetProcessDefaultLayout( DWORD layout
)
4048 process_layout
= layout
;
4053 /* 64bit versions */
4055 #ifdef GetWindowLongPtrW
4056 #undef GetWindowLongPtrW
4059 #ifdef GetWindowLongPtrA
4060 #undef GetWindowLongPtrA
4063 #ifdef SetWindowLongPtrW
4064 #undef SetWindowLongPtrW
4067 #ifdef SetWindowLongPtrA
4068 #undef SetWindowLongPtrA
4071 /*****************************************************************************
4072 * GetWindowLongPtrW (USER32.@)
4074 LONG_PTR WINAPI
GetWindowLongPtrW( HWND hwnd
, INT offset
)
4076 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), TRUE
);
4079 /*****************************************************************************
4080 * GetWindowLongPtrA (USER32.@)
4082 LONG_PTR WINAPI
GetWindowLongPtrA( HWND hwnd
, INT offset
)
4084 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), FALSE
);
4087 /*****************************************************************************
4088 * SetWindowLongPtrW (USER32.@)
4090 LONG_PTR WINAPI
SetWindowLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
4092 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, TRUE
);
4095 /*****************************************************************************
4096 * SetWindowLongPtrA (USER32.@)
4098 LONG_PTR WINAPI
SetWindowLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
4100 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, FALSE
);
4103 /*****************************************************************************
4104 * RegisterTouchWindow (USER32.@)
4106 BOOL WINAPI
RegisterTouchWindow(HWND hwnd
, ULONG flags
)
4108 FIXME("(%p %08x): stub\n", hwnd
, flags
);
4109 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4113 /*****************************************************************************
4114 * UnregisterTouchWindow (USER32.@)
4116 BOOL WINAPI
UnregisterTouchWindow(HWND hwnd
)
4118 FIXME("(%p): stub\n", hwnd
);
4119 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4123 /*****************************************************************************
4124 * CloseTouchInputHandle (USER32.@)
4126 BOOL WINAPI
CloseTouchInputHandle(HTOUCHINPUT handle
)
4128 FIXME("(%p): stub\n", handle
);
4129 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4133 /*****************************************************************************
4134 * GetTouchInputInfo (USER32.@)
4136 BOOL WINAPI
GetTouchInputInfo(HTOUCHINPUT handle
, UINT count
, TOUCHINPUT
*ptr
, int size
)
4138 FIXME("(%p %u %p %u): stub\n", handle
, count
, ptr
, size
);
4139 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4143 /*****************************************************************************
4144 * GetGestureInfo (USER32.@)
4146 BOOL WINAPI
GetGestureInfo(HGESTUREINFO handle
, PGESTUREINFO ptr
)
4148 FIXME("(%p %p): stub\n", handle
, ptr
);
4149 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4153 /*****************************************************************************
4154 * GetWindowDisplayAffinity (USER32.@)
4156 BOOL WINAPI
GetWindowDisplayAffinity(HWND hwnd
, DWORD
*affinity
)
4158 FIXME("(%p, %p): stub\n", hwnd
, affinity
);
4160 if (!hwnd
|| !affinity
)
4162 SetLastError(hwnd
? ERROR_NOACCESS
: ERROR_INVALID_WINDOW_HANDLE
);
4166 *affinity
= WDA_NONE
;
4170 /*****************************************************************************
4171 * SetWindowDisplayAffinity (USER32.@)
4173 BOOL WINAPI
SetWindowDisplayAffinity(HWND hwnd
, DWORD affinity
)
4175 FIXME("(%p, %u): stub\n", hwnd
, affinity
);
4179 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
4183 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);