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"
37 #include "user_private.h"
40 #include "wine/debug.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(win
);
44 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
45 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
47 /**********************************************************************/
49 /* helper for Get/SetWindowLong */
50 static inline LONG_PTR
get_win_data( const void *ptr
, UINT size
)
52 if (size
== sizeof(WORD
))
55 memcpy( &ret
, ptr
, sizeof(ret
) );
58 else if (size
== sizeof(DWORD
))
61 memcpy( &ret
, ptr
, sizeof(ret
) );
67 memcpy( &ret
, ptr
, sizeof(ret
) );
72 /* helper for Get/SetWindowLong */
73 static inline void set_win_data( void *ptr
, LONG_PTR val
, UINT size
)
75 if (size
== sizeof(WORD
))
78 memcpy( ptr
, &newval
, sizeof(newval
) );
80 else if (size
== sizeof(DWORD
))
83 memcpy( ptr
, &newval
, sizeof(newval
) );
87 memcpy( ptr
, &val
, sizeof(val
) );
92 static void *user_handles
[NB_USER_HANDLES
];
94 /***********************************************************************
95 * create_window_handle
97 * Create a window handle with the server.
99 static WND
*create_window_handle( HWND parent
, HWND owner
, ATOM atom
,
100 HINSTANCE instance
, BOOL unicode
)
104 HWND full_parent
= 0, full_owner
= 0;
105 struct tagCLASS
*class = NULL
;
106 user_handle_t handle
= 0;
109 /* if 16-bit instance, map to module handle */
110 if (instance
&& !HIWORD(instance
))
111 instance
= HINSTANCE_32(GetExePtr(HINSTANCE_16(instance
)));
113 SERVER_START_REQ( create_window
)
115 req
->parent
= parent
;
118 req
->instance
= instance
;
119 if (!wine_server_call_err( req
))
121 handle
= reply
->handle
;
122 full_parent
= reply
->parent
;
123 full_owner
= reply
->owner
;
124 extra_bytes
= reply
->extra
;
125 class = reply
->class_ptr
;
132 WARN( "error %d creating window\n", GetLastError() );
136 if (!(win
= HeapAlloc( GetProcessHeap(), 0, sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
138 SERVER_START_REQ( destroy_window
)
140 req
->handle
= handle
;
141 wine_server_call( req
);
144 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
148 if (!parent
) /* if parent is 0 we don't have a desktop window yet */
150 struct user_thread_info
*thread_info
= get_user_thread_info();
152 assert( !thread_info
->desktop
);
153 thread_info
->desktop
= full_parent
? full_parent
: handle
;
154 if (full_parent
&& !USER_Driver
->pCreateDesktopWindow( thread_info
->desktop
))
155 ERR( "failed to create desktop window\n" );
160 index
= USER_HANDLE_TO_INDEX(handle
);
161 assert( index
< NB_USER_HANDLES
);
162 user_handles
[index
] = win
;
163 win
->hwndSelf
= handle
;
164 win
->parent
= full_parent
;
165 win
->owner
= full_owner
;
166 win
->dwMagic
= WND_MAGIC
;
168 win
->cbWndExtra
= extra_bytes
;
169 memset( win
->wExtra
, 0, extra_bytes
);
170 CLASS_AddWindow( class, win
, unicode
);
175 /***********************************************************************
178 * Free a window handle.
180 static WND
*free_window_handle( HWND hwnd
)
183 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
185 if (index
>= NB_USER_HANDLES
) return NULL
;
187 if ((ptr
= user_handles
[index
]))
189 SERVER_START_REQ( destroy_window
)
192 if (!wine_server_call_err( req
))
194 user_handles
[index
] = NULL
;
203 HeapFree( GetProcessHeap(), 0, ptr
);
208 /*******************************************************************
209 * list_window_children
211 * Build an array of the children of a given window. The array must be
212 * freed with HeapFree. Returns NULL when no windows are found.
214 static HWND
*list_window_children( HWND hwnd
, ATOM atom
, DWORD tid
)
223 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
225 SERVER_START_REQ( get_window_children
)
230 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
231 if (!wine_server_call( req
)) count
= reply
->count
;
234 if (count
&& count
< size
)
239 HeapFree( GetProcessHeap(), 0, list
);
241 size
= count
+ 1; /* restart with a large enough buffer */
247 /*******************************************************************
248 * list_window_parents
250 * Build an array of all parents of a given window, starting with
251 * the immediate parent. The array must be freed with HeapFree.
253 static HWND
*list_window_parents( HWND hwnd
)
257 int pos
= 0, size
= 16, count
= 0;
259 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
264 if (!(win
= WIN_GetPtr( current
))) goto empty
;
265 if (win
== WND_OTHER_PROCESS
) break; /* need to do it the hard way */
266 if (win
== WND_DESKTOP
)
268 if (!pos
) goto empty
;
272 list
[pos
] = current
= win
->parent
;
273 WIN_ReleasePtr( win
);
274 if (++pos
== size
- 1)
276 /* need to grow the list */
277 HWND
*new_list
= HeapReAlloc( GetProcessHeap(), 0, list
, (size
+16) * sizeof(HWND
) );
278 if (!new_list
) goto empty
;
284 /* at least one parent belongs to another process, have to query the server */
289 SERVER_START_REQ( get_window_parents
)
292 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
293 if (!wine_server_call( req
)) count
= reply
->count
;
296 if (!count
) goto empty
;
302 HeapFree( GetProcessHeap(), 0, list
);
304 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
308 HeapFree( GetProcessHeap(), 0, list
);
313 /*******************************************************************
316 static void send_parent_notify( HWND hwnd
, UINT msg
)
318 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
319 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
))
321 HWND parent
= GetParent(hwnd
);
322 if (parent
&& parent
!= GetDesktopWindow())
323 SendMessageW( parent
, WM_PARENTNOTIFY
,
324 MAKEWPARAM( msg
, GetWindowLongPtrW( hwnd
, GWLP_ID
)), (LPARAM
)hwnd
);
329 /*******************************************************************
330 * get_server_window_text
332 * Retrieve the window text from the server.
334 static void get_server_window_text( HWND hwnd
, LPWSTR text
, INT count
)
338 SERVER_START_REQ( get_window_text
)
341 wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
342 if (!wine_server_call_err( req
)) len
= wine_server_reply_size(reply
);
345 text
[len
/ sizeof(WCHAR
)] = 0;
349 /***********************************************************************
352 * Return a pointer to the WND structure if local to the process,
353 * or WND_OTHER_PROCESS if handle may be valid in other process.
354 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
356 WND
*WIN_GetPtr( HWND hwnd
)
359 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
361 if (index
>= NB_USER_HANDLES
) return NULL
;
364 if ((ptr
= user_handles
[index
]))
366 if (ptr
->dwMagic
== WND_MAGIC
&&
367 (hwnd
== ptr
->hwndSelf
|| !HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff))
371 else if (index
== USER_HANDLE_TO_INDEX(GetDesktopWindow()))
373 if (hwnd
== GetDesktopWindow() || !HIWORD(hwnd
) || HIWORD(hwnd
) == 0xffff) ptr
= WND_DESKTOP
;
376 else ptr
= WND_OTHER_PROCESS
;
382 /***********************************************************************
383 * WIN_IsCurrentProcess
385 * Check whether a given window belongs to the current process (and return the full handle).
387 HWND
WIN_IsCurrentProcess( HWND hwnd
)
392 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
394 WIN_ReleasePtr( ptr
);
399 /***********************************************************************
400 * WIN_IsCurrentThread
402 * Check whether a given window belongs to the current thread (and return the full handle).
404 HWND
WIN_IsCurrentThread( HWND hwnd
)
409 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
410 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->hwndSelf
;
411 WIN_ReleasePtr( ptr
);
416 /***********************************************************************
419 * Convert a 16-bit window handle to a full 32-bit handle.
421 HWND
WIN_Handle32( HWND16 hwnd16
)
424 HWND hwnd
= (HWND
)(ULONG_PTR
)hwnd16
;
426 if (hwnd16
<= 1 || hwnd16
== 0xffff) return hwnd
;
427 /* do sign extension for -2 and -3 */
428 if (hwnd16
>= (HWND16
)-3) return (HWND
)(LONG_PTR
)(INT16
)hwnd16
;
430 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
432 if (ptr
== WND_DESKTOP
) return GetDesktopWindow();
434 if (ptr
!= WND_OTHER_PROCESS
)
436 hwnd
= ptr
->hwndSelf
;
437 WIN_ReleasePtr( ptr
);
439 else /* may belong to another process */
441 SERVER_START_REQ( get_window_info
)
444 if (!wine_server_call_err( req
)) hwnd
= reply
->full_handle
;
452 /***********************************************************************
455 * Change the owner of a window.
457 HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
459 WND
*win
= WIN_GetPtr( hwnd
);
462 if (!win
|| win
== WND_DESKTOP
) return 0;
463 if (win
== WND_OTHER_PROCESS
)
465 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
468 SERVER_START_REQ( set_window_owner
)
472 if (!wine_server_call( req
))
474 win
->owner
= reply
->full_owner
;
475 ret
= reply
->prev_owner
;
479 WIN_ReleasePtr( win
);
484 /***********************************************************************
487 * Change the style of a window.
489 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
492 ULONG new_style
, old_style
= 0;
493 WND
*win
= WIN_GetPtr( hwnd
);
495 if (!win
|| win
== WND_DESKTOP
) return 0;
496 if (win
== WND_OTHER_PROCESS
)
499 ERR( "cannot set style %x/%x on other process window %p\n",
500 set_bits
, clear_bits
, hwnd
);
503 new_style
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
504 if (new_style
== win
->dwStyle
)
506 WIN_ReleasePtr( win
);
509 SERVER_START_REQ( set_window_info
)
512 req
->flags
= SET_WIN_STYLE
;
513 req
->style
= new_style
;
514 req
->extra_offset
= -1;
515 if ((ok
= !wine_server_call( req
)))
517 old_style
= reply
->old_style
;
518 win
->dwStyle
= new_style
;
522 WIN_ReleasePtr( win
);
523 if (ok
) USER_Driver
->pSetWindowStyle( hwnd
, old_style
);
528 /***********************************************************************
531 * Get the window and client rectangles.
533 BOOL
WIN_GetRectangles( HWND hwnd
, RECT
*rectWindow
, RECT
*rectClient
)
535 WND
*win
= WIN_GetPtr( hwnd
);
538 if (!win
) return FALSE
;
539 if (win
== WND_DESKTOP
)
542 rect
.left
= rect
.top
= 0;
543 rect
.right
= GetSystemMetrics(SM_CXSCREEN
);
544 rect
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
545 if (rectWindow
) *rectWindow
= rect
;
546 if (rectClient
) *rectClient
= rect
;
548 else if (win
== WND_OTHER_PROCESS
)
550 SERVER_START_REQ( get_window_rectangles
)
553 if ((ret
= !wine_server_call( req
)))
557 rectWindow
->left
= reply
->window
.left
;
558 rectWindow
->top
= reply
->window
.top
;
559 rectWindow
->right
= reply
->window
.right
;
560 rectWindow
->bottom
= reply
->window
.bottom
;
564 rectClient
->left
= reply
->client
.left
;
565 rectClient
->top
= reply
->client
.top
;
566 rectClient
->right
= reply
->client
.right
;
567 rectClient
->bottom
= reply
->client
.bottom
;
575 if (rectWindow
) *rectWindow
= win
->rectWindow
;
576 if (rectClient
) *rectClient
= win
->rectClient
;
577 WIN_ReleasePtr( win
);
583 /***********************************************************************
586 * Destroy storage associated to a window. "Internals" p.358
588 LRESULT
WIN_DestroyWindow( HWND hwnd
)
592 HMENU menu
= 0, sys_menu
;
594 TRACE("%p\n", hwnd
);
596 /* free child windows */
597 if ((list
= WIN_ListChildren( hwnd
)))
600 for (i
= 0; list
[i
]; i
++)
602 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
603 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
605 HeapFree( GetProcessHeap(), 0, list
);
608 /* Unlink now so we won't bother with the children later on */
609 SERVER_START_REQ( set_parent
)
613 wine_server_call( req
);
618 * Send the WM_NCDESTROY to the window being destroyed.
620 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
622 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
624 WINPOS_CheckInternalPos( hwnd
);
626 /* free resources associated with the window */
628 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
629 if (!(wndPtr
->dwStyle
& WS_CHILD
)) menu
= (HMENU
)wndPtr
->wIDmenu
;
630 sys_menu
= wndPtr
->hSysMenu
;
631 WIN_ReleasePtr( wndPtr
);
633 if (menu
) DestroyMenu( menu
);
634 if (sys_menu
) DestroyMenu( sys_menu
);
636 USER_Driver
->pDestroyWindow( hwnd
);
638 free_window_handle( hwnd
);
642 /***********************************************************************
643 * WIN_DestroyThreadWindows
645 * Destroy all children of 'wnd' owned by the current thread.
647 void WIN_DestroyThreadWindows( HWND hwnd
)
652 if (!(list
= WIN_ListChildren( hwnd
))) return;
653 for (i
= 0; list
[i
]; i
++)
655 if (WIN_IsCurrentThread( list
[i
] ))
656 DestroyWindow( list
[i
] );
658 WIN_DestroyThreadWindows( list
[i
] );
660 HeapFree( GetProcessHeap(), 0, list
);
664 /***********************************************************************
667 * Fix the coordinates - Helper for WIN_CreateWindowEx.
668 * returns default show mode in sw.
670 static void WIN_FixCoordinates( CREATESTRUCTA
*cs
, INT
*sw
)
672 #define IS_DEFAULT(x) ((x) == CW_USEDEFAULT || (x) == CW_USEDEFAULT16)
675 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
679 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
680 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= (HMENU
)id
;
682 TRACE("MDI child id %04x\n", id
);
685 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
687 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
689 if (IS_DEFAULT(cs
->x
))
694 if (IS_DEFAULT(cs
->cx
) || !cs
->cx
) cs
->cx
= pos
[1].x
;
695 if (IS_DEFAULT(cs
->cy
) || !cs
->cy
) cs
->cy
= pos
[1].y
;
699 if (IS_DEFAULT(cs
->x
)) cs
->x
= cs
->y
= 0;
700 if (IS_DEFAULT(cs
->cx
)) cs
->cx
= cs
->cy
= 0;
703 else /* overlapped window */
706 MONITORINFO mon_info
;
709 if (!IS_DEFAULT(cs
->x
) && !IS_DEFAULT(cs
->cx
) && !IS_DEFAULT(cs
->cy
)) return;
711 monitor
= MonitorFromWindow( cs
->hwndParent
, MONITOR_DEFAULTTOPRIMARY
);
712 mon_info
.cbSize
= sizeof(mon_info
);
713 GetMonitorInfoW( monitor
, &mon_info
);
714 GetStartupInfoW( &info
);
716 if (IS_DEFAULT(cs
->x
))
718 if (!IS_DEFAULT(cs
->y
)) *sw
= cs
->y
;
719 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: mon_info
.rcWork
.left
;
720 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: mon_info
.rcWork
.top
;
723 if (IS_DEFAULT(cs
->cx
))
725 if (info
.dwFlags
& STARTF_USESIZE
)
727 cs
->cx
= info
.dwXSize
;
728 cs
->cy
= info
.dwYSize
;
732 cs
->cx
= (mon_info
.rcWork
.right
- mon_info
.rcWork
.left
) * 3 / 4 - cs
->x
;
733 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
736 /* neither x nor cx are default. Check the y values .
737 * In the trace we see Outlook and Outlook Express using
738 * cy set to CW_USEDEFAULT when opening the address book.
740 else if (IS_DEFAULT(cs
->cy
))
742 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
743 cs
->cy
= (mon_info
.rcWork
.bottom
- mon_info
.rcWork
.top
) * 3 / 4 - cs
->y
;
749 /***********************************************************************
752 static void dump_window_styles( DWORD style
, DWORD exstyle
)
755 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
756 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
757 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
758 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
759 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
760 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
761 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
762 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
763 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
766 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
767 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
769 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
770 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
771 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
772 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
773 if (style
& WS_CHILD
)
775 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
776 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
780 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
781 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
784 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
785 #define DUMPED_STYLES \
805 if(style
& ~DUMPED_STYLES
) TRACE(" %08lx", style
& ~DUMPED_STYLES
);
810 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
811 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
812 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
813 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
814 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
815 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
816 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
817 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
818 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
819 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
820 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
821 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
822 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
823 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
824 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
825 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
826 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
827 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
829 #define DUMPED_EX_STYLES \
830 (WS_EX_DLGMODALFRAME | \
832 WS_EX_NOPARENTNOTIFY | \
834 WS_EX_ACCEPTFILES | \
835 WS_EX_TRANSPARENT | \
840 WS_EX_CONTEXTHELP | \
843 WS_EX_LEFTSCROLLBAR | \
844 WS_EX_CONTROLPARENT | \
849 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08lx", exstyle
& ~DUMPED_EX_STYLES
);
851 #undef DUMPED_EX_STYLES
855 /***********************************************************************
858 * Implementation of CreateWindowEx().
860 static HWND
WIN_CreateWindowEx( CREATESTRUCTA
*cs
, ATOM classAtom
, UINT flags
)
864 HWND hwnd
, parent
, owner
, top_child
= 0;
865 BOOL unicode
= (flags
& WIN_ISUNICODE
) != 0;
866 MDICREATESTRUCTA mdi_cs
;
868 TRACE("%s %s ex=%08x style=%08x %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
869 unicode
? debugstr_w((LPCWSTR
)cs
->lpszName
) : debugstr_a(cs
->lpszName
),
870 unicode
? debugstr_w((LPCWSTR
)cs
->lpszClass
) : debugstr_a(cs
->lpszClass
),
871 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
872 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
873 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
875 /* Fix the styles for MDI children */
876 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
880 wndPtr
= WIN_GetPtr(cs
->hwndParent
);
881 if (wndPtr
&& wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
883 flags
= wndPtr
->flags
;
884 WIN_ReleasePtr(wndPtr
);
887 if (!(flags
& WIN_ISMDICLIENT
))
889 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
893 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
894 * MDICREATESTRUCT members have the originally passed values.
896 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
897 * have the same layout.
899 mdi_cs
.szClass
= cs
->lpszClass
;
900 mdi_cs
.szTitle
= cs
->lpszName
;
901 mdi_cs
.hOwner
= cs
->hInstance
;
906 mdi_cs
.style
= cs
->style
;
907 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
909 cs
->lpCreateParams
= (LPVOID
)&mdi_cs
;
911 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
913 if (cs
->style
& WS_POPUP
)
915 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
918 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
922 cs
->style
&= ~WS_POPUP
;
923 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
924 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
927 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
931 /* Restore current maximized child */
932 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
934 TRACE("Restoring current maximized child %p\n", top_child
);
935 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
936 ShowWindow(top_child
, SW_RESTORE
);
937 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
942 /* Find the parent window */
944 parent
= cs
->hwndParent
;
947 if (cs
->hwndParent
== HWND_MESSAGE
)
949 /* native ole32.OleInitialize uses HWND_MESSAGE to create the
950 * message window (style: WS_POPUP|WS_DISABLED)
952 FIXME("Parent is HWND_MESSAGE\n");
953 parent
= GetDesktopWindow();
955 else if (cs
->hwndParent
)
957 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) != WS_CHILD
)
959 parent
= GetDesktopWindow();
960 owner
= cs
->hwndParent
;
965 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
967 WARN("No parent for child window\n" );
968 SetLastError(ERROR_TLW_WITH_WSCHILD
);
969 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
971 if (classAtom
!= LOWORD(DESKTOP_CLASS_ATOM
)) /* are we creating the desktop itself? */
972 parent
= GetDesktopWindow();
975 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
977 if ((cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
978 ((!(cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
979 (cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
980 cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
982 cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
984 /* Create the window structure */
986 if (!(wndPtr
= create_window_handle( parent
, owner
, classAtom
, cs
->hInstance
, unicode
)))
988 hwnd
= wndPtr
->hwndSelf
;
990 /* Fill the window structure */
992 wndPtr
->tid
= GetCurrentThreadId();
993 wndPtr
->hInstance
= cs
->hInstance
;
995 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
996 wndPtr
->dwExStyle
= cs
->dwExStyle
;
998 wndPtr
->helpContext
= 0;
999 wndPtr
->pVScroll
= NULL
;
1000 wndPtr
->pHScroll
= NULL
;
1001 wndPtr
->userdata
= 0;
1003 wndPtr
->hIconSmall
= 0;
1004 wndPtr
->hSysMenu
= 0;
1005 wndPtr
->flags
|= (flags
& WIN_ISWIN32
);
1007 if (wndPtr
->dwStyle
& WS_SYSMENU
) SetSystemMenu( hwnd
, 0 );
1010 * Correct the window styles.
1012 * It affects only the style loaded into the WIN structure.
1015 if (!(wndPtr
->dwStyle
& WS_CHILD
))
1017 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1018 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1019 wndPtr
->dwStyle
|= WS_CAPTION
;
1023 * WS_EX_WINDOWEDGE appears to be enforced based on the other styles, so
1024 * why does the user get to set it?
1027 if ((wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1028 (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1029 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1031 wndPtr
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1033 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1034 wndPtr
->flags
|= WIN_NEED_SIZE
;
1036 SERVER_START_REQ( set_window_info
)
1039 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
| SET_WIN_UNICODE
;
1040 req
->style
= wndPtr
->dwStyle
;
1041 req
->ex_style
= wndPtr
->dwExStyle
;
1042 req
->instance
= (void *)wndPtr
->hInstance
;
1043 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1044 req
->extra_offset
= -1;
1045 wine_server_call( req
);
1049 /* Set the window menu */
1051 if (!(wndPtr
->dwStyle
& WS_CHILD
))
1055 if (!MENU_SetMenu(hwnd
, cs
->hMenu
))
1057 WIN_ReleasePtr( wndPtr
);
1058 free_window_handle( hwnd
);
1064 LPCSTR menuName
= (LPCSTR
)GetClassLongPtrA( hwnd
, GCLP_MENUNAME
);
1067 if (!cs
->hInstance
|| HIWORD(cs
->hInstance
))
1068 cs
->hMenu
= LoadMenuA(cs
->hInstance
,menuName
);
1070 cs
->hMenu
= HMENU_32(LoadMenu16(HINSTANCE_16(cs
->hInstance
),menuName
));
1072 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1076 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1077 WIN_ReleasePtr( wndPtr
);
1079 if (!USER_Driver
->pCreateWindow( hwnd
, cs
, unicode
))
1081 WIN_DestroyWindow( hwnd
);
1085 /* Notify the parent window only */
1087 send_parent_notify( hwnd
, WM_CREATE
);
1088 if (!IsWindow( hwnd
)) return 0;
1090 if (cs
->style
& WS_VISIBLE
)
1092 if (cs
->style
& WS_MAXIMIZE
)
1094 else if (cs
->style
& WS_MINIMIZE
)
1095 sw
= SW_SHOWMINIMIZED
;
1097 ShowWindow( hwnd
, sw
);
1098 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1100 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1101 /* ShowWindow won't activate child windows */
1102 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1106 /* Call WH_SHELL hook */
1108 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1109 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1111 TRACE("created window %p\n", hwnd
);
1116 /***********************************************************************
1117 * CreateWindow (USER.41)
1119 HWND16 WINAPI
CreateWindow16( LPCSTR className
, LPCSTR windowName
,
1120 DWORD style
, INT16 x
, INT16 y
, INT16 width
,
1121 INT16 height
, HWND16 parent
, HMENU16 menu
,
1122 HINSTANCE16 instance
, LPVOID data
)
1124 return CreateWindowEx16( 0, className
, windowName
, style
,
1125 x
, y
, width
, height
, parent
, menu
, instance
, data
);
1129 /***********************************************************************
1130 * CreateWindowEx (USER.452)
1132 HWND16 WINAPI
CreateWindowEx16( DWORD exStyle
, LPCSTR className
,
1133 LPCSTR windowName
, DWORD style
, INT16 x
,
1134 INT16 y
, INT16 width
, INT16 height
,
1135 HWND16 parent
, HMENU16 menu
,
1136 HINSTANCE16 instance
, LPVOID data
)
1142 /* Find the class atom */
1144 if (HIWORD(className
))
1146 if (!(classAtom
= GlobalFindAtomA( className
)))
1148 ERR( "bad class name %s\n", debugstr_a(className
) );
1154 classAtom
= LOWORD(className
);
1155 if (!GlobalGetAtomNameA( classAtom
, buffer
, sizeof(buffer
) ))
1157 ERR( "bad atom %x\n", classAtom
);
1163 /* Fix the coordinates */
1165 cs
.x
= (x
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)x
;
1166 cs
.y
= (y
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)y
;
1167 cs
.cx
= (width
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)width
;
1168 cs
.cy
= (height
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)height
;
1170 /* Create the window */
1172 cs
.lpCreateParams
= data
;
1173 cs
.hInstance
= HINSTANCE_32(instance
);
1174 cs
.hMenu
= HMENU_32(menu
);
1175 cs
.hwndParent
= WIN_Handle32( parent
);
1177 cs
.lpszName
= windowName
;
1178 cs
.lpszClass
= className
;
1179 cs
.dwExStyle
= exStyle
;
1181 return HWND_16( WIN_CreateWindowEx( &cs
, classAtom
, 0 ));
1185 /***********************************************************************
1186 * CreateWindowExA (USER32.@)
1188 HWND WINAPI
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1189 LPCSTR windowName
, DWORD style
, INT x
,
1190 INT y
, INT width
, INT height
,
1191 HWND parent
, HMENU menu
,
1192 HINSTANCE instance
, LPVOID data
)
1198 /* Find the class atom */
1200 if (HIWORD(className
))
1202 if (!(classAtom
= GlobalFindAtomA( className
)))
1204 ERR( "bad class name %s\n", debugstr_a(className
) );
1210 classAtom
= LOWORD(className
);
1211 if (!GlobalGetAtomNameA( classAtom
, buffer
, sizeof(buffer
) ))
1213 ERR( "bad atom %x\n", classAtom
);
1219 /* Create the window */
1221 cs
.lpCreateParams
= data
;
1222 cs
.hInstance
= instance
;
1224 cs
.hwndParent
= parent
;
1230 cs
.lpszName
= windowName
;
1231 cs
.lpszClass
= className
;
1232 cs
.dwExStyle
= exStyle
;
1234 return WIN_CreateWindowEx( &cs
, classAtom
, WIN_ISWIN32
);
1238 /***********************************************************************
1239 * CreateWindowExW (USER32.@)
1241 HWND WINAPI
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1242 LPCWSTR windowName
, DWORD style
, INT x
,
1243 INT y
, INT width
, INT height
,
1244 HWND parent
, HMENU menu
,
1245 HINSTANCE instance
, LPVOID data
)
1251 /* Find the class atom */
1253 if (HIWORD(className
))
1255 if (!(classAtom
= GlobalFindAtomW( className
)))
1257 ERR( "bad class name %s\n", debugstr_w(className
) );
1263 classAtom
= LOWORD(className
);
1264 if (!GlobalGetAtomNameW( classAtom
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1266 ERR( "bad atom %x\n", classAtom
);
1272 /* Create the window */
1274 cs
.lpCreateParams
= data
;
1275 cs
.hInstance
= instance
;
1277 cs
.hwndParent
= parent
;
1283 cs
.lpszName
= windowName
;
1284 cs
.lpszClass
= className
;
1285 cs
.dwExStyle
= exStyle
;
1287 /* Note: we rely on the fact that CREATESTRUCTA and */
1288 /* CREATESTRUCTW have the same layout. */
1289 return WIN_CreateWindowEx( (CREATESTRUCTA
*)&cs
, classAtom
, WIN_ISWIN32
| WIN_ISUNICODE
);
1293 /***********************************************************************
1294 * WIN_SendDestroyMsg
1296 static void WIN_SendDestroyMsg( HWND hwnd
)
1300 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1302 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1303 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1307 * Send the WM_DESTROY to the window.
1309 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1312 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1313 * make sure that the window still exists when we come back.
1320 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1322 for (i
= 0; pWndArray
[i
]; i
++)
1324 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1326 HeapFree( GetProcessHeap(), 0, pWndArray
);
1329 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1333 /***********************************************************************
1334 * DestroyWindow (USER32.@)
1336 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1340 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || (hwnd
== GetDesktopWindow()))
1342 SetLastError( ERROR_ACCESS_DENIED
);
1346 TRACE("(%p)\n", hwnd
);
1350 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
1352 if (MENU_IsMenuActive() == hwnd
)
1355 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
1359 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1360 send_parent_notify( hwnd
, WM_DESTROY
);
1362 else if (!GetWindow( hwnd
, GW_OWNER
))
1364 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1365 /* FIXME: clean up palette - see "Internals" p.352 */
1368 if (!IsWindow(hwnd
)) return TRUE
;
1370 /* Hide the window */
1371 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
1373 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1375 ShowWindow( hwnd
, SW_HIDE
);
1377 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1378 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1381 if (!IsWindow(hwnd
)) return TRUE
;
1383 /* Recursively destroy owned windows */
1390 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1393 for (i
= 0; list
[i
]; i
++)
1395 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1396 if (WIN_IsCurrentThread( list
[i
] ))
1398 DestroyWindow( list
[i
] );
1402 WIN_SetOwner( list
[i
], 0 );
1404 HeapFree( GetProcessHeap(), 0, list
);
1406 if (!got_one
) break;
1410 /* Send destroy messages */
1412 WIN_SendDestroyMsg( hwnd
);
1413 if (!IsWindow( hwnd
)) return TRUE
;
1415 if (GetClipboardOwner() == hwnd
)
1416 CLIPBOARD_ReleaseOwner();
1418 /* Destroy the window storage */
1420 WIN_DestroyWindow( hwnd
);
1425 /***********************************************************************
1426 * CloseWindow (USER32.@)
1428 BOOL WINAPI
CloseWindow( HWND hwnd
)
1430 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
1431 ShowWindow( hwnd
, SW_MINIMIZE
);
1436 /***********************************************************************
1437 * OpenIcon (USER32.@)
1439 BOOL WINAPI
OpenIcon( HWND hwnd
)
1441 if (!IsIconic( hwnd
)) return FALSE
;
1442 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1447 /***********************************************************************
1450 * Implementation of FindWindow() and FindWindowEx().
1452 static HWND
WIN_FindWindow( HWND parent
, HWND child
, ATOM className
, LPCWSTR title
)
1457 WCHAR
*buffer
= NULL
;
1459 if (!parent
) parent
= GetDesktopWindow();
1462 len
= strlenW(title
) + 1; /* one extra char to check for chars beyond the end */
1463 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
1466 if (!(list
= list_window_children( parent
, className
, 0 ))) goto done
;
1470 child
= WIN_GetFullHandle( child
);
1471 while (list
[i
] && list
[i
] != child
) i
++;
1472 if (!list
[i
]) goto done
;
1473 i
++; /* start from next window */
1480 if (GetWindowTextW( list
[i
], buffer
, len
+ 1 ) && !strcmpiW( buffer
, title
)) break;
1487 HeapFree( GetProcessHeap(), 0, list
);
1488 HeapFree( GetProcessHeap(), 0, buffer
);
1494 /***********************************************************************
1495 * FindWindowA (USER32.@)
1497 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
1499 HWND ret
= FindWindowExA( 0, 0, className
, title
);
1500 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1505 /***********************************************************************
1506 * FindWindowExA (USER32.@)
1508 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
,
1509 LPCSTR className
, LPCSTR title
)
1518 /* If the atom doesn't exist, then no class */
1519 /* with this name exists either. */
1520 if (!(atom
= GlobalFindAtomA( className
)))
1522 SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1526 if (!title
) return WIN_FindWindow( parent
, child
, atom
, NULL
);
1528 len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
1529 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
1530 MultiByteToWideChar( CP_ACP
, 0, title
, -1, buffer
, len
);
1531 hwnd
= WIN_FindWindow( parent
, child
, atom
, buffer
);
1532 HeapFree( GetProcessHeap(), 0, buffer
);
1537 /***********************************************************************
1538 * FindWindowExW (USER32.@)
1540 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
,
1541 LPCWSTR className
, LPCWSTR title
)
1547 /* If the atom doesn't exist, then no class */
1548 /* with this name exists either. */
1549 if (!(atom
= GlobalFindAtomW( className
)))
1551 SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1555 return WIN_FindWindow( parent
, child
, atom
, title
);
1559 /***********************************************************************
1560 * FindWindowW (USER32.@)
1562 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
1564 return FindWindowExW( 0, 0, className
, title
);
1568 /**********************************************************************
1569 * GetDesktopWindow (USER32.@)
1571 HWND WINAPI
GetDesktopWindow(void)
1573 struct user_thread_info
*thread_info
= get_user_thread_info();
1575 if (thread_info
->desktop
) return thread_info
->desktop
;
1577 SERVER_START_REQ( get_desktop_window
)
1580 if (!wine_server_call( req
)) thread_info
->desktop
= reply
->handle
;
1584 if (!thread_info
->desktop
)
1586 static const WCHAR command_line
[] = {'\\','e','x','p','l','o','r','e','r','.','e','x','e',' ','/','d','e','s','k','t','o','p',0};
1588 PROCESS_INFORMATION pi
;
1589 WCHAR cmdline
[MAX_PATH
+ sizeof(command_line
)/sizeof(WCHAR
)];
1591 memset( &si
, 0, sizeof(si
) );
1593 GetSystemDirectoryW( cmdline
, MAX_PATH
);
1594 lstrcatW( cmdline
, command_line
);
1595 if (CreateProcessW( NULL
, cmdline
, NULL
, NULL
, FALSE
, DETACHED_PROCESS
,
1596 NULL
, NULL
, &si
, &pi
))
1598 TRACE( "started explorer pid %04x tid %04x\n", pi
.dwProcessId
, pi
.dwThreadId
);
1599 WaitForInputIdle( pi
.hProcess
, 10000 );
1600 CloseHandle( pi
.hThread
);
1601 CloseHandle( pi
.hProcess
);
1604 else WARN( "failed to start explorer, err %d\n", GetLastError() );
1606 SERVER_START_REQ( get_desktop_window
)
1609 if (!wine_server_call( req
)) thread_info
->desktop
= reply
->handle
;
1614 if (!thread_info
->desktop
|| !USER_Driver
->pCreateDesktopWindow( thread_info
->desktop
))
1615 ERR( "failed to create desktop window\n" );
1617 return thread_info
->desktop
;
1621 /*******************************************************************
1622 * EnableWindow (USER32.@)
1624 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
1629 if (is_broadcast(hwnd
))
1631 SetLastError( ERROR_INVALID_PARAMETER
);
1635 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
1636 return SendMessageW( hwnd
, WM_WINE_ENABLEWINDOW
, enable
, 0 );
1640 TRACE("( %p, %d )\n", hwnd
, enable
);
1642 retvalue
= !IsWindowEnabled( hwnd
);
1644 if (enable
&& retvalue
)
1646 WIN_SetStyle( hwnd
, 0, WS_DISABLED
);
1647 SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
1649 else if (!enable
&& !retvalue
)
1653 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0);
1655 WIN_SetStyle( hwnd
, WS_DISABLED
, 0 );
1657 if (hwnd
== GetFocus())
1658 SetFocus( 0 ); /* A disabled window can't have the focus */
1660 capture_wnd
= GetCapture();
1661 if (hwnd
== capture_wnd
|| IsChild(hwnd
, capture_wnd
))
1662 ReleaseCapture(); /* A disabled window can't capture the mouse */
1664 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
1670 /***********************************************************************
1671 * IsWindowEnabled (USER32.@)
1673 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
1675 return !(GetWindowLongW( hWnd
, GWL_STYLE
) & WS_DISABLED
);
1679 /***********************************************************************
1680 * IsWindowUnicode (USER32.@)
1682 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
1685 BOOL retvalue
= FALSE
;
1687 if (!(wndPtr
= WIN_GetPtr(hwnd
))) return FALSE
;
1689 if (wndPtr
== WND_DESKTOP
) return TRUE
;
1691 if (wndPtr
!= WND_OTHER_PROCESS
)
1693 retvalue
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1694 WIN_ReleasePtr( wndPtr
);
1698 SERVER_START_REQ( get_window_info
)
1701 if (!wine_server_call_err( req
)) retvalue
= reply
->is_unicode
;
1709 /**********************************************************************
1712 * Helper function for GetWindowLong().
1714 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, UINT size
, BOOL unicode
)
1716 LONG_PTR retvalue
= 0;
1719 if (offset
== GWLP_HWNDPARENT
)
1721 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1722 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
1723 return (ULONG_PTR
)parent
;
1726 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
1728 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1732 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
1734 if (offset
== GWLP_WNDPROC
)
1736 SetLastError( ERROR_ACCESS_DENIED
);
1739 SERVER_START_REQ( set_window_info
)
1742 req
->flags
= 0; /* don't set anything, just retrieve */
1743 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
1744 req
->extra_size
= (offset
>= 0) ? size
: 0;
1745 if (!wine_server_call_err( req
))
1749 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
1750 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
1751 case GWLP_ID
: retvalue
= reply
->old_id
; break;
1752 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)reply
->old_instance
; break;
1753 case GWLP_USERDATA
: retvalue
= reply
->old_user_data
; break;
1755 if (offset
>= 0) retvalue
= get_win_data( &reply
->old_extra_value
, size
);
1756 else SetLastError( ERROR_INVALID_INDEX
);
1765 /* now we have a valid wndPtr */
1769 if (offset
> (int)(wndPtr
->cbWndExtra
- size
))
1771 WARN("Invalid offset %d\n", offset
);
1772 WIN_ReleasePtr( wndPtr
);
1773 SetLastError( ERROR_INVALID_INDEX
);
1776 retvalue
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
1778 /* Special case for dialog window procedure */
1779 if ((offset
== DWLP_DLGPROC
) && (size
== sizeof(LONG_PTR
)) && (wndPtr
->flags
& WIN_ISDIALOG
))
1780 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, unicode
);
1781 WIN_ReleasePtr( wndPtr
);
1787 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
1788 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
1789 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
1790 case GWLP_ID
: retvalue
= (ULONG_PTR
)wndPtr
->wIDmenu
; break;
1791 case GWLP_WNDPROC
: retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
); break;
1792 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
1794 WARN("Unknown offset %d\n", offset
);
1795 SetLastError( ERROR_INVALID_INDEX
);
1798 WIN_ReleasePtr(wndPtr
);
1803 /**********************************************************************
1806 * Helper function for SetWindowLong().
1808 * 0 is the failure code. However, in the case of failure SetLastError
1809 * must be set to distinguish between a 0 return value and a failure.
1811 LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, UINT size
, LONG_PTR newval
, BOOL unicode
)
1815 LONG_PTR retval
= 0;
1818 TRACE( "%p %d %lx %c\n", hwnd
, offset
, newval
, unicode
? 'W' : 'A' );
1820 if (is_broadcast(hwnd
))
1822 SetLastError( ERROR_INVALID_PARAMETER
);
1826 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
1828 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1831 if (wndPtr
== WND_DESKTOP
)
1833 /* can't change anything on the desktop window */
1834 SetLastError( ERROR_ACCESS_DENIED
);
1837 if (wndPtr
== WND_OTHER_PROCESS
)
1839 if (offset
== GWLP_WNDPROC
)
1841 SetLastError( ERROR_ACCESS_DENIED
);
1844 if (offset
> 32767 || offset
< -32767)
1846 SetLastError( ERROR_INVALID_INDEX
);
1849 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, MAKEWPARAM( offset
, size
), newval
);
1852 /* first some special cases */
1858 offset
== GWL_STYLE
? wndPtr
->dwStyle
: wndPtr
->dwExStyle
;
1859 style
.styleNew
= newval
;
1860 WIN_ReleasePtr( wndPtr
);
1861 SendMessageW( hwnd
, WM_STYLECHANGING
, offset
, (LPARAM
)&style
);
1862 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1863 newval
= style
.styleNew
;
1865 case GWLP_HWNDPARENT
:
1866 if (wndPtr
->parent
== GetDesktopWindow())
1868 WIN_ReleasePtr( wndPtr
);
1869 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
1873 WIN_ReleasePtr( wndPtr
);
1874 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
1879 UINT old_flags
= wndPtr
->flags
;
1880 retval
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, unicode
);
1881 if (unicode
) proc
= WINPROC_AllocProc( NULL
, (WNDPROC
)newval
);
1882 else proc
= WINPROC_AllocProc( (WNDPROC
)newval
, NULL
);
1883 if (proc
) wndPtr
->winproc
= proc
;
1884 if (WINPROC_IsUnicode( proc
, unicode
)) wndPtr
->flags
|= WIN_ISUNICODE
;
1885 else wndPtr
->flags
&= ~WIN_ISUNICODE
;
1886 if (!((old_flags
^ wndPtr
->flags
) & WIN_ISUNICODE
))
1888 WIN_ReleasePtr( wndPtr
);
1891 /* update is_unicode flag on the server side */
1895 case GWLP_HINSTANCE
:
1899 if ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
1900 (size
== sizeof(LONG_PTR
)) && (wndPtr
->flags
& WIN_ISDIALOG
))
1902 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
1903 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, unicode
);
1904 if (unicode
) *ptr
= WINPROC_AllocProc( NULL
, (WNDPROC
)newval
);
1905 else *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, NULL
);
1906 WIN_ReleasePtr( wndPtr
);
1911 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- size
))
1913 WARN("Invalid offset %d\n", offset
);
1914 WIN_ReleasePtr( wndPtr
);
1915 SetLastError( ERROR_INVALID_INDEX
);
1918 else if (get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
) == newval
)
1920 /* already set to the same value */
1921 WIN_ReleasePtr( wndPtr
);
1927 SERVER_START_REQ( set_window_info
)
1930 req
->extra_offset
= -1;
1934 req
->flags
= SET_WIN_STYLE
;
1935 req
->style
= newval
;
1938 req
->flags
= SET_WIN_EXSTYLE
;
1939 req
->ex_style
= newval
;
1942 req
->flags
= SET_WIN_ID
;
1945 case GWLP_HINSTANCE
:
1946 req
->flags
= SET_WIN_INSTANCE
;
1947 req
->instance
= (void *)newval
;
1950 req
->flags
= SET_WIN_UNICODE
;
1951 req
->is_unicode
= (wndPtr
->flags
& WIN_ISUNICODE
) != 0;
1954 req
->flags
= SET_WIN_USERDATA
;
1955 req
->user_data
= newval
;
1958 req
->flags
= SET_WIN_EXTRA
;
1959 req
->extra_offset
= offset
;
1960 req
->extra_size
= size
;
1961 set_win_data( &req
->extra_value
, newval
, size
);
1963 if ((ok
= !wine_server_call_err( req
)))
1968 wndPtr
->dwStyle
= newval
;
1969 retval
= reply
->old_style
;
1972 wndPtr
->dwExStyle
= newval
;
1973 retval
= reply
->old_ex_style
;
1976 wndPtr
->wIDmenu
= newval
;
1977 retval
= reply
->old_id
;
1979 case GWLP_HINSTANCE
:
1980 wndPtr
->hInstance
= (HINSTANCE
)newval
;
1981 retval
= (ULONG_PTR
)reply
->old_instance
;
1986 wndPtr
->userdata
= newval
;
1987 retval
= reply
->old_user_data
;
1990 retval
= get_win_data( (char *)wndPtr
->wExtra
+ offset
, size
);
1991 set_win_data( (char *)wndPtr
->wExtra
+ offset
, newval
, size
);
1997 WIN_ReleasePtr( wndPtr
);
2001 if (offset
== GWL_STYLE
) USER_Driver
->pSetWindowStyle( hwnd
, retval
);
2003 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2004 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2010 /**********************************************************************
2011 * GetWindowLong (USER.135)
2013 LONG WINAPI
GetWindowLong16( HWND16 hwnd
, INT16 offset
)
2017 BOOL is_winproc
= (offset
== GWLP_WNDPROC
);
2021 if (!(wndPtr
= WIN_GetPtr( WIN_Handle32(hwnd
) )))
2023 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2026 if (wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
2028 if (offset
> (int)(wndPtr
->cbWndExtra
- sizeof(LONG
)))
2031 * Some programs try to access last element from 16 bit
2032 * code using illegal offset value. Hopefully this is
2033 * what those programs really expect.
2035 if (wndPtr
->cbWndExtra
>= 4 && offset
== wndPtr
->cbWndExtra
- sizeof(WORD
))
2037 INT offset2
= wndPtr
->cbWndExtra
- sizeof(LONG
);
2038 ERR( "- replaced invalid offset %d with %d\n", offset
, offset2
);
2043 WARN("Invalid offset %d\n", offset
);
2044 WIN_ReleasePtr( wndPtr
);
2045 SetLastError( ERROR_INVALID_INDEX
);
2049 is_winproc
= ((offset
== DWLP_DLGPROC
) && (wndPtr
->flags
& WIN_ISDIALOG
));
2050 WIN_ReleasePtr( wndPtr
);
2053 retvalue
= GetWindowLongA( WIN_Handle32(hwnd
), offset
);
2054 if (is_winproc
) retvalue
= (LONG_PTR
)WINPROC_GetProc16( (WNDPROC
)retvalue
, FALSE
);
2059 /**********************************************************************
2060 * GetWindowWord (USER32.@)
2062 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
2067 case GWLP_HINSTANCE
:
2068 case GWLP_HWNDPARENT
:
2073 WARN("Invalid offset %d\n", offset
);
2074 SetLastError( ERROR_INVALID_INDEX
);
2079 return WIN_GetWindowLong( hwnd
, offset
, sizeof(WORD
), FALSE
);
2083 /**********************************************************************
2084 * GetWindowLongA (USER32.@)
2086 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2088 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), FALSE
);
2092 /**********************************************************************
2093 * GetWindowLongW (USER32.@)
2095 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2097 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG
), TRUE
);
2101 /**********************************************************************
2102 * SetWindowLong (USER.136)
2104 LONG WINAPI
SetWindowLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
2107 BOOL is_winproc
= (offset
== GWLP_WNDPROC
);
2109 if (offset
== DWLP_DLGPROC
)
2111 if (!(wndPtr
= WIN_GetPtr( WIN_Handle32(hwnd
) )))
2113 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2116 if (wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
2118 is_winproc
= ((wndPtr
->cbWndExtra
- sizeof(LONG_PTR
) >= DWLP_DLGPROC
) &&
2119 (wndPtr
->flags
& WIN_ISDIALOG
));
2120 WIN_ReleasePtr( wndPtr
);
2126 WNDPROC new_proc
= WINPROC_AllocProc16( (WNDPROC16
)newval
);
2127 WNDPROC old_proc
= (WNDPROC
)SetWindowLongA( WIN_Handle32(hwnd
), offset
, (LONG_PTR
)new_proc
);
2128 return (LONG
)WINPROC_GetProc16( (WNDPROC
)old_proc
, FALSE
);
2130 else return SetWindowLongA( WIN_Handle32(hwnd
), offset
, newval
);
2134 /**********************************************************************
2135 * SetWindowWord (USER32.@)
2137 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
2142 case GWLP_HINSTANCE
:
2143 case GWLP_HWNDPARENT
:
2148 WARN("Invalid offset %d\n", offset
);
2149 SetLastError( ERROR_INVALID_INDEX
);
2154 return WIN_SetWindowLong( hwnd
, offset
, sizeof(WORD
), newval
, FALSE
);
2158 /**********************************************************************
2159 * SetWindowLongA (USER32.@)
2161 * See SetWindowLongW.
2163 LONG WINAPI
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2165 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, FALSE
);
2169 /**********************************************************************
2170 * SetWindowLongW (USER32.@) Set window attribute
2172 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2173 * value in a window's extra memory.
2175 * The _hwnd_ parameter specifies the window. is the handle to a
2176 * window that has extra memory. The _newval_ parameter contains the
2177 * new attribute or extra memory value. If positive, the _offset_
2178 * parameter is the byte-addressed location in the window's extra
2179 * memory to set. If negative, _offset_ specifies the window
2180 * attribute to set, and should be one of the following values:
2182 * GWL_EXSTYLE The window's extended window style
2184 * GWL_STYLE The window's window style.
2186 * GWLP_WNDPROC Pointer to the window's window procedure.
2188 * GWLP_HINSTANCE The window's pplication instance handle.
2190 * GWLP_ID The window's identifier.
2192 * GWLP_USERDATA The window's user-specified data.
2194 * If the window is a dialog box, the _offset_ parameter can be one of
2195 * the following values:
2197 * DWLP_DLGPROC The address of the window's dialog box procedure.
2199 * DWLP_MSGRESULT The return value of a message
2200 * that the dialog box procedure processed.
2202 * DWLP_USER Application specific information.
2206 * If successful, returns the previous value located at _offset_. Otherwise,
2211 * Extra memory for a window class is specified by a nonzero cbWndExtra
2212 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2213 * time of class creation.
2215 * Using GWL_WNDPROC to set a new window procedure effectively creates
2216 * a window subclass. Use CallWindowProc() in the new windows procedure
2217 * to pass messages to the superclass's window procedure.
2219 * The user data is reserved for use by the application which created
2222 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2223 * instead, call the EnableWindow() function to change the window's
2226 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2227 * SetParent() instead.
2230 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2231 * it sends WM_STYLECHANGING before changing the settings
2232 * and WM_STYLECHANGED afterwards.
2233 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2235 LONG WINAPI
SetWindowLongW(
2236 HWND hwnd
, /* [in] window to alter */
2237 INT offset
, /* [in] offset, in bytes, of location to alter */
2238 LONG newval
/* [in] new value of location */
2240 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG
), newval
, TRUE
);
2244 /*******************************************************************
2245 * GetWindowTextA (USER32.@)
2247 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2251 if (!lpString
) return 0;
2253 if (WIN_IsCurrentProcess( hwnd
))
2254 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2256 /* when window belongs to other process, don't send a message */
2257 if (nMaxCount
<= 0) return 0;
2258 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) ))) return 0;
2259 get_server_window_text( hwnd
, buffer
, nMaxCount
);
2260 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
2261 lpString
[nMaxCount
-1] = 0;
2262 HeapFree( GetProcessHeap(), 0, buffer
);
2263 return strlen(lpString
);
2267 /*******************************************************************
2268 * InternalGetWindowText (USER32.@)
2270 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2274 if (nMaxCount
<= 0) return 0;
2275 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
2276 if (win
== WND_DESKTOP
) lpString
[0] = 0;
2277 else if (win
!= WND_OTHER_PROCESS
)
2279 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
2280 else lpString
[0] = 0;
2281 WIN_ReleasePtr( win
);
2285 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2287 return strlenW(lpString
);
2291 /*******************************************************************
2292 * GetWindowTextW (USER32.@)
2294 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2296 if (!lpString
) return 0;
2298 if (WIN_IsCurrentProcess( hwnd
))
2299 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2301 /* when window belongs to other process, don't send a message */
2302 if (nMaxCount
<= 0) return 0;
2303 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2304 return strlenW(lpString
);
2308 /*******************************************************************
2309 * SetWindowTextA (USER32.@)
2310 * SetWindowText (USER32.@)
2312 BOOL WINAPI
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2314 if (is_broadcast(hwnd
))
2316 SetLastError( ERROR_INVALID_PARAMETER
);
2319 if (!WIN_IsCurrentProcess( hwnd
))
2320 FIXME( "setting text %s of other process window %p should not use SendMessage\n",
2321 debugstr_a(lpString
), hwnd
);
2322 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2326 /*******************************************************************
2327 * SetWindowTextW (USER32.@)
2329 BOOL WINAPI
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2331 if (is_broadcast(hwnd
))
2333 SetLastError( ERROR_INVALID_PARAMETER
);
2336 if (!WIN_IsCurrentProcess( hwnd
))
2337 FIXME( "setting text %s of other process window %p should not use SendMessage\n",
2338 debugstr_w(lpString
), hwnd
);
2339 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2343 /*******************************************************************
2344 * GetWindowTextLengthA (USER32.@)
2346 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2348 return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2351 /*******************************************************************
2352 * GetWindowTextLengthW (USER32.@)
2354 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2356 return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2360 /*******************************************************************
2361 * IsWindow (USER32.@)
2363 BOOL WINAPI
IsWindow( HWND hwnd
)
2368 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
2369 if (ptr
== WND_DESKTOP
) return TRUE
;
2371 if (ptr
!= WND_OTHER_PROCESS
)
2373 WIN_ReleasePtr( ptr
);
2377 /* check other processes */
2378 SERVER_START_REQ( get_window_info
)
2381 ret
= !wine_server_call_err( req
);
2388 /***********************************************************************
2389 * GetWindowThreadProcessId (USER32.@)
2391 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
2396 if (!(ptr
= WIN_GetPtr( hwnd
)))
2398 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2402 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
2404 /* got a valid window */
2406 if (process
) *process
= GetCurrentProcessId();
2407 WIN_ReleasePtr( ptr
);
2411 /* check other processes */
2412 SERVER_START_REQ( get_window_info
)
2415 if (!wine_server_call_err( req
))
2417 tid
= (DWORD
)reply
->tid
;
2418 if (process
) *process
= (DWORD
)reply
->pid
;
2426 /*****************************************************************
2427 * GetParent (USER32.@)
2429 HWND WINAPI
GetParent( HWND hwnd
)
2434 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2436 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2439 if (wndPtr
== WND_DESKTOP
) return 0;
2440 if (wndPtr
== WND_OTHER_PROCESS
)
2442 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2443 if (style
& (WS_POPUP
| WS_CHILD
))
2445 SERVER_START_REQ( get_window_tree
)
2448 if (!wine_server_call_err( req
))
2450 if (style
& WS_POPUP
) retvalue
= reply
->owner
;
2451 else if (style
& WS_CHILD
) retvalue
= reply
->parent
;
2459 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
2460 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
2461 WIN_ReleasePtr( wndPtr
);
2467 /*****************************************************************
2468 * GetAncestor (USER32.@)
2470 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
2473 HWND
*list
, ret
= 0;
2478 if (!(win
= WIN_GetPtr( hwnd
)))
2480 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2483 if (win
== WND_DESKTOP
) return 0;
2484 if (win
!= WND_OTHER_PROCESS
)
2487 WIN_ReleasePtr( win
);
2489 else /* need to query the server */
2491 SERVER_START_REQ( get_window_tree
)
2494 if (!wine_server_call_err( req
)) ret
= reply
->parent
;
2501 if (!(list
= list_window_parents( hwnd
))) return 0;
2503 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
2507 while (list
[count
]) count
++;
2508 ret
= list
[count
- 2]; /* get the one before the desktop */
2510 HeapFree( GetProcessHeap(), 0, list
);
2514 if ((ret
= WIN_GetFullHandle( hwnd
)) == GetDesktopWindow()) return 0;
2517 HWND parent
= GetParent( ret
);
2527 /*****************************************************************
2528 * SetParent (USER32.@)
2530 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
2534 if (is_broadcast(hwnd
) || is_broadcast(parent
))
2536 SetLastError(ERROR_INVALID_PARAMETER
);
2540 if (!parent
) parent
= GetDesktopWindow();
2541 else parent
= WIN_GetFullHandle( parent
);
2543 if (!IsWindow( parent
))
2545 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2549 /* Some applications try to set a child as a parent */
2550 if (IsChild(hwnd
, parent
))
2552 SetLastError( ERROR_INVALID_PARAMETER
);
2556 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
2557 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
2559 return USER_Driver
->pSetParent( full_handle
, parent
);
2563 /*******************************************************************
2564 * IsChild (USER32.@)
2566 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
2568 HWND
*list
= list_window_parents( child
);
2572 if (!list
) return FALSE
;
2573 parent
= WIN_GetFullHandle( parent
);
2574 for (i
= 0; list
[i
]; i
++) if (list
[i
] == parent
) break;
2575 ret
= (list
[i
] != 0);
2576 HeapFree( GetProcessHeap(), 0, list
);
2581 /***********************************************************************
2582 * IsWindowVisible (USER32.@)
2584 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
2590 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
2591 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
2592 if (list
[0] && list
[1]) /* desktop window is considered always visible so we don't check it */
2594 for (i
= 0; list
[i
+1]; i
++)
2595 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
2596 retval
= !list
[i
+1];
2598 HeapFree( GetProcessHeap(), 0, list
);
2603 /***********************************************************************
2604 * WIN_IsWindowDrawable
2606 * hwnd is drawable when it is visible, all parents are not
2607 * minimized, and it is itself not minimized unless we are
2608 * trying to draw its default class icon.
2610 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
2615 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2617 if (!(style
& WS_VISIBLE
)) return FALSE
;
2618 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
2620 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
2621 if (list
[0] && list
[1]) /* desktop window is considered always visible so we don't check it */
2623 for (i
= 0; list
[i
+1]; i
++)
2624 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
2626 retval
= !list
[i
+1];
2628 HeapFree( GetProcessHeap(), 0, list
);
2633 /*******************************************************************
2634 * GetTopWindow (USER32.@)
2636 HWND WINAPI
GetTopWindow( HWND hwnd
)
2638 if (!hwnd
) hwnd
= GetDesktopWindow();
2639 return GetWindow( hwnd
, GW_CHILD
);
2643 /*******************************************************************
2644 * GetWindow (USER32.@)
2646 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
2650 if (rel
== GW_OWNER
) /* this one may be available locally */
2652 WND
*wndPtr
= WIN_GetPtr( hwnd
);
2655 SetLastError( ERROR_INVALID_HANDLE
);
2658 if (wndPtr
== WND_DESKTOP
) return 0;
2659 if (wndPtr
!= WND_OTHER_PROCESS
)
2661 retval
= wndPtr
->owner
;
2662 WIN_ReleasePtr( wndPtr
);
2665 /* else fall through to server call */
2668 SERVER_START_REQ( get_window_tree
)
2671 if (!wine_server_call_err( req
))
2676 retval
= reply
->first_sibling
;
2679 retval
= reply
->last_sibling
;
2682 retval
= reply
->next_sibling
;
2685 retval
= reply
->prev_sibling
;
2688 retval
= reply
->owner
;
2691 retval
= reply
->first_child
;
2701 /*******************************************************************
2702 * ShowOwnedPopups (USER32.@)
2704 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
2708 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
2710 if (!win_array
) return TRUE
;
2712 while (win_array
[count
]) count
++;
2713 while (--count
>= 0)
2715 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
2716 if (!(pWnd
= WIN_GetPtr( win_array
[count
] ))) continue;
2717 if (pWnd
== WND_OTHER_PROCESS
) continue;
2720 if (pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
2722 WIN_ReleasePtr( pWnd
);
2723 /* In Windows, ShowOwnedPopups(TRUE) generates
2724 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
2725 * regardless of the state of the owner
2727 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOWNORMAL
, SW_PARENTOPENING
);
2733 if (pWnd
->dwStyle
& WS_VISIBLE
)
2735 WIN_ReleasePtr( pWnd
);
2736 /* In Windows, ShowOwnedPopups(FALSE) generates
2737 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
2738 * regardless of the state of the owner
2740 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
2744 WIN_ReleasePtr( pWnd
);
2746 HeapFree( GetProcessHeap(), 0, win_array
);
2751 /*******************************************************************
2752 * GetLastActivePopup (USER32.@)
2754 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
2758 SERVER_START_REQ( get_window_info
)
2761 if (!wine_server_call_err( req
)) retval
= reply
->last_active
;
2768 /*******************************************************************
2771 * Build an array of the children of a given window. The array must be
2772 * freed with HeapFree. Returns NULL when no windows are found.
2774 HWND
*WIN_ListChildren( HWND hwnd
)
2776 return list_window_children( hwnd
, 0, 0 );
2780 /*******************************************************************
2781 * EnumWindows (USER32.@)
2783 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
2789 USER_CheckNotLock();
2791 /* We have to build a list of all windows first, to avoid */
2792 /* unpleasant side-effects, for instance if the callback */
2793 /* function changes the Z-order of the windows. */
2795 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
2797 /* Now call the callback function for every window */
2799 for (i
= 0; list
[i
]; i
++)
2801 /* Make sure that the window still exists */
2802 if (!IsWindow( list
[i
] )) continue;
2803 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
2805 HeapFree( GetProcessHeap(), 0, list
);
2810 /**********************************************************************
2811 * EnumThreadWindows (USER32.@)
2813 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
2818 USER_CheckNotLock();
2820 if (!(list
= list_window_children( GetDesktopWindow(), 0, id
))) return TRUE
;
2822 /* Now call the callback function for every window */
2824 for (i
= 0; list
[i
]; i
++)
2825 if (!func( list
[i
], lParam
)) break;
2826 HeapFree( GetProcessHeap(), 0, list
);
2831 /**********************************************************************
2832 * WIN_EnumChildWindows
2834 * Helper function for EnumChildWindows().
2836 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
2841 for ( ; *list
; list
++)
2843 /* Make sure that the window still exists */
2844 if (!IsWindow( *list
)) continue;
2845 /* Build children list first */
2846 childList
= WIN_ListChildren( *list
);
2848 ret
= func( *list
, lParam
);
2852 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
2853 HeapFree( GetProcessHeap(), 0, childList
);
2855 if (!ret
) return FALSE
;
2861 /**********************************************************************
2862 * EnumChildWindows (USER32.@)
2864 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
2869 USER_CheckNotLock();
2871 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
2872 ret
= WIN_EnumChildWindows( list
, func
, lParam
);
2873 HeapFree( GetProcessHeap(), 0, list
);
2878 /*******************************************************************
2879 * AnyPopup (USER.52)
2881 BOOL16 WINAPI
AnyPopup16(void)
2887 /*******************************************************************
2888 * AnyPopup (USER32.@)
2890 BOOL WINAPI
AnyPopup(void)
2894 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
2896 if (!list
) return FALSE
;
2897 for (i
= 0; list
[i
]; i
++)
2899 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
2901 retvalue
= (list
[i
] != 0);
2902 HeapFree( GetProcessHeap(), 0, list
);
2907 /*******************************************************************
2908 * FlashWindow (USER32.@)
2910 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
2914 TRACE("%p\n", hWnd
);
2916 if (IsIconic( hWnd
))
2918 RedrawWindow( hWnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
2920 wndPtr
= WIN_GetPtr(hWnd
);
2921 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
2922 if (bInvert
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
2924 wndPtr
->flags
|= WIN_NCACTIVATED
;
2928 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
2930 WIN_ReleasePtr( wndPtr
);
2937 wndPtr
= WIN_GetPtr(hWnd
);
2938 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
2939 hWnd
= wndPtr
->hwndSelf
; /* make it a full handle */
2941 if (bInvert
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
2942 else wparam
= (hWnd
== GetForegroundWindow());
2944 WIN_ReleasePtr( wndPtr
);
2945 SendMessageW( hWnd
, WM_NCACTIVATE
, wparam
, (LPARAM
)0 );
2950 /*******************************************************************
2951 * FlashWindowEx (USER32.@)
2953 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfwi
)
2955 FIXME("%p\n", pfwi
);
2959 /*******************************************************************
2960 * GetWindowContextHelpId (USER32.@)
2962 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
2965 WND
*wnd
= WIN_GetPtr( hwnd
);
2966 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
2967 if (wnd
== WND_OTHER_PROCESS
)
2969 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
2972 retval
= wnd
->helpContext
;
2973 WIN_ReleasePtr( wnd
);
2978 /*******************************************************************
2979 * SetWindowContextHelpId (USER32.@)
2981 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
2983 WND
*wnd
= WIN_GetPtr( hwnd
);
2984 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
2985 if (wnd
== WND_OTHER_PROCESS
)
2987 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
2990 wnd
->helpContext
= id
;
2991 WIN_ReleasePtr( wnd
);
2996 /*******************************************************************
2997 * DragDetect (USER32.@)
2999 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
3003 WORD wDragWidth
= GetSystemMetrics(SM_CXDRAG
);
3004 WORD wDragHeight
= GetSystemMetrics(SM_CYDRAG
);
3006 rect
.left
= pt
.x
- wDragWidth
;
3007 rect
.right
= pt
.x
+ wDragWidth
;
3009 rect
.top
= pt
.y
- wDragHeight
;
3010 rect
.bottom
= pt
.y
+ wDragHeight
;
3016 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
3018 if( msg
.message
== WM_LBUTTONUP
)
3023 if( msg
.message
== WM_MOUSEMOVE
)
3026 tmp
.x
= (short)LOWORD(msg
.lParam
);
3027 tmp
.y
= (short)HIWORD(msg
.lParam
);
3028 if( !PtInRect( &rect
, tmp
))
3040 /******************************************************************************
3041 * GetWindowModuleFileNameA (USER32.@)
3043 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR lpszFileName
, UINT cchFileNameMax
)
3045 FIXME("GetWindowModuleFileNameA(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3046 hwnd
, lpszFileName
, cchFileNameMax
);
3050 /******************************************************************************
3051 * GetWindowModuleFileNameW (USER32.@)
3053 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR lpszFileName
, UINT cchFileNameMax
)
3055 FIXME("GetWindowModuleFileNameW(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3056 hwnd
, lpszFileName
, cchFileNameMax
);
3060 /******************************************************************************
3061 * GetWindowInfo (USER32.@)
3063 * Note: tests show that Windows doesn't check cbSize of the structure.
3065 BOOL WINAPI
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
3067 if (!pwi
) return FALSE
;
3068 if (!IsWindow(hwnd
)) return FALSE
;
3070 GetWindowRect(hwnd
, &pwi
->rcWindow
);
3071 GetClientRect(hwnd
, &pwi
->rcClient
);
3072 /* translate to screen coordinates */
3073 MapWindowPoints(hwnd
, 0, (LPPOINT
)&pwi
->rcClient
, 2);
3075 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3076 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3077 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
3079 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
3080 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
3082 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
3083 pwi
->wCreatorVersion
= 0x0400;
3088 /******************************************************************************
3089 * SwitchDesktop (USER32.@)
3091 * NOTES: Sets the current input or interactive desktop.
3093 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
3095 FIXME("SwitchDesktop(hwnd %p) stub!\n", hDesktop
);
3099 /*****************************************************************************
3100 * SetLayeredWindowAttributes (USER32.@)
3102 BOOL WINAPI
SetLayeredWindowAttributes( HWND hWnd
, COLORREF rgbKey
,
3103 BYTE bAlpha
, DWORD dwFlags
)
3105 FIXME("(%p,0x%.8x,%d,%d): stub!\n", hWnd
, rgbKey
, bAlpha
, dwFlags
);
3109 /*****************************************************************************
3110 * UpdateLayeredWindow (USER32.@)
3112 BOOL WINAPI
UpdateLayeredWindow( HWND hwnd
, HDC hdcDst
, POINT
*pptDst
, SIZE
*psize
,
3113 HDC hdcSrc
, POINT
*pptSrc
, COLORREF crKey
, BLENDFUNCTION
*pblend
,
3116 FIXME("(%p,%p,%p,%p,%p,%p,0x%08x,%p,%d): stub!\n",
3117 hwnd
, hdcDst
, pptDst
, psize
, hdcSrc
, pptSrc
, crKey
, pblend
, dwFlags
);
3121 /* 64bit versions */
3123 #ifdef GetWindowLongPtrW
3124 #undef GetWindowLongPtrW
3127 #ifdef GetWindowLongPtrA
3128 #undef GetWindowLongPtrA
3131 #ifdef SetWindowLongPtrW
3132 #undef SetWindowLongPtrW
3135 #ifdef SetWindowLongPtrA
3136 #undef SetWindowLongPtrA
3139 /*****************************************************************************
3140 * GetWindowLongPtrW (USER32.@)
3142 LONG_PTR WINAPI
GetWindowLongPtrW( HWND hwnd
, INT offset
)
3144 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), TRUE
);
3147 /*****************************************************************************
3148 * GetWindowLongPtrA (USER32.@)
3150 LONG_PTR WINAPI
GetWindowLongPtrA( HWND hwnd
, INT offset
)
3152 return WIN_GetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), FALSE
);
3155 /*****************************************************************************
3156 * SetWindowLongPtrW (USER32.@)
3158 LONG_PTR WINAPI
SetWindowLongPtrW( HWND hwnd
, INT offset
, LONG_PTR newval
)
3160 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, TRUE
);
3163 /*****************************************************************************
3164 * SetWindowLongPtrA (USER32.@)
3166 LONG_PTR WINAPI
SetWindowLongPtrA( HWND hwnd
, INT offset
, LONG_PTR newval
)
3168 return WIN_SetWindowLong( hwnd
, offset
, sizeof(LONG_PTR
), newval
, FALSE
);