2 * Window related functions
4 * Copyright 1993, 1994 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 #include "wine/port.h"
30 #include "wine/winbase16.h"
31 #include "wine/winuser16.h"
33 #include "wine/server.h"
34 #include "wine/unicode.h"
36 #include "user_private.h"
39 #include "wine/debug.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(win
);
43 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
44 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
46 /**********************************************************************/
48 /* helper for Get/SetWindowLong */
49 static inline LONG_PTR
get_win_data( const void *ptr
, UINT size
)
51 if (size
== sizeof(WORD
))
54 memcpy( &ret
, ptr
, sizeof(ret
) );
57 else if (size
== sizeof(DWORD
))
60 memcpy( &ret
, ptr
, sizeof(ret
) );
66 memcpy( &ret
, ptr
, sizeof(ret
) );
71 /* helper for Get/SetWindowLong */
72 static inline void set_win_data( void *ptr
, LONG_PTR val
, UINT size
)
74 if (size
== sizeof(WORD
))
77 memcpy( ptr
, &newval
, sizeof(newval
) );
79 else if (size
== sizeof(DWORD
))
82 memcpy( ptr
, &newval
, sizeof(newval
) );
86 memcpy( ptr
, &val
, sizeof(val
) );
91 static void *user_handles
[NB_USER_HANDLES
];
93 /***********************************************************************
96 HANDLE
alloc_user_handle( struct user_object
*ptr
, enum user_obj_type type
)
100 SERVER_START_REQ( alloc_user_handle
)
102 if (!wine_server_call_err( req
)) handle
= wine_server_ptr_handle( reply
->handle
);
108 UINT index
= USER_HANDLE_TO_INDEX( handle
);
110 assert( index
< NB_USER_HANDLES
);
111 ptr
->handle
= handle
;
113 user_handles
[index
] = ptr
;
119 /***********************************************************************
120 * get_user_handle_ptr
122 void *get_user_handle_ptr( HANDLE handle
, enum user_obj_type type
)
124 struct user_object
*ptr
;
125 WORD index
= USER_HANDLE_TO_INDEX( handle
);
127 if (index
>= NB_USER_HANDLES
) return NULL
;
130 if ((ptr
= user_handles
[index
]))
132 if (ptr
->type
== type
&&
133 ((UINT
)(UINT_PTR
)ptr
->handle
== (UINT
)(UINT_PTR
)handle
||
134 !HIWORD(handle
) || HIWORD(handle
) == 0xffff))
138 else ptr
= OBJ_OTHER_PROCESS
;
144 /***********************************************************************
145 * release_user_handle_ptr
147 void release_user_handle_ptr( void *ptr
)
153 /***********************************************************************
156 void *free_user_handle( HANDLE handle
, enum user_obj_type type
)
158 struct user_object
*ptr
;
159 WORD index
= USER_HANDLE_TO_INDEX( handle
);
161 if ((ptr
= get_user_handle_ptr( handle
, type
)) && ptr
!= OBJ_OTHER_PROCESS
)
163 SERVER_START_REQ( free_user_handle
)
165 req
->handle
= wine_server_user_handle( handle
);
166 if (!wine_server_call( req
)) user_handles
[index
] = NULL
;
170 release_user_handle_ptr( ptr
);
176 /***********************************************************************
177 * create_window_handle
179 * Create a window handle with the server.
181 static WND
*create_window_handle( HWND parent
, HWND owner
, LPCWSTR name
,
182 HINSTANCE instance
, BOOL unicode
)
186 HWND handle
= 0, full_parent
= 0, full_owner
= 0;
187 struct tagCLASS
*class = NULL
;
190 /* if 16-bit instance, map to module handle */
191 if (instance
&& !HIWORD(instance
))
192 instance
= HINSTANCE_32(GetExePtr(HINSTANCE_16(instance
)));
194 SERVER_START_REQ( create_window
)
196 req
->parent
= wine_server_user_handle( parent
);
197 req
->owner
= wine_server_user_handle( owner
);
198 req
->instance
= wine_server_client_ptr( instance
);
199 if (!(req
->atom
= get_int_atom_value( name
)) && name
)
200 wine_server_add_data( req
, name
, strlenW(name
)*sizeof(WCHAR
) );
201 if (!wine_server_call_err( req
))
203 handle
= wine_server_ptr_handle( reply
->handle
);
204 full_parent
= wine_server_ptr_handle( reply
->parent
);
205 full_owner
= wine_server_ptr_handle( reply
->owner
);
206 extra_bytes
= reply
->extra
;
207 class = wine_server_get_ptr( reply
->class_ptr
);
214 WARN( "error %d creating window\n", GetLastError() );
218 if (!(win
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
,
219 sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
221 SERVER_START_REQ( destroy_window
)
223 req
->handle
= wine_server_user_handle( handle
);
224 wine_server_call( req
);
227 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
231 if (!parent
) /* if parent is 0 we don't have a desktop window yet */
233 struct user_thread_info
*thread_info
= get_user_thread_info();
235 if (name
== (LPCWSTR
)DESKTOP_CLASS_ATOM
)
237 if (!thread_info
->top_window
) thread_info
->top_window
= full_parent
? full_parent
: handle
;
238 else assert( full_parent
== thread_info
->top_window
);
239 if (full_parent
&& !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
240 ERR( "failed to create desktop window\n" );
242 else /* HWND_MESSAGE parent */
244 if (!thread_info
->msg_window
&& !full_parent
) thread_info
->msg_window
= handle
;
250 index
= USER_HANDLE_TO_INDEX(handle
);
251 assert( index
< NB_USER_HANDLES
);
252 user_handles
[index
] = win
;
253 win
->obj
.handle
= handle
;
254 win
->obj
.type
= USER_WINDOW
;
255 win
->parent
= full_parent
;
256 win
->owner
= full_owner
;
258 win
->winproc
= get_class_winproc( class );
259 win
->cbWndExtra
= extra_bytes
;
260 if (WINPROC_IsUnicode( win
->winproc
, unicode
)) win
->flags
|= WIN_ISUNICODE
;
265 /***********************************************************************
268 * Free a window handle.
270 static void free_window_handle( HWND hwnd
)
272 struct user_object
*ptr
;
273 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
275 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) && ptr
!= OBJ_OTHER_PROCESS
)
277 SERVER_START_REQ( destroy_window
)
279 req
->handle
= wine_server_user_handle( hwnd
);
280 if (!wine_server_call_err( req
)) user_handles
[index
] = NULL
;
284 release_user_handle_ptr( ptr
);
285 HeapFree( GetProcessHeap(), 0, ptr
);
290 /*******************************************************************
291 * list_window_children
293 * Build an array of the children of a given window. The array must be
294 * freed with HeapFree. Returns NULL when no windows are found.
296 static HWND
*list_window_children( HDESK desktop
, HWND hwnd
, LPCWSTR
class, DWORD tid
)
300 ATOM atom
= get_int_atom_value( class );
302 /* empty class is not the same as NULL class */
303 if (!atom
&& class && !class[0]) return NULL
;
309 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
311 SERVER_START_REQ( get_window_children
)
313 req
->desktop
= wine_server_obj_handle( desktop
);
314 req
->parent
= wine_server_user_handle( hwnd
);
317 if (!atom
&& class) wine_server_add_data( req
, class, strlenW(class)*sizeof(WCHAR
) );
318 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
319 if (!wine_server_call( req
)) count
= reply
->count
;
322 if (count
&& count
< size
)
324 /* start from the end since HWND is potentially larger than user_handle_t */
325 for (i
= count
- 1; i
>= 0; i
--)
326 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
330 HeapFree( GetProcessHeap(), 0, list
);
332 size
= count
+ 1; /* restart with a large enough buffer */
338 /*******************************************************************
339 * list_window_parents
341 * Build an array of all parents of a given window, starting with
342 * the immediate parent. The array must be freed with HeapFree.
344 static HWND
*list_window_parents( HWND hwnd
)
348 int i
, pos
= 0, size
= 16, count
= 0;
350 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
355 if (!(win
= WIN_GetPtr( current
))) goto empty
;
356 if (win
== WND_OTHER_PROCESS
) break; /* need to do it the hard way */
357 if (win
== WND_DESKTOP
)
359 if (!pos
) goto empty
;
363 list
[pos
] = current
= win
->parent
;
364 WIN_ReleasePtr( win
);
365 if (!current
) return list
;
366 if (++pos
== size
- 1)
368 /* need to grow the list */
369 HWND
*new_list
= HeapReAlloc( GetProcessHeap(), 0, list
, (size
+16) * sizeof(HWND
) );
370 if (!new_list
) goto empty
;
376 /* at least one parent belongs to another process, have to query the server */
381 SERVER_START_REQ( get_window_parents
)
383 req
->handle
= wine_server_user_handle( hwnd
);
384 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
385 if (!wine_server_call( req
)) count
= reply
->count
;
388 if (!count
) goto empty
;
391 /* start from the end since HWND is potentially larger than user_handle_t */
392 for (i
= count
- 1; i
>= 0; i
--)
393 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
397 HeapFree( GetProcessHeap(), 0, list
);
399 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
403 HeapFree( GetProcessHeap(), 0, list
);
408 /*******************************************************************
411 static void send_parent_notify( HWND hwnd
, UINT msg
)
413 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
414 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
))
416 HWND parent
= GetParent(hwnd
);
417 if (parent
&& parent
!= GetDesktopWindow())
418 SendMessageW( parent
, WM_PARENTNOTIFY
,
419 MAKEWPARAM( msg
, GetWindowLongPtrW( hwnd
, GWLP_ID
)), (LPARAM
)hwnd
);
424 /*******************************************************************
425 * get_server_window_text
427 * Retrieve the window text from the server.
429 static void get_server_window_text( HWND hwnd
, LPWSTR text
, INT count
)
433 SERVER_START_REQ( get_window_text
)
435 req
->handle
= wine_server_user_handle( hwnd
);
436 wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
437 if (!wine_server_call_err( req
)) len
= wine_server_reply_size(reply
);
440 text
[len
/ sizeof(WCHAR
)] = 0;
444 /*******************************************************************
445 * get_hwnd_message_parent
447 * Return the parent for HWND_MESSAGE windows.
449 HWND
get_hwnd_message_parent(void)
451 struct user_thread_info
*thread_info
= get_user_thread_info();
453 if (!thread_info
->msg_window
) GetDesktopWindow(); /* trigger creation */
454 return thread_info
->msg_window
;
458 /*******************************************************************
461 * Check if window is the desktop or the HWND_MESSAGE top parent.
463 BOOL
is_desktop_window( HWND hwnd
)
465 struct user_thread_info
*thread_info
= get_user_thread_info();
467 if (!hwnd
) return FALSE
;
468 if (hwnd
== thread_info
->top_window
) return TRUE
;
469 if (hwnd
== thread_info
->msg_window
) return TRUE
;
471 if (!HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff)
473 if (LOWORD(thread_info
->top_window
) == LOWORD(hwnd
)) return TRUE
;
474 if (LOWORD(thread_info
->msg_window
) == LOWORD(hwnd
)) return TRUE
;
480 /***********************************************************************
483 * Return a pointer to the WND structure if local to the process,
484 * or WND_OTHER_PROCESS if handle may be valid in other process.
485 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
487 WND
*WIN_GetPtr( HWND hwnd
)
491 if ((ptr
= get_user_handle_ptr( hwnd
, USER_WINDOW
)) == WND_OTHER_PROCESS
)
493 if (is_desktop_window( hwnd
)) ptr
= WND_DESKTOP
;
499 /***********************************************************************
500 * WIN_IsCurrentProcess
502 * Check whether a given window belongs to the current process (and return the full handle).
504 HWND
WIN_IsCurrentProcess( HWND hwnd
)
509 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
510 ret
= ptr
->obj
.handle
;
511 WIN_ReleasePtr( ptr
);
516 /***********************************************************************
517 * WIN_IsCurrentThread
519 * Check whether a given window belongs to the current thread (and return the full handle).
521 HWND
WIN_IsCurrentThread( HWND hwnd
)
526 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
527 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->obj
.handle
;
528 WIN_ReleasePtr( ptr
);
533 /***********************************************************************
536 * Convert a 16-bit window handle to a full 32-bit handle.
538 HWND
WIN_Handle32( HWND16 hwnd16
)
541 HWND hwnd
= (HWND
)(ULONG_PTR
)hwnd16
;
543 if (hwnd16
<= 1 || hwnd16
== 0xffff) return hwnd
;
544 /* do sign extension for -2 and -3 */
545 if (hwnd16
>= (HWND16
)-3) return (HWND
)(LONG_PTR
)(INT16
)hwnd16
;
547 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
549 if (ptr
== WND_DESKTOP
)
551 if (LOWORD(hwnd
) == LOWORD(GetDesktopWindow())) return GetDesktopWindow();
552 else return get_hwnd_message_parent();
555 if (ptr
!= WND_OTHER_PROCESS
)
557 hwnd
= ptr
->obj
.handle
;
558 WIN_ReleasePtr( ptr
);
560 else /* may belong to another process */
562 SERVER_START_REQ( get_window_info
)
564 req
->handle
= wine_server_user_handle( hwnd
);
565 if (!wine_server_call_err( req
)) hwnd
= wine_server_ptr_handle( reply
->full_handle
);
573 /***********************************************************************
576 * Change the owner of a window.
578 HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
580 WND
*win
= WIN_GetPtr( hwnd
);
583 if (!win
|| win
== WND_DESKTOP
) return 0;
584 if (win
== WND_OTHER_PROCESS
)
586 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
589 SERVER_START_REQ( set_window_owner
)
591 req
->handle
= wine_server_user_handle( hwnd
);
592 req
->owner
= wine_server_user_handle( owner
);
593 if (!wine_server_call( req
))
595 win
->owner
= wine_server_ptr_handle( reply
->full_owner
);
596 ret
= wine_server_ptr_handle( reply
->prev_owner
);
600 WIN_ReleasePtr( win
);
605 /***********************************************************************
608 * Change the style of a window.
610 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
614 WND
*win
= WIN_GetPtr( hwnd
);
616 if (!win
|| win
== WND_DESKTOP
) return 0;
617 if (win
== WND_OTHER_PROCESS
)
620 ERR( "cannot set style %x/%x on other process window %p\n",
621 set_bits
, clear_bits
, hwnd
);
624 style
.styleOld
= win
->dwStyle
;
625 style
.styleNew
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
626 if (style
.styleNew
== style
.styleOld
)
628 WIN_ReleasePtr( win
);
629 return style
.styleNew
;
631 SERVER_START_REQ( set_window_info
)
633 req
->handle
= wine_server_user_handle( hwnd
);
634 req
->flags
= SET_WIN_STYLE
;
635 req
->style
= style
.styleNew
;
636 req
->extra_offset
= -1;
637 if ((ok
= !wine_server_call( req
)))
639 style
.styleOld
= reply
->old_style
;
640 win
->dwStyle
= style
.styleNew
;
644 WIN_ReleasePtr( win
);
647 USER_Driver
->pSetWindowStyle( hwnd
, GWL_STYLE
, &style
);
648 if ((style
.styleOld
^ style
.styleNew
) & WS_VISIBLE
) invalidate_dce( hwnd
, NULL
);
650 return style
.styleOld
;
654 /***********************************************************************
657 * Get the window and client rectangles.
659 BOOL
WIN_GetRectangles( HWND hwnd
, RECT
*rectWindow
, RECT
*rectClient
)
661 WND
*win
= WIN_GetPtr( hwnd
);
666 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
669 if (win
== WND_DESKTOP
)
672 rect
.left
= rect
.top
= 0;
673 if (hwnd
== get_hwnd_message_parent())
680 rect
.right
= GetSystemMetrics(SM_CXSCREEN
);
681 rect
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
683 if (rectWindow
) *rectWindow
= rect
;
684 if (rectClient
) *rectClient
= rect
;
686 else if (win
== WND_OTHER_PROCESS
)
688 SERVER_START_REQ( get_window_rectangles
)
690 req
->handle
= wine_server_user_handle( hwnd
);
691 if ((ret
= !wine_server_call_err( req
)))
695 rectWindow
->left
= reply
->window
.left
;
696 rectWindow
->top
= reply
->window
.top
;
697 rectWindow
->right
= reply
->window
.right
;
698 rectWindow
->bottom
= reply
->window
.bottom
;
702 rectClient
->left
= reply
->client
.left
;
703 rectClient
->top
= reply
->client
.top
;
704 rectClient
->right
= reply
->client
.right
;
705 rectClient
->bottom
= reply
->client
.bottom
;
713 if (rectWindow
) *rectWindow
= win
->rectWindow
;
714 if (rectClient
) *rectClient
= win
->rectClient
;
715 WIN_ReleasePtr( win
);
721 /***********************************************************************
724 * Destroy storage associated to a window. "Internals" p.358
726 LRESULT
WIN_DestroyWindow( HWND hwnd
)
730 HMENU menu
= 0, sys_menu
;
733 TRACE("%p\n", hwnd
);
735 /* free child windows */
736 if ((list
= WIN_ListChildren( hwnd
)))
739 for (i
= 0; list
[i
]; i
++)
741 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
742 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
744 HeapFree( GetProcessHeap(), 0, list
);
747 /* Unlink now so we won't bother with the children later on */
748 SERVER_START_REQ( set_parent
)
750 req
->handle
= wine_server_user_handle( hwnd
);
752 wine_server_call( req
);
757 * Send the WM_NCDESTROY to the window being destroyed.
759 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
761 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
763 /* free resources associated with the window */
765 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
766 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
767 menu
= (HMENU
)wndPtr
->wIDmenu
;
768 sys_menu
= wndPtr
->hSysMenu
;
769 free_dce( wndPtr
->dce
, hwnd
);
771 icon_title
= wndPtr
->icon_title
;
772 WIN_ReleasePtr( wndPtr
);
774 if (icon_title
) DestroyWindow( icon_title
);
775 if (menu
) DestroyMenu( menu
);
776 if (sys_menu
) DestroyMenu( sys_menu
);
778 USER_Driver
->pDestroyWindow( hwnd
);
780 free_window_handle( hwnd
);
785 /***********************************************************************
786 * destroy_thread_window
788 * Destroy a window upon exit of its thread.
790 static void destroy_thread_window( HWND hwnd
)
794 HMENU menu
= 0, sys_menu
= 0;
797 /* free child windows */
799 if ((list
= WIN_ListChildren( hwnd
)))
802 for (i
= 0; list
[i
]; i
++)
804 if (WIN_IsCurrentThread( list
[i
] )) destroy_thread_window( list
[i
] );
805 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
807 HeapFree( GetProcessHeap(), 0, list
);
810 /* destroy the client-side storage */
812 index
= USER_HANDLE_TO_INDEX(hwnd
);
813 if (index
>= NB_USER_HANDLES
) return;
815 if ((wndPtr
= user_handles
[index
]))
817 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
) menu
= (HMENU
)wndPtr
->wIDmenu
;
818 sys_menu
= wndPtr
->hSysMenu
;
819 free_dce( wndPtr
->dce
, hwnd
);
820 user_handles
[index
] = NULL
;
824 HeapFree( GetProcessHeap(), 0, wndPtr
);
825 if (menu
) DestroyMenu( menu
);
826 if (sys_menu
) DestroyMenu( sys_menu
);
830 /***********************************************************************
831 * destroy_thread_child_windows
833 * Destroy child windows upon exit of its thread.
835 static void destroy_thread_child_windows( HWND hwnd
)
840 if (WIN_IsCurrentThread( hwnd
))
842 destroy_thread_window( hwnd
);
844 else if ((list
= WIN_ListChildren( hwnd
)))
846 for (i
= 0; list
[i
]; i
++) destroy_thread_child_windows( list
[i
] );
847 HeapFree( GetProcessHeap(), 0, list
);
852 /***********************************************************************
853 * WIN_DestroyThreadWindows
855 * Destroy all children of 'wnd' owned by the current thread.
857 void WIN_DestroyThreadWindows( HWND hwnd
)
862 if (!(list
= WIN_ListChildren( hwnd
))) return;
864 /* reset owners of top-level windows */
865 for (i
= 0; list
[i
]; i
++)
867 if (!WIN_IsCurrentThread( list
[i
] ))
869 HWND owner
= GetWindow( list
[i
], GW_OWNER
);
870 if (owner
&& WIN_IsCurrentThread( owner
)) WIN_SetOwner( list
[i
], 0 );
874 for (i
= 0; list
[i
]; i
++) destroy_thread_child_windows( list
[i
] );
875 HeapFree( GetProcessHeap(), 0, list
);
879 /***********************************************************************
882 * Fix the coordinates - Helper for WIN_CreateWindowEx.
883 * returns default show mode in sw.
885 static void WIN_FixCoordinates( CREATESTRUCTA
*cs
, INT
*sw
)
887 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == CW_USEDEFAULT16)
890 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
894 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
895 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= ULongToHandle(id
);
897 TRACE("MDI child id %04x\n", id
);
900 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
902 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
904 if (IS_DEFAULT(cs
->x
))
909 if (IS_DEFAULT(cs
->cx
) || !cs
->cx
) cs
->cx
= pos
[1].x
;
910 if (IS_DEFAULT(cs
->cy
) || !cs
->cy
) cs
->cy
= pos
[1].y
;
914 if (IS_DEFAULT(cs
->x
)) cs
->x
= cs
->y
= 0;
915 if (IS_DEFAULT(cs
->cx
)) cs
->cx
= cs
->cy
= 0;
918 else /* overlapped window */
921 MONITORINFO mon_info
;
924 if (!IS_DEFAULT(cs
->x
) && !IS_DEFAULT(cs
->cx
) && !IS_DEFAULT(cs
->cy
)) return;
926 monitor
= MonitorFromWindow( cs
->hwndParent
, MONITOR_DEFAULTTOPRIMARY
);
927 mon_info
.cbSize
= sizeof(mon_info
);
928 GetMonitorInfoW( monitor
, &mon_info
);
929 GetStartupInfoW( &info
);
931 if (IS_DEFAULT(cs
->x
))
933 if (!IS_DEFAULT(cs
->y
)) *sw
= cs
->y
;
934 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: mon_info
.rcWork
.left
;
935 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: mon_info
.rcWork
.top
;
938 if (IS_DEFAULT(cs
->cx
))
940 if (info
.dwFlags
& STARTF_USESIZE
)
942 cs
->cx
= info
.dwXSize
;
943 cs
->cy
= info
.dwYSize
;
947 cs
->cx
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) * 3 / 4 - cs
->x
;
948 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
951 /* neither x nor cx are default. Check the y values .
952 * In the trace we see Outlook and Outlook Express using
953 * cy set to CW_USEDEFAULT when opening the address book.
955 else if (IS_DEFAULT(cs
->cy
))
957 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
958 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
964 /***********************************************************************
967 static void dump_window_styles( DWORD style
, DWORD exstyle
)
970 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
971 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
972 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
973 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
974 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
975 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
976 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
977 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
978 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
981 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
982 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
984 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
985 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
986 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
987 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
988 if (style
& WS_CHILD
)
990 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
991 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
995 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
996 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
999 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
1000 #define DUMPED_STYLES \
1020 if(style
& ~DUMPED_STYLES
) TRACE(" %08lx", style
& ~DUMPED_STYLES
);
1022 #undef DUMPED_STYLES
1024 TRACE( "exstyle:" );
1025 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
1026 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
1027 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
1028 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
1029 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
1030 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
1031 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
1032 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
1033 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
1034 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
1035 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
1036 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
1037 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
1038 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
1039 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
1040 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
1041 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
1042 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
1044 #define DUMPED_EX_STYLES \
1045 (WS_EX_DLGMODALFRAME | \
1046 WS_EX_DRAGDETECT | \
1047 WS_EX_NOPARENTNOTIFY | \
1049 WS_EX_ACCEPTFILES | \
1050 WS_EX_TRANSPARENT | \
1052 WS_EX_TOOLWINDOW | \
1053 WS_EX_WINDOWEDGE | \
1054 WS_EX_CLIENTEDGE | \
1055 WS_EX_CONTEXTHELP | \
1057 WS_EX_RTLREADING | \
1058 WS_EX_LEFTSCROLLBAR | \
1059 WS_EX_CONTROLPARENT | \
1060 WS_EX_STATICEDGE | \
1064 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08lx", exstyle
& ~DUMPED_EX_STYLES
);
1066 #undef DUMPED_EX_STYLES
1070 /***********************************************************************
1071 * WIN_CreateWindowEx
1073 * Implementation of CreateWindowEx().
1075 static HWND
WIN_CreateWindowEx( CREATESTRUCTA
*cs
, LPCWSTR className
, UINT flags
)
1077 INT cx
, cy
, style
, sw
= SW_SHOW
;
1081 HWND hwnd
, parent
, owner
, top_child
= 0;
1082 BOOL unicode
= (flags
& WIN_ISUNICODE
) != 0;
1083 MDICREATESTRUCTA mdi_cs
;
1084 CBT_CREATEWNDA cbtc
;
1087 TRACE("%s %s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
1088 unicode
? debugstr_w((LPCWSTR
)cs
->lpszName
) : debugstr_a(cs
->lpszName
),
1089 debugstr_w(className
),
1090 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
1091 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
1092 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
1094 /* Fix the styles for MDI children */
1095 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1099 wndPtr
= WIN_GetPtr(cs
->hwndParent
);
1100 if (wndPtr
&& wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
1102 flags
= wndPtr
->flags
;
1103 WIN_ReleasePtr(wndPtr
);
1106 if (!(flags
& WIN_ISMDICLIENT
))
1108 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
1112 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
1113 * MDICREATESTRUCT members have the originally passed values.
1115 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
1116 * have the same layout.
1118 mdi_cs
.szClass
= cs
->lpszClass
;
1119 mdi_cs
.szTitle
= cs
->lpszName
;
1120 mdi_cs
.hOwner
= cs
->hInstance
;
1125 mdi_cs
.style
= cs
->style
;
1126 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
1128 cs
->lpCreateParams
= &mdi_cs
;
1130 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
1132 if (cs
->style
& WS_POPUP
)
1134 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
1137 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
1141 cs
->style
&= ~WS_POPUP
;
1142 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
1143 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
1146 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
1150 /* Restore current maximized child */
1151 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
1153 TRACE("Restoring current maximized child %p\n", top_child
);
1154 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
1155 ShowWindow( top_child
, SW_SHOWNORMAL
);
1156 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
1161 /* Find the parent window */
1163 parent
= cs
->hwndParent
;
1166 if (cs
->hwndParent
== HWND_MESSAGE
)
1168 cs
->hwndParent
= parent
= get_hwnd_message_parent();
1170 else if (cs
->hwndParent
)
1172 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
1174 parent
= GetDesktopWindow();
1175 owner
= cs
->hwndParent
;
1180 static const WCHAR messageW
[] = {'M','e','s','s','a','g','e',0};
1182 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
1184 WARN("No parent for child window\n" );
1185 SetLastError(ERROR_TLW_WITH_WSCHILD
);
1186 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
1188 /* are we creating the desktop or HWND_MESSAGE parent itself? */
1189 if (className
!= (LPCWSTR
)DESKTOP_CLASS_ATOM
&&
1190 (IS_INTRESOURCE(className
) || strcmpiW( className
, messageW
)))
1191 parent
= GetDesktopWindow();
1194 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
1196 if ((cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1197 ((!(cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
1198 (cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
1199 cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1201 cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1203 /* Create the window structure */
1205 if (!(wndPtr
= create_window_handle( parent
, owner
, className
, cs
->hInstance
, unicode
)))
1207 hwnd
= wndPtr
->obj
.handle
;
1209 /* Fill the window structure */
1211 wndPtr
->tid
= GetCurrentThreadId();
1212 wndPtr
->hInstance
= cs
->hInstance
;
1213 wndPtr
->text
= NULL
;
1214 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
1215 wndPtr
->dwExStyle
= cs
->dwExStyle
;
1216 wndPtr
->wIDmenu
= 0;
1217 wndPtr
->helpContext
= 0;
1218 wndPtr
->pScroll
= NULL
;
1219 wndPtr
->userdata
= 0;
1221 wndPtr
->hIconSmall
= 0;
1222 wndPtr
->hSysMenu
= 0;
1223 wndPtr
->flags
|= (flags
& WIN_ISWIN32
);
1225 wndPtr
->min_pos
.x
= wndPtr
->min_pos
.y
= -1;
1226 wndPtr
->max_pos
.x
= wndPtr
->max_pos
.y
= -1;
1228 if (wndPtr
->dwStyle
& WS_SYSMENU
) SetSystemMenu( hwnd
, 0 );
1231 * Correct the window styles.
1233 * It affects only the style loaded into the WIN structure.
1236 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1238 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1239 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1240 wndPtr
->dwStyle
|= WS_CAPTION
;
1244 * WS_EX_WINDOWEDGE appears to be enforced based on the other styles, so
1245 * why does the user get to set it?
1248 if ((wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1249 (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1250 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1252 wndPtr
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1254 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1255 wndPtr
->flags
|= WIN_NEED_SIZE
;
1257 SERVER_START_REQ( set_window_info
)
1259 req
->handle
= wine_server_user_handle( hwnd
);
1260 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
| SET_WIN_UNICODE
;
1261 req
->style
= wndPtr
->dwStyle
;
1262 req
->ex_style
= wndPtr
->dwExStyle
;
1263 req
->instance
= wine_server_client_ptr( wndPtr
->hInstance
);
1264 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1265 req
->extra_offset
= -1;
1266 wine_server_call( req
);
1270 /* Set the window menu */
1272 if ((wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) != WS_CHILD
)
1276 if (!MENU_SetMenu(hwnd
, cs
->hMenu
))
1278 WIN_ReleasePtr( wndPtr
);
1279 free_window_handle( hwnd
);
1285 LPCSTR menuName
= (LPCSTR
)GetClassLongPtrA( hwnd
, GCLP_MENUNAME
);
1288 if (!cs
->hInstance
|| HIWORD(cs
->hInstance
))
1289 cs
->hMenu
= LoadMenuA(cs
->hInstance
,menuName
);
1291 cs
->hMenu
= HMENU_32(LoadMenu16(HINSTANCE_16(cs
->hInstance
),menuName
));
1293 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1297 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1299 /* call the WH_CBT hook */
1301 /* the window style passed to the hook must be the real window style,
1302 * rather than just the window style that the caller to CreateWindowEx
1303 * passed in, so we have to copy the original CREATESTRUCT and get the
1304 * the real style. */
1306 cbcs
.style
= wndPtr
->dwStyle
;
1308 cbtc
.hwndInsertAfter
= HWND_TOP
;
1309 WIN_ReleasePtr( wndPtr
);
1310 if (HOOK_CallHooks( WH_CBT
, HCBT_CREATEWND
, (WPARAM
)hwnd
, (LPARAM
)&cbtc
, unicode
)) goto failed
;
1312 /* send the WM_GETMINMAXINFO message and fix the size if needed */
1316 if ((cs
->style
& WS_THICKFRAME
) || !(cs
->style
& (WS_POPUP
| WS_CHILD
)))
1318 POINT maxSize
, maxPos
, minTrack
, maxTrack
;
1319 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, &maxPos
, &minTrack
, &maxTrack
);
1320 if (maxTrack
.x
< cx
) cx
= maxTrack
.x
;
1321 if (maxTrack
.y
< cy
) cy
= maxTrack
.y
;
1322 if (minTrack
.x
> cx
) cx
= minTrack
.x
;
1323 if (minTrack
.y
> cy
) cy
= minTrack
.y
;
1328 SetRect( &rect
, cs
->x
, cs
->y
, cs
->x
+ cx
, cs
->y
+ cy
);
1329 /* check for wraparound */
1330 if (cs
->x
+ cx
< cs
->x
) rect
.right
= 0x7fffffff;
1331 if (cs
->y
+ cy
< cs
->y
) rect
.bottom
= 0x7fffffff;
1332 if (!set_window_pos( hwnd
, 0, SWP_NOZORDER
| SWP_NOACTIVATE
, &rect
, &rect
, NULL
)) goto failed
;
1334 /* send WM_NCCREATE */
1336 TRACE( "hwnd %p cs %d,%d %dx%d\n", hwnd
, cs
->x
, cs
->y
, cx
, cy
);
1338 result
= SendMessageW( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1340 result
= SendMessageA( hwnd
, WM_NCCREATE
, 0, (LPARAM
)cs
);
1343 WARN( "%p: aborted by WM_NCCREATE\n", hwnd
);
1347 /* send WM_NCCALCSIZE */
1349 if ((wndPtr
= WIN_GetPtr(hwnd
)))
1351 /* yes, even if the CBT hook was called with HWND_TOP */
1353 HWND insert_after
= (wndPtr
->dwStyle
& WS_CHILD
) ? HWND_BOTTOM
: HWND_TOP
;
1354 RECT window_rect
= wndPtr
->rectWindow
;
1355 RECT client_rect
= window_rect
;
1356 WIN_ReleasePtr( wndPtr
);
1358 /* the rectangle is in screen coords for WM_NCCALCSIZE when wparam is FALSE */
1360 MapWindowPoints( parent
, 0, &pt
, 1 );
1361 OffsetRect( &client_rect
, pt
.x
, pt
.y
);
1362 SendMessageW( hwnd
, WM_NCCALCSIZE
, FALSE
, (LPARAM
)&client_rect
);
1363 OffsetRect( &client_rect
, -pt
.x
, -pt
.y
);
1364 set_window_pos( hwnd
, insert_after
, SWP_NOACTIVATE
, &window_rect
, &client_rect
, NULL
);
1368 /* send WM_CREATE */
1371 result
= SendMessageW( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1373 result
= SendMessageA( hwnd
, WM_CREATE
, 0, (LPARAM
)cs
);
1374 if (result
== -1) goto failed
;
1376 /* call the driver */
1378 if (!USER_Driver
->pCreateWindow( hwnd
)) goto failed
;
1380 NotifyWinEvent(EVENT_OBJECT_CREATE
, hwnd
, OBJID_WINDOW
, 0);
1382 /* send the size messages */
1384 if (!(wndPtr
= WIN_GetPtr( hwnd
)) ||
1385 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
1386 if (!(wndPtr
->flags
& WIN_NEED_SIZE
))
1388 rect
= wndPtr
->rectClient
;
1389 WIN_ReleasePtr( wndPtr
);
1390 SendMessageW( hwnd
, WM_SIZE
, SIZE_RESTORED
,
1391 MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
));
1392 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( rect
.left
, rect
.top
) );
1394 else WIN_ReleasePtr( wndPtr
);
1396 /* Show the window, maximizing or minimizing if needed */
1398 style
= WIN_SetStyle( hwnd
, 0, WS_MAXIMIZE
| WS_MINIMIZE
);
1399 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1402 UINT swFlag
= (style
& WS_MINIMIZE
) ? SW_MINIMIZE
: SW_MAXIMIZE
;
1404 swFlag
= WINPOS_MinMaximize( hwnd
, swFlag
, &newPos
);
1405 swFlag
|= SWP_FRAMECHANGED
; /* Frame always gets changed */
1406 if (!(style
& WS_VISIBLE
) || (style
& WS_CHILD
) || GetActiveWindow()) swFlag
|= SWP_NOACTIVATE
;
1407 SetWindowPos( hwnd
, 0, newPos
.left
, newPos
.top
, newPos
.right
- newPos
.left
,
1408 newPos
.bottom
- newPos
.top
, swFlag
);
1411 /* Notify the parent window only */
1413 send_parent_notify( hwnd
, WM_CREATE
);
1414 if (!IsWindow( hwnd
)) return 0;
1416 if (cs
->style
& WS_VISIBLE
)
1418 if (cs
->style
& WS_MAXIMIZE
)
1420 else if (cs
->style
& WS_MINIMIZE
)
1421 sw
= SW_SHOWMINIMIZED
;
1423 ShowWindow( hwnd
, sw
);
1424 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1426 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1427 /* ShowWindow won't activate child windows */
1428 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1432 /* Call WH_SHELL hook */
1434 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1435 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1437 TRACE("created window %p\n", hwnd
);
1441 WIN_DestroyWindow( hwnd
);
1446 /***********************************************************************
1447 * CreateWindow (USER.41)
1449 HWND16 WINAPI
CreateWindow16( LPCSTR className
, LPCSTR windowName
,
1450 DWORD style
, INT16 x
, INT16 y
, INT16 width
,
1451 INT16 height
, HWND16 parent
, HMENU16 menu
,
1452 HINSTANCE16 instance
, LPVOID data
)
1454 return CreateWindowEx16( 0, className
, windowName
, style
,
1455 x
, y
, width
, height
, parent
, menu
, instance
, data
);
1459 /***********************************************************************
1460 * CreateWindowEx (USER.452)
1462 HWND16 WINAPI
CreateWindowEx16( DWORD exStyle
, LPCSTR className
,
1463 LPCSTR windowName
, DWORD style
, INT16 x
,
1464 INT16 y
, INT16 width
, INT16 height
,
1465 HWND16 parent
, HMENU16 menu
,
1466 HINSTANCE16 instance
, LPVOID data
)
1471 /* Fix the coordinates */
1473 cs
.x
= (x
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)x
;
1474 cs
.y
= (y
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)y
;
1475 cs
.cx
= (width
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)width
;
1476 cs
.cy
= (height
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)height
;
1478 /* Create the window */
1480 cs
.lpCreateParams
= data
;
1481 cs
.hInstance
= HINSTANCE_32(instance
);
1482 cs
.hMenu
= HMENU_32(menu
);
1483 cs
.hwndParent
= WIN_Handle32( parent
);
1485 cs
.lpszName
= windowName
;
1486 cs
.lpszClass
= className
;
1487 cs
.dwExStyle
= exStyle
;
1489 if (!IS_INTRESOURCE(className
))
1493 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) ))
1495 return HWND_16( WIN_CreateWindowEx( &cs
, bufferW
, 0 ));
1499 if (!GlobalGetAtomNameA( LOWORD(className
), buffer
, sizeof(buffer
) ))
1501 ERR( "bad atom %x\n", LOWORD(className
));
1504 cs
.lpszClass
= buffer
;
1505 return HWND_16( WIN_CreateWindowEx( &cs
, (LPCWSTR
)className
, 0 ));
1510 /***********************************************************************
1511 * CreateWindowExA (USER32.@)
1513 HWND WINAPI
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1514 LPCSTR windowName
, DWORD style
, INT x
,
1515 INT y
, INT width
, INT height
,
1516 HWND parent
, HMENU menu
,
1517 HINSTANCE instance
, LPVOID data
)
1521 cs
.lpCreateParams
= data
;
1522 cs
.hInstance
= instance
;
1524 cs
.hwndParent
= parent
;
1530 cs
.lpszName
= windowName
;
1531 cs
.lpszClass
= className
;
1532 cs
.dwExStyle
= exStyle
;
1534 if (!IS_INTRESOURCE(className
))
1537 if (!MultiByteToWideChar( CP_ACP
, 0, className
, -1, bufferW
, sizeof(bufferW
)/sizeof(WCHAR
) ))
1539 return WIN_CreateWindowEx( &cs
, bufferW
, WIN_ISWIN32
);
1541 return WIN_CreateWindowEx( &cs
, (LPCWSTR
)className
, WIN_ISWIN32
);
1545 /***********************************************************************
1546 * CreateWindowExW (USER32.@)
1548 HWND WINAPI
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1549 LPCWSTR windowName
, DWORD style
, INT x
,
1550 INT y
, INT width
, INT height
,
1551 HWND parent
, HMENU menu
,
1552 HINSTANCE instance
, LPVOID data
)
1556 cs
.lpCreateParams
= data
;
1557 cs
.hInstance
= instance
;
1559 cs
.hwndParent
= parent
;
1565 cs
.lpszName
= windowName
;
1566 cs
.lpszClass
= className
;
1567 cs
.dwExStyle
= exStyle
;
1569 /* Note: we rely on the fact that CREATESTRUCTA and */
1570 /* CREATESTRUCTW have the same layout. */
1571 return WIN_CreateWindowEx( (CREATESTRUCTA
*)&cs
, className
, WIN_ISWIN32
| WIN_ISUNICODE
);
1575 /***********************************************************************
1576 * WIN_SendDestroyMsg
1578 static void WIN_SendDestroyMsg( HWND hwnd
)
1582 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1584 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1585 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1589 * Send the WM_DESTROY to the window.
1591 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1594 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1595 * make sure that the window still exists when we come back.
1602 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1604 for (i
= 0; pWndArray
[i
]; i
++)
1606 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1608 HeapFree( GetProcessHeap(), 0, pWndArray
);
1611 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1615 /***********************************************************************
1616 * DestroyWindow (USER32.@)
1618 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1622 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || is_desktop_window( hwnd
))
1624 SetLastError( ERROR_ACCESS_DENIED
);
1628 TRACE("(%p)\n", hwnd
);
1632 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
1634 if (MENU_IsMenuActive() == hwnd
)
1637 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
1641 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1642 send_parent_notify( hwnd
, WM_DESTROY
);
1644 else if (!GetWindow( hwnd
, GW_OWNER
))
1646 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1647 /* FIXME: clean up palette - see "Internals" p.352 */
1650 if (!IsWindow(hwnd
)) return TRUE
;
1652 /* Hide the window */
1653 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
1655 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1657 ShowWindow( hwnd
, SW_HIDE
);
1659 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1660 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1663 if (!IsWindow(hwnd
)) return TRUE
;
1665 /* Recursively destroy owned windows */
1672 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1675 for (i
= 0; list
[i
]; i
++)
1677 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1678 if (WIN_IsCurrentThread( list
[i
] ))
1680 DestroyWindow( list
[i
] );
1684 WIN_SetOwner( list
[i
], 0 );
1686 HeapFree( GetProcessHeap(), 0, list
);
1688 if (!got_one
) break;
1692 /* Send destroy messages */
1694 WIN_SendDestroyMsg( hwnd
);
1695 if (!IsWindow( hwnd
)) return TRUE
;
1697 if (GetClipboardOwner() == hwnd
)
1698 CLIPBOARD_ReleaseOwner();
1700 /* Destroy the window storage */
1702 WIN_DestroyWindow( hwnd
);
1707 /***********************************************************************
1708 * CloseWindow (USER32.@)
1710 BOOL WINAPI
CloseWindow( HWND hwnd
)
1712 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
1713 ShowWindow( hwnd
, SW_MINIMIZE
);
1718 /***********************************************************************
1719 * OpenIcon (USER32.@)
1721 BOOL WINAPI
OpenIcon( HWND hwnd
)
1723 if (!IsIconic( hwnd
)) return FALSE
;
1724 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1729 /***********************************************************************
1730 * FindWindowExW (USER32.@)
1732 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
, LPCWSTR className
, LPCWSTR title
)
1737 WCHAR
*buffer
= NULL
;
1739 if (!parent
&& child
) parent
= GetDesktopWindow();
1740 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
1744 len
= strlenW(title
) + 1; /* one extra char to check for chars beyond the end */
1745 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
1748 if (!(list
= list_window_children( 0, parent
, className
, 0 ))) goto done
;
1752 child
= WIN_GetFullHandle( child
);
1753 while (list
[i
] && list
[i
] != child
) i
++;
1754 if (!list
[i
]) goto done
;
1755 i
++; /* start from next window */
1762 if (GetWindowTextW( list
[i
], buffer
, len
+ 1 ) && !strcmpiW( buffer
, title
)) break;
1769 HeapFree( GetProcessHeap(), 0, list
);
1770 HeapFree( GetProcessHeap(), 0, buffer
);
1776 /***********************************************************************
1777 * FindWindowA (USER32.@)
1779 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
1781 HWND ret
= FindWindowExA( 0, 0, className
, title
);
1782 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1787 /***********************************************************************
1788 * FindWindowExA (USER32.@)
1790 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
, LPCSTR className
, LPCSTR title
)
1792 LPWSTR titleW
= NULL
;
1797 DWORD len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
1798 if (!(titleW
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
1799 MultiByteToWideChar( CP_ACP
, 0, title
, -1, titleW
, len
);
1802 if (!IS_INTRESOURCE(className
))
1805 if (MultiByteToWideChar( CP_ACP
, 0, className
, -1, classW
, sizeof(classW
)/sizeof(WCHAR
) ))
1806 hwnd
= FindWindowExW( parent
, child
, classW
, titleW
);
1810 hwnd
= FindWindowExW( parent
, child
, (LPCWSTR
)className
, titleW
);
1813 HeapFree( GetProcessHeap(), 0, titleW
);
1818 /***********************************************************************
1819 * FindWindowW (USER32.@)
1821 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
1823 return FindWindowExW( 0, 0, className
, title
);
1827 /**********************************************************************
1828 * GetDesktopWindow (USER32.@)
1830 HWND WINAPI
GetDesktopWindow(void)
1832 struct user_thread_info
*thread_info
= get_user_thread_info();
1834 if (thread_info
->top_window
) return thread_info
->top_window
;
1836 SERVER_START_REQ( get_desktop_window
)
1839 if (!wine_server_call( req
))
1841 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
1842 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
1847 if (!thread_info
->top_window
)
1849 USEROBJECTFLAGS flags
;
1850 if (!GetUserObjectInformationW( GetProcessWindowStation(), UOI_FLAGS
, &flags
,
1851 sizeof(flags
), NULL
) || (flags
.dwFlags
& WSF_VISIBLE
))
1853 static const WCHAR command_line
[] = {'\\','e','x','p','l','o','r','e','r','.','e','x','e',' ','/','d','e','s','k','t','o','p',0};
1855 PROCESS_INFORMATION pi
;
1856 WCHAR systemdir
[MAX_PATH
];
1857 WCHAR cmdline
[MAX_PATH
+ sizeof(command_line
)/sizeof(WCHAR
)];
1859 memset( &si
, 0, sizeof(si
) );
1861 si
.dwFlags
= STARTF_USESTDHANDLES
;
1864 si
.hStdError
= GetStdHandle( STD_ERROR_HANDLE
);
1866 GetSystemDirectoryW( systemdir
, MAX_PATH
);
1867 lstrcpyW( cmdline
, systemdir
);
1868 lstrcatW( cmdline
, command_line
);
1869 if (CreateProcessW( NULL
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
,
1870 NULL
, systemdir
, &si
, &pi
))
1872 TRACE( "started explorer pid %04x tid %04x\n", pi
.dwProcessId
, pi
.dwThreadId
);
1873 WaitForInputIdle( pi
.hProcess
, 10000 );
1874 CloseHandle( pi
.hThread
);
1875 CloseHandle( pi
.hProcess
);
1877 else WARN( "failed to start explorer, err %d\n", GetLastError() );
1879 else TRACE( "not starting explorer since winstation is not visible\n" );
1881 SERVER_START_REQ( get_desktop_window
)
1884 if (!wine_server_call( req
))
1886 thread_info
->top_window
= wine_server_ptr_handle( reply
->top_window
);
1887 thread_info
->msg_window
= wine_server_ptr_handle( reply
->msg_window
);
1893 if (!thread_info
->top_window
|| !USER_Driver
->pCreateDesktopWindow( thread_info
->top_window
))
1894 ERR( "failed to create desktop window\n" );
1896 return thread_info
->top_window
;
1900 /*******************************************************************
1901 * EnableWindow (USER32.@)
1903 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
1908 if (is_broadcast(hwnd
))
1910 SetLastError( ERROR_INVALID_PARAMETER
);
1914 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
1915 return SendMessageW( hwnd
, WM_WINE_ENABLEWINDOW
, enable
, 0 );
1919 TRACE("( %p, %d )\n", hwnd
, enable
);
1921 retvalue
= !IsWindowEnabled( hwnd
);
1923 if (enable
&& retvalue
)
1925 WIN_SetStyle( hwnd
, 0, WS_DISABLED
);
1926 SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
1928 else if (!enable
&& !retvalue
)
1932 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0);
1934 WIN_SetStyle( hwnd
, WS_DISABLED
, 0 );
1936 if (hwnd
== GetFocus())
1937 SetFocus( 0 ); /* A disabled window can't have the focus */
1939 capture_wnd
= GetCapture();
1940 if (hwnd
== capture_wnd
|| IsChild(hwnd
, capture_wnd
))
1941 ReleaseCapture(); /* A disabled window can't capture the mouse */
1943 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
1949 /***********************************************************************
1950 * IsWindowEnabled (USER32.@)
1952 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
1954 return !(GetWindowLongW( hWnd
, GWL_STYLE
) & WS_DISABLED
);
1958 /***********************************************************************
1959 * IsWindowUnicode (USER32.@)
1961 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
1964 BOOL retvalue
= FALSE
;
1966 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
1968 if (wndPtr
== WND_DESKTOP
) return TRUE
;
1970 if (wndPtr
!= WND_OTHER_PROCESS
)
1972 retvalue
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1973 WIN_ReleasePtr( wndPtr
);
1977 SERVER_START_REQ( get_window_info
)
1979 req
->handle
= wine_server_user_handle( hwnd
);
1980 if (!wine_server_call_err( req
)) retvalue
= reply
->is_unicode
;
1988 /**********************************************************************
1991 * Helper function for GetWindowLong().
1993 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
1995 LONG_PTR retvalue
= 0;
1998 if (offset
== GWLP_HWNDPARENT
)
2000 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
2001 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
2002 return (ULONG_PTR
)parent
;
2005 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2007 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2011 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
2013 if (offset
== GWLP_WNDPROC
)
2015 SetLastError( ERROR_ACCESS_DENIED
);
2018 SERVER_START_REQ( set_window_info
)
2020 req
->handle
= wine_server_user_handle( hwnd
);
2021 req
->flags
= 0; /* don't set anything, just retrieve */
2022 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
2023 req
->extra_size
= (offset
>= 0) ? size
: 0;
2024 if (!wine_server_call_err( req
))
2028 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
2029 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
2030 case GWLP_ID
: retvalue
= reply
->old_id
; break;
2031 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
); break;
2032 case GWLP_USERDATA
: retvalue
= reply
->old_user_data
; break;
2034 if (offset
>= 0) retvalue
= get_win_data( &reply
->old_extra_value
, size
);
2035 else SetLastError( ERROR_INVALID_INDEX
);
2044 /* now we have a valid wndPtr */
2048 if (offset
> (int)(wndPtr
->cbWndExtra
- size
))
2050 WARN("Invalid offset %d\n", offset
);
2051 WIN_ReleasePtr( wndPtr
);
2052 SetLastError( ERROR_INVALID_INDEX
);
2055 retvalue
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2057 /* Special case for dialog window procedure */
2058 if ((offset
== DWLP_DLGPROC
) && (size
== sizeof(LONG_PTR
)) && (wndPtr
->flags
& WIN_ISDIALOG
))
2059 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, unicode
);
2060 WIN_ReleasePtr( wndPtr
);
2066 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
2067 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
2068 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
2069 case GWLP_ID
: retvalue
= wndPtr
->wIDmenu
; break;
2070 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
2072 /* This looks like a hack only for the edit control (see tests). This makes these controls
2073 * more tolerant to A/W mismatches. The lack of W->A->W conversion for such a mismatch suggests
2074 * that the hack is in GetWindowLongPtr[AW], not in winprocs.
2076 if (wndPtr
->winproc
== EDIT_winproc_handle
&& (!unicode
!= !(wndPtr
->flags
& WIN_ISUNICODE
)))
2077 retvalue
= (ULONG_PTR
)wndPtr
->winproc
;
2079 retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
);
2082 WARN("Unknown offset %d\n", offset
);
2083 SetLastError( ERROR_INVALID_INDEX
);
2086 WIN_ReleasePtr(wndPtr
);
2091 /**********************************************************************
2094 * Helper function for SetWindowLong().
2096 * 0 is the failure code. However, in the case of failure SetLastError
2097 * must be set to distinguish between a 0 return value and a failure.
2099 LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, UINT size
, LONG_PTR newval
, BOOL unicode
)
2103 LONG_PTR retval
= 0;
2106 TRACE( "%p %d %lx %c\n", hwnd
, offset
, newval
, unicode
? 'W' : 'A' );
2108 if (is_broadcast(hwnd
))
2110 SetLastError( ERROR_INVALID_PARAMETER
);
2114 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2116 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2119 if (wndPtr
== WND_DESKTOP
)
2121 /* can't change anything on the desktop window */
2122 SetLastError( ERROR_ACCESS_DENIED
);
2125 if (wndPtr
== WND_OTHER_PROCESS
)
2127 if (offset
== GWLP_WNDPROC
)
2129 SetLastError( ERROR_ACCESS_DENIED
);
2132 if (offset
> 32767 || offset
< -32767)
2134 SetLastError( ERROR_INVALID_INDEX
);
2137 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, MAKEWPARAM( offset
, size
), newval
);
2140 /* first some special cases */
2146 offset
== GWL_STYLE
? wndPtr
->dwStyle
: wndPtr
->dwExStyle
;
2147 style
.styleNew
= newval
;
2148 WIN_ReleasePtr( wndPtr
);
2149 SendMessageW( hwnd
, WM_STYLECHANGING
, offset
, (LPARAM
)&style
);
2150 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
2151 newval
= style
.styleNew
;
2153 case GWLP_HWNDPARENT
:
2154 if (wndPtr
->parent
== GetDesktopWindow())
2156 WIN_ReleasePtr( wndPtr
);
2157 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
2161 WIN_ReleasePtr( wndPtr
);
2162 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
2167 UINT old_flags
= wndPtr
->flags
;
2168 retval
= WIN_GetWindowLong( hwnd
, offset
, size
, unicode
);
2169 if (unicode
) proc
= WINPROC_AllocProc( NULL
, (WNDPROC
)newval
);
2170 else proc
= WINPROC_AllocProc( (WNDPROC
)newval
, NULL
);
2171 if (proc
) wndPtr
->winproc
= proc
;
2172 if (WINPROC_IsUnicode( proc
, unicode
)) wndPtr
->flags
|= WIN_ISUNICODE
;
2173 else wndPtr
->flags
&= ~WIN_ISUNICODE
;
2174 if (!((old_flags
^ wndPtr
->flags
) & WIN_ISUNICODE
))
2176 WIN_ReleasePtr( wndPtr
);
2179 /* update is_unicode flag on the server side */
2183 case GWLP_HINSTANCE
:
2187 if ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2188 (size
== sizeof(LONG_PTR
)) && (wndPtr
->flags
& WIN_ISDIALOG
))
2190 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
2191 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, unicode
);
2192 if (unicode
) *ptr
= WINPROC_AllocProc( NULL
, (WNDPROC
)newval
);
2193 else *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, NULL
);
2194 WIN_ReleasePtr( wndPtr
);
2199 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- size
))
2201 WARN("Invalid offset %d\n", offset
);
2202 WIN_ReleasePtr( wndPtr
);
2203 SetLastError( ERROR_INVALID_INDEX
);
2206 else if (get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
) == newval
)
2208 /* already set to the same value */
2209 WIN_ReleasePtr( wndPtr
);
2215 SERVER_START_REQ( set_window_info
)
2217 req
->handle
= wine_server_user_handle( hwnd
);
2218 req
->extra_offset
= -1;
2222 req
->flags
= SET_WIN_STYLE
;
2223 req
->style
= newval
;
2226 req
->flags
= SET_WIN_EXSTYLE
;
2227 /* WS_EX_TOPMOST can only be changed through SetWindowPos */
2228 newval
= (newval
& ~WS_EX_TOPMOST
) | (wndPtr
->dwExStyle
& WS_EX_TOPMOST
);
2229 req
->ex_style
= newval
;
2232 req
->flags
= SET_WIN_ID
;
2235 case GWLP_HINSTANCE
:
2236 req
->flags
= SET_WIN_INSTANCE
;
2237 req
->instance
= wine_server_client_ptr( (void *)newval
);
2240 req
->flags
= SET_WIN_UNICODE
;
2241 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
2244 req
->flags
= SET_WIN_USERDATA
;
2245 req
->user_data
= newval
;
2248 req
->flags
= SET_WIN_EXTRA
;
2249 req
->extra_offset
= offset
;
2250 req
->extra_size
= size
;
2251 set_win_data( &req
->extra_value
, newval
, size
);
2253 if ((ok
= !wine_server_call_err( req
)))
2258 wndPtr
->dwStyle
= newval
;
2259 retval
= reply
->old_style
;
2262 wndPtr
->dwExStyle
= newval
;
2263 retval
= reply
->old_ex_style
;
2266 wndPtr
->wIDmenu
= newval
;
2267 retval
= reply
->old_id
;
2269 case GWLP_HINSTANCE
:
2270 wndPtr
->hInstance
= (HINSTANCE
)newval
;
2271 retval
= (ULONG_PTR
)wine_server_get_ptr( reply
->old_instance
);
2276 wndPtr
->userdata
= newval
;
2277 retval
= reply
->old_user_data
;
2280 retval
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
2281 set_win_data( (char *)wndPtr
->wExtra
+ offset
, newval
, size
);
2287 WIN_ReleasePtr( wndPtr
);
2291 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2293 USER_Driver
->pSetWindowStyle( hwnd
, offset
, &style
);
2294 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2301 /**********************************************************************
2302 * GetWindowLong (USER.135)
2304 LONG WINAPI
GetWindowLong16( HWND16 hwnd
, INT16 offset
)
2308 BOOL is_winproc
= (offset
== GWLP_WNDPROC
);
2312 if (!(wndPtr
= WIN_GetPtr( WIN_Handle32(hwnd
) )))
2314 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2317 if (wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
2319 if (offset
> (int)(wndPtr
->cbWndExtra
- sizeof(LONG
)))
2322 * Some programs try to access last element from 16 bit
2323 * code using illegal offset value. Hopefully this is
2324 * what those programs really expect.
2326 if (wndPtr
->cbWndExtra
>= 4 && offset
== wndPtr
->cbWndExtra
- sizeof(WORD
))
2328 INT offset2
= wndPtr
->cbWndExtra
- sizeof(LONG
);
2329 ERR( "- replaced invalid offset %d with %d\n", offset
, offset2
);
2334 WARN("Invalid offset %d\n", offset
);
2335 WIN_ReleasePtr( wndPtr
);
2336 SetLastError( ERROR_INVALID_INDEX
);
2340 is_winproc
= ((offset
== DWLP_DLGPROC
) && (wndPtr
->flags
& WIN_ISDIALOG
));
2341 WIN_ReleasePtr( wndPtr
);
2344 retvalue
= GetWindowLongA( WIN_Handle32(hwnd
), offset
);
2345 if (is_winproc
) retvalue
= (LONG_PTR
)WINPROC_GetProc16( (WNDPROC
)retvalue
, FALSE
);
2350 /**********************************************************************
2351 * GetWindowWord (USER32.@)
2353 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
2358 case GWLP_HINSTANCE
:
2359 case GWLP_HWNDPARENT
:
2364 WARN("Invalid offset %d\n", offset
);
2365 SetLastError( ERROR_INVALID_INDEX
);
2370 return WIN_GetWindowLong( hwnd
, offset
, sizeof(WORD
), FALSE
);
2374 /**********************************************************************
2375 * GetWindowLongA (USER32.@)
2377 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2379 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), FALSE
);
2383 /**********************************************************************
2384 * GetWindowLongW (USER32.@)
2386 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2388 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), TRUE
);
2392 /**********************************************************************
2393 * SetWindowLong (USER.136)
2395 LONG WINAPI
SetWindowLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
2398 BOOL is_winproc
= (offset
== GWLP_WNDPROC
);
2400 if (offset
== DWLP_DLGPROC
)
2402 if (!(wndPtr
= WIN_GetPtr( WIN_Handle32(hwnd
) )))
2404 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2407 if (wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
2409 is_winproc
= ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2410 (wndPtr
->flags
& WIN_ISDIALOG
));
2411 WIN_ReleasePtr( wndPtr
);
2417 WNDPROC new_proc
= WINPROC_AllocProc16( (WNDPROC16
)newval
);
2418 WNDPROC old_proc
= (WNDPROC
)SetWindowLongPtrA( WIN_Handle32(hwnd
), offset
, (LONG_PTR
)new_proc
);
2419 return (LONG
)WINPROC_GetProc16( old_proc
, FALSE
);
2421 else return SetWindowLongA( WIN_Handle32(hwnd
), offset
, newval
);
2425 /**********************************************************************
2426 * SetWindowWord (USER32.@)
2428 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
2433 case GWLP_HINSTANCE
:
2434 case GWLP_HWNDPARENT
:
2439 WARN("Invalid offset %d\n", offset
);
2440 SetLastError( ERROR_INVALID_INDEX
);
2445 return WIN_SetWindowLong( hwnd
, offset
, sizeof(WORD
), newval
, FALSE
);
2449 /**********************************************************************
2450 * SetWindowLongA (USER32.@)
2452 * See SetWindowLongW.
2454 LONG WINAPI
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2456 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, FALSE
);
2460 /**********************************************************************
2461 * SetWindowLongW (USER32.@) Set window attribute
2463 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2464 * value in a window's extra memory.
2466 * The _hwnd_ parameter specifies the window. is the handle to a
2467 * window that has extra memory. The _newval_ parameter contains the
2468 * new attribute or extra memory value. If positive, the _offset_
2469 * parameter is the byte-addressed location in the window's extra
2470 * memory to set. If negative, _offset_ specifies the window
2471 * attribute to set, and should be one of the following values:
2473 * GWL_EXSTYLE The window's extended window style
2475 * GWL_STYLE The window's window style.
2477 * GWLP_WNDPROC Pointer to the window's window procedure.
2479 * GWLP_HINSTANCE The window's pplication instance handle.
2481 * GWLP_ID The window's identifier.
2483 * GWLP_USERDATA The window's user-specified data.
2485 * If the window is a dialog box, the _offset_ parameter can be one of
2486 * the following values:
2488 * DWLP_DLGPROC The address of the window's dialog box procedure.
2490 * DWLP_MSGRESULT The return value of a message
2491 * that the dialog box procedure processed.
2493 * DWLP_USER Application specific information.
2497 * If successful, returns the previous value located at _offset_. Otherwise,
2502 * Extra memory for a window class is specified by a nonzero cbWndExtra
2503 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2504 * time of class creation.
2506 * Using GWL_WNDPROC to set a new window procedure effectively creates
2507 * a window subclass. Use CallWindowProc() in the new windows procedure
2508 * to pass messages to the superclass's window procedure.
2510 * The user data is reserved for use by the application which created
2513 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2514 * instead, call the EnableWindow() function to change the window's
2517 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2518 * SetParent() instead.
2521 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2522 * it sends WM_STYLECHANGING before changing the settings
2523 * and WM_STYLECHANGED afterwards.
2524 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2526 LONG WINAPI
SetWindowLongW(
2527 HWND hwnd
, /* [in] window to alter */
2528 INT offset
, /* [in] offset, in bytes, of location to alter */
2529 LONG newval
/* [in] new value of location */
2531 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, TRUE
);
2535 /*******************************************************************
2536 * GetWindowTextA (USER32.@)
2538 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2542 if (!lpString
) return 0;
2544 if (WIN_IsCurrentProcess( hwnd
))
2545 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2547 /* when window belongs to other process, don't send a message */
2548 if (nMaxCount
<= 0) return 0;
2549 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) ))) return 0;
2550 get_server_window_text( hwnd
, buffer
, nMaxCount
);
2551 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
2552 lpString
[nMaxCount
-1] = 0;
2553 HeapFree( GetProcessHeap(), 0, buffer
);
2554 return strlen(lpString
);
2558 /*******************************************************************
2559 * InternalGetWindowText (USER32.@)
2561 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2565 if (nMaxCount
<= 0) return 0;
2566 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
2567 if (win
== WND_DESKTOP
) lpString
[0] = 0;
2568 else if (win
!= WND_OTHER_PROCESS
)
2570 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
2571 else lpString
[0] = 0;
2572 WIN_ReleasePtr( win
);
2576 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2578 return strlenW(lpString
);
2582 /*******************************************************************
2583 * GetWindowTextW (USER32.@)
2585 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2587 if (!lpString
) return 0;
2589 if (WIN_IsCurrentProcess( hwnd
))
2590 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2592 /* when window belongs to other process, don't send a message */
2593 if (nMaxCount
<= 0) return 0;
2594 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2595 return strlenW(lpString
);
2599 /*******************************************************************
2600 * SetWindowTextA (USER32.@)
2601 * SetWindowText (USER32.@)
2603 BOOL WINAPI
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2605 if (is_broadcast(hwnd
))
2607 SetLastError( ERROR_INVALID_PARAMETER
);
2610 if (!WIN_IsCurrentProcess( hwnd
))
2611 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2612 debugstr_a(lpString
), hwnd
);
2613 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2617 /*******************************************************************
2618 * SetWindowTextW (USER32.@)
2620 BOOL WINAPI
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2622 if (is_broadcast(hwnd
))
2624 SetLastError( ERROR_INVALID_PARAMETER
);
2627 if (!WIN_IsCurrentProcess( hwnd
))
2628 WARN( "setting text %s of other process window %p should not use SendMessage\n",
2629 debugstr_w(lpString
), hwnd
);
2630 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2634 /*******************************************************************
2635 * GetWindowTextLengthA (USER32.@)
2637 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2639 return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2642 /*******************************************************************
2643 * GetWindowTextLengthW (USER32.@)
2645 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2647 return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2651 /*******************************************************************
2652 * IsWindow (USER32.@)
2654 BOOL WINAPI
IsWindow( HWND hwnd
)
2659 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
2660 if (ptr
== WND_DESKTOP
) return TRUE
;
2662 if (ptr
!= WND_OTHER_PROCESS
)
2664 WIN_ReleasePtr( ptr
);
2668 /* check other processes */
2669 SERVER_START_REQ( get_window_info
)
2671 req
->handle
= wine_server_user_handle( hwnd
);
2672 ret
= !wine_server_call_err( req
);
2679 /***********************************************************************
2680 * GetWindowThreadProcessId (USER32.@)
2682 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
2687 if (!(ptr
= WIN_GetPtr( hwnd
)))
2689 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2693 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
2695 /* got a valid window */
2697 if (process
) *process
= GetCurrentProcessId();
2698 WIN_ReleasePtr( ptr
);
2702 /* check other processes */
2703 SERVER_START_REQ( get_window_info
)
2705 req
->handle
= wine_server_user_handle( hwnd
);
2706 if (!wine_server_call_err( req
))
2708 tid
= (DWORD
)reply
->tid
;
2709 if (process
) *process
= (DWORD
)reply
->pid
;
2717 /*****************************************************************
2718 * GetParent (USER32.@)
2720 HWND WINAPI
GetParent( HWND hwnd
)
2725 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2727 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2730 if (wndPtr
== WND_DESKTOP
) return 0;
2731 if (wndPtr
== WND_OTHER_PROCESS
)
2733 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2734 if (style
& (WS_POPUP
| WS_CHILD
))
2736 SERVER_START_REQ( get_window_tree
)
2738 req
->handle
= wine_server_user_handle( hwnd
);
2739 if (!wine_server_call_err( req
))
2741 if (style
& WS_POPUP
) retvalue
= wine_server_ptr_handle( reply
->owner
);
2742 else if (style
& WS_CHILD
) retvalue
= wine_server_ptr_handle( reply
->parent
);
2750 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
2751 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
2752 WIN_ReleasePtr( wndPtr
);
2758 /*****************************************************************
2759 * GetAncestor (USER32.@)
2761 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
2764 HWND
*list
, ret
= 0;
2769 if (!(win
= WIN_GetPtr( hwnd
)))
2771 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2774 if (win
== WND_DESKTOP
) return 0;
2775 if (win
!= WND_OTHER_PROCESS
)
2778 WIN_ReleasePtr( win
);
2780 else /* need to query the server */
2782 SERVER_START_REQ( get_window_tree
)
2784 req
->handle
= wine_server_user_handle( hwnd
);
2785 if (!wine_server_call_err( req
)) ret
= wine_server_ptr_handle( reply
->parent
);
2792 if (!(list
= list_window_parents( hwnd
))) return 0;
2794 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
2798 while (list
[count
]) count
++;
2799 ret
= list
[count
- 2]; /* get the one before the desktop */
2801 HeapFree( GetProcessHeap(), 0, list
);
2805 if (is_desktop_window( hwnd
)) return 0;
2806 ret
= WIN_GetFullHandle( hwnd
);
2809 HWND parent
= GetParent( ret
);
2819 /*****************************************************************
2820 * SetParent (USER32.@)
2822 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
2825 HWND old_parent
= 0;
2830 if (is_broadcast(hwnd
) || is_broadcast(parent
))
2832 SetLastError(ERROR_INVALID_PARAMETER
);
2836 if (!parent
) parent
= GetDesktopWindow();
2837 else if (parent
== HWND_MESSAGE
) parent
= get_hwnd_message_parent();
2838 else parent
= WIN_GetFullHandle( parent
);
2840 if (!IsWindow( parent
))
2842 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2846 /* Some applications try to set a child as a parent */
2847 if (IsChild(hwnd
, parent
))
2849 SetLastError( ERROR_INVALID_PARAMETER
);
2853 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
2854 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
2856 /* Windows hides the window first, then shows it again
2857 * including the WM_SHOWWINDOW messages and all */
2858 was_visible
= ShowWindow( hwnd
, SW_HIDE
);
2860 wndPtr
= WIN_GetPtr( hwnd
);
2861 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return 0;
2863 SERVER_START_REQ( set_parent
)
2865 req
->handle
= wine_server_user_handle( hwnd
);
2866 req
->parent
= wine_server_user_handle( parent
);
2867 if ((ret
= !wine_server_call( req
)))
2869 old_parent
= wine_server_ptr_handle( reply
->old_parent
);
2870 wndPtr
->parent
= parent
= wine_server_ptr_handle( reply
->full_parent
);
2875 WIN_ReleasePtr( wndPtr
);
2878 USER_Driver
->pSetParent( full_handle
, parent
, old_parent
);
2880 /* SetParent additionally needs to make hwnd the topmost window
2881 in the x-order and send the expected WM_WINDOWPOSCHANGING and
2882 WM_WINDOWPOSCHANGED notification messages.
2884 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0,
2885 SWP_NOACTIVATE
| SWP_NOMOVE
| SWP_NOSIZE
| (was_visible
? SWP_SHOWWINDOW
: 0) );
2886 /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
2887 * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
2893 /*******************************************************************
2894 * IsChild (USER32.@)
2896 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
2898 HWND
*list
= list_window_parents( child
);
2902 if (!list
) return FALSE
;
2903 parent
= WIN_GetFullHandle( parent
);
2904 for (i
= 0; list
[i
]; i
++) if (list
[i
] == parent
) break;
2905 ret
= list
[i
] && list
[i
+1];
2906 HeapFree( GetProcessHeap(), 0, list
);
2911 /***********************************************************************
2912 * IsWindowVisible (USER32.@)
2914 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
2920 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
2921 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
2924 for (i
= 0; list
[i
+1]; i
++)
2925 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
2926 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
2928 HeapFree( GetProcessHeap(), 0, list
);
2933 /***********************************************************************
2934 * WIN_IsWindowDrawable
2936 * hwnd is drawable when it is visible, all parents are not
2937 * minimized, and it is itself not minimized unless we are
2938 * trying to draw its default class icon.
2940 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
2945 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2947 if (!(style
& WS_VISIBLE
)) return FALSE
;
2948 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
2950 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
2953 for (i
= 0; list
[i
+1]; i
++)
2954 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
2956 retval
= !list
[i
+1] && (list
[i
] == GetDesktopWindow()); /* top message window isn't visible */
2958 HeapFree( GetProcessHeap(), 0, list
);
2963 /*******************************************************************
2964 * GetTopWindow (USER32.@)
2966 HWND WINAPI
GetTopWindow( HWND hwnd
)
2968 if (!hwnd
) hwnd
= GetDesktopWindow();
2969 return GetWindow( hwnd
, GW_CHILD
);
2973 /*******************************************************************
2974 * GetWindow (USER32.@)
2976 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
2980 if (rel
== GW_OWNER
) /* this one may be available locally */
2982 WND
*wndPtr
= WIN_GetPtr( hwnd
);
2985 SetLastError( ERROR_INVALID_HANDLE
);
2988 if (wndPtr
== WND_DESKTOP
) return 0;
2989 if (wndPtr
!= WND_OTHER_PROCESS
)
2991 retval
= wndPtr
->owner
;
2992 WIN_ReleasePtr( wndPtr
);
2995 /* else fall through to server call */
2998 SERVER_START_REQ( get_window_tree
)
3000 req
->handle
= wine_server_user_handle( hwnd
);
3001 if (!wine_server_call_err( req
))
3006 retval
= wine_server_ptr_handle( reply
->first_sibling
);
3009 retval
= wine_server_ptr_handle( reply
->last_sibling
);
3012 retval
= wine_server_ptr_handle( reply
->next_sibling
);
3015 retval
= wine_server_ptr_handle( reply
->prev_sibling
);
3018 retval
= wine_server_ptr_handle( reply
->owner
);
3021 retval
= wine_server_ptr_handle( reply
->first_child
);
3031 /*******************************************************************
3032 * ShowOwnedPopups (USER32.@)
3034 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
3038 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
3040 if (!win_array
) return TRUE
;
3042 while (win_array
[count
]) count
++;
3043 while (--count
>= 0)
3045 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
3046 if (!(pWnd
= WIN_GetPtr( win_array
[count
] ))) continue;
3047 if (pWnd
== WND_OTHER_PROCESS
) continue;
3050 if (pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
3052 WIN_ReleasePtr( pWnd
);
3053 /* In Windows, ShowOwnedPopups(TRUE) generates
3054 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
3055 * regardless of the state of the owner
3057 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
3063 if (pWnd
->dwStyle
& WS_VISIBLE
)
3065 WIN_ReleasePtr( pWnd
);
3066 /* In Windows, ShowOwnedPopups(FALSE) generates
3067 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
3068 * regardless of the state of the owner
3070 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
3074 WIN_ReleasePtr( pWnd
);
3076 HeapFree( GetProcessHeap(), 0, win_array
);
3081 /*******************************************************************
3082 * GetLastActivePopup (USER32.@)
3084 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
3088 SERVER_START_REQ( get_window_info
)
3090 req
->handle
= wine_server_user_handle( hwnd
);
3091 if (!wine_server_call_err( req
)) retval
= wine_server_ptr_handle( reply
->last_active
);
3098 /*******************************************************************
3101 * Build an array of the children of a given window. The array must be
3102 * freed with HeapFree. Returns NULL when no windows are found.
3104 HWND
*WIN_ListChildren( HWND hwnd
)
3108 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3111 return list_window_children( 0, hwnd
, NULL
, 0 );
3115 /*******************************************************************
3116 * EnumWindows (USER32.@)
3118 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
3124 USER_CheckNotLock();
3126 /* We have to build a list of all windows first, to avoid */
3127 /* unpleasant side-effects, for instance if the callback */
3128 /* function changes the Z-order of the windows. */
3130 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
3132 /* Now call the callback function for every window */
3134 for (i
= 0; list
[i
]; i
++)
3136 /* Make sure that the window still exists */
3137 if (!IsWindow( list
[i
] )) continue;
3138 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
3140 HeapFree( GetProcessHeap(), 0, list
);
3145 /**********************************************************************
3146 * EnumThreadWindows (USER32.@)
3148 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
3153 USER_CheckNotLock();
3155 if (!(list
= list_window_children( 0, GetDesktopWindow(), NULL
, id
))) return TRUE
;
3157 /* Now call the callback function for every window */
3159 for (i
= 0; list
[i
]; i
++)
3160 if (!func( list
[i
], lParam
)) break;
3161 HeapFree( GetProcessHeap(), 0, list
);
3166 /***********************************************************************
3167 * EnumDesktopWindows (USER32.@)
3169 BOOL WINAPI
EnumDesktopWindows( HDESK desktop
, WNDENUMPROC func
, LPARAM lparam
)
3174 USER_CheckNotLock();
3176 if (!(list
= list_window_children( desktop
, 0, NULL
, 0 ))) return TRUE
;
3178 for (i
= 0; list
[i
]; i
++)
3179 if (!func( list
[i
], lparam
)) break;
3180 HeapFree( GetProcessHeap(), 0, list
);
3185 /**********************************************************************
3186 * WIN_EnumChildWindows
3188 * Helper function for EnumChildWindows().
3190 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
3195 for ( ; *list
; list
++)
3197 /* Make sure that the window still exists */
3198 if (!IsWindow( *list
)) continue;
3199 /* Build children list first */
3200 childList
= WIN_ListChildren( *list
);
3202 ret
= func( *list
, lParam
);
3206 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
3207 HeapFree( GetProcessHeap(), 0, childList
);
3209 if (!ret
) return FALSE
;
3215 /**********************************************************************
3216 * EnumChildWindows (USER32.@)
3218 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
3223 USER_CheckNotLock();
3225 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
3226 ret
= WIN_EnumChildWindows( list
, func
, lParam
);
3227 HeapFree( GetProcessHeap(), 0, list
);
3232 /*******************************************************************
3233 * AnyPopup (USER.52)
3235 BOOL16 WINAPI
AnyPopup16(void)
3241 /*******************************************************************
3242 * AnyPopup (USER32.@)
3244 BOOL WINAPI
AnyPopup(void)
3248 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
3250 if (!list
) return FALSE
;
3251 for (i
= 0; list
[i
]; i
++)
3253 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
3255 retvalue
= (list
[i
] != 0);
3256 HeapFree( GetProcessHeap(), 0, list
);
3261 /*******************************************************************
3262 * FlashWindow (USER32.@)
3264 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
3268 TRACE("%p\n", hWnd
);
3270 if (IsIconic( hWnd
))
3272 RedrawWindow( hWnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
3274 wndPtr
= WIN_GetPtr(hWnd
);
3275 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3276 if (bInvert
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
3278 wndPtr
->flags
|= WIN_NCACTIVATED
;
3282 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
3284 WIN_ReleasePtr( wndPtr
);
3291 wndPtr
= WIN_GetPtr(hWnd
);
3292 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
3293 hWnd
= wndPtr
->obj
.handle
; /* make it a full handle */
3295 if (bInvert
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
3296 else wparam
= (hWnd
== GetForegroundWindow());
3298 WIN_ReleasePtr( wndPtr
);
3299 SendMessageW( hWnd
, WM_NCACTIVATE
, wparam
, 0 );
3304 /*******************************************************************
3305 * FlashWindowEx (USER32.@)
3307 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfwi
)
3309 FIXME("%p\n", pfwi
);
3313 /*******************************************************************
3314 * GetWindowContextHelpId (USER32.@)
3316 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
3319 WND
*wnd
= WIN_GetPtr( hwnd
);
3320 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
3321 if (wnd
== WND_OTHER_PROCESS
)
3323 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3326 retval
= wnd
->helpContext
;
3327 WIN_ReleasePtr( wnd
);
3332 /*******************************************************************
3333 * SetWindowContextHelpId (USER32.@)
3335 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
3337 WND
*wnd
= WIN_GetPtr( hwnd
);
3338 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
3339 if (wnd
== WND_OTHER_PROCESS
)
3341 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
3344 wnd
->helpContext
= id
;
3345 WIN_ReleasePtr( wnd
);
3350 /*******************************************************************
3351 * DragDetect (USER32.@)
3353 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3357 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3358 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3360 rect
.left
= pt
.x
- wDragWidth
;
3361 rect
.right
= pt
.x
+ wDragWidth
;
3363 rect
.top
= pt
.y
- wDragHeight
;
3364 rect
.bottom
= pt
.y
+ wDragHeight
;
3370 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
3372 if( msg
.message
== WM_LBUTTONUP
)
3377 if( msg
.message
== WM_MOUSEMOVE
)
3380 tmp
.x
= (short)LOWORD(msg
.lParam
);
3381 tmp
.y
= (short)HIWORD(msg
.lParam
);
3382 if( !PtInRect( &rect
, tmp
))
3394 /******************************************************************************
3395 * GetWindowModuleFileNameA (USER32.@)
3397 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR module
, UINT size
)
3402 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3404 win
= WIN_GetPtr( hwnd
);
3405 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3407 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3410 hinst
= win
->hInstance
;
3411 WIN_ReleasePtr( win
);
3413 return GetModuleFileNameA( hinst
, module
, size
);
3416 /******************************************************************************
3417 * GetWindowModuleFileNameW (USER32.@)
3419 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR module
, UINT size
)
3424 TRACE( "%p, %p, %u\n", hwnd
, module
, size
);
3426 win
= WIN_GetPtr( hwnd
);
3427 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
)
3429 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
3432 hinst
= win
->hInstance
;
3433 WIN_ReleasePtr( win
);
3435 return GetModuleFileNameW( hinst
, module
, size
);
3438 /******************************************************************************
3439 * GetWindowInfo (USER32.@)
3441 * Note: tests show that Windows doesn't check cbSize of the structure.
3443 BOOL WINAPI
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
3445 if (!pwi
) return FALSE
;
3446 if (!IsWindow(hwnd
)) return FALSE
;
3448 GetWindowRect(hwnd
, &pwi
->rcWindow
);
3449 GetClientRect(hwnd
, &pwi
->rcClient
);
3450 /* translate to screen coordinates */
3451 MapWindowPoints(hwnd
, 0, (LPPOINT
)&pwi
->rcClient
, 2);
3453 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3454 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3455 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
3457 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
3458 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
3460 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
3461 pwi
->wCreatorVersion
= 0x0400;
3466 /******************************************************************************
3467 * SwitchDesktop (USER32.@)
3469 * NOTES: Sets the current input or interactive desktop.
3471 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
3473 FIXME("SwitchDesktop(hwnd %p) stub!\n", hDesktop
);
3477 /*****************************************************************************
3478 * SetLayeredWindowAttributes (USER32.@)
3480 BOOL WINAPI
SetLayeredWindowAttributes( HWND hwnd
, COLORREF key
, BYTE alpha
, DWORD flags
)
3484 TRACE("(%p,%08x,%d,%x): stub!\n", hwnd
, key
, alpha
, flags
);
3486 SERVER_START_REQ( set_window_layered_info
)
3488 req
->handle
= wine_server_user_handle( hwnd
);
3489 req
->color_key
= key
;
3492 ret
= !wine_server_call_err( req
);
3496 if (ret
) USER_Driver
->pSetLayeredWindowAttributes( hwnd
, key
, alpha
, flags
);
3502 /*****************************************************************************
3503 * GetLayeredWindowAttributes (USER32.@)
3505 BOOL WINAPI
GetLayeredWindowAttributes( HWND hwnd
, COLORREF
*key
, BYTE
*alpha
, DWORD
*flags
)
3509 SERVER_START_REQ( get_window_layered_info
)
3511 req
->handle
= wine_server_user_handle( hwnd
);
3512 if ((ret
= !wine_server_call_err( req
)))
3514 if (key
) *key
= reply
->color_key
;
3515 if (alpha
) *alpha
= reply
->alpha
;
3516 if (flags
) *flags
= reply
->flags
;
3525 /*****************************************************************************
3526 * UpdateLayeredWindowIndirect (USER32.@)
3528 BOOL WINAPI
UpdateLayeredWindowIndirect( HWND hwnd
, const UPDATELAYEREDWINDOWINFO
*info
)
3532 if (!(info
->dwFlags
& ULW_EX_NORESIZE
) && (info
->pptDst
|| info
->psize
))
3534 int x
= 0, y
= 0, cx
= 0, cy
= 0;
3535 DWORD flags
= SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_NOREDRAW
| SWP_NOSENDCHANGING
;
3539 x
= info
->pptDst
->x
;
3540 y
= info
->pptDst
->y
;
3541 flags
&= ~SWP_NOMOVE
;
3545 cx
= info
->psize
->cx
;
3546 cy
= info
->psize
->cy
;
3547 flags
&= ~SWP_NOSIZE
;
3549 TRACE( "moving window %p pos %d,%d %dx%x\n", hwnd
, x
, y
, cx
, cy
);
3550 SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
3556 HDC hdc
= GetDCEx( hwnd
, 0, DCX_CACHE
);
3562 GetClientRect( hwnd
, &rect
);
3565 x
= info
->pptSrc
->x
;
3566 y
= info
->pptSrc
->y
;
3568 /* FIXME: intersect rect with info->prcDirty */
3569 TRACE( "copying window %p pos %d,%d\n", hwnd
, x
, y
);
3570 BitBlt( hdc
, rect
.left
, rect
.top
, rect
.right
, rect
.bottom
,
3571 info
->hdcSrc
, rect
.left
+ x
, rect
.top
+ y
, SRCCOPY
);
3572 ReleaseDC( hwnd
, hdc
);
3576 if (info
->pblend
&& !(info
->dwFlags
& ULW_OPAQUE
)) alpha
= info
->pblend
->SourceConstantAlpha
;
3577 TRACE( "setting window %p alpha %u\n", hwnd
, alpha
);
3578 USER_Driver
->pSetLayeredWindowAttributes( hwnd
, info
->crKey
, alpha
,
3579 info
->dwFlags
& (LWA_ALPHA
| LWA_COLORKEY
) );
3584 /*****************************************************************************
3585 * UpdateLayeredWindow (USER32.@)
3587 BOOL WINAPI
UpdateLayeredWindow( HWND hwnd
, HDC hdcDst
, POINT
*pptDst
, SIZE
*psize
,
3588 HDC hdcSrc
, POINT
*pptSrc
, COLORREF crKey
, BLENDFUNCTION
*pblend
,
3591 UPDATELAYEREDWINDOWINFO info
;
3593 info
.cbSize
= sizeof(info
);
3594 info
.hdcDst
= hdcDst
;
3595 info
.pptDst
= pptDst
;
3597 info
.hdcSrc
= hdcSrc
;
3598 info
.pptSrc
= pptSrc
;
3600 info
.pblend
= pblend
;
3601 info
.dwFlags
= dwFlags
;
3602 info
.prcDirty
= NULL
;
3603 return UpdateLayeredWindowIndirect( hwnd
, &info
);
3606 /* 64bit versions */
3608 #ifdef GetWindowLongPtrW
3609 #undef GetWindowLongPtrW
3612 #ifdef GetWindowLongPtrA
3613 #undef GetWindowLongPtrA
3616 #ifdef SetWindowLongPtrW
3617 #undef SetWindowLongPtrW
3620 #ifdef SetWindowLongPtrA
3621 #undef SetWindowLongPtrA
3624 /*****************************************************************************
3625 * GetWindowLongPtrW (USER32.@)
3627 LONG_PTR WINAPI
GetWindowLongPtrW( HWND hwnd
, INT offset
)
3629 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), TRUE
);
3632 /*****************************************************************************
3633 * GetWindowLongPtrA (USER32.@)
3635 LONG_PTR WINAPI
GetWindowLongPtrA( HWND hwnd
, INT offset
)
3637 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), FALSE
);
3640 /*****************************************************************************
3641 * SetWindowLongPtrW (USER32.@)
3643 LONG_PTR WINAPI
SetWindowLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
3645 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, TRUE
);
3648 /*****************************************************************************
3649 * SetWindowLongPtrA (USER32.@)
3651 LONG_PTR WINAPI
SetWindowLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
3653 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, FALSE
);