2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
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.
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.
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
27 #include "wine/winuser16.h"
28 #include "wine/server.h"
36 #include "nonclient.h"
37 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win);
42 #define HAS_DLGFRAME(style,exStyle) \
43 (((exStyle) & WS_EX_DLGMODALFRAME) || \
44 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
46 #define HAS_THICKFRAME(style) \
47 (((style) & WS_THICKFRAME) && \
48 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
50 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
52 #define PLACE_MIN 0x0001
53 #define PLACE_MAX 0x0002
54 #define PLACE_RECT 0x0004
57 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
69 /* ----- internal variables ----- */
71 static HWND hGlobalShellWindow=0; /*the shell*/
72 static HWND hGlobalTaskmanWindow=0;
73 static HWND hGlobalProgmanWindow=0;
75 static LPCSTR atomInternalPos;
78 /***********************************************************************
79 * WINPOS_CreateInternalPosAtom
81 BOOL WINPOS_CreateInternalPosAtom()
84 atomInternalPos = (LPCSTR)(DWORD)GlobalAddAtomA(str);
85 return (atomInternalPos) ? TRUE : FALSE;
88 /***********************************************************************
89 * WINPOS_CheckInternalPos
91 * Called when a window is destroyed.
93 void WINPOS_CheckInternalPos( HWND hwnd )
95 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( hwnd, atomInternalPos );
99 if( IsWindow(lpPos->hwndIconTitle) )
100 DestroyWindow( lpPos->hwndIconTitle );
101 HeapFree( GetProcessHeap(), 0, lpPos );
105 /***********************************************************************
106 * ArrangeIconicWindows (USER32.@)
108 UINT WINAPI ArrangeIconicWindows( HWND parent )
112 INT x, y, xspacing, yspacing;
114 GetClientRect( parent, &rectParent );
116 y = rectParent.bottom;
117 xspacing = GetSystemMetrics(SM_CXICONSPACING);
118 yspacing = GetSystemMetrics(SM_CYICONSPACING);
120 hwndChild = GetWindow( parent, GW_CHILD );
123 if( IsIconic( hwndChild ) )
125 WINPOS_ShowIconTitle( hwndChild, FALSE );
127 SetWindowPos( hwndChild, 0, x + (xspacing - GetSystemMetrics(SM_CXICON)) / 2,
128 y - yspacing - GetSystemMetrics(SM_CYICON)/2, 0, 0,
129 SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
130 if( IsWindow(hwndChild) )
131 WINPOS_ShowIconTitle(hwndChild , TRUE );
133 if (x <= rectParent.right - xspacing) x += xspacing;
140 hwndChild = GetWindow( hwndChild, GW_HWNDNEXT );
146 /***********************************************************************
147 * SwitchToThisWindow (USER32.@)
149 void WINAPI SwitchToThisWindow( HWND hwnd, BOOL restore )
151 ShowWindow( hwnd, restore ? SW_RESTORE : SW_SHOWMINIMIZED );
155 /***********************************************************************
156 * GetWindowRect (USER32.@)
158 BOOL WINAPI GetWindowRect( HWND hwnd, LPRECT rect )
160 BOOL ret = WIN_GetRectangles( hwnd, rect, NULL );
163 MapWindowPoints( GetAncestor( hwnd, GA_PARENT ), 0, (POINT *)rect, 2 );
164 TRACE( "hwnd %04x (%d,%d)-(%d,%d)\n",
165 hwnd, rect->left, rect->top, rect->right, rect->bottom);
171 /***********************************************************************
172 * GetWindowRgn (USER32.@)
174 int WINAPI GetWindowRgn ( HWND hwnd, HRGN hrgn )
177 WND *wndPtr = WIN_GetPtr( hwnd );
179 if (wndPtr == WND_OTHER_PROCESS)
181 if (IsWindow( hwnd ))
182 FIXME( "not supported on other process window %x\n", hwnd );
187 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
190 if (wndPtr->hrgnWnd) nRet = CombineRgn( hrgn, wndPtr->hrgnWnd, 0, RGN_COPY );
191 WIN_ReleasePtr( wndPtr );
196 /***********************************************************************
197 * SetWindowRgn (USER32.@)
199 int WINAPI SetWindowRgn( HWND hwnd, HRGN hrgn, BOOL bRedraw )
204 if (hrgn) /* verify that region really exists */
206 if (GetRgnBox( hrgn, &rect ) == ERROR) return FALSE;
209 if (USER_Driver.pSetWindowRgn)
210 return USER_Driver.pSetWindowRgn( hwnd, hrgn, bRedraw );
212 if ((wndPtr = WIN_GetPtr( hwnd )) == WND_OTHER_PROCESS)
214 if (IsWindow( hwnd ))
215 FIXME( "not supported on other process window %x\n", hwnd );
220 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
224 if (wndPtr->hrgnWnd == hrgn)
226 WIN_ReleasePtr( wndPtr );
232 /* delete previous region */
233 DeleteObject(wndPtr->hrgnWnd);
236 wndPtr->hrgnWnd = hrgn;
237 WIN_ReleasePtr( wndPtr );
239 /* Size the window to the rectangle of the new region (if it isn't NULL) */
240 if (hrgn) SetWindowPos( hwnd, 0, rect.left, rect.top,
241 rect.right - rect.left, rect.bottom - rect.top,
242 SWP_NOSIZE | SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOACTIVATE |
243 SWP_NOZORDER | (bRedraw ? 0 : SWP_NOREDRAW) );
248 /***********************************************************************
249 * GetClientRect (USER32.@)
251 BOOL WINAPI GetClientRect( HWND hwnd, LPRECT rect )
255 rect->right = rect->bottom = 0;
256 if ((ret = WIN_GetRectangles( hwnd, NULL, rect )))
258 rect->right -= rect->left;
259 rect->bottom -= rect->top;
261 rect->left = rect->top = 0;
266 /*******************************************************************
267 * ClientToScreen (USER32.@)
269 BOOL WINAPI ClientToScreen( HWND hwnd, LPPOINT lppnt )
271 MapWindowPoints( hwnd, 0, lppnt, 1 );
276 /*******************************************************************
277 * ScreenToClient (USER32.@)
279 BOOL WINAPI ScreenToClient( HWND hwnd, LPPOINT lppnt )
281 MapWindowPoints( 0, hwnd, lppnt, 1 );
286 /***********************************************************************
287 * find_child_from_point
289 * Find the child that contains pt. Helper for WindowFromPoint.
290 * pt is in parent client coordinates.
291 * lparam is the param to pass in the WM_NCHITTEST message.
293 static HWND find_child_from_point( HWND parent, POINT pt, INT *hittest, LPARAM lparam )
297 RECT rectWindow, rectClient;
299 HWND *list = WIN_ListChildren( parent );
303 for (i = 0; list[i]; i++)
305 /* If point is in window, and window is visible, and it */
306 /* is enabled (or it's a top-level window), then explore */
307 /* its children. Otherwise, go to the next window. */
309 style = GetWindowLongW( list[i], GWL_STYLE );
310 if (!(style & WS_VISIBLE)) continue; /* not visible -> skip */
311 if ((style & (WS_POPUP | WS_CHILD | WS_DISABLED)) == (WS_CHILD | WS_DISABLED))
312 continue; /* disabled child -> skip */
313 exstyle = GetWindowLongW( list[i], GWL_EXSTYLE );
314 if ((exstyle & (WS_EX_LAYERED | WS_EX_TRANSPARENT)) == (WS_EX_LAYERED | WS_EX_TRANSPARENT))
315 continue; /* transparent -> skip */
317 if (!WIN_GetRectangles( list[i], &rectWindow, &rectClient )) continue;
318 if (!PtInRect( &rectWindow, pt )) continue; /* not in window -> skip */
320 /* FIXME: check window region for other processes too */
321 if ((wndPtr = WIN_GetPtr( list[i] )) && wndPtr != WND_OTHER_PROCESS)
323 if (wndPtr->hrgnWnd && !PtInRegion( wndPtr->hrgnWnd,
324 pt.x - rectWindow.left, pt.y - rectWindow.top ))
326 WIN_ReleasePtr( wndPtr );
327 continue; /* point outside window region -> skip */
329 WIN_ReleasePtr( wndPtr );
332 /* If window is minimized or disabled, return at once */
333 if (style & WS_MINIMIZE)
335 *hittest = HTCAPTION;
339 if (style & WS_DISABLED)
346 /* If point is in client area, explore children */
347 if (PtInRect( &rectClient, pt ))
351 new_pt.x = pt.x - rectClient.left;
352 new_pt.y = pt.y - rectClient.top;
353 if ((retvalue = find_child_from_point( list[i], new_pt, hittest, lparam ))) break;
356 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
357 if (!WIN_IsCurrentThread( list[i] ))
363 if ((res = SendMessageA( list[i], WM_NCHITTEST, 0, lparam )) != HTTRANSPARENT)
365 *hittest = res; /* Found the window */
369 /* continue search with next sibling */
371 HeapFree( GetProcessHeap(), 0, list );
376 /***********************************************************************
377 * WINPOS_WindowFromPoint
379 * Find the window and hittest for a given point.
381 HWND WINPOS_WindowFromPoint( HWND hwndScope, POINT pt, INT *hittest )
387 TRACE("scope %04x %ld,%ld\n", hwndScope, pt.x, pt.y);
389 if (!hwndScope) hwndScope = GetDesktopWindow();
390 style = GetWindowLongW( hwndScope, GWL_STYLE );
393 if (style & WS_DISABLED) return 0;
395 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope, GA_PARENT ), &xy, 1 );
397 if (!(style & WS_MINIMIZE))
400 if (WIN_GetRectangles( hwndScope, NULL, &rectClient ) && PtInRect( &rectClient, xy ))
404 xy.x -= rectClient.left;
405 xy.y -= rectClient.top;
406 if ((ret = find_child_from_point( hwndScope, xy, hittest, MAKELONG( pt.x, pt.y ) )))
408 TRACE( "found child %x\n", ret );
414 /* If nothing found, try the scope window */
415 if (!WIN_IsCurrentThread( hwndScope ))
418 TRACE( "returning %x\n", hwndScope );
421 res = SendMessageA( hwndScope, WM_NCHITTEST, 0, MAKELONG( pt.x, pt.y ) );
422 if (res != HTTRANSPARENT)
424 *hittest = res; /* Found the window */
425 TRACE( "returning %x\n", hwndScope );
428 *hittest = HTNOWHERE;
429 TRACE( "nothing found\n" );
434 /*******************************************************************
435 * WindowFromPoint (USER32.@)
437 HWND WINAPI WindowFromPoint( POINT pt )
440 return WINPOS_WindowFromPoint( 0, pt, &hittest );
444 /*******************************************************************
445 * ChildWindowFromPoint (USER32.@)
447 HWND WINAPI ChildWindowFromPoint( HWND hwndParent, POINT pt )
449 return ChildWindowFromPointEx( hwndParent, pt, CWP_ALL );
452 /*******************************************************************
453 * ChildWindowFromPointEx (USER32.@)
455 HWND WINAPI ChildWindowFromPointEx( HWND hwndParent, POINT pt, UINT uFlags)
457 /* pt is in the client coordinates */
463 GetClientRect( hwndParent, &rect );
464 if (!PtInRect( &rect, pt )) return 0;
465 if (!(list = WIN_ListChildren( hwndParent ))) return 0;
467 for (i = 0; list[i]; i++)
469 if (!WIN_GetRectangles( list[i], &rect, NULL )) continue;
470 if (!PtInRect( &rect, pt )) continue;
471 if (uFlags & (CWP_SKIPINVISIBLE|CWP_SKIPDISABLED))
473 LONG style = GetWindowLongW( list[i], GWL_STYLE );
474 if ((uFlags & CWP_SKIPINVISIBLE) && !(style & WS_VISIBLE)) continue;
475 if ((uFlags & CWP_SKIPDISABLED) && (style & WS_DISABLED)) continue;
477 if (uFlags & CWP_SKIPTRANSPARENT)
479 if (GetWindowLongW( list[i], GWL_EXSTYLE ) & WS_EX_TRANSPARENT) continue;
484 HeapFree( GetProcessHeap(), 0, list );
485 if (!retvalue) retvalue = hwndParent;
490 /*******************************************************************
491 * WINPOS_GetWinOffset
493 * Calculate the offset between the origin of the two windows. Used
494 * to implement MapWindowPoints.
496 static void WINPOS_GetWinOffset( HWND hwndFrom, HWND hwndTo, POINT *offset )
500 offset->x = offset->y = 0;
502 /* Translate source window origin to screen coords */
505 HWND hwnd = hwndFrom;
509 if (hwnd == hwndTo) return;
510 if (!(wndPtr = WIN_GetPtr( hwnd )))
512 ERR( "bad hwndFrom = %04x\n", hwnd );
515 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
516 offset->x += wndPtr->rectClient.left;
517 offset->y += wndPtr->rectClient.top;
518 hwnd = wndPtr->parent;
519 WIN_ReleasePtr( wndPtr );
523 /* Translate origin to destination window coords */
530 if (!(wndPtr = WIN_GetPtr( hwnd )))
532 ERR( "bad hwndTo = %04x\n", hwnd );
535 if (wndPtr == WND_OTHER_PROCESS) goto other_process;
536 offset->x -= wndPtr->rectClient.left;
537 offset->y -= wndPtr->rectClient.top;
538 hwnd = wndPtr->parent;
539 WIN_ReleasePtr( wndPtr );
544 other_process: /* one of the parents may belong to another process, do it the hard way */
545 offset->x = offset->y = 0;
546 SERVER_START_REQ( get_windows_offset )
548 req->from = hwndFrom;
550 if (!wine_server_call( req ))
552 offset->x = reply->x;
553 offset->y = reply->y;
560 /*******************************************************************
561 * MapWindowPoints (USER.258)
563 void WINAPI MapWindowPoints16( HWND16 hwndFrom, HWND16 hwndTo,
564 LPPOINT16 lppt, UINT16 count )
568 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom), WIN_Handle32(hwndTo), &offset );
578 /*******************************************************************
579 * MapWindowPoints (USER32.@)
581 INT WINAPI MapWindowPoints( HWND hwndFrom, HWND hwndTo, LPPOINT lppt, UINT count )
585 WINPOS_GetWinOffset( hwndFrom, hwndTo, &offset );
592 return MAKELONG( LOWORD(offset.x), LOWORD(offset.y) );
596 /***********************************************************************
597 * IsIconic (USER32.@)
599 BOOL WINAPI IsIconic(HWND hWnd)
601 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MINIMIZE) != 0;
605 /***********************************************************************
606 * IsZoomed (USER32.@)
608 BOOL WINAPI IsZoomed(HWND hWnd)
610 return (GetWindowLongW( hWnd, GWL_STYLE ) & WS_MAXIMIZE) != 0;
614 /*******************************************************************
615 * AllowSetForegroundWindow (USER32.@)
617 BOOL WINAPI AllowSetForegroundWindow( DWORD procid )
619 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
620 * implemented, then fix this function. */
625 /*******************************************************************
626 * LockSetForegroundWindow (USER32.@)
628 BOOL WINAPI LockSetForegroundWindow( UINT lockcode )
630 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
631 * implemented, then fix this function. */
636 /*******************************************************************
637 * SetShellWindow (USER32.@)
639 HWND WINAPI SetShellWindow(HWND hwndshell)
640 { WARN("(hWnd=%08x) semi stub\n",hwndshell );
642 hGlobalShellWindow = WIN_GetFullHandle( hwndshell );
643 return hGlobalShellWindow;
647 /*******************************************************************
648 * GetShellWindow (USER32.@)
650 HWND WINAPI GetShellWindow(void)
651 { WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow );
653 return hGlobalShellWindow;
657 /***********************************************************************
658 * BringWindowToTop (USER32.@)
660 BOOL WINAPI BringWindowToTop( HWND hwnd )
662 return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
666 /***********************************************************************
667 * MoveWindow (USER32.@)
669 BOOL WINAPI MoveWindow( HWND hwnd, INT x, INT y, INT cx, INT cy,
672 int flags = SWP_NOZORDER | SWP_NOACTIVATE;
673 if (!repaint) flags |= SWP_NOREDRAW;
674 TRACE("%04x %d,%d %dx%d %d\n",
675 hwnd, x, y, cx, cy, repaint );
676 return SetWindowPos( hwnd, 0, x, y, cx, cy, flags );
679 /***********************************************************************
680 * WINPOS_InitInternalPos
682 static LPINTERNALPOS WINPOS_InitInternalPos( WND* wnd, POINT pt, const RECT *restoreRect )
684 LPINTERNALPOS lpPos = (LPINTERNALPOS) GetPropA( wnd->hwndSelf,
688 /* this happens when the window is minimized/maximized
689 * for the first time (rectWindow is not adjusted yet) */
691 lpPos = HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS) );
692 if( !lpPos ) return NULL;
694 SetPropA( wnd->hwndSelf, atomInternalPos, (HANDLE)lpPos );
695 lpPos->hwndIconTitle = 0; /* defer until needs to be shown */
696 CONV_RECT32TO16( &wnd->rectWindow, &lpPos->rectNormal );
697 *(UINT*)&lpPos->ptIconPos = *(UINT*)&lpPos->ptMaxPos = 0xFFFFFFFF;
700 if( wnd->dwStyle & WS_MINIMIZE )
701 CONV_POINT32TO16( &pt, &lpPos->ptIconPos );
702 else if( wnd->dwStyle & WS_MAXIMIZE )
703 CONV_POINT32TO16( &pt, &lpPos->ptMaxPos );
704 else if( restoreRect )
705 CONV_RECT32TO16( restoreRect, &lpPos->rectNormal );
710 /***********************************************************************
711 * WINPOS_RedrawIconTitle
713 BOOL WINPOS_RedrawIconTitle( HWND hWnd )
715 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hWnd, atomInternalPos );
718 if( lpPos->hwndIconTitle )
720 SendMessageA( lpPos->hwndIconTitle, WM_SHOWWINDOW, TRUE, 0);
721 InvalidateRect( lpPos->hwndIconTitle, NULL, TRUE );
728 /***********************************************************************
729 * WINPOS_ShowIconTitle
731 BOOL WINPOS_ShowIconTitle( HWND hwnd, BOOL bShow )
733 LPINTERNALPOS lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
735 if( lpPos && !(GetWindowLongA( hwnd, GWL_EXSTYLE) & WS_EX_MANAGED))
737 HWND title = lpPos->hwndIconTitle;
739 TRACE("0x%04x %i\n", hwnd, (bShow != 0) );
742 lpPos->hwndIconTitle = title = ICONTITLE_Create( hwnd );
745 if (!IsWindowVisible(title))
747 SendMessageA( title, WM_SHOWWINDOW, TRUE, 0 );
748 SetWindowPos( title, 0, 0, 0, 0, 0, SWP_NOSIZE | SWP_NOMOVE |
749 SWP_NOACTIVATE | SWP_NOZORDER | SWP_SHOWWINDOW );
752 else ShowWindow( title, SW_HIDE );
757 /*******************************************************************
758 * WINPOS_GetMinMaxInfo
760 * Get the minimized and maximized information for a window.
762 void WINPOS_GetMinMaxInfo( HWND hwnd, POINT *maxSize, POINT *maxPos,
763 POINT *minTrack, POINT *maxTrack )
768 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
769 LONG exstyle = GetWindowLongA( hwnd, GWL_EXSTYLE );
771 /* Compute default values */
773 MinMax.ptMaxSize.x = GetSystemMetrics(SM_CXSCREEN);
774 MinMax.ptMaxSize.y = GetSystemMetrics(SM_CYSCREEN);
775 MinMax.ptMinTrackSize.x = GetSystemMetrics(SM_CXMINTRACK);
776 MinMax.ptMinTrackSize.y = GetSystemMetrics(SM_CYMINTRACK);
777 MinMax.ptMaxTrackSize.x = GetSystemMetrics(SM_CXSCREEN);
778 MinMax.ptMaxTrackSize.y = GetSystemMetrics(SM_CYSCREEN);
780 if (HAS_DLGFRAME( style, exstyle ))
782 xinc = GetSystemMetrics(SM_CXDLGFRAME);
783 yinc = GetSystemMetrics(SM_CYDLGFRAME);
788 if (HAS_THICKFRAME(style))
790 xinc += GetSystemMetrics(SM_CXFRAME);
791 yinc += GetSystemMetrics(SM_CYFRAME);
793 if (style & WS_BORDER)
795 xinc += GetSystemMetrics(SM_CXBORDER);
796 yinc += GetSystemMetrics(SM_CYBORDER);
799 MinMax.ptMaxSize.x += 2 * xinc;
800 MinMax.ptMaxSize.y += 2 * yinc;
802 lpPos = (LPINTERNALPOS)GetPropA( hwnd, atomInternalPos );
803 if( lpPos && !EMPTYPOINT(lpPos->ptMaxPos) )
804 CONV_POINT16TO32( &lpPos->ptMaxPos, &MinMax.ptMaxPosition );
807 MinMax.ptMaxPosition.x = -xinc;
808 MinMax.ptMaxPosition.y = -yinc;
811 SendMessageA( hwnd, WM_GETMINMAXINFO, 0, (LPARAM)&MinMax );
813 /* Some sanity checks */
815 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
816 MinMax.ptMaxSize.x, MinMax.ptMaxSize.y,
817 MinMax.ptMaxPosition.x, MinMax.ptMaxPosition.y,
818 MinMax.ptMaxTrackSize.x, MinMax.ptMaxTrackSize.y,
819 MinMax.ptMinTrackSize.x, MinMax.ptMinTrackSize.y);
820 MinMax.ptMaxTrackSize.x = max( MinMax.ptMaxTrackSize.x,
821 MinMax.ptMinTrackSize.x );
822 MinMax.ptMaxTrackSize.y = max( MinMax.ptMaxTrackSize.y,
823 MinMax.ptMinTrackSize.y );
825 if (maxSize) *maxSize = MinMax.ptMaxSize;
826 if (maxPos) *maxPos = MinMax.ptMaxPosition;
827 if (minTrack) *minTrack = MinMax.ptMinTrackSize;
828 if (maxTrack) *maxTrack = MinMax.ptMaxTrackSize;
831 /***********************************************************************
832 * ShowWindowAsync (USER32.@)
834 * doesn't wait; returns immediately.
835 * used by threads to toggle windows in other (possibly hanging) threads
837 BOOL WINAPI ShowWindowAsync( HWND hwnd, INT cmd )
841 if ((full_handle = WIN_IsCurrentThread( hwnd )))
842 return USER_Driver.pShowWindow( full_handle, cmd );
843 return SendNotifyMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
847 /***********************************************************************
848 * ShowWindow (USER32.@)
850 BOOL WINAPI ShowWindow( HWND hwnd, INT cmd )
854 if ((full_handle = WIN_IsCurrentThread( hwnd )))
855 return USER_Driver.pShowWindow( full_handle, cmd );
856 return SendMessageW( hwnd, WM_WINE_SHOWWINDOW, cmd, 0 );
860 /***********************************************************************
861 * GetInternalWindowPos (USER32.@)
863 UINT WINAPI GetInternalWindowPos( HWND hwnd, LPRECT rectWnd,
866 WINDOWPLACEMENT wndpl;
867 if (GetWindowPlacement( hwnd, &wndpl ))
869 if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
870 if (ptIcon) *ptIcon = wndpl.ptMinPosition;
871 return wndpl.showCmd;
877 /***********************************************************************
878 * GetWindowPlacement (USER32.@)
881 * Fails if wndpl->length of Win95 (!) apps is invalid.
883 BOOL WINAPI GetWindowPlacement( HWND hwnd, WINDOWPLACEMENT *wndpl )
885 WND *pWnd = WIN_FindWndPtr( hwnd );
888 if(!pWnd ) return FALSE;
890 lpPos = WINPOS_InitInternalPos( pWnd, *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
891 wndpl->length = sizeof(*wndpl);
892 if( pWnd->dwStyle & WS_MINIMIZE )
893 wndpl->showCmd = SW_SHOWMINIMIZED;
895 wndpl->showCmd = ( pWnd->dwStyle & WS_MAXIMIZE ) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL ;
896 if( pWnd->flags & WIN_RESTORE_MAX )
897 wndpl->flags = WPF_RESTORETOMAXIMIZED;
900 CONV_POINT16TO32( &lpPos->ptIconPos, &wndpl->ptMinPosition );
901 CONV_POINT16TO32( &lpPos->ptMaxPos, &wndpl->ptMaxPosition );
902 CONV_RECT16TO32( &lpPos->rectNormal, &wndpl->rcNormalPosition );
903 WIN_ReleaseWndPtr(pWnd);
908 /***********************************************************************
909 * WINPOS_SetPlacement
911 static BOOL WINPOS_SetPlacement( HWND hwnd, const WINDOWPLACEMENT *wndpl, UINT flags )
913 WND *pWnd = WIN_FindWndPtr( hwnd );
916 LPINTERNALPOS lpPos = (LPINTERNALPOS)WINPOS_InitInternalPos( pWnd,
917 *(LPPOINT)&pWnd->rectWindow.left, &pWnd->rectWindow );
919 if( flags & PLACE_MIN ) CONV_POINT32TO16( &wndpl->ptMinPosition, &lpPos->ptIconPos );
920 if( flags & PLACE_MAX ) CONV_POINT32TO16( &wndpl->ptMaxPosition, &lpPos->ptMaxPos );
921 if( flags & PLACE_RECT) CONV_RECT32TO16( &wndpl->rcNormalPosition, &lpPos->rectNormal );
923 if( pWnd->dwStyle & WS_MINIMIZE )
925 WINPOS_ShowIconTitle( pWnd->hwndSelf, FALSE );
926 if( wndpl->flags & WPF_SETMINPOSITION && !EMPTYPOINT(lpPos->ptIconPos))
927 SetWindowPos( hwnd, 0, lpPos->ptIconPos.x, lpPos->ptIconPos.y,
928 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
930 else if( pWnd->dwStyle & WS_MAXIMIZE )
932 if( !EMPTYPOINT(lpPos->ptMaxPos) )
933 SetWindowPos( hwnd, 0, lpPos->ptMaxPos.x, lpPos->ptMaxPos.y,
934 0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE );
936 else if( flags & PLACE_RECT )
937 SetWindowPos( hwnd, 0, lpPos->rectNormal.left, lpPos->rectNormal.top,
938 lpPos->rectNormal.right - lpPos->rectNormal.left,
939 lpPos->rectNormal.bottom - lpPos->rectNormal.top,
940 SWP_NOZORDER | SWP_NOACTIVATE );
942 ShowWindow( hwnd, wndpl->showCmd );
943 if( IsWindow(hwnd) && pWnd->dwStyle & WS_MINIMIZE )
945 if( pWnd->dwStyle & WS_VISIBLE ) WINPOS_ShowIconTitle( pWnd->hwndSelf, TRUE );
947 /* SDK: ...valid only the next time... */
948 if( wndpl->flags & WPF_RESTORETOMAXIMIZED ) pWnd->flags |= WIN_RESTORE_MAX;
950 WIN_ReleaseWndPtr(pWnd);
957 /***********************************************************************
958 * SetWindowPlacement (USER32.@)
961 * Fails if wndpl->length of Win95 (!) apps is invalid.
963 BOOL WINAPI SetWindowPlacement( HWND hwnd, const WINDOWPLACEMENT *wpl )
965 if (!wpl) return FALSE;
966 return WINPOS_SetPlacement( hwnd, wpl, PLACE_MIN | PLACE_MAX | PLACE_RECT );
970 /***********************************************************************
971 * AnimateWindow (USER32.@)
972 * Shows/Hides a window with an animation
975 BOOL WINAPI AnimateWindow(HWND hwnd, DWORD dwTime, DWORD dwFlags)
977 FIXME("partial stub\n");
979 /* If trying to show/hide and it's already *
980 * shown/hidden or invalid window, fail with *
981 * invalid parameter */
982 if(!IsWindow(hwnd) ||
983 (IsWindowVisible(hwnd) && !(dwFlags & AW_HIDE)) ||
984 (!IsWindowVisible(hwnd) && (dwFlags & AW_HIDE)))
986 SetLastError(ERROR_INVALID_PARAMETER);
990 ShowWindow(hwnd, (dwFlags & AW_HIDE) ? SW_HIDE : ((dwFlags & AW_ACTIVATE) ? SW_SHOW : SW_SHOWNA));
995 /***********************************************************************
996 * SetInternalWindowPos (USER32.@)
998 void WINAPI SetInternalWindowPos( HWND hwnd, UINT showCmd,
999 LPRECT rect, LPPOINT pt )
1001 if( IsWindow(hwnd) )
1003 WINDOWPLACEMENT wndpl;
1006 wndpl.length = sizeof(wndpl);
1007 wndpl.showCmd = showCmd;
1008 wndpl.flags = flags = 0;
1013 wndpl.flags |= WPF_SETMINPOSITION;
1014 wndpl.ptMinPosition = *pt;
1018 flags |= PLACE_RECT;
1019 wndpl.rcNormalPosition = *rect;
1021 WINPOS_SetPlacement( hwnd, &wndpl, flags );
1026 /*******************************************************************
1027 * can_activate_window
1029 * Check if we can activate the specified window.
1031 static BOOL can_activate_window( HWND hwnd )
1035 if (!hwnd) return FALSE;
1036 style = GetWindowLongW( hwnd, GWL_STYLE );
1037 if (!(style & WS_VISIBLE)) return FALSE;
1038 if ((style & (WS_POPUP|WS_CHILD)) == WS_CHILD) return FALSE;
1039 return !(style & WS_DISABLED);
1043 /*******************************************************************
1044 * WINPOS_ActivateOtherWindow
1046 * Activates window other than pWnd.
1048 void WINPOS_ActivateOtherWindow(HWND hwnd)
1052 if ((GetWindowLongW( hwnd, GWL_STYLE ) & WS_POPUP) && (hwndTo = GetWindow( hwnd, GW_OWNER )))
1054 hwndTo = GetAncestor( hwndTo, GA_ROOT );
1055 if (can_activate_window( hwndTo )) goto done;
1061 if (!(hwndTo = GetWindow( hwndTo, GW_HWNDNEXT ))) break;
1062 if (can_activate_window( hwndTo )) break;
1066 fg = GetForegroundWindow();
1067 TRACE("win = %x fg = %x\n", hwndTo, fg);
1068 if (!fg || (hwnd == fg))
1070 if (SetForegroundWindow( hwndTo )) return;
1072 if (!SetActiveWindow( hwndTo )) SetActiveWindow(0);
1076 /***********************************************************************
1077 * WINPOS_HandleWindowPosChanging16
1079 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1081 LONG WINPOS_HandleWindowPosChanging16( HWND hwnd, WINDOWPOS16 *winpos )
1083 POINT maxSize, minTrack;
1084 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1086 if (winpos->flags & SWP_NOSIZE) return 0;
1087 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1089 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1090 if (maxSize.x < winpos->cx) winpos->cx = maxSize.x;
1091 if (maxSize.y < winpos->cy) winpos->cy = maxSize.y;
1092 if (!(style & WS_MINIMIZE))
1094 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1095 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1102 /***********************************************************************
1103 * WINPOS_HandleWindowPosChanging
1105 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1107 LONG WINPOS_HandleWindowPosChanging( HWND hwnd, WINDOWPOS *winpos )
1109 POINT maxSize, minTrack;
1110 LONG style = GetWindowLongA( hwnd, GWL_STYLE );
1112 if (winpos->flags & SWP_NOSIZE) return 0;
1113 if ((style & WS_THICKFRAME) || ((style & (WS_POPUP | WS_CHILD)) == 0))
1115 WINPOS_GetMinMaxInfo( hwnd, &maxSize, NULL, &minTrack, NULL );
1116 winpos->cx = min( winpos->cx, maxSize.x );
1117 winpos->cy = min( winpos->cy, maxSize.y );
1118 if (!(style & WS_MINIMIZE))
1120 if (winpos->cx < minTrack.x ) winpos->cx = minTrack.x;
1121 if (winpos->cy < minTrack.y ) winpos->cy = minTrack.y;
1128 /***********************************************************************
1131 static void dump_winpos_flags(UINT flags)
1134 if(flags & SWP_NOSIZE) DPRINTF(" SWP_NOSIZE");
1135 if(flags & SWP_NOMOVE) DPRINTF(" SWP_NOMOVE");
1136 if(flags & SWP_NOZORDER) DPRINTF(" SWP_NOZORDER");
1137 if(flags & SWP_NOREDRAW) DPRINTF(" SWP_NOREDRAW");
1138 if(flags & SWP_NOACTIVATE) DPRINTF(" SWP_NOACTIVATE");
1139 if(flags & SWP_FRAMECHANGED) DPRINTF(" SWP_FRAMECHANGED");
1140 if(flags & SWP_SHOWWINDOW) DPRINTF(" SWP_SHOWWINDOW");
1141 if(flags & SWP_HIDEWINDOW) DPRINTF(" SWP_HIDEWINDOW");
1142 if(flags & SWP_NOCOPYBITS) DPRINTF(" SWP_NOCOPYBITS");
1143 if(flags & SWP_NOOWNERZORDER) DPRINTF(" SWP_NOOWNERZORDER");
1144 if(flags & SWP_NOSENDCHANGING) DPRINTF(" SWP_NOSENDCHANGING");
1145 if(flags & SWP_DEFERERASE) DPRINTF(" SWP_DEFERERASE");
1146 if(flags & SWP_ASYNCWINDOWPOS) DPRINTF(" SWP_ASYNCWINDOWPOS");
1148 #define DUMPED_FLAGS \
1154 SWP_FRAMECHANGED | \
1158 SWP_NOOWNERZORDER | \
1159 SWP_NOSENDCHANGING | \
1163 if(flags & ~DUMPED_FLAGS) DPRINTF(" %08x", flags & ~DUMPED_FLAGS);
1168 /***********************************************************************
1169 * SetWindowPos (USER32.@)
1171 BOOL WINAPI SetWindowPos( HWND hwnd, HWND hwndInsertAfter,
1172 INT x, INT y, INT cx, INT cy, UINT flags )
1176 TRACE("hwnd %x, after %x, %d,%d (%dx%d), flags %08x\n",
1177 hwnd, hwndInsertAfter, x, y, cx, cy, flags);
1178 if(TRACE_ON(win)) dump_winpos_flags(flags);
1180 winpos.hwnd = WIN_GetFullHandle(hwnd);
1181 winpos.hwndInsertAfter = WIN_GetFullHandle(hwndInsertAfter);
1186 winpos.flags = flags;
1187 if (WIN_IsCurrentThread( hwnd )) return USER_Driver.pSetWindowPos( &winpos );
1188 return SendMessageW( winpos.hwnd, WM_WINE_SETWINDOWPOS, 0, (LPARAM)&winpos );
1192 /***********************************************************************
1193 * BeginDeferWindowPos (USER32.@)
1195 HDWP WINAPI BeginDeferWindowPos( INT count )
1202 SetLastError(ERROR_INVALID_PARAMETER);
1205 /* Windows allows zero count, in which case it allocates context for 8 moves */
1206 if (count == 0) count = 8;
1208 handle = USER_HEAP_ALLOC( sizeof(DWP) + (count-1)*sizeof(WINDOWPOS) );
1209 if (!handle) return 0;
1210 pDWP = (DWP *) USER_HEAP_LIN_ADDR( handle );
1211 pDWP->actualCount = 0;
1212 pDWP->suggestedCount = count;
1214 pDWP->wMagic = DWP_MAGIC;
1215 pDWP->hwndParent = 0;
1220 /***********************************************************************
1221 * DeferWindowPos (USER32.@)
1223 HDWP WINAPI DeferWindowPos( HDWP hdwp, HWND hwnd, HWND hwndAfter,
1224 INT x, INT y, INT cx, INT cy,
1229 HDWP newhdwp = hdwp,retvalue;
1231 hwnd = WIN_GetFullHandle( hwnd );
1232 if (hwnd == GetDesktopWindow()) return 0;
1234 if (!(pDWP = USER_HEAP_LIN_ADDR( hdwp ))) return 0;
1238 for (i = 0; i < pDWP->actualCount; i++)
1240 if (pDWP->winPos[i].hwnd == hwnd)
1242 /* Merge with the other changes */
1243 if (!(flags & SWP_NOZORDER))
1245 pDWP->winPos[i].hwndInsertAfter = WIN_GetFullHandle(hwndAfter);
1247 if (!(flags & SWP_NOMOVE))
1249 pDWP->winPos[i].x = x;
1250 pDWP->winPos[i].y = y;
1252 if (!(flags & SWP_NOSIZE))
1254 pDWP->winPos[i].cx = cx;
1255 pDWP->winPos[i].cy = cy;
1257 pDWP->winPos[i].flags &= flags | ~(SWP_NOSIZE | SWP_NOMOVE |
1258 SWP_NOZORDER | SWP_NOREDRAW |
1259 SWP_NOACTIVATE | SWP_NOCOPYBITS|
1261 pDWP->winPos[i].flags |= flags & (SWP_SHOWWINDOW | SWP_HIDEWINDOW |
1267 if (pDWP->actualCount >= pDWP->suggestedCount)
1269 newhdwp = USER_HEAP_REALLOC( hdwp,
1270 sizeof(DWP) + pDWP->suggestedCount*sizeof(WINDOWPOS) );
1276 pDWP = (DWP *) USER_HEAP_LIN_ADDR( newhdwp );
1277 pDWP->suggestedCount++;
1279 pDWP->winPos[pDWP->actualCount].hwnd = hwnd;
1280 pDWP->winPos[pDWP->actualCount].hwndInsertAfter = hwndAfter;
1281 pDWP->winPos[pDWP->actualCount].x = x;
1282 pDWP->winPos[pDWP->actualCount].y = y;
1283 pDWP->winPos[pDWP->actualCount].cx = cx;
1284 pDWP->winPos[pDWP->actualCount].cy = cy;
1285 pDWP->winPos[pDWP->actualCount].flags = flags;
1286 pDWP->actualCount++;
1294 /***********************************************************************
1295 * EndDeferWindowPos (USER32.@)
1297 BOOL WINAPI EndDeferWindowPos( HDWP hdwp )
1304 pDWP = (DWP *) USER_HEAP_LIN_ADDR( hdwp );
1305 if (!pDWP) return FALSE;
1306 for (i = 0, winpos = pDWP->winPos; i < pDWP->actualCount; i++, winpos++)
1308 if (!(res = USER_Driver.pSetWindowPos( winpos ))) break;
1310 USER_HEAP_FREE( hdwp );
1315 /***********************************************************************
1316 * TileChildWindows (USER.199)
1318 void WINAPI TileChildWindows16( HWND16 parent, WORD action )
1320 FIXME("(%04x, %d): stub\n", parent, action);
1323 /***********************************************************************
1324 * CascadeChildWindows (USER.198)
1326 void WINAPI CascadeChildWindows16( HWND16 parent, WORD action )
1328 FIXME("(%04x, %d): stub\n", parent, action);
1331 /***********************************************************************
1332 * SetProgmanWindow (USER32.@)
1334 HWND WINAPI SetProgmanWindow ( HWND hwnd )
1336 hGlobalProgmanWindow = hwnd;
1337 return hGlobalProgmanWindow;
1340 /***********************************************************************
1341 * GetProgmanWindow (USER32.@)
1343 HWND WINAPI GetProgmanWindow(void)
1345 return hGlobalProgmanWindow;
1348 /***********************************************************************
1349 * SetShellWindowEx (USER32.@)
1350 * hwndProgman = Progman[Program Manager]
1351 * |-> SHELLDLL_DefView
1352 * hwndListView = | |-> SysListView32
1353 * | | |-> tooltips_class32
1359 HWND WINAPI SetShellWindowEx ( HWND hwndProgman, HWND hwndListView )
1361 FIXME("0x%08x 0x%08x stub\n",hwndProgman ,hwndListView );
1362 hGlobalShellWindow = hwndProgman;
1363 return hGlobalShellWindow;
1367 /***********************************************************************
1368 * SetTaskmanWindow (USER32.@)
1370 * hwnd = MSTaskSwWClass
1371 * |-> SysTabControl32
1373 HWND WINAPI SetTaskmanWindow ( HWND hwnd )
1375 hGlobalTaskmanWindow = hwnd;
1376 return hGlobalTaskmanWindow;
1379 /***********************************************************************
1380 * GetTaskmanWindow (USER32.@)
1382 HWND WINAPI GetTaskmanWindow(void)
1384 return hGlobalTaskmanWindow;