2 * Window position related functions.
4 * Copyright 1993, 1994, 1995 Alexandre Julliard
5 * 1995, 1996, 1999 Alex Korobka
13 #include "wine/winuser16.h"
23 #include "nonclient.h"
24 #include "debugtools.h"
27 DEFAULT_DEBUG_CHANNEL(win
);
29 #define HAS_DLGFRAME(style,exStyle) \
30 (((exStyle) & WS_EX_DLGMODALFRAME) || \
31 (((style) & WS_DLGFRAME) && !((style) & WS_BORDER)))
33 #define HAS_THICKFRAME(style) \
34 (((style) & WS_THICKFRAME) && \
35 !(((style) & (WS_DLGFRAME|WS_BORDER)) == WS_DLGFRAME))
37 #define EMPTYPOINT(pt) ((*(LONG*)&(pt)) == -1)
39 #define PLACE_MIN 0x0001
40 #define PLACE_MAX 0x0002
41 #define PLACE_RECT 0x0004
44 #define DWP_MAGIC ((INT)('W' | ('P' << 8) | ('O' << 16) | ('S' << 24)))
56 /* ----- internal variables ----- */
58 static HWND hwndPrevActive
= 0; /* Previously active window */
59 static HWND hGlobalShellWindow
=0; /*the shell*/
60 static HWND hGlobalTaskmanWindow
=0;
61 static HWND hGlobalProgmanWindow
=0;
63 static LPCSTR atomInternalPos
;
65 extern HQUEUE16 hActiveQueue
;
67 /***********************************************************************
68 * WINPOS_CreateInternalPosAtom
70 BOOL
WINPOS_CreateInternalPosAtom()
73 atomInternalPos
= (LPCSTR
)(DWORD
)GlobalAddAtomA(str
);
74 return (atomInternalPos
) ? TRUE
: FALSE
;
77 /***********************************************************************
78 * WINPOS_CheckInternalPos
80 * Called when a window is destroyed.
82 void WINPOS_CheckInternalPos( HWND hwnd
)
85 MESSAGEQUEUE
*pMsgQ
= 0;
86 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
88 lpPos
= (LPINTERNALPOS
) GetPropA( hwnd
, atomInternalPos
);
90 /* Retrieve the message queue associated with this window */
91 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
94 WARN("\tMessage queue not found. Exiting!\n" );
95 WIN_ReleaseWndPtr( wndPtr
);
99 if( hwnd
== hwndPrevActive
) hwndPrevActive
= 0;
101 if( hwnd
== PERQDATA_GetActiveWnd( pMsgQ
->pQData
) )
103 PERQDATA_SetActiveWnd( pMsgQ
->pQData
, 0 );
104 WARN("\tattempt to activate destroyed window!\n");
109 if( IsWindow(lpPos
->hwndIconTitle
) )
110 DestroyWindow( lpPos
->hwndIconTitle
);
111 HeapFree( GetProcessHeap(), 0, lpPos
);
114 QUEUE_Unlock( pMsgQ
);
115 WIN_ReleaseWndPtr( wndPtr
);
119 /***********************************************************************
120 * ArrangeIconicWindows (USER32.@)
122 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
126 INT x
, y
, xspacing
, yspacing
;
128 GetClientRect( parent
, &rectParent
);
130 y
= rectParent
.bottom
;
131 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
132 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
134 hwndChild
= GetWindow( parent
, GW_CHILD
);
137 if( IsIconic( hwndChild
) )
139 WINPOS_ShowIconTitle( hwndChild
, FALSE
);
141 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
142 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
143 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
144 if( IsWindow(hwndChild
) )
145 WINPOS_ShowIconTitle(hwndChild
, TRUE
);
147 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
154 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
160 /***********************************************************************
161 * SwitchToThisWindow (USER32.@)
163 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
165 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
169 /***********************************************************************
170 * GetWindowRect (USER32.@)
172 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
174 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
175 if (!wndPtr
) return FALSE
;
176 *rect
= wndPtr
->rectWindow
;
177 WIN_ReleaseWndPtr(wndPtr
);
178 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
179 TRACE("hwnd %04x (%d,%d)-(%d,%d)\n",
180 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
185 /***********************************************************************
186 * GetWindowRgn (USER32.@)
188 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
191 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
194 if (wndPtr
->hrgnWnd
) nRet
= CombineRgn( hrgn
, wndPtr
->hrgnWnd
, 0, RGN_COPY
);
195 WIN_ReleaseWndPtr(wndPtr
);
200 /***********************************************************************
201 * SetWindowRgn (USER32.@)
203 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
209 if (USER_Driver
.pSetWindowRgn
)
210 return USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
212 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return FALSE
;
214 if (wndPtr
->hrgnWnd
== hrgn
)
220 if (hrgn
) /* verify that region really exists */
222 if (GetRgnBox( hrgn
, &rect
) == ERROR
) goto done
;
227 /* delete previous region */
228 DeleteObject(wndPtr
->hrgnWnd
);
231 wndPtr
->hrgnWnd
= hrgn
;
233 /* Size the window to the rectangle of the new region (if it isn't NULL) */
234 if (hrgn
) SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
235 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
236 SWP_NOSIZE
| SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOACTIVATE
|
237 SWP_NOZORDER
| (bRedraw
? 0 : SWP_NOREDRAW
) );
241 WIN_ReleaseWndPtr(wndPtr
);
246 /***********************************************************************
247 * GetClientRect (USER32.@)
249 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
251 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
253 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
254 if (!wndPtr
) return FALSE
;
255 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
256 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
258 WIN_ReleaseWndPtr(wndPtr
);
259 TRACE("hwnd %04x (%d,%d)-(%d,%d)\n",
260 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
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 * WINPOS_WindowFromPoint
288 * Find the window and hittest for a given point.
290 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
292 WND
*wndScope
, *wndPtr
, *wndTmp
;
296 TRACE("scope %04x %ld,%ld\n", hwndScope
, pt
.x
, pt
.y
);
298 if (!hwndScope
) hwndScope
= GetDesktopWindow();
299 if (!(wndScope
= WIN_FindWndPtr( hwndScope
))) return 0;
300 hwndScope
= wndScope
->hwndSelf
; /* make it a full handle */
303 wndPtr
= WIN_LockWndPtr(wndScope
->child
);
305 if( wndScope
->dwStyle
& WS_DISABLED
)
311 if (wndScope
->parent
)
312 MapWindowPoints( GetDesktopWindow(), wndScope
->parent
->hwndSelf
, &xy
, 1 );
314 if (xy
.x
< wndScope
->rectClient
.left
|| pt
.x
>= wndScope
->rectClient
.right
||
315 xy
.y
< wndScope
->rectClient
.top
|| pt
.y
>= wndScope
->rectClient
.bottom
||
316 wndScope
->dwStyle
& WS_MINIMIZE
)
319 xy
.x
-= wndScope
->rectClient
.left
;
320 xy
.y
-= wndScope
->rectClient
.top
;
326 /* If point is in window, and window is visible, and it */
327 /* is enabled (or it's a top-level window), then explore */
328 /* its children. Otherwise, go to the next window. */
330 if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
331 ((wndPtr
->dwExStyle
& (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) != (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) &&
332 (!(wndPtr
->dwStyle
& WS_DISABLED
) ||
333 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)) &&
335 PtInRegion(wndPtr
->hrgnWnd
, xy
.x
- wndPtr
->rectWindow
.left
,
336 xy
.y
- wndPtr
->rectWindow
.top
) :
337 ((xy
.x
>= wndPtr
->rectWindow
.left
) &&
338 (xy
.x
< wndPtr
->rectWindow
.right
) &&
339 (xy
.y
>= wndPtr
->rectWindow
.top
) &&
340 (xy
.y
< wndPtr
->rectWindow
.bottom
))))
342 TRACE("%ld,%ld is inside %04x\n", xy
.x
, xy
.y
, wndPtr
->hwndSelf
);
343 hwnd_ret
= wndPtr
->hwndSelf
; /* Got a suitable window */
345 /* If window is minimized or disabled, return at once */
346 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
348 *hittest
= HTCAPTION
;
351 if (wndPtr
->dwStyle
& WS_DISABLED
)
357 /* If point is not in client area, ignore the children */
358 if ((xy
.x
< wndPtr
->rectClient
.left
) ||
359 (xy
.x
>= wndPtr
->rectClient
.right
) ||
360 (xy
.y
< wndPtr
->rectClient
.top
) ||
361 (xy
.y
>= wndPtr
->rectClient
.bottom
)) break;
363 xy
.x
-= wndPtr
->rectClient
.left
;
364 xy
.y
-= wndPtr
->rectClient
.top
;
365 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->child
);
369 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
);
374 /* If nothing found, try the scope window */
375 if (!hwnd_ret
) hwnd_ret
= hwndScope
;
377 /* Send the WM_NCHITTEST message (only if to the same task) */
378 if (GetWindowThreadProcessId( hwnd_ret
, NULL
) == GetCurrentThreadId())
380 INT res
= SendMessageA( hwnd_ret
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
381 if (res
!= HTTRANSPARENT
)
383 *hittest
= res
; /* Found the window */
393 if (!(wndTmp
= WIN_FindWndPtr( hwnd_ret
))) break;
395 /* If no children found in last search, make point relative to parent */
398 xy
.x
+= wndTmp
->rectClient
.left
;
399 xy
.y
+= wndTmp
->rectClient
.top
;
402 /* Restart the search from the next sibling */
403 WIN_UpdateWndPtr(&wndPtr
,wndTmp
->next
);
404 hwnd_ret
= wndTmp
->parent
? wndTmp
->parent
->hwndSelf
: 0;
405 WIN_ReleaseWndPtr( wndTmp
);
409 WIN_ReleaseWndPtr(wndPtr
);
410 WIN_ReleaseWndPtr(wndScope
);
415 /*******************************************************************
416 * WindowFromPoint (USER32.@)
418 HWND WINAPI
WindowFromPoint( POINT pt
)
421 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
425 /*******************************************************************
426 * ChildWindowFromPoint (USER32.@)
428 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
430 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
433 /*******************************************************************
434 * ChildWindowFromPointEx (USER32.@)
436 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
438 /* pt is in the client coordinates */
444 GetClientRect( hwndParent
, &rect
);
445 if (!PtInRect( &rect
, pt
)) return 0;
446 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
448 for (i
= 0; list
[i
] && !retvalue
; i
++)
450 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
452 if (PtInRect( &wnd
->rectWindow
, pt
))
454 if ( (uFlags
& CWP_SKIPINVISIBLE
) &&
455 !(wnd
->dwStyle
& WS_VISIBLE
) );
456 else if ( (uFlags
& CWP_SKIPDISABLED
) &&
457 (wnd
->dwStyle
& WS_DISABLED
) );
458 else if ( (uFlags
& CWP_SKIPTRANSPARENT
) &&
459 (wnd
->dwExStyle
& WS_EX_TRANSPARENT
) );
460 else retvalue
= list
[i
];
462 WIN_ReleaseWndPtr( wnd
);
464 HeapFree( GetProcessHeap(), 0, list
);
465 if (!retvalue
) retvalue
= hwndParent
;
470 /*******************************************************************
471 * WINPOS_GetWinOffset
473 * Calculate the offset between the origin of the two windows. Used
474 * to implement MapWindowPoints.
476 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
,
481 offset
->x
= offset
->y
= 0;
482 if (hwndFrom
== hwndTo
) return;
484 /* Translate source window origin to screen coords */
487 if (!(wndPtr
= WIN_FindWndPtr( hwndFrom
)))
489 ERR("bad hwndFrom = %04x\n",hwndFrom
);
492 while (wndPtr
->parent
)
494 offset
->x
+= wndPtr
->rectClient
.left
;
495 offset
->y
+= wndPtr
->rectClient
.top
;
496 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
498 WIN_ReleaseWndPtr(wndPtr
);
501 /* Translate origin to destination window coords */
504 if (!(wndPtr
= WIN_FindWndPtr( hwndTo
)))
506 ERR("bad hwndTo = %04x\n", hwndTo
);
509 while (wndPtr
->parent
)
511 offset
->x
-= wndPtr
->rectClient
.left
;
512 offset
->y
-= wndPtr
->rectClient
.top
;
513 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
515 WIN_ReleaseWndPtr(wndPtr
);
520 /*******************************************************************
521 * MapWindowPoints (USER.258)
523 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
524 LPPOINT16 lppt
, UINT16 count
)
528 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
538 /*******************************************************************
539 * MapWindowPoints (USER32.@)
541 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
,
542 LPPOINT lppt
, UINT count
)
546 WINPOS_GetWinOffset( WIN_GetFullHandle(hwndFrom
), WIN_GetFullHandle(hwndTo
), &offset
);
553 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
557 /***********************************************************************
558 * IsIconic (USER32.@)
560 BOOL WINAPI
IsIconic(HWND hWnd
)
563 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
564 if (wndPtr
== NULL
) return FALSE
;
565 retvalue
= (wndPtr
->dwStyle
& WS_MINIMIZE
) != 0;
566 WIN_ReleaseWndPtr(wndPtr
);
571 /***********************************************************************
572 * IsZoomed (USER32.@)
574 BOOL WINAPI
IsZoomed(HWND hWnd
)
577 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
578 if (wndPtr
== NULL
) return FALSE
;
579 retvalue
= (wndPtr
->dwStyle
& WS_MAXIMIZE
) != 0;
580 WIN_ReleaseWndPtr(wndPtr
);
585 /*******************************************************************
586 * GetActiveWindow (USER32.@)
588 HWND WINAPI
GetActiveWindow(void)
590 MESSAGEQUEUE
*pCurMsgQ
= 0;
592 /* Get the messageQ for the current thread */
593 if (!(pCurMsgQ
= QUEUE_Current()))
595 WARN("\tCurrent message queue not found. Exiting!\n" );
599 /* Return the current active window from the perQ data of the current message Q */
600 return PERQDATA_GetActiveWnd( pCurMsgQ
->pQData
);
604 /*******************************************************************
607 static BOOL
WINPOS_CanActivate(HWND hwnd
)
609 if (!hwnd
) return FALSE
;
610 return ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_DISABLED
|WS_VISIBLE
|WS_CHILD
)) == WS_VISIBLE
);
614 /*******************************************************************
615 * SetActiveWindow (USER32.@)
617 HWND WINAPI
SetActiveWindow( HWND hwnd
)
620 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
621 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
623 if (!wndPtr
|| (wndPtr
->dwStyle
& (WS_DISABLED
| WS_CHILD
)))
629 /* Get the messageQ for the current thread */
630 if (!(pCurMsgQ
= QUEUE_Current()))
632 WARN("\tCurrent message queue not found. Exiting!\n" );
636 /* Retrieve the message queue associated with this window */
637 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
640 WARN("\tWindow message queue not found. Exiting!\n" );
644 /* Make sure that the window is associated with the calling threads
645 * message queue. It must share the same perQ data.
648 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
651 /* Save current active window */
652 prev
= PERQDATA_GetActiveWnd( pMsgQ
->pQData
);
654 WINPOS_SetActiveWindow( hwnd
, 0, 0 );
657 /* Unlock the queues before returning */
659 QUEUE_Unlock( pMsgQ
);
662 WIN_ReleaseWndPtr(wndPtr
);
667 /*******************************************************************
668 * GetForegroundWindow (USER32.@)
670 HWND WINAPI
GetForegroundWindow(void)
674 /* Get the foreground window (active window of hActiveQueue) */
677 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
679 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
681 QUEUE_Unlock( pActiveQueue
);
687 /*******************************************************************
688 * SetForegroundWindow (USER32.@)
690 BOOL WINAPI
SetForegroundWindow( HWND hwnd
)
692 return WINPOS_ChangeActiveWindow( hwnd
, FALSE
);
696 /*******************************************************************
697 * AllowSetForegroundWindow (USER32.@)
699 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
701 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
702 * implemented, then fix this function. */
707 /*******************************************************************
708 * LockSetForegroundWindow (USER32.@)
710 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
712 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
713 * implemented, then fix this function. */
718 /*******************************************************************
719 * SetShellWindow (USER32.@)
721 HWND WINAPI
SetShellWindow(HWND hwndshell
)
722 { WARN("(hWnd=%08x) semi stub\n",hwndshell
);
724 hGlobalShellWindow
= WIN_GetFullHandle( hwndshell
);
725 return hGlobalShellWindow
;
729 /*******************************************************************
730 * GetShellWindow (USER32.@)
732 HWND WINAPI
GetShellWindow(void)
733 { WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow
);
735 return hGlobalShellWindow
;
739 /***********************************************************************
740 * BringWindowToTop (USER32.@)
742 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
744 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
748 /***********************************************************************
749 * MoveWindow (USER32.@)
751 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
754 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
755 if (!repaint
) flags
|= SWP_NOREDRAW
;
756 TRACE("%04x %d,%d %dx%d %d\n",
757 hwnd
, x
, y
, cx
, cy
, repaint
);
758 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
761 /***********************************************************************
762 * WINPOS_InitInternalPos
764 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
,
767 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
771 /* this happens when the window is minimized/maximized
772 * for the first time (rectWindow is not adjusted yet) */
774 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
775 if( !lpPos
) return NULL
;
777 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
778 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
779 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
780 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
783 if( wnd
->dwStyle
& WS_MINIMIZE
)
784 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
785 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
786 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
787 else if( restoreRect
)
788 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
793 /***********************************************************************
794 * WINPOS_RedrawIconTitle
796 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
798 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
801 if( lpPos
->hwndIconTitle
)
803 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
804 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
811 /***********************************************************************
812 * WINPOS_ShowIconTitle
814 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
816 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
818 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
820 HWND title
= lpPos
->hwndIconTitle
;
822 TRACE("0x%04x %i\n", hwnd
, (bShow
!= 0) );
825 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
828 if (!IsWindowVisible(title
))
830 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
831 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
832 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
835 else ShowWindow( title
, SW_HIDE
);
840 /*******************************************************************
841 * WINPOS_GetMinMaxInfo
843 * Get the minimized and maximized information for a window.
845 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
846 POINT
*minTrack
, POINT
*maxTrack
)
851 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
852 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
854 /* Compute default values */
856 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
857 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
858 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
859 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
860 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
861 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
863 if (HAS_DLGFRAME( style
, exstyle
))
865 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
866 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
871 if (HAS_THICKFRAME(style
))
873 xinc
+= GetSystemMetrics(SM_CXFRAME
);
874 yinc
+= GetSystemMetrics(SM_CYFRAME
);
876 if (style
& WS_BORDER
)
878 xinc
+= GetSystemMetrics(SM_CXBORDER
);
879 yinc
+= GetSystemMetrics(SM_CYBORDER
);
882 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
883 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
885 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
886 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
887 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
890 MinMax
.ptMaxPosition
.x
= -xinc
;
891 MinMax
.ptMaxPosition
.y
= -yinc
;
894 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
896 /* Some sanity checks */
898 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
899 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
900 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
901 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
902 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
903 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
904 MinMax
.ptMinTrackSize
.x
);
905 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
906 MinMax
.ptMinTrackSize
.y
);
908 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
909 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
910 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
911 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
914 /***********************************************************************
915 * ShowWindowAsync (USER32.@)
917 * doesn't wait; returns immediately.
918 * used by threads to toggle windows in other (possibly hanging) threads
920 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
922 /* FIXME: does ShowWindow() return immediately ? */
923 return ShowWindow(hwnd
, cmd
);
927 /***********************************************************************
928 * ShowWindow (USER32.@)
930 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
932 return USER_Driver
.pShowWindow( hwnd
, cmd
);
936 /***********************************************************************
937 * GetInternalWindowPos (USER.460)
939 UINT16 WINAPI
GetInternalWindowPos16( HWND16 hwnd
, LPRECT16 rectWnd
,
942 WINDOWPLACEMENT16 wndpl
;
943 if (GetWindowPlacement16( hwnd
, &wndpl
))
945 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
946 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
947 return wndpl
.showCmd
;
953 /***********************************************************************
954 * GetInternalWindowPos (USER32.@)
956 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
959 WINDOWPLACEMENT wndpl
;
960 if (GetWindowPlacement( hwnd
, &wndpl
))
962 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
963 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
964 return wndpl
.showCmd
;
970 /***********************************************************************
971 * GetWindowPlacement (USER32.@)
974 * Fails if wndpl->length of Win95 (!) apps is invalid.
976 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*wndpl
)
978 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
981 if(!pWnd
) return FALSE
;
983 lpPos
= WINPOS_InitInternalPos( pWnd
, *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
984 wndpl
->length
= sizeof(*wndpl
);
985 if( pWnd
->dwStyle
& WS_MINIMIZE
)
986 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
988 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
) ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
989 if( pWnd
->flags
& WIN_RESTORE_MAX
)
990 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
993 CONV_POINT16TO32( &lpPos
->ptIconPos
, &wndpl
->ptMinPosition
);
994 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &wndpl
->ptMaxPosition
);
995 CONV_RECT16TO32( &lpPos
->rectNormal
, &wndpl
->rcNormalPosition
);
996 WIN_ReleaseWndPtr(pWnd
);
1001 /***********************************************************************
1002 * WINPOS_SetPlacement
1004 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wndpl
, UINT flags
)
1006 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
1009 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
1010 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
1012 if( flags
& PLACE_MIN
) CONV_POINT32TO16( &wndpl
->ptMinPosition
, &lpPos
->ptIconPos
);
1013 if( flags
& PLACE_MAX
) CONV_POINT32TO16( &wndpl
->ptMaxPosition
, &lpPos
->ptMaxPos
);
1014 if( flags
& PLACE_RECT
) CONV_RECT32TO16( &wndpl
->rcNormalPosition
, &lpPos
->rectNormal
);
1016 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1018 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
1019 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
1020 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
1021 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1023 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1025 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
1026 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
1027 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1029 else if( flags
& PLACE_RECT
)
1030 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
1031 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
1032 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
1033 SWP_NOZORDER
| SWP_NOACTIVATE
);
1035 ShowWindow( hwnd
, wndpl
->showCmd
);
1036 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
1038 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
1040 /* SDK: ...valid only the next time... */
1041 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
1043 WIN_ReleaseWndPtr(pWnd
);
1050 /***********************************************************************
1051 * SetWindowPlacement (USER32.@)
1054 * Fails if wndpl->length of Win95 (!) apps is invalid.
1056 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*wpl
)
1058 if (!wpl
) return FALSE
;
1059 return WINPOS_SetPlacement( hwnd
, wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1063 /***********************************************************************
1064 * AnimateWindow (USER32.@)
1065 * Shows/Hides a window with an animation
1068 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1070 FIXME("partial stub\n");
1072 /* If trying to show/hide and it's already *
1073 * shown/hidden or invalid window, fail with *
1074 * invalid parameter */
1075 if(!IsWindow(hwnd
) ||
1076 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1077 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1079 SetLastError(ERROR_INVALID_PARAMETER
);
1083 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1088 /***********************************************************************
1089 * SetInternalWindowPos (USER32.@)
1091 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1092 LPRECT rect
, LPPOINT pt
)
1094 if( IsWindow(hwnd
) )
1096 WINDOWPLACEMENT wndpl
;
1099 wndpl
.length
= sizeof(wndpl
);
1100 wndpl
.showCmd
= showCmd
;
1101 wndpl
.flags
= flags
= 0;
1106 wndpl
.flags
|= WPF_SETMINPOSITION
;
1107 wndpl
.ptMinPosition
= *pt
;
1111 flags
|= PLACE_RECT
;
1112 wndpl
.rcNormalPosition
= *rect
;
1114 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1118 /*******************************************************************
1119 * WINPOS_SetActiveWindow
1121 * SetActiveWindow() back-end. This is the only function that
1122 * can assign active status to a window. It must be called only
1123 * for the top level windows.
1125 BOOL
WINPOS_SetActiveWindow( HWND hWnd
, BOOL fMouse
, BOOL fChangeFocus
)
1127 WND
* wndPtr
=0, *wndTemp
;
1128 HQUEUE16 hOldActiveQueue
, hNewActiveQueue
;
1129 MESSAGEQUEUE
*pOldActiveQueue
= 0, *pNewActiveQueue
= 0;
1131 HWND hwndActive
= 0;
1134 TRACE("(%04x, %d, %d)\n", hWnd
, fMouse
, fChangeFocus
);
1136 /* Get current active window from the active queue */
1139 pOldActiveQueue
= QUEUE_Lock( hActiveQueue
);
1140 if ( pOldActiveQueue
)
1141 hwndActive
= PERQDATA_GetActiveWnd( pOldActiveQueue
->pQData
);
1144 if ((wndPtr
= WIN_FindWndPtr(hWnd
)))
1145 hWnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1147 /* paranoid checks */
1148 if( hWnd
== GetDesktopWindow() || (bRet
= (hWnd
== hwndActive
)) )
1151 /* if (wndPtr && (GetFastQueue16() != wndPtr->hmemTaskQ))
1154 hOldActiveQueue
= hActiveQueue
;
1156 if( (wndTemp
= WIN_FindWndPtr(hwndActive
)) )
1158 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1159 WIN_ReleaseWndPtr(wndTemp
);
1162 TRACE("no current active window.\n");
1164 /* call CBT hook chain */
1165 if (HOOK_IsHooked( WH_CBT
))
1167 CBTACTIVATESTRUCT cbt
;
1168 cbt
.fMouse
= fMouse
;
1169 cbt
.hWndActive
= hwndActive
;
1170 if (HOOK_CallHooksA( WH_CBT
, HCBT_ACTIVATE
, (WPARAM
)hWnd
, (LPARAM
)&cbt
)) goto CLEANUP_END
;
1173 /* set prev active wnd to current active wnd and send notification */
1174 if ((hwndPrevActive
= hwndActive
) && IsWindow(hwndPrevActive
))
1176 MESSAGEQUEUE
*pTempActiveQueue
= 0;
1178 if (!SendMessageA( hwndPrevActive
, WM_NCACTIVATE
, FALSE
, 0 ))
1180 if (GetSysModalWindow16() != WIN_Handle16(hWnd
)) goto CLEANUP_END
;
1181 /* disregard refusal if hWnd is sysmodal */
1184 SendMessageA( hwndPrevActive
, WM_ACTIVATE
,
1185 MAKEWPARAM( WA_INACTIVE
, wIconized
),
1188 /* check if something happened during message processing
1189 * (global active queue may have changed)
1191 pTempActiveQueue
= QUEUE_Lock( hActiveQueue
);
1192 if(!pTempActiveQueue
)
1195 hwndActive
= PERQDATA_GetActiveWnd( pTempActiveQueue
->pQData
);
1196 QUEUE_Unlock( pTempActiveQueue
);
1197 if( hwndPrevActive
!= hwndActive
)
1201 /* Set new active window in the message queue */
1205 pNewActiveQueue
= QUEUE_Lock( wndPtr
->hmemTaskQ
);
1206 if ( pNewActiveQueue
)
1207 PERQDATA_SetActiveWnd( pNewActiveQueue
->pQData
, hwndActive
);
1209 else /* have to do this or MDI frame activation goes to hell */
1210 if( pOldActiveQueue
)
1211 PERQDATA_SetActiveWnd( pOldActiveQueue
->pQData
, 0 );
1213 /* send palette messages */
1214 if (hWnd
&& SendMessageW( hWnd
, WM_QUERYNEWPALETTE
, 0, 0L))
1215 SendMessageW( HWND_BROADCAST
, WM_PALETTEISCHANGING
, (WPARAM
)hWnd
, 0 );
1217 /* if prev wnd is minimized redraw icon title */
1218 if( IsIconic( hwndPrevActive
) ) WINPOS_RedrawIconTitle(hwndPrevActive
);
1220 /* managed windows will get ConfigureNotify event */
1221 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
) && !(wndPtr
->dwExStyle
& WS_EX_MANAGED
))
1223 /* check Z-order and bring hWnd to the top */
1224 HWND tmp
= GetTopWindow(0);
1225 while (tmp
&& !(GetWindowLongA( tmp
, GWL_STYLE
) & WS_VISIBLE
))
1226 tmp
= GetWindow( tmp
, GW_HWNDNEXT
);
1229 SetWindowPos(hWnd
, HWND_TOP
, 0,0,0,0,
1230 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1231 if (!IsWindow(hWnd
))
1235 /* Get a handle to the new active queue */
1236 hNewActiveQueue
= wndPtr
? wndPtr
->hmemTaskQ
: 0;
1238 /* send WM_ACTIVATEAPP if necessary */
1239 if (hOldActiveQueue
!= hNewActiveQueue
)
1242 DWORD old_thread
= GetWindowThreadProcessId( hwndPrevActive
, NULL
);
1243 DWORD new_thread
= GetWindowThreadProcessId( hwndActive
, NULL
);
1245 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
1247 for (phwnd
= list
; *phwnd
; phwnd
++)
1249 if (!IsWindow( *phwnd
)) continue;
1250 if (GetWindowThreadProcessId( *phwnd
, NULL
) == old_thread
)
1251 SendMessageW( *phwnd
, WM_ACTIVATEAPP
, 0, new_thread
);
1253 HeapFree( GetProcessHeap(), 0, list
);
1256 hActiveQueue
= hNewActiveQueue
;
1258 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
1260 for (phwnd
= list
; *phwnd
; phwnd
++)
1262 if (!IsWindow( *phwnd
)) continue;
1263 if (GetWindowThreadProcessId( *phwnd
, NULL
) == new_thread
)
1264 SendMessageW( *phwnd
, WM_ACTIVATEAPP
, 1, old_thread
);
1266 HeapFree( GetProcessHeap(), 0, list
);
1269 if (hWnd
&& !IsWindow(hWnd
)) goto CLEANUP
;
1274 /* walk up to the first unowned window */
1275 HWND tmp
= GetAncestor( hWnd
, GA_ROOTOWNER
);
1276 wndTemp
= WIN_FindWndPtr( tmp
);
1277 /* and set last active owned popup */
1278 wndTemp
->hwndLastActive
= hWnd
;
1280 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1281 WIN_ReleaseWndPtr(wndTemp
);
1282 SendMessageA( hWnd
, WM_NCACTIVATE
, TRUE
, 0 );
1283 SendMessageA( hWnd
, WM_ACTIVATE
,
1284 MAKEWPARAM( (fMouse
) ? WA_CLICKACTIVE
: WA_ACTIVE
, wIconized
),
1285 (LPARAM
)hwndPrevActive
);
1286 if( !IsWindow(hWnd
) ) goto CLEANUP
;
1289 /* change focus if possible */
1292 if ( pNewActiveQueue
)
1294 HWND hOldFocus
= PERQDATA_GetFocusWnd( pNewActiveQueue
->pQData
);
1296 if ( hOldFocus
&& GetAncestor( hOldFocus
, GA_ROOT
) != hwndActive
)
1297 FOCUS_SwitchFocus( pNewActiveQueue
, hOldFocus
,
1298 (wndPtr
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))?
1302 if ( pOldActiveQueue
&&
1303 ( !pNewActiveQueue
||
1304 pNewActiveQueue
->pQData
!= pOldActiveQueue
->pQData
) )
1306 HWND hOldFocus
= PERQDATA_GetFocusWnd( pOldActiveQueue
->pQData
);
1308 FOCUS_SwitchFocus( pOldActiveQueue
, hOldFocus
, 0 );
1312 if( !hwndPrevActive
&& wndPtr
)
1314 if (USER_Driver
.pForceWindowRaise
) USER_Driver
.pForceWindowRaise( wndPtr
->hwndSelf
);
1317 /* if active wnd is minimized redraw icon title */
1318 if( IsIconic(hwndActive
) ) WINPOS_RedrawIconTitle(hwndActive
);
1320 bRet
= (hWnd
== hwndActive
); /* Success? */
1322 CLEANUP
: /* Unlock the message queues before returning */
1324 if ( pNewActiveQueue
)
1325 QUEUE_Unlock( pNewActiveQueue
);
1329 if ( pOldActiveQueue
)
1330 QUEUE_Unlock( pOldActiveQueue
);
1332 WIN_ReleaseWndPtr(wndPtr
);
1336 /*******************************************************************
1337 * WINPOS_ActivateOtherWindow
1339 * Activates window other than pWnd.
1341 BOOL
WINPOS_ActivateOtherWindow(HWND hwnd
)
1345 HWND hwndActive
= 0;
1349 /* Get current active window from the active queue */
1352 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
1355 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
1356 QUEUE_Unlock( pActiveQueue
);
1360 pWnd
= WIN_FindWndPtr( hwnd
);
1361 hwnd
= pWnd
->hwndSelf
;
1363 if( hwnd
== hwndPrevActive
)
1366 if( hwndActive
!= hwnd
&&
1367 ( hwndActive
|| QUEUE_IsExitingQueue(pWnd
->hmemTaskQ
)) )
1369 WIN_ReleaseWndPtr( pWnd
);
1373 owner
= GetWindow( hwnd
, GW_OWNER
);
1374 if( !(pWnd
->dwStyle
& WS_POPUP
) || !owner
||
1375 !WINPOS_CanActivate((hwndTo
= GetAncestor( owner
, GA_ROOT
))) )
1377 HWND tmp
= GetAncestor( hwnd
, GA_ROOT
);
1378 hwndTo
= hwndPrevActive
;
1380 while( !WINPOS_CanActivate(hwndTo
) )
1382 /* by now owned windows should've been taken care of */
1383 tmp
= hwndTo
= GetWindow( tmp
, GW_HWNDNEXT
);
1384 if( !hwndTo
) break;
1387 WIN_ReleaseWndPtr( pWnd
);
1389 bRet
= WINPOS_SetActiveWindow( hwndTo
, FALSE
, TRUE
);
1395 /*******************************************************************
1396 * WINPOS_ChangeActiveWindow
1399 BOOL
WINPOS_ChangeActiveWindow( HWND hWnd
, BOOL mouseMsg
)
1403 HWND hwndActive
= 0;
1405 /* Get current active window from the active queue */
1408 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
1411 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
1412 QUEUE_Unlock( pActiveQueue
);
1417 return WINPOS_SetActiveWindow( 0, mouseMsg
, TRUE
);
1419 if (!(wndPtr
= WIN_FindWndPtr(hWnd
))) return FALSE
;
1420 hWnd
= wndPtr
->hwndSelf
;
1422 /* child windows get WM_CHILDACTIVATE message */
1423 if( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1425 WIN_ReleaseWndPtr(wndPtr
);
1426 return SendMessageA(hWnd
, WM_CHILDACTIVATE
, 0, 0L);
1429 if( hWnd
== hwndActive
)
1435 if( !WINPOS_SetActiveWindow(hWnd
,mouseMsg
,TRUE
) )
1443 WIN_ReleaseWndPtr(wndPtr
);
1448 /***********************************************************************
1449 * WINPOS_SendNCCalcSize
1451 * Send a WM_NCCALCSIZE message to a window.
1452 * All parameters are read-only except newClientRect.
1453 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1454 * when calcValidRect is TRUE.
1456 LONG
WINPOS_SendNCCalcSize( HWND hwnd
, BOOL calcValidRect
,
1457 RECT
*newWindowRect
, RECT
*oldWindowRect
,
1458 RECT
*oldClientRect
, WINDOWPOS
*winpos
,
1459 RECT
*newClientRect
)
1461 NCCALCSIZE_PARAMS params
;
1462 WINDOWPOS winposCopy
;
1465 params
.rgrc
[0] = *newWindowRect
;
1468 winposCopy
= *winpos
;
1469 params
.rgrc
[1] = *oldWindowRect
;
1470 params
.rgrc
[2] = *oldClientRect
;
1471 params
.lppos
= &winposCopy
;
1473 result
= SendMessageA( hwnd
, WM_NCCALCSIZE
, calcValidRect
,
1475 TRACE("%d,%d-%d,%d\n",
1476 params
.rgrc
[0].left
, params
.rgrc
[0].top
,
1477 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
1479 /* If the application send back garbage, ignore it */
1480 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&& params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
1481 *newClientRect
= params
.rgrc
[0];
1487 /***********************************************************************
1488 * WINPOS_HandleWindowPosChanging16
1490 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1492 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1494 POINT maxSize
, minTrack
;
1495 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1497 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1498 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1500 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1501 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1502 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1503 if (!(style
& WS_MINIMIZE
))
1505 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1506 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1513 /***********************************************************************
1514 * WINPOS_HandleWindowPosChanging
1516 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1518 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1520 POINT maxSize
, minTrack
;
1521 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1523 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1524 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1526 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1527 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1528 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1529 if (!(style
& WS_MINIMIZE
))
1531 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1532 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1539 /***********************************************************************
1540 * SetWindowPos (USER32.@)
1542 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1543 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1548 winpos
.hwndInsertAfter
= hwndInsertAfter
;
1553 winpos
.flags
= flags
;
1554 return USER_Driver
.pSetWindowPos( &winpos
);
1558 /***********************************************************************
1559 * BeginDeferWindowPos (USER32.@)
1561 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1568 SetLastError(ERROR_INVALID_PARAMETER
);
1571 /* Windows allows zero count, in which case it allocates context for 8 moves */
1572 if (count
== 0) count
= 8;
1574 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1575 if (!handle
) return 0;
1576 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1577 pDWP
->actualCount
= 0;
1578 pDWP
->suggestedCount
= count
;
1580 pDWP
->wMagic
= DWP_MAGIC
;
1581 pDWP
->hwndParent
= 0;
1586 /***********************************************************************
1587 * DeferWindowPos (USER32.@)
1589 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1590 INT x
, INT y
, INT cx
, INT cy
,
1595 HDWP newhdwp
= hdwp
,retvalue
;
1599 hwnd
= WIN_GetFullHandle( hwnd
);
1600 if (hwnd
== GetDesktopWindow()) return 0;
1602 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1604 if (!(pWnd
= WIN_FindWndPtr( hwnd
))) return 0;
1606 /* Numega Bounds Checker Demo dislikes the following code.
1607 In fact, I've not been able to find any "same parent" requirement in any docu
1611 /* All the windows of a DeferWindowPos() must have the same parent */
1612 parent
= pWnd
->parent
->hwndSelf
;
1613 if (pDWP
->actualCount
== 0) pDWP
->hwndParent
= parent
;
1614 else if (parent
!= pDWP
->hwndParent
)
1616 USER_HEAP_FREE( hdwp
);
1622 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1624 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1626 /* Merge with the other changes */
1627 if (!(flags
& SWP_NOZORDER
))
1629 pDWP
->winPos
[i
].hwndInsertAfter
= hwndAfter
;
1631 if (!(flags
& SWP_NOMOVE
))
1633 pDWP
->winPos
[i
].x
= x
;
1634 pDWP
->winPos
[i
].y
= y
;
1636 if (!(flags
& SWP_NOSIZE
))
1638 pDWP
->winPos
[i
].cx
= cx
;
1639 pDWP
->winPos
[i
].cy
= cy
;
1641 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1642 SWP_NOZORDER
| SWP_NOREDRAW
|
1643 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1645 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1651 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1653 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1654 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1660 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1661 pDWP
->suggestedCount
++;
1663 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1664 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1665 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1666 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1667 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1668 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1669 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1670 pDWP
->actualCount
++;
1673 WIN_ReleaseWndPtr(pWnd
);
1678 /***********************************************************************
1679 * EndDeferWindowPos (USER32.@)
1681 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
1688 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1689 if (!pDWP
) return FALSE
;
1690 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
1692 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
1694 USER_HEAP_FREE( hdwp
);
1699 /***********************************************************************
1700 * TileChildWindows (USER.199)
1702 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
1704 FIXME("(%04x, %d): stub\n", parent
, action
);
1707 /***********************************************************************
1708 * CascadeChildWindows (USER.198)
1710 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
1712 FIXME("(%04x, %d): stub\n", parent
, action
);
1715 /***********************************************************************
1716 * SetProgmanWindow (USER32.@)
1718 HWND WINAPI
SetProgmanWindow ( HWND hwnd
)
1720 hGlobalProgmanWindow
= hwnd
;
1721 return hGlobalProgmanWindow
;
1724 /***********************************************************************
1725 * GetProgmanWindow (USER32.@)
1727 HWND WINAPI
GetProgmanWindow(void)
1729 return hGlobalProgmanWindow
;
1732 /***********************************************************************
1733 * SetShellWindowEx (USER32.@)
1734 * hwndProgman = Progman[Program Manager]
1735 * |-> SHELLDLL_DefView
1736 * hwndListView = | |-> SysListView32
1737 * | | |-> tooltips_class32
1743 HWND WINAPI
SetShellWindowEx ( HWND hwndProgman
, HWND hwndListView
)
1745 FIXME("0x%08x 0x%08x stub\n",hwndProgman
,hwndListView
);
1746 hGlobalShellWindow
= hwndProgman
;
1747 return hGlobalShellWindow
;
1751 /***********************************************************************
1752 * SetTaskmanWindow (USER32.@)
1754 * hwnd = MSTaskSwWClass
1755 * |-> SysTabControl32
1757 HWND WINAPI
SetTaskmanWindow ( HWND hwnd
)
1759 hGlobalTaskmanWindow
= hwnd
;
1760 return hGlobalTaskmanWindow
;
1763 /***********************************************************************
1764 * GetTaskmanWindow (USER32.@)
1766 HWND WINAPI
GetTaskmanWindow(void)
1768 return hGlobalTaskmanWindow
;