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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
28 #define WIN32_NO_STATUS
33 #include "wine/server.h"
35 #include "user_private.h"
37 #include "wine/debug.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(win
);
41 #define SWP_AGG_NOGEOMETRYCHANGE \
42 (SWP_NOSIZE | SWP_NOCLIENTSIZE | SWP_NOZORDER)
43 #define SWP_AGG_NOPOSCHANGE \
44 (SWP_NOSIZE | SWP_NOMOVE | SWP_NOCLIENTSIZE | SWP_NOCLIENTMOVE | SWP_NOZORDER)
45 #define SWP_AGG_STATUSFLAGS \
46 (SWP_AGG_NOPOSCHANGE | SWP_FRAMECHANGED | SWP_HIDEWINDOW | SWP_SHOWWINDOW)
48 #define HAS_DLGFRAME(style,exStyle) \
49 (((exStyle) & WS_EX_DLGMODALFRAME) || \
50 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
52 #define HAS_THICKFRAME(style) \
53 (((style) & WS_THICKFRAME) && \
54 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
56 #define EMPTYPOINT(pt) ((pt).x == -1 && (pt).y == -1)
58 #define ON_LEFT_BORDER(hit) \
59 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
60 #define ON_RIGHT_BORDER(hit) \
61 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
62 #define ON_TOP_BORDER(hit) \
63 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
64 #define ON_BOTTOM_BORDER(hit) \
65 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
67 #define PLACE_MIN 0x0001
68 #define PLACE_MAX 0x0002
69 #define PLACE_RECT 0x0004
72 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
85 /***********************************************************************
86 * SwitchToThisWindow (USER32.@)
88 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
90 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
94 /***********************************************************************
95 * GetWindowRect (USER32.@)
97 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
99 BOOL ret
= WIN_GetRectangles( hwnd
, rect
, NULL
);
102 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
103 TRACE( "hwnd %p (%s)\n", hwnd
, wine_dbgstr_rect(rect
) );
109 /***********************************************************************
110 * GetWindowRgn (USER32.@)
112 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
122 if (!(data
= HeapAlloc( GetProcessHeap(), 0, sizeof(*data
) + size
- 1 )))
124 SetLastError( ERROR_OUTOFMEMORY
);
127 SERVER_START_REQ( get_window_region
)
129 req
->window
= wine_server_user_handle( hwnd
);
130 wine_server_set_reply( req
, data
->Buffer
, size
);
131 if (!(status
= wine_server_call( req
)))
133 size_t reply_size
= wine_server_reply_size( reply
);
136 data
->rdh
.dwSize
= sizeof(data
->rdh
);
137 data
->rdh
.iType
= RDH_RECTANGLES
;
138 data
->rdh
.nCount
= reply_size
/ sizeof(RECT
);
139 data
->rdh
.nRgnSize
= reply_size
;
140 win_rgn
= ExtCreateRegion( NULL
, size
, data
);
143 else size
= reply
->total_size
;
146 HeapFree( GetProcessHeap(), 0, data
);
147 } while (status
== STATUS_BUFFER_OVERFLOW
);
149 if (status
) SetLastError( RtlNtStatusToDosError(status
) );
152 nRet
= CombineRgn( hrgn
, win_rgn
, 0, RGN_COPY
);
153 DeleteObject( win_rgn
);
158 /***********************************************************************
159 * GetWindowRgnBox (USER32.@)
161 int WINAPI
GetWindowRgnBox( HWND hwnd
, LPRECT prect
)
169 if ((hrgn
= CreateRectRgn(0, 0, 0, 0)))
171 if ((ret
= GetWindowRgn( hwnd
, hrgn
)) != ERROR
)
172 ret
= GetRgnBox( hrgn
, prect
);
179 /***********************************************************************
180 * SetWindowRgn (USER32.@)
182 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
184 static const RECT empty_rect
;
192 if (!(size
= GetRegionData( hrgn
, 0, NULL
))) return FALSE
;
193 if (!(data
= HeapAlloc( GetProcessHeap(), 0, size
))) return FALSE
;
194 if (!GetRegionData( hrgn
, size
, data
))
196 HeapFree( GetProcessHeap(), 0, data
);
199 SERVER_START_REQ( set_window_region
)
201 req
->window
= wine_server_user_handle( hwnd
);
202 req
->redraw
= (bRedraw
!= 0);
203 if (data
->rdh
.nCount
)
204 wine_server_add_data( req
, data
->Buffer
, data
->rdh
.nCount
* sizeof(RECT
) );
206 wine_server_add_data( req
, &empty_rect
, sizeof(empty_rect
) );
207 ret
= !wine_server_call_err( req
);
210 HeapFree( GetProcessHeap(), 0, data
);
212 else /* clear existing region */
214 SERVER_START_REQ( set_window_region
)
216 req
->window
= wine_server_user_handle( hwnd
);
217 req
->redraw
= (bRedraw
!= 0);
218 ret
= !wine_server_call_err( req
);
223 if (ret
) ret
= USER_Driver
->pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
227 UINT swp_flags
= SWP_NOSIZE
|SWP_NOMOVE
|SWP_NOZORDER
|SWP_NOACTIVATE
|SWP_FRAMECHANGED
|SWP_NOCLIENTSIZE
|SWP_NOCLIENTMOVE
;
228 if (!bRedraw
) swp_flags
|= SWP_NOREDRAW
;
229 SetWindowPos( hwnd
, 0, 0, 0, 0, 0, swp_flags
);
230 invalidate_dce( hwnd
, NULL
);
236 /***********************************************************************
237 * GetClientRect (USER32.@)
239 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
243 if ((ret
= WIN_GetRectangles( hwnd
, NULL
, rect
)))
245 rect
->right
-= rect
->left
;
246 rect
->bottom
-= rect
->top
;
247 rect
->left
= rect
->top
= 0;
253 /*******************************************************************
254 * ClientToScreen (USER32.@)
256 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
258 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
263 /*******************************************************************
264 * ScreenToClient (USER32.@)
266 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
268 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
273 /***********************************************************************
274 * list_children_from_point
276 * Get the list of children that can contain point from the server.
277 * Point is in screen coordinates.
278 * Returned list must be freed by caller.
280 static HWND
*list_children_from_point( HWND hwnd
, POINT pt
)
289 if (!(list
= HeapAlloc( GetProcessHeap(), 0, size
* sizeof(HWND
) ))) break;
291 SERVER_START_REQ( get_window_children_from_point
)
293 req
->parent
= wine_server_user_handle( hwnd
);
296 wine_server_set_reply( req
, list
, (size
-1) * sizeof(user_handle_t
) );
297 if (!wine_server_call( req
)) count
= reply
->count
;
300 if (count
&& count
< size
)
302 /* start from the end since HWND is potentially larger than user_handle_t */
303 for (i
= count
- 1; i
>= 0; i
--)
304 list
[i
] = wine_server_ptr_handle( ((user_handle_t
*)list
)[i
] );
308 HeapFree( GetProcessHeap(), 0, list
);
310 size
= count
+ 1; /* restart with a large enough buffer */
316 /***********************************************************************
317 * WINPOS_WindowFromPoint
319 * Find the window and hittest for a given point.
321 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
326 if (!hwndScope
) hwndScope
= GetDesktopWindow();
328 *hittest
= HTNOWHERE
;
330 if (!(list
= list_children_from_point( hwndScope
, pt
))) return 0;
332 /* now determine the hittest */
334 for (i
= 0; list
[i
]; i
++)
336 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
338 /* If window is minimized or disabled, return at once */
339 if (style
& WS_MINIMIZE
)
341 *hittest
= HTCAPTION
;
344 if (style
& WS_DISABLED
)
349 /* Send WM_NCCHITTEST (if same thread) */
350 if (!WIN_IsCurrentThread( list
[i
] ))
355 res
= SendMessageW( list
[i
], WM_NCHITTEST
, 0, MAKELONG(pt
.x
,pt
.y
) );
356 if (res
!= HTTRANSPARENT
)
358 *hittest
= res
; /* Found the window */
361 /* continue search with next window in z-order */
364 HeapFree( GetProcessHeap(), 0, list
);
365 TRACE( "scope %p (%d,%d) returning %p\n", hwndScope
, pt
.x
, pt
.y
, ret
);
370 /*******************************************************************
371 * WindowFromPoint (USER32.@)
373 HWND WINAPI
WindowFromPoint( POINT pt
)
376 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
380 /*******************************************************************
381 * ChildWindowFromPoint (USER32.@)
383 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
385 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
388 /*******************************************************************
389 * RealChildWindowFromPoint (USER32.@)
391 HWND WINAPI
RealChildWindowFromPoint( HWND hwndParent
, POINT pt
)
393 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_SKIPTRANSPARENT
);
396 /*******************************************************************
397 * ChildWindowFromPointEx (USER32.@)
399 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
401 /* pt is in the client coordinates */
407 GetClientRect( hwndParent
, &rect
);
408 if (!PtInRect( &rect
, pt
)) return 0;
409 if (!(list
= WIN_ListChildren( hwndParent
))) return hwndParent
;
411 for (i
= 0; list
[i
]; i
++)
413 if (!WIN_GetRectangles( list
[i
], &rect
, NULL
)) continue;
414 if (!PtInRect( &rect
, pt
)) continue;
415 if (uFlags
& (CWP_SKIPINVISIBLE
|CWP_SKIPDISABLED
))
417 LONG style
= GetWindowLongW( list
[i
], GWL_STYLE
);
418 if ((uFlags
& CWP_SKIPINVISIBLE
) && !(style
& WS_VISIBLE
)) continue;
419 if ((uFlags
& CWP_SKIPDISABLED
) && (style
& WS_DISABLED
)) continue;
421 if (uFlags
& CWP_SKIPTRANSPARENT
)
423 if (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TRANSPARENT
) continue;
428 HeapFree( GetProcessHeap(), 0, list
);
429 if (!retvalue
) retvalue
= hwndParent
;
434 /*******************************************************************
435 * WINPOS_GetWinOffset
437 * Calculate the offset between the origin of the two windows. Used
438 * to implement MapWindowPoints.
440 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
, POINT
*offset
)
444 offset
->x
= offset
->y
= 0;
446 /* Translate source window origin to screen coords */
449 HWND hwnd
= hwndFrom
;
453 if (hwnd
== hwndTo
) return;
454 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
456 ERR( "bad hwndFrom = %p\n", hwnd
);
459 if (wndPtr
== WND_DESKTOP
) break;
460 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
463 offset
->x
+= wndPtr
->rectClient
.left
;
464 offset
->y
+= wndPtr
->rectClient
.top
;
466 hwnd
= wndPtr
->parent
;
467 WIN_ReleasePtr( wndPtr
);
471 /* Translate origin to destination window coords */
478 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
480 ERR( "bad hwndTo = %p\n", hwnd
);
483 if (wndPtr
== WND_DESKTOP
) break;
484 if (wndPtr
== WND_OTHER_PROCESS
) goto other_process
;
487 offset
->x
-= wndPtr
->rectClient
.left
;
488 offset
->y
-= wndPtr
->rectClient
.top
;
490 hwnd
= wndPtr
->parent
;
491 WIN_ReleasePtr( wndPtr
);
496 other_process
: /* one of the parents may belong to another process, do it the hard way */
497 offset
->x
= offset
->y
= 0;
498 SERVER_START_REQ( get_windows_offset
)
500 req
->from
= wine_server_user_handle( hwndFrom
);
501 req
->to
= wine_server_user_handle( hwndTo
);
502 if (!wine_server_call( req
))
504 offset
->x
= reply
->x
;
505 offset
->y
= reply
->y
;
512 /*******************************************************************
513 * MapWindowPoints (USER.258)
515 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
516 LPPOINT16 lppt
, UINT16 count
)
520 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
530 /*******************************************************************
531 * MapWindowPoints (USER32.@)
533 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
, LPPOINT lppt
, UINT count
)
537 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
544 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
548 /***********************************************************************
549 * IsIconic (USER32.@)
551 BOOL WINAPI
IsIconic(HWND hWnd
)
553 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MINIMIZE
) != 0;
557 /***********************************************************************
558 * IsZoomed (USER32.@)
560 BOOL WINAPI
IsZoomed(HWND hWnd
)
562 return (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_MAXIMIZE
) != 0;
566 /*******************************************************************
567 * AllowSetForegroundWindow (USER32.@)
569 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
571 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
572 * implemented, then fix this function. */
577 /*******************************************************************
578 * LockSetForegroundWindow (USER32.@)
580 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
582 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
583 * implemented, then fix this function. */
588 /***********************************************************************
589 * BringWindowToTop (USER32.@)
591 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
593 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
597 /***********************************************************************
598 * MoveWindow (USER32.@)
600 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
603 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
604 if (!repaint
) flags
|= SWP_NOREDRAW
;
605 TRACE("%p %d,%d %dx%d %d\n", hwnd
, x
, y
, cx
, cy
, repaint
);
606 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
610 /***********************************************************************
611 * WINPOS_RedrawIconTitle
613 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
616 WND
*win
= WIN_GetPtr( hWnd
);
618 if (win
&& win
!= WND_OTHER_PROCESS
&& win
!= WND_DESKTOP
)
620 icon_title
= win
->icon_title
;
621 WIN_ReleasePtr( win
);
623 if (!icon_title
) return FALSE
;
624 SendMessageW( icon_title
, WM_SHOWWINDOW
, TRUE
, 0 );
625 InvalidateRect( icon_title
, NULL
, TRUE
);
629 /***********************************************************************
630 * WINPOS_ShowIconTitle
632 static BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
634 if (!GetPropA( hwnd
, "__wine_x11_managed" ))
636 WND
*win
= WIN_GetPtr( hwnd
);
639 TRACE("%p %i\n", hwnd
, (bShow
!= 0) );
641 if (!win
|| win
== WND_OTHER_PROCESS
|| win
== WND_DESKTOP
) return FALSE
;
642 title
= win
->icon_title
;
643 WIN_ReleasePtr( win
);
649 title
= ICONTITLE_Create( hwnd
);
650 if (!(win
= WIN_GetPtr( hwnd
)) || win
== WND_OTHER_PROCESS
)
652 DestroyWindow( title
);
655 win
->icon_title
= title
;
656 WIN_ReleasePtr( win
);
658 if (!IsWindowVisible(title
))
660 SendMessageW( title
, WM_SHOWWINDOW
, TRUE
, 0 );
661 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
662 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
665 else if (title
) ShowWindow( title
, SW_HIDE
);
670 /*******************************************************************
671 * WINPOS_GetMinMaxInfo
673 * Get the minimized and maximized information for a window.
675 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
676 POINT
*minTrack
, POINT
*maxTrack
)
681 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
683 LONG exstyle
= GetWindowLongW( hwnd
, GWL_EXSTYLE
);
687 /* Compute default values */
689 GetWindowRect(hwnd
, &rc
);
690 MinMax
.ptReserved
.x
= rc
.left
;
691 MinMax
.ptReserved
.y
= rc
.top
;
693 if ((style
& WS_CAPTION
) == WS_CAPTION
)
694 adjustedStyle
= style
& ~WS_BORDER
; /* WS_CAPTION = WS_DLGFRAME | WS_BORDER */
696 adjustedStyle
= style
;
698 GetClientRect(GetAncestor(hwnd
,GA_PARENT
), &rc
);
699 AdjustWindowRectEx(&rc
, adjustedStyle
, ((style
& WS_POPUP
) && GetMenu(hwnd
)), exstyle
);
704 MinMax
.ptMaxSize
.x
= rc
.right
- rc
.left
;
705 MinMax
.ptMaxSize
.y
= rc
.bottom
- rc
.top
;
706 if (style
& (WS_DLGFRAME
| WS_BORDER
))
708 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
709 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
713 MinMax
.ptMinTrackSize
.x
= 2 * xinc
;
714 MinMax
.ptMinTrackSize
.y
= 2 * yinc
;
716 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXMAXTRACK
);
717 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYMAXTRACK
);
718 MinMax
.ptMaxPosition
.x
= -xinc
;
719 MinMax
.ptMaxPosition
.y
= -yinc
;
721 if ((win
= WIN_GetPtr( hwnd
)) && win
!= WND_DESKTOP
&& win
!= WND_OTHER_PROCESS
)
723 if (!EMPTYPOINT(win
->max_pos
)) MinMax
.ptMaxPosition
= win
->max_pos
;
724 WIN_ReleasePtr( win
);
727 SendMessageW( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
729 /* if the app didn't change the values, adapt them for the current monitor */
731 if ((monitor
= MonitorFromWindow( hwnd
, MONITOR_DEFAULTTOPRIMARY
)))
734 MONITORINFO mon_info
;
736 mon_info
.cbSize
= sizeof(mon_info
);
737 GetMonitorInfoW( monitor
, &mon_info
);
739 rc_work
= mon_info
.rcMonitor
;
741 if (style
& WS_MAXIMIZEBOX
)
743 if ((style
& WS_CAPTION
) == WS_CAPTION
|| !(style
& (WS_CHILD
| WS_POPUP
)))
744 rc_work
= mon_info
.rcWork
;
747 if (MinMax
.ptMaxSize
.x
== GetSystemMetrics(SM_CXSCREEN
) + 2 * xinc
&&
748 MinMax
.ptMaxSize
.y
== GetSystemMetrics(SM_CYSCREEN
) + 2 * yinc
)
750 MinMax
.ptMaxSize
.x
= (rc_work
.right
- rc_work
.left
) + 2 * xinc
;
751 MinMax
.ptMaxSize
.y
= (rc_work
.bottom
- rc_work
.top
) + 2 * yinc
;
753 if (MinMax
.ptMaxPosition
.x
== -xinc
&& MinMax
.ptMaxPosition
.y
== -yinc
)
755 MinMax
.ptMaxPosition
.x
= rc_work
.left
- xinc
;
756 MinMax
.ptMaxPosition
.y
= rc_work
.top
- yinc
;
760 /* Some sanity checks */
762 TRACE("%d %d / %d %d / %d %d / %d %d\n",
763 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
764 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
765 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
766 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
767 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
768 MinMax
.ptMinTrackSize
.x
);
769 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
770 MinMax
.ptMinTrackSize
.y
);
772 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
773 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
774 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
775 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
779 /***********************************************************************
782 * Find a suitable place for an iconic window.
784 static POINT
WINPOS_FindIconPos( HWND hwnd
, POINT pt
)
786 RECT rect
, rectParent
;
789 int xspacing
, yspacing
;
791 parent
= GetAncestor( hwnd
, GA_PARENT
);
792 GetClientRect( parent
, &rectParent
);
793 if ((pt
.x
>= rectParent
.left
) && (pt
.x
+ GetSystemMetrics(SM_CXICON
) < rectParent
.right
) &&
794 (pt
.y
>= rectParent
.top
) && (pt
.y
+ GetSystemMetrics(SM_CYICON
) < rectParent
.bottom
))
795 return pt
; /* The icon already has a suitable position */
797 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
798 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
800 /* Check if another icon already occupies this spot */
801 /* FIXME: this is completely inefficient */
803 hrgn
= CreateRectRgn( 0, 0, 0, 0 );
804 tmp
= CreateRectRgn( 0, 0, 0, 0 );
805 for (child
= GetWindow( parent
, GW_HWNDFIRST
); child
; child
= GetWindow( child
, GW_HWNDNEXT
))
808 if (child
== hwnd
) continue;
809 if ((GetWindowLongW( child
, GWL_STYLE
) & (WS_VISIBLE
|WS_MINIMIZE
)) != (WS_VISIBLE
|WS_MINIMIZE
))
811 if (!(childPtr
= WIN_GetPtr( child
)) || childPtr
== WND_OTHER_PROCESS
)
813 SetRectRgn( tmp
, childPtr
->rectWindow
.left
, childPtr
->rectWindow
.top
,
814 childPtr
->rectWindow
.right
, childPtr
->rectWindow
.bottom
);
815 CombineRgn( hrgn
, hrgn
, tmp
, RGN_OR
);
816 WIN_ReleasePtr( childPtr
);
820 for (rect
.bottom
= rectParent
.bottom
; rect
.bottom
>= yspacing
; rect
.bottom
-= yspacing
)
822 for (rect
.left
= rectParent
.left
; rect
.left
<= rectParent
.right
- xspacing
; rect
.left
+= xspacing
)
824 rect
.right
= rect
.left
+ xspacing
;
825 rect
.top
= rect
.bottom
- yspacing
;
826 if (!RectInRegion( hrgn
, &rect
))
828 /* No window was found, so it's OK for us */
829 pt
.x
= rect
.left
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2;
830 pt
.y
= rect
.top
+ (yspacing
- GetSystemMetrics(SM_CYICON
)) / 2;
831 DeleteObject( hrgn
);
836 DeleteObject( hrgn
);
842 /***********************************************************************
845 UINT
WINPOS_MinMaximize( HWND hwnd
, UINT cmd
, LPRECT rect
)
853 TRACE("%p %u\n", hwnd
, cmd
);
855 wpl
.length
= sizeof(wpl
);
856 GetWindowPlacement( hwnd
, &wpl
);
858 if (HOOK_CallHooks( WH_CBT
, HCBT_MINMAX
, (WPARAM
)hwnd
, cmd
, TRUE
))
859 return SWP_NOSIZE
| SWP_NOMOVE
;
861 if (IsIconic( hwnd
))
865 case SW_SHOWMINNOACTIVE
:
866 case SW_SHOWMINIMIZED
:
867 case SW_FORCEMINIMIZE
:
869 return SWP_NOSIZE
| SWP_NOMOVE
;
871 if (!SendMessageW( hwnd
, WM_QUERYOPEN
, 0, 0 )) return SWP_NOSIZE
| SWP_NOMOVE
;
872 swpFlags
|= SWP_NOCOPYBITS
;
877 case SW_SHOWMINNOACTIVE
:
878 case SW_SHOWMINIMIZED
:
879 case SW_FORCEMINIMIZE
:
881 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
882 if( wndPtr
->dwStyle
& WS_MAXIMIZE
) wndPtr
->flags
|= WIN_RESTORE_MAX
;
883 else wndPtr
->flags
&= ~WIN_RESTORE_MAX
;
884 WIN_ReleasePtr( wndPtr
);
886 old_style
= WIN_SetStyle( hwnd
, WS_MINIMIZE
, WS_MAXIMIZE
);
888 wpl
.ptMinPosition
= WINPOS_FindIconPos( hwnd
, wpl
.ptMinPosition
);
890 if (!(old_style
& WS_MINIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
891 SetRect( rect
, wpl
.ptMinPosition
.x
, wpl
.ptMinPosition
.y
,
892 wpl
.ptMinPosition
.x
+ GetSystemMetrics(SM_CXICON
),
893 wpl
.ptMinPosition
.y
+ GetSystemMetrics(SM_CYICON
) );
894 swpFlags
|= SWP_NOCOPYBITS
;
898 old_style
= GetWindowLongW( hwnd
, GWL_STYLE
);
899 if ((old_style
& WS_MAXIMIZE
) && (old_style
& WS_VISIBLE
)) return SWP_NOSIZE
| SWP_NOMOVE
;
901 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
903 old_style
= WIN_SetStyle( hwnd
, WS_MAXIMIZE
, WS_MINIMIZE
);
904 if (old_style
& WS_MINIMIZE
) WINPOS_ShowIconTitle( hwnd
, FALSE
);
906 if (!(old_style
& WS_MAXIMIZE
)) swpFlags
|= SWP_STATECHANGED
;
907 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
908 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
911 case SW_SHOWNOACTIVATE
:
914 old_style
= WIN_SetStyle( hwnd
, 0, WS_MINIMIZE
| WS_MAXIMIZE
);
915 if (old_style
& WS_MINIMIZE
)
919 WINPOS_ShowIconTitle( hwnd
, FALSE
);
921 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
922 restore_max
= (wndPtr
->flags
& WIN_RESTORE_MAX
) != 0;
923 WIN_ReleasePtr( wndPtr
);
926 /* Restore to maximized position */
927 WINPOS_GetMinMaxInfo( hwnd
, &size
, &wpl
.ptMaxPosition
, NULL
, NULL
);
928 WIN_SetStyle( hwnd
, WS_MAXIMIZE
, 0 );
929 swpFlags
|= SWP_STATECHANGED
;
930 SetRect( rect
, wpl
.ptMaxPosition
.x
, wpl
.ptMaxPosition
.y
,
931 wpl
.ptMaxPosition
.x
+ size
.x
, wpl
.ptMaxPosition
.y
+ size
.y
);
935 else if (!(old_style
& WS_MAXIMIZE
)) break;
937 swpFlags
|= SWP_STATECHANGED
;
939 /* Restore to normal position */
941 *rect
= wpl
.rcNormalPosition
;
949 /***********************************************************************
952 * Implementation of ShowWindow and ShowWindowAsync.
954 static BOOL
show_window( HWND hwnd
, INT cmd
)
958 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
959 BOOL wasVisible
= (style
& WS_VISIBLE
) != 0;
960 BOOL showFlag
= TRUE
;
961 RECT newPos
= {0, 0, 0, 0};
964 TRACE("hwnd=%p, cmd=%d, wasVisible %d\n", hwnd
, cmd
, wasVisible
);
969 if (!wasVisible
) return FALSE
;
971 swp
|= SWP_HIDEWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
972 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
975 case SW_SHOWMINNOACTIVE
:
977 case SW_FORCEMINIMIZE
: /* FIXME: Does not work if thread is hung. */
978 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
980 case SW_SHOWMINIMIZED
:
981 swp
|= SWP_SHOWWINDOW
| SWP_FRAMECHANGED
;
982 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
983 if ((style
& WS_MINIMIZE
) && wasVisible
) return TRUE
;
986 case SW_SHOWMAXIMIZED
: /* same as SW_MAXIMIZE */
987 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
988 swp
|= SWP_FRAMECHANGED
;
989 swp
|= WINPOS_MinMaximize( hwnd
, SW_MAXIMIZE
, &newPos
);
990 if ((style
& WS_MAXIMIZE
) && wasVisible
) return TRUE
;
994 swp
|= SWP_NOACTIVATE
| SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
995 if (style
& WS_CHILD
) swp
|= SWP_NOZORDER
;
998 if (wasVisible
) return TRUE
;
999 swp
|= SWP_SHOWWINDOW
| SWP_NOSIZE
| SWP_NOMOVE
;
1000 if (style
& WS_CHILD
) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1003 case SW_SHOWNOACTIVATE
:
1004 swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1008 case SW_SHOWNORMAL
: /* same as SW_NORMAL: */
1009 case SW_SHOWDEFAULT
: /* FIXME: should have its own handler */
1010 if (!wasVisible
) swp
|= SWP_SHOWWINDOW
;
1011 if (style
& (WS_MINIMIZE
| WS_MAXIMIZE
))
1013 swp
|= SWP_FRAMECHANGED
;
1014 swp
|= WINPOS_MinMaximize( hwnd
, cmd
, &newPos
);
1018 if (wasVisible
) return TRUE
;
1019 swp
|= SWP_NOSIZE
| SWP_NOMOVE
;
1021 if (style
& WS_CHILD
&& !(swp
& SWP_STATECHANGED
)) swp
|= SWP_NOACTIVATE
| SWP_NOZORDER
;
1027 if ((showFlag
!= wasVisible
|| cmd
== SW_SHOWNA
) && cmd
!= SW_SHOWMAXIMIZED
&& !(swp
& SWP_STATECHANGED
))
1029 SendMessageW( hwnd
, WM_SHOWWINDOW
, showFlag
, 0 );
1030 if (!IsWindow( hwnd
)) return wasVisible
;
1033 swp
= USER_Driver
->pShowWindow( hwnd
, cmd
, &newPos
, swp
);
1035 parent
= GetAncestor( hwnd
, GA_PARENT
);
1036 if (parent
&& !IsWindowVisible( parent
) && !(swp
& SWP_STATECHANGED
))
1038 /* if parent is not visible simply toggle WS_VISIBLE and return */
1039 if (showFlag
) WIN_SetStyle( hwnd
, WS_VISIBLE
, 0 );
1040 else WIN_SetStyle( hwnd
, 0, WS_VISIBLE
);
1043 SetWindowPos( hwnd
, HWND_TOP
, newPos
.left
, newPos
.top
,
1044 newPos
.right
- newPos
.left
, newPos
.bottom
- newPos
.top
, swp
);
1050 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1052 /* FIXME: This will cause the window to be activated irrespective
1053 * of whether it is owned by the same thread. Has to be done
1057 if (hwnd
== GetActiveWindow())
1058 WINPOS_ActivateOtherWindow(hwnd
);
1060 /* Revert focus to parent */
1061 hFocus
= GetFocus();
1062 if (hwnd
== hFocus
|| IsChild(hwnd
, hFocus
))
1064 HWND parent
= GetAncestor(hwnd
, GA_PARENT
);
1065 if (parent
== GetDesktopWindow()) parent
= 0;
1071 if (IsIconic(hwnd
)) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1073 if (!(wndPtr
= WIN_GetPtr( hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return wasVisible
;
1075 if (wndPtr
->flags
& WIN_NEED_SIZE
)
1077 /* should happen only in CreateWindowEx() */
1078 int wParam
= SIZE_RESTORED
;
1079 RECT client
= wndPtr
->rectClient
;
1081 wndPtr
->flags
&= ~WIN_NEED_SIZE
;
1082 if (wndPtr
->dwStyle
& WS_MAXIMIZE
) wParam
= SIZE_MAXIMIZED
;
1083 else if (wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= SIZE_MINIMIZED
;
1084 WIN_ReleasePtr( wndPtr
);
1086 SendMessageW( hwnd
, WM_SIZE
, wParam
,
1087 MAKELONG( client
.right
- client
.left
, client
.bottom
- client
.top
));
1088 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG( client
.left
, client
.top
));
1090 else WIN_ReleasePtr( wndPtr
);
1092 /* if previous state was minimized Windows sets focus to the window */
1093 if (style
& WS_MINIMIZE
) SetFocus( hwnd
);
1099 /***********************************************************************
1100 * ShowWindowAsync (USER32.@)
1102 * doesn't wait; returns immediately.
1103 * used by threads to toggle windows in other (possibly hanging) threads
1105 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1109 if (is_broadcast(hwnd
))
1111 SetLastError( ERROR_INVALID_PARAMETER
);
1115 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1116 return show_window( full_handle
, cmd
);
1118 return SendNotifyMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1122 /***********************************************************************
1123 * ShowWindow (USER32.@)
1125 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1129 if (is_broadcast(hwnd
))
1131 SetLastError( ERROR_INVALID_PARAMETER
);
1134 if ((full_handle
= WIN_IsCurrentThread( hwnd
)))
1135 return show_window( full_handle
, cmd
);
1137 return SendMessageW( hwnd
, WM_WINE_SHOWWINDOW
, cmd
, 0 );
1141 /***********************************************************************
1142 * GetInternalWindowPos (USER32.@)
1144 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1147 WINDOWPLACEMENT wndpl
;
1148 if (GetWindowPlacement( hwnd
, &wndpl
))
1150 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1151 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1152 return wndpl
.showCmd
;
1158 /***********************************************************************
1159 * GetWindowPlacement (USER32.@)
1162 * Fails if wndpl->length of Win95 (!) apps is invalid.
1164 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
1166 WND
*pWnd
= WIN_GetPtr( hwnd
);
1168 if (!pWnd
) return FALSE
;
1170 if (pWnd
== WND_DESKTOP
)
1172 wndpl
->length
= sizeof(*wndpl
);
1173 wndpl
->showCmd
= SW_SHOWNORMAL
;
1175 wndpl
->ptMinPosition
.x
= -1;
1176 wndpl
->ptMinPosition
.y
= -1;
1177 wndpl
->ptMaxPosition
.x
= -1;
1178 wndpl
->ptMaxPosition
.y
= -1;
1179 GetWindowRect( hwnd
, &wndpl
->rcNormalPosition
);
1182 if (pWnd
== WND_OTHER_PROCESS
)
1184 if (IsWindow( hwnd
)) FIXME( "not supported on other process window %p\n", hwnd
);
1188 /* update the placement according to the current style */
1189 if (pWnd
->dwStyle
& WS_MINIMIZE
)
1191 pWnd
->min_pos
.x
= pWnd
->rectWindow
.left
;
1192 pWnd
->min_pos
.y
= pWnd
->rectWindow
.top
;
1194 else if (pWnd
->dwStyle
& WS_MAXIMIZE
)
1196 pWnd
->max_pos
.x
= pWnd
->rectWindow
.left
;
1197 pWnd
->max_pos
.y
= pWnd
->rectWindow
.top
;
1201 pWnd
->normal_rect
= pWnd
->rectWindow
;
1204 wndpl
->length
= sizeof(*wndpl
);
1205 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1206 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1208 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1209 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1210 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1213 wndpl
->ptMinPosition
= pWnd
->min_pos
;
1214 wndpl
->ptMaxPosition
= pWnd
->max_pos
;
1215 wndpl
->rcNormalPosition
= pWnd
->normal_rect
;
1216 WIN_ReleasePtr( pWnd
);
1218 TRACE( "%p: returning min %d,%d max %d,%d normal %s\n",
1219 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1220 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1221 wine_dbgstr_rect(&wndpl
->rcNormalPosition
) );
1225 /* make sure the specified rect is visible on screen */
1226 static void make_rect_onscreen( RECT
*rect
)
1229 HMONITOR monitor
= MonitorFromRect( rect
, MONITOR_DEFAULTTONEAREST
);
1231 info
.cbSize
= sizeof(info
);
1232 if (!monitor
|| !GetMonitorInfoW( monitor
, &info
)) return;
1233 /* FIXME: map coordinates from rcWork to rcMonitor */
1234 if (rect
->right
<= info
.rcWork
.left
)
1236 rect
->right
+= info
.rcWork
.left
- rect
->left
;
1237 rect
->left
= info
.rcWork
.left
;
1239 else if (rect
->left
>= info
.rcWork
.right
)
1241 rect
->left
+= info
.rcWork
.right
- rect
->right
;
1242 rect
->right
= info
.rcWork
.right
;
1244 if (rect
->bottom
<= info
.rcWork
.top
)
1246 rect
->bottom
+= info
.rcWork
.top
- rect
->top
;
1247 rect
->top
= info
.rcWork
.top
;
1249 else if (rect
->top
>= info
.rcWork
.bottom
)
1251 rect
->top
+= info
.rcWork
.bottom
- rect
->bottom
;
1252 rect
->bottom
= info
.rcWork
.bottom
;
1256 /* make sure the specified point is visible on screen */
1257 static void make_point_onscreen( POINT
*pt
)
1261 SetRect( &rect
, pt
->x
, pt
->y
, pt
->x
+ 1, pt
->y
+ 1 );
1262 make_rect_onscreen( &rect
);
1268 /***********************************************************************
1269 * WINPOS_SetPlacement
1271 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1274 WND
*pWnd
= WIN_GetPtr( hwnd
);
1275 WINDOWPLACEMENT wp
= *wndpl
;
1277 if (flags
& PLACE_MIN
) make_point_onscreen( &wp
.ptMinPosition
);
1278 if (flags
& PLACE_MAX
) make_point_onscreen( &wp
.ptMaxPosition
);
1279 if (flags
& PLACE_RECT
) make_rect_onscreen( &wp
.rcNormalPosition
);
1281 TRACE( "%p: setting min %d,%d max %d,%d normal %s flags %x ajusted to min %d,%d max %d,%d normal %s\n",
1282 hwnd
, wndpl
->ptMinPosition
.x
, wndpl
->ptMinPosition
.y
,
1283 wndpl
->ptMaxPosition
.x
, wndpl
->ptMaxPosition
.y
,
1284 wine_dbgstr_rect(&wndpl
->rcNormalPosition
), flags
,
1285 wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
,
1286 wine_dbgstr_rect(&wp
.rcNormalPosition
) );
1288 if (!pWnd
|| pWnd
== WND_OTHER_PROCESS
|| pWnd
== WND_DESKTOP
) return FALSE
;
1290 if( flags
& PLACE_MIN
) pWnd
->min_pos
= wp
.ptMinPosition
;
1291 if( flags
& PLACE_MAX
) pWnd
->max_pos
= wp
.ptMaxPosition
;
1292 if( flags
& PLACE_RECT
) pWnd
->normal_rect
= wp
.rcNormalPosition
;
1294 style
= pWnd
->dwStyle
;
1296 WIN_ReleasePtr( pWnd
);
1298 if( style
& WS_MINIMIZE
)
1300 if (flags
& PLACE_MIN
)
1302 WINPOS_ShowIconTitle( hwnd
, FALSE
);
1303 SetWindowPos( hwnd
, 0, wp
.ptMinPosition
.x
, wp
.ptMinPosition
.y
, 0, 0,
1304 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1307 else if( style
& WS_MAXIMIZE
)
1309 if (flags
& PLACE_MAX
)
1310 SetWindowPos( hwnd
, 0, wp
.ptMaxPosition
.x
, wp
.ptMaxPosition
.y
, 0, 0,
1311 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1313 else if( flags
& PLACE_RECT
)
1314 SetWindowPos( hwnd
, 0, wp
.rcNormalPosition
.left
, wp
.rcNormalPosition
.top
,
1315 wp
.rcNormalPosition
.right
- wp
.rcNormalPosition
.left
,
1316 wp
.rcNormalPosition
.bottom
- wp
.rcNormalPosition
.top
,
1317 SWP_NOZORDER
| SWP_NOACTIVATE
);
1319 ShowWindow( hwnd
, wndpl
->showCmd
);
1321 if (IsIconic( hwnd
))
1323 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_VISIBLE
) WINPOS_ShowIconTitle( hwnd
, TRUE
);
1325 /* SDK: ...valid only the next time... */
1326 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
)
1328 pWnd
= WIN_GetPtr( hwnd
);
1329 if (pWnd
&& pWnd
!= WND_OTHER_PROCESS
)
1331 pWnd
->flags
|= WIN_RESTORE_MAX
;
1332 WIN_ReleasePtr( pWnd
);
1340 /***********************************************************************
1341 * SetWindowPlacement (USER32.@)
1344 * Fails if wndpl->length of Win95 (!) apps is invalid.
1346 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1348 UINT flags
= PLACE_MAX
| PLACE_RECT
;
1349 if (!wpl
) return FALSE
;
1350 if (wpl
->flags
& WPF_SETMINPOSITION
) flags
|= PLACE_MIN
;
1351 return WINPOS_SetPlacement( hwnd
, wpl
, flags
);
1355 /***********************************************************************
1356 * AnimateWindow (USER32.@)
1357 * Shows/Hides a window with an animation
1360 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1362 FIXME("partial stub\n");
1364 /* If trying to show/hide and it's already *
1365 * shown/hidden or invalid window, fail with *
1366 * invalid parameter */
1367 if(!IsWindow(hwnd
) ||
1368 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1369 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1371 SetLastError(ERROR_INVALID_PARAMETER
);
1375 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1380 /***********************************************************************
1381 * SetInternalWindowPos (USER32.@)
1383 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1384 LPRECT rect
, LPPOINT pt
)
1386 WINDOWPLACEMENT wndpl
;
1389 wndpl
.length
= sizeof(wndpl
);
1390 wndpl
.showCmd
= showCmd
;
1391 wndpl
.flags
= flags
= 0;
1396 wndpl
.flags
|= WPF_SETMINPOSITION
;
1397 wndpl
.ptMinPosition
= *pt
;
1401 flags
|= PLACE_RECT
;
1402 wndpl
.rcNormalPosition
= *rect
;
1404 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1408 /*******************************************************************
1409 * can_activate_window
1411 * Check if we can activate the specified window.
1413 static BOOL
can_activate_window( HWND hwnd
)
1417 if (!hwnd
) return FALSE
;
1418 style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1419 if (!(style
& WS_VISIBLE
)) return FALSE
;
1420 if ((style
& (WS_POPUP
|WS_CHILD
)) == WS_CHILD
) return FALSE
;
1421 return !(style
& WS_DISABLED
);
1425 /*******************************************************************
1426 * WINPOS_ActivateOtherWindow
1428 * Activates window other than pWnd.
1430 void WINPOS_ActivateOtherWindow(HWND hwnd
)
1434 if ((GetWindowLongW( hwnd
, GWL_STYLE
) & WS_POPUP
) && (hwndTo
= GetWindow( hwnd
, GW_OWNER
)))
1436 hwndTo
= GetAncestor( hwndTo
, GA_ROOT
);
1437 if (can_activate_window( hwndTo
)) goto done
;
1443 if (!(hwndTo
= GetWindow( hwndTo
, GW_HWNDNEXT
))) break;
1444 if (can_activate_window( hwndTo
)) break;
1448 fg
= GetForegroundWindow();
1449 TRACE("win = %p fg = %p\n", hwndTo
, fg
);
1450 if (!fg
|| (hwnd
== fg
))
1452 if (SetForegroundWindow( hwndTo
)) return;
1454 if (!SetActiveWindow( hwndTo
)) SetActiveWindow(0);
1458 /***********************************************************************
1459 * WINPOS_HandleWindowPosChanging
1461 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1463 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1465 POINT minTrack
, maxTrack
;
1466 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1468 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1469 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1471 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
1472 if (winpos
->cx
> maxTrack
.x
) winpos
->cx
= maxTrack
.x
;
1473 if (winpos
->cy
> maxTrack
.y
) winpos
->cy
= maxTrack
.y
;
1474 if (!(style
& WS_MINIMIZE
))
1476 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1477 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1484 /***********************************************************************
1487 static void dump_winpos_flags(UINT flags
)
1489 static const DWORD dumped_flags
= (SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOZORDER
| SWP_NOREDRAW
|
1490 SWP_NOACTIVATE
| SWP_FRAMECHANGED
| SWP_SHOWWINDOW
|
1491 SWP_HIDEWINDOW
| SWP_NOCOPYBITS
| SWP_NOOWNERZORDER
|
1492 SWP_NOSENDCHANGING
| SWP_DEFERERASE
| SWP_ASYNCWINDOWPOS
|
1493 SWP_NOCLIENTSIZE
| SWP_NOCLIENTMOVE
| SWP_STATECHANGED
);
1495 if(flags
& SWP_NOSIZE
) TRACE(" SWP_NOSIZE");
1496 if(flags
& SWP_NOMOVE
) TRACE(" SWP_NOMOVE");
1497 if(flags
& SWP_NOZORDER
) TRACE(" SWP_NOZORDER");
1498 if(flags
& SWP_NOREDRAW
) TRACE(" SWP_NOREDRAW");
1499 if(flags
& SWP_NOACTIVATE
) TRACE(" SWP_NOACTIVATE");
1500 if(flags
& SWP_FRAMECHANGED
) TRACE(" SWP_FRAMECHANGED");
1501 if(flags
& SWP_SHOWWINDOW
) TRACE(" SWP_SHOWWINDOW");
1502 if(flags
& SWP_HIDEWINDOW
) TRACE(" SWP_HIDEWINDOW");
1503 if(flags
& SWP_NOCOPYBITS
) TRACE(" SWP_NOCOPYBITS");
1504 if(flags
& SWP_NOOWNERZORDER
) TRACE(" SWP_NOOWNERZORDER");
1505 if(flags
& SWP_NOSENDCHANGING
) TRACE(" SWP_NOSENDCHANGING");
1506 if(flags
& SWP_DEFERERASE
) TRACE(" SWP_DEFERERASE");
1507 if(flags
& SWP_ASYNCWINDOWPOS
) TRACE(" SWP_ASYNCWINDOWPOS");
1508 if(flags
& SWP_NOCLIENTSIZE
) TRACE(" SWP_NOCLIENTSIZE");
1509 if(flags
& SWP_NOCLIENTMOVE
) TRACE(" SWP_NOCLIENTMOVE");
1510 if(flags
& SWP_STATECHANGED
) TRACE(" SWP_STATECHANGED");
1512 if(flags
& ~dumped_flags
) TRACE(" %08x", flags
& ~dumped_flags
);
1516 /***********************************************************************
1517 * SWP_DoWinPosChanging
1519 static BOOL
SWP_DoWinPosChanging( WINDOWPOS
* pWinpos
, RECT
* pNewWindowRect
, RECT
* pNewClientRect
)
1523 /* Send WM_WINDOWPOSCHANGING message */
1525 if (!(pWinpos
->flags
& SWP_NOSENDCHANGING
))
1526 SendMessageW( pWinpos
->hwnd
, WM_WINDOWPOSCHANGING
, 0, (LPARAM
)pWinpos
);
1528 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) ||
1529 wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
1531 /* Calculate new position and size */
1533 *pNewWindowRect
= wndPtr
->rectWindow
;
1534 *pNewClientRect
= (wndPtr
->dwStyle
& WS_MINIMIZE
) ? wndPtr
->rectWindow
1535 : wndPtr
->rectClient
;
1537 if (!(pWinpos
->flags
& SWP_NOSIZE
))
1539 pNewWindowRect
->right
= pNewWindowRect
->left
+ pWinpos
->cx
;
1540 pNewWindowRect
->bottom
= pNewWindowRect
->top
+ pWinpos
->cy
;
1542 if (!(pWinpos
->flags
& SWP_NOMOVE
))
1544 pNewWindowRect
->left
= pWinpos
->x
;
1545 pNewWindowRect
->top
= pWinpos
->y
;
1546 pNewWindowRect
->right
+= pWinpos
->x
- wndPtr
->rectWindow
.left
;
1547 pNewWindowRect
->bottom
+= pWinpos
->y
- wndPtr
->rectWindow
.top
;
1549 OffsetRect( pNewClientRect
, pWinpos
->x
- wndPtr
->rectWindow
.left
,
1550 pWinpos
->y
- wndPtr
->rectWindow
.top
);
1552 pWinpos
->flags
|= SWP_NOCLIENTMOVE
| SWP_NOCLIENTSIZE
;
1554 TRACE( "hwnd %p, after %p, swp %d,%d %dx%d flags %08x\n",
1555 pWinpos
->hwnd
, pWinpos
->hwndInsertAfter
, pWinpos
->x
, pWinpos
->y
,
1556 pWinpos
->cx
, pWinpos
->cy
, pWinpos
->flags
);
1557 TRACE( "current %s style %08x new %s\n",
1558 wine_dbgstr_rect( &wndPtr
->rectWindow
), wndPtr
->dwStyle
,
1559 wine_dbgstr_rect( pNewWindowRect
));
1561 WIN_ReleasePtr( wndPtr
);
1565 /***********************************************************************
1568 * Compute the valid rects from the old and new client rect and WVR_* flags.
1569 * Helper for WM_NCCALCSIZE handling.
1571 static inline void get_valid_rects( const RECT
*old_client
, const RECT
*new_client
, UINT flags
,
1576 if (flags
& WVR_REDRAW
)
1578 SetRectEmpty( &valid
[0] );
1579 SetRectEmpty( &valid
[1] );
1583 if (flags
& WVR_VALIDRECTS
)
1585 if (!IntersectRect( &valid
[0], &valid
[0], new_client
) ||
1586 !IntersectRect( &valid
[1], &valid
[1], old_client
))
1588 SetRectEmpty( &valid
[0] );
1589 SetRectEmpty( &valid
[1] );
1592 flags
= WVR_ALIGNLEFT
| WVR_ALIGNTOP
;
1596 valid
[0] = *new_client
;
1597 valid
[1] = *old_client
;
1600 /* make sure the rectangles have the same size */
1601 cx
= min( valid
[0].right
- valid
[0].left
, valid
[1].right
- valid
[1].left
);
1602 cy
= min( valid
[0].bottom
- valid
[0].top
, valid
[1].bottom
- valid
[1].top
);
1604 if (flags
& WVR_ALIGNBOTTOM
)
1606 valid
[0].top
= valid
[0].bottom
- cy
;
1607 valid
[1].top
= valid
[1].bottom
- cy
;
1611 valid
[0].bottom
= valid
[0].top
+ cy
;
1612 valid
[1].bottom
= valid
[1].top
+ cy
;
1614 if (flags
& WVR_ALIGNRIGHT
)
1616 valid
[0].left
= valid
[0].right
- cx
;
1617 valid
[1].left
= valid
[1].right
- cx
;
1621 valid
[0].right
= valid
[0].left
+ cx
;
1622 valid
[1].right
= valid
[1].left
+ cx
;
1627 /***********************************************************************
1630 * fix Z order taking into account owned popups -
1631 * basically we need to maintain them above the window that owns them
1633 * FIXME: hide/show owned popups when owner visibility changes.
1635 static HWND
SWP_DoOwnedPopups(HWND hwnd
, HWND hwndInsertAfter
)
1637 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
1638 HWND owner
, *list
= NULL
;
1641 TRACE("(%p) hInsertAfter = %p\n", hwnd
, hwndInsertAfter
);
1643 if ((style
& WS_POPUP
) && (owner
= GetWindow( hwnd
, GW_OWNER
)))
1645 /* make sure this popup stays above the owner */
1647 if (hwndInsertAfter
!= HWND_TOP
&& hwndInsertAfter
!= HWND_TOPMOST
)
1649 if (!(list
= WIN_ListChildren( GetDesktopWindow() ))) return hwndInsertAfter
;
1651 for (i
= 0; list
[i
]; i
++)
1653 if (list
[i
] == owner
)
1655 if (i
> 0) hwndInsertAfter
= list
[i
-1];
1656 else hwndInsertAfter
= HWND_TOP
;
1660 if (hwndInsertAfter
== HWND_NOTOPMOST
)
1662 if (!(GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) break;
1664 else if (list
[i
] == hwndInsertAfter
) break;
1668 else if (style
& WS_CHILD
) return hwndInsertAfter
;
1670 if (hwndInsertAfter
== HWND_BOTTOM
) goto done
;
1671 if (!list
&& !(list
= WIN_ListChildren( GetDesktopWindow() ))) goto done
;
1674 if (hwndInsertAfter
== HWND_TOP
|| hwndInsertAfter
== HWND_NOTOPMOST
)
1676 if (hwndInsertAfter
== HWND_NOTOPMOST
|| !(GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_TOPMOST
))
1678 /* skip all the topmost windows */
1679 while (list
[i
] && (GetWindowLongW( list
[i
], GWL_EXSTYLE
) & WS_EX_TOPMOST
)) i
++;
1682 else if (hwndInsertAfter
!= HWND_TOPMOST
)
1684 /* skip windows that are already placed correctly */
1685 for (i
= 0; list
[i
]; i
++)
1687 if (list
[i
] == hwndInsertAfter
) break;
1688 if (list
[i
] == hwnd
) goto done
; /* nothing to do if window is moving backwards in z-order */
1692 for ( ; list
[i
]; i
++)
1694 if (list
[i
] == hwnd
) break;
1695 if (!(GetWindowLongW( list
[i
], GWL_STYLE
) & WS_POPUP
)) continue;
1696 if (GetWindow( list
[i
], GW_OWNER
) != hwnd
) continue;
1697 TRACE( "moving %p owned by %p after %p\n", list
[i
], hwnd
, hwndInsertAfter
);
1698 SetWindowPos( list
[i
], hwndInsertAfter
, 0, 0, 0, 0,
1699 SWP_NOMOVE
| SWP_NOSIZE
| SWP_NOACTIVATE
| SWP_NOSENDCHANGING
| SWP_DEFERERASE
);
1700 hwndInsertAfter
= list
[i
];
1704 HeapFree( GetProcessHeap(), 0, list
);
1705 return hwndInsertAfter
;
1708 /***********************************************************************
1711 static UINT
SWP_DoNCCalcSize( WINDOWPOS
* pWinpos
, const RECT
* pNewWindowRect
, RECT
* pNewClientRect
,
1717 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1719 /* Send WM_NCCALCSIZE message to get new client area */
1720 if( (pWinpos
->flags
& (SWP_FRAMECHANGED
| SWP_NOSIZE
)) != SWP_NOSIZE
)
1722 NCCALCSIZE_PARAMS params
;
1723 WINDOWPOS winposCopy
;
1725 params
.rgrc
[0] = *pNewWindowRect
;
1726 params
.rgrc
[1] = wndPtr
->rectWindow
;
1727 params
.rgrc
[2] = wndPtr
->rectClient
;
1728 params
.lppos
= &winposCopy
;
1729 winposCopy
= *pWinpos
;
1730 WIN_ReleasePtr( wndPtr
);
1732 wvrFlags
= SendMessageW( pWinpos
->hwnd
, WM_NCCALCSIZE
, TRUE
, (LPARAM
)¶ms
);
1734 *pNewClientRect
= params
.rgrc
[0];
1736 if (!(wndPtr
= WIN_GetPtr( pWinpos
->hwnd
)) || wndPtr
== WND_OTHER_PROCESS
) return 0;
1738 TRACE( "hwnd %p old win %s old client %s new win %s new client %s\n", pWinpos
->hwnd
,
1739 wine_dbgstr_rect(&wndPtr
->rectWindow
), wine_dbgstr_rect(&wndPtr
->rectClient
),
1740 wine_dbgstr_rect(pNewWindowRect
), wine_dbgstr_rect(pNewClientRect
) );
1742 if( pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1743 pNewClientRect
->top
!= wndPtr
->rectClient
.top
)
1744 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1746 if( (pNewClientRect
->right
- pNewClientRect
->left
!=
1747 wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
))
1748 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1750 wvrFlags
&= ~WVR_HREDRAW
;
1752 if (pNewClientRect
->bottom
- pNewClientRect
->top
!=
1753 wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
)
1754 pWinpos
->flags
&= ~SWP_NOCLIENTSIZE
;
1756 wvrFlags
&= ~WVR_VREDRAW
;
1758 validRects
[0] = params
.rgrc
[1];
1759 validRects
[1] = params
.rgrc
[2];
1763 if (!(pWinpos
->flags
& SWP_NOMOVE
) &&
1764 (pNewClientRect
->left
!= wndPtr
->rectClient
.left
||
1765 pNewClientRect
->top
!= wndPtr
->rectClient
.top
))
1766 pWinpos
->flags
&= ~SWP_NOCLIENTMOVE
;
1769 if (pWinpos
->flags
& (SWP_NOCOPYBITS
| SWP_NOREDRAW
| SWP_SHOWWINDOW
| SWP_HIDEWINDOW
))
1771 SetRectEmpty( &validRects
[0] );
1772 SetRectEmpty( &validRects
[1] );
1774 else get_valid_rects( &wndPtr
->rectClient
, pNewClientRect
, wvrFlags
, validRects
);
1776 WIN_ReleasePtr( wndPtr
);
1780 /* fix redundant flags and values in the WINDOWPOS structure */
1781 static BOOL
fixup_flags( WINDOWPOS
*winpos
)
1784 WND
*wndPtr
= WIN_GetPtr( winpos
->hwnd
);
1787 if (!wndPtr
|| wndPtr
== WND_OTHER_PROCESS
)
1789 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
1792 winpos
->hwnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1794 /* Finally make sure that all coordinates are valid */
1795 if (winpos
->x
< -32768) winpos
->x
= -32768;
1796 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1797 if (winpos
->y
< -32768) winpos
->y
= -32768;
1798 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1800 if (winpos
->cx
< 0) winpos
->cx
= 0;
1801 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1802 if (winpos
->cy
< 0) winpos
->cy
= 0;
1803 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1805 parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1806 if (!IsWindowVisible( parent
)) winpos
->flags
|= SWP_NOREDRAW
;
1808 if (wndPtr
->dwStyle
& WS_VISIBLE
) winpos
->flags
&= ~SWP_SHOWWINDOW
;
1811 winpos
->flags
&= ~SWP_HIDEWINDOW
;
1812 if (!(winpos
->flags
& SWP_SHOWWINDOW
)) winpos
->flags
|= SWP_NOREDRAW
;
1815 if ((wndPtr
->rectWindow
.right
- wndPtr
->rectWindow
.left
== winpos
->cx
) &&
1816 (wndPtr
->rectWindow
.bottom
- wndPtr
->rectWindow
.top
== winpos
->cy
))
1817 winpos
->flags
|= SWP_NOSIZE
; /* Already the right size */
1819 if ((wndPtr
->rectWindow
.left
== winpos
->x
) && (wndPtr
->rectWindow
.top
== winpos
->y
))
1820 winpos
->flags
|= SWP_NOMOVE
; /* Already the right position */
1822 if ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)
1824 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)) && /* Bring to the top when activating */
1825 (winpos
->flags
& SWP_NOZORDER
||
1826 (winpos
->hwndInsertAfter
!= HWND_TOPMOST
&& winpos
->hwndInsertAfter
!= HWND_NOTOPMOST
)))
1828 winpos
->flags
&= ~SWP_NOZORDER
;
1829 winpos
->hwndInsertAfter
= HWND_TOP
;
1833 /* Check hwndInsertAfter */
1834 if (winpos
->flags
& SWP_NOZORDER
) goto done
;
1836 /* fix sign extension */
1837 if (winpos
->hwndInsertAfter
== (HWND
)0xffff) winpos
->hwndInsertAfter
= HWND_TOPMOST
;
1838 else if (winpos
->hwndInsertAfter
== (HWND
)0xfffe) winpos
->hwndInsertAfter
= HWND_NOTOPMOST
;
1840 /* hwndInsertAfter must be a sibling of the window */
1841 if (winpos
->hwndInsertAfter
== HWND_TOP
)
1843 if (GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1844 winpos
->flags
|= SWP_NOZORDER
;
1846 else if (winpos
->hwndInsertAfter
== HWND_BOTTOM
)
1848 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDLAST
) == winpos
->hwnd
)
1849 winpos
->flags
|= SWP_NOZORDER
;
1851 else if (winpos
->hwndInsertAfter
== HWND_TOPMOST
)
1853 if ((wndPtr
->dwExStyle
& WS_EX_TOPMOST
) && GetWindow(winpos
->hwnd
, GW_HWNDFIRST
) == winpos
->hwnd
)
1854 winpos
->flags
|= SWP_NOZORDER
;
1856 else if (winpos
->hwndInsertAfter
== HWND_NOTOPMOST
)
1858 if (!(wndPtr
->dwExStyle
& WS_EX_TOPMOST
))
1859 winpos
->flags
|= SWP_NOZORDER
;
1863 if (GetAncestor( winpos
->hwndInsertAfter
, GA_PARENT
) != parent
) ret
= FALSE
;
1866 /* don't need to change the Zorder of hwnd if it's already inserted
1867 * after hwndInsertAfter or when inserting hwnd after itself.
1869 if ((winpos
->hwnd
== winpos
->hwndInsertAfter
) ||
1870 (winpos
->hwnd
== GetWindow( winpos
->hwndInsertAfter
, GW_HWNDNEXT
)))
1871 winpos
->flags
|= SWP_NOZORDER
;
1875 WIN_ReleasePtr( wndPtr
);
1880 /***********************************************************************
1883 * Backend implementation of SetWindowPos.
1885 BOOL
set_window_pos( HWND hwnd
, HWND insert_after
, UINT swp_flags
,
1886 const RECT
*window_rect
, const RECT
*client_rect
, const RECT
*valid_rects
)
1890 RECT visible_rect
, old_window_rect
;
1892 visible_rect
= *window_rect
;
1893 USER_Driver
->pWindowPosChanging( hwnd
, insert_after
, swp_flags
,
1894 window_rect
, client_rect
, &visible_rect
);
1896 if (!(win
= WIN_GetPtr( hwnd
))) return FALSE
;
1897 if (win
== WND_DESKTOP
|| win
== WND_OTHER_PROCESS
) return FALSE
;
1899 old_window_rect
= win
->rectWindow
;
1900 SERVER_START_REQ( set_window_pos
)
1902 req
->handle
= wine_server_user_handle( hwnd
);
1903 req
->previous
= wine_server_user_handle( insert_after
);
1904 req
->flags
= swp_flags
;
1905 req
->window
.left
= window_rect
->left
;
1906 req
->window
.top
= window_rect
->top
;
1907 req
->window
.right
= window_rect
->right
;
1908 req
->window
.bottom
= window_rect
->bottom
;
1909 req
->client
.left
= client_rect
->left
;
1910 req
->client
.top
= client_rect
->top
;
1911 req
->client
.right
= client_rect
->right
;
1912 req
->client
.bottom
= client_rect
->bottom
;
1913 if (memcmp( window_rect
, &visible_rect
, sizeof(RECT
) ) || !IsRectEmpty( &valid_rects
[0] ))
1915 wine_server_add_data( req
, &visible_rect
, sizeof(visible_rect
) );
1916 if (!IsRectEmpty( &valid_rects
[0] ))
1917 wine_server_add_data( req
, valid_rects
, 2 * sizeof(*valid_rects
) );
1919 if ((ret
= !wine_server_call( req
)))
1921 win
->dwStyle
= reply
->new_style
;
1922 win
->dwExStyle
= reply
->new_ex_style
;
1923 win
->rectWindow
= *window_rect
;
1924 win
->rectClient
= *client_rect
;
1928 WIN_ReleasePtr( win
);
1932 if (((swp_flags
& SWP_AGG_NOPOSCHANGE
) != SWP_AGG_NOPOSCHANGE
) ||
1933 (swp_flags
& (SWP_HIDEWINDOW
| SWP_SHOWWINDOW
| SWP_STATECHANGED
)))
1934 invalidate_dce( hwnd
, &old_window_rect
);
1936 USER_Driver
->pWindowPosChanged( hwnd
, insert_after
, swp_flags
, window_rect
,
1937 client_rect
, &visible_rect
, valid_rects
);
1943 /***********************************************************************
1946 * User32 internal function
1948 BOOL
USER_SetWindowPos( WINDOWPOS
* winpos
)
1950 RECT newWindowRect
, newClientRect
, valid_rects
[2];
1953 orig_flags
= winpos
->flags
;
1955 /* First make sure that coordinates are valid for WM_WINDOWPOSCHANGING */
1956 if (!(winpos
->flags
& SWP_NOMOVE
))
1958 if (winpos
->x
< -32768) winpos
->x
= -32768;
1959 else if (winpos
->x
> 32767) winpos
->x
= 32767;
1960 if (winpos
->y
< -32768) winpos
->y
= -32768;
1961 else if (winpos
->y
> 32767) winpos
->y
= 32767;
1963 if (!(winpos
->flags
& SWP_NOSIZE
))
1965 if (winpos
->cx
< 0) winpos
->cx
= 0;
1966 else if (winpos
->cx
> 32767) winpos
->cx
= 32767;
1967 if (winpos
->cy
< 0) winpos
->cy
= 0;
1968 else if (winpos
->cy
> 32767) winpos
->cy
= 32767;
1971 if (!SWP_DoWinPosChanging( winpos
, &newWindowRect
, &newClientRect
)) return FALSE
;
1973 /* Fix redundant flags */
1974 if (!fixup_flags( winpos
)) return FALSE
;
1976 if((winpos
->flags
& (SWP_NOZORDER
| SWP_HIDEWINDOW
| SWP_SHOWWINDOW
)) != SWP_NOZORDER
)
1978 if (GetAncestor( winpos
->hwnd
, GA_PARENT
) == GetDesktopWindow())
1979 winpos
->hwndInsertAfter
= SWP_DoOwnedPopups( winpos
->hwnd
, winpos
->hwndInsertAfter
);
1982 /* Common operations */
1984 SWP_DoNCCalcSize( winpos
, &newWindowRect
, &newClientRect
, valid_rects
);
1986 if (!set_window_pos( winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->flags
,
1987 &newWindowRect
, &newClientRect
, valid_rects
))
1990 /* erase parent when hiding or resizing child */
1991 if (!(orig_flags
& SWP_DEFERERASE
) &&
1992 ((orig_flags
& SWP_HIDEWINDOW
) ||
1993 (!(orig_flags
& SWP_SHOWWINDOW
) &&
1994 (winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOGEOMETRYCHANGE
)))
1996 HWND parent
= GetAncestor( winpos
->hwnd
, GA_PARENT
);
1997 if (!parent
|| parent
== GetDesktopWindow()) parent
= winpos
->hwnd
;
1998 erase_now( parent
, 0 );
2001 if( winpos
->flags
& SWP_HIDEWINDOW
)
2002 HideCaret(winpos
->hwnd
);
2003 else if (winpos
->flags
& SWP_SHOWWINDOW
)
2004 ShowCaret(winpos
->hwnd
);
2006 if (!(winpos
->flags
& (SWP_NOACTIVATE
|SWP_HIDEWINDOW
)))
2008 /* child windows get WM_CHILDACTIVATE message */
2009 if ((GetWindowLongW( winpos
->hwnd
, GWL_STYLE
) & (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
2010 SendMessageW( winpos
->hwnd
, WM_CHILDACTIVATE
, 0, 0 );
2012 SetForegroundWindow( winpos
->hwnd
);
2015 /* And last, send the WM_WINDOWPOSCHANGED message */
2017 TRACE("\tstatus flags = %04x\n", winpos
->flags
& SWP_AGG_STATUSFLAGS
);
2019 if (((winpos
->flags
& SWP_AGG_STATUSFLAGS
) != SWP_AGG_NOPOSCHANGE
))
2021 /* WM_WINDOWPOSCHANGED is sent even if SWP_NOSENDCHANGING is set
2022 and always contains final window position.
2024 winpos
->x
= newWindowRect
.left
;
2025 winpos
->y
= newWindowRect
.top
;
2026 winpos
->cx
= newWindowRect
.right
- newWindowRect
.left
;
2027 winpos
->cy
= newWindowRect
.bottom
- newWindowRect
.top
;
2028 SendMessageW( winpos
->hwnd
, WM_WINDOWPOSCHANGED
, 0, (LPARAM
)winpos
);
2033 /***********************************************************************
2034 * SetWindowPos (USER32.@)
2036 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
2037 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
2041 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2042 hwnd
, hwndInsertAfter
, x
, y
, cx
, cy
, flags
);
2043 if(TRACE_ON(win
)) dump_winpos_flags(flags
);
2045 if (is_broadcast(hwnd
))
2047 SetLastError( ERROR_INVALID_PARAMETER
);
2051 winpos
.hwnd
= WIN_GetFullHandle(hwnd
);
2052 winpos
.hwndInsertAfter
= WIN_GetFullHandle(hwndInsertAfter
);
2057 winpos
.flags
= flags
;
2059 if (WIN_IsCurrentThread( hwnd
))
2060 return USER_SetWindowPos(&winpos
);
2062 return SendMessageW( winpos
.hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)&winpos
);
2066 /***********************************************************************
2067 * BeginDeferWindowPos (USER32.@)
2069 HDWP WINAPI
BeginDeferWindowPos( INT count
)
2074 TRACE("%d\n", count
);
2078 SetLastError(ERROR_INVALID_PARAMETER
);
2081 /* Windows allows zero count, in which case it allocates context for 8 moves */
2082 if (count
== 0) count
= 8;
2084 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
2085 if (!handle
) return 0;
2086 pDWP
= USER_HEAP_LIN_ADDR( handle
);
2087 pDWP
->actualCount
= 0;
2088 pDWP
->suggestedCount
= count
;
2090 pDWP
->wMagic
= DWP_MAGIC
;
2091 pDWP
->hwndParent
= 0;
2093 TRACE("returning hdwp %p\n", handle
);
2098 /***********************************************************************
2099 * DeferWindowPos (USER32.@)
2101 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
2102 INT x
, INT y
, INT cx
, INT cy
,
2107 HDWP newhdwp
= hdwp
,retvalue
;
2109 TRACE("hdwp %p, hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2110 hdwp
, hwnd
, hwndAfter
, x
, y
, cx
, cy
, flags
);
2112 hwnd
= WIN_GetFullHandle( hwnd
);
2113 if (is_desktop_window( hwnd
)) return 0;
2115 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
2119 for (i
= 0; i
< pDWP
->actualCount
; i
++)
2121 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
2123 /* Merge with the other changes */
2124 if (!(flags
& SWP_NOZORDER
))
2126 pDWP
->winPos
[i
].hwndInsertAfter
= WIN_GetFullHandle(hwndAfter
);
2128 if (!(flags
& SWP_NOMOVE
))
2130 pDWP
->winPos
[i
].x
= x
;
2131 pDWP
->winPos
[i
].y
= y
;
2133 if (!(flags
& SWP_NOSIZE
))
2135 pDWP
->winPos
[i
].cx
= cx
;
2136 pDWP
->winPos
[i
].cy
= cy
;
2138 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2139 SWP_NOZORDER
| SWP_NOREDRAW
|
2140 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2142 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2148 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2150 newhdwp
= USER_HEAP_REALLOC( hdwp
,
2151 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
2157 pDWP
= USER_HEAP_LIN_ADDR( newhdwp
);
2158 pDWP
->suggestedCount
++;
2160 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2161 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2162 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2163 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2164 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2165 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2166 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2167 pDWP
->actualCount
++;
2175 /***********************************************************************
2176 * EndDeferWindowPos (USER32.@)
2178 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2185 TRACE("%p\n", hdwp
);
2187 pDWP
= USER_HEAP_LIN_ADDR( hdwp
);
2188 if (!pDWP
) return FALSE
;
2189 for (i
= 0, winpos
= pDWP
->winPos
; res
&& i
< pDWP
->actualCount
; i
++, winpos
++)
2191 TRACE("hwnd %p, after %p, %d,%d (%dx%d), flags %08x\n",
2192 winpos
->hwnd
, winpos
->hwndInsertAfter
, winpos
->x
, winpos
->y
,
2193 winpos
->cx
, winpos
->cy
, winpos
->flags
);
2195 if (WIN_IsCurrentThread( winpos
->hwnd
))
2196 res
= USER_SetWindowPos( winpos
);
2198 res
= SendMessageW( winpos
->hwnd
, WM_WINE_SETWINDOWPOS
, 0, (LPARAM
)winpos
);
2200 USER_HEAP_FREE( hdwp
);
2205 /***********************************************************************
2206 * ArrangeIconicWindows (USER32.@)
2208 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
2212 INT x
, y
, xspacing
, yspacing
;
2214 GetClientRect( parent
, &rectParent
);
2215 x
= rectParent
.left
;
2216 y
= rectParent
.bottom
;
2217 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
2218 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
2220 hwndChild
= GetWindow( parent
, GW_CHILD
);
2223 if( IsIconic( hwndChild
) )
2225 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
2227 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
2228 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
2229 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
2230 if( IsWindow(hwndChild
) )
2231 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
2233 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
2236 x
= rectParent
.left
;
2240 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
2246 /***********************************************************************
2249 * Draw the frame used when moving or resizing window.
2251 static void draw_moving_frame( HDC hdc
, RECT
*rect
, BOOL thickframe
)
2255 const int width
= GetSystemMetrics(SM_CXFRAME
);
2256 const int height
= GetSystemMetrics(SM_CYFRAME
);
2258 HBRUSH hbrush
= SelectObject( hdc
, GetStockObject( GRAY_BRUSH
) );
2259 PatBlt( hdc
, rect
->left
, rect
->top
,
2260 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
2261 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
2262 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2263 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
2264 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
2265 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
2266 rect
->bottom
- rect
->top
- height
, PATINVERT
);
2267 SelectObject( hdc
, hbrush
);
2269 else DrawFocusRect( hdc
, rect
);
2273 /***********************************************************************
2276 * Initialization of a move or resize, when initiated from a menu choice.
2277 * Return hit test code for caption or sizing border.
2279 static LONG
start_size_move( HWND hwnd
, WPARAM wParam
, POINT
*capturePoint
, LONG style
)
2286 GetWindowRect( hwnd
, &rectWindow
);
2288 if ((wParam
& 0xfff0) == SC_MOVE
)
2290 /* Move pointer at the center of the caption */
2291 RECT rect
= rectWindow
;
2292 /* Note: to be exactly centered we should take the different types
2293 * of border into account, but it shouldn't make more than a few pixels
2294 * of difference so let's not bother with that */
2295 rect
.top
+= GetSystemMetrics(SM_CYBORDER
);
2296 if (style
& WS_SYSMENU
)
2297 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
2298 if (style
& WS_MINIMIZEBOX
)
2299 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2300 if (style
& WS_MAXIMIZEBOX
)
2301 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
2302 pt
.x
= (rect
.right
+ rect
.left
) / 2;
2303 pt
.y
= rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
2304 hittest
= HTCAPTION
;
2309 SetCursor( LoadCursorW( 0, (LPWSTR
)IDC_SIZEALL
) );
2313 if (!GetMessageW( &msg
, 0, 0, 0 )) return 0;
2314 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2319 pt
.x
= min( max( msg
.pt
.x
, rectWindow
.left
), rectWindow
.right
- 1 );
2320 pt
.y
= min( max( msg
.pt
.y
, rectWindow
.top
), rectWindow
.bottom
- 1 );
2321 hittest
= SendMessageW( hwnd
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
2322 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
)) hittest
= 0;
2333 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2334 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
2338 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
2339 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
2343 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
2344 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2348 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
2349 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
2357 TranslateMessage( &msg
);
2358 DispatchMessageW( &msg
);
2364 SetCursorPos( pt
.x
, pt
.y
);
2365 SendMessageW( hwnd
, WM_SETCURSOR
, (WPARAM
)hwnd
, MAKELONG( hittest
, WM_MOUSEMOVE
));
2370 /***********************************************************************
2371 * WINPOS_SysCommandSizeMove
2373 * Perform SC_MOVE and SC_SIZE commands.
2375 void WINPOS_SysCommandSizeMove( HWND hwnd
, WPARAM wParam
)
2378 RECT sizingRect
, mouseRect
, origRect
;
2381 LONG hittest
= (LONG
)(wParam
& 0x0f);
2382 WPARAM syscommand
= wParam
& 0xfff0;
2383 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
2384 POINT minTrack
, maxTrack
;
2385 POINT capturePoint
, pt
;
2386 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
2387 BOOL thickframe
= HAS_THICKFRAME( style
);
2388 BOOL iconic
= style
& WS_MINIMIZE
;
2390 DWORD dwPoint
= GetMessagePos ();
2391 BOOL DragFullWindows
= TRUE
;
2393 if (IsZoomed(hwnd
) || !IsWindowVisible(hwnd
)) return;
2395 pt
.x
= (short)LOWORD(dwPoint
);
2396 pt
.y
= (short)HIWORD(dwPoint
);
2399 TRACE("hwnd %p command %04lx, hittest %d, pos %d,%d\n",
2400 hwnd
, syscommand
, hittest
, pt
.x
, pt
.y
);
2402 if (syscommand
== SC_MOVE
)
2404 if (!hittest
) hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2405 if (!hittest
) return;
2409 if ( hittest
&& (syscommand
!= SC_MOUSEMENU
) )
2410 hittest
+= (HTLEFT
- WMSZ_LEFT
);
2413 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2414 hittest
= start_size_move( hwnd
, wParam
, &capturePoint
, style
);
2417 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2423 /* Get min/max info */
2425 WINPOS_GetMinMaxInfo( hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
2426 GetWindowRect( hwnd
, &sizingRect
);
2427 if (style
& WS_CHILD
)
2429 parent
= GetParent(hwnd
);
2430 /* make sizing rect relative to parent */
2431 MapWindowPoints( 0, parent
, (POINT
*)&sizingRect
, 2 );
2432 GetClientRect( parent
, &mouseRect
);
2437 GetClientRect( GetDesktopWindow(), &mouseRect
);
2438 mouseRect
.left
= GetSystemMetrics( SM_XVIRTUALSCREEN
);
2439 mouseRect
.top
= GetSystemMetrics( SM_YVIRTUALSCREEN
);
2440 mouseRect
.right
= mouseRect
.left
+ GetSystemMetrics( SM_CXVIRTUALSCREEN
);
2441 mouseRect
.bottom
= mouseRect
.top
+ GetSystemMetrics( SM_CYVIRTUALSCREEN
);
2443 origRect
= sizingRect
;
2445 if (ON_LEFT_BORDER(hittest
))
2447 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
2448 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
2450 else if (ON_RIGHT_BORDER(hittest
))
2452 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
2453 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
2455 if (ON_TOP_BORDER(hittest
))
2457 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
2458 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
2460 else if (ON_BOTTOM_BORDER(hittest
))
2462 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
2463 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
2465 if (parent
) MapWindowPoints( parent
, 0, (LPPOINT
)&mouseRect
, 2 );
2467 /* Retrieve a default cache DC (without using the window style) */
2468 hdc
= GetDCEx( parent
, 0, DCX_CACHE
);
2470 if( iconic
) /* create a cursor for dragging */
2472 hDragCursor
= (HCURSOR
)GetClassLongPtrW( hwnd
, GCLP_HICON
);
2473 if( !hDragCursor
) hDragCursor
= (HCURSOR
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
2474 if( !hDragCursor
) iconic
= FALSE
;
2477 /* we only allow disabling the full window drag for child windows */
2478 if (parent
) SystemParametersInfoW( SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0 );
2480 /* repaint the window before moving it around */
2481 RedrawWindow( hwnd
, NULL
, 0, RDW_UPDATENOW
| RDW_ALLCHILDREN
);
2483 SendMessageW( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
2484 set_capture_window( hwnd
, GUI_INMOVESIZE
, NULL
);
2490 if (!GetMessageW( &msg
, 0, 0, 0 )) break;
2491 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
2493 /* Exit on button-up, Return, or Esc */
2494 if ((msg
.message
== WM_LBUTTONUP
) ||
2495 ((msg
.message
== WM_KEYDOWN
) &&
2496 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
2498 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
2500 TranslateMessage( &msg
);
2501 DispatchMessageW( &msg
);
2502 continue; /* We are not interested in other messages */
2507 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
2509 case VK_UP
: pt
.y
-= 8; break;
2510 case VK_DOWN
: pt
.y
+= 8; break;
2511 case VK_LEFT
: pt
.x
-= 8; break;
2512 case VK_RIGHT
: pt
.x
+= 8; break;
2515 pt
.x
= max( pt
.x
, mouseRect
.left
);
2516 pt
.x
= min( pt
.x
, mouseRect
.right
);
2517 pt
.y
= max( pt
.y
, mouseRect
.top
);
2518 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
2520 dx
= pt
.x
- capturePoint
.x
;
2521 dy
= pt
.y
- capturePoint
.y
;
2529 if( iconic
) /* ok, no system popup tracking */
2531 hOldCursor
= SetCursor(hDragCursor
);
2533 WINPOS_ShowIconTitle( hwnd
, FALSE
);
2535 else if(!DragFullWindows
)
2536 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2539 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
2542 RECT newRect
= sizingRect
;
2543 WPARAM wpSizingHit
= 0;
2545 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
2546 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
2547 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
2548 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
2549 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
2550 if(!iconic
&& !DragFullWindows
) draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2553 /* determine the hit location */
2554 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
2555 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
2556 SendMessageW( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
2560 if(!DragFullWindows
)
2561 draw_moving_frame( hdc
, &newRect
, thickframe
);
2563 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
2564 newRect
.right
- newRect
.left
,
2565 newRect
.bottom
- newRect
.top
,
2566 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2568 sizingRect
= newRect
;
2575 if( moved
) /* restore cursors, show icon title later on */
2577 ShowCursor( FALSE
);
2578 SetCursor( hOldCursor
);
2581 else if (moved
&& !DragFullWindows
)
2583 draw_moving_frame( hdc
, &sizingRect
, thickframe
);
2586 set_capture_window( 0, GUI_INMOVESIZE
, NULL
);
2587 ReleaseDC( parent
, hdc
);
2589 if (HOOK_CallHooks( WH_CBT
, HCBT_MOVESIZE
, (WPARAM
)hwnd
, (LPARAM
)&sizingRect
, TRUE
))
2592 SendMessageW( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
2593 SendMessageW( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
2595 /* window moved or resized */
2598 /* if the moving/resizing isn't canceled call SetWindowPos
2599 * with the new position or the new size of the window
2601 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
2603 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
2604 if(!DragFullWindows
|| iconic
)
2605 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
2606 sizingRect
.right
- sizingRect
.left
,
2607 sizingRect
.bottom
- sizingRect
.top
,
2608 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2611 { /* restore previous size/position */
2613 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
2614 origRect
.right
- origRect
.left
,
2615 origRect
.bottom
- origRect
.top
,
2616 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
2622 /* Single click brings up the system menu when iconized */
2626 if(style
& WS_SYSMENU
)
2627 SendMessageW( hwnd
, WM_SYSCOMMAND
,
2628 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
2630 else WINPOS_ShowIconTitle( hwnd
, TRUE
);