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 HWND hGlobalShellWindow
=0; /*the shell*/
71 static HWND hGlobalTaskmanWindow
=0;
72 static HWND hGlobalProgmanWindow
=0;
74 static LPCSTR atomInternalPos
;
77 /***********************************************************************
78 * WINPOS_CreateInternalPosAtom
80 BOOL
WINPOS_CreateInternalPosAtom()
83 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
84 return (atomInternalPos
) ? TRUE
: FALSE
;
87 /***********************************************************************
88 * WINPOS_CheckInternalPos
90 * Called when a window is destroyed.
92 void WINPOS_CheckInternalPos( HWND hwnd
)
94 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
98 if( IsWindow(lpPos
->hwndIconTitle
) )
99 DestroyWindow( lpPos
->hwndIconTitle
);
100 HeapFree( GetProcessHeap(), 0, lpPos
);
104 /***********************************************************************
105 * ArrangeIconicWindows (USER32.@)
107 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
111 INT x
, y
, xspacing
, yspacing
;
113 GetClientRect( parent
, &rectParent
);
115 y
= rectParent
.bottom
;
116 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
117 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
119 hwndChild
= GetWindow( parent
, GW_CHILD
);
122 if( IsIconic( hwndChild
) )
124 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
126 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
127 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
128 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
129 if( IsWindow(hwndChild
) )
130 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
132 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
139 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
145 /***********************************************************************
146 * SwitchToThisWindow (USER32.@)
148 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
150 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
154 /***********************************************************************
155 * GetWindowRect (USER32.@)
157 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
159 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
162 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
163 TRACE( "hwnd %p (%ld,%ld)-(%ld,%ld)\n",
164 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
170 /***********************************************************************
171 * GetWindowRgn (USER32.@)
173 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
176 WND
*wndPtr
= WIN_GetPtr( hwnd
);
178 if (wndPtr
== WND_OTHER_PROCESS
)
180 if (IsWindow( hwnd
))
181 FIXME( "not supported on other process window %p\n", hwnd
);
186 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
189 if (wndPtr
->hrgnWnd
) nRet
= CombineRgn( hrgn
, wndPtr
->hrgnWnd
, 0, RGN_COPY
);
190 WIN_ReleasePtr( wndPtr
);
195 /***********************************************************************
196 * SetWindowRgn (USER32.@)
198 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
203 if (hrgn
) /* verify that region really exists */
205 if (GetRgnBox( hrgn
, &rect
) == ERROR
) return FALSE
;
208 if (USER_Driver
.pSetWindowRgn
)
209 return USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
211 if ((wndPtr
= WIN_GetPtr( hwnd
)) == WND_OTHER_PROCESS
)
213 if (IsWindow( hwnd
))
214 FIXME( "not supported on other process window %p\n", hwnd
);
219 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
223 if (wndPtr
->hrgnWnd
== hrgn
)
225 WIN_ReleasePtr( wndPtr
);
231 /* delete previous region */
232 DeleteObject(wndPtr
->hrgnWnd
);
235 wndPtr
->hrgnWnd
= hrgn
;
236 WIN_ReleasePtr( wndPtr
);
238 /* Size the window to the rectangle of the new region (if it isn't NULL) */
239 if (hrgn
) SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
240 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
241 SWP_NOSIZE
| SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOACTIVATE
|
242 SWP_NOZORDER
| (bRedraw
? 0 : SWP_NOREDRAW
) );
247 /***********************************************************************
248 * GetClientRect (USER32.@)
250 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
254 rect
->right
= rect
->bottom
= 0;
255 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
257 rect
->right
-= rect
->left
;
258 rect
->bottom
-= rect
->top
;
260 rect
->left
= rect
->top
= 0;
265 /*******************************************************************
266 * ClientToScreen (USER32.@)
268 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
270 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
275 /*******************************************************************
276 * ScreenToClient (USER32.@)
278 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
280 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
285 /***********************************************************************
286 * find_child_from_point
288 * Find the child that contains pt. Helper for WindowFromPoint.
289 * pt is in parent client coordinates.
290 * lparam is the param to pass in the WM_NCHITTEST message.
292 static HWND
find_child_from_point( HWND parent
, POINT pt
, INT
*hittest
, LPARAM lparam
)
296 RECT rectWindow
, rectClient
;
298 HWND
*list
= WIN_ListChildren( parent
);
302 for (i
= 0; list
[i
]; i
++)
304 /* If point is in window, and window is visible, and it */
305 /* is enabled (or it's a top-level window), then explore */
306 /* its children. Otherwise, go to the next window. */
308 style
= GetWindowLongW( list
[i
], GWL_STYLE
);
309 if (!(style
& WS_VISIBLE
)) continue; /* not visible -> skip */
310 if ((style
& (WS_POPUP
| WS_CHILD
| WS_DISABLED
)) == (WS_CHILD
| WS_DISABLED
))
311 continue; /* disabled child -> skip */
312 exstyle
= GetWindowLongW( list
[i
], GWL_EXSTYLE
);
313 if ((exstyle
& (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) == (WS_EX_LAYERED
| WS_EX_TRANSPARENT
))
314 continue; /* transparent -> skip */
316 if (!WIN_GetRectangles( list
[i
], &rectWindow
, &rectClient
)) continue;
317 if (!PtInRect( &rectWindow
, pt
)) continue; /* not in window -> skip */
319 /* FIXME: check window region for other processes too */
320 if ((wndPtr
= WIN_GetPtr( list
[i
] )) && wndPtr
!= WND_OTHER_PROCESS
)
322 if (wndPtr
->hrgnWnd
&& !PtInRegion( wndPtr
->hrgnWnd
,
323 pt
.x
- rectWindow
.left
, pt
.y
- rectWindow
.top
))
325 WIN_ReleasePtr( wndPtr
);
326 continue; /* point outside window region -> skip */
328 WIN_ReleasePtr( wndPtr
);
331 /* If window is minimized or disabled, return at once */
332 if (style
& WS_MINIMIZE
)
334 *hittest
= HTCAPTION
;
338 if (style
& WS_DISABLED
)
345 /* If point is in client area, explore children */
346 if (PtInRect( &rectClient
, pt
))
350 new_pt
.x
= pt
.x
- rectClient
.left
;
351 new_pt
.y
= pt
.y
- rectClient
.top
;
352 if ((retvalue
= find_child_from_point( list
[i
], new_pt
, hittest
, lparam
))) break;
355 /* Now it's inside window, send WM_NCCHITTEST (if same thread) */
356 if (!WIN_IsCurrentThread( list
[i
] ))
362 if ((res
= SendMessageA( list
[i
], WM_NCHITTEST
, 0, lparam
)) != HTTRANSPARENT
)
364 *hittest
= res
; /* Found the window */
368 /* continue search with next sibling */
370 HeapFree( GetProcessHeap(), 0, list
);
375 /***********************************************************************
376 * WINPOS_WindowFromPoint
378 * Find the window and hittest for a given point.
380 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
386 TRACE("scope %p %ld,%ld\n", hwndScope
, pt
.x
, pt
.y
);
388 if (!hwndScope
) hwndScope
= GetDesktopWindow();
389 style
= GetWindowLongW( hwndScope
, GWL_STYLE
);
392 if (style
& WS_DISABLED
) return 0;
394 MapWindowPoints( GetDesktopWindow(), GetAncestor( hwndScope
, GA_PARENT
), &xy
, 1 );
396 if (!(style
& WS_MINIMIZE
))
399 if (WIN_GetRectangles( hwndScope
, NULL
, &rectClient
) && PtInRect( &rectClient
, xy
))
403 xy
.x
-= rectClient
.left
;
404 xy
.y
-= rectClient
.top
;
405 if ((ret
= find_child_from_point( hwndScope
, xy
, hittest
, MAKELONG( pt
.x
, pt
.y
) )))
407 TRACE( "found child %p\n", ret
);
413 /* If nothing found, try the scope window */
414 if (!WIN_IsCurrentThread( hwndScope
))
417 TRACE( "returning %p\n", hwndScope
);
420 res
= SendMessageA( hwndScope
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
421 if (res
!= HTTRANSPARENT
)
423 *hittest
= res
; /* Found the window */
424 TRACE( "returning %p\n", hwndScope
);
427 *hittest
= HTNOWHERE
;
428 TRACE( "nothing found\n" );
433 /*******************************************************************
434 * WindowFromPoint (USER32.@)
436 HWND WINAPI
WindowFromPoint( POINT pt
)
439 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
443 /*******************************************************************
444 * ChildWindowFromPoint (USER32.@)
446 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
448 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
451 /*******************************************************************
452 * ChildWindowFromPointEx (USER32.@)
454 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
456 /* pt is in the client coordinates */
462 GetClientRect( hwndParent
, &rect
);
463 if (!PtInRect( &rect
, pt
)) return 0;
464 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
466 for (i
= 0; list
[i
]; i
++)
468 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
469 if (!PtInRect( &rect
, pt
)) continue;
470 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
472 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
473 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
474 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
476 if (uFlags
& CWP_SKIPTRANSPARENT
)
478 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
483 HeapFree( GetProcessHeap(), 0, list
);
484 if (!retvalue
) retvalue
= hwndParent
;
489 /*******************************************************************
490 * WINPOS_GetWinOffset
492 * Calculate the offset between the origin of the two windows. Used
493 * to implement MapWindowPoints.
495 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
499 offset
->x
= offset
->y
= 0;
501 /* Translate source window origin to screen coords */
504 HWND hwnd
= hwndFrom
;
508 if (hwnd
== hwndTo
) return;
509 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
511 ERR( "bad hwndFrom = %p\n", hwnd
);
514 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
515 offset
->x
+= wndPtr
->rectClient
.left
;
516 offset
->y
+= wndPtr
->rectClient
.top
;
517 hwnd
= wndPtr
->parent
;
518 WIN_ReleasePtr( wndPtr
);
522 /* Translate origin to destination window coords */
529 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
531 ERR( "bad hwndTo = %p\n", hwnd
);
534 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
535 offset
->x
-= wndPtr
->rectClient
.left
;
536 offset
->y
-= wndPtr
->rectClient
.top
;
537 hwnd
= wndPtr
->parent
;
538 WIN_ReleasePtr( wndPtr
);
543 other_process
: /* one of the parents may belong to another process, do it the hard way */
544 offset
->x
= offset
->y
= 0;
545 SERVER_START_REQ( get_windows_offset
)
547 req
->from
= hwndFrom
;
549 if (!wine_server_call( req
))
551 offset
->x
= reply
->x
;
552 offset
->y
= reply
->y
;
559 /*******************************************************************
560 * MapWindowPoints (USER.258)
562 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
563 LPPOINT16 lppt
, UINT16 count
)
567 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
577 /*******************************************************************
578 * MapWindowPoints (USER32.@)
580 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
584 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
591 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
595 /***********************************************************************
596 * IsIconic (USER32.@)
598 BOOL WINAPI
IsIconic(HWND hWnd
)
600 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
604 /***********************************************************************
605 * IsZoomed (USER32.@)
607 BOOL WINAPI
IsZoomed(HWND hWnd
)
609 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
613 /*******************************************************************
614 * AllowSetForegroundWindow (USER32.@)
616 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
618 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
619 * implemented, then fix this function. */
624 /*******************************************************************
625 * LockSetForegroundWindow (USER32.@)
627 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
629 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
630 * implemented, then fix this function. */
635 /*******************************************************************
636 * SetShellWindow (USER32.@)
638 HWND WINAPI
SetShellWindow(HWND hwndshell
)
639 { WARN("(hWnd=%p) semi stub\n",hwndshell
);
641 hGlobalShellWindow
= WIN_GetFullHandle( hwndshell
);
642 return hGlobalShellWindow
;
646 /*******************************************************************
647 * GetShellWindow (USER32.@)
649 HWND WINAPI
GetShellWindow(void)
650 { WARN("(hWnd=%p) semi stub\n",hGlobalShellWindow
);
652 return hGlobalShellWindow
;
656 /***********************************************************************
657 * BringWindowToTop (USER32.@)
659 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
661 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
665 /***********************************************************************
666 * MoveWindow (USER32.@)
668 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
671 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
672 if (!repaint
) flags
|= SWP_NOREDRAW
;
673 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
674 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
677 /***********************************************************************
678 * WINPOS_InitInternalPos
680 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
, const RECT
*restoreRect
)
682 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
686 /* this happens when the window is minimized/maximized
687 * for the first time (rectWindow is not adjusted yet) */
689 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
690 if( !lpPos
) return NULL
;
692 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
693 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
694 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
695 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
698 if( wnd
->dwStyle
& WS_MINIMIZE
)
699 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
700 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
701 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
702 else if( restoreRect
)
703 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
708 /***********************************************************************
709 * WINPOS_RedrawIconTitle
711 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
713 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
716 if( lpPos
->hwndIconTitle
)
718 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
719 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
726 /***********************************************************************
727 * WINPOS_ShowIconTitle
729 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
731 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
733 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
735 HWND title
= lpPos
->hwndIconTitle
;
737 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
740 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
743 if (!IsWindowVisible(title
))
745 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
746 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
747 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
750 else ShowWindow( title
, SW_HIDE
);
755 /*******************************************************************
756 * WINPOS_GetMinMaxInfo
758 * Get the minimized and maximized information for a window.
760 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
761 POINT
*minTrack
, POINT
*maxTrack
)
766 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
767 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
769 /* Compute default values */
771 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
772 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
773 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
774 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
775 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
776 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
778 if (HAS_DLGFRAME( style
, exstyle
))
780 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
781 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
786 if (HAS_THICKFRAME(style
))
788 xinc
+= GetSystemMetrics(SM_CXFRAME
);
789 yinc
+= GetSystemMetrics(SM_CYFRAME
);
791 if (style
& WS_BORDER
)
793 xinc
+= GetSystemMetrics(SM_CXBORDER
);
794 yinc
+= GetSystemMetrics(SM_CYBORDER
);
797 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
798 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
800 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
801 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
802 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
805 MinMax
.ptMaxPosition
.x
= -xinc
;
806 MinMax
.ptMaxPosition
.y
= -yinc
;
809 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
811 /* Some sanity checks */
813 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
814 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
815 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
816 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
817 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
818 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
819 MinMax
.ptMinTrackSize
.x
);
820 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
821 MinMax
.ptMinTrackSize
.y
);
823 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
824 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
825 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
826 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
829 /***********************************************************************
830 * ShowWindowAsync (USER32.@)
832 * doesn't wait; returns immediately.
833 * used by threads to toggle windows in other (possibly hanging) threads
835 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
839 if (is_broadcast(hwnd
))
841 SetLastError( ERROR_INVALID_PARAMETER
);
845 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
846 return USER_Driver
.pShowWindow( full_handle
, cmd
);
847 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
851 /***********************************************************************
852 * ShowWindow (USER32.@)
854 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
858 if (is_broadcast(hwnd
))
860 SetLastError( ERROR_INVALID_PARAMETER
);
863 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
865 if (USER_Driver
.pShowWindow
)
866 return USER_Driver
.pShowWindow( full_handle
, cmd
);
869 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
873 /***********************************************************************
874 * GetInternalWindowPos (USER32.@)
876 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
879 WINDOWPLACEMENT wndpl
;
880 if (GetWindowPlacement( hwnd
, &wndpl
))
882 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
883 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
884 return wndpl
.showCmd
;
890 /***********************************************************************
891 * GetWindowPlacement (USER32.@)
894 * Fails if wndpl->length of Win95 (!) apps is invalid.
896 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
898 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
901 if(!pWnd
) return FALSE
;
903 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
904 wndpl
->length
= sizeof(*wndpl
);
905 if( pWnd
->dwStyle
& WS_MINIMIZE
)
906 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
908 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
909 if( pWnd
->flags
& WIN_RESTORE_MAX
)
910 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
913 CONV_POINT16TO32( &lpPos
->ptIconPos
, &wndpl
->ptMinPosition
);
914 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &wndpl
->ptMaxPosition
);
915 CONV_RECT16TO32( &lpPos
->rectNormal
, &wndpl
->rcNormalPosition
);
916 WIN_ReleaseWndPtr(pWnd
);
921 /***********************************************************************
922 * WINPOS_SetPlacement
924 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
926 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
929 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
930 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
932 if( flags
& PLACE_MIN
) CONV_POINT32TO16( &wndpl
->ptMinPosition
, &lpPos
->ptIconPos
);
933 if( flags
& PLACE_MAX
) CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &lpPos
->ptMaxPos
);
934 if( flags
& PLACE_RECT
) CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &lpPos
->rectNormal
);
936 if( pWnd
->dwStyle
& WS_MINIMIZE
)
938 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
939 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
940 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
941 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
943 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
945 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
946 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
947 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
949 else if( flags
& PLACE_RECT
)
950 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
951 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
952 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
953 SWP_NOZORDER
| SWP_NOACTIVATE
);
955 ShowWindow( hwnd
, wndpl
->showCmd
);
956 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
958 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
960 /* SDK: ...valid only the next time... */
961 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
963 WIN_ReleaseWndPtr(pWnd
);
970 /***********************************************************************
971 * SetWindowPlacement (USER32.@)
974 * Fails if wndpl->length of Win95 (!) apps is invalid.
976 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
978 if (!wpl
) return FALSE
;
979 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
983 /***********************************************************************
984 * AnimateWindow (USER32.@)
985 * Shows/Hides a window with an animation
988 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
990 FIXME("partial stub\n");
992 /* If trying to show/hide and it's already *
993 * shown/hidden or invalid window, fail with *
994 * invalid parameter */
995 if(!IsWindow(hwnd
) ||
996 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
997 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
999 SetLastError(ERROR_INVALID_PARAMETER
);
1003 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1008 /***********************************************************************
1009 * SetInternalWindowPos (USER32.@)
1011 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1012 LPRECT rect
, LPPOINT pt
)
1014 if( IsWindow(hwnd
) )
1016 WINDOWPLACEMENT wndpl
;
1019 wndpl
.length
= sizeof(wndpl
);
1020 wndpl
.showCmd
= showCmd
;
1021 wndpl
.flags
= flags
= 0;
1026 wndpl
.flags
|= WPF_SETMINPOSITION
;
1027 wndpl
.ptMinPosition
= *pt
;
1031 flags
|= PLACE_RECT
;
1032 wndpl
.rcNormalPosition
= *rect
;
1034 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1039 /*******************************************************************
1040 * can_activate_window
1042 * Check if we can activate the specified window.
1044 static BOOL
can_activate_window( HWND hwnd
)
1048 if (!hwnd
) return FALSE
;
1049 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1050 if (!(style
& WS_VISIBLE
)) return FALSE
;
1051 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1052 return !(style
& WS_DISABLED
);
1056 /*******************************************************************
1057 * WINPOS_ActivateOtherWindow
1059 * Activates window other than pWnd.
1061 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1065 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1067 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1068 if (can_activate_window( hwndTo
)) goto done
;
1074 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1075 if (can_activate_window( hwndTo
)) break;
1079 fg
= GetForegroundWindow();
1080 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1081 if (!fg
|| (hwnd
== fg
))
1083 if (SetForegroundWindow( hwndTo
)) return;
1085 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1089 /***********************************************************************
1090 * WINPOS_HandleWindowPosChanging16
1092 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1094 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1096 POINT maxSize
, minTrack
;
1097 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1099 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1100 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1102 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1103 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1104 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1105 if (!(style
& WS_MINIMIZE
))
1107 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1108 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1115 /***********************************************************************
1116 * WINPOS_HandleWindowPosChanging
1118 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1120 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1122 POINT maxSize
, minTrack
;
1123 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1125 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1126 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1128 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1129 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1130 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1131 if (!(style
& WS_MINIMIZE
))
1133 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1134 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1141 /***********************************************************************
1144 static void dump_winpos_flags(UINT flags
)
1147 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1148 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1149 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1150 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1151 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1152 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1153 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1154 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1155 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1156 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1157 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1158 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1159 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1161 #define DUMPED_FLAGS \
1167 SWP_FRAMECHANGED | \
1171 SWP_NOOWNERZORDER | \
1172 SWP_NOSENDCHANGING | \
1176 if(flags
& ~DUMPED_FLAGS
) TRACE(" %08x", flags
& ~DUMPED_FLAGS
);
1181 /***********************************************************************
1182 * SetWindowPos (USER32.@)
1184 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1185 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1189 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
1190 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
1191 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
1193 if (is_broadcast(hwnd
))
1195 SetLastError( ERROR_INVALID_PARAMETER
);
1199 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
1200 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
1205 winpos
.flags
= flags
;
1206 if (WIN_IsCurrentThread( hwnd
)) return USER_Driver
.pSetWindowPos( &winpos
);
1207 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
1211 /***********************************************************************
1212 * BeginDeferWindowPos (USER32.@)
1214 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1221 SetLastError(ERROR_INVALID_PARAMETER
);
1224 /* Windows allows zero count, in which case it allocates context for 8 moves */
1225 if (count
== 0) count
= 8;
1227 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1228 if (!handle
) return 0;
1229 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1230 pDWP
->actualCount
= 0;
1231 pDWP
->suggestedCount
= count
;
1233 pDWP
->wMagic
= DWP_MAGIC
;
1234 pDWP
->hwndParent
= 0;
1239 /***********************************************************************
1240 * DeferWindowPos (USER32.@)
1242 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1243 INT x
, INT y
, INT cx
, INT cy
,
1248 HDWP newhdwp
= hdwp
,retvalue
;
1250 hwnd
= WIN_GetFullHandle( hwnd
);
1251 if (hwnd
== GetDesktopWindow()) return 0;
1253 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1257 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1259 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1261 /* Merge with the other changes */
1262 if (!(flags
& SWP_NOZORDER
))
1264 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
1266 if (!(flags
& SWP_NOMOVE
))
1268 pDWP
->winPos
[i
].x
= x
;
1269 pDWP
->winPos
[i
].y
= y
;
1271 if (!(flags
& SWP_NOSIZE
))
1273 pDWP
->winPos
[i
].cx
= cx
;
1274 pDWP
->winPos
[i
].cy
= cy
;
1276 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1277 SWP_NOZORDER
| SWP_NOREDRAW
|
1278 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1280 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1286 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1288 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1289 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1295 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1296 pDWP
->suggestedCount
++;
1298 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1299 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1300 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1301 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1302 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1303 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1304 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1305 pDWP
->actualCount
++;
1313 /***********************************************************************
1314 * EndDeferWindowPos (USER32.@)
1316 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1323 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1324 if (!pDWP
) return FALSE
;
1325 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1327 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1329 USER_HEAP_FREE( hdwp
);
1334 /***********************************************************************
1335 * TileChildWindows (USER.199)
1337 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1339 FIXME("(%04x, %d): stub\n", parent
, action
);
1342 /***********************************************************************
1343 * CascadeChildWindows (USER.198)
1345 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1347 FIXME("(%04x, %d): stub\n", parent
, action
);
1350 /***********************************************************************
1351 * SetProgmanWindow (USER32.@)
1353 HWND WINAPI
SetProgmanWindow ( HWND hwnd
)
1355 hGlobalProgmanWindow
= hwnd
;
1356 return hGlobalProgmanWindow
;
1359 /***********************************************************************
1360 * GetProgmanWindow (USER32.@)
1362 HWND WINAPI
GetProgmanWindow(void)
1364 return hGlobalProgmanWindow
;
1367 /***********************************************************************
1368 * SetShellWindowEx (USER32.@)
1369 * hwndProgman = Progman[Program Manager]
1370 * |-> SHELLDLL_DefView
1371 * hwndListView = | |-> SysListView32
1372 * | | |-> tooltips_class32
1378 HWND WINAPI
SetShellWindowEx ( HWND hwndProgman
, HWND hwndListView
)
1380 FIXME("%p %p stub\n",hwndProgman
,hwndListView
);
1381 hGlobalShellWindow
= hwndProgman
;
1382 return hGlobalShellWindow
;
1386 /***********************************************************************
1387 * SetTaskmanWindow (USER32.@)
1389 * hwnd = MSTaskSwWClass
1390 * |-> SysTabControl32
1392 HWND WINAPI
SetTaskmanWindow ( HWND hwnd
)
1394 hGlobalTaskmanWindow
= hwnd
;
1395 return hGlobalTaskmanWindow
;
1398 /***********************************************************************
1399 * GetTaskmanWindow (USER32.@)
1401 HWND WINAPI
GetTaskmanWindow(void)
1403 return hGlobalTaskmanWindow
;