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
29 #include "wine/winuser16.h"
30 #include "wine/server.h"
36 #include "nonclient.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 #define HAS_DLGFRAME(style,exStyle) \
42 (((exStyle) & WS_EX_DLGMODALFRAME) || \
43 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
45 #define HAS_THICKFRAME(style) \
46 (((style) & WS_THICKFRAME) && \
47 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
49 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
51 #define PLACE_MIN 0x0001
52 #define PLACE_MAX 0x0002
53 #define PLACE_RECT 0x0004
56 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
68 /* ----- internal variables ----- */
70 static LPCSTR atomInternalPos
;
73 /***********************************************************************
74 * WINPOS_CreateInternalPosAtom
76 BOOL
WINPOS_CreateInternalPosAtom()
79 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
80 return (atomInternalPos
) ? TRUE
: FALSE
;
83 /***********************************************************************
84 * WINPOS_CheckInternalPos
86 * Called when a window is destroyed.
88 void WINPOS_CheckInternalPos( HWND hwnd
)
90 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
94 if( IsWindow(lpPos
->hwndIconTitle
) )
95 DestroyWindow( lpPos
->hwndIconTitle
);
96 HeapFree( GetProcessHeap(), 0, lpPos
);
100 /***********************************************************************
101 * ArrangeIconicWindows (USER32.@)
103 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
107 INT x
, y
, xspacing
, yspacing
;
109 GetClientRect( parent
, &rectParent
);
111 y
= rectParent
.bottom
;
112 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
113 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
115 hwndChild
= GetWindow( parent
, GW_CHILD
);
118 if( IsIconic( hwndChild
) )
120 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
122 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
123 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
124 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
125 if( IsWindow(hwndChild
) )
126 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
128 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
135 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
141 /***********************************************************************
142 * SwitchToThisWindow (USER32.@)
144 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
146 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
150 /***********************************************************************
151 * GetWindowRect (USER32.@)
153 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
155 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
158 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
159 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
160 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
166 /***********************************************************************
167 * GetWindowRgn (USER32.@)
169 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
172 WND
*wndPtr
= WIN_GetPtr( hwnd
);
174 if (wndPtr
== WND_OTHER_PROCESS
)
176 if (IsWindow( hwnd
))
177 FIXME( "not supported on other process window %p\n", hwnd
);
182 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
185 if (wndPtr
->hrgnWnd
) nRet
= CombineRgn( hrgn
, wndPtr
->hrgnWnd
, 0, RGN_COPY
);
186 WIN_ReleasePtr( wndPtr
);
191 /***********************************************************************
192 * SetWindowRgn (USER32.@)
194 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
199 if (hrgn
) /* verify that region really exists */
201 if (GetRgnBox( hrgn
, &rect
) == ERROR
) return FALSE
;
204 if (USER_Driver
.pSetWindowRgn
)
205 return USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
207 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
209 if (IsWindow( hwnd
))
210 FIXME( "not supported on other process window %p\n", hwnd
);
215 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
219 if (wndPtr
->hrgnWnd
== hrgn
)
221 WIN_ReleasePtr( wndPtr
);
227 /* delete previous region */
228 DeleteObject(wndPtr
->hrgnWnd
);
231 wndPtr
->hrgnWnd
= hrgn
;
232 WIN_ReleasePtr( wndPtr
);
234 /* Size the window to the rectangle of the new region (if it isn't NULL) */
235 if (hrgn
) SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
236 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
237 SWP_NOSIZE
| SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOACTIVATE
|
238 SWP_NOZORDER
| (bRedraw
? 0 : SWP_NOREDRAW
) );
243 /***********************************************************************
244 * GetClientRect (USER32.@)
246 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
250 rect
->right
= rect
->bottom
= 0;
251 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
253 rect
->right
-= rect
->left
;
254 rect
->bottom
-= rect
->top
;
256 rect
->left
= rect
->top
= 0;
261 /*******************************************************************
262 * ClientToScreen (USER32.@)
264 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
266 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
271 /*******************************************************************
272 * ScreenToClient (USER32.@)
274 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
276 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
281 /***********************************************************************
282 * find_child_from_point
284 * Find the child that contains pt. Helper for WindowFromPoint.
285 * pt is in parent client coordinates.
286 * lparam is the param to pass in the WM_NCHITTEST message.
288 static HWND
find_child_from_point( HWND parent
, POINT pt
, INT
*hittest
, LPARAM lparam
)
292 RECT rectWindow
, rectClient
;
294 HWND
*list
= WIN_ListChildren( parent
);
298 for (i
= 0; list
[i
]; i
++)
300 /* If point is in window, and window is visible, and it */
301 /* is enabled (or it's a top-level window), then explore */
302 /* its children. Otherwise, go to the next window. */
304 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
305 if (!(style
& WS_VISIBLE
)) continue; /* not visible -> skip */
306 if ((style
& (WS_POPUP
| WS_CHILD
| WS_DISABLED
)) == (WS_CHILD
| WS_DISABLED
))
307 continue; /* disabled child -> skip */
308 exstyle
= GetWindowLongW( list
[i
], GWL_EXSTYLE
);
309 if ((exstyle
& (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
| WS_EX_TRANSPARENT
))
310 continue; /* transparent -> skip */
312 if (!WIN_GetRectangles( list
[i
], &rectWindow
, &rectClient
)) continue;
313 if (!PtInRect( &rectWindow
, pt
)) continue; /* not in window -> skip */
315 /* FIXME: check window region for other processes too */
316 if ((wndPtr
= WIN_GetPtr( list
[i
] )) && wndPtr
!= WND_OTHER_PROCESS
)
318 if (wndPtr
->hrgnWnd
&& !PtInRegion( wndPtr
->hrgnWnd
,
319 pt
.x
- rectWindow
.left
, pt
.y
- rectWindow
.top
))
321 WIN_ReleasePtr( wndPtr
);
322 continue; /* point outside window region -> skip */
324 WIN_ReleasePtr( wndPtr
);
327 /* If window is minimized or disabled, return at once */
328 if (style
& WS_MINIMIZE
)
330 *hittest
= HTCAPTION
;
334 if (style
& WS_DISABLED
)
341 /* If point is in client area, explore children */
342 if (PtInRect( &rectClient
, pt
))
346 new_pt
.x
= pt
.x
- rectClient
.left
;
347 new_pt
.y
= pt
.y
- rectClient
.top
;
348 if ((retvalue
= find_child_from_point( list
[i
], new_pt
, hittest
, lparam
))) break;
351 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
352 if (!WIN_IsCurrentThread( list
[i
] ))
358 if ((res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, lparam
)) != HTTRANSPARENT
)
360 *hittest
= res
; /* Found the window */
364 /* continue search with next sibling */
366 HeapFree( GetProcessHeap(), 0, list
);
371 /***********************************************************************
372 * WINPOS_WindowFromPoint
374 * Find the window and hittest for a given point.
376 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
382 TRACE("scope %p %ld,%ld\n", hwndScope
, pt
.x
, pt
.y
);
384 if (!hwndScope
) hwndScope
= GetDesktopWindow();
385 style
= GetWindowLongW( hwndScope
, GWL_STYLE
);
388 if (style
& WS_DISABLED
) return 0;
390 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope
, GA_PARENT
), &xy
, 1 );
392 if (!(style
& WS_MINIMIZE
))
395 if (WIN_GetRectangles( hwndScope
, NULL
, &rectClient
) && PtInRect( &rectClient
, xy
))
399 xy
.x
-= rectClient
.left
;
400 xy
.y
-= rectClient
.top
;
401 if ((ret
= find_child_from_point( hwndScope
, xy
, hittest
, MAKELONG( pt
.x
, pt
.y
) )))
403 TRACE( "found child %p\n", ret
);
409 /* If nothing found, try the scope window */
410 if (!WIN_IsCurrentThread( hwndScope
))
413 TRACE( "returning %p\n", hwndScope
);
416 res
= SendMessageA( hwndScope
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
417 if (res
!= HTTRANSPARENT
)
419 *hittest
= res
; /* Found the window */
420 TRACE( "returning %p\n", hwndScope
);
423 *hittest
= HTNOWHERE
;
424 TRACE( "nothing found\n" );
429 /*******************************************************************
430 * WindowFromPoint (USER32.@)
432 HWND WINAPI
WindowFromPoint( POINT pt
)
435 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
439 /*******************************************************************
440 * ChildWindowFromPoint (USER32.@)
442 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
444 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
447 /*******************************************************************
448 * ChildWindowFromPointEx (USER32.@)
450 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
452 /* pt is in the client coordinates */
458 GetClientRect( hwndParent
, &rect
);
459 if (!PtInRect( &rect
, pt
)) return 0;
460 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
462 for (i
= 0; list
[i
]; i
++)
464 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
465 if (!PtInRect( &rect
, pt
)) continue;
466 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
468 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
469 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
470 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
472 if (uFlags
& CWP_SKIPTRANSPARENT
)
474 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
479 HeapFree( GetProcessHeap(), 0, list
);
480 if (!retvalue
) retvalue
= hwndParent
;
485 /*******************************************************************
486 * WINPOS_GetWinOffset
488 * Calculate the offset between the origin of the two windows. Used
489 * to implement MapWindowPoints.
491 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
495 offset
->x
= offset
->y
= 0;
497 /* Translate source window origin to screen coords */
500 HWND hwnd
= hwndFrom
;
504 if (hwnd
== hwndTo
) return;
505 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
507 ERR( "bad hwndFrom = %p\n", hwnd
);
510 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
511 offset
->x
+= wndPtr
->rectClient
.left
;
512 offset
->y
+= wndPtr
->rectClient
.top
;
513 hwnd
= wndPtr
->parent
;
514 WIN_ReleasePtr( wndPtr
);
518 /* Translate origin to destination window coords */
525 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
527 ERR( "bad hwndTo = %p\n", hwnd
);
530 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
531 offset
->x
-= wndPtr
->rectClient
.left
;
532 offset
->y
-= wndPtr
->rectClient
.top
;
533 hwnd
= wndPtr
->parent
;
534 WIN_ReleasePtr( wndPtr
);
539 other_process
: /* one of the parents may belong to another process, do it the hard way */
540 offset
->x
= offset
->y
= 0;
541 SERVER_START_REQ( get_windows_offset
)
543 req
->from
= hwndFrom
;
545 if (!wine_server_call( req
))
547 offset
->x
= reply
->x
;
548 offset
->y
= reply
->y
;
555 /*******************************************************************
556 * MapWindowPoints (USER.258)
558 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
559 LPPOINT16 lppt
, UINT16 count
)
563 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
573 /*******************************************************************
574 * MapWindowPoints (USER32.@)
576 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
580 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
587 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
591 /***********************************************************************
592 * IsIconic (USER32.@)
594 BOOL WINAPI
IsIconic(HWND hWnd
)
596 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
600 /***********************************************************************
601 * IsZoomed (USER32.@)
603 BOOL WINAPI
IsZoomed(HWND hWnd
)
605 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
609 /*******************************************************************
610 * AllowSetForegroundWindow (USER32.@)
612 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
614 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
615 * implemented, then fix this function. */
620 /*******************************************************************
621 * LockSetForegroundWindow (USER32.@)
623 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
625 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
626 * implemented, then fix this function. */
631 /***********************************************************************
632 * BringWindowToTop (USER32.@)
634 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
636 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
640 /***********************************************************************
641 * MoveWindow (USER32.@)
643 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
646 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
647 if (!repaint
) flags
|= SWP_NOREDRAW
;
648 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
649 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
652 /***********************************************************************
653 * WINPOS_InitInternalPos
655 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
657 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
661 /* this happens when the window is minimized/maximized
662 * for the first time (rectWindow is not adjusted yet) */
664 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
665 if( !lpPos
) return NULL
;
667 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
668 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
669 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
670 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
673 if( wnd
->dwStyle
& WS_MINIMIZE
)
674 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
675 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
676 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
677 else if( restoreRect
)
678 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
683 /***********************************************************************
684 * WINPOS_RedrawIconTitle
686 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
688 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
691 if( lpPos
->hwndIconTitle
)
693 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
694 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
701 /***********************************************************************
702 * WINPOS_ShowIconTitle
704 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
706 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
708 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
710 HWND title
= lpPos
->hwndIconTitle
;
712 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
715 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
718 if (!IsWindowVisible(title
))
720 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
721 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
722 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
725 else ShowWindow( title
, SW_HIDE
);
730 /*******************************************************************
731 * WINPOS_GetMinMaxInfo
733 * Get the minimized and maximized information for a window.
735 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
736 POINT
*minTrack
, POINT
*maxTrack
)
741 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
742 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
744 /* Compute default values */
746 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
747 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
748 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
749 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
750 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
751 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
753 if (HAS_DLGFRAME( style
, exstyle
))
755 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
756 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
761 if (HAS_THICKFRAME(style
))
763 xinc
+= GetSystemMetrics(SM_CXFRAME
);
764 yinc
+= GetSystemMetrics(SM_CYFRAME
);
766 if (style
& WS_BORDER
)
768 xinc
+= GetSystemMetrics(SM_CXBORDER
);
769 yinc
+= GetSystemMetrics(SM_CYBORDER
);
772 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
773 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
775 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
776 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
777 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
780 MinMax
.ptMaxPosition
.x
= -xinc
;
781 MinMax
.ptMaxPosition
.y
= -yinc
;
784 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
786 /* Some sanity checks */
788 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
789 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
790 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
791 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
792 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
793 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
794 MinMax
.ptMinTrackSize
.x
);
795 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
796 MinMax
.ptMinTrackSize
.y
);
798 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
799 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
800 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
801 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
804 /***********************************************************************
805 * ShowWindowAsync (USER32.@)
807 * doesn't wait; returns immediately.
808 * used by threads to toggle windows in other (possibly hanging) threads
810 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
814 if (is_broadcast(hwnd
))
816 SetLastError( ERROR_INVALID_PARAMETER
);
820 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
821 return USER_Driver
.pShowWindow( full_handle
, cmd
);
822 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
826 /***********************************************************************
827 * ShowWindow (USER32.@)
829 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
833 if (is_broadcast(hwnd
))
835 SetLastError( ERROR_INVALID_PARAMETER
);
838 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
840 if (USER_Driver
.pShowWindow
)
841 return USER_Driver
.pShowWindow( full_handle
, cmd
);
844 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
848 /***********************************************************************
849 * GetInternalWindowPos (USER32.@)
851 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
854 WINDOWPLACEMENT wndpl
;
855 if (GetWindowPlacement( hwnd
, &wndpl
))
857 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
858 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
859 return wndpl
.showCmd
;
865 /***********************************************************************
866 * GetWindowPlacement (USER32.@)
869 * Fails if wndpl->length of Win95 (!) apps is invalid.
871 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
873 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
876 if(!pWnd
) return FALSE
;
878 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
879 wndpl
->length
= sizeof(*wndpl
);
880 if( pWnd
->dwStyle
& WS_MINIMIZE
)
881 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
883 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
884 if( pWnd
->flags
& WIN_RESTORE_MAX
)
885 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
888 CONV_POINT16TO32( &lpPos
->ptIconPos
, &wndpl
->ptMinPosition
);
889 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &wndpl
->ptMaxPosition
);
890 CONV_RECT16TO32( &lpPos
->rectNormal
, &wndpl
->rcNormalPosition
);
891 WIN_ReleaseWndPtr(pWnd
);
896 /***********************************************************************
897 * WINPOS_SetPlacement
899 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
901 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
904 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
905 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
907 if( flags
& PLACE_MIN
) CONV_POINT32TO16( &wndpl
->ptMinPosition
, &lpPos
->ptIconPos
);
908 if( flags
& PLACE_MAX
) CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &lpPos
->ptMaxPos
);
909 if( flags
& PLACE_RECT
) CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &lpPos
->rectNormal
);
911 if( pWnd
->dwStyle
& WS_MINIMIZE
)
913 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
914 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
915 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
916 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
918 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
920 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
921 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
922 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
924 else if( flags
& PLACE_RECT
)
925 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
926 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
927 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
928 SWP_NOZORDER
| SWP_NOACTIVATE
);
930 ShowWindow( hwnd
, wndpl
->showCmd
);
931 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
933 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
935 /* SDK: ...valid only the next time... */
936 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
938 WIN_ReleaseWndPtr(pWnd
);
945 /***********************************************************************
946 * SetWindowPlacement (USER32.@)
949 * Fails if wndpl->length of Win95 (!) apps is invalid.
951 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
953 if (!wpl
) return FALSE
;
954 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
958 /***********************************************************************
959 * AnimateWindow (USER32.@)
960 * Shows/Hides a window with an animation
963 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
965 FIXME("partial stub\n");
967 /* If trying to show/hide and it's already *
968 * shown/hidden or invalid window, fail with *
969 * invalid parameter */
970 if(!IsWindow(hwnd
) ||
971 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
972 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
974 SetLastError(ERROR_INVALID_PARAMETER
);
978 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
983 /***********************************************************************
984 * SetInternalWindowPos (USER32.@)
986 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
987 LPRECT rect
, LPPOINT pt
)
991 WINDOWPLACEMENT wndpl
;
994 wndpl
.length
= sizeof(wndpl
);
995 wndpl
.showCmd
= showCmd
;
996 wndpl
.flags
= flags
= 0;
1001 wndpl
.flags
|= WPF_SETMINPOSITION
;
1002 wndpl
.ptMinPosition
= *pt
;
1006 flags
|= PLACE_RECT
;
1007 wndpl
.rcNormalPosition
= *rect
;
1009 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1014 /*******************************************************************
1015 * can_activate_window
1017 * Check if we can activate the specified window.
1019 static BOOL
can_activate_window( HWND hwnd
)
1023 if (!hwnd
) return FALSE
;
1024 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1025 if (!(style
& WS_VISIBLE
)) return FALSE
;
1026 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1027 return !(style
& WS_DISABLED
);
1031 /*******************************************************************
1032 * WINPOS_ActivateOtherWindow
1034 * Activates window other than pWnd.
1036 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1040 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1042 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1043 if (can_activate_window( hwndTo
)) goto done
;
1049 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1050 if (can_activate_window( hwndTo
)) break;
1054 fg
= GetForegroundWindow();
1055 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1056 if (!fg
|| (hwnd
== fg
))
1058 if (SetForegroundWindow( hwndTo
)) return;
1060 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1064 /***********************************************************************
1065 * WINPOS_HandleWindowPosChanging16
1067 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1069 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1071 POINT maxSize
, minTrack
;
1072 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1074 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1075 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1077 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1078 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1079 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1080 if (!(style
& WS_MINIMIZE
))
1082 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1083 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1090 /***********************************************************************
1091 * WINPOS_HandleWindowPosChanging
1093 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1095 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1097 POINT maxSize
, minTrack
;
1098 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1100 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1101 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1103 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1104 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1105 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1106 if (!(style
& WS_MINIMIZE
))
1108 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1109 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1116 /***********************************************************************
1119 static void dump_winpos_flags(UINT flags
)
1122 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1123 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1124 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1125 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1126 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1127 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1128 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1129 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1130 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1131 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1132 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1133 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1134 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1136 #define DUMPED_FLAGS \
1142 SWP_FRAMECHANGED | \
1146 SWP_NOOWNERZORDER | \
1147 SWP_NOSENDCHANGING | \
1151 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1156 /***********************************************************************
1157 * SetWindowPos (USER32.@)
1159 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1160 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1164 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1165 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1166 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1168 if (is_broadcast(hwnd
))
1170 SetLastError( ERROR_INVALID_PARAMETER
);
1174 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1175 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1180 winpos
.flags
= flags
;
1181 if (WIN_IsCurrentThread( hwnd
)) return USER_Driver
.pSetWindowPos( &winpos
);
1182 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1186 /***********************************************************************
1187 * BeginDeferWindowPos (USER32.@)
1189 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1196 SetLastError(ERROR_INVALID_PARAMETER
);
1199 /* Windows allows zero count, in which case it allocates context for 8 moves */
1200 if (count
== 0) count
= 8;
1202 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1203 if (!handle
) return 0;
1204 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1205 pDWP
->actualCount
= 0;
1206 pDWP
->suggestedCount
= count
;
1208 pDWP
->wMagic
= DWP_MAGIC
;
1209 pDWP
->hwndParent
= 0;
1214 /***********************************************************************
1215 * DeferWindowPos (USER32.@)
1217 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1218 INT x
, INT y
, INT cx
, INT cy
,
1223 HDWP newhdwp
= hdwp
,retvalue
;
1225 hwnd
= WIN_GetFullHandle( hwnd
);
1226 if (hwnd
== GetDesktopWindow()) return 0;
1228 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1232 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1234 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1236 /* Merge with the other changes */
1237 if (!(flags
& SWP_NOZORDER
))
1239 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1241 if (!(flags
& SWP_NOMOVE
))
1243 pDWP
->winPos
[i
].x
= x
;
1244 pDWP
->winPos
[i
].y
= y
;
1246 if (!(flags
& SWP_NOSIZE
))
1248 pDWP
->winPos
[i
].cx
= cx
;
1249 pDWP
->winPos
[i
].cy
= cy
;
1251 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1252 SWP_NOZORDER
| SWP_NOREDRAW
|
1253 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1255 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1261 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1263 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1264 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1270 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1271 pDWP
->suggestedCount
++;
1273 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1274 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1275 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1276 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1277 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1278 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1279 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1280 pDWP
->actualCount
++;
1288 /***********************************************************************
1289 * EndDeferWindowPos (USER32.@)
1291 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1298 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1299 if (!pDWP
) return FALSE
;
1300 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1302 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1304 USER_HEAP_FREE( hdwp
);
1309 /***********************************************************************
1310 * TileChildWindows (USER.199)
1312 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1314 FIXME("(%04x, %d): stub\n", parent
, action
);
1317 /***********************************************************************
1318 * CascadeChildWindows (USER.198)
1320 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1322 FIXME("(%04x, %d): stub\n", parent
, action
);