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 %p (%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 %p\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 %p\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 %p %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 %p\n", ret
);
414 /* If nothing found, try the scope window */
415 if (!WIN_IsCurrentThread( hwndScope
))
418 TRACE( "returning %p\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 %p\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 = %p\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 = %p\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=%p) semi stub\n",hwndshell
);
642 hGlobalShellWindow
= WIN_GetFullHandle( hwndshell
);
643 return hGlobalShellWindow
;
647 /*******************************************************************
648 * GetShellWindow (USER32.@)
650 HWND WINAPI
GetShellWindow(void)
651 { WARN("(hWnd=%p) 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("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
675 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
678 /***********************************************************************
679 * WINPOS_InitInternalPos
681 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
683 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
687 /* this happens when the window is minimized/maximized
688 * for the first time (rectWindow is not adjusted yet) */
690 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
691 if( !lpPos
) return NULL
;
693 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
694 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
695 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
696 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
699 if( wnd
->dwStyle
& WS_MINIMIZE
)
700 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
701 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
702 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
703 else if( restoreRect
)
704 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
709 /***********************************************************************
710 * WINPOS_RedrawIconTitle
712 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
714 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
717 if( lpPos
->hwndIconTitle
)
719 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
720 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
727 /***********************************************************************
728 * WINPOS_ShowIconTitle
730 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
732 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
734 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
736 HWND title
= lpPos
->hwndIconTitle
;
738 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
741 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
744 if (!IsWindowVisible(title
))
746 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
747 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
748 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
751 else ShowWindow( title
, SW_HIDE
);
756 /*******************************************************************
757 * WINPOS_GetMinMaxInfo
759 * Get the minimized and maximized information for a window.
761 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
762 POINT
*minTrack
, POINT
*maxTrack
)
767 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
768 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
770 /* Compute default values */
772 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
773 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
774 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
775 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
776 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
777 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
779 if (HAS_DLGFRAME( style
, exstyle
))
781 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
782 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
787 if (HAS_THICKFRAME(style
))
789 xinc
+= GetSystemMetrics(SM_CXFRAME
);
790 yinc
+= GetSystemMetrics(SM_CYFRAME
);
792 if (style
& WS_BORDER
)
794 xinc
+= GetSystemMetrics(SM_CXBORDER
);
795 yinc
+= GetSystemMetrics(SM_CYBORDER
);
798 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
799 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
801 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
802 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
803 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
806 MinMax
.ptMaxPosition
.x
= -xinc
;
807 MinMax
.ptMaxPosition
.y
= -yinc
;
810 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
812 /* Some sanity checks */
814 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
815 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
816 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
817 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
818 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
819 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
820 MinMax
.ptMinTrackSize
.x
);
821 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
822 MinMax
.ptMinTrackSize
.y
);
824 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
825 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
826 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
827 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
830 /***********************************************************************
831 * ShowWindowAsync (USER32.@)
833 * doesn't wait; returns immediately.
834 * used by threads to toggle windows in other (possibly hanging) threads
836 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
840 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
841 return USER_Driver
.pShowWindow( full_handle
, cmd
);
842 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
846 /***********************************************************************
847 * ShowWindow (USER32.@)
849 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
853 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
854 return USER_Driver
.pShowWindow( full_handle
, cmd
);
855 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
859 /***********************************************************************
860 * GetInternalWindowPos (USER32.@)
862 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
865 WINDOWPLACEMENT wndpl
;
866 if (GetWindowPlacement( hwnd
, &wndpl
))
868 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
869 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
870 return wndpl
.showCmd
;
876 /***********************************************************************
877 * GetWindowPlacement (USER32.@)
880 * Fails if wndpl->length of Win95 (!) apps is invalid.
882 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
884 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
887 if(!pWnd
) return FALSE
;
889 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
890 wndpl
->length
= sizeof(*wndpl
);
891 if( pWnd
->dwStyle
& WS_MINIMIZE
)
892 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
894 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
895 if( pWnd
->flags
& WIN_RESTORE_MAX
)
896 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
899 CONV_POINT16TO32( &lpPos
->ptIconPos
, &wndpl
->ptMinPosition
);
900 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &wndpl
->ptMaxPosition
);
901 CONV_RECT16TO32( &lpPos
->rectNormal
, &wndpl
->rcNormalPosition
);
902 WIN_ReleaseWndPtr(pWnd
);
907 /***********************************************************************
908 * WINPOS_SetPlacement
910 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
912 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
915 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
916 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
918 if( flags
& PLACE_MIN
) CONV_POINT32TO16( &wndpl
->ptMinPosition
, &lpPos
->ptIconPos
);
919 if( flags
& PLACE_MAX
) CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &lpPos
->ptMaxPos
);
920 if( flags
& PLACE_RECT
) CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &lpPos
->rectNormal
);
922 if( pWnd
->dwStyle
& WS_MINIMIZE
)
924 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
925 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
926 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
927 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
929 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
931 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
932 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
933 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
935 else if( flags
& PLACE_RECT
)
936 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
937 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
938 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
939 SWP_NOZORDER
| SWP_NOACTIVATE
);
941 ShowWindow( hwnd
, wndpl
->showCmd
);
942 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
944 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
946 /* SDK: ...valid only the next time... */
947 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
949 WIN_ReleaseWndPtr(pWnd
);
956 /***********************************************************************
957 * SetWindowPlacement (USER32.@)
960 * Fails if wndpl->length of Win95 (!) apps is invalid.
962 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
964 if (!wpl
) return FALSE
;
965 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
969 /***********************************************************************
970 * AnimateWindow (USER32.@)
971 * Shows/Hides a window with an animation
974 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
976 FIXME("partial stub\n");
978 /* If trying to show/hide and it's already *
979 * shown/hidden or invalid window, fail with *
980 * invalid parameter */
981 if(!IsWindow(hwnd
) ||
982 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
983 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
985 SetLastError(ERROR_INVALID_PARAMETER
);
989 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
994 /***********************************************************************
995 * SetInternalWindowPos (USER32.@)
997 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
998 LPRECT rect
, LPPOINT pt
)
1000 if( IsWindow(hwnd
) )
1002 WINDOWPLACEMENT wndpl
;
1005 wndpl
.length
= sizeof(wndpl
);
1006 wndpl
.showCmd
= showCmd
;
1007 wndpl
.flags
= flags
= 0;
1012 wndpl
.flags
|= WPF_SETMINPOSITION
;
1013 wndpl
.ptMinPosition
= *pt
;
1017 flags
|= PLACE_RECT
;
1018 wndpl
.rcNormalPosition
= *rect
;
1020 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1025 /*******************************************************************
1026 * can_activate_window
1028 * Check if we can activate the specified window.
1030 static BOOL
can_activate_window( HWND hwnd
)
1034 if (!hwnd
) return FALSE
;
1035 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1036 if (!(style
& WS_VISIBLE
)) return FALSE
;
1037 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1038 return !(style
& WS_DISABLED
);
1042 /*******************************************************************
1043 * WINPOS_ActivateOtherWindow
1045 * Activates window other than pWnd.
1047 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1051 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1053 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1054 if (can_activate_window( hwndTo
)) goto done
;
1060 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1061 if (can_activate_window( hwndTo
)) break;
1065 fg
= GetForegroundWindow();
1066 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1067 if (!fg
|| (hwnd
== fg
))
1069 if (SetForegroundWindow( hwndTo
)) return;
1071 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1075 /***********************************************************************
1076 * WINPOS_HandleWindowPosChanging16
1078 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1080 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1082 POINT maxSize
, minTrack
;
1083 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1085 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1086 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1088 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1089 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1090 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1091 if (!(style
& WS_MINIMIZE
))
1093 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1094 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1101 /***********************************************************************
1102 * WINPOS_HandleWindowPosChanging
1104 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1106 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1108 POINT maxSize
, minTrack
;
1109 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1111 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1112 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1114 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1115 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1116 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1117 if (!(style
& WS_MINIMIZE
))
1119 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1120 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1127 /***********************************************************************
1130 static void dump_winpos_flags(UINT flags
)
1133 if(flags
& SWP_NOSIZE
) DPRINTF(" SWP_NOSIZE");
1134 if(flags
& SWP_NOMOVE
) DPRINTF(" SWP_NOMOVE");
1135 if(flags
& SWP_NOZORDER
) DPRINTF(" SWP_NOZORDER");
1136 if(flags
& SWP_NOREDRAW
) DPRINTF(" SWP_NOREDRAW");
1137 if(flags
& SWP_NOACTIVATE
) DPRINTF(" SWP_NOACTIVATE");
1138 if(flags
& SWP_FRAMECHANGED
) DPRINTF(" SWP_FRAMECHANGED");
1139 if(flags
& SWP_SHOWWINDOW
) DPRINTF(" SWP_SHOWWINDOW");
1140 if(flags
& SWP_HIDEWINDOW
) DPRINTF(" SWP_HIDEWINDOW");
1141 if(flags
& SWP_NOCOPYBITS
) DPRINTF(" SWP_NOCOPYBITS");
1142 if(flags
& SWP_NOOWNERZORDER
) DPRINTF(" SWP_NOOWNERZORDER");
1143 if(flags
& SWP_NOSENDCHANGING
) DPRINTF(" SWP_NOSENDCHANGING");
1144 if(flags
& SWP_DEFERERASE
) DPRINTF(" SWP_DEFERERASE");
1145 if(flags
& SWP_ASYNCWINDOWPOS
) DPRINTF(" SWP_ASYNCWINDOWPOS");
1147 #define DUMPED_FLAGS \
1153 SWP_FRAMECHANGED | \
1157 SWP_NOOWNERZORDER | \
1158 SWP_NOSENDCHANGING | \
1162 if(flags
& ~DUMPED_FLAGS
) DPRINTF(" %08x", flags
& ~DUMPED_FLAGS
);
1167 /***********************************************************************
1168 * SetWindowPos (USER32.@)
1170 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1171 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1175 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1176 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1177 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1179 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1180 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1185 winpos
.flags
= flags
;
1186 if (WIN_IsCurrentThread( hwnd
)) return USER_Driver
.pSetWindowPos( &winpos
);
1187 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1191 /***********************************************************************
1192 * BeginDeferWindowPos (USER32.@)
1194 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1201 SetLastError(ERROR_INVALID_PARAMETER
);
1204 /* Windows allows zero count, in which case it allocates context for 8 moves */
1205 if (count
== 0) count
= 8;
1207 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1208 if (!handle
) return 0;
1209 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1210 pDWP
->actualCount
= 0;
1211 pDWP
->suggestedCount
= count
;
1213 pDWP
->wMagic
= DWP_MAGIC
;
1214 pDWP
->hwndParent
= 0;
1219 /***********************************************************************
1220 * DeferWindowPos (USER32.@)
1222 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1223 INT x
, INT y
, INT cx
, INT cy
,
1228 HDWP newhdwp
= hdwp
,retvalue
;
1230 hwnd
= WIN_GetFullHandle( hwnd
);
1231 if (hwnd
== GetDesktopWindow()) return 0;
1233 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1237 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1239 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1241 /* Merge with the other changes */
1242 if (!(flags
& SWP_NOZORDER
))
1244 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1246 if (!(flags
& SWP_NOMOVE
))
1248 pDWP
->winPos
[i
].x
= x
;
1249 pDWP
->winPos
[i
].y
= y
;
1251 if (!(flags
& SWP_NOSIZE
))
1253 pDWP
->winPos
[i
].cx
= cx
;
1254 pDWP
->winPos
[i
].cy
= cy
;
1256 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1257 SWP_NOZORDER
| SWP_NOREDRAW
|
1258 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1260 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1266 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1268 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1269 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1275 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1276 pDWP
->suggestedCount
++;
1278 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1279 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1280 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1281 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1282 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1283 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1284 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1285 pDWP
->actualCount
++;
1293 /***********************************************************************
1294 * EndDeferWindowPos (USER32.@)
1296 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1303 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1304 if (!pDWP
) return FALSE
;
1305 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1307 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1309 USER_HEAP_FREE( hdwp
);
1314 /***********************************************************************
1315 * TileChildWindows (USER.199)
1317 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1319 FIXME("(%04x, %d): stub\n", parent
, action
);
1322 /***********************************************************************
1323 * CascadeChildWindows (USER.198)
1325 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1327 FIXME("(%04x, %d): stub\n", parent
, action
);
1330 /***********************************************************************
1331 * SetProgmanWindow (USER32.@)
1333 HWND WINAPI
SetProgmanWindow ( HWND hwnd
)
1335 hGlobalProgmanWindow
= hwnd
;
1336 return hGlobalProgmanWindow
;
1339 /***********************************************************************
1340 * GetProgmanWindow (USER32.@)
1342 HWND WINAPI
GetProgmanWindow(void)
1344 return hGlobalProgmanWindow
;
1347 /***********************************************************************
1348 * SetShellWindowEx (USER32.@)
1349 * hwndProgman = Progman[Program Manager]
1350 * |-> SHELLDLL_DefView
1351 * hwndListView = | |-> SysListView32
1352 * | | |-> tooltips_class32
1358 HWND WINAPI
SetShellWindowEx ( HWND hwndProgman
, HWND hwndListView
)
1360 FIXME("%p %p stub\n",hwndProgman
,hwndListView
);
1361 hGlobalShellWindow
= hwndProgman
;
1362 return hGlobalShellWindow
;
1366 /***********************************************************************
1367 * SetTaskmanWindow (USER32.@)
1369 * hwnd = MSTaskSwWClass
1370 * |-> SysTabControl32
1372 HWND WINAPI
SetTaskmanWindow ( HWND hwnd
)
1374 hGlobalTaskmanWindow
= hwnd
;
1375 return hGlobalTaskmanWindow
;
1378 /***********************************************************************
1379 * GetTaskmanWindow (USER32.@)
1381 HWND WINAPI
GetTaskmanWindow(void)
1383 return hGlobalTaskmanWindow
;