2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
13 #include "wine/winuser16.h"
14 #include "wine/server.h"
24 #include "nonclient.h"
25 #include "debugtools.h"
28 DEFAULT_DEBUG_CHANNEL(win);
30 #define HAS_DLGFRAME(style,exStyle) \
31 (((exStyle) & WS_EX_DLGMODALFRAME) || \
32 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
34 #define HAS_THICKFRAME(style) \
35 (((style) & WS_THICKFRAME) && \
36 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
38 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
40 #define PLACE_MIN 0x0001
41 #define PLACE_MAX 0x0002
42 #define PLACE_RECT 0x0004
45 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
57 /* ----- internal variables ----- */
59 static HWND hwndPrevActive = 0; /* Previously active window */
60 static HWND hGlobalShellWindow=0; /*the shell*/
61 static HWND hGlobalTaskmanWindow=0;
62 static HWND hGlobalProgmanWindow=0;
64 static LPCSTR atomInternalPos;
66 extern HQUEUE16 hActiveQueue;
68 /***********************************************************************
69 * WINPOS_CreateInternalPosAtom
71 BOOL WINPOS_CreateInternalPosAtom()
74 atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
75 return (atomInternalPos) ? TRUE : FALSE;
78 /***********************************************************************
79 * WINPOS_CheckInternalPos
81 * Called when a window is destroyed.
83 void WINPOS_CheckInternalPos( HWND hwnd )
86 MESSAGEQUEUE *pMsgQ = 0;
87 WND *wndPtr = WIN_GetPtr( hwnd );
89 if (!wndPtr || wndPtr == WND_OTHER_PROCESS) return;
91 lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
93 /* Retrieve the message queue associated with this window */
94 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
97 WARN("\tMessage queue not found. Exiting!\n" );
98 WIN_ReleasePtr( wndPtr );
102 if( hwnd == hwndPrevActive ) hwndPrevActive = 0;
104 if( hwnd == PERQDATA_GetActiveWnd( pMsgQ->pQData ) )
106 PERQDATA_SetActiveWnd( pMsgQ->pQData, 0 );
107 WARN("\tattempt to activate destroyed window!\n");
112 if( IsWindow(lpPos->hwndIconTitle) )
113 DestroyWindow( lpPos->hwndIconTitle );
114 HeapFree( GetProcessHeap(), 0, lpPos );
117 QUEUE_Unlock( pMsgQ );
118 WIN_ReleasePtr( wndPtr );
121 /***********************************************************************
122 * ArrangeIconicWindows (USER32.@)
124 UINT WINAPI ArrangeIconicWindows( HWND parent )
128 INT x, y, xspacing, yspacing;
130 GetClientRect( parent, &rectParent );
132 y = rectParent.bottom;
133 xspacing = GetSystemMetrics(SM_CXICONSPACING);
134 yspacing = GetSystemMetrics(SM_CYICONSPACING);
136 hwndChild = GetWindow( parent, GW_CHILD );
139 if( IsIconic( hwndChild ) )
141 WINPOS_ShowIconTitle( hwndChild, FALSE );
143 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
144 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
145 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
146 if( IsWindow(hwndChild) )
147 WINPOS_ShowIconTitle(hwndChild , TRUE );
149 if (x <= rectParent.right - xspacing) x += xspacing;
156 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
162 /***********************************************************************
163 * SwitchToThisWindow (USER32.@)
165 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
167 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
171 /***********************************************************************
172 * GetWindowRect (USER32.@)
174 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
176 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
179 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
180 TRACE( "hwnd %04x (%d,%d)-(%d,%d)\n",
181 hwnd, rect->left, rect->top, rect->right, rect->bottom);
187 /***********************************************************************
188 * GetWindowRgn (USER32.@)
190 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
193 WND *wndPtr = WIN_GetPtr( hwnd );
195 if (wndPtr == WND_OTHER_PROCESS)
197 if (IsWindow( hwnd ))
198 FIXME( "not supported on other process window %x\n", hwnd );
203 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
206 if (wndPtr->hrgnWnd) nRet = CombineRgn( hrgn, wndPtr->hrgnWnd, 0, RGN_COPY );
207 WIN_ReleasePtr( wndPtr );
212 /***********************************************************************
213 * SetWindowRgn (USER32.@)
215 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
220 if (hrgn) /* verify that region really exists */
222 if (GetRgnBox( hrgn, &rect ) == ERROR) return FALSE;
225 if (USER_Driver.pSetWindowRgn)
226 return USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
228 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
230 if (IsWindow( hwnd ))
231 FIXME( "not supported on other process window %x\n", hwnd );
236 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
240 if (wndPtr->hrgnWnd == hrgn)
242 WIN_ReleasePtr( wndPtr );
248 /* delete previous region */
249 DeleteObject(wndPtr->hrgnWnd);
252 wndPtr->hrgnWnd = hrgn;
253 WIN_ReleasePtr( wndPtr );
255 /* Size the window to the rectangle of the new region (if it isn't NULL) */
256 if (hrgn) SetWindowPos( hwnd, 0, rect.left, rect.top,
257 rect.right - rect.left, rect.bottom - rect.top,
258 SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE |
259 SWP_NOZORDER | (bRedraw ? 0 : SWP_NOREDRAW) );
264 /***********************************************************************
265 * GetClientRect (USER32.@)
267 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
271 rect->right = rect->bottom = 0;
272 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
274 rect->right -= rect->left;
275 rect->bottom -= rect->top;
277 rect->left = rect->top = 0;
282 /*******************************************************************
283 * ClientToScreen (USER32.@)
285 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
287 MapWindowPoints( hwnd, 0, lppnt, 1 );
292 /*******************************************************************
293 * ScreenToClient (USER32.@)
295 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
297 MapWindowPoints( 0, hwnd, lppnt, 1 );
302 /***********************************************************************
303 * find_child_from_point
305 * Find the child that contains pt. Helper for WindowFromPoint.
306 * pt is in parent client coordinates.
307 * lparam is the param to pass in the WM_NCHITTEST message.
309 static HWND find_child_from_point( HWND parent, POINT pt, INT *hittest, LPARAM lparam )
313 RECT rectWindow, rectClient;
315 HWND *list = WIN_ListChildren( parent );
318 for (i = 0; list[i]; i++)
320 /* If point is in window, and window is visible, and it */
321 /* is enabled (or it's a top-level window), then explore */
322 /* its children. Otherwise, go to the next window. */
324 style = GetWindowLongW( list[i], GWL_STYLE );
325 if (!(style & WS_VISIBLE)) continue; /* not visible -> skip */
326 if ((style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED))
327 continue; /* disabled child -> skip */
328 exstyle = GetWindowLongW( list[i], GWL_EXSTYLE );
329 if ((exstyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) == (WS_EX_LAYERED | WS_EX_TRANSPARENT))
330 continue; /* transparent -> skip */
332 if (!WIN_GetRectangles( list[i], &rectWindow, &rectClient )) continue;
333 if (!PtInRect( &rectWindow, pt )) continue; /* not in window -> skip */
335 /* FIXME: check window region for other processes too */
336 if ((wndPtr = WIN_GetPtr( list[i] )) && wndPtr != WND_OTHER_PROCESS)
338 if (wndPtr->hrgnWnd && !PtInRegion( wndPtr->hrgnWnd,
339 pt.x - rectWindow.left, pt.y - rectWindow.top ))
341 WIN_ReleasePtr( wndPtr );
342 continue; /* point outside window region -> skip */
344 WIN_ReleasePtr( wndPtr );
347 /* If window is minimized or disabled, return at once */
348 if (style & WS_MINIMIZE)
350 *hittest = HTCAPTION;
353 if (style & WS_DISABLED)
359 /* If point is in client area, explore children */
360 if (PtInRect( &rectClient, pt ))
365 new_pt.x = pt.x - rectClient.left;
366 new_pt.y = pt.y - rectClient.top;
367 if ((ret = find_child_from_point( list[i], new_pt, hittest, lparam )))
371 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
372 if (!WIN_IsCurrentThread( list[i] ))
377 if ((res = SendMessageA( list[i], WM_NCHITTEST, 0, lparam )) != HTTRANSPARENT)
379 *hittest = res; /* Found the window */
382 /* continue search with next sibling */
388 /***********************************************************************
389 * WINPOS_WindowFromPoint
391 * Find the window and hittest for a given point.
393 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
399 TRACE("scope %04x %ld,%ld\n", hwndScope, pt.x, pt.y);
401 if (!hwndScope) hwndScope = GetDesktopWindow();
402 style = GetWindowLongW( hwndScope, GWL_STYLE );
405 if (style & WS_DISABLED) return 0;
407 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope, GA_PARENT ), &xy, 1 );
409 if (!(style & WS_MINIMIZE))
412 if (WIN_GetRectangles( hwndScope, NULL, &rectClient ) && PtInRect( &rectClient, xy ))
416 xy.x -= rectClient.left;
417 xy.y -= rectClient.top;
418 if ((ret = find_child_from_point( hwndScope, xy, hittest, MAKELONG( pt.x, pt.y ) )))
420 TRACE( "found child %x\n", ret );
426 /* If nothing found, try the scope window */
427 if (!WIN_IsCurrentThread( hwndScope ))
430 TRACE( "returning %x\n", hwndScope );
433 res = SendMessageA( hwndScope, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
434 if (res != HTTRANSPARENT)
436 *hittest = res; /* Found the window */
437 TRACE( "returning %x\n", hwndScope );
440 *hittest = HTNOWHERE;
441 TRACE( "nothing found\n" );
446 /*******************************************************************
447 * WindowFromPoint (USER32.@)
449 HWND WINAPI WindowFromPoint( POINT pt )
452 return WINPOS_WindowFromPoint( 0, pt, &hittest );
456 /*******************************************************************
457 * ChildWindowFromPoint (USER32.@)
459 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
461 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
464 /*******************************************************************
465 * ChildWindowFromPointEx (USER32.@)
467 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
469 /* pt is in the client coordinates */
475 GetClientRect( hwndParent, &rect );
476 if (!PtInRect( &rect, pt )) return 0;
477 if (!(list = WIN_ListChildren( hwndParent ))) return 0;
479 for (i = 0; list[i]; i++)
481 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
482 if (!PtInRect( &rect, pt )) continue;
483 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
485 LONG style = GetWindowLongW( list[i], GWL_STYLE );
486 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
487 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
489 if (uFlags & CWP_SKIPTRANSPARENT)
491 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
496 HeapFree( GetProcessHeap(), 0, list );
497 if (!retvalue) retvalue = hwndParent;
502 /*******************************************************************
503 * WINPOS_GetWinOffset
505 * Calculate the offset between the origin of the two windows. Used
506 * to implement MapWindowPoints.
508 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
512 offset->x = offset->y = 0;
514 /* Translate source window origin to screen coords */
517 HWND hwnd = hwndFrom;
521 if (hwnd == hwndTo) return;
522 if (!(wndPtr = WIN_GetPtr( hwnd )))
524 ERR( "bad hwndFrom = %04x\n", hwnd );
527 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
528 offset->x += wndPtr->rectClient.left;
529 offset->y += wndPtr->rectClient.top;
530 hwnd = wndPtr->parent;
531 WIN_ReleasePtr( wndPtr );
535 /* Translate origin to destination window coords */
542 if (!(wndPtr = WIN_GetPtr( hwnd )))
544 ERR( "bad hwndTo = %04x\n", hwnd );
547 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
548 offset->x -= wndPtr->rectClient.left;
549 offset->y -= wndPtr->rectClient.top;
550 hwnd = wndPtr->parent;
551 WIN_ReleasePtr( wndPtr );
556 other_process: /* one of the parents may belong to another process, do it the hard way */
557 offset->x = offset->y = 0;
558 SERVER_START_REQ( get_windows_offset )
560 req->from = hwndFrom;
562 if (!wine_server_call( req ))
564 offset->x = reply->x;
565 offset->y = reply->y;
572 /*******************************************************************
573 * MapWindowPoints (USER.258)
575 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
576 LPPOINT16 lppt, UINT16 count )
580 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
590 /*******************************************************************
591 * MapWindowPoints (USER32.@)
593 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
597 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
604 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
608 /***********************************************************************
609 * IsIconic (USER32.@)
611 BOOL WINAPI IsIconic(HWND hWnd)
613 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
617 /***********************************************************************
618 * IsZoomed (USER32.@)
620 BOOL WINAPI IsZoomed(HWND hWnd)
622 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
626 /*******************************************************************
627 * GetActiveWindow (USER32.@)
629 HWND WINAPI GetActiveWindow(void)
631 MESSAGEQUEUE *pCurMsgQ = 0;
633 /* Get the messageQ for the current thread */
634 if (!(pCurMsgQ = QUEUE_Current()))
636 WARN("\tCurrent message queue not found. Exiting!\n" );
640 /* Return the current active window from the perQ data of the current message Q */
641 return PERQDATA_GetActiveWnd( pCurMsgQ->pQData );
645 /*******************************************************************
648 static BOOL WINPOS_CanActivate(HWND hwnd)
650 if (!hwnd) return FALSE;
651 return ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_DISABLED|WS_CHILD)) == 0);
654 /*******************************************************************
657 static BOOL WINPOS_IsVisible(HWND hwnd)
659 if (!hwnd) return FALSE;
660 return ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_VISIBLE) == WS_VISIBLE);
664 /*******************************************************************
665 * SetActiveWindow (USER32.@)
667 HWND WINAPI SetActiveWindow( HWND hwnd )
670 WND *wndPtr = WIN_FindWndPtr( hwnd );
671 MESSAGEQUEUE *pMsgQ = 0, *pCurMsgQ = 0;
673 if (!wndPtr) return 0;
675 if (wndPtr->dwStyle & (WS_DISABLED | WS_CHILD)) goto error;
677 /* Get the messageQ for the current thread */
678 if (!(pCurMsgQ = QUEUE_Current()))
680 WARN("\tCurrent message queue not found. Exiting!\n" );
684 /* Retrieve the message queue associated with this window */
685 pMsgQ = (MESSAGEQUEUE *)QUEUE_Lock( wndPtr->hmemTaskQ );
688 WARN("\tWindow message queue not found. Exiting!\n" );
692 /* Make sure that the window is associated with the calling threads
693 * message queue. It must share the same perQ data.
695 if ( pCurMsgQ->pQData != pMsgQ->pQData )
697 QUEUE_Unlock( pMsgQ );
701 /* Save current active window */
702 prev = PERQDATA_GetActiveWnd( pMsgQ->pQData );
703 QUEUE_Unlock( pMsgQ );
704 WIN_ReleaseWndPtr(wndPtr);
705 WINPOS_SetActiveWindow( hwnd, FALSE, TRUE );
709 WIN_ReleaseWndPtr(wndPtr);
714 /*******************************************************************
715 * GetForegroundWindow (USER32.@)
717 HWND WINAPI GetForegroundWindow(void)
721 /* Get the foreground window (active window of hActiveQueue) */
724 MESSAGEQUEUE *pActiveQueue = QUEUE_Lock( hActiveQueue );
726 hwndActive = PERQDATA_GetActiveWnd( pActiveQueue->pQData );
728 QUEUE_Unlock( pActiveQueue );
734 /*******************************************************************
735 * SetForegroundWindow (USER32.@)
737 BOOL WINAPI SetForegroundWindow( HWND hwnd )
739 if (!hwnd) return WINPOS_SetActiveWindow( 0, FALSE, TRUE );
741 /* child windows get WM_CHILDACTIVATE message */
742 if ((GetWindowLongW( hwnd, GWL_STYLE ) & (WS_CHILD | WS_POPUP)) == WS_CHILD)
743 return SendMessageA( hwnd, WM_CHILDACTIVATE, 0, 0 );
745 hwnd = WIN_GetFullHandle( hwnd );
746 if( hwnd == GetForegroundWindow() ) return FALSE;
748 return WINPOS_SetActiveWindow( hwnd, FALSE, TRUE );
752 /*******************************************************************
753 * AllowSetForegroundWindow (USER32.@)
755 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
757 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
758 * implemented, then fix this function. */
763 /*******************************************************************
764 * LockSetForegroundWindow (USER32.@)
766 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
768 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
769 * implemented, then fix this function. */
774 /*******************************************************************
775 * SetShellWindow (USER32.@)
777 HWND WINAPI SetShellWindow(HWND hwndshell)
778 { WARN("(hWnd=%08x) semi stub\n",hwndshell );
780 hGlobalShellWindow = WIN_GetFullHandle( hwndshell );
781 return hGlobalShellWindow;
785 /*******************************************************************
786 * GetShellWindow (USER32.@)
788 HWND WINAPI GetShellWindow(void)
789 { WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow );
791 return hGlobalShellWindow;
795 /***********************************************************************
796 * BringWindowToTop (USER32.@)
798 BOOL WINAPI BringWindowToTop( HWND hwnd )
800 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
804 /***********************************************************************
805 * MoveWindow (USER32.@)
807 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
810 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
811 if (!repaint) flags |= SWP_NOREDRAW;
812 TRACE("%04x %d,%d %dx%d %d\n",
813 hwnd, x, y, cx, cy, repaint );
814 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
817 /***********************************************************************
818 * WINPOS_InitInternalPos
820 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, const RECT *restoreRect )
822 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf,
826 /* this happens when the window is minimized/maximized
827 * for the first time (rectWindow is not adjusted yet) */
829 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
830 if( !lpPos ) return NULL;
832 SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
833 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
834 CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
835 *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF;
838 if( wnd->dwStyle & WS_MINIMIZE )
839 CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
840 else if( wnd->dwStyle & WS_MAXIMIZE )
841 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
842 else if( restoreRect )
843 CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
848 /***********************************************************************
849 * WINPOS_RedrawIconTitle
851 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
853 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
856 if( lpPos->hwndIconTitle )
858 SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
859 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
866 /***********************************************************************
867 * WINPOS_ShowIconTitle
869 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
871 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
873 if( lpPos && !(GetWindowLongA( hwnd, GWL_EXSTYLE) & WS_EX_MANAGED))
875 HWND title = lpPos->hwndIconTitle;
877 TRACE("0x%04x %i\n", hwnd, (bShow != 0) );
880 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
883 if (!IsWindowVisible(title))
885 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
886 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
887 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
890 else ShowWindow( title, SW_HIDE );
895 /*******************************************************************
896 * WINPOS_GetMinMaxInfo
898 * Get the minimized and maximized information for a window.
900 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
901 POINT *minTrack, POINT *maxTrack )
906 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
907 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
909 /* Compute default values */
911 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
912 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
913 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
914 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
915 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
916 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
918 if (HAS_DLGFRAME( style, exstyle ))
920 xinc = GetSystemMetrics(SM_CXDLGFRAME);
921 yinc = GetSystemMetrics(SM_CYDLGFRAME);
926 if (HAS_THICKFRAME(style))
928 xinc += GetSystemMetrics(SM_CXFRAME);
929 yinc += GetSystemMetrics(SM_CYFRAME);
931 if (style & WS_BORDER)
933 xinc += GetSystemMetrics(SM_CXBORDER);
934 yinc += GetSystemMetrics(SM_CYBORDER);
937 MinMax.ptMaxSize.x += 2 * xinc;
938 MinMax.ptMaxSize.y += 2 * yinc;
940 lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
941 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
942 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
945 MinMax.ptMaxPosition.x = -xinc;
946 MinMax.ptMaxPosition.y = -yinc;
949 SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
951 /* Some sanity checks */
953 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
954 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
955 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
956 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
957 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
958 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
959 MinMax.ptMinTrackSize.x );
960 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
961 MinMax.ptMinTrackSize.y );
963 if (maxSize) *maxSize = MinMax.ptMaxSize;
964 if (maxPos) *maxPos = MinMax.ptMaxPosition;
965 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
966 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
969 /***********************************************************************
970 * ShowWindowAsync (USER32.@)
972 * doesn't wait; returns immediately.
973 * used by threads to toggle windows in other (possibly hanging) threads
975 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
977 /* FIXME: does ShowWindow() return immediately ? */
978 return ShowWindow(hwnd, cmd);
982 /***********************************************************************
983 * ShowWindow (USER32.@)
985 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
989 if ((full_handle = WIN_IsCurrentThread( hwnd )))
990 return USER_Driver.pShowWindow( full_handle, cmd );
991 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
995 /***********************************************************************
996 * GetInternalWindowPos (USER.460)
998 UINT16 WINAPI GetInternalWindowPos16( HWND16 hwnd, LPRECT16 rectWnd,
1001 WINDOWPLACEMENT16 wndpl;
1002 if (GetWindowPlacement16( hwnd, &wndpl ))
1004 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1005 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1006 return wndpl.showCmd;
1012 /***********************************************************************
1013 * GetInternalWindowPos (USER32.@)
1015 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
1018 WINDOWPLACEMENT wndpl;
1019 if (GetWindowPlacement( hwnd, &wndpl ))
1021 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
1022 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
1023 return wndpl.showCmd;
1029 /***********************************************************************
1030 * GetWindowPlacement (USER32.@)
1033 * Fails if wndpl->length of Win95 (!) apps is invalid.
1035 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
1037 WND *pWnd = WIN_FindWndPtr( hwnd );
1038 LPINTERNALPOS lpPos;
1040 if(!pWnd ) return FALSE;
1042 lpPos = WINPOS_InitInternalPos( pWnd, *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
1043 wndpl->length = sizeof(*wndpl);
1044 if( pWnd->dwStyle & WS_MINIMIZE )
1045 wndpl->showCmd = SW_SHOWMINIMIZED;
1047 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
1048 if( pWnd->flags & WIN_RESTORE_MAX )
1049 wndpl->flags = WPF_RESTORETOMAXIMIZED;
1052 CONV_POINT16TO32( &lpPos->ptIconPos, &wndpl->ptMinPosition );
1053 CONV_POINT16TO32( &lpPos->ptMaxPos, &wndpl->ptMaxPosition );
1054 CONV_RECT16TO32( &lpPos->rectNormal, &wndpl->rcNormalPosition );
1055 WIN_ReleaseWndPtr(pWnd);
1060 /***********************************************************************
1061 * WINPOS_SetPlacement
1063 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
1065 WND *pWnd = WIN_FindWndPtr( hwnd );
1068 LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
1069 *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
1071 if( flags & PLACE_MIN ) CONV_POINT32TO16( &wndpl->ptMinPosition, &lpPos->ptIconPos );
1072 if( flags & PLACE_MAX ) CONV_POINT32TO16( &wndpl->ptMaxPosition, &lpPos->ptMaxPos );
1073 if( flags & PLACE_RECT) CONV_RECT32TO16( &wndpl->rcNormalPosition, &lpPos->rectNormal );
1075 if( pWnd->dwStyle & WS_MINIMIZE )
1077 WINPOS_ShowIconTitle( pWnd->hwndSelf, FALSE );
1078 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
1079 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
1080 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1082 else if( pWnd->dwStyle & WS_MAXIMIZE )
1084 if( !EMPTYPOINT(lpPos->ptMaxPos) )
1085 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
1086 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
1088 else if( flags & PLACE_RECT )
1089 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
1090 lpPos->rectNormal.right - lpPos->rectNormal.left,
1091 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
1092 SWP_NOZORDER | SWP_NOACTIVATE );
1094 ShowWindow( hwnd, wndpl->showCmd );
1095 if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
1097 if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd->hwndSelf, TRUE );
1099 /* SDK: ...valid only the next time... */
1100 if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
1102 WIN_ReleaseWndPtr(pWnd);
1109 /***********************************************************************
1110 * SetWindowPlacement (USER32.@)
1113 * Fails if wndpl->length of Win95 (!) apps is invalid.
1115 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
1117 if (!wpl) return FALSE;
1118 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
1122 /***********************************************************************
1123 * AnimateWindow (USER32.@)
1124 * Shows/Hides a window with an animation
1127 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
1129 FIXME("partial stub\n");
1131 /* If trying to show/hide and it's already *
1132 * shown/hidden or invalid window, fail with *
1133 * invalid parameter */
1134 if(!IsWindow(hwnd) ||
1135 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
1136 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
1138 SetLastError(ERROR_INVALID_PARAMETER);
1142 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
1147 /***********************************************************************
1148 * SetInternalWindowPos (USER32.@)
1150 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
1151 LPRECT rect, LPPOINT pt )
1153 if( IsWindow(hwnd) )
1155 WINDOWPLACEMENT wndpl;
1158 wndpl.length = sizeof(wndpl);
1159 wndpl.showCmd = showCmd;
1160 wndpl.flags = flags = 0;
1165 wndpl.flags |= WPF_SETMINPOSITION;
1166 wndpl.ptMinPosition = *pt;
1170 flags |= PLACE_RECT;
1171 wndpl.rcNormalPosition = *rect;
1173 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1177 /*******************************************************************
1178 * WINPOS_SetActiveWindow
1180 * SetActiveWindow() back-end. This is the only function that
1181 * can assign active status to a window. It must be called only
1182 * for the top level windows.
1184 BOOL WINPOS_SetActiveWindow( HWND hWnd, BOOL fMouse, BOOL fChangeFocus)
1186 WND* wndPtr=0, *wndTemp;
1187 HQUEUE16 hOldActiveQueue, hNewActiveQueue;
1188 MESSAGEQUEUE *pOldActiveQueue = 0, *pNewActiveQueue = 0;
1190 HWND hwndActive = 0;
1193 TRACE("(%04x, %d, %d)\n", hWnd, fMouse, fChangeFocus );
1195 /* Get current active window from the active queue */
1198 pOldActiveQueue = QUEUE_Lock( hActiveQueue );
1199 if ( pOldActiveQueue )
1200 hwndActive = PERQDATA_GetActiveWnd( pOldActiveQueue->pQData );
1203 if ((wndPtr = WIN_FindWndPtr(hWnd)))
1204 hWnd = wndPtr->hwndSelf; /* make it a full handle */
1206 /* paranoid checks */
1207 if( hWnd == GetDesktopWindow() || (bRet = (hWnd == hwndActive)) )
1210 /* if (wndPtr && (GetFastQueue16() != wndPtr->hmemTaskQ))
1213 hOldActiveQueue = hActiveQueue;
1215 if( (wndTemp = WIN_FindWndPtr(hwndActive)) )
1217 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1218 WIN_ReleaseWndPtr(wndTemp);
1221 TRACE("no current active window.\n");
1223 /* call CBT hook chain */
1224 if (HOOK_IsHooked( WH_CBT ))
1226 CBTACTIVATESTRUCT cbt;
1227 cbt.fMouse = fMouse;
1228 cbt.hWndActive = hwndActive;
1229 if (HOOK_CallHooksA( WH_CBT, HCBT_ACTIVATE, (WPARAM)hWnd, (LPARAM)&cbt )) goto CLEANUP_END;
1232 /* set prev active wnd to current active wnd and send notification */
1233 if ((hwndPrevActive = hwndActive) && IsWindow(hwndPrevActive))
1235 MESSAGEQUEUE *pTempActiveQueue = 0;
1237 if (!SendMessageA( hwndPrevActive, WM_NCACTIVATE, FALSE, 0 ))
1239 if (GetSysModalWindow16() != WIN_Handle16(hWnd)) goto CLEANUP_END;
1240 /* disregard refusal if hWnd is sysmodal */
1243 SendMessageA( hwndPrevActive, WM_ACTIVATE,
1244 MAKEWPARAM( WA_INACTIVE, wIconized ),
1247 /* check if something happened during message processing
1248 * (global active queue may have changed)
1250 pTempActiveQueue = QUEUE_Lock( hActiveQueue );
1251 if(!pTempActiveQueue)
1254 hwndActive = PERQDATA_GetActiveWnd( pTempActiveQueue->pQData );
1255 QUEUE_Unlock( pTempActiveQueue );
1256 if( hwndPrevActive != hwndActive )
1260 /* Set new active window in the message queue */
1264 pNewActiveQueue = QUEUE_Lock( wndPtr->hmemTaskQ );
1265 if ( pNewActiveQueue )
1266 PERQDATA_SetActiveWnd( pNewActiveQueue->pQData, hwndActive );
1268 else /* have to do this or MDI frame activation goes to hell */
1269 if( pOldActiveQueue )
1270 PERQDATA_SetActiveWnd( pOldActiveQueue->pQData, 0 );
1272 /* send palette messages */
1273 if (hWnd && SendMessageW( hWnd, WM_QUERYNEWPALETTE, 0, 0L))
1274 SendMessageW( HWND_BROADCAST, WM_PALETTEISCHANGING, (WPARAM)hWnd, 0 );
1276 /* if prev wnd is minimized redraw icon title */
1277 if( IsIconic( hwndPrevActive ) ) WINPOS_RedrawIconTitle(hwndPrevActive);
1279 /* managed windows will get ConfigureNotify event */
1280 if (wndPtr && !(wndPtr->dwStyle & WS_CHILD) && !(wndPtr->dwExStyle & WS_EX_MANAGED))
1282 /* check Z-order and bring hWnd to the top */
1283 HWND tmp = GetTopWindow(0);
1284 while (tmp && !(GetWindowLongA( tmp, GWL_STYLE ) & WS_VISIBLE))
1285 tmp = GetWindow( tmp, GW_HWNDNEXT );
1288 SetWindowPos(hWnd, HWND_TOP, 0,0,0,0,
1289 SWP_NOSIZE | SWP_NOMOVE | SWP_NOACTIVATE );
1290 if (!IsWindow(hWnd))
1294 /* Get a handle to the new active queue */
1295 hNewActiveQueue = wndPtr ? wndPtr->hmemTaskQ : 0;
1297 /* send WM_ACTIVATEAPP if necessary */
1298 if (hOldActiveQueue != hNewActiveQueue)
1301 DWORD old_thread = GetWindowThreadProcessId( hwndPrevActive, NULL );
1302 DWORD new_thread = GetWindowThreadProcessId( hwndActive, NULL );
1304 if ((list = WIN_ListChildren( GetDesktopWindow() )))
1306 for (phwnd = list; *phwnd; phwnd++)
1308 if (!IsWindow( *phwnd )) continue;
1309 if (GetWindowThreadProcessId( *phwnd, NULL ) == old_thread)
1310 SendMessageW( *phwnd, WM_ACTIVATEAPP, 0, new_thread );
1312 HeapFree( GetProcessHeap(), 0, list );
1315 hActiveQueue = hNewActiveQueue;
1317 if ((list = WIN_ListChildren( GetDesktopWindow() )))
1319 for (phwnd = list; *phwnd; phwnd++)
1321 if (!IsWindow( *phwnd )) continue;
1322 if (GetWindowThreadProcessId( *phwnd, NULL ) == new_thread)
1323 SendMessageW( *phwnd, WM_ACTIVATEAPP, 1, old_thread );
1325 HeapFree( GetProcessHeap(), 0, list );
1328 if (hWnd && !IsWindow(hWnd)) goto CLEANUP;
1333 /* walk up to the first unowned window */
1334 HWND tmp = GetAncestor( hWnd, GA_ROOTOWNER );
1335 if ((wndTemp = WIN_FindWndPtr( tmp )))
1337 /* and set last active owned popup */
1338 wndTemp->hwndLastActive = hWnd;
1340 wIconized = HIWORD(wndTemp->dwStyle & WS_MINIMIZE);
1341 WIN_ReleaseWndPtr(wndTemp);
1343 SendMessageA( hWnd, WM_NCACTIVATE, TRUE, 0 );
1344 SendMessageA( hWnd, WM_ACTIVATE,
1345 MAKEWPARAM( (fMouse) ? WA_CLICKACTIVE : WA_ACTIVE, wIconized),
1346 (LPARAM)hwndPrevActive );
1347 if( !IsWindow(hWnd) ) goto CLEANUP;
1350 /* change focus if possible */
1353 if ( pNewActiveQueue )
1355 HWND hOldFocus = PERQDATA_GetFocusWnd( pNewActiveQueue->pQData );
1357 if ( !hOldFocus || GetAncestor( hOldFocus, GA_ROOT ) != hwndActive )
1358 FOCUS_SwitchFocus( pNewActiveQueue, hOldFocus,
1359 (wndPtr && (wndPtr->dwStyle & WS_MINIMIZE))?
1363 if ( pOldActiveQueue &&
1364 ( !pNewActiveQueue ||
1365 pNewActiveQueue->pQData != pOldActiveQueue->pQData ) )
1367 HWND hOldFocus = PERQDATA_GetFocusWnd( pOldActiveQueue->pQData );
1369 FOCUS_SwitchFocus( pOldActiveQueue, hOldFocus, 0 );
1373 if( !hwndPrevActive && wndPtr )
1375 if (USER_Driver.pForceWindowRaise) USER_Driver.pForceWindowRaise( wndPtr->hwndSelf );
1378 /* if active wnd is minimized redraw icon title */
1379 if( IsIconic(hwndActive) ) WINPOS_RedrawIconTitle(hwndActive);
1381 bRet = (hWnd == hwndActive); /* Success? */
1383 CLEANUP: /* Unlock the message queues before returning */
1385 if ( pNewActiveQueue )
1386 QUEUE_Unlock( pNewActiveQueue );
1390 if ( pOldActiveQueue )
1391 QUEUE_Unlock( pOldActiveQueue );
1393 WIN_ReleaseWndPtr(wndPtr);
1397 /*******************************************************************
1398 * WINPOS_ActivateOtherWindow
1400 * Activates window other than pWnd.
1402 void WINPOS_ActivateOtherWindow(HWND hwnd)
1404 HWND hwndActive = 0;
1406 HWND hwndDefaultTo = 0;
1409 /* Get current active window from the active queue */
1412 MESSAGEQUEUE *pActiveQueue = QUEUE_Lock( hActiveQueue );
1415 hwndActive = PERQDATA_GetActiveWnd( pActiveQueue->pQData );
1416 QUEUE_Unlock( pActiveQueue );
1420 if (!(hwnd = WIN_IsCurrentThread( hwnd ))) return;
1422 if( hwnd == hwndPrevActive )
1425 if( hwndActive != hwnd && (hwndActive || USER_IsExitingThread( GetCurrentThreadId() )))
1428 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) ||
1429 !(owner = GetWindow( hwnd, GW_OWNER )) ||
1430 !WINPOS_CanActivate((hwndTo = GetAncestor( owner, GA_ROOT ))) ||
1431 !WINPOS_IsVisible(hwndTo))
1433 HWND tmp = GetAncestor( hwnd, GA_ROOT );
1434 hwndTo = hwndPrevActive;
1436 while( !WINPOS_CanActivate(hwndTo) || !WINPOS_IsVisible(hwndTo))
1438 /* by now owned windows should've been taken care of */
1439 if(!hwndDefaultTo && WINPOS_CanActivate(hwndTo))
1440 hwndDefaultTo = hwndTo;
1441 tmp = hwndTo = GetWindow( tmp, GW_HWNDNEXT );
1444 hwndTo = hwndDefaultTo;
1450 SetActiveWindow( hwndTo );
1455 /***********************************************************************
1456 * WINPOS_HandleWindowPosChanging16
1458 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1460 LONG WINPOS_HandleWindowPosChanging16( HWND hwnd, WINDOWPOS16 *winpos )
1462 POINT maxSize, minTrack;
1463 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1465 if (winpos->flags & SWP_NOSIZE) return 0;
1466 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1468 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1469 if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1470 if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1471 if (!(style & WS_MINIMIZE))
1473 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1474 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1481 /***********************************************************************
1482 * WINPOS_HandleWindowPosChanging
1484 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1486 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1488 POINT maxSize, minTrack;
1489 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1491 if (winpos->flags & SWP_NOSIZE) return 0;
1492 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1494 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1495 winpos->cx = min( winpos->cx, maxSize.x );
1496 winpos->cy = min( winpos->cy, maxSize.y );
1497 if (!(style & WS_MINIMIZE))
1499 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1500 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1507 /***********************************************************************
1508 * SetWindowPos (USER32.@)
1510 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1511 INT x, INT y, INT cx, INT cy, UINT flags )
1516 winpos.hwndInsertAfter = hwndInsertAfter;
1521 winpos.flags = flags;
1522 if (WIN_IsCurrentThread( hwnd )) return USER_Driver.pSetWindowPos( &winpos );
1523 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1527 /***********************************************************************
1528 * BeginDeferWindowPos (USER32.@)
1530 HDWP WINAPI BeginDeferWindowPos( INT count )
1537 SetLastError(ERROR_INVALID_PARAMETER);
1540 /* Windows allows zero count, in which case it allocates context for 8 moves */
1541 if (count == 0) count = 8;
1543 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1544 if (!handle) return 0;
1545 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1546 pDWP->actualCount = 0;
1547 pDWP->suggestedCount = count;
1549 pDWP->wMagic = DWP_MAGIC;
1550 pDWP->hwndParent = 0;
1555 /***********************************************************************
1556 * DeferWindowPos (USER32.@)
1558 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1559 INT x, INT y, INT cx, INT cy,
1564 HDWP newhdwp = hdwp,retvalue;
1566 hwnd = WIN_GetFullHandle( hwnd );
1567 if (hwnd == GetDesktopWindow()) return 0;
1569 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1573 for (i = 0; i < pDWP->actualCount; i++)
1575 if (pDWP->winPos[i].hwnd == hwnd)
1577 /* Merge with the other changes */
1578 if (!(flags & SWP_NOZORDER))
1580 pDWP->winPos[i].hwndInsertAfter = hwndAfter;
1582 if (!(flags & SWP_NOMOVE))
1584 pDWP->winPos[i].x = x;
1585 pDWP->winPos[i].y = y;
1587 if (!(flags & SWP_NOSIZE))
1589 pDWP->winPos[i].cx = cx;
1590 pDWP->winPos[i].cy = cy;
1592 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1593 SWP_NOZORDER | SWP_NOREDRAW |
1594 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1596 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1602 if (pDWP->actualCount >= pDWP->suggestedCount)
1604 newhdwp = USER_HEAP_REALLOC( hdwp,
1605 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1611 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1612 pDWP->suggestedCount++;
1614 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1615 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1616 pDWP->winPos[pDWP->actualCount].x = x;
1617 pDWP->winPos[pDWP->actualCount].y = y;
1618 pDWP->winPos[pDWP->actualCount].cx = cx;
1619 pDWP->winPos[pDWP->actualCount].cy = cy;
1620 pDWP->winPos[pDWP->actualCount].flags = flags;
1621 pDWP->actualCount++;
1629 /***********************************************************************
1630 * EndDeferWindowPos (USER32.@)
1632 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1639 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1640 if (!pDWP) return FALSE;
1641 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1643 if (!(res = USER_Driver.pSetWindowPos( winpos ))) break;
1645 USER_HEAP_FREE( hdwp );
1650 /***********************************************************************
1651 * TileChildWindows (USER.199)
1653 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1655 FIXME("(%04x, %d): stub\n", parent, action);
1658 /***********************************************************************
1659 * CascadeChildWindows (USER.198)
1661 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1663 FIXME("(%04x, %d): stub\n", parent, action);
1666 /***********************************************************************
1667 * SetProgmanWindow (USER32.@)
1669 HWND WINAPI SetProgmanWindow ( HWND hwnd )
1671 hGlobalProgmanWindow = hwnd;
1672 return hGlobalProgmanWindow;
1675 /***********************************************************************
1676 * GetProgmanWindow (USER32.@)
1678 HWND WINAPI GetProgmanWindow(void)
1680 return hGlobalProgmanWindow;
1683 /***********************************************************************
1684 * SetShellWindowEx (USER32.@)
1685 * hwndProgman = Progman[Program Manager]
1686 * |-> SHELLDLL_DefView
1687 * hwndListView = | |-> SysListView32
1688 * | | |-> tooltips_class32
1694 HWND WINAPI SetShellWindowEx ( HWND hwndProgman, HWND hwndListView )
1696 FIXME("0x%08x 0x%08x stub\n",hwndProgman ,hwndListView );
1697 hGlobalShellWindow = hwndProgman;
1698 return hGlobalShellWindow;
1702 /***********************************************************************
1703 * SetTaskmanWindow (USER32.@)
1705 * hwnd = MSTaskSwWClass
1706 * |-> SysTabControl32
1708 HWND WINAPI SetTaskmanWindow ( HWND hwnd )
1710 hGlobalTaskmanWindow = hwnd;
1711 return hGlobalTaskmanWindow;
1714 /***********************************************************************
1715 * GetTaskmanWindow (USER32.@)
1717 HWND WINAPI GetTaskmanWindow(void)
1719 return hGlobalTaskmanWindow;