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( WND
* wndPtr
)
85 MESSAGEQUEUE
*pMsgQ
= 0;
86 HWND hwnd
= wndPtr
->hwndSelf
;
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" );
98 if( hwnd
== hwndPrevActive
) hwndPrevActive
= 0;
100 if( hwnd
== PERQDATA_GetActiveWnd( pMsgQ
->pQData
) )
102 PERQDATA_SetActiveWnd( pMsgQ
->pQData
, 0 );
103 WARN("\tattempt to activate destroyed window!\n");
108 if( IsWindow(lpPos
->hwndIconTitle
) )
109 DestroyWindow( lpPos
->hwndIconTitle
);
110 HeapFree( GetProcessHeap(), 0, lpPos
);
113 QUEUE_Unlock( pMsgQ
);
117 /***********************************************************************
118 * ArrangeIconicWindows (USER.170)
120 UINT16 WINAPI
ArrangeIconicWindows16( HWND16 parent
)
122 return ArrangeIconicWindows(parent
);
124 /***********************************************************************
125 * ArrangeIconicWindows (USER32.@)
127 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
131 INT x
, y
, xspacing
, yspacing
;
133 GetClientRect( parent
, &rectParent
);
135 y
= rectParent
.bottom
;
136 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
137 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
139 hwndChild
= GetWindow( parent
, GW_CHILD
);
142 if( IsIconic( hwndChild
) )
144 WND
*wndPtr
= WIN_FindWndPtr(hwndChild
);
146 WINPOS_ShowIconTitle( wndPtr
, FALSE
);
148 SetWindowPos( hwndChild
, 0, x
+ (xspacing
- GetSystemMetrics(SM_CXICON
)) / 2,
149 y
- yspacing
- GetSystemMetrics(SM_CYICON
)/2, 0, 0,
150 SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
151 if( IsWindow(hwndChild
) )
152 WINPOS_ShowIconTitle(wndPtr
, TRUE
);
153 WIN_ReleaseWndPtr(wndPtr
);
155 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
162 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
168 /***********************************************************************
169 * SwitchToThisWindow (USER.172)
171 void WINAPI
SwitchToThisWindow16( HWND16 hwnd
, BOOL16 restore
)
173 SwitchToThisWindow( hwnd
, restore
);
177 /***********************************************************************
178 * SwitchToThisWindow (USER32.@)
180 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
182 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
186 /***********************************************************************
187 * GetWindowRect (USER.32)
189 void WINAPI
GetWindowRect16( HWND16 hwnd
, LPRECT16 rect
)
191 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
194 CONV_RECT32TO16( &wndPtr
->rectWindow
, rect
);
196 MapWindowPoints16( wndPtr
->parent
->hwndSelf
, 0, (POINT16
*)rect
, 2 );
197 WIN_ReleaseWndPtr(wndPtr
);
201 /***********************************************************************
202 * GetWindowRect (USER32.@)
204 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
206 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
207 if (!wndPtr
) return FALSE
;
209 *rect
= wndPtr
->rectWindow
;
211 MapWindowPoints( wndPtr
->parent
->hwndSelf
, 0, (POINT
*)rect
, 2 );
212 WIN_ReleaseWndPtr(wndPtr
);
213 TRACE("hwnd %04x (%d,%d)-(%d,%d)\n",
214 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
219 /***********************************************************************
220 * GetWindowRgn (USER32.@)
222 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
225 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
228 if (wndPtr
->hrgnWnd
) nRet
= CombineRgn( hrgn
, wndPtr
->hrgnWnd
, 0, RGN_COPY
);
229 WIN_ReleaseWndPtr(wndPtr
);
234 /***********************************************************************
235 * SetWindowRgn (USER32.@)
237 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
243 if (USER_Driver
.pSetWindowRgn
)
244 return USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
246 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return FALSE
;
248 if (wndPtr
->hrgnWnd
== hrgn
)
254 if (hrgn
) /* verify that region really exists */
256 if (GetRgnBox( hrgn
, &rect
) == ERROR
) goto done
;
261 /* delete previous region */
262 DeleteObject(wndPtr
->hrgnWnd
);
265 wndPtr
->hrgnWnd
= hrgn
;
267 /* Size the window to the rectangle of the new region (if it isn't NULL) */
268 if (hrgn
) SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
269 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
270 SWP_NOSIZE
| SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOACTIVATE
|
271 SWP_NOZORDER
| (bRedraw
? 0 : SWP_NOREDRAW
) );
275 WIN_ReleaseWndPtr(wndPtr
);
279 /***********************************************************************
280 * SetWindowRgn (USER.668)
282 INT16 WINAPI
SetWindowRgn16( HWND16 hwnd
, HRGN16 hrgn
,BOOL16 bRedraw
)
286 FIXME("SetWindowRgn16: stub\n");
291 /***********************************************************************
292 * GetClientRect (USER.33)
294 void WINAPI
GetClientRect16( HWND16 hwnd
, LPRECT16 rect
)
296 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
298 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
301 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
302 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
304 WIN_ReleaseWndPtr(wndPtr
);
308 /***********************************************************************
309 * GetClientRect (USER32.@)
311 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
313 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
315 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
316 if (!wndPtr
) return FALSE
;
317 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
318 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
320 WIN_ReleaseWndPtr(wndPtr
);
321 TRACE("hwnd %04x (%d,%d)-(%d,%d)\n",
322 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
327 /*******************************************************************
328 * ClientToScreen (USER.28)
330 void WINAPI
ClientToScreen16( HWND16 hwnd
, LPPOINT16 lppnt
)
332 MapWindowPoints16( hwnd
, 0, lppnt
, 1 );
336 /*******************************************************************
337 * ClientToScreen (USER32.@)
339 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
341 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
346 /*******************************************************************
347 * ScreenToClient (USER.29)
349 void WINAPI
ScreenToClient16( HWND16 hwnd
, LPPOINT16 lppnt
)
351 MapWindowPoints16( 0, hwnd
, lppnt
, 1 );
355 /*******************************************************************
356 * ScreenToClient (USER32.@)
358 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
360 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
365 /***********************************************************************
366 * WINPOS_WindowFromPoint
368 * Find the window and hittest for a given point.
370 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
372 WND
*wndScope
, *wndPtr
, *wndTmp
;
376 TRACE("scope %04x %ld,%ld\n", hwndScope
, pt
.x
, pt
.y
);
378 if (!hwndScope
) hwndScope
= GetDesktopWindow();
379 if (!(wndScope
= WIN_FindWndPtr( hwndScope
))) return 0;
382 wndPtr
= WIN_LockWndPtr(wndScope
->child
);
384 if( wndScope
->dwStyle
& WS_DISABLED
)
390 if (wndScope
->parent
)
391 MapWindowPoints( GetDesktopWindow(), wndScope
->parent
->hwndSelf
, &xy
, 1 );
393 if (xy
.x
< wndScope
->rectClient
.left
|| pt
.x
>= wndScope
->rectClient
.right
||
394 xy
.y
< wndScope
->rectClient
.top
|| pt
.y
>= wndScope
->rectClient
.bottom
||
395 wndScope
->dwStyle
& WS_MINIMIZE
)
398 xy
.x
-= wndScope
->rectClient
.left
;
399 xy
.y
-= wndScope
->rectClient
.top
;
405 /* If point is in window, and window is visible, and it */
406 /* is enabled (or it's a top-level window), then explore */
407 /* its children. Otherwise, go to the next window. */
409 if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
410 ((wndPtr
->dwExStyle
& (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) != (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) &&
411 (!(wndPtr
->dwStyle
& WS_DISABLED
) ||
412 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)) &&
414 PtInRegion(wndPtr
->hrgnWnd
, xy
.x
- wndPtr
->rectWindow
.left
,
415 xy
.y
- wndPtr
->rectWindow
.top
) :
416 ((xy
.x
>= wndPtr
->rectWindow
.left
) &&
417 (xy
.x
< wndPtr
->rectWindow
.right
) &&
418 (xy
.y
>= wndPtr
->rectWindow
.top
) &&
419 (xy
.y
< wndPtr
->rectWindow
.bottom
))))
421 TRACE("%ld,%ld is inside %04x\n", xy
.x
, xy
.y
, wndPtr
->hwndSelf
);
422 hwnd_ret
= wndPtr
->hwndSelf
; /* Got a suitable window */
424 /* If window is minimized or disabled, return at once */
425 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
427 *hittest
= HTCAPTION
;
430 if (wndPtr
->dwStyle
& WS_DISABLED
)
436 /* If point is not in client area, ignore the children */
437 if ((xy
.x
< wndPtr
->rectClient
.left
) ||
438 (xy
.x
>= wndPtr
->rectClient
.right
) ||
439 (xy
.y
< wndPtr
->rectClient
.top
) ||
440 (xy
.y
>= wndPtr
->rectClient
.bottom
)) break;
442 xy
.x
-= wndPtr
->rectClient
.left
;
443 xy
.y
-= wndPtr
->rectClient
.top
;
444 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->child
);
448 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
);
453 /* If nothing found, try the scope window */
454 if (!hwnd_ret
) hwnd_ret
= hwndScope
;
456 /* Send the WM_NCHITTEST message (only if to the same task) */
457 if (GetWindowThreadProcessId( hwnd_ret
, NULL
) == GetCurrentThreadId())
459 INT res
= SendMessageA( hwnd_ret
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
460 if (res
!= HTTRANSPARENT
)
462 *hittest
= res
; /* Found the window */
472 if (!(wndTmp
= WIN_FindWndPtr( hwnd_ret
))) break;
474 /* If no children found in last search, make point relative to parent */
477 xy
.x
+= wndTmp
->rectClient
.left
;
478 xy
.y
+= wndTmp
->rectClient
.top
;
481 /* Restart the search from the next sibling */
482 WIN_UpdateWndPtr(&wndPtr
,wndTmp
->next
);
483 hwnd_ret
= wndTmp
->parent
? wndTmp
->parent
->hwndSelf
: 0;
484 WIN_ReleaseWndPtr( wndTmp
);
488 WIN_ReleaseWndPtr(wndPtr
);
489 WIN_ReleaseWndPtr(wndScope
);
494 /*******************************************************************
495 * WindowFromPoint (USER.30)
497 HWND16 WINAPI
WindowFromPoint16( POINT16 pt
)
501 CONV_POINT16TO32( &pt
, &pt32
);
502 return WindowFromPoint( pt32
);
506 /*******************************************************************
507 * WindowFromPoint (USER32.@)
509 HWND WINAPI
WindowFromPoint( POINT pt
)
512 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
516 /*******************************************************************
517 * ChildWindowFromPoint (USER.191)
519 HWND16 WINAPI
ChildWindowFromPoint16( HWND16 hwndParent
, POINT16 pt
)
522 CONV_POINT16TO32( &pt
, &pt32
);
523 return (HWND16
)ChildWindowFromPoint( hwndParent
, pt32
);
527 /*******************************************************************
528 * ChildWindowFromPoint (USER32.@)
530 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
532 /* pt is in the client coordinates */
534 WND
* wnd
= WIN_FindWndPtr(hwndParent
);
540 /* get client rect fast */
541 rect
.top
= rect
.left
= 0;
542 rect
.right
= wnd
->rectClient
.right
- wnd
->rectClient
.left
;
543 rect
.bottom
= wnd
->rectClient
.bottom
- wnd
->rectClient
.top
;
545 if (!PtInRect( &rect
, pt
))
550 WIN_UpdateWndPtr(&wnd
,wnd
->child
);
553 if (PtInRect( &wnd
->rectWindow
, pt
))
555 retvalue
= wnd
->hwndSelf
;
558 WIN_UpdateWndPtr(&wnd
,wnd
->next
);
560 retvalue
= hwndParent
;
562 WIN_ReleaseWndPtr(wnd
);
566 /*******************************************************************
567 * ChildWindowFromPointEx (USER.399)
569 HWND16 WINAPI
ChildWindowFromPointEx16( HWND16 hwndParent
, POINT16 pt
, UINT16 uFlags
)
572 CONV_POINT16TO32( &pt
, &pt32
);
573 return (HWND16
)ChildWindowFromPointEx( hwndParent
, pt32
, uFlags
);
577 /*******************************************************************
578 * ChildWindowFromPointEx (USER32.@)
580 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
,
583 /* pt is in the client coordinates */
585 WND
* wnd
= WIN_FindWndPtr(hwndParent
);
591 /* get client rect fast */
592 rect
.top
= rect
.left
= 0;
593 rect
.right
= wnd
->rectClient
.right
- wnd
->rectClient
.left
;
594 rect
.bottom
= wnd
->rectClient
.bottom
- wnd
->rectClient
.top
;
596 if (!PtInRect( &rect
, pt
))
601 WIN_UpdateWndPtr(&wnd
,wnd
->child
);
605 if (PtInRect( &wnd
->rectWindow
, pt
)) {
606 if ( (uFlags
& CWP_SKIPINVISIBLE
) &&
607 !(wnd
->dwStyle
& WS_VISIBLE
) );
608 else if ( (uFlags
& CWP_SKIPDISABLED
) &&
609 (wnd
->dwStyle
& WS_DISABLED
) );
610 else if ( (uFlags
& CWP_SKIPTRANSPARENT
) &&
611 (wnd
->dwExStyle
& WS_EX_TRANSPARENT
) );
614 retvalue
= wnd
->hwndSelf
;
619 WIN_UpdateWndPtr(&wnd
,wnd
->next
);
621 retvalue
= hwndParent
;
623 WIN_ReleaseWndPtr(wnd
);
628 /*******************************************************************
629 * WINPOS_GetWinOffset
631 * Calculate the offset between the origin of the two windows. Used
632 * to implement MapWindowPoints.
634 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
,
639 offset
->x
= offset
->y
= 0;
640 if (hwndFrom
== hwndTo
) return;
642 /* Translate source window origin to screen coords */
645 if (!(wndPtr
= WIN_FindWndPtr( hwndFrom
)))
647 ERR("bad hwndFrom = %04x\n",hwndFrom
);
650 while (wndPtr
->parent
)
652 offset
->x
+= wndPtr
->rectClient
.left
;
653 offset
->y
+= wndPtr
->rectClient
.top
;
654 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
656 WIN_ReleaseWndPtr(wndPtr
);
659 /* Translate origin to destination window coords */
662 if (!(wndPtr
= WIN_FindWndPtr( hwndTo
)))
664 ERR("bad hwndTo = %04x\n", hwndTo
);
667 while (wndPtr
->parent
)
669 offset
->x
-= wndPtr
->rectClient
.left
;
670 offset
->y
-= wndPtr
->rectClient
.top
;
671 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
673 WIN_ReleaseWndPtr(wndPtr
);
678 /*******************************************************************
679 * MapWindowPoints (USER.258)
681 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
682 LPPOINT16 lppt
, UINT16 count
)
686 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
696 /*******************************************************************
697 * MapWindowPoints (USER32.@)
699 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
,
700 LPPOINT lppt
, UINT count
)
704 WINPOS_GetWinOffset( hwndFrom
, hwndTo
, &offset
);
711 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
715 /***********************************************************************
718 BOOL16 WINAPI
IsIconic16(HWND16 hWnd
)
720 return IsIconic(hWnd
);
724 /***********************************************************************
725 * IsIconic (USER32.@)
727 BOOL WINAPI
IsIconic(HWND hWnd
)
730 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
731 if (wndPtr
== NULL
) return FALSE
;
732 retvalue
= (wndPtr
->dwStyle
& WS_MINIMIZE
) != 0;
733 WIN_ReleaseWndPtr(wndPtr
);
738 /***********************************************************************
739 * IsZoomed (USER.272)
741 BOOL16 WINAPI
IsZoomed16(HWND16 hWnd
)
743 return IsZoomed(hWnd
);
747 /***********************************************************************
748 * IsZoomed (USER32.@)
750 BOOL WINAPI
IsZoomed(HWND hWnd
)
753 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
754 if (wndPtr
== NULL
) return FALSE
;
755 retvalue
= (wndPtr
->dwStyle
& WS_MAXIMIZE
) != 0;
756 WIN_ReleaseWndPtr(wndPtr
);
761 /*******************************************************************
762 * GetActiveWindow (USER.60)
764 HWND16 WINAPI
GetActiveWindow16(void)
766 return (HWND16
)GetActiveWindow();
769 /*******************************************************************
770 * GetActiveWindow (USER32.@)
772 HWND WINAPI
GetActiveWindow(void)
774 MESSAGEQUEUE
*pCurMsgQ
= 0;
776 /* Get the messageQ for the current thread */
777 if (!(pCurMsgQ
= QUEUE_Current()))
779 WARN("\tCurrent message queue not found. Exiting!\n" );
783 /* Return the current active window from the perQ data of the current message Q */
784 return PERQDATA_GetActiveWnd( pCurMsgQ
->pQData
);
788 /*******************************************************************
791 static BOOL
WINPOS_CanActivate(WND
* pWnd
)
793 if( pWnd
&& ( (pWnd
->dwStyle
& (WS_DISABLED
| WS_VISIBLE
| WS_CHILD
))
794 == WS_VISIBLE
) ) return TRUE
;
799 /*******************************************************************
800 * SetActiveWindow (USER.59)
802 HWND16 WINAPI
SetActiveWindow16( HWND16 hwnd
)
804 return SetActiveWindow(hwnd
);
808 /*******************************************************************
809 * SetActiveWindow (USER32.@)
811 HWND WINAPI
SetActiveWindow( HWND hwnd
)
814 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
815 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
817 if (!wndPtr
|| (wndPtr
->dwStyle
& (WS_DISABLED
| WS_CHILD
)))
823 /* Get the messageQ for the current thread */
824 if (!(pCurMsgQ
= QUEUE_Current()))
826 WARN("\tCurrent message queue not found. Exiting!\n" );
830 /* Retrieve the message queue associated with this window */
831 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
834 WARN("\tWindow message queue not found. Exiting!\n" );
838 /* Make sure that the window is associated with the calling threads
839 * message queue. It must share the same perQ data.
842 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
845 /* Save current active window */
846 prev
= PERQDATA_GetActiveWnd( pMsgQ
->pQData
);
848 WINPOS_SetActiveWindow( hwnd
, 0, 0 );
851 /* Unlock the queues before returning */
853 QUEUE_Unlock( pMsgQ
);
856 WIN_ReleaseWndPtr(wndPtr
);
861 /*******************************************************************
862 * GetForegroundWindow (USER.608)
864 HWND16 WINAPI
GetForegroundWindow16(void)
866 return (HWND16
)GetForegroundWindow();
870 /*******************************************************************
871 * SetForegroundWindow (USER.609)
873 BOOL16 WINAPI
SetForegroundWindow16( HWND16 hwnd
)
875 return SetForegroundWindow( hwnd
);
879 /*******************************************************************
880 * GetForegroundWindow (USER32.@)
882 HWND WINAPI
GetForegroundWindow(void)
886 /* Get the foreground window (active window of hActiveQueue) */
889 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
891 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
893 QUEUE_Unlock( pActiveQueue
);
899 /*******************************************************************
900 * SetForegroundWindow (USER32.@)
902 BOOL WINAPI
SetForegroundWindow( HWND hwnd
)
904 return WINPOS_ChangeActiveWindow( hwnd
, FALSE
);
908 /*******************************************************************
909 * AllowSetForegroundWindow (USER32.@)
911 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
913 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
914 * implemented, then fix this function. */
919 /*******************************************************************
920 * LockSetForegroundWindow (USER32.@)
922 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
924 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
925 * implemented, then fix this function. */
930 /*******************************************************************
931 * GetShellWindow (USER.600)
933 HWND16 WINAPI
GetShellWindow16(void)
935 return GetShellWindow();
938 /*******************************************************************
939 * SetShellWindow (USER32.@)
941 HWND WINAPI
SetShellWindow(HWND hwndshell
)
942 { WARN("(hWnd=%08x) semi stub\n",hwndshell
);
944 hGlobalShellWindow
= hwndshell
;
945 return hGlobalShellWindow
;
949 /*******************************************************************
950 * GetShellWindow (USER32.@)
952 HWND WINAPI
GetShellWindow(void)
953 { WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow
);
955 return hGlobalShellWindow
;
959 /***********************************************************************
960 * BringWindowToTop (USER.45)
962 BOOL16 WINAPI
BringWindowToTop16( HWND16 hwnd
)
964 return BringWindowToTop(hwnd
);
968 /***********************************************************************
969 * BringWindowToTop (USER32.@)
971 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
973 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
977 /***********************************************************************
978 * MoveWindow (USER.56)
980 BOOL16 WINAPI
MoveWindow16( HWND16 hwnd
, INT16 x
, INT16 y
, INT16 cx
, INT16 cy
,
983 return MoveWindow(hwnd
,x
,y
,cx
,cy
,repaint
);
987 /***********************************************************************
988 * MoveWindow (USER32.@)
990 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
993 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
994 if (!repaint
) flags
|= SWP_NOREDRAW
;
995 TRACE("%04x %d,%d %dx%d %d\n",
996 hwnd
, x
, y
, cx
, cy
, repaint
);
997 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
1000 /***********************************************************************
1001 * WINPOS_InitInternalPos
1003 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
,
1004 LPRECT restoreRect
)
1006 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
1010 /* this happens when the window is minimized/maximized
1011 * for the first time (rectWindow is not adjusted yet) */
1013 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
1014 if( !lpPos
) return NULL
;
1016 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
1017 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
1018 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
1019 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
1022 if( wnd
->dwStyle
& WS_MINIMIZE
)
1023 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
1024 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
1025 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
1026 else if( restoreRect
)
1027 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
1032 /***********************************************************************
1033 * WINPOS_RedrawIconTitle
1035 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
1037 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
1040 if( lpPos
->hwndIconTitle
)
1042 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
1043 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
1050 /***********************************************************************
1051 * WINPOS_ShowIconTitle
1053 BOOL
WINPOS_ShowIconTitle( WND
* pWnd
, BOOL bShow
)
1055 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( pWnd
->hwndSelf
, atomInternalPos
);
1057 if( lpPos
&& !(pWnd
->dwExStyle
& WS_EX_MANAGED
))
1059 HWND16 hWnd
= lpPos
->hwndIconTitle
;
1061 TRACE("0x%04x %i\n", pWnd
->hwndSelf
, (bShow
!= 0) );
1064 lpPos
->hwndIconTitle
= hWnd
= ICONTITLE_Create( pWnd
);
1067 if( ( pWnd
= WIN_FindWndPtr(hWnd
) ) != NULL
)
1069 if( !(pWnd
->dwStyle
& WS_VISIBLE
) )
1071 SendMessageA( hWnd
, WM_SHOWWINDOW
, TRUE
, 0 );
1072 SetWindowPos( hWnd
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
1073 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
1075 WIN_ReleaseWndPtr(pWnd
);
1078 else ShowWindow( hWnd
, SW_HIDE
);
1083 /*******************************************************************
1084 * WINPOS_GetMinMaxInfo
1086 * Get the minimized and maximized information for a window.
1088 void WINPOS_GetMinMaxInfo( WND
*wndPtr
, POINT
*maxSize
, POINT
*maxPos
,
1089 POINT
*minTrack
, POINT
*maxTrack
)
1091 LPINTERNALPOS lpPos
;
1095 /* Compute default values */
1097 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
1098 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
1099 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
1100 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
1101 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
1102 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
1104 if (HAS_DLGFRAME( wndPtr
->dwStyle
, wndPtr
->dwExStyle
))
1106 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
1107 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
1112 if (HAS_THICKFRAME(wndPtr
->dwStyle
))
1114 xinc
+= GetSystemMetrics(SM_CXFRAME
);
1115 yinc
+= GetSystemMetrics(SM_CYFRAME
);
1117 if (wndPtr
->dwStyle
& WS_BORDER
)
1119 xinc
+= GetSystemMetrics(SM_CXBORDER
);
1120 yinc
+= GetSystemMetrics(SM_CYBORDER
);
1123 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
1124 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
1126 lpPos
= (LPINTERNALPOS
)GetPropA( wndPtr
->hwndSelf
, atomInternalPos
);
1127 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
1128 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
1131 MinMax
.ptMaxPosition
.x
= -xinc
;
1132 MinMax
.ptMaxPosition
.y
= -yinc
;
1135 SendMessageA( wndPtr
->hwndSelf
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
1137 /* Some sanity checks */
1139 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
1140 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
1141 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
1142 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
1143 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
1144 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
1145 MinMax
.ptMinTrackSize
.x
);
1146 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
1147 MinMax
.ptMinTrackSize
.y
);
1149 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
1150 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
1151 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
1152 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
1155 /***********************************************************************
1156 * ShowWindowAsync (USER32.@)
1158 * doesn't wait; returns immediately.
1159 * used by threads to toggle windows in other (possibly hanging) threads
1161 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1163 /* FIXME: does ShowWindow() return immediately ? */
1164 return ShowWindow(hwnd
, cmd
);
1168 /***********************************************************************
1169 * ShowWindow (USER.42)
1171 BOOL16 WINAPI
ShowWindow16( HWND16 hwnd
, INT16 cmd
)
1173 return ShowWindow(hwnd
,cmd
);
1177 /***********************************************************************
1178 * ShowWindow (USER32.@)
1180 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1182 return USER_Driver
.pShowWindow( hwnd
, cmd
);
1186 /***********************************************************************
1187 * GetInternalWindowPos (USER.460)
1189 UINT16 WINAPI
GetInternalWindowPos16( HWND16 hwnd
, LPRECT16 rectWnd
,
1192 WINDOWPLACEMENT16 wndpl
;
1193 if (GetWindowPlacement16( hwnd
, &wndpl
))
1195 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1196 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1197 return wndpl
.showCmd
;
1203 /***********************************************************************
1204 * GetInternalWindowPos (USER32.@)
1206 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1209 WINDOWPLACEMENT wndpl
;
1210 if (GetWindowPlacement( hwnd
, &wndpl
))
1212 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1213 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1214 return wndpl
.showCmd
;
1219 /***********************************************************************
1220 * GetWindowPlacement (USER.370)
1222 BOOL16 WINAPI
GetWindowPlacement16( HWND16 hwnd
, WINDOWPLACEMENT16
*wndpl
)
1224 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
1225 LPINTERNALPOS lpPos
;
1227 if(!pWnd
) return FALSE
;
1229 lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
1230 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
1231 wndpl
->length
= sizeof(*wndpl
);
1232 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1233 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1235 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
)
1236 ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1237 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1238 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1241 wndpl
->ptMinPosition
= lpPos
->ptIconPos
;
1242 wndpl
->ptMaxPosition
= lpPos
->ptMaxPos
;
1243 wndpl
->rcNormalPosition
= lpPos
->rectNormal
;
1245 WIN_ReleaseWndPtr(pWnd
);
1250 /***********************************************************************
1251 * GetWindowPlacement (USER32.@)
1254 * Fails if wndpl->length of Win95 (!) apps is invalid.
1256 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*pwpl32
)
1260 WINDOWPLACEMENT16 wpl
;
1261 wpl
.length
= sizeof(wpl
);
1262 if( GetWindowPlacement16( hwnd
, &wpl
) )
1264 pwpl32
->length
= sizeof(*pwpl32
);
1265 pwpl32
->flags
= wpl
.flags
;
1266 pwpl32
->showCmd
= wpl
.showCmd
;
1267 CONV_POINT16TO32( &wpl
.ptMinPosition
, &pwpl32
->ptMinPosition
);
1268 CONV_POINT16TO32( &wpl
.ptMaxPosition
, &pwpl32
->ptMaxPosition
);
1269 CONV_RECT16TO32( &wpl
.rcNormalPosition
, &pwpl32
->rcNormalPosition
);
1277 /***********************************************************************
1278 * WINPOS_SetPlacement
1280 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT16
*wndpl
,
1283 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
1286 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
1287 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
1289 if( flags
& PLACE_MIN
) lpPos
->ptIconPos
= wndpl
->ptMinPosition
;
1290 if( flags
& PLACE_MAX
) lpPos
->ptMaxPos
= wndpl
->ptMaxPosition
;
1291 if( flags
& PLACE_RECT
) lpPos
->rectNormal
= wndpl
->rcNormalPosition
;
1293 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1295 WINPOS_ShowIconTitle( pWnd
, FALSE
);
1296 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
1297 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
1298 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1300 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1302 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
1303 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
1304 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1306 else if( flags
& PLACE_RECT
)
1307 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
1308 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
1309 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
1310 SWP_NOZORDER
| SWP_NOACTIVATE
);
1312 ShowWindow( hwnd
, wndpl
->showCmd
);
1313 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
1315 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
, TRUE
);
1317 /* SDK: ...valid only the next time... */
1318 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
1320 WIN_ReleaseWndPtr(pWnd
);
1327 /***********************************************************************
1328 * SetWindowPlacement (USER.371)
1330 BOOL16 WINAPI
SetWindowPlacement16(HWND16 hwnd
, const WINDOWPLACEMENT16
*wndpl
)
1332 return WINPOS_SetPlacement( hwnd
, wndpl
,
1333 PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1336 /***********************************************************************
1337 * SetWindowPlacement (USER32.@)
1340 * Fails if wndpl->length of Win95 (!) apps is invalid.
1342 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*pwpl32
)
1346 WINDOWPLACEMENT16 wpl
;
1348 wpl
.length
= sizeof(WINDOWPLACEMENT16
);
1349 wpl
.flags
= pwpl32
->flags
;
1350 wpl
.showCmd
= pwpl32
->showCmd
;
1351 wpl
.ptMinPosition
.x
= pwpl32
->ptMinPosition
.x
;
1352 wpl
.ptMinPosition
.y
= pwpl32
->ptMinPosition
.y
;
1353 wpl
.ptMaxPosition
.x
= pwpl32
->ptMaxPosition
.x
;
1354 wpl
.ptMaxPosition
.y
= pwpl32
->ptMaxPosition
.y
;
1355 wpl
.rcNormalPosition
.left
= pwpl32
->rcNormalPosition
.left
;
1356 wpl
.rcNormalPosition
.top
= pwpl32
->rcNormalPosition
.top
;
1357 wpl
.rcNormalPosition
.right
= pwpl32
->rcNormalPosition
.right
;
1358 wpl
.rcNormalPosition
.bottom
= pwpl32
->rcNormalPosition
.bottom
;
1360 return WINPOS_SetPlacement( hwnd
, &wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1366 /***********************************************************************
1367 * SetInternalWindowPos (USER.461)
1369 void WINAPI
SetInternalWindowPos16( HWND16 hwnd
, UINT16 showCmd
,
1370 LPRECT16 rect
, LPPOINT16 pt
)
1372 if( IsWindow16(hwnd
) )
1374 WINDOWPLACEMENT16 wndpl
;
1377 wndpl
.length
= sizeof(wndpl
);
1378 wndpl
.showCmd
= showCmd
;
1379 wndpl
.flags
= flags
= 0;
1384 wndpl
.flags
|= WPF_SETMINPOSITION
;
1385 wndpl
.ptMinPosition
= *pt
;
1389 flags
|= PLACE_RECT
;
1390 wndpl
.rcNormalPosition
= *rect
;
1392 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1396 /***********************************************************************
1397 * AnimateWindow (USER32.@)
1398 * Shows/Hides a window with an animation
1401 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1403 FIXME("partial stub\n");
1405 /* If trying to show/hide and it's already *
1406 * shown/hidden or invalid window, fail with *
1407 * invalid parameter */
1408 if(!IsWindow(hwnd
) ||
1409 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1410 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1412 SetLastError(ERROR_INVALID_PARAMETER
);
1416 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1421 /***********************************************************************
1422 * SetInternalWindowPos (USER32.@)
1424 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1425 LPRECT rect
, LPPOINT pt
)
1427 if( IsWindow(hwnd
) )
1429 WINDOWPLACEMENT16 wndpl
;
1432 wndpl
.length
= sizeof(wndpl
);
1433 wndpl
.showCmd
= showCmd
;
1434 wndpl
.flags
= flags
= 0;
1439 wndpl
.flags
|= WPF_SETMINPOSITION
;
1440 CONV_POINT32TO16( pt
, &wndpl
.ptMinPosition
);
1444 flags
|= PLACE_RECT
;
1445 CONV_RECT32TO16( rect
, &wndpl
.rcNormalPosition
);
1447 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1451 /*******************************************************************
1452 * WINPOS_SetActiveWindow
1454 * SetActiveWindow() back-end. This is the only function that
1455 * can assign active status to a window. It must be called only
1456 * for the top level windows.
1458 BOOL
WINPOS_SetActiveWindow( HWND hWnd
, BOOL fMouse
, BOOL fChangeFocus
)
1460 WND
* wndPtr
=0, *wndTemp
;
1461 HQUEUE16 hOldActiveQueue
, hNewActiveQueue
;
1462 MESSAGEQUEUE
*pOldActiveQueue
= 0, *pNewActiveQueue
= 0;
1464 HWND hwndActive
= 0;
1467 TRACE("(%04x, %d, %d)\n", hWnd
, fMouse
, fChangeFocus
);
1469 /* Get current active window from the active queue */
1472 pOldActiveQueue
= QUEUE_Lock( hActiveQueue
);
1473 if ( pOldActiveQueue
)
1474 hwndActive
= PERQDATA_GetActiveWnd( pOldActiveQueue
->pQData
);
1477 /* paranoid checks */
1478 if( hWnd
== GetDesktopWindow() || (bRet
= (hWnd
== hwndActive
)) )
1481 /* if (wndPtr && (GetFastQueue16() != wndPtr->hmemTaskQ))
1484 wndPtr
= WIN_FindWndPtr(hWnd
);
1485 hOldActiveQueue
= hActiveQueue
;
1487 if( (wndTemp
= WIN_FindWndPtr(hwndActive
)) )
1489 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1490 WIN_ReleaseWndPtr(wndTemp
);
1493 TRACE("no current active window.\n");
1495 /* call CBT hook chain */
1496 if (HOOK_IsHooked( WH_CBT
))
1498 CBTACTIVATESTRUCT cbt
;
1499 cbt
.fMouse
= fMouse
;
1500 cbt
.hWndActive
= hwndActive
;
1501 if (HOOK_CallHooksA( WH_CBT
, HCBT_ACTIVATE
, hWnd
, (LPARAM
)&cbt
)) goto CLEANUP_END
;
1504 /* set prev active wnd to current active wnd and send notification */
1505 if ((hwndPrevActive
= hwndActive
) && IsWindow(hwndPrevActive
))
1507 MESSAGEQUEUE
*pTempActiveQueue
= 0;
1509 if (!SendMessageA( hwndPrevActive
, WM_NCACTIVATE
, FALSE
, 0 ))
1511 if (GetSysModalWindow16() != hWnd
)
1513 /* disregard refusal if hWnd is sysmodal */
1516 SendMessageA( hwndPrevActive
, WM_ACTIVATE
,
1517 MAKEWPARAM( WA_INACTIVE
, wIconized
),
1520 /* check if something happened during message processing
1521 * (global active queue may have changed)
1523 pTempActiveQueue
= QUEUE_Lock( hActiveQueue
);
1524 if(!pTempActiveQueue
)
1527 hwndActive
= PERQDATA_GetActiveWnd( pTempActiveQueue
->pQData
);
1528 QUEUE_Unlock( pTempActiveQueue
);
1529 if( hwndPrevActive
!= hwndActive
)
1533 /* Set new active window in the message queue */
1537 pNewActiveQueue
= QUEUE_Lock( wndPtr
->hmemTaskQ
);
1538 if ( pNewActiveQueue
)
1539 PERQDATA_SetActiveWnd( pNewActiveQueue
->pQData
, hwndActive
);
1541 else /* have to do this or MDI frame activation goes to hell */
1542 if( pOldActiveQueue
)
1543 PERQDATA_SetActiveWnd( pOldActiveQueue
->pQData
, 0 );
1545 /* send palette messages */
1546 if (hWnd
&& SendMessage16( hWnd
, WM_QUERYNEWPALETTE
, 0, 0L))
1547 SendMessage16((HWND16
)-1, WM_PALETTEISCHANGING
, (WPARAM16
)hWnd
, 0L );
1549 /* if prev wnd is minimized redraw icon title */
1550 if( IsIconic( hwndPrevActive
) ) WINPOS_RedrawIconTitle(hwndPrevActive
);
1552 /* managed windows will get ConfigureNotify event */
1553 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
) && !(wndPtr
->dwExStyle
& WS_EX_MANAGED
))
1555 /* check Z-order and bring hWnd to the top */
1556 for (wndTemp
= WIN_LockWndPtr(WIN_GetDesktop()->child
); wndTemp
; WIN_UpdateWndPtr(&wndTemp
,wndTemp
->next
))
1558 if (wndTemp
->dwStyle
& WS_VISIBLE
) break;
1560 WIN_ReleaseDesktop();
1561 WIN_ReleaseWndPtr(wndTemp
);
1563 if( wndTemp
!= wndPtr
)
1564 SetWindowPos(hWnd
, HWND_TOP
, 0,0,0,0,
1565 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1566 if (!IsWindow(hWnd
))
1570 /* Get a handle to the new active queue */
1571 hNewActiveQueue
= wndPtr
? wndPtr
->hmemTaskQ
: 0;
1573 /* send WM_ACTIVATEAPP if necessary */
1574 if (hOldActiveQueue
!= hNewActiveQueue
)
1576 WND
**list
, **ppWnd
;
1577 WND
*pDesktop
= WIN_GetDesktop();
1579 if ((list
= WIN_BuildWinArray( pDesktop
, 0, NULL
)))
1581 DWORD new_thread
= GetWindowThreadProcessId( hwndActive
, NULL
);
1582 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1584 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
1586 if ((*ppWnd
)->hmemTaskQ
== hOldActiveQueue
)
1587 SendMessageW( (*ppWnd
)->hwndSelf
, WM_ACTIVATEAPP
, 0, new_thread
);
1589 WIN_ReleaseWinArray(list
);
1592 hActiveQueue
= hNewActiveQueue
;
1594 if ((list
= WIN_BuildWinArray(pDesktop
, 0, NULL
)))
1596 DWORD old_thread
= GetWindowThreadProcessId( hwndPrevActive
, NULL
);
1597 for (ppWnd
= list
; *ppWnd
; ppWnd
++)
1599 if (!IsWindow( (*ppWnd
)->hwndSelf
)) continue;
1601 if ((*ppWnd
)->hmemTaskQ
== hNewActiveQueue
)
1602 SendMessageW( (*ppWnd
)->hwndSelf
, WM_ACTIVATEAPP
, 1, old_thread
);
1604 WIN_ReleaseWinArray(list
);
1606 WIN_ReleaseDesktop();
1608 if (hWnd
&& !IsWindow(hWnd
)) goto CLEANUP
;
1613 /* walk up to the first unowned window */
1614 wndTemp
= WIN_LockWndPtr(wndPtr
);
1615 while (wndTemp
->owner
)
1617 WIN_UpdateWndPtr(&wndTemp
,wndTemp
->owner
);
1619 /* and set last active owned popup */
1620 wndTemp
->hwndLastActive
= hWnd
;
1622 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1623 WIN_ReleaseWndPtr(wndTemp
);
1624 SendMessageA( hWnd
, WM_NCACTIVATE
, TRUE
, 0 );
1625 SendMessageA( hWnd
, WM_ACTIVATE
,
1626 MAKEWPARAM( (fMouse
) ? WA_CLICKACTIVE
: WA_ACTIVE
, wIconized
),
1627 (LPARAM
)hwndPrevActive
);
1628 if( !IsWindow(hWnd
) ) goto CLEANUP
;
1631 /* change focus if possible */
1634 if ( pNewActiveQueue
)
1636 HWND hOldFocus
= PERQDATA_GetFocusWnd( pNewActiveQueue
->pQData
);
1638 if ( hOldFocus
&& WIN_GetTopParent( hOldFocus
) != hwndActive
)
1639 FOCUS_SwitchFocus( pNewActiveQueue
, hOldFocus
,
1640 (wndPtr
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))?
1644 if ( pOldActiveQueue
&&
1645 ( !pNewActiveQueue
||
1646 pNewActiveQueue
->pQData
!= pOldActiveQueue
->pQData
) )
1648 HWND hOldFocus
= PERQDATA_GetFocusWnd( pOldActiveQueue
->pQData
);
1650 FOCUS_SwitchFocus( pOldActiveQueue
, hOldFocus
, 0 );
1654 if( !hwndPrevActive
&& wndPtr
)
1656 if (USER_Driver
.pForceWindowRaise
) USER_Driver
.pForceWindowRaise( wndPtr
->hwndSelf
);
1659 /* if active wnd is minimized redraw icon title */
1660 if( IsIconic(hwndActive
) ) WINPOS_RedrawIconTitle(hwndActive
);
1662 bRet
= (hWnd
== hwndActive
); /* Success? */
1664 CLEANUP
: /* Unlock the message queues before returning */
1666 if ( pNewActiveQueue
)
1667 QUEUE_Unlock( pNewActiveQueue
);
1671 if ( pOldActiveQueue
)
1672 QUEUE_Unlock( pOldActiveQueue
);
1674 WIN_ReleaseWndPtr(wndPtr
);
1678 /*******************************************************************
1679 * WINPOS_ActivateOtherWindow
1681 * Activates window other than pWnd.
1683 BOOL
WINPOS_ActivateOtherWindow(WND
* pWnd
)
1687 HWND hwndActive
= 0;
1689 /* Get current active window from the active queue */
1692 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
1695 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
1696 QUEUE_Unlock( pActiveQueue
);
1700 if( pWnd
->hwndSelf
== hwndPrevActive
)
1703 if( hwndActive
!= pWnd
->hwndSelf
&&
1704 ( hwndActive
|| QUEUE_IsExitingQueue(pWnd
->hmemTaskQ
)) )
1707 if( !(pWnd
->dwStyle
& WS_POPUP
) || !(pWnd
->owner
) ||
1708 !WINPOS_CanActivate((pWndTo
= WIN_GetTopParentPtr(pWnd
->owner
))) )
1710 WND
* pWndPtr
= WIN_GetTopParentPtr(pWnd
);
1712 WIN_ReleaseWndPtr(pWndTo
);
1713 pWndTo
= WIN_FindWndPtr(hwndPrevActive
);
1715 while( !WINPOS_CanActivate(pWndTo
) )
1717 /* by now owned windows should've been taken care of */
1718 WIN_UpdateWndPtr(&pWndTo
,pWndPtr
->next
);
1719 WIN_UpdateWndPtr(&pWndPtr
,pWndTo
);
1720 if( !pWndTo
) break;
1722 WIN_ReleaseWndPtr(pWndPtr
);
1725 bRet
= WINPOS_SetActiveWindow( pWndTo
? pWndTo
->hwndSelf
: 0, FALSE
, TRUE
);
1727 if( pWndTo
) WIN_ReleaseWndPtr(pWndTo
);
1733 /*******************************************************************
1734 * WINPOS_ChangeActiveWindow
1737 BOOL
WINPOS_ChangeActiveWindow( HWND hWnd
, BOOL mouseMsg
)
1741 HWND hwndActive
= 0;
1743 /* Get current active window from the active queue */
1746 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
1749 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
1750 QUEUE_Unlock( pActiveQueue
);
1755 return WINPOS_SetActiveWindow( 0, mouseMsg
, TRUE
);
1757 wndPtr
= WIN_FindWndPtr(hWnd
);
1758 if( !wndPtr
) return FALSE
;
1760 /* child windows get WM_CHILDACTIVATE message */
1761 if( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1763 retvalue
= SendMessageA(hWnd
, WM_CHILDACTIVATE
, 0, 0L);
1767 if( hWnd
== hwndActive
)
1773 if( !WINPOS_SetActiveWindow(hWnd
,mouseMsg
,TRUE
) )
1781 WIN_ReleaseWndPtr(wndPtr
);
1786 /***********************************************************************
1787 * WINPOS_SendNCCalcSize
1789 * Send a WM_NCCALCSIZE message to a window.
1790 * All parameters are read-only except newClientRect.
1791 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1792 * when calcValidRect is TRUE.
1794 LONG
WINPOS_SendNCCalcSize( HWND hwnd
, BOOL calcValidRect
,
1795 RECT
*newWindowRect
, RECT
*oldWindowRect
,
1796 RECT
*oldClientRect
, WINDOWPOS
*winpos
,
1797 RECT
*newClientRect
)
1799 NCCALCSIZE_PARAMS params
;
1800 WINDOWPOS winposCopy
;
1803 params
.rgrc
[0] = *newWindowRect
;
1806 winposCopy
= *winpos
;
1807 params
.rgrc
[1] = *oldWindowRect
;
1808 params
.rgrc
[2] = *oldClientRect
;
1809 params
.lppos
= &winposCopy
;
1811 result
= SendMessageA( hwnd
, WM_NCCALCSIZE
, calcValidRect
,
1813 TRACE("%d,%d-%d,%d\n",
1814 params
.rgrc
[0].left
, params
.rgrc
[0].top
,
1815 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
1817 /* If the application send back garbage, ignore it */
1818 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&& params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
1819 *newClientRect
= params
.rgrc
[0];
1825 /***********************************************************************
1826 * WINPOS_HandleWindowPosChanging16
1828 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1830 LONG
WINPOS_HandleWindowPosChanging16( WND
*wndPtr
, WINDOWPOS16
*winpos
)
1832 POINT maxSize
, minTrack
;
1833 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1834 if ((wndPtr
->dwStyle
& WS_THICKFRAME
) ||
1835 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) == 0))
1837 WINPOS_GetMinMaxInfo( wndPtr
, &maxSize
, NULL
, &minTrack
, NULL
);
1838 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1839 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1840 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
1842 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1843 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1850 /***********************************************************************
1851 * WINPOS_HandleWindowPosChanging
1853 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1855 LONG
WINPOS_HandleWindowPosChanging( WND
*wndPtr
, WINDOWPOS
*winpos
)
1857 POINT maxSize
, minTrack
;
1858 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1859 if ((wndPtr
->dwStyle
& WS_THICKFRAME
) ||
1860 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) == 0))
1862 WINPOS_GetMinMaxInfo( wndPtr
, &maxSize
, NULL
, &minTrack
, NULL
);
1863 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1864 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1865 if (!(wndPtr
->dwStyle
& WS_MINIMIZE
))
1867 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1868 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1874 /***********************************************************************
1875 * SetWindowPos (USER.232)
1877 BOOL16 WINAPI
SetWindowPos16( HWND16 hwnd
, HWND16 hwndInsertAfter
,
1878 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, WORD flags
)
1880 return SetWindowPos(hwnd
,(INT
)(INT16
)hwndInsertAfter
,x
,y
,cx
,cy
,flags
);
1883 /***********************************************************************
1884 * SetWindowPos (USER32.@)
1886 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1887 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1892 winpos
.hwndInsertAfter
= hwndInsertAfter
;
1897 winpos
.flags
= flags
;
1898 return USER_Driver
.pSetWindowPos( &winpos
);
1902 /***********************************************************************
1903 * BeginDeferWindowPos (USER.259)
1905 HDWP16 WINAPI
BeginDeferWindowPos16( INT16 count
)
1907 return BeginDeferWindowPos( count
);
1911 /***********************************************************************
1912 * BeginDeferWindowPos (USER32.@)
1914 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1921 SetLastError(ERROR_INVALID_PARAMETER
);
1924 /* Windows allows zero count, in which case it allocates context for 8 moves */
1925 if (count
== 0) count
= 8;
1927 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1928 if (!handle
) return 0;
1929 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1930 pDWP
->actualCount
= 0;
1931 pDWP
->suggestedCount
= count
;
1933 pDWP
->wMagic
= DWP_MAGIC
;
1934 pDWP
->hwndParent
= 0;
1939 /***********************************************************************
1940 * DeferWindowPos (USER.260)
1942 HDWP16 WINAPI
DeferWindowPos16( HDWP16 hdwp
, HWND16 hwnd
, HWND16 hwndAfter
,
1943 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
,
1946 return DeferWindowPos( hdwp
, hwnd
, (INT
)(INT16
)hwndAfter
,
1947 x
, y
, cx
, cy
, flags
);
1951 /***********************************************************************
1952 * DeferWindowPos (USER32.@)
1954 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1955 INT x
, INT y
, INT cx
, INT cy
,
1960 HDWP newhdwp
= hdwp
,retvalue
;
1964 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
1965 if (!pDWP
) return 0;
1966 if (hwnd
== GetDesktopWindow()) return 0;
1968 if (!(pWnd
=WIN_FindWndPtr( hwnd
))) {
1969 USER_HEAP_FREE( hdwp
);
1973 /* Numega Bounds Checker Demo dislikes the following code.
1974 In fact, I've not been able to find any "same parent" requirement in any docu
1978 /* All the windows of a DeferWindowPos() must have the same parent */
1979 parent
= pWnd
->parent
->hwndSelf
;
1980 if (pDWP
->actualCount
== 0) pDWP
->hwndParent
= parent
;
1981 else if (parent
!= pDWP
->hwndParent
)
1983 USER_HEAP_FREE( hdwp
);
1989 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1991 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1993 /* Merge with the other changes */
1994 if (!(flags
& SWP_NOZORDER
))
1996 pDWP
->winPos
[i
].hwndInsertAfter
= hwndAfter
;
1998 if (!(flags
& SWP_NOMOVE
))
2000 pDWP
->winPos
[i
].x
= x
;
2001 pDWP
->winPos
[i
].y
= y
;
2003 if (!(flags
& SWP_NOSIZE
))
2005 pDWP
->winPos
[i
].cx
= cx
;
2006 pDWP
->winPos
[i
].cy
= cy
;
2008 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
2009 SWP_NOZORDER
| SWP_NOREDRAW
|
2010 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
2012 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
2018 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
2020 newhdwp
= USER_HEAP_REALLOC( hdwp
,
2021 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
2027 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
2028 pDWP
->suggestedCount
++;
2030 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
2031 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
2032 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
2033 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
2034 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
2035 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
2036 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
2037 pDWP
->actualCount
++;
2040 WIN_ReleaseWndPtr(pWnd
);
2045 /***********************************************************************
2046 * EndDeferWindowPos (USER.261)
2048 BOOL16 WINAPI
EndDeferWindowPos16( HDWP16 hdwp
)
2050 return EndDeferWindowPos( hdwp
);
2054 /***********************************************************************
2055 * EndDeferWindowPos (USER32.@)
2057 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2064 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
2065 if (!pDWP
) return FALSE
;
2066 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
2068 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
2070 USER_HEAP_FREE( hdwp
);
2075 /***********************************************************************
2076 * TileChildWindows (USER.199)
2078 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
2080 FIXME("(%04x, %d): stub\n", parent
, action
);
2083 /***********************************************************************
2084 * CascadeChildWindows (USER.198)
2086 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
2088 FIXME("(%04x, %d): stub\n", parent
, action
);
2091 /***********************************************************************
2092 * SetProgmanWindow (USER32.@)
2094 HRESULT WINAPI
SetProgmanWindow ( HWND hwnd
)
2096 hGlobalProgmanWindow
= hwnd
;
2097 return hGlobalProgmanWindow
;
2100 /***********************************************************************
2101 * GetProgmanWindow (USER32.@)
2103 HRESULT WINAPI
GetProgmanWindow ( )
2105 return hGlobalProgmanWindow
;
2108 /***********************************************************************
2109 * SetShellWindowEx (USER32.@)
2110 * hwndProgman = Progman[Program Manager]
2111 * |-> SHELLDLL_DefView
2112 * hwndListView = | |-> SysListView32
2113 * | | |-> tooltips_class32
2119 HRESULT WINAPI
SetShellWindowEx ( HWND hwndProgman
, HWND hwndListView
)
2121 FIXME("0x%08x 0x%08x stub\n",hwndProgman
,hwndListView
);
2122 hGlobalShellWindow
= hwndProgman
;
2123 return hGlobalShellWindow
;
2127 /***********************************************************************
2128 * SetTaskmanWindow (USER32.@)
2130 * hwnd = MSTaskSwWClass
2131 * |-> SysTabControl32
2133 HRESULT WINAPI
SetTaskmanWindow ( HWND hwnd
)
2135 hGlobalTaskmanWindow
= hwnd
;
2136 return hGlobalTaskmanWindow
;
2139 /***********************************************************************
2140 * GetTaskmanWindow (USER32.@)
2142 HRESULT WINAPI
GetTaskmanWindow ( )
2144 return hGlobalTaskmanWindow
;