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
26 #include "user_private.h"
29 #include "wine/server.h"
34 #include "wine/exception.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(win
);
39 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
40 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
42 static DWORD process_layout
= ~0u;
44 static struct list window_surfaces
= LIST_INIT( window_surfaces
);
46 static CRITICAL_SECTION surfaces_section
;
47 static CRITICAL_SECTION_DEBUG critsect_debug
=
49 0, 0, &surfaces_section
,
50 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
51 0, 0, { (DWORD_PTR
)(__FILE__
": surfaces_section") }
53 static CRITICAL_SECTION surfaces_section
= { &critsect_debug
, -1, 0, 0, 0, 0 };
55 /**********************************************************************/
57 /* helper for Get/SetWindowLong */
58 static inline LONG_PTR
get_win_data( const void *ptr
, UINT size
)
60 if (size
== sizeof(WORD
))
63 memcpy( &ret
, ptr
, sizeof(ret
) );
66 else if (size
== sizeof(DWORD
))
69 memcpy( &ret
, ptr
, sizeof(ret
) );
75 memcpy( &ret
, ptr
, sizeof(ret
) );
80 /* helper for Get/SetWindowLong */
81 static inline void set_win_data( void *ptr
, LONG_PTR val
, UINT size
)
83 if (size
== sizeof(WORD
))
86 memcpy( ptr
, &newval
, sizeof(newval
) );
88 else if (size
== sizeof(DWORD
))
91 memcpy( ptr
, &newval
, sizeof(newval
) );
95 memcpy( ptr
, &val
, sizeof(val
) );
100 static void *user_handles
[NB_USER_HANDLES
];
102 /***********************************************************************
105 HANDLE
alloc_user_handle( struct user_object
*ptr
, enum user_obj_type type
)
109 SERVER_START_REQ( alloc_user_handle
)
111 if (!wine_server_call_err( req
)) handle
= wine_server_ptr_handle( reply
->handle
);
117 UINT index
= USER_HANDLE_TO_INDEX( handle
);
119 assert( index
< NB_USER_HANDLES
);
120 ptr
->handle
= handle
;
122 InterlockedExchangePointer( &user_handles
[index
], ptr
);
128 /***********************************************************************
129 * get_user_handle_ptr
131 void *get_user_handle_ptr( HANDLE handle
, enum user_obj_type type
)
133 struct user_object
*ptr
;
134 WORD index
= USER_HANDLE_TO_INDEX( handle
);
136 if (index
>= NB_USER_HANDLES
) return NULL
;
139 if ((ptr
= user_handles
[index
]))
141 if (ptr
->type
== type
&&
142 ((UINT
)(UINT_PTR
)ptr
->handle
== (UINT
)(UINT_PTR
)handle
||
143 !HIWORD(handle
) || HIWORD(handle
) == 0xffff))
147 else ptr
= OBJ_OTHER_PROCESS
;
153 /***********************************************************************
154 * release_user_handle_ptr
156 void release_user_handle_ptr( void *ptr
)
158 assert( ptr
&& ptr
!= OBJ_OTHER_PROCESS
);
163 /***********************************************************************
166 void *free_user_handle( HANDLE handle
, enum user_obj_type type
)
168 struct user_object
*ptr
;
169 WORD index
= USER_HANDLE_TO_INDEX( handle
);
171 if ((ptr
= get_user_handle_ptr( handle
, type
)) && ptr
!= OBJ_OTHER_PROCESS
)
173 SERVER_START_REQ( free_user_handle
)
175 req
->handle
= wine_server_user_handle( handle
);
176 if (wine_server_call( req
)) ptr
= NULL
;
177 else InterlockedCompareExchangePointer( &user_handles
[index
], NULL
, ptr
);
186 /***********************************************************************
187 * create_window_handle
189 * Create a window handle with the server.
191 static WND
*create_window_handle( HWND parent
, HWND owner
, LPCWSTR name
,
192 HINSTANCE instance
, BOOL unicode
,
193 DWORD style
, DWORD ex_style
)
197 HWND handle
= 0, full_parent
= 0, full_owner
= 0;
198 struct tagCLASS
*class = NULL
;
200 DPI_AWARENESS awareness
= GetAwarenessFromDpiAwarenessContext( GetThreadDpiAwarenessContext() );
203 SERVER_START_REQ( create_window
)
205 req
->parent
= wine_server_user_handle( parent
);
206 req
->owner
= wine_server_user_handle( owner
);
207 req
->instance
= wine_server_client_ptr( instance
);
208 req
->dpi
= GetDpiForSystem();
209 req
->awareness
= awareness
;
211 req
->ex_style
= ex_style
;
212 if (!(req
->atom
= get_int_atom_value( name
)) && name
)
213 wine_server_add_data( req
, name
, lstrlenW(name
)*sizeof(WCHAR
) );
214 if (!wine_server_call_err( req
))
216 handle
= wine_server_ptr_handle( reply
->handle
);
217 full_parent
= wine_server_ptr_handle( reply
->parent
);
218 full_owner
= wine_server_ptr_handle( reply
->owner
);
219 extra_bytes
= reply
->extra
;
221 awareness
= reply
->awareness
;
222 class = wine_server_get_ptr( reply
->class_ptr
);
229 WARN( "error %d creating window\n", GetLastError() );
233 if (!(win
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
234 sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
236 SERVER_START_REQ( destroy_window
)
238 req
->handle
= wine_server_user_handle( handle
);
239 wine_server_call( req
);
242 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
246 if (!parent
) /* if parent is 0 we don't have a desktop window yet */
248 struct user_thread_info
*thread_info
= get_user_thread_info();
250 if (name
== (LPCWSTR
)DESKTOP_CLASS_ATOM
)
252 if (!thread_info
->top_window
) thread_info
->top_window
= full_parent
? full_parent
: handle
;
253 else assert( full_parent
== thread_info
->top_window
);
254 if (full_parent
&& !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
255 ERR( "failed to create desktop window\n" );
256 register_builtin_classes();
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, lstrlenW(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 void update_window_state( HWND hwnd
)
449 DPI_AWARENESS_CONTEXT context
;
450 RECT window_rect
, client_rect
, valid_rects
[2];
452 if (!WIN_IsCurrentThread( hwnd
))
454 PostMessageW( hwnd
, WM_WINE_UPDATEWINDOWSTATE
, 0, 0 );
458 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
459 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
460 valid_rects
[0] = valid_rects
[1] = client_rect
;
461 set_window_pos( hwnd
, 0, SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
|
462 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
,
463 &window_rect
, &client_rect
, valid_rects
);
464 SetThreadDpiAwarenessContext( context
);
468 /*******************************************************************
469 * get_server_window_text
471 * Retrieve the window text from the server.
473 static data_size_t
get_server_window_text( HWND hwnd
, WCHAR
*text
, data_size_t count
)
475 data_size_t len
= 0, needed
= 0;
477 SERVER_START_REQ( get_window_text
)
479 req
->handle
= wine_server_user_handle( hwnd
);
480 if (count
) wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
481 if (!wine_server_call_err( req
))
483 needed
= reply
->length
;
484 len
= wine_server_reply_size(reply
);
488 if (text
) text
[len
/ sizeof(WCHAR
)] = 0;
493 /*******************************************************************
494 * get_hwnd_message_parent
496 * Return the parent for HWND_MESSAGE windows.
498 HWND
get_hwnd_message_parent(void)
500 struct user_thread_info
*thread_info
= get_user_thread_info();
502 if (!thread_info
->msg_window
) GetDesktopWindow(); /* trigger creation */
503 return thread_info
->msg_window
;
507 /*******************************************************************
510 * Check if window is the desktop or the HWND_MESSAGE top parent.
512 BOOL
is_desktop_window( HWND hwnd
)
514 struct user_thread_info
*thread_info
= get_user_thread_info();
516 if (!hwnd
) return FALSE
;
517 if (hwnd
== thread_info
->top_window
) return TRUE
;
518 if (hwnd
== thread_info
->msg_window
) return TRUE
;
520 if (!HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff)
522 if (LOWORD(thread_info
->top_window
) == LOWORD(hwnd
)) return TRUE
;
523 if (LOWORD(thread_info
->msg_window
) == LOWORD(hwnd
)) return TRUE
;
529 /*******************************************************************
530 * Dummy window surface for windows that shouldn't get painted.
533 static void CDECL
dummy_surface_lock( struct window_surface
*window_surface
)
538 static void CDECL
dummy_surface_unlock( struct window_surface
*window_surface
)
543 static void *CDECL
dummy_surface_get_bitmap_info( struct window_surface
*window_surface
, BITMAPINFO
*info
)
545 static DWORD dummy_data
;
547 info
->bmiHeader
.biSize
= sizeof( info
->bmiHeader
);
548 info
->bmiHeader
.biWidth
= dummy_surface
.rect
.right
;
549 info
->bmiHeader
.biHeight
= dummy_surface
.rect
.bottom
;
550 info
->bmiHeader
.biPlanes
= 1;
551 info
->bmiHeader
.biBitCount
= 32;
552 info
->bmiHeader
.biCompression
= BI_RGB
;
553 info
->bmiHeader
.biSizeImage
= 0;
554 info
->bmiHeader
.biXPelsPerMeter
= 0;
555 info
->bmiHeader
.biYPelsPerMeter
= 0;
556 info
->bmiHeader
.biClrUsed
= 0;
557 info
->bmiHeader
.biClrImportant
= 0;
561 static RECT
*CDECL
dummy_surface_get_bounds( struct window_surface
*window_surface
)
563 static RECT dummy_bounds
;
564 return &dummy_bounds
;
567 static void CDECL
dummy_surface_set_region( struct window_surface
*window_surface
, HRGN region
)
572 static void CDECL
dummy_surface_flush( struct window_surface
*window_surface
)
577 static void CDECL
dummy_surface_destroy( struct window_surface
*window_surface
)
582 static const struct window_surface_funcs dummy_surface_funcs
=
585 dummy_surface_unlock
,
586 dummy_surface_get_bitmap_info
,
587 dummy_surface_get_bounds
,
588 dummy_surface_set_region
,
590 dummy_surface_destroy
593 struct window_surface dummy_surface
= { &dummy_surface_funcs
, { NULL
, NULL
}, 1, { 0, 0, 1, 1 } };
595 /*******************************************************************
596 * Off-screen window surface.
599 struct offscreen_window_surface
601 struct window_surface header
;
608 static const struct window_surface_funcs offscreen_window_surface_funcs
;
610 static inline void reset_bounds( RECT
*bounds
)
612 bounds
->left
= bounds
->top
= INT_MAX
;
613 bounds
->right
= bounds
->bottom
= INT_MIN
;
616 static struct offscreen_window_surface
*impl_from_window_surface( struct window_surface
*base
)
618 if (!base
|| base
->funcs
!= &offscreen_window_surface_funcs
) return NULL
;
619 return CONTAINING_RECORD( base
, struct offscreen_window_surface
, header
);
622 static void CDECL
offscreen_window_surface_lock( struct window_surface
*base
)
624 struct offscreen_window_surface
*impl
= impl_from_window_surface( base
);
625 EnterCriticalSection( &impl
->cs
);
628 static void CDECL
offscreen_window_surface_unlock( struct window_surface
*base
)
630 struct offscreen_window_surface
*impl
= impl_from_window_surface( base
);
631 LeaveCriticalSection( &impl
->cs
);
634 static RECT
*CDECL
offscreen_window_surface_get_bounds( struct window_surface
*base
)
636 struct offscreen_window_surface
*impl
= impl_from_window_surface( base
);
637 return &impl
->bounds
;
640 static void *CDECL
offscreen_window_surface_get_bitmap_info( struct window_surface
*base
, BITMAPINFO
*info
)
642 struct offscreen_window_surface
*impl
= impl_from_window_surface( base
);
643 memcpy( info
, &impl
->info
, offsetof( BITMAPINFO
, bmiColors
[0] ) );
647 static void CDECL
offscreen_window_surface_set_region( struct window_surface
*base
, HRGN region
)
651 static void CDECL
offscreen_window_surface_flush( struct window_surface
*base
)
653 struct offscreen_window_surface
*impl
= impl_from_window_surface( base
);
654 base
->funcs
->lock( base
);
655 reset_bounds( &impl
->bounds
);
656 base
->funcs
->unlock( base
);
659 static void CDECL
offscreen_window_surface_destroy( struct window_surface
*base
)
661 struct offscreen_window_surface
*impl
= impl_from_window_surface( base
);
662 impl
->cs
.DebugInfo
->Spare
[0] = 0;
663 DeleteCriticalSection( &impl
->cs
);
667 static const struct window_surface_funcs offscreen_window_surface_funcs
=
669 offscreen_window_surface_lock
,
670 offscreen_window_surface_unlock
,
671 offscreen_window_surface_get_bitmap_info
,
672 offscreen_window_surface_get_bounds
,
673 offscreen_window_surface_set_region
,
674 offscreen_window_surface_flush
,
675 offscreen_window_surface_destroy
678 void create_offscreen_window_surface( const RECT
*visible_rect
, struct window_surface
**surface
)
680 struct offscreen_window_surface
*impl
;
682 RECT surface_rect
= *visible_rect
;
684 TRACE( "visible_rect %s, surface %p.\n", wine_dbgstr_rect( visible_rect
), surface
);
686 OffsetRect( &surface_rect
, -surface_rect
.left
, -surface_rect
.top
);
687 surface_rect
.right
= (surface_rect
.right
+ 0x1f) & ~0x1f;
688 surface_rect
.bottom
= (surface_rect
.bottom
+ 0x1f) & ~0x1f;
690 /* check that old surface is an offscreen_window_surface, or release it */
691 if ((impl
= impl_from_window_surface( *surface
)))
693 /* if the rect didn't change, keep the same surface */
694 if (EqualRect( &surface_rect
, &impl
->header
.rect
)) return;
695 window_surface_release( &impl
->header
);
697 else if (*surface
) window_surface_release( *surface
);
699 /* create a new window surface */
701 size
= surface_rect
.right
* surface_rect
.bottom
* 4;
702 if (!(impl
= calloc(1, offsetof( struct offscreen_window_surface
, info
.bmiColors
[0] ) + size
))) return;
704 impl
->header
.funcs
= &offscreen_window_surface_funcs
;
705 impl
->header
.ref
= 1;
706 impl
->header
.rect
= surface_rect
;
708 InitializeCriticalSection( &impl
->cs
);
709 impl
->cs
.DebugInfo
->Spare
[0] = (DWORD_PTR
)(__FILE__
": surface");
710 reset_bounds( &impl
->bounds
);
712 impl
->bits
= (char *)&impl
->info
.bmiColors
[0];
713 impl
->info
.bmiHeader
.biSize
= sizeof( impl
->info
);
714 impl
->info
.bmiHeader
.biWidth
= surface_rect
.right
;
715 impl
->info
.bmiHeader
.biHeight
= surface_rect
.bottom
;
716 impl
->info
.bmiHeader
.biPlanes
= 1;
717 impl
->info
.bmiHeader
.biBitCount
= 32;
718 impl
->info
.bmiHeader
.biCompression
= BI_RGB
;
719 impl
->info
.bmiHeader
.biSizeImage
= size
;
721 TRACE( "created window surface %p\n", &impl
->header
);
723 *surface
= &impl
->header
;
726 /*******************************************************************
727 * register_window_surface
729 * Register a window surface in the global list, possibly replacing another one.
731 void register_window_surface( struct window_surface
*old
, struct window_surface
*new )
733 if (old
== new) return;
734 EnterCriticalSection( &surfaces_section
);
735 if (old
&& old
!= &dummy_surface
) list_remove( &old
->entry
);
736 if (new && new != &dummy_surface
) list_add_tail( &window_surfaces
, &new->entry
);
737 LeaveCriticalSection( &surfaces_section
);
741 /*******************************************************************
742 * flush_window_surfaces
744 * Flush pending output from all window surfaces.
746 void flush_window_surfaces( BOOL idle
)
748 static DWORD last_idle
;
750 struct window_surface
*surface
;
752 EnterCriticalSection( &surfaces_section
);
753 now
= GetTickCount();
754 if (idle
) last_idle
= now
;
755 /* if not idle, we only flush if there's evidence that the app never goes idle */
756 else if ((int)(now
- last_idle
) < 50) goto done
;
758 LIST_FOR_EACH_ENTRY( surface
, &window_surfaces
, struct window_surface
, entry
)
759 surface
->funcs
->flush( surface
);
761 LeaveCriticalSection( &surfaces_section
);
765 /***********************************************************************
768 * Return a pointer to the WND structure if local to the process,
769 * or WND_OTHER_PROCESS if handle may be valid in other process.
770 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
772 WND
*WIN_GetPtr( HWND hwnd
)
776 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) == WND_OTHER_PROCESS
)
778 if (is_desktop_window( hwnd
)) ptr
= WND_DESKTOP
;
784 /***********************************************************************
785 * WIN_IsCurrentProcess
787 * Check whether a given window belongs to the current process (and return the full handle).
789 HWND
WIN_IsCurrentProcess( HWND hwnd
)
794 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
795 ret
= ptr
->obj
.handle
;
796 WIN_ReleasePtr( ptr
);
801 /***********************************************************************
802 * WIN_IsCurrentThread
804 * Check whether a given window belongs to the current thread (and return the full handle).
806 HWND
WIN_IsCurrentThread( HWND hwnd
)
811 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
812 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->obj
.handle
;
813 WIN_ReleasePtr( ptr
);
818 /***********************************************************************
821 * Set the flags of a window and return the previous value.
823 UINT
win_set_flags( HWND hwnd
, UINT set_mask
, UINT clear_mask
)
826 WND
*ptr
= WIN_GetPtr( hwnd
);
828 if (!ptr
|| ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
830 ptr
->flags
= (ret
& ~clear_mask
) | set_mask
;
831 WIN_ReleasePtr( ptr
);
836 /***********************************************************************
839 * Convert a possibly truncated window handle to a full 32-bit handle.
841 HWND
WIN_GetFullHandle( HWND hwnd
)
845 if (!hwnd
|| (ULONG_PTR
)hwnd
>> 16) return hwnd
;
846 if (LOWORD(hwnd
) <= 1 || LOWORD(hwnd
) == 0xffff) return hwnd
;
847 /* do sign extension for -2 and -3 */
848 if (LOWORD(hwnd
) >= (WORD
)-3) return (HWND
)(LONG_PTR
)(INT16
)LOWORD(hwnd
);
850 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
852 if (ptr
== WND_DESKTOP
)
854 if (LOWORD(hwnd
) == LOWORD(GetDesktopWindow())) return GetDesktopWindow();
855 else return get_hwnd_message_parent();
858 if (ptr
!= WND_OTHER_PROCESS
)
860 hwnd
= ptr
->obj
.handle
;
861 WIN_ReleasePtr( ptr
);
863 else /* may belong to another process */
865 SERVER_START_REQ( get_window_info
)
867 req
->handle
= wine_server_user_handle( hwnd
);
868 if (!wine_server_call_err( req
)) hwnd
= wine_server_ptr_handle( reply
->full_handle
);
876 /***********************************************************************
879 * Change the owner of a window.
881 static HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
883 WND
*win
= WIN_GetPtr( hwnd
);
886 if (!win
|| win
== WND_DESKTOP
) return 0;
887 if (win
== WND_OTHER_PROCESS
)
889 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
892 SERVER_START_REQ( set_window_owner
)
894 req
->handle
= wine_server_user_handle( hwnd
);
895 req
->owner
= wine_server_user_handle( owner
);
896 if (!wine_server_call( req
))
898 win
->owner
= wine_server_ptr_handle( reply
->full_owner
);
899 ret
= wine_server_ptr_handle( reply
->prev_owner
);
903 WIN_ReleasePtr( win
);
908 /***********************************************************************
911 * Change the style of a window.
913 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
915 BOOL ok
, made_visible
= FALSE
;
917 WND
*win
= WIN_GetPtr( hwnd
);
919 if (!win
|| win
== WND_DESKTOP
) return 0;
920 if (win
== WND_OTHER_PROCESS
)
923 return SendMessageW(hwnd
, WM_WINE_SETSTYLE
, set_bits
, clear_bits
);
926 style
.styleOld
= win
->dwStyle
;
927 style
.styleNew
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
928 if (style
.styleNew
== style
.styleOld
)
930 WIN_ReleasePtr( win
);
931 return style
.styleNew
;
933 SERVER_START_REQ( set_window_info
)
935 req
->handle
= wine_server_user_handle( hwnd
);
936 req
->flags
= SET_WIN_STYLE
;
937 req
->style
= style
.styleNew
;
938 req
->extra_offset
= -1;
939 if ((ok
= !wine_server_call( req
)))
941 style
.styleOld
= reply
->old_style
;
942 win
->dwStyle
= style
.styleNew
;
947 if (ok
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
))
949 made_visible
= (style
.styleNew
& WS_VISIBLE
) != 0;
950 invalidate_dce( win
, NULL
);
952 WIN_ReleasePtr( win
);
956 USER_Driver
->pSetWindowStyle( hwnd
, GWL_STYLE
, &style
);
957 if (made_visible
) update_window_state( hwnd
);
959 return style
.styleOld
;
963 /***********************************************************************
966 * Get the window and client rectangles.
968 BOOL
WIN_GetRectangles( HWND hwnd
, enum coords_relative relative
, RECT
*rectWindow
, RECT
*rectClient
)
970 WND
*win
= WIN_GetPtr( hwnd
);
975 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
978 if (win
== WND_DESKTOP
)
981 rect
.left
= rect
.top
= 0;
982 if (hwnd
== get_hwnd_message_parent())
986 rect
= rect_win_to_thread_dpi( hwnd
, rect
);
990 rect
= get_primary_monitor_rect();
992 if (rectWindow
) *rectWindow
= rect
;
993 if (rectClient
) *rectClient
= rect
;
996 if (win
!= WND_OTHER_PROCESS
)
998 RECT window_rect
= win
->window_rect
, client_rect
= win
->client_rect
;
1003 OffsetRect( &window_rect
, -win
->client_rect
.left
, -win
->client_rect
.top
);
1004 OffsetRect( &client_rect
, -win
->client_rect
.left
, -win
->client_rect
.top
);
1005 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
1006 mirror_rect( &win
->client_rect
, &window_rect
);
1009 OffsetRect( &window_rect
, -win
->window_rect
.left
, -win
->window_rect
.top
);
1010 OffsetRect( &client_rect
, -win
->window_rect
.left
, -win
->window_rect
.top
);
1011 if (win
->dwExStyle
& WS_EX_LAYOUTRTL
)
1012 mirror_rect( &win
->window_rect
, &client_rect
);
1017 WND
*parent
= WIN_GetPtr( win
->parent
);
1018 if (parent
== WND_DESKTOP
) break;
1019 if (!parent
|| parent
== WND_OTHER_PROCESS
)
1021 WIN_ReleasePtr( win
);
1024 if (parent
->flags
& WIN_CHILDREN_MOVED
)
1026 WIN_ReleasePtr( parent
);
1027 WIN_ReleasePtr( win
);
1030 if (parent
->dwExStyle
& WS_EX_LAYOUTRTL
)
1032 mirror_rect( &parent
->client_rect
, &window_rect
);
1033 mirror_rect( &parent
->client_rect
, &client_rect
);
1035 WIN_ReleasePtr( parent
);
1041 WND
*parent
= WIN_GetPtr( win
->parent
);
1042 if (parent
== WND_DESKTOP
) break;
1043 if (!parent
|| parent
== WND_OTHER_PROCESS
)
1045 WIN_ReleasePtr( win
);
1048 WIN_ReleasePtr( win
);
1049 if (parent
->flags
& WIN_CHILDREN_MOVED
)
1051 WIN_ReleasePtr( parent
);
1057 OffsetRect( &window_rect
, win
->client_rect
.left
, win
->client_rect
.top
);
1058 OffsetRect( &client_rect
, win
->client_rect
.left
, win
->client_rect
.top
);
1063 if (rectWindow
) *rectWindow
= rect_win_to_thread_dpi( hwnd
, window_rect
);
1064 if (rectClient
) *rectClient
= rect_win_to_thread_dpi( hwnd
, client_rect
);
1065 WIN_ReleasePtr( win
);
1070 SERVER_START_REQ( get_window_rectangles
)
1072 req
->handle
= wine_server_user_handle( hwnd
);
1073 req
->relative
= relative
;
1074 req
->dpi
= get_thread_dpi();
1075 if ((ret
= !wine_server_call_err( req
)))
1079 rectWindow
->left
= reply
->window
.left
;
1080 rectWindow
->top
= reply
->window
.top
;
1081 rectWindow
->right
= reply
->window
.right
;
1082 rectWindow
->bottom
= reply
->window
.bottom
;
1086 rectClient
->left
= reply
->client
.left
;
1087 rectClient
->top
= reply
->client
.top
;
1088 rectClient
->right
= reply
->client
.right
;
1089 rectClient
->bottom
= reply
->client
.bottom
;
1098 /***********************************************************************
1101 * Destroy storage associated to a window. "Internals" p.358
1103 LRESULT
WIN_DestroyWindow( HWND hwnd
)
1107 HMENU menu
= 0, sys_menu
;
1108 struct window_surface
*surface
;
1110 TRACE("%p\n", hwnd
);
1112 /* destroy default IME window */
1113 if (win_set_flags( hwnd
, 0, WIN_HAS_IME_WIN
) & WIN_HAS_IME_WIN
)
1115 TRACE("unregister IME window for %p\n", hwnd
);
1116 imm_unregister_window( hwnd
);
1119 /* free child windows */
1120 if ((list
= WIN_ListChildren( hwnd
)))
1123 for (i
= 0; list
[i
]; i
++)
1125 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
1126 else SendNotifyMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
1128 HeapFree( GetProcessHeap(), 0, list
);
1131 /* Unlink now so we won't bother with the children later on */
1132 SERVER_START_REQ( set_parent
)
1134 req
->handle
= wine_server_user_handle( hwnd
);
1136 wine_server_call( req
);
1141 * Send the WM_NCDESTROY to the window being destroyed.
1143 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
1145 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
1147 /* free resources associated with the window */
1149 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1150 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1151 menu
= (HMENU
)wndPtr
->wIDmenu
;
1152 sys_menu
= wndPtr
->hSysMenu
;
1153 free_dce( wndPtr
->dce
, hwnd
);
1155 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
1156 wndPtr
->text
= NULL
;
1157 HeapFree( GetProcessHeap(), 0, wndPtr
->pScroll
);
1158 wndPtr
->pScroll
= NULL
;
1159 DestroyIcon( wndPtr
->hIconSmall2
);
1160 surface
= wndPtr
->surface
;
1161 wndPtr
->surface
= NULL
;
1162 WIN_ReleasePtr( wndPtr
);
1164 if (menu
) DestroyMenu( menu
);
1165 if (sys_menu
) DestroyMenu( sys_menu
);
1168 register_window_surface( surface
, NULL
);
1169 window_surface_release( surface
);
1172 USER_Driver
->pDestroyWindow( hwnd
);
1174 free_window_handle( hwnd
);
1179 /***********************************************************************
1180 * next_thread_window
1182 static WND
*next_thread_window( HWND
*hwnd
)
1184 struct user_object
*ptr
;
1186 WORD index
= *hwnd
? USER_HANDLE_TO_INDEX( *hwnd
) + 1 : 0;
1189 while (index
< NB_USER_HANDLES
)
1191 if (!(ptr
= user_handles
[index
++])) continue;
1192 if (ptr
->type
!= USER_WINDOW
) continue;
1194 if (win
->tid
!= GetCurrentThreadId()) continue;
1195 *hwnd
= ptr
->handle
;
1203 /***********************************************************************
1204 * destroy_thread_windows
1206 * Destroy all window owned by the current thread.
1208 void destroy_thread_windows(void)
1211 HWND hwnd
= 0, *list
;
1212 HMENU menu
, sys_menu
;
1213 struct window_surface
*surface
;
1216 while ((wndPtr
= next_thread_window( &hwnd
)))
1218 /* destroy the client-side storage */
1220 list
= WIN_ListChildren( hwnd
);
1221 menu
= ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
) ? (HMENU
)wndPtr
->wIDmenu
: 0;
1222 sys_menu
= wndPtr
->hSysMenu
;
1223 free_dce( wndPtr
->dce
, hwnd
);
1224 surface
= wndPtr
->surface
;
1225 InterlockedCompareExchangePointer( &user_handles
[USER_HANDLE_TO_INDEX(hwnd
)], NULL
, wndPtr
);
1226 WIN_ReleasePtr( wndPtr
);
1227 HeapFree( GetProcessHeap(), 0, wndPtr
);
1228 if (menu
) DestroyMenu( menu
);
1229 if (sys_menu
) DestroyMenu( sys_menu
);
1232 register_window_surface( surface
, NULL
);
1233 window_surface_release( surface
);
1236 /* free child windows */
1238 if (!list
) continue;
1239 for (i
= 0; list
[i
]; i
++)
1240 if (!WIN_IsCurrentThread( list
[i
] ))
1241 SendNotifyMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
1242 HeapFree( GetProcessHeap(), 0, list
);
1247 /***********************************************************************
1248 * WIN_FixCoordinates
1250 * Fix the coordinates - Helper for WIN_CreateWindowEx.
1251 * returns default show mode in sw.
1253 static void WIN_FixCoordinates( CREATESTRUCTW
*cs
, INT
*sw
)
1255 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == (SHORT)0x8000)
1258 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1262 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
1263 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= ULongToHandle(id
);
1265 TRACE("MDI child id %04x\n", id
);
1268 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
1270 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1272 if (IS_DEFAULT(cs
->x
))
1277 if (IS_DEFAULT(cs
->cx
) || !cs
->cx
) cs
->cx
= pos
[1].x
;
1278 if (IS_DEFAULT(cs
->cy
) || !cs
->cy
) cs
->cy
= pos
[1].y
;
1282 if (IS_DEFAULT(cs
->x
)) cs
->x
= cs
->y
= 0;
1283 if (IS_DEFAULT(cs
->cx
)) cs
->cx
= cs
->cy
= 0;
1286 else /* overlapped window */
1289 MONITORINFO mon_info
;
1292 if (!IS_DEFAULT(cs
->x
) && !IS_DEFAULT(cs
->cx
) && !IS_DEFAULT(cs
->cy
)) return;
1294 monitor
= MonitorFromWindow( cs
->hwndParent
, MONITOR_DEFAULTTOPRIMARY
);
1295 mon_info
.cbSize
= sizeof(mon_info
);
1296 GetMonitorInfoW( monitor
, &mon_info
);
1297 GetStartupInfoW( &info
);
1299 if (IS_DEFAULT(cs
->x
))
1301 if (!IS_DEFAULT(cs
->y
)) *sw
= cs
->y
;
1302 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: mon_info
.rcWork
.left
;
1303 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: mon_info
.rcWork
.top
;
1306 if (IS_DEFAULT(cs
->cx
))
1308 if (info
.dwFlags
& STARTF_USESIZE
)
1310 cs
->cx
= info
.dwXSize
;
1311 cs
->cy
= info
.dwYSize
;
1315 cs
->cx
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) * 3 / 4 - cs
->x
;
1316 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1319 /* neither x nor cx are default. Check the y values .
1320 * In the trace we see Outlook and Outlook Express using
1321 * cy set to CW_USEDEFAULT when opening the address book.
1323 else if (IS_DEFAULT(cs
->cy
))
1325 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
1326 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
1332 /***********************************************************************
1333 * dump_window_styles
1335 static void dump_window_styles( DWORD style
, DWORD exstyle
)
1338 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
1339 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
1340 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
1341 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
1342 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
1343 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
1344 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
1345 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
1346 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
1349 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
1350 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
1352 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
1353 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
1354 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
1355 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
1356 if (style
& WS_CHILD
)
1358 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
1359 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
1363 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
1364 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
1367 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
1368 #define DUMPED_STYLES \
1369 ((DWORD)(WS_POPUP | \
1388 if(style
& ~DUMPED_STYLES
) TRACE(" %08x", style
& ~DUMPED_STYLES
);
1390 #undef DUMPED_STYLES
1392 TRACE( "exstyle:" );
1393 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
1394 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
1395 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
1396 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
1397 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
1398 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
1399 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
1400 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
1401 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
1402 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
1403 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
1404 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
1405 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
1406 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
1407 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
1408 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
1409 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
1410 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
1411 if(exstyle
& WS_EX_NOINHERITLAYOUT
) TRACE(" WS_EX_NOINHERITLAYOUT");
1412 if(exstyle
& WS_EX_LAYOUTRTL
) TRACE(" WS_EX_LAYOUTRTL");
1413 if(exstyle
& WS_EX_COMPOSITED
) TRACE(" WS_EX_COMPOSITED");
1414 if(exstyle
& WS_EX_NOACTIVATE
) TRACE(" WS_EX_NOACTIVATE");
1416 #define DUMPED_EX_STYLES \
1417 ((DWORD)(WS_EX_DLGMODALFRAME | \
1418 WS_EX_DRAGDETECT | \
1419 WS_EX_NOPARENTNOTIFY | \
1421 WS_EX_ACCEPTFILES | \
1422 WS_EX_TRANSPARENT | \
1424 WS_EX_TOOLWINDOW | \
1425 WS_EX_WINDOWEDGE | \
1426 WS_EX_CLIENTEDGE | \
1427 WS_EX_CONTEXTHELP | \
1429 WS_EX_RTLREADING | \
1430 WS_EX_LEFTSCROLLBAR | \
1431 WS_EX_CONTROLPARENT | \
1432 WS_EX_STATICEDGE | \
1435 WS_EX_NOINHERITLAYOUT | \
1440 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08x", exstyle
& ~DUMPED_EX_STYLES
);
1442 #undef DUMPED_EX_STYLES
1445 /***********************************************************************
1446 * map_dpi_create_struct
1448 static void map_dpi_create_struct( CREATESTRUCTW
*cs
, UINT dpi_from
, UINT dpi_to
)
1450 if (!dpi_from
&& !dpi_to
) return;
1451 if (!dpi_from
|| !dpi_to
)
1453 POINT pt
= { cs
->x
, cs
->y
};
1454 UINT mon_dpi
= get_monitor_dpi( MonitorFromPoint( pt
, MONITOR_DEFAULTTONEAREST
));
1455 if (!dpi_from
) dpi_from
= mon_dpi
;
1456 else dpi_to
= mon_dpi
;
1458 if (dpi_from
== dpi_to
) return;
1459 cs
->x
= MulDiv( cs
->x
, dpi_to
, dpi_from
);
1460 cs
->y
= MulDiv( cs
->y
, dpi_to
, dpi_from
);
1461 cs
->cx
= MulDiv( cs
->cx
, dpi_to
, dpi_from
);
1462 cs
->cy
= MulDiv( cs
->cy
, dpi_to
, dpi_from
);
1465 /***********************************************************************
1468 static DWORD
fix_exstyle( DWORD style
, DWORD exstyle
)
1470 if ((exstyle
& WS_EX_DLGMODALFRAME
) ||
1471 (!(exstyle
& WS_EX_STATICEDGE
) &&
1472 (style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1473 exstyle
|= WS_EX_WINDOWEDGE
;
1475 exstyle
&= ~WS_EX_WINDOWEDGE
;
1479 /***********************************************************************
1480 * WIN_CreateWindowEx
1482 * Implementation of CreateWindowEx().
1484 HWND
WIN_CreateWindowEx( CREATESTRUCTW
*cs
, LPCWSTR className
, HINSTANCE module
, BOOL unicode
)
1486 INT cx
, cy
, style
, ex_style
, sw
= SW_SHOW
;
1490 HWND hwnd
, parent
, owner
, top_child
= 0;
1491 const WCHAR
*p
= className
;
1492 UINT win_dpi
, thread_dpi
= get_thread_dpi();
1493 DPI_AWARENESS_CONTEXT context
;
1494 MDICREATESTRUCTW mdi_cs
;
1495 CBT_CREATEWNDW cbtc
;
1498 className
= CLASS_GetVersionedName(className
, NULL
, NULL
, TRUE
);
1500 TRACE("%s %s%s%s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
1501 unicode
? debugstr_w(cs
->lpszName
) : debugstr_a((LPCSTR
)cs
->lpszName
),
1502 debugstr_w(p
), p
!= className
? "->" : "", p
!= className
? debugstr_w(className
) : "",
1503 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
1504 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
1505 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
1507 /* Fix the styles for MDI children */
1508 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1510 if (!(win_get_flags( cs
->hwndParent
) & WIN_ISMDICLIENT
))
1512 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
1516 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
1517 * MDICREATESTRUCT members have the originally passed values.
1519 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
1520 * have the same layout.
1522 mdi_cs
.szClass
= cs
->lpszClass
;
1523 mdi_cs
.szTitle
= cs
->lpszName
;
1524 mdi_cs
.hOwner
= cs
->hInstance
;
1529 mdi_cs
.style
= cs
->style
;
1530 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
1532 cs
->lpCreateParams
= &mdi_cs
;
1534 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1536 if (cs
->style
& WS_POPUP
)
1538 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
1541 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
1545 cs
->style
&= ~WS_POPUP
;
1546 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1547 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1550 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
1554 /* Restore current maximized child */
1555 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
1557 TRACE("Restoring current maximized child %p\n", top_child
);
1558 if (cs
->style
& WS_MAXIMIZE
)
1560 /* if the new window is maximized don't bother repainting */
1561 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
1562 ShowWindow( top_child
, SW_SHOWNORMAL
);
1563 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
1565 else ShowWindow( top_child
, SW_SHOWNORMAL
);
1570 /* Find the parent window */
1572 parent
= cs
->hwndParent
;
1575 if (cs
->hwndParent
== HWND_MESSAGE
)
1577 cs
->hwndParent
= parent
= get_hwnd_message_parent();
1579 else if (cs
->hwndParent
)
1581 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1583 parent
= GetDesktopWindow();
1584 owner
= cs
->hwndParent
;
1588 DWORD parent_style
= GetWindowLongW( parent
, GWL_EXSTYLE
);
1589 if ((parent_style
& WS_EX_LAYOUTRTL
) && !(parent_style
& WS_EX_NOINHERITLAYOUT
))
1590 cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1595 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1597 WARN("No parent for child window\n" );
1598 SetLastError(ERROR_TLW_WITH_WSCHILD
);
1599 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1602 /* are we creating the desktop or HWND_MESSAGE parent itself? */
1603 if (className
!= (LPCWSTR
)DESKTOP_CLASS_ATOM
&&
1604 (IS_INTRESOURCE(className
) || wcsicmp( className
, L
"Message" )))
1607 GetProcessDefaultLayout( &layout
);
1608 if (layout
& LAYOUT_RTL
) cs
->dwExStyle
|= WS_EX_LAYOUTRTL
;
1609 parent
= GetDesktopWindow();
1613 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
1614 cs
->dwExStyle
= fix_exstyle(cs
->style
, cs
->dwExStyle
);
1616 /* Create the window structure */
1618 style
= cs
->style
& ~WS_VISIBLE
;
1619 ex_style
= cs
->dwExStyle
& ~WS_EX_LAYERED
;
1620 if (!(wndPtr
= create_window_handle( parent
, owner
, className
, module
,
1621 unicode
, style
, ex_style
)))
1624 /* if it's a comctl32 class, GetClassInfo will load it, then we can retry */
1625 if (GetLastError() != ERROR_INVALID_HANDLE
||
1626 !GetClassInfoW( 0, className
, &wc
) ||
1627 !(wndPtr
= create_window_handle( parent
, owner
, className
, module
,
1628 unicode
, style
, ex_style
)))
1631 hwnd
= wndPtr
->obj
.handle
;
1633 /* Fill the window structure */
1635 wndPtr
->tid
= GetCurrentThreadId();
1636 wndPtr
->hInstance
= cs
->hInstance
;
1637 wndPtr
->text
= NULL
;
1638 wndPtr
->dwStyle
= style
;
1639 wndPtr
->dwExStyle
= ex_style
;
1640 wndPtr
->wIDmenu
= 0;
1641 wndPtr
->helpContext
= 0;
1642 wndPtr
->pScroll
= NULL
;
1643 wndPtr
->userdata
= 0;
1645 wndPtr
->hIconSmall
= 0;
1646 wndPtr
->hIconSmall2
= 0;
1647 wndPtr
->hSysMenu
= 0;
1649 wndPtr
->min_pos
.x
= wndPtr
->min_pos
.y
= -1;
1650 wndPtr
->max_pos
.x
= wndPtr
->max_pos
.y
= -1;
1651 SetRect( &wndPtr
->normal_rect
, cs
->x
, cs
->y
, cs
->x
+ cs
->cx
, cs
->y
+ cs
->cy
);
1653 if (wndPtr
->dwStyle
& WS_SYSMENU
) SetSystemMenu( hwnd
, 0 );
1655 /* call the WH_CBT hook */
1657 WIN_ReleasePtr( wndPtr
);
1660 cbtc
.hwndInsertAfter
= HWND_TOP
;
1661 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
) ||
1662 !(wndPtr
= WIN_GetPtr( hwnd
)))
1664 free_window_handle( hwnd
);
1669 * Correct the window styles.
1671 * It affects only the style loaded into the WIN structure.
1674 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1676 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1677 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1678 wndPtr
->dwStyle
|= WS_CAPTION
;
1681 wndPtr
->dwExStyle
= cs
->dwExStyle
;
1682 /* WS_EX_WINDOWEDGE depends on some other styles */
1683 if ((wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)) &&
1684 !(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1685 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1687 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1688 wndPtr
->flags
|= WIN_NEED_SIZE
;
1690 SERVER_START_REQ( set_window_info
)
1692 req
->handle
= wine_server_user_handle( hwnd
);
1693 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
| SET_WIN_UNICODE
;
1694 req
->style
= wndPtr
->dwStyle
;
1695 req
->ex_style
= wndPtr
->dwExStyle
;
1696 req
->instance
= wine_server_client_ptr( wndPtr
->hInstance
);
1697 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1698 req
->extra_offset
= -1;
1699 wine_server_call( req
);
1703 /* Set the window menu */
1705 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1709 if (!MENU_SetMenu(hwnd
, cs
->hMenu
))
1711 WIN_ReleasePtr( wndPtr
);
1712 free_window_handle( hwnd
);
1718 LPCWSTR menuName
= (LPCWSTR
)GetClassLongPtrW( hwnd
, GCLP_MENUNAME
);
1721 cs
->hMenu
= LoadMenuW( cs
->hInstance
, menuName
);
1722 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1726 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1728 win_dpi
= wndPtr
->dpi
;
1729 WIN_ReleasePtr( wndPtr
);
1731 if (parent
) map_dpi_create_struct( cs
, thread_dpi
, win_dpi
);
1733 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
1735 /* send the WM_GETMINMAXINFO message and fix the size if needed */
1739 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1741 MINMAXINFO info
= WINPOS_GetMinMaxInfo( hwnd
);
1742 cx
= max( min( cx
, info
.ptMaxTrackSize
.x
), info
.ptMinTrackSize
.x
);
1743 cy
= max( min( cy
, info
.ptMaxTrackSize
.y
), info
.ptMinTrackSize
.y
);
1748 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cx
, cs
->y
+ cy
);
1749 /* check for wraparound */
1750 if (cs
->x
> 0x7fffffff - cx
) rect
.right
= 0x7fffffff;
1751 if (cs
->y
> 0x7fffffff - cy
) rect
.bottom
= 0x7fffffff;
1752 if (!set_window_pos( hwnd
, 0, SWP_NOZORDER
| SWP_NOACTIVATE
, &rect
, &rect
, NULL
)) goto failed
;
1754 /* send WM_NCCREATE */
1756 TRACE( "hwnd %p cs %d,%d %dx%d %s\n", hwnd
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, wine_dbgstr_rect(&rect
) );
1758 result
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1760 result
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1763 WARN( "%p: aborted by WM_NCCREATE\n", hwnd
);
1767 /* create default IME window */
1769 if (imm_register_window
&& !is_desktop_window( hwnd
) &&
1770 parent
!= get_hwnd_message_parent() && imm_register_window( hwnd
))
1772 TRACE("register IME window for %p\n", hwnd
);
1773 win_set_flags( hwnd
, WIN_HAS_IME_WIN
, 0 );
1776 /* send WM_NCCALCSIZE */
1778 if (WIN_GetRectangles( hwnd
, COORDS_PARENT
, &rect
, NULL
))
1780 /* yes, even if the CBT hook was called with HWND_TOP */
1781 HWND insert_after
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1782 RECT client_rect
= rect
;
1784 /* the rectangle is in screen coords for WM_NCCALCSIZE when wparam is FALSE */
1785 MapWindowPoints( parent
, 0, (POINT
*)&client_rect
, 2 );
1786 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&client_rect
);
1787 MapWindowPoints( 0, parent
, (POINT
*)&client_rect
, 2 );
1788 set_window_pos( hwnd
, insert_after
, SWP_NOACTIVATE
, &rect
, &client_rect
, NULL
);
1792 /* send WM_CREATE */
1795 result
= SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1797 result
= SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1798 if (result
== -1) goto failed
;
1800 /* call the driver */
1802 if (!USER_Driver
->pCreateWindow( hwnd
)) goto failed
;
1804 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1806 /* send the size messages */
1808 if (!(win_get_flags( hwnd
) & WIN_NEED_SIZE
))
1810 WIN_GetRectangles( hwnd
, COORDS_PARENT
, NULL
, &rect
);
1811 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1812 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1813 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1816 /* Show the window, maximizing or minimizing if needed */
1818 style
= WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1819 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1822 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1824 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1825 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1826 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1827 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
, newPos
.right
- newPos
.left
,
1828 newPos
.bottom
- newPos
.top
, swFlag
);
1831 /* Notify the parent window only */
1833 send_parent_notify( hwnd
, WM_CREATE
);
1834 if (!IsWindow( hwnd
))
1836 SetThreadDpiAwarenessContext( context
);
1840 if (parent
== GetDesktopWindow())
1841 PostMessageW( parent
, WM_PARENTNOTIFY
, WM_CREATE
, (LPARAM
)hwnd
);
1843 if (cs
->style
& WS_VISIBLE
)
1845 if (cs
->style
& WS_MAXIMIZE
)
1847 else if (cs
->style
& WS_MINIMIZE
)
1848 sw
= SW_SHOWMINIMIZED
;
1850 ShowWindow( hwnd
, sw
);
1851 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1853 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1854 /* ShowWindow won't activate child windows */
1855 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1859 /* Call WH_SHELL hook */
1861 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1862 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1864 TRACE("created window %p\n", hwnd
);
1865 SetThreadDpiAwarenessContext( context
);
1869 WIN_DestroyWindow( hwnd
);
1870 SetThreadDpiAwarenessContext( context
);
1875 /***********************************************************************
1876 * CreateWindowExA (USER32.@)
1878 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1879 LPCSTR windowName
, DWORD style
, INT x
,
1880 INT y
, INT width
, INT height
,
1881 HWND parent
, HMENU menu
,
1882 HINSTANCE instance
, LPVOID data
)
1886 cs
.lpCreateParams
= data
;
1887 cs
.hInstance
= instance
;
1889 cs
.hwndParent
= parent
;
1895 cs
.lpszName
= windowName
;
1896 cs
.lpszClass
= className
;
1897 cs
.dwExStyle
= exStyle
;
1899 if (!IS_INTRESOURCE(className
))
1902 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, bufferW
, ARRAY_SIZE( bufferW
)))
1904 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, bufferW
, instance
, FALSE
);
1906 /* Note: we rely on the fact that CREATESTRUCTA and */
1907 /* CREATESTRUCTW have the same layout. */
1908 return wow_handlers
.create_window( (CREATESTRUCTW
*)&cs
, (LPCWSTR
)className
, instance
, FALSE
);
1912 /***********************************************************************
1913 * CreateWindowExW (USER32.@)
1915 HWND WINAPI DECLSPEC_HOTPATCH
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1916 LPCWSTR windowName
, DWORD style
, INT x
,
1917 INT y
, INT width
, INT height
,
1918 HWND parent
, HMENU menu
,
1919 HINSTANCE instance
, LPVOID data
)
1923 cs
.lpCreateParams
= data
;
1924 cs
.hInstance
= instance
;
1926 cs
.hwndParent
= parent
;
1932 cs
.lpszName
= windowName
;
1933 cs
.lpszClass
= className
;
1934 cs
.dwExStyle
= exStyle
;
1936 return wow_handlers
.create_window( &cs
, className
, instance
, TRUE
);
1940 /***********************************************************************
1941 * WIN_SendDestroyMsg
1943 static void WIN_SendDestroyMsg( HWND hwnd
)
1947 info
.cbSize
= sizeof(info
);
1948 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1950 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1951 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1954 if (hwnd
== NtUserGetClipboardOwner()) CLIPBOARD_ReleaseOwner( hwnd
);
1957 * Send the WM_DESTROY to the window.
1959 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1962 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1963 * make sure that the window still exists when we come back.
1970 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1972 for (i
= 0; pWndArray
[i
]; i
++)
1974 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1976 HeapFree( GetProcessHeap(), 0, pWndArray
);
1979 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1983 /***********************************************************************
1984 * DestroyWindow (USER32.@)
1986 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1990 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || is_desktop_window( hwnd
))
1992 SetLastError( ERROR_ACCESS_DENIED
);
1996 TRACE("(%p)\n", hwnd
);
2000 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
2002 if (MENU_IsMenuActive() == hwnd
)
2005 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
2009 if (!USER_IsExitingThread( GetCurrentThreadId() ))
2010 send_parent_notify( hwnd
, WM_DESTROY
);
2012 else if (!GetWindow( hwnd
, GW_OWNER
))
2014 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
2015 /* FIXME: clean up palette - see "Internals" p.352 */
2018 if (!IsWindow(hwnd
)) return TRUE
;
2020 /* Hide the window */
2021 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
2023 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
2025 ShowWindow( hwnd
, SW_HIDE
);
2027 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
2028 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
2031 if (!IsWindow(hwnd
)) return TRUE
;
2033 /* Recursively destroy owned windows */
2040 BOOL got_one
= FALSE
;
2041 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
2044 for (i
= 0; list
[i
]; i
++)
2046 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
2047 if (WIN_IsCurrentThread( list
[i
] ))
2049 DestroyWindow( list
[i
] );
2053 WIN_SetOwner( list
[i
], 0 );
2055 HeapFree( GetProcessHeap(), 0, list
);
2057 if (!got_one
) break;
2061 /* Send destroy messages */
2063 WIN_SendDestroyMsg( hwnd
);
2064 if (!IsWindow( hwnd
)) return TRUE
;
2066 /* Destroy the window storage */
2068 WIN_DestroyWindow( hwnd
);
2073 /***********************************************************************
2074 * CloseWindow (USER32.@)
2076 BOOL WINAPI
CloseWindow( HWND hwnd
)
2078 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
2079 ShowWindow( hwnd
, SW_MINIMIZE
);
2084 /***********************************************************************
2085 * OpenIcon (USER32.@)
2087 BOOL WINAPI
OpenIcon( HWND hwnd
)
2089 if (!IsIconic( hwnd
)) return FALSE
;
2090 ShowWindow( hwnd
, SW_SHOWNORMAL
);
2095 /***********************************************************************
2096 * FindWindowExW (USER32.@)
2098 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
, LPCWSTR className
, LPCWSTR title
)
2103 WCHAR
*buffer
= NULL
;
2105 if (!parent
&& child
) parent
= GetDesktopWindow();
2106 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
2110 len
= lstrlenW(title
) + 1; /* one extra char to check for chars beyond the end */
2111 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
2114 if (!(list
= list_window_children( 0, parent
, className
, 0 ))) goto done
;
2118 child
= WIN_GetFullHandle( child
);
2119 while (list
[i
] && list
[i
] != child
) i
++;
2120 if (!list
[i
]) goto done
;
2121 i
++; /* start from next window */
2128 if (InternalGetWindowText( list
[i
], buffer
, len
+ 1 ))
2130 if (!wcsicmp( buffer
, title
)) break;
2134 if (!title
[0]) break;
2142 HeapFree( GetProcessHeap(), 0, list
);
2143 HeapFree( GetProcessHeap(), 0, buffer
);
2149 /***********************************************************************
2150 * FindWindowA (USER32.@)
2152 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
2154 HWND ret
= FindWindowExA( 0, 0, className
, title
);
2155 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
2160 /***********************************************************************
2161 * FindWindowExA (USER32.@)
2163 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
, LPCSTR className
, LPCSTR title
)
2165 LPWSTR titleW
= NULL
;
2170 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
2171 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
2172 MultiByteToWideChar( CP_ACP
, 0, title
, -1, titleW
, len
);
2175 if (!IS_INTRESOURCE(className
))
2178 if (MultiByteToWideChar( CP_ACP
, 0, className
, -1, classW
, ARRAY_SIZE( classW
)))
2179 hwnd
= FindWindowExW( parent
, child
, classW
, titleW
);
2183 hwnd
= FindWindowExW( parent
, child
, (LPCWSTR
)className
, titleW
);
2186 HeapFree( GetProcessHeap(), 0, titleW
);
2191 /***********************************************************************
2192 * FindWindowW (USER32.@)
2194 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
2196 return FindWindowExW( 0, 0, className
, title
);
2200 /**********************************************************************
2201 * GetDesktopWindow (USER32.@)
2203 HWND WINAPI
GetDesktopWindow(void)
2205 struct user_thread_info
*thread_info
= get_user_thread_info();
2207 if (thread_info
->top_window
) return thread_info
->top_window
;
2209 SERVER_START_REQ( get_desktop_window
)
2212 if (!wine_server_call( req
))
2214 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2215 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2220 if (!thread_info
->top_window
)
2223 PROCESS_INFORMATION pi
;
2224 WCHAR windir
[MAX_PATH
];
2225 WCHAR app
[MAX_PATH
+ ARRAY_SIZE( L
"\\explorer.exe" )];
2226 WCHAR cmdline
[MAX_PATH
+ ARRAY_SIZE( L
"\\explorer.exe /desktop" )];
2227 WCHAR desktop
[MAX_PATH
];
2230 SERVER_START_REQ( set_user_object_info
)
2232 req
->handle
= wine_server_obj_handle( NtUserGetThreadDesktop(GetCurrentThreadId()) );
2233 req
->flags
= SET_USER_OBJECT_GET_FULL_NAME
;
2234 wine_server_set_reply( req
, desktop
, sizeof(desktop
) - sizeof(WCHAR
) );
2235 if (!wine_server_call( req
))
2237 size_t size
= wine_server_reply_size( reply
);
2238 desktop
[size
/ sizeof(WCHAR
)] = 0;
2239 TRACE( "starting explorer for desktop %s\n", debugstr_w(desktop
) );
2246 memset( &si
, 0, sizeof(si
) );
2248 si
.lpDesktop
= *desktop
? desktop
: NULL
;
2249 si
.dwFlags
= STARTF_USESTDHANDLES
;
2252 si
.hStdError
= GetStdHandle( STD_ERROR_HANDLE
);
2254 GetSystemDirectoryW( windir
, MAX_PATH
);
2255 lstrcpyW( app
, windir
);
2256 lstrcatW( app
, L
"\\explorer.exe" );
2257 lstrcpyW( cmdline
, app
);
2258 lstrcatW( cmdline
, L
" /desktop" );
2260 Wow64DisableWow64FsRedirection( &redir
);
2261 if (CreateProcessW( app
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
,
2262 NULL
, windir
, &si
, &pi
))
2264 TRACE( "started explorer pid %04x tid %04x\n", pi
.dwProcessId
, pi
.dwThreadId
);
2265 WaitForInputIdle( pi
.hProcess
, 10000 );
2266 CloseHandle( pi
.hThread
);
2267 CloseHandle( pi
.hProcess
);
2269 else WARN( "failed to start explorer, err %d\n", GetLastError() );
2270 Wow64RevertWow64FsRedirection( redir
);
2272 SERVER_START_REQ( get_desktop_window
)
2275 if (!wine_server_call( req
))
2277 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
2278 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
2284 if (!thread_info
->top_window
|| !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
2285 ERR( "failed to create desktop window\n" );
2287 register_builtin_classes();
2288 return thread_info
->top_window
;
2292 /*******************************************************************
2293 * EnableWindow (USER32.@)
2295 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
2299 if (is_broadcast(hwnd
))
2301 SetLastError( ERROR_INVALID_PARAMETER
);
2305 TRACE("( %p, %d )\n", hwnd
, enable
);
2309 retvalue
= (WIN_SetStyle( hwnd
, 0, WS_DISABLED
) & WS_DISABLED
) != 0;
2310 if (retvalue
) SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
2314 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0 );
2316 retvalue
= (WIN_SetStyle( hwnd
, WS_DISABLED
, 0 ) & WS_DISABLED
) != 0;
2319 if (hwnd
== GetFocus())
2320 SetFocus( 0 ); /* A disabled window can't have the focus */
2322 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
2329 /***********************************************************************
2330 * IsWindowEnabled (USER32.@)
2332 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
2336 SetLastError(NO_ERROR
);
2337 ret
= GetWindowLongW( hWnd
, GWL_STYLE
);
2338 if (!ret
&& GetLastError() != NO_ERROR
) return FALSE
;
2339 return !(ret
& WS_DISABLED
);
2342 /***********************************************************************
2343 * IsWindowUnicode (USER32.@)
2345 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
2348 BOOL retvalue
= FALSE
;
2350 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
2352 if (wndPtr
== WND_DESKTOP
) return TRUE
;
2354 if (wndPtr
!= WND_OTHER_PROCESS
)
2356 retvalue
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2357 WIN_ReleasePtr( wndPtr
);
2361 SERVER_START_REQ( get_window_info
)
2363 req
->handle
= wine_server_user_handle( hwnd
);
2364 if (!wine_server_call_err( req
)) retvalue
= reply
->is_unicode
;
2372 /***********************************************************************
2373 * GetWindowDpiAwarenessContext (USER32.@)
2375 DPI_AWARENESS_CONTEXT WINAPI
GetWindowDpiAwarenessContext( HWND hwnd
)
2378 DPI_AWARENESS_CONTEXT ret
= 0;
2380 if (!(win
= WIN_GetPtr( hwnd
)))
2382 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2385 if (win
== WND_DESKTOP
) return DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
;
2386 if (win
!= WND_OTHER_PROCESS
)
2388 ret
= ULongToHandle( win
->dpi_awareness
| 0x10 );
2389 WIN_ReleasePtr( win
);
2393 SERVER_START_REQ( get_window_info
)
2395 req
->handle
= wine_server_user_handle( hwnd
);
2396 if (!wine_server_call_err( req
)) ret
= ULongToHandle( reply
->awareness
| 0x10 );
2404 /***********************************************************************
2405 * GetDpiForWindow (USER32.@)
2407 UINT WINAPI
GetDpiForWindow( HWND hwnd
)
2412 if (!(win
= WIN_GetPtr( hwnd
)))
2414 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2417 if (win
== WND_DESKTOP
)
2419 POINT pt
= { 0, 0 };
2420 return get_monitor_dpi( MonitorFromPoint( pt
, MONITOR_DEFAULTTOPRIMARY
));
2422 if (win
!= WND_OTHER_PROCESS
)
2425 if (!ret
) ret
= get_win_monitor_dpi( hwnd
);
2426 WIN_ReleasePtr( win
);
2430 SERVER_START_REQ( get_window_info
)
2432 req
->handle
= wine_server_user_handle( hwnd
);
2433 if (!wine_server_call_err( req
)) ret
= reply
->dpi
;
2441 /**********************************************************************
2444 * Helper function for GetWindowLong().
2446 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
2448 LONG_PTR retvalue
= 0;
2451 if (offset
== GWLP_HWNDPARENT
)
2453 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
2454 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
2455 return (ULONG_PTR
)parent
;
2458 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2460 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2464 if (wndPtr
== WND_DESKTOP
)
2469 retvalue
= WS_POPUP
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
; /* message parent is not visible */
2470 if (WIN_GetFullHandle( hwnd
) == GetDesktopWindow())
2471 retvalue
|= WS_VISIBLE
;
2476 case GWLP_HINSTANCE
:
2479 SetLastError( ERROR_ACCESS_DENIED
);
2482 SetLastError( ERROR_INVALID_INDEX
);
2486 if (wndPtr
== WND_OTHER_PROCESS
)
2488 if (offset
== GWLP_WNDPROC
)
2490 SetLastError( ERROR_ACCESS_DENIED
);
2493 SERVER_START_REQ( set_window_info
)
2495 req
->handle
= wine_server_user_handle( hwnd
);
2496 req
->flags
= 0; /* don't set anything, just retrieve */
2497 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
2498 req
->extra_size
= (offset
>= 0) ? size
: 0;
2499 if (!wine_server_call_err( req
))
2503 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
2504 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
2505 case GWLP_ID
: retvalue
= reply
->old_id
; break;
2506 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
); break;
2507 case GWLP_USERDATA
: retvalue
= reply
->old_user_data
; break;
2509 if (offset
>= 0) retvalue
= get_win_data( &reply
->old_extra_value
, size
);
2510 else SetLastError( ERROR_INVALID_INDEX
);
2519 /* now we have a valid wndPtr */
2523 if (offset
> (int)(wndPtr
->cbWndExtra
- size
))
2525 WARN("Invalid offset %d\n", offset
);
2526 WIN_ReleasePtr( wndPtr
);
2527 SetLastError( ERROR_INVALID_INDEX
);
2530 retvalue
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2532 /* Special case for dialog window procedure */
2533 if ((offset
== DWLP_DLGPROC
) && (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2534 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, unicode
);
2535 WIN_ReleasePtr( wndPtr
);
2541 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
2542 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
2543 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
2544 case GWLP_ID
: retvalue
= wndPtr
->wIDmenu
; break;
2545 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
2547 /* This looks like a hack only for the edit control (see tests). This makes these controls
2548 * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests
2549 * that the hack is in GetWindowLongPtr[AW], not in winprocs.
2551 if (wndPtr
->winproc
== BUILTIN_WINPROC(WINPROC_EDIT
) && (!unicode
!= !(wndPtr
->flags
& WIN_ISUNICODE
)))
2552 retvalue
= (ULONG_PTR
)wndPtr
->winproc
;
2554 retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
);
2557 WARN("Unknown offset %d\n", offset
);
2558 SetLastError( ERROR_INVALID_INDEX
);
2561 WIN_ReleasePtr(wndPtr
);
2566 /**********************************************************************
2569 * Helper function for SetWindowLong().
2571 * 0 is the failure code. However, in the case of failure SetLastError
2572 * must be set to distinguish between a 0 return value and a failure.
2574 LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, UINT size
, LONG_PTR newval
, BOOL unicode
)
2577 BOOL ok
, made_visible
= FALSE
;
2578 LONG_PTR retval
= 0;
2581 TRACE( "%p %d %lx %c\n", hwnd
, offset
, newval
, unicode
? 'W' : 'A' );
2583 if (is_broadcast(hwnd
))
2585 SetLastError( ERROR_INVALID_PARAMETER
);
2589 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2591 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2594 if (wndPtr
== WND_DESKTOP
)
2596 /* can't change anything on the desktop window */
2597 SetLastError( ERROR_ACCESS_DENIED
);
2600 if (wndPtr
== WND_OTHER_PROCESS
)
2602 if (offset
== GWLP_WNDPROC
)
2604 SetLastError( ERROR_ACCESS_DENIED
);
2607 if (offset
> 32767 || offset
< -32767)
2609 SetLastError( ERROR_INVALID_INDEX
);
2612 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, MAKEWPARAM( offset
, size
), newval
);
2615 /* first some special cases */
2619 style
.styleOld
= wndPtr
->dwStyle
;
2620 style
.styleNew
= newval
;
2621 WIN_ReleasePtr( wndPtr
);
2622 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_STYLE
, (LPARAM
)&style
);
2623 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2624 newval
= style
.styleNew
;
2625 /* WS_CLIPSIBLINGS can't be reset on top-level windows */
2626 if (wndPtr
->parent
== GetDesktopWindow()) newval
|= WS_CLIPSIBLINGS
;
2627 /* WS_MINIMIZE can't be reset */
2628 if (wndPtr
->dwStyle
& WS_MINIMIZE
) newval
|= WS_MINIMIZE
;
2631 style
.styleOld
= wndPtr
->dwExStyle
;
2632 style
.styleNew
= newval
;
2633 WIN_ReleasePtr( wndPtr
);
2634 SendMessageW( hwnd
, WM_STYLECHANGING
, GWL_EXSTYLE
, (LPARAM
)&style
);
2635 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2636 /* WS_EX_TOPMOST can only be changed through SetWindowPos */
2637 newval
= (style
.styleNew
& ~WS_EX_TOPMOST
) | (wndPtr
->dwExStyle
& WS_EX_TOPMOST
);
2638 newval
= fix_exstyle(wndPtr
->dwStyle
, newval
);
2640 case GWLP_HWNDPARENT
:
2641 if (wndPtr
->parent
== GetDesktopWindow())
2643 WIN_ReleasePtr( wndPtr
);
2644 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
2648 WIN_ReleasePtr( wndPtr
);
2649 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
2654 UINT old_flags
= wndPtr
->flags
;
2655 retval
= WIN_GetWindowLong( hwnd
, offset
, size
, unicode
);
2656 proc
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2657 if (proc
) wndPtr
->winproc
= proc
;
2658 if (WINPROC_IsUnicode( proc
, unicode
)) wndPtr
->flags
|= WIN_ISUNICODE
;
2659 else wndPtr
->flags
&= ~WIN_ISUNICODE
;
2660 if (!((old_flags
^ wndPtr
->flags
) & WIN_ISUNICODE
))
2662 WIN_ReleasePtr( wndPtr
);
2665 /* update is_unicode flag on the server side */
2669 case GWLP_HINSTANCE
:
2673 if ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2674 (size
== sizeof(LONG_PTR
)) && wndPtr
->dlgInfo
)
2676 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
2677 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, unicode
);
2678 *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, unicode
);
2679 WIN_ReleasePtr( wndPtr
);
2684 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- size
))
2686 WARN("Invalid offset %d\n", offset
);
2687 WIN_ReleasePtr( wndPtr
);
2688 SetLastError( ERROR_INVALID_INDEX
);
2691 else if (get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
) == newval
)
2693 /* already set to the same value */
2694 WIN_ReleasePtr( wndPtr
);
2700 SERVER_START_REQ( set_window_info
)
2702 req
->handle
= wine_server_user_handle( hwnd
);
2703 req
->extra_offset
= -1;
2707 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
;
2708 req
->style
= newval
;
2709 req
->ex_style
= fix_exstyle(newval
, wndPtr
->dwExStyle
);
2712 req
->flags
= SET_WIN_EXSTYLE
;
2713 req
->ex_style
= newval
;
2716 req
->flags
= SET_WIN_ID
;
2719 case GWLP_HINSTANCE
:
2720 req
->flags
= SET_WIN_INSTANCE
;
2721 req
->instance
= wine_server_client_ptr( (void *)newval
);
2724 req
->flags
= SET_WIN_UNICODE
;
2725 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2728 req
->flags
= SET_WIN_USERDATA
;
2729 req
->user_data
= newval
;
2732 req
->flags
= SET_WIN_EXTRA
;
2733 req
->extra_offset
= offset
;
2734 req
->extra_size
= size
;
2735 set_win_data( &req
->extra_value
, newval
, size
);
2737 if ((ok
= !wine_server_call_err( req
)))
2742 wndPtr
->dwStyle
= newval
;
2743 wndPtr
->dwExStyle
= fix_exstyle(wndPtr
->dwStyle
, wndPtr
->dwExStyle
);
2744 retval
= reply
->old_style
;
2747 wndPtr
->dwExStyle
= newval
;
2748 retval
= reply
->old_ex_style
;
2751 wndPtr
->wIDmenu
= newval
;
2752 retval
= reply
->old_id
;
2754 case GWLP_HINSTANCE
:
2755 wndPtr
->hInstance
= (HINSTANCE
)newval
;
2756 retval
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
2761 wndPtr
->userdata
= newval
;
2762 retval
= reply
->old_user_data
;
2765 retval
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2766 set_win_data( (char *)wndPtr
->wExtra
+ offset
, newval
, size
);
2773 if ((offset
== GWL_STYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
)) ||
2774 (offset
== GWL_EXSTYLE
&& ((style
.styleOld
^ style
.styleNew
) & WS_EX_LAYERED
)))
2776 made_visible
= (wndPtr
->dwStyle
& WS_VISIBLE
) != 0;
2777 invalidate_dce( wndPtr
, NULL
);
2779 WIN_ReleasePtr( wndPtr
);
2783 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2785 style
.styleOld
= retval
;
2786 style
.styleNew
= newval
;
2787 USER_Driver
->pSetWindowStyle( hwnd
, offset
, &style
);
2788 if (made_visible
) update_window_state( hwnd
);
2789 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2796 /**********************************************************************
2797 * GetWindowWord (USER32.@)
2799 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
2804 case GWLP_HINSTANCE
:
2805 case GWLP_HWNDPARENT
:
2810 WARN("Invalid offset %d\n", offset
);
2811 SetLastError( ERROR_INVALID_INDEX
);
2816 return WIN_GetWindowLong( hwnd
, offset
, sizeof(WORD
), FALSE
);
2820 /**********************************************************************
2821 * GetWindowLongA (USER32.@)
2823 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2829 case GWLP_HINSTANCE
:
2830 case GWLP_HWNDPARENT
:
2831 WARN( "Invalid offset %d\n", offset
);
2832 SetLastError( ERROR_INVALID_INDEX
);
2836 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), FALSE
);
2841 /**********************************************************************
2842 * GetWindowLongW (USER32.@)
2844 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2850 case GWLP_HINSTANCE
:
2851 case GWLP_HWNDPARENT
:
2852 WARN( "Invalid offset %d\n", offset
);
2853 SetLastError( ERROR_INVALID_INDEX
);
2857 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), TRUE
);
2862 /**********************************************************************
2863 * SetWindowWord (USER32.@)
2865 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
2870 case GWLP_HINSTANCE
:
2871 case GWLP_HWNDPARENT
:
2876 WARN("Invalid offset %d\n", offset
);
2877 SetLastError( ERROR_INVALID_INDEX
);
2882 return WIN_SetWindowLong( hwnd
, offset
, sizeof(WORD
), newval
, FALSE
);
2886 /**********************************************************************
2887 * SetWindowLongA (USER32.@)
2889 * See SetWindowLongW.
2891 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2897 case GWLP_HINSTANCE
:
2898 case GWLP_HWNDPARENT
:
2899 WARN( "Invalid offset %d\n", offset
);
2900 SetLastError( ERROR_INVALID_INDEX
);
2904 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, FALSE
);
2909 /**********************************************************************
2910 * SetWindowLongW (USER32.@) Set window attribute
2912 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2913 * value in a window's extra memory.
2915 * The _hwnd_ parameter specifies the handle to a window that
2916 * has extra memory. The _newval_ parameter contains the new
2917 * attribute or extra memory value. If positive, the _offset_
2918 * parameter is the byte-addressed location in the window's extra
2919 * memory to set. If negative, _offset_ specifies the window
2920 * attribute to set, and should be one of the following values:
2922 * GWL_EXSTYLE The window's extended window style
2924 * GWL_STYLE The window's window style.
2926 * GWLP_WNDPROC Pointer to the window's window procedure.
2928 * GWLP_HINSTANCE The window's application instance handle.
2930 * GWLP_ID The window's identifier.
2932 * GWLP_USERDATA The window's user-specified data.
2934 * If the window is a dialog box, the _offset_ parameter can be one of
2935 * the following values:
2937 * DWLP_DLGPROC The address of the window's dialog box procedure.
2939 * DWLP_MSGRESULT The return value of a message
2940 * that the dialog box procedure processed.
2942 * DWLP_USER Application specific information.
2946 * If successful, returns the previous value located at _offset_. Otherwise,
2951 * Extra memory for a window class is specified by a nonzero cbWndExtra
2952 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2953 * time of class creation.
2955 * Using GWL_WNDPROC to set a new window procedure effectively creates
2956 * a window subclass. Use CallWindowProc() in the new windows procedure
2957 * to pass messages to the superclass's window procedure.
2959 * The user data is reserved for use by the application which created
2962 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2963 * instead, call the EnableWindow() function to change the window's
2966 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2967 * SetParent() instead.
2970 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2971 * it sends WM_STYLECHANGING before changing the settings
2972 * and WM_STYLECHANGED afterwards.
2973 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2975 LONG WINAPI DECLSPEC_HOTPATCH
SetWindowLongW(
2976 HWND hwnd
, /* [in] window to alter */
2977 INT offset
, /* [in] offset, in bytes, of location to alter */
2978 LONG newval
/* [in] new value of location */
2985 case GWLP_HINSTANCE
:
2986 case GWLP_HWNDPARENT
:
2987 WARN("Invalid offset %d\n", offset
);
2988 SetLastError( ERROR_INVALID_INDEX
);
2992 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, TRUE
);
2997 /*******************************************************************
2998 * GetWindowTextA (USER32.@)
3000 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
3005 if (!lpString
|| nMaxCount
<= 0) return 0;
3011 if (WIN_IsCurrentProcess( hwnd
))
3013 ret
= (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
3015 else if ((buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) )))
3017 /* when window belongs to other process, don't send a message */
3018 get_server_window_text( hwnd
, buffer
, nMaxCount
);
3019 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
3020 lpString
[nMaxCount
-1] = 0;
3021 HeapFree( GetProcessHeap(), 0, buffer
);
3022 ret
= strlen(lpString
);
3035 /*******************************************************************
3036 * InternalGetWindowText (USER32.@)
3038 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
3042 if (nMaxCount
<= 0) return 0;
3043 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
3044 if (win
== WND_DESKTOP
) lpString
[0] = 0;
3045 else if (win
!= WND_OTHER_PROCESS
)
3047 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
3048 else lpString
[0] = 0;
3049 WIN_ReleasePtr( win
);
3053 get_server_window_text( hwnd
, lpString
, nMaxCount
);
3055 return lstrlenW(lpString
);
3059 /*******************************************************************
3060 * GetWindowTextW (USER32.@)
3062 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
3066 if (!lpString
|| nMaxCount
<= 0) return 0;
3072 if (WIN_IsCurrentProcess( hwnd
))
3074 ret
= (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
3078 /* when window belongs to other process, don't send a message */
3079 get_server_window_text( hwnd
, lpString
, nMaxCount
);
3080 ret
= lstrlenW(lpString
);
3093 /*******************************************************************
3094 * SetWindowTextA (USER32.@)
3095 * SetWindowText (USER32.@)
3097 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
3099 if (is_broadcast(hwnd
))
3101 SetLastError( ERROR_INVALID_PARAMETER
);
3104 if (!WIN_IsCurrentProcess( hwnd
))
3105 WARN( "setting text %s of other process window %p should not use SendMessage\n",
3106 debugstr_a(lpString
), hwnd
);
3107 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
3111 /*******************************************************************
3112 * SetWindowTextW (USER32.@)
3114 BOOL WINAPI DECLSPEC_HOTPATCH
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
3116 if (is_broadcast(hwnd
))
3118 SetLastError( ERROR_INVALID_PARAMETER
);
3121 if (!WIN_IsCurrentProcess( hwnd
))
3122 WARN( "setting text %s of other process window %p should not use SendMessage\n",
3123 debugstr_w(lpString
), hwnd
);
3124 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
3128 /*******************************************************************
3129 * GetWindowTextLengthA (USER32.@)
3131 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
3135 if (WIN_IsCurrentProcess( hwnd
)) return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
3137 /* when window belongs to other process, don't send a message */
3138 GetCPInfo( CP_ACP
, &info
);
3139 return get_server_window_text( hwnd
, NULL
, 0 ) * info
.MaxCharSize
;
3142 /*******************************************************************
3143 * GetWindowTextLengthW (USER32.@)
3145 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
3147 if (WIN_IsCurrentProcess( hwnd
)) return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
3149 /* when window belongs to other process, don't send a message */
3150 return get_server_window_text( hwnd
, NULL
, 0 );
3154 /*******************************************************************
3155 * IsWindow (USER32.@)
3157 BOOL WINAPI
IsWindow( HWND hwnd
)
3162 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
3163 if (ptr
== WND_DESKTOP
) return TRUE
;
3165 if (ptr
!= WND_OTHER_PROCESS
)
3167 WIN_ReleasePtr( ptr
);
3171 /* check other processes */
3172 SERVER_START_REQ( get_window_info
)
3174 req
->handle
= wine_server_user_handle( hwnd
);
3175 ret
= !wine_server_call_err( req
);
3182 /***********************************************************************
3183 * GetWindowThreadProcessId (USER32.@)
3185 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
3190 if (!(ptr
= WIN_GetPtr( hwnd
)))
3192 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3196 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
3198 /* got a valid window */
3200 if (process
) *process
= GetCurrentProcessId();
3201 WIN_ReleasePtr( ptr
);
3205 /* check other processes */
3206 SERVER_START_REQ( get_window_info
)
3208 req
->handle
= wine_server_user_handle( hwnd
);
3209 if (!wine_server_call_err( req
))
3211 tid
= (DWORD
)reply
->tid
;
3212 if (process
) *process
= (DWORD
)reply
->pid
;
3220 /*****************************************************************
3221 * GetParent (USER32.@)
3223 HWND WINAPI
GetParent( HWND hwnd
)
3228 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
3230 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3233 if (wndPtr
== WND_DESKTOP
) return 0;
3234 if (wndPtr
== WND_OTHER_PROCESS
)
3236 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3237 if (style
& (WS_POPUP
| WS_CHILD
))
3239 SERVER_START_REQ( get_window_tree
)
3241 req
->handle
= wine_server_user_handle( hwnd
);
3242 if (!wine_server_call_err( req
))
3244 if (style
& WS_POPUP
) retvalue
= wine_server_ptr_handle( reply
->owner
);
3245 else if (style
& WS_CHILD
) retvalue
= wine_server_ptr_handle( reply
->parent
);
3253 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
3254 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
3255 WIN_ReleasePtr( wndPtr
);
3261 /*****************************************************************
3262 * GetAncestor (USER32.@)
3264 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
3267 HWND
*list
, ret
= 0;
3272 if (!(win
= WIN_GetPtr( hwnd
)))
3274 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3277 if (win
== WND_DESKTOP
) return 0;
3278 if (win
!= WND_OTHER_PROCESS
)
3281 WIN_ReleasePtr( win
);
3283 else /* need to query the server */
3285 SERVER_START_REQ( get_window_tree
)
3287 req
->handle
= wine_server_user_handle( hwnd
);
3288 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->parent
);
3295 if (!(list
= list_window_parents( hwnd
))) return 0;
3297 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
3301 while (list
[count
]) count
++;
3302 ret
= list
[count
- 2]; /* get the one before the desktop */
3304 HeapFree( GetProcessHeap(), 0, list
);
3308 if (is_desktop_window( hwnd
)) return 0;
3309 ret
= WIN_GetFullHandle( hwnd
);
3312 HWND parent
= GetParent( ret
);
3322 /*****************************************************************
3323 * SetParent (USER32.@)
3325 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
3329 HWND old_parent
= 0;
3333 DPI_AWARENESS_CONTEXT context
;
3334 RECT window_rect
, old_screen_rect
, new_screen_rect
;
3336 TRACE("(%p %p)\n", hwnd
, parent
);
3338 if (is_broadcast(hwnd
) || is_broadcast(parent
))
3340 SetLastError(ERROR_INVALID_PARAMETER
);
3344 if (!parent
) parent
= GetDesktopWindow();
3345 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
3346 else parent
= WIN_GetFullHandle( parent
);
3348 if (!IsWindow( parent
))
3350 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3354 /* Some applications try to set a child as a parent */
3355 if (IsChild(hwnd
, parent
))
3357 SetLastError( ERROR_INVALID_PARAMETER
);
3361 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
3362 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
3364 if (full_handle
== parent
)
3366 SetLastError( ERROR_INVALID_PARAMETER
);
3370 /* Windows hides the window first, then shows it again
3371 * including the WM_SHOWWINDOW messages and all */
3372 was_visible
= ShowWindow( hwnd
, SW_HIDE
);
3374 wndPtr
= WIN_GetPtr( hwnd
);
3375 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
3377 context
= SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
3378 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, NULL
);
3379 SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
3380 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &old_screen_rect
, NULL
);
3381 SetThreadDpiAwarenessContext( context
);
3383 SERVER_START_REQ( set_parent
)
3385 req
->handle
= wine_server_user_handle( hwnd
);
3386 req
->parent
= wine_server_user_handle( parent
);
3387 if ((ret
= !wine_server_call( req
)))
3389 old_parent
= wine_server_ptr_handle( reply
->old_parent
);
3390 wndPtr
->parent
= parent
= wine_server_ptr_handle( reply
->full_parent
);
3391 wndPtr
->dpi
= reply
->dpi
;
3392 wndPtr
->dpi_awareness
= reply
->awareness
;
3397 WIN_ReleasePtr( wndPtr
);
3400 context
= SetThreadDpiAwarenessContext( DPI_AWARENESS_CONTEXT_PER_MONITOR_AWARE
);
3401 WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &new_screen_rect
, NULL
);
3402 SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( hwnd
));
3404 USER_Driver
->pSetParent( full_handle
, parent
, old_parent
);
3407 winpos
.hwndInsertAfter
= HWND_TOP
;
3408 winpos
.x
= window_rect
.left
;
3409 winpos
.y
= window_rect
.top
;
3412 winpos
.flags
= SWP_NOSIZE
;
3414 USER_SetWindowPos( &winpos
, new_screen_rect
.left
- old_screen_rect
.left
,
3415 new_screen_rect
.top
- old_screen_rect
.top
);
3417 if (was_visible
) ShowWindow( hwnd
, SW_SHOW
);
3419 SetThreadDpiAwarenessContext( context
);
3424 /*******************************************************************
3425 * IsChild (USER32.@)
3427 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
3433 if (!(GetWindowLongW( child
, GWL_STYLE
) & WS_CHILD
)) return FALSE
;
3434 if (!(list
= list_window_parents( child
))) return FALSE
;
3435 parent
= WIN_GetFullHandle( parent
);
3436 for (i
= 0; list
[i
]; i
++)
3438 if (list
[i
] == parent
)
3440 ret
= list
[i
] && list
[i
+1];
3443 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_CHILD
)) break;
3445 HeapFree( GetProcessHeap(), 0, list
);
3450 /***********************************************************************
3451 * IsWindowVisible (USER32.@)
3453 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
3459 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
3460 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3463 for (i
= 0; list
[i
+1]; i
++)
3464 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
3465 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3467 HeapFree( GetProcessHeap(), 0, list
);
3472 /***********************************************************************
3473 * WIN_IsWindowDrawable
3475 * hwnd is drawable when it is visible, all parents are not
3476 * minimized, and it is itself not minimized unless we are
3477 * trying to draw its default class icon.
3479 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
3484 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
3486 if (!(style
& WS_VISIBLE
)) return FALSE
;
3487 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
3489 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
3492 for (i
= 0; list
[i
+1]; i
++)
3493 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
3495 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
3497 HeapFree( GetProcessHeap(), 0, list
);
3502 /*******************************************************************
3503 * GetTopWindow (USER32.@)
3505 HWND WINAPI
GetTopWindow( HWND hwnd
)
3507 if (!hwnd
) hwnd
= GetDesktopWindow();
3508 return GetWindow( hwnd
, GW_CHILD
);
3512 /*******************************************************************
3513 * GetWindow (USER32.@)
3515 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
3519 if (rel
== GW_OWNER
) /* this one may be available locally */
3521 WND
*wndPtr
= WIN_GetPtr( hwnd
);
3524 SetLastError( ERROR_INVALID_HANDLE
);
3527 if (wndPtr
== WND_DESKTOP
) return 0;
3528 if (wndPtr
!= WND_OTHER_PROCESS
)
3530 retval
= wndPtr
->owner
;
3531 WIN_ReleasePtr( wndPtr
);
3534 /* else fall through to server call */
3537 SERVER_START_REQ( get_window_tree
)
3539 req
->handle
= wine_server_user_handle( hwnd
);
3540 if (!wine_server_call_err( req
))
3545 retval
= wine_server_ptr_handle( reply
->first_sibling
);
3548 retval
= wine_server_ptr_handle( reply
->last_sibling
);
3551 retval
= wine_server_ptr_handle( reply
->next_sibling
);
3554 retval
= wine_server_ptr_handle( reply
->prev_sibling
);
3557 retval
= wine_server_ptr_handle( reply
->owner
);
3560 retval
= wine_server_ptr_handle( reply
->first_child
);
3570 /*******************************************************************
3571 * ShowOwnedPopups (USER32.@)
3573 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
3576 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
3578 if (!win_array
) return TRUE
;
3580 while (win_array
[count
]) count
++;
3581 while (--count
>= 0)
3583 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
3586 if (win_get_flags( win_array
[count
] ) & WIN_NEEDS_SHOW_OWNEDPOPUP
)
3587 /* In Windows, ShowOwnedPopups(TRUE) generates
3588 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
3589 * regardless of the state of the owner
3591 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
3595 if (GetWindowLongW( win_array
[count
], GWL_STYLE
) & WS_VISIBLE
)
3596 /* In Windows, ShowOwnedPopups(FALSE) generates
3597 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
3598 * regardless of the state of the owner
3600 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
3603 HeapFree( GetProcessHeap(), 0, win_array
);
3608 /*******************************************************************
3609 * GetLastActivePopup (USER32.@)
3611 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
3615 SERVER_START_REQ( get_window_info
)
3617 req
->handle
= wine_server_user_handle( hwnd
);
3618 if (!wine_server_call_err( req
)) retval
= wine_server_ptr_handle( reply
->last_active
);
3625 /*******************************************************************
3628 * Build an array of the children of a given window. The array must be
3629 * freed with HeapFree. Returns NULL when no windows are found.
3631 HWND
*WIN_ListChildren( HWND hwnd
)
3635 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3638 return list_window_children( 0, hwnd
, NULL
, 0 );
3642 /*******************************************************************
3643 * EnumWindows (USER32.@)
3645 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
3651 USER_CheckNotLock();
3653 /* We have to build a list of all windows first, to avoid */
3654 /* unpleasant side-effects, for instance if the callback */
3655 /* function changes the Z-order of the windows. */
3657 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
3659 /* Now call the callback function for every window */
3661 for (i
= 0; list
[i
]; i
++)
3663 /* Make sure that the window still exists */
3664 if (!IsWindow( list
[i
] )) continue;
3665 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
3667 HeapFree( GetProcessHeap(), 0, list
);
3672 /**********************************************************************
3673 * EnumThreadWindows (USER32.@)
3675 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
3681 USER_CheckNotLock();
3683 if (!(list
= list_window_children( 0, GetDesktopWindow(), NULL
, id
))) return TRUE
;
3685 /* Now call the callback function for every window */
3687 for (i
= 0; list
[i
]; i
++)
3688 if (!(ret
= func( list
[i
], lParam
))) break;
3689 HeapFree( GetProcessHeap(), 0, list
);
3694 /***********************************************************************
3695 * EnumDesktopWindows (USER32.@)
3697 BOOL WINAPI
EnumDesktopWindows( HDESK desktop
, WNDENUMPROC func
, LPARAM lparam
)
3702 USER_CheckNotLock();
3704 if (!(list
= list_window_children( desktop
, 0, NULL
, 0 ))) return TRUE
;
3706 for (i
= 0; list
[i
]; i
++)
3707 if (!func( list
[i
], lparam
)) break;
3708 HeapFree( GetProcessHeap(), 0, list
);
3714 /* Some apps pass a non-stdcall proc to EnumChildWindows,
3715 * so we need a small assembly wrapper to call the proc.
3717 extern LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
);
3718 __ASM_GLOBAL_FUNC( enum_callback_wrapper
,
3720 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
3721 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
3722 "movl %esp,%ebp\n\t"
3723 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
3724 "pushl 16(%ebp)\n\t"
3725 "pushl 12(%ebp)\n\t"
3728 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
3729 __ASM_CFI(".cfi_same_value %ebp\n\t")
3732 static inline LRESULT
enum_callback_wrapper( WNDENUMPROC proc
, HWND hwnd
, LPARAM lparam
)
3734 return proc( hwnd
, lparam
);
3736 #endif /* __i386__ */
3738 /**********************************************************************
3739 * WIN_EnumChildWindows
3741 * Helper function for EnumChildWindows().
3743 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
3748 for ( ; *list
; list
++)
3750 /* Make sure that the window still exists */
3751 if (!IsWindow( *list
)) continue;
3752 /* Build children list first */
3753 childList
= WIN_ListChildren( *list
);
3755 ret
= enum_callback_wrapper( func
, *list
, lParam
);
3759 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
3760 HeapFree( GetProcessHeap(), 0, childList
);
3762 if (!ret
) return FALSE
;
3768 /**********************************************************************
3769 * EnumChildWindows (USER32.@)
3771 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
3776 USER_CheckNotLock();
3778 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
3779 ret
= WIN_EnumChildWindows( list
, func
, lParam
);
3780 HeapFree( GetProcessHeap(), 0, list
);
3785 /*******************************************************************
3786 * AnyPopup (USER32.@)
3788 BOOL WINAPI
AnyPopup(void)
3792 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
3794 if (!list
) return FALSE
;
3795 for (i
= 0; list
[i
]; i
++)
3797 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
3799 retvalue
= (list
[i
] != 0);
3800 HeapFree( GetProcessHeap(), 0, list
);
3805 /*******************************************************************
3806 * FlashWindow (USER32.@)
3808 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
3812 finfo
.cbSize
= sizeof(FLASHWINFO
);
3813 finfo
.dwFlags
= bInvert
? FLASHW_ALL
: FLASHW_STOP
;
3815 finfo
.dwTimeout
= 0;
3817 return FlashWindowEx( &finfo
);
3820 /*******************************************************************
3821 * FlashWindowEx (USER32.@)
3823 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfinfo
)
3827 TRACE( "%p\n", pfinfo
);
3831 SetLastError( ERROR_NOACCESS
);
3835 if (!pfinfo
->hwnd
|| pfinfo
->cbSize
!= sizeof(FLASHWINFO
) || !IsWindow( pfinfo
->hwnd
))
3837 SetLastError( ERROR_INVALID_PARAMETER
);
3840 FIXME( "%p - semi-stub\n", pfinfo
);
3842 if (IsIconic( pfinfo
->hwnd
))
3844 RedrawWindow( pfinfo
->hwnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
3846 wndPtr
= WIN_GetPtr( pfinfo
->hwnd
);
3847 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3848 if (pfinfo
->dwFlags
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
3850 wndPtr
->flags
|= WIN_NCACTIVATED
;
3854 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
3856 WIN_ReleasePtr( wndPtr
);
3857 USER_Driver
->pFlashWindowEx( pfinfo
);
3863 HWND hwnd
= pfinfo
->hwnd
;
3865 wndPtr
= WIN_GetPtr( hwnd
);
3866 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3867 hwnd
= wndPtr
->obj
.handle
; /* make it a full handle */
3869 if (pfinfo
->dwFlags
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
3870 else wparam
= (hwnd
== GetForegroundWindow());
3872 WIN_ReleasePtr( wndPtr
);
3873 SendMessageW( hwnd
, WM_NCACTIVATE
, wparam
, 0 );
3874 USER_Driver
->pFlashWindowEx( pfinfo
);
3879 /*******************************************************************
3880 * GetWindowContextHelpId (USER32.@)
3882 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
3885 WND
*wnd
= WIN_GetPtr( hwnd
);
3886 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
3887 if (wnd
== WND_OTHER_PROCESS
)
3889 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3892 retval
= wnd
->helpContext
;
3893 WIN_ReleasePtr( wnd
);
3898 /*******************************************************************
3899 * SetWindowContextHelpId (USER32.@)
3901 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
3903 WND
*wnd
= WIN_GetPtr( hwnd
);
3904 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
3905 if (wnd
== WND_OTHER_PROCESS
)
3907 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3910 wnd
->helpContext
= id
;
3911 WIN_ReleasePtr( wnd
);
3916 /*******************************************************************
3917 * DragDetect (USER32.@)
3919 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3923 WORD wDragWidth
, wDragHeight
;
3925 TRACE( "%p,%s\n", hWnd
, wine_dbgstr_point( &pt
) );
3927 if (!(NtUserGetKeyState( VK_LBUTTON
) & 0x8000))
3930 wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3931 wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3932 SetRect(&rect
, pt
.x
- wDragWidth
, pt
.y
- wDragHeight
, pt
.x
+ wDragWidth
, pt
.y
+ wDragHeight
);
3938 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
3940 if( msg
.message
== WM_LBUTTONUP
)
3945 if( msg
.message
== WM_MOUSEMOVE
)
3948 tmp
.x
= (short)LOWORD(msg
.lParam
);
3949 tmp
.y
= (short)HIWORD(msg
.lParam
);
3950 if( !PtInRect( &rect
, tmp
))
3962 /******************************************************************************
3963 * GetWindowModuleFileNameA (USER32.@)
3965 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR module
, UINT size
)
3970 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3972 win
= WIN_GetPtr( hwnd
);
3973 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3975 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3978 hinst
= win
->hInstance
;
3979 WIN_ReleasePtr( win
);
3981 return GetModuleFileNameA( hinst
, module
, size
);
3984 /******************************************************************************
3985 * GetWindowModuleFileNameW (USER32.@)
3987 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR module
, UINT size
)
3992 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3994 win
= WIN_GetPtr( hwnd
);
3995 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3997 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
4000 hinst
= win
->hInstance
;
4001 WIN_ReleasePtr( win
);
4003 return GetModuleFileNameW( hinst
, module
, size
);
4006 /******************************************************************************
4007 * GetWindowInfo (USER32.@)
4009 * Note: tests show that Windows doesn't check cbSize of the structure.
4011 BOOL WINAPI DECLSPEC_HOTPATCH
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
4013 RECT rcWindow
, rcClient
;
4015 if (!WIN_GetRectangles( hwnd
, COORDS_SCREEN
, &rcWindow
, &rcClient
)) return FALSE
;
4016 if (!pwi
) return FALSE
;
4018 pwi
->rcWindow
= rcWindow
;
4019 pwi
->rcClient
= rcClient
;
4020 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
4021 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
4022 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
4024 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
4025 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
4027 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
4028 pwi
->wCreatorVersion
= 0x0400;
4033 /******************************************************************************
4034 * SwitchDesktop (USER32.@)
4036 * NOTES: Sets the current input or interactive desktop.
4038 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
4040 FIXME("(hwnd %p) stub!\n", hDesktop
);
4045 /***********************************************************************
4046 * __wine_set_pixel_format
4048 BOOL CDECL
__wine_set_pixel_format( HWND hwnd
, int format
)
4050 WND
*win
= WIN_GetPtr( hwnd
);
4052 if (!win
|| win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
)
4054 WARN( "setting format %d on win %p not supported\n", format
, hwnd
);
4057 win
->pixel_format
= format
;
4058 WIN_ReleasePtr( win
);
4060 update_window_state( hwnd
);
4065 /*****************************************************************************
4066 * SetLayeredWindowAttributes (USER32.@)
4068 BOOL WINAPI
SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
4072 TRACE("(%p,%08x,%d,%x)\n", hwnd
, key
, alpha
, flags
);
4074 SERVER_START_REQ( set_window_layered_info
)
4076 req
->handle
= wine_server_user_handle( hwnd
);
4077 req
->color_key
= key
;
4080 ret
= !wine_server_call_err( req
);
4086 USER_Driver
->pSetLayeredWindowAttributes( hwnd
, key
, alpha
, flags
);
4087 update_window_state( hwnd
);
4094 /*****************************************************************************
4095 * UpdateLayeredWindowIndirect (USER32.@)
4097 BOOL WINAPI
UpdateLayeredWindowIndirect( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
)
4099 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
;
4100 RECT window_rect
, client_rect
;
4104 info
->cbSize
!= sizeof(*info
) ||
4105 info
->dwFlags
& ~(ULW_COLORKEY
| ULW_ALPHA
| ULW_OPAQUE
| ULW_EX_NORESIZE
) ||
4106 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_LAYERED
) ||
4107 NtUserGetLayeredWindowAttributes( hwnd
, NULL
, NULL
, NULL
))
4109 SetLastError( ERROR_INVALID_PARAMETER
);
4113 WIN_GetRectangles( hwnd
, COORDS_PARENT
, &window_rect
, &client_rect
);
4117 offset
.cx
= info
->pptDst
->x
- window_rect
.left
;
4118 offset
.cy
= info
->pptDst
->y
- window_rect
.top
;
4119 OffsetRect( &client_rect
, offset
.cx
, offset
.cy
);
4120 OffsetRect( &window_rect
, offset
.cx
, offset
.cy
);
4121 flags
&= ~SWP_NOMOVE
;
4125 offset
.cx
= info
->psize
->cx
- (window_rect
.right
- window_rect
.left
);
4126 offset
.cy
= info
->psize
->cy
- (window_rect
.bottom
- window_rect
.top
);
4127 if (info
->psize
->cx
<= 0 || info
->psize
->cy
<= 0)
4129 SetLastError( ERROR_INVALID_PARAMETER
);
4132 if ((info
->dwFlags
& ULW_EX_NORESIZE
) && (offset
.cx
|| offset
.cy
))
4134 SetLastError( ERROR_INCORRECT_SIZE
);
4137 client_rect
.right
+= offset
.cx
;
4138 client_rect
.bottom
+= offset
.cy
;
4139 window_rect
.right
+= offset
.cx
;
4140 window_rect
.bottom
+= offset
.cy
;
4141 flags
&= ~SWP_NOSIZE
;
4144 TRACE( "window %p win %s client %s\n", hwnd
,
4145 wine_dbgstr_rect(&window_rect
), wine_dbgstr_rect(&client_rect
) );
4147 set_window_pos( hwnd
, 0, flags
, &window_rect
, &client_rect
, NULL
);
4148 return USER_Driver
->pUpdateLayeredWindow( hwnd
, info
, &window_rect
);
4152 /*****************************************************************************
4153 * UpdateLayeredWindow (USER32.@)
4155 BOOL WINAPI
UpdateLayeredWindow( HWND hwnd
, HDC hdcDst
, POINT
*pptDst
, SIZE
*psize
,
4156 HDC hdcSrc
, POINT
*pptSrc
, COLORREF crKey
, BLENDFUNCTION
*pblend
,
4159 UPDATELAYEREDWINDOWINFO info
;
4161 if (flags
& ULW_EX_NORESIZE
) /* only valid for UpdateLayeredWindowIndirect */
4163 SetLastError( ERROR_INVALID_PARAMETER
);
4166 info
.cbSize
= sizeof(info
);
4167 info
.hdcDst
= hdcDst
;
4168 info
.pptDst
= pptDst
;
4170 info
.hdcSrc
= hdcSrc
;
4171 info
.pptSrc
= pptSrc
;
4173 info
.pblend
= pblend
;
4174 info
.dwFlags
= flags
;
4175 info
.prcDirty
= NULL
;
4176 return UpdateLayeredWindowIndirect( hwnd
, &info
);
4180 /******************************************************************************
4181 * GetProcessDefaultLayout [USER32.@]
4183 * Gets the default layout for parentless windows.
4185 BOOL WINAPI
GetProcessDefaultLayout( DWORD
*layout
)
4189 SetLastError( ERROR_NOACCESS
);
4192 if (process_layout
== ~0u)
4194 WCHAR
*str
, buffer
[MAX_PATH
];
4195 DWORD i
, len
, version_layout
= 0;
4196 DWORD user_lang
= GetUserDefaultLangID();
4200 GetModuleFileNameW( 0, buffer
, MAX_PATH
);
4201 if (!(len
= GetFileVersionInfoSizeW( buffer
, NULL
))) goto done
;
4202 if (!(data
= HeapAlloc( GetProcessHeap(), 0, len
))) goto done
;
4203 if (!GetFileVersionInfoW( buffer
, 0, len
, data
)) goto done
;
4204 if (!VerQueryValueW( data
, L
"\\VarFileInfo\\Translation", (void **)&languages
, &len
) || !len
) goto done
;
4206 len
/= sizeof(DWORD
);
4207 for (i
= 0; i
< len
; i
++) if (LOWORD(languages
[i
]) == user_lang
) break;
4208 if (i
== len
) /* try neutral language */
4209 for (i
= 0; i
< len
; i
++)
4210 if (LOWORD(languages
[i
]) == MAKELANGID( PRIMARYLANGID(user_lang
), SUBLANG_NEUTRAL
)) break;
4211 if (i
== len
) i
= 0; /* default to the first one */
4213 swprintf( buffer
, ARRAY_SIZE(buffer
), L
"\\StringFileInfo\\%04x%04x\\FileDescription",
4214 LOWORD(languages
[i
]), HIWORD(languages
[i
]) );
4215 if (!VerQueryValueW( data
, buffer
, (void **)&str
, &len
)) goto done
;
4216 TRACE( "found description %s\n", debugstr_w( str
));
4217 if (str
[0] == 0x200e && str
[1] == 0x200e) version_layout
= LAYOUT_RTL
;
4220 HeapFree( GetProcessHeap(), 0, data
);
4221 process_layout
= version_layout
;
4223 *layout
= process_layout
;
4228 /******************************************************************************
4229 * SetProcessDefaultLayout [USER32.@]
4231 * Sets the default layout for parentless windows.
4233 BOOL WINAPI
SetProcessDefaultLayout( DWORD layout
)
4235 process_layout
= layout
;
4240 /* 64bit versions */
4242 #ifdef GetWindowLongPtrW
4243 #undef GetWindowLongPtrW
4246 #ifdef GetWindowLongPtrA
4247 #undef GetWindowLongPtrA
4250 #ifdef SetWindowLongPtrW
4251 #undef SetWindowLongPtrW
4254 #ifdef SetWindowLongPtrA
4255 #undef SetWindowLongPtrA
4258 /*****************************************************************************
4259 * GetWindowLongPtrW (USER32.@)
4261 LONG_PTR WINAPI
GetWindowLongPtrW( HWND hwnd
, INT offset
)
4263 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), TRUE
);
4266 /*****************************************************************************
4267 * GetWindowLongPtrA (USER32.@)
4269 LONG_PTR WINAPI
GetWindowLongPtrA( HWND hwnd
, INT offset
)
4271 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), FALSE
);
4274 /*****************************************************************************
4275 * SetWindowLongPtrW (USER32.@)
4277 LONG_PTR WINAPI
SetWindowLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
4279 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, TRUE
);
4282 /*****************************************************************************
4283 * SetWindowLongPtrA (USER32.@)
4285 LONG_PTR WINAPI
SetWindowLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
4287 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, FALSE
);
4290 /*****************************************************************************
4291 * RegisterTouchWindow (USER32.@)
4293 BOOL WINAPI
RegisterTouchWindow(HWND hwnd
, ULONG flags
)
4295 FIXME("(%p %08x): stub\n", hwnd
, flags
);
4296 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4300 /*****************************************************************************
4301 * UnregisterTouchWindow (USER32.@)
4303 BOOL WINAPI
UnregisterTouchWindow(HWND hwnd
)
4305 FIXME("(%p): stub\n", hwnd
);
4306 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4310 /*****************************************************************************
4311 * CloseTouchInputHandle (USER32.@)
4313 BOOL WINAPI
CloseTouchInputHandle(HTOUCHINPUT handle
)
4315 FIXME("(%p): stub\n", handle
);
4316 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4320 /*****************************************************************************
4321 * GetTouchInputInfo (USER32.@)
4323 BOOL WINAPI
GetTouchInputInfo(HTOUCHINPUT handle
, UINT count
, TOUCHINPUT
*ptr
, int size
)
4325 FIXME("(%p %u %p %u): stub\n", handle
, count
, ptr
, size
);
4326 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4330 /*****************************************************************************
4331 * GetGestureInfo (USER32.@)
4333 BOOL WINAPI
GetGestureInfo(HGESTUREINFO handle
, PGESTUREINFO ptr
)
4335 FIXME("(%p %p): stub\n", handle
, ptr
);
4336 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4340 /*****************************************************************************
4341 * GetWindowDisplayAffinity (USER32.@)
4343 BOOL WINAPI
GetWindowDisplayAffinity(HWND hwnd
, DWORD
*affinity
)
4345 FIXME("(%p, %p): stub\n", hwnd
, affinity
);
4347 if (!hwnd
|| !affinity
)
4349 SetLastError(hwnd
? ERROR_NOACCESS
: ERROR_INVALID_WINDOW_HANDLE
);
4353 *affinity
= WDA_NONE
;
4357 /*****************************************************************************
4358 * SetWindowDisplayAffinity (USER32.@)
4360 BOOL WINAPI
SetWindowDisplayAffinity(HWND hwnd
, DWORD affinity
)
4362 FIXME("(%p, %u): stub\n", hwnd
, affinity
);
4366 SetLastError(ERROR_INVALID_WINDOW_HANDLE
);
4370 SetLastError(ERROR_NOT_ENOUGH_MEMORY
);
4374 /**********************************************************************
4375 * SetWindowCompositionAttribute (USER32.@)
4377 BOOL WINAPI
SetWindowCompositionAttribute(HWND hwnd
, void *data
)
4379 FIXME("(%p, %p): stub\n", hwnd
, data
);
4380 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
4384 /***********************************************************************
4385 * InternalGetWindowIcon (USER32.@)
4387 HICON WINAPI
InternalGetWindowIcon( HWND hwnd
, UINT type
)
4389 WND
*win
= WIN_GetPtr( hwnd
);
4392 TRACE( "hwnd %p, type %#x\n", hwnd
, type
);
4396 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
4399 if (win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
4401 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
4409 if (!ret
) ret
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
4414 ret
= win
->hIconSmall
? win
->hIconSmall
: win
->hIconSmall2
;
4415 if (!ret
) ret
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICONSM
);
4416 if (!ret
) ret
= (HICON
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
4420 SetLastError( ERROR_INVALID_PARAMETER
);
4421 WIN_ReleasePtr( win
);
4425 if (!ret
) ret
= LoadIconW( 0, (const WCHAR
*)IDI_APPLICATION
);
4427 WIN_ReleasePtr( win
);
4428 return CopyIcon( ret
);