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"
34 #include "nonclient.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(win
);
39 #define HAS_DLGFRAME(style,exStyle) \
40 (((exStyle) & WS_EX_DLGMODALFRAME) || \
41 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
43 #define HAS_THICKFRAME(style) \
44 (((style) & WS_THICKFRAME) && \
45 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
47 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
49 #define PLACE_MIN 0x0001
50 #define PLACE_MAX 0x0002
51 #define PLACE_RECT 0x0004
54 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
66 /* ----- internal variables ----- */
68 static HWND hGlobalShellWindow
=0; /*the shell*/
69 static HWND hGlobalTaskmanWindow
=0;
70 static HWND hGlobalProgmanWindow
=0;
72 static LPCSTR atomInternalPos
;
75 /***********************************************************************
76 * WINPOS_CreateInternalPosAtom
78 BOOL
WINPOS_CreateInternalPosAtom()
81 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
82 return (atomInternalPos
) ? TRUE
: FALSE
;
85 /***********************************************************************
86 * WINPOS_CheckInternalPos
88 * Called when a window is destroyed.
90 void WINPOS_CheckInternalPos( HWND hwnd
)
92 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
96 if( IsWindow(lpPos
->hwndIconTitle
) )
97 DestroyWindow( lpPos
->hwndIconTitle
);
98 HeapFree( GetProcessHeap(), 0, lpPos
);
102 /***********************************************************************
103 * ArrangeIconicWindows (USER32.@)
105 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
109 INT x
, y
, xspacing
, yspacing
;
111 GetClientRect( parent
, &rectParent
);
113 y
= rectParent
.bottom
;
114 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
115 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
117 hwndChild
= GetWindow( parent
, GW_CHILD
);
120 if( IsIconic( hwndChild
) )
122 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
124 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
125 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
126 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
127 if( IsWindow(hwndChild
) )
128 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
130 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
137 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
143 /***********************************************************************
144 * SwitchToThisWindow (USER32.@)
146 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
148 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
152 /***********************************************************************
153 * GetWindowRect (USER32.@)
155 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
157 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
160 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
161 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
162 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
168 /***********************************************************************
169 * GetWindowRgn (USER32.@)
171 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
174 WND
*wndPtr
= WIN_GetPtr( hwnd
);
176 if (wndPtr
== WND_OTHER_PROCESS
)
178 if (IsWindow( hwnd
))
179 FIXME( "not supported on other process window %p\n", hwnd
);
184 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
187 if (wndPtr
->hrgnWnd
) nRet
= CombineRgn( hrgn
, wndPtr
->hrgnWnd
, 0, RGN_COPY
);
188 WIN_ReleasePtr( wndPtr
);
193 /***********************************************************************
194 * SetWindowRgn (USER32.@)
196 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
201 if (hrgn
) /* verify that region really exists */
203 if (GetRgnBox( hrgn
, &rect
) == ERROR
) return FALSE
;
206 if (USER_Driver
.pSetWindowRgn
)
207 return USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
209 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
211 if (IsWindow( hwnd
))
212 FIXME( "not supported on other process window %p\n", hwnd
);
217 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
221 if (wndPtr
->hrgnWnd
== hrgn
)
223 WIN_ReleasePtr( wndPtr
);
229 /* delete previous region */
230 DeleteObject(wndPtr
->hrgnWnd
);
233 wndPtr
->hrgnWnd
= hrgn
;
234 WIN_ReleasePtr( wndPtr
);
236 /* Size the window to the rectangle of the new region (if it isn't NULL) */
237 if (hrgn
) SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
238 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
239 SWP_NOSIZE
| SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOACTIVATE
|
240 SWP_NOZORDER
| (bRedraw
? 0 : SWP_NOREDRAW
) );
245 /***********************************************************************
246 * GetClientRect (USER32.@)
248 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
252 rect
->right
= rect
->bottom
= 0;
253 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
255 rect
->right
-= rect
->left
;
256 rect
->bottom
-= rect
->top
;
258 rect
->left
= rect
->top
= 0;
263 /*******************************************************************
264 * ClientToScreen (USER32.@)
266 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
268 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
273 /*******************************************************************
274 * ScreenToClient (USER32.@)
276 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
278 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
283 /***********************************************************************
284 * find_child_from_point
286 * Find the child that contains pt. Helper for WindowFromPoint.
287 * pt is in parent client coordinates.
288 * lparam is the param to pass in the WM_NCHITTEST message.
290 static HWND
find_child_from_point( HWND parent
, POINT pt
, INT
*hittest
, LPARAM lparam
)
294 RECT rectWindow
, rectClient
;
296 HWND
*list
= WIN_ListChildren( parent
);
300 for (i
= 0; list
[i
]; i
++)
302 /* If point is in window, and window is visible, and it */
303 /* is enabled (or it's a top-level window), then explore */
304 /* its children. Otherwise, go to the next window. */
306 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
307 if (!(style
& WS_VISIBLE
)) continue; /* not visible -> skip */
308 if ((style
& (WS_POPUP
| WS_CHILD
| WS_DISABLED
)) == (WS_CHILD
| WS_DISABLED
))
309 continue; /* disabled child -> skip */
310 exstyle
= GetWindowLongW( list
[i
], GWL_EXSTYLE
);
311 if ((exstyle
& (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
| WS_EX_TRANSPARENT
))
312 continue; /* transparent -> skip */
314 if (!WIN_GetRectangles( list
[i
], &rectWindow
, &rectClient
)) continue;
315 if (!PtInRect( &rectWindow
, pt
)) continue; /* not in window -> skip */
317 /* FIXME: check window region for other processes too */
318 if ((wndPtr
= WIN_GetPtr( list
[i
] )) && wndPtr
!= WND_OTHER_PROCESS
)
320 if (wndPtr
->hrgnWnd
&& !PtInRegion( wndPtr
->hrgnWnd
,
321 pt
.x
- rectWindow
.left
, pt
.y
- rectWindow
.top
))
323 WIN_ReleasePtr( wndPtr
);
324 continue; /* point outside window region -> skip */
326 WIN_ReleasePtr( wndPtr
);
329 /* If window is minimized or disabled, return at once */
330 if (style
& WS_MINIMIZE
)
332 *hittest
= HTCAPTION
;
336 if (style
& WS_DISABLED
)
343 /* If point is in client area, explore children */
344 if (PtInRect( &rectClient
, pt
))
348 new_pt
.x
= pt
.x
- rectClient
.left
;
349 new_pt
.y
= pt
.y
- rectClient
.top
;
350 if ((retvalue
= find_child_from_point( list
[i
], new_pt
, hittest
, lparam
))) break;
353 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
354 if (!WIN_IsCurrentThread( list
[i
] ))
360 if ((res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, lparam
)) != HTTRANSPARENT
)
362 *hittest
= res
; /* Found the window */
366 /* continue search with next sibling */
368 HeapFree( GetProcessHeap(), 0, list
);
373 /***********************************************************************
374 * WINPOS_WindowFromPoint
376 * Find the window and hittest for a given point.
378 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
384 TRACE("scope %p %ld,%ld\n", hwndScope
, pt
.x
, pt
.y
);
386 if (!hwndScope
) hwndScope
= GetDesktopWindow();
387 style
= GetWindowLongW( hwndScope
, GWL_STYLE
);
390 if (style
& WS_DISABLED
) return 0;
392 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope
, GA_PARENT
), &xy
, 1 );
394 if (!(style
& WS_MINIMIZE
))
397 if (WIN_GetRectangles( hwndScope
, NULL
, &rectClient
) && PtInRect( &rectClient
, xy
))
401 xy
.x
-= rectClient
.left
;
402 xy
.y
-= rectClient
.top
;
403 if ((ret
= find_child_from_point( hwndScope
, xy
, hittest
, MAKELONG( pt
.x
, pt
.y
) )))
405 TRACE( "found child %p\n", ret
);
411 /* If nothing found, try the scope window */
412 if (!WIN_IsCurrentThread( hwndScope
))
415 TRACE( "returning %p\n", hwndScope
);
418 res
= SendMessageA( hwndScope
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
419 if (res
!= HTTRANSPARENT
)
421 *hittest
= res
; /* Found the window */
422 TRACE( "returning %p\n", hwndScope
);
425 *hittest
= HTNOWHERE
;
426 TRACE( "nothing found\n" );
431 /*******************************************************************
432 * WindowFromPoint (USER32.@)
434 HWND WINAPI
WindowFromPoint( POINT pt
)
437 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
441 /*******************************************************************
442 * ChildWindowFromPoint (USER32.@)
444 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
446 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
449 /*******************************************************************
450 * ChildWindowFromPointEx (USER32.@)
452 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
454 /* pt is in the client coordinates */
460 GetClientRect( hwndParent
, &rect
);
461 if (!PtInRect( &rect
, pt
)) return 0;
462 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
464 for (i
= 0; list
[i
]; i
++)
466 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
467 if (!PtInRect( &rect
, pt
)) continue;
468 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
470 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
471 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
472 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
474 if (uFlags
& CWP_SKIPTRANSPARENT
)
476 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
481 HeapFree( GetProcessHeap(), 0, list
);
482 if (!retvalue
) retvalue
= hwndParent
;
487 /*******************************************************************
488 * WINPOS_GetWinOffset
490 * Calculate the offset between the origin of the two windows. Used
491 * to implement MapWindowPoints.
493 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
497 offset
->x
= offset
->y
= 0;
499 /* Translate source window origin to screen coords */
502 HWND hwnd
= hwndFrom
;
506 if (hwnd
== hwndTo
) return;
507 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
509 ERR( "bad hwndFrom = %p\n", hwnd
);
512 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
513 offset
->x
+= wndPtr
->rectClient
.left
;
514 offset
->y
+= wndPtr
->rectClient
.top
;
515 hwnd
= wndPtr
->parent
;
516 WIN_ReleasePtr( wndPtr
);
520 /* Translate origin to destination window coords */
527 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
529 ERR( "bad hwndTo = %p\n", hwnd
);
532 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
533 offset
->x
-= wndPtr
->rectClient
.left
;
534 offset
->y
-= wndPtr
->rectClient
.top
;
535 hwnd
= wndPtr
->parent
;
536 WIN_ReleasePtr( wndPtr
);
541 other_process
: /* one of the parents may belong to another process, do it the hard way */
542 offset
->x
= offset
->y
= 0;
543 SERVER_START_REQ( get_windows_offset
)
545 req
->from
= hwndFrom
;
547 if (!wine_server_call( req
))
549 offset
->x
= reply
->x
;
550 offset
->y
= reply
->y
;
557 /*******************************************************************
558 * MapWindowPoints (USER.258)
560 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
561 LPPOINT16 lppt
, UINT16 count
)
565 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
575 /*******************************************************************
576 * MapWindowPoints (USER32.@)
578 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
582 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
589 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
593 /***********************************************************************
594 * IsIconic (USER32.@)
596 BOOL WINAPI
IsIconic(HWND hWnd
)
598 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
602 /***********************************************************************
603 * IsZoomed (USER32.@)
605 BOOL WINAPI
IsZoomed(HWND hWnd
)
607 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
611 /*******************************************************************
612 * AllowSetForegroundWindow (USER32.@)
614 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
616 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
617 * implemented, then fix this function. */
622 /*******************************************************************
623 * LockSetForegroundWindow (USER32.@)
625 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
627 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
628 * implemented, then fix this function. */
633 /*******************************************************************
634 * SetShellWindow (USER32.@)
636 HWND WINAPI
SetShellWindow(HWND hwndshell
)
637 { WARN("(hWnd=%p) semi stub\n",hwndshell
);
639 hGlobalShellWindow
= WIN_GetFullHandle( hwndshell
);
640 return hGlobalShellWindow
;
644 /*******************************************************************
645 * GetShellWindow (USER32.@)
647 HWND WINAPI
GetShellWindow(void)
648 { WARN("(hWnd=%p) semi stub\n",hGlobalShellWindow
);
650 return hGlobalShellWindow
;
654 /***********************************************************************
655 * BringWindowToTop (USER32.@)
657 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
659 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
663 /***********************************************************************
664 * MoveWindow (USER32.@)
666 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
669 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
670 if (!repaint
) flags
|= SWP_NOREDRAW
;
671 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
672 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
675 /***********************************************************************
676 * WINPOS_InitInternalPos
678 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
680 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
684 /* this happens when the window is minimized/maximized
685 * for the first time (rectWindow is not adjusted yet) */
687 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
688 if( !lpPos
) return NULL
;
690 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
691 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
692 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
693 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
696 if( wnd
->dwStyle
& WS_MINIMIZE
)
697 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
698 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
699 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
700 else if( restoreRect
)
701 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
706 /***********************************************************************
707 * WINPOS_RedrawIconTitle
709 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
711 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
714 if( lpPos
->hwndIconTitle
)
716 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
717 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
724 /***********************************************************************
725 * WINPOS_ShowIconTitle
727 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
729 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
731 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
733 HWND title
= lpPos
->hwndIconTitle
;
735 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
738 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
741 if (!IsWindowVisible(title
))
743 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
744 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
745 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
748 else ShowWindow( title
, SW_HIDE
);
753 /*******************************************************************
754 * WINPOS_GetMinMaxInfo
756 * Get the minimized and maximized information for a window.
758 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
759 POINT
*minTrack
, POINT
*maxTrack
)
764 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
765 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
767 /* Compute default values */
769 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
770 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
771 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
772 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
773 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
774 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
776 if (HAS_DLGFRAME( style
, exstyle
))
778 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
779 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
784 if (HAS_THICKFRAME(style
))
786 xinc
+= GetSystemMetrics(SM_CXFRAME
);
787 yinc
+= GetSystemMetrics(SM_CYFRAME
);
789 if (style
& WS_BORDER
)
791 xinc
+= GetSystemMetrics(SM_CXBORDER
);
792 yinc
+= GetSystemMetrics(SM_CYBORDER
);
795 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
796 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
798 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
799 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
800 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
803 MinMax
.ptMaxPosition
.x
= -xinc
;
804 MinMax
.ptMaxPosition
.y
= -yinc
;
807 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
809 /* Some sanity checks */
811 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
812 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
813 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
814 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
815 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
816 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
817 MinMax
.ptMinTrackSize
.x
);
818 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
819 MinMax
.ptMinTrackSize
.y
);
821 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
822 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
823 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
824 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
827 /***********************************************************************
828 * ShowWindowAsync (USER32.@)
830 * doesn't wait; returns immediately.
831 * used by threads to toggle windows in other (possibly hanging) threads
833 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
837 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
838 return USER_Driver
.pShowWindow( full_handle
, cmd
);
839 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
843 /***********************************************************************
844 * ShowWindow (USER32.@)
846 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
850 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
851 return USER_Driver
.pShowWindow( full_handle
, cmd
);
852 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
856 /***********************************************************************
857 * GetInternalWindowPos (USER32.@)
859 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
862 WINDOWPLACEMENT wndpl
;
863 if (GetWindowPlacement( hwnd
, &wndpl
))
865 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
866 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
867 return wndpl
.showCmd
;
873 /***********************************************************************
874 * GetWindowPlacement (USER32.@)
877 * Fails if wndpl->length of Win95 (!) apps is invalid.
879 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
881 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
884 if(!pWnd
) return FALSE
;
886 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
887 wndpl
->length
= sizeof(*wndpl
);
888 if( pWnd
->dwStyle
& WS_MINIMIZE
)
889 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
891 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
892 if( pWnd
->flags
& WIN_RESTORE_MAX
)
893 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
896 CONV_POINT16TO32( &lpPos
->ptIconPos
, &wndpl
->ptMinPosition
);
897 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &wndpl
->ptMaxPosition
);
898 CONV_RECT16TO32( &lpPos
->rectNormal
, &wndpl
->rcNormalPosition
);
899 WIN_ReleaseWndPtr(pWnd
);
904 /***********************************************************************
905 * WINPOS_SetPlacement
907 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
909 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
912 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
913 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
915 if( flags
& PLACE_MIN
) CONV_POINT32TO16( &wndpl
->ptMinPosition
, &lpPos
->ptIconPos
);
916 if( flags
& PLACE_MAX
) CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &lpPos
->ptMaxPos
);
917 if( flags
& PLACE_RECT
) CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &lpPos
->rectNormal
);
919 if( pWnd
->dwStyle
& WS_MINIMIZE
)
921 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
922 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
923 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
924 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
926 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
928 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
929 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
930 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
932 else if( flags
& PLACE_RECT
)
933 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
934 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
935 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
936 SWP_NOZORDER
| SWP_NOACTIVATE
);
938 ShowWindow( hwnd
, wndpl
->showCmd
);
939 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
941 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
943 /* SDK: ...valid only the next time... */
944 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
946 WIN_ReleaseWndPtr(pWnd
);
953 /***********************************************************************
954 * SetWindowPlacement (USER32.@)
957 * Fails if wndpl->length of Win95 (!) apps is invalid.
959 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
961 if (!wpl
) return FALSE
;
962 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
966 /***********************************************************************
967 * AnimateWindow (USER32.@)
968 * Shows/Hides a window with an animation
971 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
973 FIXME("partial stub\n");
975 /* If trying to show/hide and it's already *
976 * shown/hidden or invalid window, fail with *
977 * invalid parameter */
978 if(!IsWindow(hwnd
) ||
979 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
980 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
982 SetLastError(ERROR_INVALID_PARAMETER
);
986 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
991 /***********************************************************************
992 * SetInternalWindowPos (USER32.@)
994 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
995 LPRECT rect
, LPPOINT pt
)
999 WINDOWPLACEMENT wndpl
;
1002 wndpl
.length
= sizeof(wndpl
);
1003 wndpl
.showCmd
= showCmd
;
1004 wndpl
.flags
= flags
= 0;
1009 wndpl
.flags
|= WPF_SETMINPOSITION
;
1010 wndpl
.ptMinPosition
= *pt
;
1014 flags
|= PLACE_RECT
;
1015 wndpl
.rcNormalPosition
= *rect
;
1017 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1022 /*******************************************************************
1023 * can_activate_window
1025 * Check if we can activate the specified window.
1027 static BOOL
can_activate_window( HWND hwnd
)
1031 if (!hwnd
) return FALSE
;
1032 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1033 if (!(style
& WS_VISIBLE
)) return FALSE
;
1034 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1035 return !(style
& WS_DISABLED
);
1039 /*******************************************************************
1040 * WINPOS_ActivateOtherWindow
1042 * Activates window other than pWnd.
1044 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1048 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1050 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1051 if (can_activate_window( hwndTo
)) goto done
;
1057 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1058 if (can_activate_window( hwndTo
)) break;
1062 fg
= GetForegroundWindow();
1063 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1064 if (!fg
|| (hwnd
== fg
))
1066 if (SetForegroundWindow( hwndTo
)) return;
1068 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1072 /***********************************************************************
1073 * WINPOS_HandleWindowPosChanging16
1075 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1077 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1079 POINT maxSize
, minTrack
;
1080 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1082 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1083 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1085 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1086 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1087 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1088 if (!(style
& WS_MINIMIZE
))
1090 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1091 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1098 /***********************************************************************
1099 * WINPOS_HandleWindowPosChanging
1101 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1103 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1105 POINT maxSize
, minTrack
;
1106 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1108 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1109 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1111 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1112 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1113 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1114 if (!(style
& WS_MINIMIZE
))
1116 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1117 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1124 /***********************************************************************
1127 static void dump_winpos_flags(UINT flags
)
1130 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1131 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1132 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1133 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1134 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1135 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1136 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1137 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1138 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1139 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1140 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1141 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1142 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1144 #define DUMPED_FLAGS \
1150 SWP_FRAMECHANGED | \
1154 SWP_NOOWNERZORDER | \
1155 SWP_NOSENDCHANGING | \
1159 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1164 /***********************************************************************
1165 * SetWindowPos (USER32.@)
1167 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1168 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1172 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1173 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1174 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1176 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1177 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1182 winpos
.flags
= flags
;
1183 if (WIN_IsCurrentThread( hwnd
)) return USER_Driver
.pSetWindowPos( &winpos
);
1184 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1188 /***********************************************************************
1189 * BeginDeferWindowPos (USER32.@)
1191 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1198 SetLastError(ERROR_INVALID_PARAMETER
);
1201 /* Windows allows zero count, in which case it allocates context for 8 moves */
1202 if (count
== 0) count
= 8;
1204 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1205 if (!handle
) return 0;
1206 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1207 pDWP
->actualCount
= 0;
1208 pDWP
->suggestedCount
= count
;
1210 pDWP
->wMagic
= DWP_MAGIC
;
1211 pDWP
->hwndParent
= 0;
1216 /***********************************************************************
1217 * DeferWindowPos (USER32.@)
1219 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1220 INT x
, INT y
, INT cx
, INT cy
,
1225 HDWP newhdwp
= hdwp
,retvalue
;
1227 hwnd
= WIN_GetFullHandle( hwnd
);
1228 if (hwnd
== GetDesktopWindow()) return 0;
1230 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1234 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1236 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1238 /* Merge with the other changes */
1239 if (!(flags
& SWP_NOZORDER
))
1241 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1243 if (!(flags
& SWP_NOMOVE
))
1245 pDWP
->winPos
[i
].x
= x
;
1246 pDWP
->winPos
[i
].y
= y
;
1248 if (!(flags
& SWP_NOSIZE
))
1250 pDWP
->winPos
[i
].cx
= cx
;
1251 pDWP
->winPos
[i
].cy
= cy
;
1253 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1254 SWP_NOZORDER
| SWP_NOREDRAW
|
1255 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1257 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1263 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1265 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1266 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1272 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1273 pDWP
->suggestedCount
++;
1275 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1276 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1277 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1278 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1279 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1280 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1281 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1282 pDWP
->actualCount
++;
1290 /***********************************************************************
1291 * EndDeferWindowPos (USER32.@)
1293 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1300 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1301 if (!pDWP
) return FALSE
;
1302 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1304 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1306 USER_HEAP_FREE( hdwp
);
1311 /***********************************************************************
1312 * TileChildWindows (USER.199)
1314 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1316 FIXME("(%04x, %d): stub\n", parent
, action
);
1319 /***********************************************************************
1320 * CascadeChildWindows (USER.198)
1322 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1324 FIXME("(%04x, %d): stub\n", parent
, action
);
1327 /***********************************************************************
1328 * SetProgmanWindow (USER32.@)
1330 HWND WINAPI
SetProgmanWindow ( HWND hwnd
)
1332 hGlobalProgmanWindow
= hwnd
;
1333 return hGlobalProgmanWindow
;
1336 /***********************************************************************
1337 * GetProgmanWindow (USER32.@)
1339 HWND WINAPI
GetProgmanWindow(void)
1341 return hGlobalProgmanWindow
;
1344 /***********************************************************************
1345 * SetShellWindowEx (USER32.@)
1346 * hwndProgman = Progman[Program Manager]
1347 * |-> SHELLDLL_DefView
1348 * hwndListView = | |-> SysListView32
1349 * | | |-> tooltips_class32
1355 HWND WINAPI
SetShellWindowEx ( HWND hwndProgman
, HWND hwndListView
)
1357 FIXME("%p %p stub\n",hwndProgman
,hwndListView
);
1358 hGlobalShellWindow
= hwndProgman
;
1359 return hGlobalShellWindow
;
1363 /***********************************************************************
1364 * SetTaskmanWindow (USER32.@)
1366 * hwnd = MSTaskSwWClass
1367 * |-> SysTabControl32
1369 HWND WINAPI
SetTaskmanWindow ( HWND hwnd
)
1371 hGlobalTaskmanWindow
= hwnd
;
1372 return hGlobalTaskmanWindow
;
1375 /***********************************************************************
1376 * GetTaskmanWindow (USER32.@)
1378 HWND WINAPI
GetTaskmanWindow(void)
1380 return hGlobalTaskmanWindow
;