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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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"
38 #include "cursoricon.h"
42 #include "wine/debug.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(win
);
45 WINE_DECLARE_DEBUG_CHANNEL(msg
);
47 #define NB_USER_HANDLES ((LAST_USER_HANDLE - FIRST_USER_HANDLE + 1) >> 1)
48 #define USER_HANDLE_TO_INDEX(hwnd) ((LOWORD(hwnd) - FIRST_USER_HANDLE) >> 1)
50 /**********************************************************************/
53 static HWND hwndDesktop
;
55 static WORD wDragWidth
= 4;
56 static WORD wDragHeight
= 3;
58 static void *user_handles
[NB_USER_HANDLES
];
60 /***********************************************************************
61 * create_window_handle
63 * Create a window handle with the server.
65 static WND
*create_window_handle( HWND parent
, HWND owner
, ATOM atom
,
66 HINSTANCE instance
, WINDOWPROCTYPE type
)
70 struct tagCLASS
*class = NULL
;
71 user_handle_t handle
= 0;
74 /* if 16-bit instance, map to module handle */
75 if (instance
&& !HIWORD(instance
))
76 instance
= HINSTANCE_32(GetExePtr(HINSTANCE_16(instance
)));
78 SERVER_START_REQ( create_window
)
83 req
->instance
= instance
;
84 if (!wine_server_call_err( req
))
86 handle
= reply
->handle
;
87 extra_bytes
= reply
->extra
;
88 class = reply
->class_ptr
;
95 WARN( "error %ld creating window\n", GetLastError() );
99 if (!(win
= HeapAlloc( GetProcessHeap(), 0, sizeof(WND
) + extra_bytes
- sizeof(win
->wExtra
) )))
101 SERVER_START_REQ( destroy_window
)
103 req
->handle
= handle
;
104 wine_server_call( req
);
107 SetLastError( ERROR_NOT_ENOUGH_MEMORY
);
113 index
= USER_HANDLE_TO_INDEX(handle
);
114 assert( index
< NB_USER_HANDLES
);
115 user_handles
[index
] = win
;
116 win
->hwndSelf
= handle
;
117 win
->dwMagic
= WND_MAGIC
;
118 win
->cbWndExtra
= extra_bytes
;
119 memset( win
->wExtra
, 0, extra_bytes
);
120 CLASS_AddWindow( class, win
, type
);
125 /***********************************************************************
128 * Free a window handle.
130 static WND
*free_window_handle( HWND hwnd
)
133 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
135 if (index
>= NB_USER_HANDLES
) return NULL
;
137 if ((ptr
= user_handles
[index
]))
139 SERVER_START_REQ( destroy_window
)
142 if (!wine_server_call_err( req
))
143 user_handles
[index
] = NULL
;
151 HeapFree( GetProcessHeap(), 0, ptr
);
156 /*******************************************************************
157 * list_window_children
159 * Build an array of the children of a given window. The array must be
160 * freed with HeapFree. Returns NULL when no windows are found.
162 static HWND
*list_window_children( HWND hwnd
, ATOM atom
, DWORD tid
)
171 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
173 SERVER_START_REQ( get_window_children
)
178 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
179 if (!wine_server_call( req
)) count
= reply
->count
;
182 if (count
&& count
< size
)
187 HeapFree( GetProcessHeap(), 0, list
);
189 size
= count
+ 1; /* restart with a large enough buffer */
195 /*******************************************************************
196 * list_window_parents
198 * Build an array of all parents of a given window, starting with
199 * the immediate parent. The array must be freed with HeapFree.
200 * Returns NULL if window is a top-level window.
202 static HWND
*list_window_parents( HWND hwnd
)
206 int pos
= 0, size
= 16, count
= 0;
208 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
213 if (!(win
= WIN_GetPtr( current
))) goto empty
;
214 if (win
== WND_OTHER_PROCESS
) break; /* need to do it the hard way */
215 if (win
== WND_DESKTOP
)
217 if (!pos
) goto empty
;
221 list
[pos
] = current
= win
->parent
;
222 WIN_ReleasePtr( win
);
223 if (++pos
== size
- 1)
225 /* need to grow the list */
226 HWND
*new_list
= HeapReAlloc( GetProcessHeap(), 0, list
, (size
+16) * sizeof(HWND
) );
227 if (!new_list
) goto empty
;
233 /* at least one parent belongs to another process, have to query the server */
238 SERVER_START_REQ( get_window_parents
)
241 wine_server_set_reply( req
, list
, (size
-1) * sizeof(HWND
) );
242 if (!wine_server_call( req
)) count
= reply
->count
;
245 if (!count
) goto empty
;
251 HeapFree( GetProcessHeap(), 0, list
);
253 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) return NULL
;
257 HeapFree( GetProcessHeap(), 0, list
);
262 /*******************************************************************
265 static void send_parent_notify( HWND hwnd
, UINT msg
)
267 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
&&
268 !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_NOPARENTNOTIFY
))
269 SendMessageW( GetParent(hwnd
), WM_PARENTNOTIFY
,
270 MAKEWPARAM( msg
, GetWindowLongPtrW( hwnd
, GWLP_ID
)), (LPARAM
)hwnd
);
274 /*******************************************************************
275 * get_server_window_text
277 * Retrieve the window text from the server.
279 static void get_server_window_text( HWND hwnd
, LPWSTR text
, INT count
)
283 SERVER_START_REQ( get_window_text
)
286 wine_server_set_reply( req
, text
, (count
- 1) * sizeof(WCHAR
) );
287 if (!wine_server_call_err( req
)) len
= wine_server_reply_size(reply
);
290 text
[len
/ sizeof(WCHAR
)] = 0;
294 /***********************************************************************
297 * Return a pointer to the WND structure if local to the process,
298 * or WND_OTHER_PROCESS if handle may be valid in other process.
299 * If ret value is a valid pointer, it must be released with WIN_ReleasePtr.
301 WND
*WIN_GetPtr( HWND hwnd
)
304 WORD index
= USER_HANDLE_TO_INDEX(hwnd
);
306 if (index
>= NB_USER_HANDLES
) return NULL
;
309 if ((ptr
= user_handles
[index
]))
311 if (ptr
->dwMagic
== WND_MAGIC
&& (!HIWORD(hwnd
) || hwnd
== ptr
->hwndSelf
))
315 else if (index
== USER_HANDLE_TO_INDEX(hwndDesktop
))
317 if (!HIWORD(hwnd
) || hwnd
== GetDesktopWindow()) ptr
= WND_DESKTOP
;
320 else ptr
= WND_OTHER_PROCESS
;
326 /***********************************************************************
327 * WIN_IsCurrentProcess
329 * Check whether a given window belongs to the current process (and return the full handle).
331 HWND
WIN_IsCurrentProcess( HWND hwnd
)
336 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
338 WIN_ReleasePtr( ptr
);
343 /***********************************************************************
344 * WIN_IsCurrentThread
346 * Check whether a given window belongs to the current thread (and return the full handle).
348 HWND
WIN_IsCurrentThread( HWND hwnd
)
353 if (!(ptr
= WIN_GetPtr( hwnd
)) || ptr
== WND_OTHER_PROCESS
|| ptr
== WND_DESKTOP
) return 0;
354 if (ptr
->tid
== GetCurrentThreadId()) ret
= ptr
->hwndSelf
;
355 WIN_ReleasePtr( ptr
);
360 /***********************************************************************
363 * Convert a 16-bit window handle to a full 32-bit handle.
365 HWND
WIN_Handle32( HWND16 hwnd16
)
368 HWND hwnd
= (HWND
)(ULONG_PTR
)hwnd16
;
370 if (hwnd16
<= 1 || hwnd16
== 0xffff) return hwnd
;
371 /* do sign extension for -2 and -3 */
372 if (hwnd16
>= (HWND16
)-3) return (HWND
)(LONG_PTR
)(INT16
)hwnd16
;
374 if (!(ptr
= WIN_GetPtr( hwnd
))) return hwnd
;
376 if (ptr
== WND_DESKTOP
) return GetDesktopWindow();
378 if (ptr
!= WND_OTHER_PROCESS
)
380 hwnd
= ptr
->hwndSelf
;
381 WIN_ReleasePtr( ptr
);
383 else /* may belong to another process */
385 SERVER_START_REQ( get_window_info
)
388 if (!wine_server_call_err( req
)) hwnd
= reply
->full_handle
;
396 /***********************************************************************
399 * Change the owner of a window.
401 HWND
WIN_SetOwner( HWND hwnd
, HWND owner
)
403 WND
*win
= WIN_GetPtr( hwnd
);
406 if (!win
|| win
== WND_DESKTOP
) return 0;
407 if (win
== WND_OTHER_PROCESS
)
409 if (IsWindow(hwnd
)) ERR( "cannot set owner %p on other process window %p\n", owner
, hwnd
);
412 SERVER_START_REQ( set_window_owner
)
416 if (!wine_server_call( req
))
418 win
->owner
= reply
->full_owner
;
419 ret
= reply
->prev_owner
;
423 WIN_ReleasePtr( win
);
428 /***********************************************************************
431 * Change the style of a window.
433 ULONG
WIN_SetStyle( HWND hwnd
, ULONG set_bits
, ULONG clear_bits
)
436 ULONG new_style
, old_style
= 0;
437 WND
*win
= WIN_GetPtr( hwnd
);
439 if (!win
|| win
== WND_DESKTOP
) return 0;
440 if (win
== WND_OTHER_PROCESS
)
443 ERR( "cannot set style %lx/%lx on other process window %p\n",
444 set_bits
, clear_bits
, hwnd
);
447 new_style
= (win
->dwStyle
| set_bits
) & ~clear_bits
;
448 if (new_style
== win
->dwStyle
)
450 WIN_ReleasePtr( win
);
453 SERVER_START_REQ( set_window_info
)
456 req
->flags
= SET_WIN_STYLE
;
457 req
->style
= new_style
;
458 req
->extra_offset
= -1;
459 if ((ok
= !wine_server_call( req
)))
461 old_style
= reply
->old_style
;
462 win
->dwStyle
= new_style
;
466 WIN_ReleasePtr( win
);
467 if (ok
&& USER_Driver
.pSetWindowStyle
) USER_Driver
.pSetWindowStyle( hwnd
, old_style
);
472 /***********************************************************************
475 * Get the window and client rectangles.
477 BOOL
WIN_GetRectangles( HWND hwnd
, RECT
*rectWindow
, RECT
*rectClient
)
479 WND
*win
= WIN_GetPtr( hwnd
);
482 if (!win
) return FALSE
;
483 if (win
== WND_DESKTOP
)
486 rect
.left
= rect
.top
= 0;
487 rect
.right
= GetSystemMetrics(SM_CXSCREEN
);
488 rect
.bottom
= GetSystemMetrics(SM_CYSCREEN
);
489 if (rectWindow
) *rectWindow
= rect
;
490 if (rectClient
) *rectClient
= rect
;
492 else if (win
== WND_OTHER_PROCESS
)
494 SERVER_START_REQ( get_window_rectangles
)
497 if ((ret
= !wine_server_call( req
)))
501 rectWindow
->left
= reply
->window
.left
;
502 rectWindow
->top
= reply
->window
.top
;
503 rectWindow
->right
= reply
->window
.right
;
504 rectWindow
->bottom
= reply
->window
.bottom
;
508 rectClient
->left
= reply
->client
.left
;
509 rectClient
->top
= reply
->client
.top
;
510 rectClient
->right
= reply
->client
.right
;
511 rectClient
->bottom
= reply
->client
.bottom
;
519 if (rectWindow
) *rectWindow
= win
->rectWindow
;
520 if (rectClient
) *rectClient
= win
->rectClient
;
521 WIN_ReleasePtr( win
);
527 /***********************************************************************
530 * Destroy storage associated to a window. "Internals" p.358
532 LRESULT
WIN_DestroyWindow( HWND hwnd
)
536 HMENU menu
= 0, sys_menu
;
538 TRACE("%p\n", hwnd
);
540 /* free child windows */
541 if ((list
= WIN_ListChildren( hwnd
)))
544 for (i
= 0; list
[i
]; i
++)
546 if (WIN_IsCurrentThread( list
[i
] )) WIN_DestroyWindow( list
[i
] );
547 else SendMessageW( list
[i
], WM_WINE_DESTROYWINDOW
, 0, 0 );
549 HeapFree( GetProcessHeap(), 0, list
);
552 /* Unlink now so we won't bother with the children later on */
553 SERVER_START_REQ( set_parent
)
557 wine_server_call( req
);
562 * Send the WM_NCDESTROY to the window being destroyed.
564 SendMessageW( hwnd
, WM_NCDESTROY
, 0, 0 );
566 /* FIXME: do we need to fake QS_MOUSEMOVE wakebit? */
568 WINPOS_CheckInternalPos( hwnd
);
570 /* free resources associated with the window */
572 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
573 if (!(wndPtr
->dwStyle
& WS_CHILD
)) menu
= (HMENU
)wndPtr
->wIDmenu
;
574 sys_menu
= wndPtr
->hSysMenu
;
575 WIN_ReleasePtr( wndPtr
);
577 if (menu
) DestroyMenu( menu
);
578 if (sys_menu
) DestroyMenu( sys_menu
);
580 if (USER_Driver
.pDestroyWindow
) USER_Driver
.pDestroyWindow( hwnd
);
582 free_window_handle( hwnd
);
586 /***********************************************************************
587 * WIN_DestroyThreadWindows
589 * Destroy all children of 'wnd' owned by the current thread.
590 * Return TRUE if something was done.
592 void WIN_DestroyThreadWindows( HWND hwnd
)
597 if (!(list
= WIN_ListChildren( hwnd
))) return;
598 for (i
= 0; list
[i
]; i
++)
600 if (WIN_IsCurrentThread( list
[i
] ))
601 DestroyWindow( list
[i
] );
603 WIN_DestroyThreadWindows( list
[i
] );
605 HeapFree( GetProcessHeap(), 0, list
);
608 /***********************************************************************
609 * WIN_CreateDesktopWindow
611 * Create the desktop window.
613 BOOL
WIN_CreateDesktopWindow(void)
617 TRACE("Creating desktop window\n");
619 if (!WINPOS_CreateInternalPosAtom()) return FALSE
;
621 SERVER_START_REQ( create_window
)
625 req
->atom
= LOWORD(DESKTOP_CLASS_ATOM
);
627 if (!wine_server_call_err( req
)) hwndDesktop
= reply
->handle
;
633 ERR( "error %ld creating desktop window\n", GetLastError() );
637 cs
.lpCreateParams
= NULL
;
643 cs
.cx
= GetSystemMetrics( SM_CXSCREEN
);
644 cs
.cy
= GetSystemMetrics( SM_CYSCREEN
);
645 cs
.style
= WS_POPUP
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CLIPCHILDREN
;
648 cs
.lpszClass
= DESKTOP_CLASS_ATOM
;
650 return USER_Driver
.pCreateWindow( hwndDesktop
, &cs
, TRUE
);
654 /***********************************************************************
657 * Fix the coordinates - Helper for WIN_CreateWindowEx.
658 * returns default show mode in sw.
659 * Note: the feature presented as undocumented *is* in the MSDN since 1993.
661 static void WIN_FixCoordinates( CREATESTRUCTA
*cs
, INT
*sw
)
665 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
669 MDI_CalcDefaultChildPos(cs
->hwndParent
, -1, pos
, 0, &id
);
670 if (!(cs
->style
& WS_POPUP
)) cs
->hMenu
= (HMENU
)id
;
672 TRACE("MDI child id %04x\n", id
);
675 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
||
676 cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
)
678 if (cs
->style
& (WS_CHILD
| WS_POPUP
))
680 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
682 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
687 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
|| !cs
->cx
)
689 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
|| !cs
->cy
)
694 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
696 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
)
700 else /* overlapped window */
704 GetStartupInfoW( &info
);
706 if (cs
->x
== CW_USEDEFAULT
|| cs
->x
== CW_USEDEFAULT16
)
708 /* Never believe Microsoft's documentation... CreateWindowEx doc says
709 * that if an overlapped window is created with WS_VISIBLE style bit
710 * set and the x parameter is set to CW_USEDEFAULT, the system ignores
711 * the y parameter. However, disassembling NT implementation (WIN32K.SYS)
714 * 1) not only it checks for CW_USEDEFAULT but also for CW_USEDEFAULT16
715 * 2) it does not ignore the y parameter as the docs claim; instead, it
716 * uses it as second parameter to ShowWindow() unless y is either
717 * CW_USEDEFAULT or CW_USEDEFAULT16.
719 * The fact that we didn't do 2) caused bogus windows pop up when wine
720 * was running apps that were using this obscure feature. Example -
721 * calc.exe that comes with Win98 (only Win98, it's different from
722 * the one that comes with Win95 and NT)
724 if (cs
->y
!= CW_USEDEFAULT
&& cs
->y
!= CW_USEDEFAULT16
) *sw
= cs
->y
;
725 cs
->x
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwX
: 0;
726 cs
->y
= (info
.dwFlags
& STARTF_USEPOSITION
) ? info
.dwY
: 0;
729 if (cs
->cx
== CW_USEDEFAULT
|| cs
->cx
== CW_USEDEFAULT16
)
731 if (info
.dwFlags
& STARTF_USESIZE
)
733 cs
->cx
= info
.dwXSize
;
734 cs
->cy
= info
.dwYSize
;
736 else /* if no other hint from the app, pick 3/4 of the screen real estate */
739 SystemParametersInfoW( SPI_GETWORKAREA
, 0, &r
, 0);
740 cs
->cx
= (((r
.right
- r
.left
) * 3) / 4) - cs
->x
;
741 cs
->cy
= (((r
.bottom
- r
.top
) * 3) / 4) - cs
->y
;
744 /* Handle case where only the cy values is set to default */
745 else if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
)
748 SystemParametersInfoW( SPI_GETWORKAREA
, 0, &r
, 0);
749 cs
->cy
= (((r
.bottom
- r
.top
) * 3) / 4) - cs
->y
;
755 /* neither x nor cx are default. Check the y values .
756 * In the trace we see Outlook and Outlook Express using
757 * cy set to CW_USEDEFAULT when opening the address book.
759 if (cs
->cy
== CW_USEDEFAULT
|| cs
->cy
== CW_USEDEFAULT16
) {
761 FIXME("Strange use of CW_USEDEFAULT in nHeight\n");
762 SystemParametersInfoW( SPI_GETWORKAREA
, 0, &r
, 0);
763 cs
->cy
= (((r
.bottom
- r
.top
) * 3) / 4) - cs
->y
;
768 /***********************************************************************
771 static void dump_window_styles( DWORD style
, DWORD exstyle
)
774 if(style
& WS_POPUP
) TRACE(" WS_POPUP");
775 if(style
& WS_CHILD
) TRACE(" WS_CHILD");
776 if(style
& WS_MINIMIZE
) TRACE(" WS_MINIMIZE");
777 if(style
& WS_VISIBLE
) TRACE(" WS_VISIBLE");
778 if(style
& WS_DISABLED
) TRACE(" WS_DISABLED");
779 if(style
& WS_CLIPSIBLINGS
) TRACE(" WS_CLIPSIBLINGS");
780 if(style
& WS_CLIPCHILDREN
) TRACE(" WS_CLIPCHILDREN");
781 if(style
& WS_MAXIMIZE
) TRACE(" WS_MAXIMIZE");
782 if((style
& WS_CAPTION
) == WS_CAPTION
) TRACE(" WS_CAPTION");
785 if(style
& WS_BORDER
) TRACE(" WS_BORDER");
786 if(style
& WS_DLGFRAME
) TRACE(" WS_DLGFRAME");
788 if(style
& WS_VSCROLL
) TRACE(" WS_VSCROLL");
789 if(style
& WS_HSCROLL
) TRACE(" WS_HSCROLL");
790 if(style
& WS_SYSMENU
) TRACE(" WS_SYSMENU");
791 if(style
& WS_THICKFRAME
) TRACE(" WS_THICKFRAME");
792 if(style
& WS_GROUP
) TRACE(" WS_GROUP");
793 if(style
& WS_TABSTOP
) TRACE(" WS_TABSTOP");
794 if(style
& WS_MINIMIZEBOX
) TRACE(" WS_MINIMIZEBOX");
795 if(style
& WS_MAXIMIZEBOX
) TRACE(" WS_MAXIMIZEBOX");
797 /* FIXME: Add dumping of BS_/ES_/SBS_/LBS_/CBS_/DS_/etc. styles */
798 #define DUMPED_STYLES \
818 if(style
& ~DUMPED_STYLES
) TRACE(" %08lx", style
& ~DUMPED_STYLES
);
823 if(exstyle
& WS_EX_DLGMODALFRAME
) TRACE(" WS_EX_DLGMODALFRAME");
824 if(exstyle
& WS_EX_DRAGDETECT
) TRACE(" WS_EX_DRAGDETECT");
825 if(exstyle
& WS_EX_NOPARENTNOTIFY
) TRACE(" WS_EX_NOPARENTNOTIFY");
826 if(exstyle
& WS_EX_TOPMOST
) TRACE(" WS_EX_TOPMOST");
827 if(exstyle
& WS_EX_ACCEPTFILES
) TRACE(" WS_EX_ACCEPTFILES");
828 if(exstyle
& WS_EX_TRANSPARENT
) TRACE(" WS_EX_TRANSPARENT");
829 if(exstyle
& WS_EX_MDICHILD
) TRACE(" WS_EX_MDICHILD");
830 if(exstyle
& WS_EX_TOOLWINDOW
) TRACE(" WS_EX_TOOLWINDOW");
831 if(exstyle
& WS_EX_WINDOWEDGE
) TRACE(" WS_EX_WINDOWEDGE");
832 if(exstyle
& WS_EX_CLIENTEDGE
) TRACE(" WS_EX_CLIENTEDGE");
833 if(exstyle
& WS_EX_CONTEXTHELP
) TRACE(" WS_EX_CONTEXTHELP");
834 if(exstyle
& WS_EX_RIGHT
) TRACE(" WS_EX_RIGHT");
835 if(exstyle
& WS_EX_RTLREADING
) TRACE(" WS_EX_RTLREADING");
836 if(exstyle
& WS_EX_LEFTSCROLLBAR
) TRACE(" WS_EX_LEFTSCROLLBAR");
837 if(exstyle
& WS_EX_CONTROLPARENT
) TRACE(" WS_EX_CONTROLPARENT");
838 if(exstyle
& WS_EX_STATICEDGE
) TRACE(" WS_EX_STATICEDGE");
839 if(exstyle
& WS_EX_APPWINDOW
) TRACE(" WS_EX_APPWINDOW");
840 if(exstyle
& WS_EX_LAYERED
) TRACE(" WS_EX_LAYERED");
842 #define DUMPED_EX_STYLES \
843 (WS_EX_DLGMODALFRAME | \
845 WS_EX_NOPARENTNOTIFY | \
847 WS_EX_ACCEPTFILES | \
848 WS_EX_TRANSPARENT | \
853 WS_EX_CONTEXTHELP | \
856 WS_EX_LEFTSCROLLBAR | \
857 WS_EX_CONTROLPARENT | \
862 if(exstyle
& ~DUMPED_EX_STYLES
) TRACE(" %08lx", exstyle
& ~DUMPED_EX_STYLES
);
864 #undef DUMPED_EX_STYLES
868 /***********************************************************************
871 * Implementation of CreateWindowEx().
873 static HWND
WIN_CreateWindowEx( CREATESTRUCTA
*cs
, ATOM classAtom
,
874 WINDOWPROCTYPE type
)
878 HWND hwnd
, parent
, owner
, top_child
= 0;
879 BOOL unicode
= (type
== WIN_PROC_32W
);
881 TRACE("%s %s ex=%08lx style=%08lx %d,%d %dx%d parent=%p menu=%p inst=%p params=%p\n",
882 (type
== WIN_PROC_32W
) ? debugstr_w((LPWSTR
)cs
->lpszName
) : debugstr_a(cs
->lpszName
),
883 (type
== WIN_PROC_32W
) ? debugstr_w((LPWSTR
)cs
->lpszClass
) : debugstr_a(cs
->lpszClass
),
884 cs
->dwExStyle
, cs
->style
, cs
->x
, cs
->y
, cs
->cx
, cs
->cy
,
885 cs
->hwndParent
, cs
->hMenu
, cs
->hInstance
, cs
->lpCreateParams
);
887 if(TRACE_ON(win
)) dump_window_styles( cs
->style
, cs
->dwExStyle
);
889 TRACE("winproc type is %d (%s)\n", type
, (type
== WIN_PROC_16
) ? "WIN_PROC_16" :
890 ((type
== WIN_PROC_32A
) ? "WIN_PROC_32A" : "WIN_PROC_32W") );
892 /* Fix the styles for MDI children */
893 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
895 MDICREATESTRUCTA mdi_cs
;
898 wndPtr
= WIN_GetPtr(cs
->hwndParent
);
899 if (wndPtr
&& wndPtr
!= WND_OTHER_PROCESS
&& wndPtr
!= WND_DESKTOP
)
901 flags
= wndPtr
->flags
;
902 WIN_ReleasePtr(wndPtr
);
905 if (!(flags
& WIN_ISMDICLIENT
))
907 WARN("WS_EX_MDICHILD, but parent %p is not MDIClient\n", cs
->hwndParent
);
911 /* cs->lpCreateParams of WM_[NC]CREATE is different for MDI children.
912 * MDICREATESTRUCT members have the originally passed values.
914 * Note: we rely on the fact that MDICREATESTRUCTA and MDICREATESTRUCTW
915 * have the same layout.
917 mdi_cs
.szClass
= cs
->lpszClass
;
918 mdi_cs
.szTitle
= cs
->lpszName
;
919 mdi_cs
.hOwner
= cs
->hInstance
;
924 mdi_cs
.style
= cs
->style
;
925 mdi_cs
.lParam
= (LPARAM
)cs
->lpCreateParams
;
927 cs
->lpCreateParams
= (LPVOID
)&mdi_cs
;
929 if (GetWindowLongW(cs
->hwndParent
, GWL_STYLE
) & MDIS_ALLCHILDSTYLES
)
931 if (cs
->style
& WS_POPUP
)
933 TRACE("WS_POPUP with MDIS_ALLCHILDSTYLES is not allowed\n");
936 cs
->style
|= WS_CHILD
| WS_CLIPSIBLINGS
;
940 cs
->style
&= ~WS_POPUP
;
941 cs
->style
|= WS_CHILD
| WS_VISIBLE
| WS_CLIPSIBLINGS
| WS_CAPTION
|
942 WS_SYSMENU
| WS_THICKFRAME
| WS_MINIMIZEBOX
| WS_MAXIMIZEBOX
;
945 top_child
= GetWindow(cs
->hwndParent
, GW_CHILD
);
949 /* Restore current maximized child */
950 if((cs
->style
& WS_VISIBLE
) && IsZoomed(top_child
))
952 TRACE("Restoring current maximized child %p\n", top_child
);
953 SendMessageW( top_child
, WM_SETREDRAW
, FALSE
, 0 );
954 ShowWindow(top_child
, SW_RESTORE
);
955 SendMessageW( top_child
, WM_SETREDRAW
, TRUE
, 0 );
960 /* Find the parent window */
962 parent
= GetDesktopWindow();
965 if (cs
->hwndParent
== HWND_MESSAGE
)
967 /* native ole32.OleInitialize uses HWND_MESSAGE to create the
968 * message window (style: WS_POPUP|WS_DISABLED)
970 FIXME("Parent is HWND_MESSAGE\n");
972 else if (cs
->hwndParent
)
974 /* Make sure parent is valid */
975 if (!IsWindow( cs
->hwndParent
))
977 WARN("Bad parent %p\n", cs
->hwndParent
);
980 if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
981 parent
= WIN_GetFullHandle(cs
->hwndParent
);
983 owner
= GetAncestor( cs
->hwndParent
, GA_ROOT
);
985 else if ((cs
->style
& (WS_CHILD
|WS_POPUP
)) == WS_CHILD
)
987 WARN("No parent for child window\n" );
988 return 0; /* WS_CHILD needs a parent, but WS_POPUP doesn't */
991 WIN_FixCoordinates(cs
, &sw
); /* fix default coordinates */
993 if ((cs
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
994 ((!(cs
->dwExStyle
& WS_EX_STATICEDGE
)) &&
995 (cs
->style
& (WS_DLGFRAME
| WS_THICKFRAME
))))
996 cs
->dwExStyle
|= WS_EX_WINDOWEDGE
;
998 cs
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1000 /* Create the window structure */
1002 if (!(wndPtr
= create_window_handle( parent
, owner
, classAtom
, cs
->hInstance
, type
)))
1004 TRACE("out of memory\n" );
1007 hwnd
= wndPtr
->hwndSelf
;
1009 /* Fill the window structure */
1011 wndPtr
->tid
= GetCurrentThreadId();
1012 wndPtr
->owner
= owner
;
1013 wndPtr
->parent
= parent
;
1014 wndPtr
->hInstance
= cs
->hInstance
;
1015 wndPtr
->text
= NULL
;
1016 wndPtr
->dwStyle
= cs
->style
& ~WS_VISIBLE
;
1017 wndPtr
->dwExStyle
= cs
->dwExStyle
;
1018 wndPtr
->wIDmenu
= 0;
1019 wndPtr
->helpContext
= 0;
1020 wndPtr
->flags
= (type
== WIN_PROC_16
) ? 0 : WIN_ISWIN32
;
1021 wndPtr
->pVScroll
= NULL
;
1022 wndPtr
->pHScroll
= NULL
;
1023 wndPtr
->userdata
= 0;
1025 wndPtr
->hIconSmall
= 0;
1026 wndPtr
->hSysMenu
= (wndPtr
->dwStyle
& WS_SYSMENU
) ? MENU_GetSysMenu( hwnd
, (HMENU
)-1 ) : 0;
1029 * Correct the window styles.
1031 * It affects only the style loaded into the WIN structure.
1034 if (!(wndPtr
->dwStyle
& WS_CHILD
))
1036 wndPtr
->dwStyle
|= WS_CLIPSIBLINGS
;
1037 if (!(wndPtr
->dwStyle
& WS_POPUP
))
1038 wndPtr
->dwStyle
|= WS_CAPTION
;
1042 * WS_EX_WINDOWEDGE appears to be enforced based on the other styles, so
1043 * why does the user get to set it?
1046 if ((wndPtr
->dwExStyle
& WS_EX_DLGMODALFRAME
) ||
1047 (wndPtr
->dwStyle
& (WS_DLGFRAME
| WS_THICKFRAME
)))
1048 wndPtr
->dwExStyle
|= WS_EX_WINDOWEDGE
;
1050 wndPtr
->dwExStyle
&= ~WS_EX_WINDOWEDGE
;
1052 if (!(wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)))
1053 wndPtr
->flags
|= WIN_NEED_SIZE
;
1055 SERVER_START_REQ( set_window_info
)
1058 req
->flags
= SET_WIN_STYLE
| SET_WIN_EXSTYLE
| SET_WIN_INSTANCE
;
1059 req
->style
= wndPtr
->dwStyle
;
1060 req
->ex_style
= wndPtr
->dwExStyle
;
1061 req
->instance
= (void *)wndPtr
->hInstance
;
1062 req
->extra_offset
= -1;
1063 wine_server_call( req
);
1067 /* Set the window menu */
1069 if (((wndPtr
->dwStyle
& (WS_CAPTION
|WS_CHILD
)) == WS_CAPTION
) ||
1070 (wndPtr
->dwExStyle
& WS_EX_APPWINDOW
))
1072 if (cs
->hMenu
) MENU_SetMenu(hwnd
, cs
->hMenu
);
1075 LPCSTR menuName
= (LPCSTR
)GetClassLongPtrA( hwnd
, GCLP_MENUNAME
);
1078 if (HIWORD(cs
->hInstance
))
1079 cs
->hMenu
= LoadMenuA(cs
->hInstance
,menuName
);
1081 cs
->hMenu
= HMENU_32(LoadMenu16(HINSTANCE_16(cs
->hInstance
),menuName
));
1083 if (cs
->hMenu
) MENU_SetMenu( hwnd
, cs
->hMenu
);
1087 else SetWindowLongPtrW( hwnd
, GWLP_ID
, (ULONG_PTR
)cs
->hMenu
);
1088 WIN_ReleasePtr( wndPtr
);
1090 if (!USER_Driver
.pCreateWindow
|| !USER_Driver
.pCreateWindow( hwnd
, cs
, unicode
))
1092 WIN_DestroyWindow( hwnd
);
1096 /* Notify the parent window only */
1098 send_parent_notify( hwnd
, WM_CREATE
);
1099 if (!IsWindow( hwnd
)) return 0;
1101 if (cs
->style
& WS_VISIBLE
)
1103 if (cs
->style
& WS_MAXIMIZE
)
1104 sw
= SW_SHOWMAXIMIZED
;
1105 else if (cs
->style
& WS_MINIMIZE
)
1106 sw
= SW_SHOWMINIMIZED
;
1108 ShowWindow( hwnd
, sw
);
1109 if (cs
->dwExStyle
& WS_EX_MDICHILD
)
1111 SendMessageW(cs
->hwndParent
, WM_MDIREFRESHMENU
, 0, 0);
1112 /* ShowWindow won't activate child windows */
1113 SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_SHOWWINDOW
| SWP_NOMOVE
| SWP_NOSIZE
);
1117 /* Call WH_SHELL hook */
1119 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) && !GetWindow( hwnd
, GW_OWNER
))
1120 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWCREATED
, (WPARAM
)hwnd
, 0, TRUE
);
1122 TRACE("created window %p\n", hwnd
);
1127 /***********************************************************************
1128 * CreateWindow (USER.41)
1130 HWND16 WINAPI
CreateWindow16( LPCSTR className
, LPCSTR windowName
,
1131 DWORD style
, INT16 x
, INT16 y
, INT16 width
,
1132 INT16 height
, HWND16 parent
, HMENU16 menu
,
1133 HINSTANCE16 instance
, LPVOID data
)
1135 return CreateWindowEx16( 0, className
, windowName
, style
,
1136 x
, y
, width
, height
, parent
, menu
, instance
, data
);
1140 /***********************************************************************
1141 * CreateWindowEx (USER.452)
1143 HWND16 WINAPI
CreateWindowEx16( DWORD exStyle
, LPCSTR className
,
1144 LPCSTR windowName
, DWORD style
, INT16 x
,
1145 INT16 y
, INT16 width
, INT16 height
,
1146 HWND16 parent
, HMENU16 menu
,
1147 HINSTANCE16 instance
, LPVOID data
)
1153 /* Find the class atom */
1155 if (HIWORD(className
))
1157 if (!(classAtom
= GlobalFindAtomA( className
)))
1159 ERR( "bad class name %s\n", debugstr_a(className
) );
1165 classAtom
= LOWORD(className
);
1166 if (!GlobalGetAtomNameA( classAtom
, buffer
, sizeof(buffer
) ))
1168 ERR( "bad atom %x\n", classAtom
);
1174 /* Fix the coordinates */
1176 cs
.x
= (x
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)x
;
1177 cs
.y
= (y
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)y
;
1178 cs
.cx
= (width
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)width
;
1179 cs
.cy
= (height
== CW_USEDEFAULT16
) ? CW_USEDEFAULT
: (INT
)height
;
1181 /* Create the window */
1183 cs
.lpCreateParams
= data
;
1184 cs
.hInstance
= HINSTANCE_32(instance
);
1185 cs
.hMenu
= HMENU_32(menu
);
1186 cs
.hwndParent
= WIN_Handle32( parent
);
1188 cs
.lpszName
= windowName
;
1189 cs
.lpszClass
= className
;
1190 cs
.dwExStyle
= exStyle
;
1192 return HWND_16( WIN_CreateWindowEx( &cs
, classAtom
, WIN_PROC_16
));
1196 /***********************************************************************
1197 * CreateWindowExA (USER32.@)
1199 HWND WINAPI
CreateWindowExA( DWORD exStyle
, LPCSTR className
,
1200 LPCSTR windowName
, DWORD style
, INT x
,
1201 INT y
, INT width
, INT height
,
1202 HWND parent
, HMENU menu
,
1203 HINSTANCE instance
, LPVOID data
)
1209 /* Find the class atom */
1211 if (HIWORD(className
))
1213 if (!(classAtom
= GlobalFindAtomA( className
)))
1215 ERR( "bad class name %s\n", debugstr_a(className
) );
1221 classAtom
= LOWORD(className
);
1222 if (!GlobalGetAtomNameA( classAtom
, buffer
, sizeof(buffer
) ))
1224 ERR( "bad atom %x\n", classAtom
);
1230 /* Create the window */
1232 cs
.lpCreateParams
= data
;
1233 cs
.hInstance
= instance
;
1235 cs
.hwndParent
= parent
;
1241 cs
.lpszName
= windowName
;
1242 cs
.lpszClass
= className
;
1243 cs
.dwExStyle
= exStyle
;
1245 return WIN_CreateWindowEx( &cs
, classAtom
, WIN_PROC_32A
);
1249 /***********************************************************************
1250 * CreateWindowExW (USER32.@)
1252 HWND WINAPI
CreateWindowExW( DWORD exStyle
, LPCWSTR className
,
1253 LPCWSTR windowName
, DWORD style
, INT x
,
1254 INT y
, INT width
, INT height
,
1255 HWND parent
, HMENU menu
,
1256 HINSTANCE instance
, LPVOID data
)
1262 /* Find the class atom */
1264 if (HIWORD(className
))
1266 if (!(classAtom
= GlobalFindAtomW( className
)))
1268 ERR( "bad class name %s\n", debugstr_w(className
) );
1274 classAtom
= LOWORD(className
);
1275 if (!GlobalGetAtomNameW( classAtom
, buffer
, sizeof(buffer
)/sizeof(WCHAR
) ))
1277 ERR( "bad atom %x\n", classAtom
);
1283 /* Create the window */
1285 cs
.lpCreateParams
= data
;
1286 cs
.hInstance
= instance
;
1288 cs
.hwndParent
= parent
;
1294 cs
.lpszName
= windowName
;
1295 cs
.lpszClass
= className
;
1296 cs
.dwExStyle
= exStyle
;
1298 /* Note: we rely on the fact that CREATESTRUCTA and */
1299 /* CREATESTRUCTW have the same layout. */
1300 return WIN_CreateWindowEx( (CREATESTRUCTA
*)&cs
, classAtom
, WIN_PROC_32W
);
1304 /***********************************************************************
1305 * WIN_SendDestroyMsg
1307 static void WIN_SendDestroyMsg( HWND hwnd
)
1311 if (GetGUIThreadInfo( GetCurrentThreadId(), &info
))
1313 if (hwnd
== info
.hwndCaret
) DestroyCaret();
1314 if (hwnd
== info
.hwndActive
) WINPOS_ActivateOtherWindow( hwnd
);
1316 if (USER_Driver
.pResetSelectionOwner
)
1317 USER_Driver
.pResetSelectionOwner( hwnd
, TRUE
);
1320 * Send the WM_DESTROY to the window.
1322 SendMessageW( hwnd
, WM_DESTROY
, 0, 0);
1325 * This WM_DESTROY message can trigger re-entrant calls to DestroyWindow
1326 * make sure that the window still exists when we come back.
1333 if (!(pWndArray
= WIN_ListChildren( hwnd
))) return;
1335 for (i
= 0; pWndArray
[i
]; i
++)
1337 if (IsWindow( pWndArray
[i
] )) WIN_SendDestroyMsg( pWndArray
[i
] );
1339 HeapFree( GetProcessHeap(), 0, pWndArray
);
1342 WARN("\tdestroyed itself while in WM_DESTROY!\n");
1346 /***********************************************************************
1347 * DestroyWindow (USER32.@)
1349 BOOL WINAPI
DestroyWindow( HWND hwnd
)
1353 if (!(hwnd
= WIN_IsCurrentThread( hwnd
)) || (hwnd
== GetDesktopWindow()))
1355 SetLastError( ERROR_ACCESS_DENIED
);
1359 TRACE("(%p)\n", hwnd
);
1363 if (HOOK_CallHooks( WH_CBT
, HCBT_DESTROYWND
, (WPARAM
)hwnd
, 0, TRUE
)) return FALSE
;
1365 if (MENU_IsMenuActive() == hwnd
)
1368 is_child
= (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) != 0;
1372 if (!USER_IsExitingThread( GetCurrentThreadId() ))
1373 send_parent_notify( hwnd
, WM_DESTROY
);
1375 else if (!GetWindow( hwnd
, GW_OWNER
))
1377 HOOK_CallHooks( WH_SHELL
, HSHELL_WINDOWDESTROYED
, (WPARAM
)hwnd
, 0L, TRUE
);
1378 /* FIXME: clean up palette - see "Internals" p.352 */
1381 if (!IsWindow(hwnd
)) return TRUE
;
1383 if (USER_Driver
.pResetSelectionOwner
)
1384 USER_Driver
.pResetSelectionOwner( hwnd
, FALSE
); /* before the window is unmapped */
1386 /* Hide the window */
1387 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)
1389 /* Only child windows receive WM_SHOWWINDOW in DestroyWindow() */
1391 ShowWindow( hwnd
, SW_HIDE
);
1393 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, SWP_NOMOVE
| SWP_NOSIZE
|
1394 SWP_NOZORDER
| SWP_NOACTIVATE
| SWP_HIDEWINDOW
);
1397 if (!IsWindow(hwnd
)) return TRUE
;
1399 /* Recursively destroy owned windows */
1406 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
1409 for (i
= 0; list
[i
]; i
++)
1411 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1412 if (WIN_IsCurrentThread( list
[i
] ))
1414 DestroyWindow( list
[i
] );
1418 WIN_SetOwner( list
[i
], 0 );
1420 HeapFree( GetProcessHeap(), 0, list
);
1422 if (!got_one
) break;
1426 /* Send destroy messages */
1428 WIN_SendDestroyMsg( hwnd
);
1429 if (!IsWindow( hwnd
)) return TRUE
;
1431 if (GetClipboardOwner() == hwnd
)
1432 CLIPBOARD_ReleaseOwner();
1434 /* Destroy the window storage */
1436 WIN_DestroyWindow( hwnd
);
1441 /***********************************************************************
1442 * CloseWindow (USER32.@)
1444 BOOL WINAPI
CloseWindow( HWND hwnd
)
1446 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
) return FALSE
;
1447 ShowWindow( hwnd
, SW_MINIMIZE
);
1452 /***********************************************************************
1453 * OpenIcon (USER32.@)
1455 BOOL WINAPI
OpenIcon( HWND hwnd
)
1457 if (!IsIconic( hwnd
)) return FALSE
;
1458 ShowWindow( hwnd
, SW_SHOWNORMAL
);
1463 /***********************************************************************
1466 * Implementation of FindWindow() and FindWindowEx().
1468 static HWND
WIN_FindWindow( HWND parent
, HWND child
, ATOM className
, LPCWSTR title
)
1473 WCHAR
*buffer
= NULL
;
1475 if (!parent
) parent
= GetDesktopWindow();
1478 len
= strlenW(title
) + 1; /* one extra char to check for chars beyond the end */
1479 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, (len
+ 1) * sizeof(WCHAR
) ))) return 0;
1482 if (!(list
= list_window_children( parent
, className
, 0 ))) goto done
;
1486 child
= WIN_GetFullHandle( child
);
1487 while (list
[i
] && list
[i
] != child
) i
++;
1488 if (!list
[i
]) goto done
;
1489 i
++; /* start from next window */
1496 if (GetWindowTextW( list
[i
], buffer
, len
+ 1 ) && !strcmpiW( buffer
, title
)) break;
1503 HeapFree( GetProcessHeap(), 0, list
);
1504 HeapFree( GetProcessHeap(), 0, buffer
);
1510 /***********************************************************************
1511 * FindWindowA (USER32.@)
1513 HWND WINAPI
FindWindowA( LPCSTR className
, LPCSTR title
)
1515 HWND ret
= FindWindowExA( 0, 0, className
, title
);
1516 if (!ret
) SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1521 /***********************************************************************
1522 * FindWindowExA (USER32.@)
1524 HWND WINAPI
FindWindowExA( HWND parent
, HWND child
,
1525 LPCSTR className
, LPCSTR title
)
1534 /* If the atom doesn't exist, then no class */
1535 /* with this name exists either. */
1536 if (!(atom
= GlobalFindAtomA( className
)))
1538 SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1542 if (!title
) return WIN_FindWindow( parent
, child
, atom
, NULL
);
1544 len
= MultiByteToWideChar( CP_ACP
, 0, title
, -1, NULL
, 0 );
1545 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, len
* sizeof(WCHAR
) ))) return 0;
1546 MultiByteToWideChar( CP_ACP
, 0, title
, -1, buffer
, len
);
1547 hwnd
= WIN_FindWindow( parent
, child
, atom
, buffer
);
1548 HeapFree( GetProcessHeap(), 0, buffer
);
1553 /***********************************************************************
1554 * FindWindowExW (USER32.@)
1556 HWND WINAPI
FindWindowExW( HWND parent
, HWND child
,
1557 LPCWSTR className
, LPCWSTR title
)
1563 /* If the atom doesn't exist, then no class */
1564 /* with this name exists either. */
1565 if (!(atom
= GlobalFindAtomW( className
)))
1567 SetLastError (ERROR_CANNOT_FIND_WND_CLASS
);
1571 return WIN_FindWindow( parent
, child
, atom
, title
);
1575 /***********************************************************************
1576 * FindWindowW (USER32.@)
1578 HWND WINAPI
FindWindowW( LPCWSTR className
, LPCWSTR title
)
1580 return FindWindowExW( 0, 0, className
, title
);
1584 /**********************************************************************
1585 * GetDesktopWindow (USER32.@)
1587 HWND WINAPI
GetDesktopWindow(void)
1589 if (hwndDesktop
) return hwndDesktop
;
1590 ERR( "Wine init error: either you're trying to use an invalid native USER.EXE config, or some graphics/GUI libraries or DLLs didn't initialize properly. Aborting.\n" );
1596 /*******************************************************************
1597 * EnableWindow (USER32.@)
1599 BOOL WINAPI
EnableWindow( HWND hwnd
, BOOL enable
)
1604 if (is_broadcast(hwnd
))
1606 SetLastError( ERROR_INVALID_PARAMETER
);
1610 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
1611 return SendMessageW( hwnd
, WM_WINE_ENABLEWINDOW
, enable
, 0 );
1615 TRACE("( %p, %d )\n", hwnd
, enable
);
1617 retvalue
= !IsWindowEnabled( hwnd
);
1619 if (enable
&& retvalue
)
1621 WIN_SetStyle( hwnd
, 0, WS_DISABLED
);
1622 SendMessageW( hwnd
, WM_ENABLE
, TRUE
, 0 );
1624 else if (!enable
&& !retvalue
)
1628 SendMessageW( hwnd
, WM_CANCELMODE
, 0, 0);
1630 WIN_SetStyle( hwnd
, WS_DISABLED
, 0 );
1632 if (hwnd
== GetFocus())
1633 SetFocus( 0 ); /* A disabled window can't have the focus */
1635 capture_wnd
= GetCapture();
1636 if (hwnd
== capture_wnd
|| IsChild(hwnd
, capture_wnd
))
1637 ReleaseCapture(); /* A disabled window can't capture the mouse */
1639 SendMessageW( hwnd
, WM_ENABLE
, FALSE
, 0 );
1645 /***********************************************************************
1646 * IsWindowEnabled (USER32.@)
1648 BOOL WINAPI
IsWindowEnabled(HWND hWnd
)
1650 return !(GetWindowLongW( hWnd
, GWL_STYLE
) & WS_DISABLED
);
1654 /***********************************************************************
1655 * IsWindowUnicode (USER32.@)
1657 BOOL WINAPI
IsWindowUnicode( HWND hwnd
)
1662 if (!(wndPtr
= WIN_GetPtr(hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return FALSE
;
1663 if (wndPtr
== WND_DESKTOP
) return TRUE
;
1664 retvalue
= (WINPROC_GetProcType( wndPtr
->winproc
) == WIN_PROC_32W
);
1665 WIN_ReleasePtr( wndPtr
);
1670 /**********************************************************************
1671 * GetWindowWord (USER32.@)
1673 WORD WINAPI
GetWindowWord( HWND hwnd
, INT offset
)
1678 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1681 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1684 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
1686 SERVER_START_REQ( set_window_info
)
1689 req
->flags
= 0; /* don't set anything, just retrieve */
1690 req
->extra_offset
= offset
;
1691 req
->extra_size
= sizeof(retvalue
);
1692 if (!wine_server_call_err( req
))
1693 memcpy( &retvalue
, &reply
->old_extra_value
, sizeof(retvalue
) );
1698 if (offset
> (int)(wndPtr
->cbWndExtra
- sizeof(WORD
)))
1700 WARN("Invalid offset %d\n", offset
);
1701 SetLastError( ERROR_INVALID_INDEX
);
1703 else memcpy( &retvalue
, (char *)wndPtr
->wExtra
+ offset
, sizeof(retvalue
) );
1704 WIN_ReleasePtr( wndPtr
);
1710 case GWLP_HWNDPARENT
:
1711 return GetWindowLongPtrW( hwnd
, offset
);
1713 case GWLP_HINSTANCE
:
1715 LONG_PTR ret
= GetWindowLongPtrW( hwnd
, offset
);
1717 WARN("%d: discards high bits of 0x%08lx!\n", offset
, ret
);
1721 WARN("Invalid offset %d\n", offset
);
1727 /**********************************************************************
1728 * SetWindowWord (USER32.@)
1730 WORD WINAPI
SetWindowWord( HWND hwnd
, INT offset
, WORD newval
)
1738 case GWLP_HINSTANCE
:
1739 case GWLP_HWNDPARENT
:
1740 return SetWindowLongPtrW( hwnd
, offset
, (ULONG_PTR
)newval
);
1744 WARN("Invalid offset %d\n", offset
);
1745 SetLastError( ERROR_INVALID_INDEX
);
1750 wndPtr
= WIN_GetPtr( hwnd
);
1751 if (wndPtr
== WND_DESKTOP
)
1753 SetLastError( ERROR_ACCESS_DENIED
);
1756 if (wndPtr
== WND_OTHER_PROCESS
)
1759 FIXME( "set %d <- %x not supported yet on other process window %p\n",
1760 offset
, newval
, hwnd
);
1765 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1769 if (offset
> (int)(wndPtr
->cbWndExtra
- sizeof(WORD
)))
1771 WARN("Invalid offset %d\n", offset
);
1772 WIN_ReleasePtr(wndPtr
);
1773 SetLastError( ERROR_INVALID_INDEX
);
1777 SERVER_START_REQ( set_window_info
)
1780 req
->flags
= SET_WIN_EXTRA
;
1781 req
->extra_offset
= offset
;
1782 req
->extra_size
= sizeof(newval
);
1783 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
1784 if (!wine_server_call_err( req
))
1786 void *ptr
= (char *)wndPtr
->wExtra
+ offset
;
1787 memcpy( &retval
, ptr
, sizeof(retval
) );
1788 memcpy( ptr
, &newval
, sizeof(newval
) );
1792 WIN_ReleasePtr( wndPtr
);
1797 /**********************************************************************
1800 * Helper function for GetWindowLong().
1802 static LONG_PTR
WIN_GetWindowLong( HWND hwnd
, INT offset
, WINDOWPROCTYPE type
)
1804 LONG_PTR retvalue
= 0;
1807 if (offset
== GWLP_HWNDPARENT
)
1809 HWND parent
= GetAncestor( hwnd
, GA_PARENT
);
1810 if (parent
== GetDesktopWindow()) parent
= GetWindow( hwnd
, GW_OWNER
);
1811 return (ULONG_PTR
)parent
;
1814 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
1816 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1820 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
)
1822 if (offset
== GWLP_WNDPROC
)
1824 SetLastError( ERROR_ACCESS_DENIED
);
1827 SERVER_START_REQ( set_window_info
)
1830 req
->flags
= 0; /* don't set anything, just retrieve */
1831 req
->extra_offset
= (offset
>= 0) ? offset
: -1;
1832 req
->extra_size
= (offset
>= 0) ? sizeof(retvalue
) : 0;
1833 if (!wine_server_call_err( req
))
1837 case GWL_STYLE
: retvalue
= reply
->old_style
; break;
1838 case GWL_EXSTYLE
: retvalue
= reply
->old_ex_style
; break;
1839 case GWLP_ID
: retvalue
= reply
->old_id
; break;
1840 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)reply
->old_instance
; break;
1841 case GWLP_USERDATA
: retvalue
= (ULONG_PTR
)reply
->old_user_data
; break;
1843 if (offset
>= 0) retvalue
= reply
->old_extra_value
;
1844 else SetLastError( ERROR_INVALID_INDEX
);
1853 /* now we have a valid wndPtr */
1857 if (offset
> (int)(wndPtr
->cbWndExtra
- sizeof(LONG
)))
1860 * Some programs try to access last element from 16 bit
1861 * code using illegal offset value. Hopefully this is
1862 * what those programs really expect.
1864 if (type
== WIN_PROC_16
&&
1865 wndPtr
->cbWndExtra
>= 4 &&
1866 offset
== wndPtr
->cbWndExtra
- sizeof(WORD
))
1868 INT offset2
= wndPtr
->cbWndExtra
- sizeof(LONG
);
1870 ERR( "- replaced invalid offset %d with %d\n",
1873 retvalue
= *(LONG_PTR
*)(((char *)wndPtr
->wExtra
) + offset2
);
1874 WIN_ReleasePtr( wndPtr
);
1877 WARN("Invalid offset %d\n", offset
);
1878 WIN_ReleasePtr( wndPtr
);
1879 SetLastError( ERROR_INVALID_INDEX
);
1882 retvalue
= *(LONG_PTR
*)(((char *)wndPtr
->wExtra
) + offset
);
1883 /* Special case for dialog window procedure */
1884 if ((offset
== DWLP_DLGPROC
) && (wndPtr
->flags
& WIN_ISDIALOG
))
1885 retvalue
= (LONG_PTR
)WINPROC_GetProc( (WNDPROC
)retvalue
, type
);
1886 WIN_ReleasePtr( wndPtr
);
1892 case GWLP_USERDATA
: retvalue
= wndPtr
->userdata
; break;
1893 case GWL_STYLE
: retvalue
= wndPtr
->dwStyle
; break;
1894 case GWL_EXSTYLE
: retvalue
= wndPtr
->dwExStyle
; break;
1895 case GWLP_ID
: retvalue
= (ULONG_PTR
)wndPtr
->wIDmenu
; break;
1896 case GWLP_WNDPROC
: retvalue
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, type
); break;
1897 case GWLP_HINSTANCE
: retvalue
= (ULONG_PTR
)wndPtr
->hInstance
; break;
1899 WARN("Unknown offset %d\n", offset
);
1900 SetLastError( ERROR_INVALID_INDEX
);
1903 WIN_ReleasePtr(wndPtr
);
1908 /**********************************************************************
1911 * Helper function for SetWindowLong().
1913 * 0 is the failure code. However, in the case of failure SetLastError
1914 * must be set to distinguish between a 0 return value and a failure.
1916 static LONG_PTR
WIN_SetWindowLong( HWND hwnd
, INT offset
, LONG_PTR newval
,
1917 WINDOWPROCTYPE type
)
1921 LONG_PTR retval
= 0;
1924 TRACE( "%p %d %lx %x\n", hwnd
, offset
, newval
, type
);
1926 if (is_broadcast(hwnd
))
1928 SetLastError( ERROR_INVALID_PARAMETER
);
1932 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
1934 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1937 if (wndPtr
== WND_DESKTOP
)
1939 /* can't change anything on the desktop window */
1940 SetLastError( ERROR_ACCESS_DENIED
);
1943 if (wndPtr
== WND_OTHER_PROCESS
)
1945 if (offset
== GWLP_WNDPROC
)
1947 SetLastError( ERROR_ACCESS_DENIED
);
1950 return SendMessageW( hwnd
, WM_WINE_SETWINDOWLONG
, offset
, newval
);
1953 /* first some special cases */
1959 offset
== GWL_STYLE
? wndPtr
->dwStyle
: wndPtr
->dwExStyle
;
1960 style
.styleNew
= newval
;
1961 WIN_ReleasePtr( wndPtr
);
1962 SendMessageW( hwnd
, WM_STYLECHANGING
, offset
, (LPARAM
)&style
);
1963 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1964 newval
= style
.styleNew
;
1966 case GWLP_HWNDPARENT
:
1967 if (wndPtr
->parent
== GetDesktopWindow())
1969 WIN_ReleasePtr( wndPtr
);
1970 return (ULONG_PTR
)WIN_SetOwner( hwnd
, (HWND
)newval
);
1974 WIN_ReleasePtr( wndPtr
);
1975 return (ULONG_PTR
)SetParent( hwnd
, (HWND
)newval
);
1978 retval
= (ULONG_PTR
)WINPROC_GetProc( wndPtr
->winproc
, type
);
1979 wndPtr
->winproc
= WINPROC_AllocProc( (WNDPROC
)newval
, type
);
1980 WIN_ReleasePtr( wndPtr
);
1983 case GWLP_HINSTANCE
:
1987 if ((wndPtr
->cbWndExtra
+ sizeof(LONG_PTR
) >= DWLP_DLGPROC
) && (wndPtr
->flags
& WIN_ISDIALOG
))
1989 WNDPROC
*ptr
= (WNDPROC
*)((char *)wndPtr
->wExtra
+ DWLP_DLGPROC
);
1990 retval
= (ULONG_PTR
)WINPROC_GetProc( *ptr
, type
);
1991 *ptr
= WINPROC_AllocProc( (WNDPROC
)newval
, type
);
1992 WIN_ReleasePtr( wndPtr
);
1997 if (offset
< 0 || offset
> (int)(wndPtr
->cbWndExtra
- sizeof(LONG_PTR
)))
1999 WARN("Invalid offset %d\n", offset
);
2000 WIN_ReleasePtr( wndPtr
);
2001 SetLastError( ERROR_INVALID_INDEX
);
2006 LONG_PTR
*ptr
= (LONG_PTR
*)((char *)wndPtr
->wExtra
+ offset
);
2007 if (*ptr
== newval
) /* already set to the same value */
2009 WIN_ReleasePtr( wndPtr
);
2016 SERVER_START_REQ( set_window_info
)
2019 req
->extra_offset
= -1;
2023 req
->flags
= SET_WIN_STYLE
;
2024 req
->style
= newval
;
2027 req
->flags
= SET_WIN_EXSTYLE
;
2028 req
->ex_style
= newval
;
2031 req
->flags
= SET_WIN_ID
;
2034 case GWLP_HINSTANCE
:
2035 req
->flags
= SET_WIN_INSTANCE
;
2036 req
->instance
= (void *)newval
;
2039 req
->flags
= SET_WIN_USERDATA
;
2040 req
->user_data
= (void *)newval
;
2043 req
->flags
= SET_WIN_EXTRA
;
2044 req
->extra_offset
= offset
;
2045 req
->extra_size
= sizeof(newval
);
2046 memcpy( &req
->extra_value
, &newval
, sizeof(newval
) );
2048 if ((ok
= !wine_server_call_err( req
)))
2053 wndPtr
->dwStyle
= newval
;
2054 retval
= reply
->old_style
;
2057 wndPtr
->dwExStyle
= newval
;
2058 retval
= reply
->old_ex_style
;
2061 wndPtr
->wIDmenu
= newval
;
2062 retval
= reply
->old_id
;
2064 case GWLP_HINSTANCE
:
2065 wndPtr
->hInstance
= (HINSTANCE
)newval
;
2066 retval
= (ULONG_PTR
)reply
->old_instance
;
2069 wndPtr
->userdata
= newval
;
2070 retval
= (ULONG_PTR
)reply
->old_user_data
;
2074 void *ptr
= (char *)wndPtr
->wExtra
+ offset
;
2075 memcpy( &retval
, ptr
, sizeof(retval
) );
2076 memcpy( ptr
, &newval
, sizeof(newval
) );
2083 WIN_ReleasePtr( wndPtr
);
2087 if (offset
== GWL_STYLE
&& USER_Driver
.pSetWindowStyle
)
2088 USER_Driver
.pSetWindowStyle( hwnd
, retval
);
2090 if (offset
== GWL_STYLE
|| offset
== GWL_EXSTYLE
)
2091 SendMessageW( hwnd
, WM_STYLECHANGED
, offset
, (LPARAM
)&style
);
2097 /**********************************************************************
2098 * GetWindowLong (USER.135)
2100 LONG WINAPI
GetWindowLong16( HWND16 hwnd
, INT16 offset
)
2102 return WIN_GetWindowLong( WIN_Handle32(hwnd
), offset
, WIN_PROC_16
);
2106 /**********************************************************************
2107 * GetWindowLongA (USER32.@)
2109 LONG WINAPI
GetWindowLongA( HWND hwnd
, INT offset
)
2111 return WIN_GetWindowLong( hwnd
, offset
, WIN_PROC_32A
);
2115 /**********************************************************************
2116 * GetWindowLongW (USER32.@)
2118 LONG WINAPI
GetWindowLongW( HWND hwnd
, INT offset
)
2120 return WIN_GetWindowLong( hwnd
, offset
, WIN_PROC_32W
);
2124 /**********************************************************************
2125 * SetWindowLong (USER.136)
2127 LONG WINAPI
SetWindowLong16( HWND16 hwnd
, INT16 offset
, LONG newval
)
2129 return WIN_SetWindowLong( WIN_Handle32(hwnd
), offset
, newval
, WIN_PROC_16
);
2133 /**********************************************************************
2134 * SetWindowLongA (USER32.@)
2136 LONG WINAPI
SetWindowLongA( HWND hwnd
, INT offset
, LONG newval
)
2138 return WIN_SetWindowLong( hwnd
, offset
, newval
, WIN_PROC_32A
);
2142 /**********************************************************************
2143 * SetWindowLongW (USER32.@) Set window attribute
2145 * SetWindowLong() alters one of a window's attributes or sets a 32-bit (long)
2146 * value in a window's extra memory.
2148 * The _hwnd_ parameter specifies the window. is the handle to a
2149 * window that has extra memory. The _newval_ parameter contains the
2150 * new attribute or extra memory value. If positive, the _offset_
2151 * parameter is the byte-addressed location in the window's extra
2152 * memory to set. If negative, _offset_ specifies the window
2153 * attribute to set, and should be one of the following values:
2155 * GWL_EXSTYLE The window's extended window style
2157 * GWL_STYLE The window's window style.
2159 * GWLP_WNDPROC Pointer to the window's window procedure.
2161 * GWLP_HINSTANCE The window's pplication instance handle.
2163 * GWLP_ID The window's identifier.
2165 * GWLP_USERDATA The window's user-specified data.
2167 * If the window is a dialog box, the _offset_ parameter can be one of
2168 * the following values:
2170 * DWLP_DLGPROC The address of the window's dialog box procedure.
2172 * DWLP_MSGRESULT The return value of a message
2173 * that the dialog box procedure processed.
2175 * DWLP_USER Application specific information.
2179 * If successful, returns the previous value located at _offset_. Otherwise,
2184 * Extra memory for a window class is specified by a nonzero cbWndExtra
2185 * parameter of the WNDCLASS structure passed to RegisterClass() at the
2186 * time of class creation.
2188 * Using GWL_WNDPROC to set a new window procedure effectively creates
2189 * a window subclass. Use CallWindowProc() in the new windows procedure
2190 * to pass messages to the superclass's window procedure.
2192 * The user data is reserved for use by the application which created
2195 * Do not use GWL_STYLE to change the window's WS_DISABLED style;
2196 * instead, call the EnableWindow() function to change the window's
2199 * Do not use GWL_HWNDPARENT to reset the window's parent, use
2200 * SetParent() instead.
2203 * When offset is GWL_STYLE and the calling app's ver is 4.0,
2204 * it sends WM_STYLECHANGING before changing the settings
2205 * and WM_STYLECHANGED afterwards.
2206 * App ver 4.0 can't use SetWindowLong to change WS_EX_TOPMOST.
2208 LONG WINAPI
SetWindowLongW(
2209 HWND hwnd
, /* [in] window to alter */
2210 INT offset
, /* [in] offset, in bytes, of location to alter */
2211 LONG newval
/* [in] new value of location */
2213 return WIN_SetWindowLong( hwnd
, offset
, newval
, WIN_PROC_32W
);
2217 /*******************************************************************
2218 * GetWindowTextA (USER32.@)
2220 INT WINAPI
GetWindowTextA( HWND hwnd
, LPSTR lpString
, INT nMaxCount
)
2224 if (WIN_IsCurrentProcess( hwnd
))
2225 return (INT
)SendMessageA( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2227 /* when window belongs to other process, don't send a message */
2228 if (nMaxCount
<= 0) return 0;
2229 if (!(buffer
= HeapAlloc( GetProcessHeap(), 0, nMaxCount
* sizeof(WCHAR
) ))) return 0;
2230 get_server_window_text( hwnd
, buffer
, nMaxCount
);
2231 if (!WideCharToMultiByte( CP_ACP
, 0, buffer
, -1, lpString
, nMaxCount
, NULL
, NULL
))
2232 lpString
[nMaxCount
-1] = 0;
2233 HeapFree( GetProcessHeap(), 0, buffer
);
2234 return strlen(lpString
);
2238 /*******************************************************************
2239 * InternalGetWindowText (USER32.@)
2241 INT WINAPI
InternalGetWindowText(HWND hwnd
,LPWSTR lpString
,INT nMaxCount
)
2245 if (nMaxCount
<= 0) return 0;
2246 if (!(win
= WIN_GetPtr( hwnd
))) return 0;
2247 if (win
== WND_DESKTOP
) lpString
[0] = 0;
2248 else if (win
!= WND_OTHER_PROCESS
)
2250 if (win
->text
) lstrcpynW( lpString
, win
->text
, nMaxCount
);
2251 else lpString
[0] = 0;
2252 WIN_ReleasePtr( win
);
2256 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2258 return strlenW(lpString
);
2262 /*******************************************************************
2263 * GetWindowTextW (USER32.@)
2265 INT WINAPI
GetWindowTextW( HWND hwnd
, LPWSTR lpString
, INT nMaxCount
)
2267 if (WIN_IsCurrentProcess( hwnd
))
2268 return (INT
)SendMessageW( hwnd
, WM_GETTEXT
, nMaxCount
, (LPARAM
)lpString
);
2270 /* when window belongs to other process, don't send a message */
2271 if (nMaxCount
<= 0) return 0;
2272 get_server_window_text( hwnd
, lpString
, nMaxCount
);
2273 return strlenW(lpString
);
2277 /*******************************************************************
2278 * SetWindowText (USER32.@)
2279 * SetWindowTextA (USER32.@)
2281 BOOL WINAPI
SetWindowTextA( HWND hwnd
, LPCSTR lpString
)
2283 if (is_broadcast(hwnd
))
2285 SetLastError( ERROR_INVALID_PARAMETER
);
2288 if (!WIN_IsCurrentProcess( hwnd
))
2290 FIXME( "cannot set text %s of other process window %p\n", debugstr_a(lpString
), hwnd
);
2291 SetLastError( ERROR_ACCESS_DENIED
);
2294 return (BOOL
)SendMessageA( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2298 /*******************************************************************
2299 * SetWindowTextW (USER32.@)
2301 BOOL WINAPI
SetWindowTextW( HWND hwnd
, LPCWSTR lpString
)
2303 if (is_broadcast(hwnd
))
2305 SetLastError( ERROR_INVALID_PARAMETER
);
2308 if (!WIN_IsCurrentProcess( hwnd
))
2310 FIXME( "cannot set text %s of other process window %p\n", debugstr_w(lpString
), hwnd
);
2311 SetLastError( ERROR_ACCESS_DENIED
);
2314 return (BOOL
)SendMessageW( hwnd
, WM_SETTEXT
, 0, (LPARAM
)lpString
);
2318 /*******************************************************************
2319 * GetWindowTextLengthA (USER32.@)
2321 INT WINAPI
GetWindowTextLengthA( HWND hwnd
)
2323 return SendMessageA( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2326 /*******************************************************************
2327 * GetWindowTextLengthW (USER32.@)
2329 INT WINAPI
GetWindowTextLengthW( HWND hwnd
)
2331 return SendMessageW( hwnd
, WM_GETTEXTLENGTH
, 0, 0 );
2335 /*******************************************************************
2336 * IsWindow (USER32.@)
2338 BOOL WINAPI
IsWindow( HWND hwnd
)
2343 if (!(ptr
= WIN_GetPtr( hwnd
))) return FALSE
;
2344 if (ptr
== WND_DESKTOP
) return TRUE
;
2346 if (ptr
!= WND_OTHER_PROCESS
)
2348 WIN_ReleasePtr( ptr
);
2352 /* check other processes */
2353 SERVER_START_REQ( get_window_info
)
2356 ret
= !wine_server_call_err( req
);
2363 /***********************************************************************
2364 * GetWindowThreadProcessId (USER32.@)
2366 DWORD WINAPI
GetWindowThreadProcessId( HWND hwnd
, LPDWORD process
)
2371 if (!(ptr
= WIN_GetPtr( hwnd
)))
2373 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2377 if (ptr
!= WND_OTHER_PROCESS
&& ptr
!= WND_DESKTOP
)
2379 /* got a valid window */
2381 if (process
) *process
= GetCurrentProcessId();
2382 WIN_ReleasePtr( ptr
);
2386 /* check other processes */
2387 SERVER_START_REQ( get_window_info
)
2390 if (!wine_server_call_err( req
))
2392 tid
= (DWORD
)reply
->tid
;
2393 if (process
) *process
= (DWORD
)reply
->pid
;
2401 /*****************************************************************
2402 * GetParent (USER32.@)
2404 HWND WINAPI
GetParent( HWND hwnd
)
2409 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
2411 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2414 if (wndPtr
== WND_DESKTOP
) return 0;
2415 if (wndPtr
== WND_OTHER_PROCESS
)
2417 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2418 if (style
& (WS_POPUP
| WS_CHILD
))
2420 SERVER_START_REQ( get_window_tree
)
2423 if (!wine_server_call_err( req
))
2425 if (style
& WS_POPUP
) retvalue
= reply
->owner
;
2426 else if (style
& WS_CHILD
) retvalue
= reply
->parent
;
2434 if (wndPtr
->dwStyle
& WS_POPUP
) retvalue
= wndPtr
->owner
;
2435 else if (wndPtr
->dwStyle
& WS_CHILD
) retvalue
= wndPtr
->parent
;
2436 WIN_ReleasePtr( wndPtr
);
2442 /*****************************************************************
2443 * GetAncestor (USER32.@)
2445 HWND WINAPI
GetAncestor( HWND hwnd
, UINT type
)
2448 HWND
*list
, ret
= 0;
2453 if (!(win
= WIN_GetPtr( hwnd
)))
2455 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2458 if (win
== WND_DESKTOP
) return 0;
2459 if (win
!= WND_OTHER_PROCESS
)
2462 WIN_ReleasePtr( win
);
2464 else /* need to query the server */
2466 SERVER_START_REQ( get_window_tree
)
2469 if (!wine_server_call_err( req
)) ret
= reply
->parent
;
2476 if (!(list
= list_window_parents( hwnd
))) return 0;
2478 if (!list
[0] || !list
[1]) ret
= WIN_GetFullHandle( hwnd
); /* top-level window */
2482 while (list
[count
]) count
++;
2483 ret
= list
[count
- 2]; /* get the one before the desktop */
2485 HeapFree( GetProcessHeap(), 0, list
);
2489 if ((ret
= WIN_GetFullHandle( hwnd
)) == GetDesktopWindow()) return 0;
2492 HWND parent
= GetParent( ret
);
2502 /*****************************************************************
2503 * SetParent (USER32.@)
2505 HWND WINAPI
SetParent( HWND hwnd
, HWND parent
)
2509 if (is_broadcast(hwnd
) || is_broadcast(parent
))
2511 SetLastError(ERROR_INVALID_PARAMETER
);
2515 if (!parent
) parent
= GetDesktopWindow();
2516 else parent
= WIN_GetFullHandle( parent
);
2518 if (!IsWindow( parent
))
2520 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
2524 /* Some applications try to set a child as a parent */
2525 if (IsChild(hwnd
, parent
))
2527 SetLastError( ERROR_INVALID_PARAMETER
);
2531 if (!(full_handle
= WIN_IsCurrentThread( hwnd
)))
2532 return (HWND
)SendMessageW( hwnd
, WM_WINE_SETPARENT
, (WPARAM
)parent
, 0 );
2534 if (USER_Driver
.pSetParent
)
2535 return USER_Driver
.pSetParent( full_handle
, parent
);
2541 /*******************************************************************
2542 * IsChild (USER32.@)
2544 BOOL WINAPI
IsChild( HWND parent
, HWND child
)
2546 HWND
*list
= list_window_parents( child
);
2550 if (!list
) return FALSE
;
2551 parent
= WIN_GetFullHandle( parent
);
2552 for (i
= 0; list
[i
]; i
++) if (list
[i
] == parent
) break;
2553 ret
= (list
[i
] != 0);
2554 HeapFree( GetProcessHeap(), 0, list
);
2559 /***********************************************************************
2560 * IsWindowVisible (USER32.@)
2562 BOOL WINAPI
IsWindowVisible( HWND hwnd
)
2568 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
)) return FALSE
;
2569 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
2570 for (i
= 0; list
[i
]; i
++)
2571 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_VISIBLE
)) break;
2573 HeapFree( GetProcessHeap(), 0, list
);
2578 /***********************************************************************
2579 * WIN_IsWindowDrawable
2581 * hwnd is drawable when it is visible, all parents are not
2582 * minimized, and it is itself not minimized unless we are
2583 * trying to draw its default class icon.
2585 BOOL
WIN_IsWindowDrawable( HWND hwnd
, BOOL icon
)
2590 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2592 if (!(style
& WS_VISIBLE
)) return FALSE
;
2593 if ((style
& WS_MINIMIZE
) && icon
&& GetClassLongPtrW( hwnd
, GCLP_HICON
)) return FALSE
;
2595 if (!(list
= list_window_parents( hwnd
))) return TRUE
;
2596 for (i
= 0; list
[i
]; i
++)
2597 if ((GetWindowLongW( list
[i
], GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != WS_VISIBLE
)
2600 HeapFree( GetProcessHeap(), 0, list
);
2605 /*******************************************************************
2606 * GetTopWindow (USER32.@)
2608 HWND WINAPI
GetTopWindow( HWND hwnd
)
2610 if (!hwnd
) hwnd
= GetDesktopWindow();
2611 return GetWindow( hwnd
, GW_CHILD
);
2615 /*******************************************************************
2616 * GetWindow (USER32.@)
2618 HWND WINAPI
GetWindow( HWND hwnd
, UINT rel
)
2622 if (rel
== GW_OWNER
) /* this one may be available locally */
2624 WND
*wndPtr
= WIN_GetPtr( hwnd
);
2627 SetLastError( ERROR_INVALID_HANDLE
);
2630 if (wndPtr
== WND_DESKTOP
) return 0;
2631 if (wndPtr
!= WND_OTHER_PROCESS
)
2633 retval
= wndPtr
->owner
;
2634 WIN_ReleasePtr( wndPtr
);
2637 /* else fall through to server call */
2640 SERVER_START_REQ( get_window_tree
)
2643 if (!wine_server_call_err( req
))
2648 retval
= reply
->first_sibling
;
2651 retval
= reply
->last_sibling
;
2654 retval
= reply
->next_sibling
;
2657 retval
= reply
->prev_sibling
;
2660 retval
= reply
->owner
;
2663 retval
= reply
->first_child
;
2673 /*******************************************************************
2674 * ShowOwnedPopups (USER32.@)
2676 BOOL WINAPI
ShowOwnedPopups( HWND owner
, BOOL fShow
)
2680 HWND
*win_array
= WIN_ListChildren( GetDesktopWindow() );
2682 if (!win_array
) return TRUE
;
2684 while (win_array
[count
]) count
++;
2685 while (--count
>= 0)
2687 if (GetWindow( win_array
[count
], GW_OWNER
) != owner
) continue;
2688 if (!(pWnd
= WIN_GetPtr( win_array
[count
] ))) continue;
2689 if (pWnd
== WND_OTHER_PROCESS
) continue;
2691 if (pWnd
->dwStyle
& WS_POPUP
)
2695 if (pWnd
->flags
& WIN_NEEDS_SHOW_OWNEDPOPUP
)
2697 pWnd
->flags
&= ~WIN_NEEDS_SHOW_OWNEDPOPUP
;
2698 WIN_ReleasePtr( pWnd
);
2699 /* In Windows, ShowOwnedPopups(TRUE) generates
2700 * WM_SHOWWINDOW messages with SW_PARENTOPENING,
2701 * regardless of the state of the owner
2703 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_SHOW
, SW_PARENTOPENING
);
2709 if (pWnd
->dwStyle
& WS_VISIBLE
)
2711 pWnd
->flags
|= WIN_NEEDS_SHOW_OWNEDPOPUP
;
2712 WIN_ReleasePtr( pWnd
);
2713 /* In Windows, ShowOwnedPopups(FALSE) generates
2714 * WM_SHOWWINDOW messages with SW_PARENTCLOSING,
2715 * regardless of the state of the owner
2717 SendMessageW(win_array
[count
], WM_SHOWWINDOW
, SW_HIDE
, SW_PARENTCLOSING
);
2722 WIN_ReleasePtr( pWnd
);
2724 HeapFree( GetProcessHeap(), 0, win_array
);
2729 /*******************************************************************
2730 * GetLastActivePopup (USER32.@)
2732 HWND WINAPI
GetLastActivePopup( HWND hwnd
)
2736 SERVER_START_REQ( get_window_info
)
2739 if (!wine_server_call_err( req
)) retval
= reply
->last_active
;
2746 /*******************************************************************
2749 * Build an array of the children of a given window. The array must be
2750 * freed with HeapFree. Returns NULL when no windows are found.
2752 HWND
*WIN_ListChildren( HWND hwnd
)
2754 return list_window_children( hwnd
, 0, 0 );
2758 /*******************************************************************
2759 * EnumWindows (USER32.@)
2761 BOOL WINAPI
EnumWindows( WNDENUMPROC lpEnumFunc
, LPARAM lParam
)
2767 USER_CheckNotLock();
2769 /* We have to build a list of all windows first, to avoid */
2770 /* unpleasant side-effects, for instance if the callback */
2771 /* function changes the Z-order of the windows. */
2773 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return TRUE
;
2775 /* Now call the callback function for every window */
2777 for (i
= 0; list
[i
]; i
++)
2779 /* Make sure that the window still exists */
2780 if (!IsWindow( list
[i
] )) continue;
2781 if (!(ret
= lpEnumFunc( list
[i
], lParam
))) break;
2783 HeapFree( GetProcessHeap(), 0, list
);
2788 /**********************************************************************
2789 * EnumThreadWindows (USER32.@)
2791 BOOL WINAPI
EnumThreadWindows( DWORD id
, WNDENUMPROC func
, LPARAM lParam
)
2796 USER_CheckNotLock();
2798 if (!(list
= list_window_children( GetDesktopWindow(), 0, id
))) return TRUE
;
2800 /* Now call the callback function for every window */
2802 for (i
= 0; list
[i
]; i
++)
2803 if (!func( list
[i
], lParam
)) break;
2804 HeapFree( GetProcessHeap(), 0, list
);
2809 /**********************************************************************
2810 * WIN_EnumChildWindows
2812 * Helper function for EnumChildWindows().
2814 static BOOL
WIN_EnumChildWindows( HWND
*list
, WNDENUMPROC func
, LPARAM lParam
)
2819 for ( ; *list
; list
++)
2821 /* Make sure that the window still exists */
2822 if (!IsWindow( *list
)) continue;
2823 /* skip owned windows */
2824 if (GetWindow( *list
, GW_OWNER
)) continue;
2825 /* Build children list first */
2826 childList
= WIN_ListChildren( *list
);
2828 ret
= func( *list
, lParam
);
2832 if (ret
) ret
= WIN_EnumChildWindows( childList
, func
, lParam
);
2833 HeapFree( GetProcessHeap(), 0, childList
);
2835 if (!ret
) return FALSE
;
2841 /**********************************************************************
2842 * EnumChildWindows (USER32.@)
2844 BOOL WINAPI
EnumChildWindows( HWND parent
, WNDENUMPROC func
, LPARAM lParam
)
2848 USER_CheckNotLock();
2850 if (!(list
= WIN_ListChildren( parent
))) return FALSE
;
2851 WIN_EnumChildWindows( list
, func
, lParam
);
2852 HeapFree( GetProcessHeap(), 0, list
);
2857 /*******************************************************************
2858 * AnyPopup (USER.52)
2860 BOOL16 WINAPI
AnyPopup16(void)
2866 /*******************************************************************
2867 * AnyPopup (USER32.@)
2869 BOOL WINAPI
AnyPopup(void)
2873 HWND
*list
= WIN_ListChildren( GetDesktopWindow() );
2875 if (!list
) return FALSE
;
2876 for (i
= 0; list
[i
]; i
++)
2878 if (IsWindowVisible( list
[i
] ) && GetWindow( list
[i
], GW_OWNER
)) break;
2880 retvalue
= (list
[i
] != 0);
2881 HeapFree( GetProcessHeap(), 0, list
);
2886 /*******************************************************************
2887 * FlashWindow (USER32.@)
2889 BOOL WINAPI
FlashWindow( HWND hWnd
, BOOL bInvert
)
2893 TRACE("%p\n", hWnd
);
2895 if (IsIconic( hWnd
))
2897 RedrawWindow( hWnd
, 0, 0, RDW_INVALIDATE
| RDW_ERASE
| RDW_UPDATENOW
| RDW_FRAME
);
2899 wndPtr
= WIN_GetPtr(hWnd
);
2900 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
2901 if (bInvert
&& !(wndPtr
->flags
& WIN_NCACTIVATED
))
2903 wndPtr
->flags
|= WIN_NCACTIVATED
;
2907 wndPtr
->flags
&= ~WIN_NCACTIVATED
;
2909 WIN_ReleasePtr( wndPtr
);
2916 wndPtr
= WIN_GetPtr(hWnd
);
2917 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
2918 hWnd
= wndPtr
->hwndSelf
; /* make it a full handle */
2920 if (bInvert
) wparam
= !(wndPtr
->flags
& WIN_NCACTIVATED
);
2921 else wparam
= (hWnd
== GetForegroundWindow());
2923 WIN_ReleasePtr( wndPtr
);
2924 SendMessageW( hWnd
, WM_NCACTIVATE
, wparam
, (LPARAM
)0 );
2929 /*******************************************************************
2930 * FlashWindowEx (USER32.@)
2932 BOOL WINAPI
FlashWindowEx( PFLASHWINFO pfwi
)
2934 FIXME("%p\n", pfwi
);
2938 /*******************************************************************
2939 * GetWindowContextHelpId (USER32.@)
2941 DWORD WINAPI
GetWindowContextHelpId( HWND hwnd
)
2944 WND
*wnd
= WIN_GetPtr( hwnd
);
2945 if (!wnd
|| wnd
== WND_DESKTOP
) return 0;
2946 if (wnd
== WND_OTHER_PROCESS
)
2948 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
2951 retval
= wnd
->helpContext
;
2952 WIN_ReleasePtr( wnd
);
2957 /*******************************************************************
2958 * SetWindowContextHelpId (USER32.@)
2960 BOOL WINAPI
SetWindowContextHelpId( HWND hwnd
, DWORD id
)
2962 WND
*wnd
= WIN_GetPtr( hwnd
);
2963 if (!wnd
|| wnd
== WND_DESKTOP
) return FALSE
;
2964 if (wnd
== WND_OTHER_PROCESS
)
2966 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
2969 wnd
->helpContext
= id
;
2970 WIN_ReleasePtr( wnd
);
2975 /*******************************************************************
2976 * DragDetect (USER32.@)
2978 BOOL WINAPI
DragDetect( HWND hWnd
, POINT pt
)
2983 rect
.left
= pt
.x
- wDragWidth
;
2984 rect
.right
= pt
.x
+ wDragWidth
;
2986 rect
.top
= pt
.y
- wDragHeight
;
2987 rect
.bottom
= pt
.y
+ wDragHeight
;
2993 while (PeekMessageW( &msg
, 0, WM_MOUSEFIRST
, WM_MOUSELAST
, PM_REMOVE
))
2995 if( msg
.message
== WM_LBUTTONUP
)
3000 if( msg
.message
== WM_MOUSEMOVE
)
3003 tmp
.x
= LOWORD(msg
.lParam
);
3004 tmp
.y
= HIWORD(msg
.lParam
);
3005 if( !PtInRect( &rect
, tmp
))
3017 /******************************************************************************
3018 * GetWindowModuleFileNameA (USER32.@)
3020 UINT WINAPI
GetWindowModuleFileNameA( HWND hwnd
, LPSTR lpszFileName
, UINT cchFileNameMax
)
3022 FIXME("GetWindowModuleFileNameA(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3023 hwnd
, lpszFileName
, cchFileNameMax
);
3027 /******************************************************************************
3028 * GetWindowModuleFileNameW (USER32.@)
3030 UINT WINAPI
GetWindowModuleFileNameW( HWND hwnd
, LPWSTR lpszFileName
, UINT cchFileNameMax
)
3032 FIXME("GetWindowModuleFileNameW(hwnd %p, lpszFileName %p, cchFileNameMax %u) stub!\n",
3033 hwnd
, lpszFileName
, cchFileNameMax
);
3037 /******************************************************************************
3038 * GetWindowInfo (USER32.@)
3040 * Note: tests show that Windows doesn't check cbSize of the structure.
3042 BOOL WINAPI
GetWindowInfo( HWND hwnd
, PWINDOWINFO pwi
)
3044 if (!pwi
) return FALSE
;
3045 if (!IsWindow(hwnd
)) return FALSE
;
3047 GetWindowRect(hwnd
, &pwi
->rcWindow
);
3048 GetClientRect(hwnd
, &pwi
->rcClient
);
3049 /* translate to screen coordinates */
3050 MapWindowPoints(hwnd
, 0, (LPPOINT
)&pwi
->rcClient
, 2);
3052 pwi
->dwStyle
= GetWindowLongW(hwnd
, GWL_STYLE
);
3053 pwi
->dwExStyle
= GetWindowLongW(hwnd
, GWL_EXSTYLE
);
3054 pwi
->dwWindowStatus
= ((GetActiveWindow() == hwnd
) ? WS_ACTIVECAPTION
: 0);
3056 pwi
->cxWindowBorders
= pwi
->rcClient
.left
- pwi
->rcWindow
.left
;
3057 pwi
->cyWindowBorders
= pwi
->rcWindow
.bottom
- pwi
->rcClient
.bottom
;
3059 pwi
->atomWindowType
= GetClassLongW( hwnd
, GCW_ATOM
);
3060 pwi
->wCreatorVersion
= 0x0400;
3065 /******************************************************************************
3066 * SwitchDesktop (USER32.@)
3068 * NOTES: Sets the current input or interactive desktop.
3070 BOOL WINAPI
SwitchDesktop( HDESK hDesktop
)
3072 FIXME("SwitchDesktop(hwnd %p) stub!\n", hDesktop
);