Install the shell hook as a 32-bit hook.
[wine] / windows / winpos.c
1 /*
2  * Window position related functions.
3  *
4  * Copyright 1993, 1994, 1995 Alexandre Julliard
5  *                       1995, 1996, 1999 Alex Korobka
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20  */
21
22 #include <string.h>
23 #include "winerror.h"
24 #include "windef.h"
25 #include "wingdi.h"
26 #include "winerror.h"
27 #include "wine/winuser16.h"
28 #include "wine/server.h"
29 #include "controls.h"
30 #include "user.h"
31 #include "win.h"
32 #include "hook.h"
33 #include "message.h"
34 #include "queue.h"
35 #include "winpos.h"
36 #include "dce.h"
37 #include "nonclient.h"
38 #include "wine/debug.h"
39 #include "input.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(win);
42
43 #define HAS_DLGFRAME(style,exStyle) \
44     (((exStyle) & WS_EX_DLGMODALFRAME) || \
45      (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
46
47 #define HAS_THICKFRAME(style) \
48     (((style) & WS_THICKFRAME) && \
49      !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
50
51 #define EMPTYPOINT(pt)          ((*(LONG*)&(pt)) == -1)
52
53 #define PLACE_MIN               0x0001
54 #define PLACE_MAX               0x0002
55 #define PLACE_RECT              0x0004
56
57
58 #define DWP_MAGIC  ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
59
60 typedef struct
61 {
62     INT       actualCount;
63     INT       suggestedCount;
64     BOOL      valid;
65     INT       wMagic;
66     HWND      hwndParent;
67     WINDOWPOS winPos[1];
68 } DWP;
69
70 /* ----- internal variables ----- */
71
72 static HWND hGlobalShellWindow=0; /*the shell*/
73 static HWND hGlobalTaskmanWindow=0;
74 static HWND hGlobalProgmanWindow=0;
75
76 static LPCSTR atomInternalPos;
77
78
79 /***********************************************************************
80  *           WINPOS_CreateInternalPosAtom
81  */
82 BOOL WINPOS_CreateInternalPosAtom()
83 {
84     LPSTR str = "SysIP";
85     atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
86     return (atomInternalPos) ? TRUE : FALSE;
87 }
88
89 /***********************************************************************
90  *           WINPOS_CheckInternalPos
91  *
92  * Called when a window is destroyed.
93  */
94 void WINPOS_CheckInternalPos( HWND hwnd )
95 {
96     LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
97
98     if( lpPos )
99     {
100         if( IsWindow(lpPos->hwndIconTitle) )
101             DestroyWindow( lpPos->hwndIconTitle );
102         HeapFree( GetProcessHeap(), 0, lpPos );
103     }
104 }
105
106 /***********************************************************************
107  *              ArrangeIconicWindows (USER32.@)
108  */
109 UINT WINAPI ArrangeIconicWindows( HWND parent )
110 {
111     RECT rectParent;
112     HWND hwndChild;
113     INT x, y, xspacing, yspacing;
114
115     GetClientRect( parent, &rectParent );
116     x = rectParent.left;
117     y = rectParent.bottom;
118     xspacing = GetSystemMetrics(SM_CXICONSPACING);
119     yspacing = GetSystemMetrics(SM_CYICONSPACING);
120
121     hwndChild = GetWindow( parent, GW_CHILD );
122     while (hwndChild)
123     {
124         if( IsIconic( hwndChild ) )
125         {
126             WINPOS_ShowIconTitle( hwndChild, FALSE );
127
128             SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
129                             y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
130                             SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
131             if( IsWindow(hwndChild) )
132                 WINPOS_ShowIconTitle(hwndChild , TRUE );
133
134             if (x <= rectParent.right - xspacing) x += xspacing;
135             else
136             {
137                 x = rectParent.left;
138                 y -= yspacing;
139             }
140         }
141         hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
142     }
143     return yspacing;
144 }
145
146
147 /***********************************************************************
148  *              SwitchToThisWindow (USER32.@)
149  */
150 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
151 {
152     ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
153 }
154
155
156 /***********************************************************************
157  *              GetWindowRect (USER32.@)
158  */
159 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
160 {
161     BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
162     if (ret)
163     {
164         MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
165         TRACE( "hwnd %04x (%d,%d)-(%d,%d)\n",
166                hwnd, rect->left, rect->top, rect->right, rect->bottom);
167     }
168     return ret;
169 }
170
171
172 /***********************************************************************
173  *              GetWindowRgn (USER32.@)
174  */
175 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
176 {
177     int nRet = ERROR;
178     WND *wndPtr = WIN_GetPtr( hwnd );
179
180     if (wndPtr == WND_OTHER_PROCESS)
181     {
182         if (IsWindow( hwnd ))
183             FIXME( "not supported on other process window %x\n", hwnd );
184         wndPtr = NULL;
185     }
186     if (!wndPtr)
187     {
188         SetLastError( ERROR_INVALID_WINDOW_HANDLE );
189         return ERROR;
190     }
191     if (wndPtr->hrgnWnd) nRet = CombineRgn( hrgn, wndPtr->hrgnWnd, 0, RGN_COPY );
192     WIN_ReleasePtr( wndPtr );
193     return nRet;
194 }
195
196
197 /***********************************************************************
198  *              SetWindowRgn (USER32.@)
199  */
200 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
201 {
202     RECT rect;
203     WND *wndPtr;
204
205     if (hrgn) /* verify that region really exists */
206     {
207         if (GetRgnBox( hrgn, &rect ) == ERROR) return FALSE;
208     }
209
210     if (USER_Driver.pSetWindowRgn)
211         return USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
212
213     if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
214     {
215         if (IsWindow( hwnd ))
216             FIXME( "not supported on other process window %x\n", hwnd );
217         wndPtr = NULL;
218     }
219     if (!wndPtr)
220     {
221         SetLastError( ERROR_INVALID_WINDOW_HANDLE );
222         return FALSE;
223     }
224
225     if (wndPtr->hrgnWnd == hrgn)
226     {
227         WIN_ReleasePtr( wndPtr );
228         return TRUE;
229     }
230
231     if (wndPtr->hrgnWnd)
232     {
233         /* delete previous region */
234         DeleteObject(wndPtr->hrgnWnd);
235         wndPtr->hrgnWnd = 0;
236     }
237     wndPtr->hrgnWnd = hrgn;
238     WIN_ReleasePtr( wndPtr );
239
240     /* Size the window to the rectangle of the new region (if it isn't NULL) */
241     if (hrgn) SetWindowPos( hwnd, 0, rect.left, rect.top,
242                             rect.right  - rect.left, rect.bottom - rect.top,
243                             SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE |
244                             SWP_NOZORDER | (bRedraw ? 0 : SWP_NOREDRAW) );
245     return TRUE;
246 }
247
248
249 /***********************************************************************
250  *              GetClientRect (USER32.@)
251  */
252 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
253 {
254     BOOL ret;
255
256     rect->right = rect->bottom = 0;
257     if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
258     {
259         rect->right -= rect->left;
260         rect->bottom -= rect->top;
261     }
262     rect->left = rect->top = 0;
263     return ret;
264 }
265
266
267 /*******************************************************************
268  *              ClientToScreen (USER32.@)
269  */
270 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
271 {
272     MapWindowPoints( hwnd, 0, lppnt, 1 );
273     return TRUE;
274 }
275
276
277 /*******************************************************************
278  *              ScreenToClient (USER32.@)
279  */
280 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
281 {
282     MapWindowPoints( 0, hwnd, lppnt, 1 );
283     return TRUE;
284 }
285
286
287 /***********************************************************************
288  *           find_child_from_point
289  *
290  * Find the child that contains pt. Helper for WindowFromPoint.
291  * pt is in parent client coordinates.
292  * lparam is the param to pass in the WM_NCHITTEST message.
293  */
294 static HWND find_child_from_point( HWND parent, POINT pt, INT *hittest, LPARAM lparam )
295 {
296     int i, res;
297     LONG style, exstyle;
298     RECT rectWindow, rectClient;
299     WND *wndPtr;
300     HWND *list = WIN_ListChildren( parent );
301     HWND retvalue = 0;
302
303     if (!list) return 0;
304     for (i = 0; list[i]; i++)
305     {
306         /* If point is in window, and window is visible, and it  */
307         /* is enabled (or it's a top-level window), then explore */
308         /* its children. Otherwise, go to the next window.       */
309
310         style = GetWindowLongW( list[i], GWL_STYLE );
311         if (!(style & WS_VISIBLE)) continue;  /* not visible -> skip */
312         if ((style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED))
313             continue;  /* disabled child -> skip */
314         exstyle = GetWindowLongW( list[i], GWL_EXSTYLE );
315         if ((exstyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) == (WS_EX_LAYERED | WS_EX_TRANSPARENT))
316             continue;  /* transparent -> skip */
317
318         if (!WIN_GetRectangles( list[i], &rectWindow, &rectClient )) continue;
319         if (!PtInRect( &rectWindow, pt )) continue;  /* not in window -> skip */
320
321         /* FIXME: check window region for other processes too */
322         if ((wndPtr = WIN_GetPtr( list[i] )) && wndPtr != WND_OTHER_PROCESS)
323         {
324             if (wndPtr->hrgnWnd && !PtInRegion( wndPtr->hrgnWnd,
325                                                 pt.x - rectWindow.left, pt.y - rectWindow.top ))
326             {
327                 WIN_ReleasePtr( wndPtr );
328                 continue;  /* point outside window region -> skip */
329             }
330             WIN_ReleasePtr( wndPtr );
331         }
332
333         /* If window is minimized or disabled, return at once */
334         if (style & WS_MINIMIZE)
335         {
336             *hittest = HTCAPTION;
337             retvalue = list[i];
338             break;
339         }
340         if (style & WS_DISABLED)
341         {
342             *hittest = HTERROR;
343             retvalue = list[i];
344             break;
345         }
346
347         /* If point is in client area, explore children */
348         if (PtInRect( &rectClient, pt ))
349         {
350             POINT new_pt;
351
352             new_pt.x = pt.x - rectClient.left;
353             new_pt.y = pt.y - rectClient.top;
354             if ((retvalue = find_child_from_point( list[i], new_pt, hittest, lparam ))) break;
355         }
356
357         /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
358         if (!WIN_IsCurrentThread( list[i] ))
359         {
360             *hittest = HTCLIENT;
361             retvalue = list[i];
362             break;
363         }
364         if ((res = SendMessageA( list[i], WM_NCHITTEST, 0, lparam )) != HTTRANSPARENT)
365         {
366             *hittest = res;  /* Found the window */
367             retvalue = list[i];
368             break;
369         }
370         /* continue search with next sibling */
371     }
372     HeapFree( GetProcessHeap(), 0, list );
373     return retvalue;
374 }
375
376
377 /***********************************************************************
378  *           WINPOS_WindowFromPoint
379  *
380  * Find the window and hittest for a given point.
381  */
382 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
383 {
384     POINT xy = pt;
385     int res;
386     LONG style;
387
388     TRACE("scope %04x %ld,%ld\n", hwndScope, pt.x, pt.y);
389
390     if (!hwndScope) hwndScope = GetDesktopWindow();
391     style = GetWindowLongW( hwndScope, GWL_STYLE );
392
393     *hittest = HTERROR;
394     if (style & WS_DISABLED) return 0;
395
396     MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope, GA_PARENT ), &xy, 1 );
397
398     if (!(style & WS_MINIMIZE))
399     {
400         RECT rectClient;
401         if (WIN_GetRectangles( hwndScope, NULL, &rectClient ) && PtInRect( &rectClient, xy ))
402         {
403             HWND ret;
404
405             xy.x -= rectClient.left;
406             xy.y -= rectClient.top;
407             if ((ret = find_child_from_point( hwndScope, xy, hittest, MAKELONG( pt.x, pt.y ) )))
408             {
409                 TRACE( "found child %x\n", ret );
410                 return ret;
411             }
412         }
413     }
414
415     /* If nothing found, try the scope window */
416     if (!WIN_IsCurrentThread( hwndScope ))
417     {
418         *hittest = HTCLIENT;
419         TRACE( "returning %x\n", hwndScope );
420         return hwndScope;
421     }
422     res = SendMessageA( hwndScope, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
423     if (res != HTTRANSPARENT)
424     {
425         *hittest = res;  /* Found the window */
426         TRACE( "returning %x\n", hwndScope );
427         return hwndScope;
428     }
429     *hittest = HTNOWHERE;
430     TRACE( "nothing found\n" );
431     return 0;
432 }
433
434
435 /*******************************************************************
436  *              WindowFromPoint (USER32.@)
437  */
438 HWND WINAPI WindowFromPoint( POINT pt )
439 {
440     INT hittest;
441     return WINPOS_WindowFromPoint( 0, pt, &hittest );
442 }
443
444
445 /*******************************************************************
446  *              ChildWindowFromPoint (USER32.@)
447  */
448 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
449 {
450     return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
451 }
452
453 /*******************************************************************
454  *              ChildWindowFromPointEx (USER32.@)
455  */
456 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
457 {
458     /* pt is in the client coordinates */
459     HWND *list;
460     int i;
461     RECT rect;
462     HWND retvalue;
463
464     GetClientRect( hwndParent, &rect );
465     if (!PtInRect( &rect, pt )) return 0;
466     if (!(list = WIN_ListChildren( hwndParent ))) return 0;
467
468     for (i = 0; list[i]; i++)
469     {
470         if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
471         if (!PtInRect( &rect, pt )) continue;
472         if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
473         {
474             LONG style = GetWindowLongW( list[i], GWL_STYLE );
475             if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
476             if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
477         }
478         if (uFlags & CWP_SKIPTRANSPARENT)
479         {
480             if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
481         }
482         break;
483     }
484     retvalue = list[i];
485     HeapFree( GetProcessHeap(), 0, list );
486     if (!retvalue) retvalue = hwndParent;
487     return retvalue;
488 }
489
490
491 /*******************************************************************
492  *         WINPOS_GetWinOffset
493  *
494  * Calculate the offset between the origin of the two windows. Used
495  * to implement MapWindowPoints.
496  */
497 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
498 {
499     WND * wndPtr;
500
501     offset->x = offset->y = 0;
502
503     /* Translate source window origin to screen coords */
504     if (hwndFrom)
505     {
506         HWND hwnd = hwndFrom;
507
508         while (hwnd)
509         {
510             if (hwnd == hwndTo) return;
511             if (!(wndPtr = WIN_GetPtr( hwnd )))
512             {
513                 ERR( "bad hwndFrom = %04x\n", hwnd );
514                 return;
515             }
516             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
517             offset->x += wndPtr->rectClient.left;
518             offset->y += wndPtr->rectClient.top;
519             hwnd = wndPtr->parent;
520             WIN_ReleasePtr( wndPtr );
521         }
522     }
523
524     /* Translate origin to destination window coords */
525     if (hwndTo)
526     {
527         HWND hwnd = hwndTo;
528
529         while (hwnd)
530         {
531             if (!(wndPtr = WIN_GetPtr( hwnd )))
532             {
533                 ERR( "bad hwndTo = %04x\n", hwnd );
534                 return;
535             }
536             if (wndPtr == WND_OTHER_PROCESS) goto other_process;
537             offset->x -= wndPtr->rectClient.left;
538             offset->y -= wndPtr->rectClient.top;
539             hwnd = wndPtr->parent;
540             WIN_ReleasePtr( wndPtr );
541         }
542     }
543     return;
544
545  other_process:  /* one of the parents may belong to another process, do it the hard way */
546     offset->x = offset->y = 0;
547     SERVER_START_REQ( get_windows_offset )
548     {
549         req->from = hwndFrom;
550         req->to   = hwndTo;
551         if (!wine_server_call( req ))
552         {
553             offset->x = reply->x;
554             offset->y = reply->y;
555         }
556     }
557     SERVER_END_REQ;
558 }
559
560
561 /*******************************************************************
562  *              MapWindowPoints (USER.258)
563  */
564 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
565                                LPPOINT16 lppt, UINT16 count )
566 {
567     POINT offset;
568
569     WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
570     while (count--)
571     {
572         lppt->x += offset.x;
573         lppt->y += offset.y;
574         lppt++;
575     }
576 }
577
578
579 /*******************************************************************
580  *              MapWindowPoints (USER32.@)
581  */
582 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
583 {
584     POINT offset;
585
586     WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
587     while (count--)
588     {
589         lppt->x += offset.x;
590         lppt->y += offset.y;
591         lppt++;
592     }
593     return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
594 }
595
596
597 /***********************************************************************
598  *              IsIconic (USER32.@)
599  */
600 BOOL WINAPI IsIconic(HWND hWnd)
601 {
602     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
603 }
604
605
606 /***********************************************************************
607  *              IsZoomed (USER32.@)
608  */
609 BOOL WINAPI IsZoomed(HWND hWnd)
610 {
611     return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
612 }
613
614
615 /*******************************************************************
616  *              AllowSetForegroundWindow (USER32.@)
617  */
618 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
619 {
620     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
621      * implemented, then fix this function. */
622     return TRUE;
623 }
624
625
626 /*******************************************************************
627  *              LockSetForegroundWindow (USER32.@)
628  */
629 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
630 {
631     /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
632      * implemented, then fix this function. */
633     return TRUE;
634 }
635
636
637 /*******************************************************************
638  *              SetShellWindow (USER32.@)
639  */
640 HWND WINAPI SetShellWindow(HWND hwndshell)
641 {   WARN("(hWnd=%08x) semi stub\n",hwndshell );
642
643     hGlobalShellWindow = WIN_GetFullHandle( hwndshell );
644     return hGlobalShellWindow;
645 }
646
647
648 /*******************************************************************
649  *              GetShellWindow (USER32.@)
650  */
651 HWND WINAPI GetShellWindow(void)
652 {   WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow );
653
654     return hGlobalShellWindow;
655 }
656
657
658 /***********************************************************************
659  *              BringWindowToTop (USER32.@)
660  */
661 BOOL WINAPI BringWindowToTop( HWND hwnd )
662 {
663     return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
664 }
665
666
667 /***********************************************************************
668  *              MoveWindow (USER32.@)
669  */
670 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
671                             BOOL repaint )
672 {
673     int flags = SWP_NOZORDER | SWP_NOACTIVATE;
674     if (!repaint) flags |= SWP_NOREDRAW;
675     TRACE("%04x %d,%d %dx%d %d\n",
676             hwnd, x, y, cx, cy, repaint );
677     return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
678 }
679
680 /***********************************************************************
681  *           WINPOS_InitInternalPos
682  */
683 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, const RECT *restoreRect )
684 {
685     LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf,
686                                                       atomInternalPos );
687     if( !lpPos )
688     {
689         /* this happens when the window is minimized/maximized
690          * for the first time (rectWindow is not adjusted yet) */
691
692         lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
693         if( !lpPos ) return NULL;
694
695         SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
696         lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
697         CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
698         *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF;
699     }
700
701     if( wnd->dwStyle & WS_MINIMIZE )
702         CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
703     else if( wnd->dwStyle & WS_MAXIMIZE )
704         CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
705     else if( restoreRect )
706         CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
707
708     return lpPos;
709 }
710
711 /***********************************************************************
712  *           WINPOS_RedrawIconTitle
713  */
714 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
715 {
716     LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
717     if( lpPos )
718     {
719         if( lpPos->hwndIconTitle )
720         {
721             SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
722             InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
723             return TRUE;
724         }
725     }
726     return FALSE;
727 }
728
729 /***********************************************************************
730  *           WINPOS_ShowIconTitle
731  */
732 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
733 {
734     LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
735
736     if( lpPos && !(GetWindowLongA( hwnd, GWL_EXSTYLE) & WS_EX_MANAGED))
737     {
738         HWND title = lpPos->hwndIconTitle;
739
740         TRACE("0x%04x %i\n", hwnd, (bShow != 0) );
741
742         if( !title )
743             lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
744         if( bShow )
745         {
746             if (!IsWindowVisible(title))
747             {
748                 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
749                 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
750                               SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
751             }
752         }
753         else ShowWindow( title, SW_HIDE );
754     }
755     return FALSE;
756 }
757
758 /*******************************************************************
759  *           WINPOS_GetMinMaxInfo
760  *
761  * Get the minimized and maximized information for a window.
762  */
763 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
764                            POINT *minTrack, POINT *maxTrack )
765 {
766     LPINTERNALPOS lpPos;
767     MINMAXINFO MinMax;
768     INT xinc, yinc;
769     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
770     LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
771
772     /* Compute default values */
773
774     MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
775     MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
776     MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
777     MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
778     MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
779     MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
780
781     if (HAS_DLGFRAME( style, exstyle ))
782     {
783         xinc = GetSystemMetrics(SM_CXDLGFRAME);
784         yinc = GetSystemMetrics(SM_CYDLGFRAME);
785     }
786     else
787     {
788         xinc = yinc = 0;
789         if (HAS_THICKFRAME(style))
790         {
791             xinc += GetSystemMetrics(SM_CXFRAME);
792             yinc += GetSystemMetrics(SM_CYFRAME);
793         }
794         if (style & WS_BORDER)
795         {
796             xinc += GetSystemMetrics(SM_CXBORDER);
797             yinc += GetSystemMetrics(SM_CYBORDER);
798         }
799     }
800     MinMax.ptMaxSize.x += 2 * xinc;
801     MinMax.ptMaxSize.y += 2 * yinc;
802
803     lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
804     if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
805         CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
806     else
807     {
808         MinMax.ptMaxPosition.x = -xinc;
809         MinMax.ptMaxPosition.y = -yinc;
810     }
811
812     SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
813
814       /* Some sanity checks */
815
816     TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
817                       MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
818                       MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
819                       MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
820                       MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
821     MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
822                                    MinMax.ptMinTrackSize.x );
823     MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
824                                    MinMax.ptMinTrackSize.y );
825
826     if (maxSize) *maxSize = MinMax.ptMaxSize;
827     if (maxPos) *maxPos = MinMax.ptMaxPosition;
828     if (minTrack) *minTrack = MinMax.ptMinTrackSize;
829     if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
830 }
831
832 /***********************************************************************
833  *              ShowWindowAsync (USER32.@)
834  *
835  * doesn't wait; returns immediately.
836  * used by threads to toggle windows in other (possibly hanging) threads
837  */
838 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
839 {
840     /* FIXME: does ShowWindow() return immediately ? */
841     return ShowWindow(hwnd, cmd);
842 }
843
844
845 /***********************************************************************
846  *              ShowWindow (USER32.@)
847  */
848 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
849 {
850     HWND full_handle;
851
852     if ((full_handle = WIN_IsCurrentThread( hwnd )))
853         return USER_Driver.pShowWindow( full_handle, cmd );
854     return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
855 }
856
857
858 /***********************************************************************
859  *              GetInternalWindowPos (USER.460)
860  */
861 UINT16 WINAPI GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd,
862                                       LPPOINT16 ptIcon )
863 {
864     WINDOWPLACEMENT16 wndpl;
865     if (GetWindowPlacement16( hwnd, &wndpl ))
866     {
867         if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
868         if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
869         return wndpl.showCmd;
870     }
871     return 0;
872 }
873
874
875 /***********************************************************************
876  *              GetInternalWindowPos (USER32.@)
877  */
878 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
879                                       LPPOINT ptIcon )
880 {
881     WINDOWPLACEMENT wndpl;
882     if (GetWindowPlacement( hwnd, &wndpl ))
883     {
884         if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
885         if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
886         return wndpl.showCmd;
887     }
888     return 0;
889 }
890
891
892 /***********************************************************************
893  *              GetWindowPlacement (USER32.@)
894  *
895  * Win95:
896  * Fails if wndpl->length of Win95 (!) apps is invalid.
897  */
898 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
899 {
900     WND *pWnd = WIN_FindWndPtr( hwnd );
901     LPINTERNALPOS lpPos;
902
903     if(!pWnd ) return FALSE;
904
905     lpPos = WINPOS_InitInternalPos( pWnd, *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
906     wndpl->length  = sizeof(*wndpl);
907     if( pWnd->dwStyle & WS_MINIMIZE )
908         wndpl->showCmd = SW_SHOWMINIMIZED;
909     else
910         wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
911     if( pWnd->flags & WIN_RESTORE_MAX )
912         wndpl->flags = WPF_RESTORETOMAXIMIZED;
913     else
914         wndpl->flags = 0;
915     CONV_POINT16TO32( &lpPos->ptIconPos, &wndpl->ptMinPosition );
916     CONV_POINT16TO32( &lpPos->ptMaxPos, &wndpl->ptMaxPosition );
917     CONV_RECT16TO32( &lpPos->rectNormal, &wndpl->rcNormalPosition );
918     WIN_ReleaseWndPtr(pWnd);
919     return TRUE;
920 }
921
922
923 /***********************************************************************
924  *           WINPOS_SetPlacement
925  */
926 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
927 {
928     WND *pWnd = WIN_FindWndPtr( hwnd );
929     if( pWnd )
930     {
931         LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
932                              *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
933
934         if( flags & PLACE_MIN ) CONV_POINT32TO16( &wndpl->ptMinPosition, &lpPos->ptIconPos );
935         if( flags & PLACE_MAX ) CONV_POINT32TO16( &wndpl->ptMaxPosition, &lpPos->ptMaxPos );
936         if( flags & PLACE_RECT) CONV_RECT32TO16( &wndpl->rcNormalPosition, &lpPos->rectNormal );
937
938         if( pWnd->dwStyle & WS_MINIMIZE )
939         {
940             WINPOS_ShowIconTitle( pWnd->hwndSelf, FALSE );
941             if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
942                 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
943                                 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
944         }
945         else if( pWnd->dwStyle & WS_MAXIMIZE )
946         {
947             if( !EMPTYPOINT(lpPos->ptMaxPos) )
948                 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
949                                 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
950         }
951         else if( flags & PLACE_RECT )
952                 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
953                                 lpPos->rectNormal.right - lpPos->rectNormal.left,
954                                 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
955                                 SWP_NOZORDER | SWP_NOACTIVATE );
956
957         ShowWindow( hwnd, wndpl->showCmd );
958         if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
959         {
960             if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd->hwndSelf, TRUE );
961
962             /* SDK: ...valid only the next time... */
963             if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
964         }
965         WIN_ReleaseWndPtr(pWnd);
966         return TRUE;
967     }
968     return FALSE;
969 }
970
971
972 /***********************************************************************
973  *              SetWindowPlacement (USER32.@)
974  *
975  * Win95:
976  * Fails if wndpl->length of Win95 (!) apps is invalid.
977  */
978 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
979 {
980     if (!wpl) return FALSE;
981     return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
982 }
983
984
985 /***********************************************************************
986  *              AnimateWindow (USER32.@)
987  *              Shows/Hides a window with an animation
988  *              NO ANIMATION YET
989  */
990 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
991 {
992         FIXME("partial stub\n");
993
994         /* If trying to show/hide and it's already   *
995          * shown/hidden or invalid window, fail with *
996          * invalid parameter                         */
997         if(!IsWindow(hwnd) ||
998            (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
999            (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1000         {
1001                 SetLastError(ERROR_INVALID_PARAMETER);
1002                 return FALSE;
1003         }
1004
1005         ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1006
1007         return TRUE;
1008 }
1009
1010 /***********************************************************************
1011  *              SetInternalWindowPos (USER32.@)
1012  */
1013 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1014                                     LPRECT rect, LPPOINT pt )
1015 {
1016     if( IsWindow(hwnd) )
1017     {
1018         WINDOWPLACEMENT wndpl;
1019         UINT flags;
1020
1021         wndpl.length  = sizeof(wndpl);
1022         wndpl.showCmd = showCmd;
1023         wndpl.flags = flags = 0;
1024
1025         if( pt )
1026         {
1027             flags |= PLACE_MIN;
1028             wndpl.flags |= WPF_SETMINPOSITION;
1029             wndpl.ptMinPosition = *pt;
1030         }
1031         if( rect )
1032         {
1033             flags |= PLACE_RECT;
1034             wndpl.rcNormalPosition = *rect;
1035         }
1036         WINPOS_SetPlacement( hwnd, &wndpl, flags );
1037     }
1038 }
1039
1040
1041 /*******************************************************************
1042  *         can_activate_window
1043  *
1044  * Check if we can activate the specified window.
1045  */
1046 static BOOL can_activate_window( HWND hwnd )
1047 {
1048     LONG style;
1049
1050     if (!hwnd) return FALSE;
1051     style = GetWindowLongW( hwnd, GWL_STYLE );
1052     if (!(style & WS_VISIBLE)) return FALSE;
1053     if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1054     return !(style & WS_DISABLED);
1055 }
1056
1057
1058 /*******************************************************************
1059  *         WINPOS_ActivateOtherWindow
1060  *
1061  *  Activates window other than pWnd.
1062  */
1063 void WINPOS_ActivateOtherWindow(HWND hwnd)
1064 {
1065     HWND hwndTo, fg;
1066
1067     if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1068     {
1069         hwndTo = GetAncestor( hwndTo, GA_ROOT );
1070         if (can_activate_window( hwndTo )) goto done;
1071     }
1072
1073     hwndTo = hwnd;
1074     for (;;)
1075     {
1076         if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1077         if (can_activate_window( hwndTo )) break;
1078     }
1079
1080  done:
1081     fg = GetForegroundWindow();
1082     TRACE("win = %x fg = %x\n", hwndTo, fg);
1083     if (!fg || (hwnd == fg))
1084     {
1085         if (SetForegroundWindow( hwndTo )) return;
1086     }
1087     if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1088 }
1089
1090
1091 /***********************************************************************
1092  *           WINPOS_HandleWindowPosChanging16
1093  *
1094  * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1095  */
1096 LONG WINPOS_HandleWindowPosChanging16( HWND hwnd, WINDOWPOS16 *winpos )
1097 {
1098     POINT maxSize, minTrack;
1099     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1100
1101     if (winpos->flags & SWP_NOSIZE) return 0;
1102     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1103     {
1104         WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1105         if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1106         if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1107         if (!(style & WS_MINIMIZE))
1108         {
1109             if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1110             if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1111         }
1112     }
1113     return 0;
1114 }
1115
1116
1117 /***********************************************************************
1118  *           WINPOS_HandleWindowPosChanging
1119  *
1120  * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1121  */
1122 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1123 {
1124     POINT maxSize, minTrack;
1125     LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1126
1127     if (winpos->flags & SWP_NOSIZE) return 0;
1128     if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1129     {
1130         WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1131         winpos->cx = min( winpos->cx, maxSize.x );
1132         winpos->cy = min( winpos->cy, maxSize.y );
1133         if (!(style & WS_MINIMIZE))
1134         {
1135             if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1136             if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1137         }
1138     }
1139     return 0;
1140 }
1141
1142
1143 /***********************************************************************
1144  *           dump_winpos_flags
1145  */
1146 static void dump_winpos_flags(UINT flags)
1147 {
1148     TRACE("flags:");
1149     if(flags & SWP_NOSIZE) DPRINTF(" SWP_NOSIZE");
1150     if(flags & SWP_NOMOVE) DPRINTF(" SWP_NOMOVE");
1151     if(flags & SWP_NOZORDER) DPRINTF(" SWP_NOZORDER");
1152     if(flags & SWP_NOREDRAW) DPRINTF(" SWP_NOREDRAW");
1153     if(flags & SWP_NOACTIVATE) DPRINTF(" SWP_NOACTIVATE");
1154     if(flags & SWP_FRAMECHANGED) DPRINTF(" SWP_FRAMECHANGED");
1155     if(flags & SWP_SHOWWINDOW) DPRINTF(" SWP_SHOWWINDOW");
1156     if(flags & SWP_HIDEWINDOW) DPRINTF(" SWP_HIDEWINDOW");
1157     if(flags & SWP_NOCOPYBITS) DPRINTF(" SWP_NOCOPYBITS");
1158     if(flags & SWP_NOOWNERZORDER) DPRINTF(" SWP_NOOWNERZORDER");
1159     if(flags & SWP_NOSENDCHANGING) DPRINTF(" SWP_NOSENDCHANGING");
1160     if(flags & SWP_DEFERERASE) DPRINTF(" SWP_DEFERERASE");
1161     if(flags & SWP_ASYNCWINDOWPOS) DPRINTF(" SWP_ASYNCWINDOWPOS");
1162
1163 #define DUMPED_FLAGS \
1164     (SWP_NOSIZE | \
1165     SWP_NOMOVE | \
1166     SWP_NOZORDER | \
1167     SWP_NOREDRAW | \
1168     SWP_NOACTIVATE | \
1169     SWP_FRAMECHANGED | \
1170     SWP_SHOWWINDOW | \
1171     SWP_HIDEWINDOW | \
1172     SWP_NOCOPYBITS | \
1173     SWP_NOOWNERZORDER | \
1174     SWP_NOSENDCHANGING | \
1175     SWP_DEFERERASE | \
1176     SWP_ASYNCWINDOWPOS)
1177
1178     if(flags & ~DUMPED_FLAGS) DPRINTF(" %08x", flags & ~DUMPED_FLAGS);
1179     DPRINTF("\n");
1180 #undef DUMPED_FLAGS
1181 }
1182
1183 /***********************************************************************
1184  *              SetWindowPos (USER32.@)
1185  */
1186 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1187                           INT x, INT y, INT cx, INT cy, UINT flags )
1188 {
1189     WINDOWPOS winpos;
1190
1191     TRACE("hwnd %x, after %x, %d,%d (%dx%d), flags %08x\n",
1192            hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1193     if(TRACE_ON(win)) dump_winpos_flags(flags);
1194
1195     winpos.hwnd = hwnd;
1196     winpos.hwndInsertAfter = hwndInsertAfter;
1197     winpos.x = x;
1198     winpos.y = y;
1199     winpos.cx = cx;
1200     winpos.cy = cy;
1201     winpos.flags = flags;
1202     if (WIN_IsCurrentThread( hwnd )) return USER_Driver.pSetWindowPos( &winpos );
1203     return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1204 }
1205
1206
1207 /***********************************************************************
1208  *              BeginDeferWindowPos (USER32.@)
1209  */
1210 HDWP WINAPI BeginDeferWindowPos( INT count )
1211 {
1212     HDWP handle;
1213     DWP *pDWP;
1214
1215     if (count < 0)
1216     {
1217         SetLastError(ERROR_INVALID_PARAMETER);
1218         return 0;
1219     }
1220     /* Windows allows zero count, in which case it allocates context for 8 moves */
1221     if (count == 0) count = 8;
1222
1223     handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1224     if (!handle) return 0;
1225     pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1226     pDWP->actualCount    = 0;
1227     pDWP->suggestedCount = count;
1228     pDWP->valid          = TRUE;
1229     pDWP->wMagic         = DWP_MAGIC;
1230     pDWP->hwndParent     = 0;
1231     return handle;
1232 }
1233
1234
1235 /***********************************************************************
1236  *              DeferWindowPos (USER32.@)
1237  */
1238 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1239                                 INT x, INT y, INT cx, INT cy,
1240                                 UINT flags )
1241 {
1242     DWP *pDWP;
1243     int i;
1244     HDWP newhdwp = hdwp,retvalue;
1245
1246     hwnd = WIN_GetFullHandle( hwnd );
1247     if (hwnd == GetDesktopWindow()) return 0;
1248
1249     if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1250
1251     USER_Lock();
1252
1253     for (i = 0; i < pDWP->actualCount; i++)
1254     {
1255         if (pDWP->winPos[i].hwnd == hwnd)
1256         {
1257               /* Merge with the other changes */
1258             if (!(flags & SWP_NOZORDER))
1259             {
1260                 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1261             }
1262             if (!(flags & SWP_NOMOVE))
1263             {
1264                 pDWP->winPos[i].x = x;
1265                 pDWP->winPos[i].y = y;
1266             }
1267             if (!(flags & SWP_NOSIZE))
1268             {
1269                 pDWP->winPos[i].cx = cx;
1270                 pDWP->winPos[i].cy = cy;
1271             }
1272             pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1273                                                SWP_NOZORDER | SWP_NOREDRAW |
1274                                                SWP_NOACTIVATE | SWP_NOCOPYBITS|
1275                                                SWP_NOOWNERZORDER);
1276             pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1277                                               SWP_FRAMECHANGED);
1278             retvalue = hdwp;
1279             goto END;
1280         }
1281     }
1282     if (pDWP->actualCount >= pDWP->suggestedCount)
1283     {
1284         newhdwp = USER_HEAP_REALLOC( hdwp,
1285                       sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1286         if (!newhdwp)
1287         {
1288             retvalue = 0;
1289             goto END;
1290         }
1291         pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1292         pDWP->suggestedCount++;
1293     }
1294     pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1295     pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1296     pDWP->winPos[pDWP->actualCount].x = x;
1297     pDWP->winPos[pDWP->actualCount].y = y;
1298     pDWP->winPos[pDWP->actualCount].cx = cx;
1299     pDWP->winPos[pDWP->actualCount].cy = cy;
1300     pDWP->winPos[pDWP->actualCount].flags = flags;
1301     pDWP->actualCount++;
1302     retvalue = newhdwp;
1303 END:
1304     USER_Unlock();
1305     return retvalue;
1306 }
1307
1308
1309 /***********************************************************************
1310  *              EndDeferWindowPos (USER32.@)
1311  */
1312 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1313 {
1314     DWP *pDWP;
1315     WINDOWPOS *winpos;
1316     BOOL res = TRUE;
1317     int i;
1318
1319     pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1320     if (!pDWP) return FALSE;
1321     for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1322     {
1323         if (!(res = USER_Driver.pSetWindowPos( winpos ))) break;
1324     }
1325     USER_HEAP_FREE( hdwp );
1326     return res;
1327 }
1328
1329
1330 /***********************************************************************
1331  *              TileChildWindows (USER.199)
1332  */
1333 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1334 {
1335     FIXME("(%04x, %d): stub\n", parent, action);
1336 }
1337
1338 /***********************************************************************
1339  *              CascadeChildWindows (USER.198)
1340  */
1341 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1342 {
1343     FIXME("(%04x, %d): stub\n", parent, action);
1344 }
1345
1346 /***********************************************************************
1347  *              SetProgmanWindow (USER32.@)
1348  */
1349 HWND WINAPI SetProgmanWindow ( HWND hwnd )
1350 {
1351         hGlobalProgmanWindow = hwnd;
1352         return hGlobalProgmanWindow;
1353 }
1354
1355 /***********************************************************************
1356  *              GetProgmanWindow (USER32.@)
1357  */
1358 HWND WINAPI GetProgmanWindow(void)
1359 {
1360         return hGlobalProgmanWindow;
1361 }
1362
1363 /***********************************************************************
1364  *              SetShellWindowEx (USER32.@)
1365  * hwndProgman =  Progman[Program Manager]
1366  *                |-> SHELLDLL_DefView
1367  * hwndListView = |   |-> SysListView32
1368  *                |   |   |-> tooltips_class32
1369  *                |   |
1370  *                |   |-> SysHeader32
1371  *                |
1372  *                |-> ProxyTarget
1373  */
1374 HWND WINAPI SetShellWindowEx ( HWND hwndProgman, HWND hwndListView )
1375 {
1376         FIXME("0x%08x 0x%08x stub\n",hwndProgman ,hwndListView );
1377         hGlobalShellWindow = hwndProgman;
1378         return hGlobalShellWindow;
1379
1380 }
1381
1382 /***********************************************************************
1383  *              SetTaskmanWindow (USER32.@)
1384  * NOTES
1385  *   hwnd = MSTaskSwWClass
1386  *          |-> SysTabControl32
1387  */
1388 HWND WINAPI SetTaskmanWindow ( HWND hwnd )
1389 {
1390         hGlobalTaskmanWindow = hwnd;
1391         return hGlobalTaskmanWindow;
1392 }
1393
1394 /***********************************************************************
1395  *              GetTaskmanWindow (USER32.@)
1396  */
1397 HWND WINAPI GetTaskmanWindow(void)
1398 {
1399         return hGlobalTaskmanWindow;
1400 }