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 (USER.170)
122 UINT16 WINAPI
ArrangeIconicWindows16( HWND16 parent
)
124 return ArrangeIconicWindows(parent
);
126 /***********************************************************************
127 * ArrangeIconicWindows (USER32.@)
129 UINT WINAPI
ArrangeIconicWindows( HWND parent
)
133 INT x
, y
, xspacing
, yspacing
;
135 GetClientRect( parent
, &rectParent
);
137 y
= rectParent
.bottom
;
138 xspacing
= GetSystemMetrics(SM_CXICONSPACING
);
139 yspacing
= GetSystemMetrics(SM_CYICONSPACING
);
141 hwndChild
= GetWindow( parent
, GW_CHILD
);
144 if( IsIconic( hwndChild
) )
146 WINPOS_ShowIconTitle( hwndChild
, 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(hwndChild
, TRUE
);
154 if (x
<= rectParent
.right
- xspacing
) x
+= xspacing
;
161 hwndChild
= GetWindow( hwndChild
, GW_HWNDNEXT
);
167 /***********************************************************************
168 * SwitchToThisWindow (USER.172)
170 void WINAPI
SwitchToThisWindow16( HWND16 hwnd
, BOOL16 restore
)
172 SwitchToThisWindow( hwnd
, restore
);
176 /***********************************************************************
177 * SwitchToThisWindow (USER32.@)
179 void WINAPI
SwitchToThisWindow( HWND hwnd
, BOOL restore
)
181 ShowWindow( hwnd
, restore
? SW_RESTORE
: SW_SHOWMINIMIZED
);
185 /***********************************************************************
186 * GetWindowRect (USER.32)
188 void WINAPI
GetWindowRect16( HWND16 hwnd
, LPRECT16 rect
)
192 GetWindowRect( hwnd
, &rect32
);
193 rect
->left
= rect32
.left
;
194 rect
->top
= rect32
.top
;
195 rect
->right
= rect32
.right
;
196 rect
->bottom
= rect32
.bottom
;
200 /***********************************************************************
201 * GetWindowRect (USER32.@)
203 BOOL WINAPI
GetWindowRect( HWND hwnd
, LPRECT rect
)
205 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
206 if (!wndPtr
) return FALSE
;
207 *rect
= wndPtr
->rectWindow
;
208 WIN_ReleaseWndPtr(wndPtr
);
209 MapWindowPoints( GetAncestor( hwnd
, GA_PARENT
), 0, (POINT
*)rect
, 2 );
210 TRACE("hwnd %04x (%d,%d)-(%d,%d)\n",
211 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
216 /***********************************************************************
217 * GetWindowRgn (USER32.@)
219 int WINAPI
GetWindowRgn ( HWND hwnd
, HRGN hrgn
)
222 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
225 if (wndPtr
->hrgnWnd
) nRet
= CombineRgn( hrgn
, wndPtr
->hrgnWnd
, 0, RGN_COPY
);
226 WIN_ReleaseWndPtr(wndPtr
);
231 /***********************************************************************
232 * SetWindowRgn (USER32.@)
234 int WINAPI
SetWindowRgn( HWND hwnd
, HRGN hrgn
, BOOL bRedraw
)
240 if (USER_Driver
.pSetWindowRgn
)
241 return USER_Driver
.pSetWindowRgn( hwnd
, hrgn
, bRedraw
);
243 if (!(wndPtr
= WIN_FindWndPtr(hwnd
))) return FALSE
;
245 if (wndPtr
->hrgnWnd
== hrgn
)
251 if (hrgn
) /* verify that region really exists */
253 if (GetRgnBox( hrgn
, &rect
) == ERROR
) goto done
;
258 /* delete previous region */
259 DeleteObject(wndPtr
->hrgnWnd
);
262 wndPtr
->hrgnWnd
= hrgn
;
264 /* Size the window to the rectangle of the new region (if it isn't NULL) */
265 if (hrgn
) SetWindowPos( hwnd
, 0, rect
.left
, rect
.top
,
266 rect
.right
- rect
.left
, rect
.bottom
- rect
.top
,
267 SWP_NOSIZE
| SWP_FRAMECHANGED
| SWP_NOMOVE
| SWP_NOACTIVATE
|
268 SWP_NOZORDER
| (bRedraw
? 0 : SWP_NOREDRAW
) );
272 WIN_ReleaseWndPtr(wndPtr
);
276 /***********************************************************************
277 * SetWindowRgn (USER.668)
279 INT16 WINAPI
SetWindowRgn16( HWND16 hwnd
, HRGN16 hrgn
,BOOL16 bRedraw
)
283 FIXME("SetWindowRgn16: stub\n");
288 /***********************************************************************
289 * GetClientRect (USER.33)
291 void WINAPI
GetClientRect16( HWND16 hwnd
, LPRECT16 rect
)
293 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
295 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
298 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
299 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
301 WIN_ReleaseWndPtr(wndPtr
);
305 /***********************************************************************
306 * GetClientRect (USER32.@)
308 BOOL WINAPI
GetClientRect( HWND hwnd
, LPRECT rect
)
310 WND
* wndPtr
= WIN_FindWndPtr( hwnd
);
312 rect
->left
= rect
->top
= rect
->right
= rect
->bottom
= 0;
313 if (!wndPtr
) return FALSE
;
314 rect
->right
= wndPtr
->rectClient
.right
- wndPtr
->rectClient
.left
;
315 rect
->bottom
= wndPtr
->rectClient
.bottom
- wndPtr
->rectClient
.top
;
317 WIN_ReleaseWndPtr(wndPtr
);
318 TRACE("hwnd %04x (%d,%d)-(%d,%d)\n",
319 hwnd
, rect
->left
, rect
->top
, rect
->right
, rect
->bottom
);
324 /*******************************************************************
325 * ClientToScreen (USER.28)
327 void WINAPI
ClientToScreen16( HWND16 hwnd
, LPPOINT16 lppnt
)
329 MapWindowPoints16( hwnd
, 0, lppnt
, 1 );
333 /*******************************************************************
334 * ClientToScreen (USER32.@)
336 BOOL WINAPI
ClientToScreen( HWND hwnd
, LPPOINT lppnt
)
338 MapWindowPoints( hwnd
, 0, lppnt
, 1 );
343 /*******************************************************************
344 * ScreenToClient (USER.29)
346 void WINAPI
ScreenToClient16( HWND16 hwnd
, LPPOINT16 lppnt
)
348 MapWindowPoints16( 0, hwnd
, lppnt
, 1 );
352 /*******************************************************************
353 * ScreenToClient (USER32.@)
355 BOOL WINAPI
ScreenToClient( HWND hwnd
, LPPOINT lppnt
)
357 MapWindowPoints( 0, hwnd
, lppnt
, 1 );
362 /***********************************************************************
363 * WINPOS_WindowFromPoint
365 * Find the window and hittest for a given point.
367 HWND
WINPOS_WindowFromPoint( HWND hwndScope
, POINT pt
, INT
*hittest
)
369 WND
*wndScope
, *wndPtr
, *wndTmp
;
373 TRACE("scope %04x %ld,%ld\n", hwndScope
, pt
.x
, pt
.y
);
375 if (!hwndScope
) hwndScope
= GetDesktopWindow();
376 if (!(wndScope
= WIN_FindWndPtr( hwndScope
))) return 0;
377 hwndScope
= wndScope
->hwndSelf
; /* make it a full handle */
380 wndPtr
= WIN_LockWndPtr(wndScope
->child
);
382 if( wndScope
->dwStyle
& WS_DISABLED
)
388 if (wndScope
->parent
)
389 MapWindowPoints( GetDesktopWindow(), wndScope
->parent
->hwndSelf
, &xy
, 1 );
391 if (xy
.x
< wndScope
->rectClient
.left
|| pt
.x
>= wndScope
->rectClient
.right
||
392 xy
.y
< wndScope
->rectClient
.top
|| pt
.y
>= wndScope
->rectClient
.bottom
||
393 wndScope
->dwStyle
& WS_MINIMIZE
)
396 xy
.x
-= wndScope
->rectClient
.left
;
397 xy
.y
-= wndScope
->rectClient
.top
;
403 /* If point is in window, and window is visible, and it */
404 /* is enabled (or it's a top-level window), then explore */
405 /* its children. Otherwise, go to the next window. */
407 if ((wndPtr
->dwStyle
& WS_VISIBLE
) &&
408 ((wndPtr
->dwExStyle
& (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) != (WS_EX_LAYERED
| WS_EX_TRANSPARENT
)) &&
409 (!(wndPtr
->dwStyle
& WS_DISABLED
) ||
410 ((wndPtr
->dwStyle
& (WS_POPUP
| WS_CHILD
)) != WS_CHILD
)) &&
412 PtInRegion(wndPtr
->hrgnWnd
, xy
.x
- wndPtr
->rectWindow
.left
,
413 xy
.y
- wndPtr
->rectWindow
.top
) :
414 ((xy
.x
>= wndPtr
->rectWindow
.left
) &&
415 (xy
.x
< wndPtr
->rectWindow
.right
) &&
416 (xy
.y
>= wndPtr
->rectWindow
.top
) &&
417 (xy
.y
< wndPtr
->rectWindow
.bottom
))))
419 TRACE("%ld,%ld is inside %04x\n", xy
.x
, xy
.y
, wndPtr
->hwndSelf
);
420 hwnd_ret
= wndPtr
->hwndSelf
; /* Got a suitable window */
422 /* If window is minimized or disabled, return at once */
423 if (wndPtr
->dwStyle
& WS_MINIMIZE
)
425 *hittest
= HTCAPTION
;
428 if (wndPtr
->dwStyle
& WS_DISABLED
)
434 /* If point is not in client area, ignore the children */
435 if ((xy
.x
< wndPtr
->rectClient
.left
) ||
436 (xy
.x
>= wndPtr
->rectClient
.right
) ||
437 (xy
.y
< wndPtr
->rectClient
.top
) ||
438 (xy
.y
>= wndPtr
->rectClient
.bottom
)) break;
440 xy
.x
-= wndPtr
->rectClient
.left
;
441 xy
.y
-= wndPtr
->rectClient
.top
;
442 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->child
);
446 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->next
);
451 /* If nothing found, try the scope window */
452 if (!hwnd_ret
) hwnd_ret
= hwndScope
;
454 /* Send the WM_NCHITTEST message (only if to the same task) */
455 if (GetWindowThreadProcessId( hwnd_ret
, NULL
) == GetCurrentThreadId())
457 INT res
= SendMessageA( hwnd_ret
, WM_NCHITTEST
, 0, MAKELONG( pt
.x
, pt
.y
) );
458 if (res
!= HTTRANSPARENT
)
460 *hittest
= res
; /* Found the window */
470 if (!(wndTmp
= WIN_FindWndPtr( hwnd_ret
))) break;
472 /* If no children found in last search, make point relative to parent */
475 xy
.x
+= wndTmp
->rectClient
.left
;
476 xy
.y
+= wndTmp
->rectClient
.top
;
479 /* Restart the search from the next sibling */
480 WIN_UpdateWndPtr(&wndPtr
,wndTmp
->next
);
481 hwnd_ret
= wndTmp
->parent
? wndTmp
->parent
->hwndSelf
: 0;
482 WIN_ReleaseWndPtr( wndTmp
);
486 WIN_ReleaseWndPtr(wndPtr
);
487 WIN_ReleaseWndPtr(wndScope
);
492 /*******************************************************************
493 * WindowFromPoint (USER.30)
495 HWND16 WINAPI
WindowFromPoint16( POINT16 pt
)
499 CONV_POINT16TO32( &pt
, &pt32
);
500 return WindowFromPoint( pt32
);
504 /*******************************************************************
505 * WindowFromPoint (USER32.@)
507 HWND WINAPI
WindowFromPoint( POINT pt
)
510 return WINPOS_WindowFromPoint( 0, pt
, &hittest
);
514 /*******************************************************************
515 * ChildWindowFromPoint (USER.191)
517 HWND16 WINAPI
ChildWindowFromPoint16( HWND16 hwndParent
, POINT16 pt
)
520 CONV_POINT16TO32( &pt
, &pt32
);
521 return (HWND16
)ChildWindowFromPoint( hwndParent
, pt32
);
525 /*******************************************************************
526 * ChildWindowFromPoint (USER32.@)
528 HWND WINAPI
ChildWindowFromPoint( HWND hwndParent
, POINT pt
)
530 return ChildWindowFromPointEx( hwndParent
, pt
, CWP_ALL
);
533 /*******************************************************************
534 * ChildWindowFromPointEx (USER.399)
536 HWND16 WINAPI
ChildWindowFromPointEx16( HWND16 hwndParent
, POINT16 pt
, UINT16 uFlags
)
539 CONV_POINT16TO32( &pt
, &pt32
);
540 return (HWND16
)ChildWindowFromPointEx( hwndParent
, pt32
, uFlags
);
544 /*******************************************************************
545 * ChildWindowFromPointEx (USER32.@)
547 HWND WINAPI
ChildWindowFromPointEx( HWND hwndParent
, POINT pt
, UINT uFlags
)
549 /* pt is in the client coordinates */
555 GetClientRect( hwndParent
, &rect
);
556 if (!PtInRect( &rect
, pt
)) return 0;
557 if (!(list
= WIN_ListChildren( hwndParent
))) return 0;
559 for (i
= 0; list
[i
] && !retvalue
; i
++)
561 WND
*wnd
= WIN_FindWndPtr( list
[i
] );
563 if (PtInRect( &wnd
->rectWindow
, pt
))
565 if ( (uFlags
& CWP_SKIPINVISIBLE
) &&
566 !(wnd
->dwStyle
& WS_VISIBLE
) );
567 else if ( (uFlags
& CWP_SKIPDISABLED
) &&
568 (wnd
->dwStyle
& WS_DISABLED
) );
569 else if ( (uFlags
& CWP_SKIPTRANSPARENT
) &&
570 (wnd
->dwExStyle
& WS_EX_TRANSPARENT
) );
571 else retvalue
= list
[i
];
573 WIN_ReleaseWndPtr( wnd
);
575 HeapFree( GetProcessHeap(), 0, list
);
576 if (!retvalue
) retvalue
= hwndParent
;
581 /*******************************************************************
582 * WINPOS_GetWinOffset
584 * Calculate the offset between the origin of the two windows. Used
585 * to implement MapWindowPoints.
587 static void WINPOS_GetWinOffset( HWND hwndFrom
, HWND hwndTo
,
592 offset
->x
= offset
->y
= 0;
593 if (hwndFrom
== hwndTo
) return;
595 /* Translate source window origin to screen coords */
598 if (!(wndPtr
= WIN_FindWndPtr( hwndFrom
)))
600 ERR("bad hwndFrom = %04x\n",hwndFrom
);
603 while (wndPtr
->parent
)
605 offset
->x
+= wndPtr
->rectClient
.left
;
606 offset
->y
+= wndPtr
->rectClient
.top
;
607 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
609 WIN_ReleaseWndPtr(wndPtr
);
612 /* Translate origin to destination window coords */
615 if (!(wndPtr
= WIN_FindWndPtr( hwndTo
)))
617 ERR("bad hwndTo = %04x\n", hwndTo
);
620 while (wndPtr
->parent
)
622 offset
->x
-= wndPtr
->rectClient
.left
;
623 offset
->y
-= wndPtr
->rectClient
.top
;
624 WIN_UpdateWndPtr(&wndPtr
,wndPtr
->parent
);
626 WIN_ReleaseWndPtr(wndPtr
);
631 /*******************************************************************
632 * MapWindowPoints (USER.258)
634 void WINAPI
MapWindowPoints16( HWND16 hwndFrom
, HWND16 hwndTo
,
635 LPPOINT16 lppt
, UINT16 count
)
639 WINPOS_GetWinOffset( WIN_Handle32(hwndFrom
), WIN_Handle32(hwndTo
), &offset
);
649 /*******************************************************************
650 * MapWindowPoints (USER32.@)
652 INT WINAPI
MapWindowPoints( HWND hwndFrom
, HWND hwndTo
,
653 LPPOINT lppt
, UINT count
)
657 WINPOS_GetWinOffset( WIN_GetFullHandle(hwndFrom
), WIN_GetFullHandle(hwndTo
), &offset
);
664 return MAKELONG( LOWORD(offset
.x
), LOWORD(offset
.y
) );
668 /***********************************************************************
671 BOOL16 WINAPI
IsIconic16(HWND16 hWnd
)
673 return IsIconic(hWnd
);
677 /***********************************************************************
678 * IsIconic (USER32.@)
680 BOOL WINAPI
IsIconic(HWND hWnd
)
683 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
684 if (wndPtr
== NULL
) return FALSE
;
685 retvalue
= (wndPtr
->dwStyle
& WS_MINIMIZE
) != 0;
686 WIN_ReleaseWndPtr(wndPtr
);
691 /***********************************************************************
692 * IsZoomed (USER.272)
694 BOOL16 WINAPI
IsZoomed16(HWND16 hWnd
)
696 return IsZoomed(hWnd
);
700 /***********************************************************************
701 * IsZoomed (USER32.@)
703 BOOL WINAPI
IsZoomed(HWND hWnd
)
706 WND
* wndPtr
= WIN_FindWndPtr(hWnd
);
707 if (wndPtr
== NULL
) return FALSE
;
708 retvalue
= (wndPtr
->dwStyle
& WS_MAXIMIZE
) != 0;
709 WIN_ReleaseWndPtr(wndPtr
);
714 /*******************************************************************
715 * GetActiveWindow (USER.60)
717 HWND16 WINAPI
GetActiveWindow16(void)
719 return (HWND16
)GetActiveWindow();
722 /*******************************************************************
723 * GetActiveWindow (USER32.@)
725 HWND WINAPI
GetActiveWindow(void)
727 MESSAGEQUEUE
*pCurMsgQ
= 0;
729 /* Get the messageQ for the current thread */
730 if (!(pCurMsgQ
= QUEUE_Current()))
732 WARN("\tCurrent message queue not found. Exiting!\n" );
736 /* Return the current active window from the perQ data of the current message Q */
737 return PERQDATA_GetActiveWnd( pCurMsgQ
->pQData
);
741 /*******************************************************************
744 static BOOL
WINPOS_CanActivate(HWND hwnd
)
746 if (!hwnd
) return FALSE
;
747 return ((GetWindowLongW( hwnd
, GWL_STYLE
) & (WS_DISABLED
|WS_VISIBLE
|WS_CHILD
)) == WS_VISIBLE
);
751 /*******************************************************************
752 * SetActiveWindow (USER.59)
754 HWND16 WINAPI
SetActiveWindow16( HWND16 hwnd
)
756 return SetActiveWindow(hwnd
);
760 /*******************************************************************
761 * SetActiveWindow (USER32.@)
763 HWND WINAPI
SetActiveWindow( HWND hwnd
)
766 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
767 MESSAGEQUEUE
*pMsgQ
= 0, *pCurMsgQ
= 0;
769 if (!wndPtr
|| (wndPtr
->dwStyle
& (WS_DISABLED
| WS_CHILD
)))
775 /* Get the messageQ for the current thread */
776 if (!(pCurMsgQ
= QUEUE_Current()))
778 WARN("\tCurrent message queue not found. Exiting!\n" );
782 /* Retrieve the message queue associated with this window */
783 pMsgQ
= (MESSAGEQUEUE
*)QUEUE_Lock( wndPtr
->hmemTaskQ
);
786 WARN("\tWindow message queue not found. Exiting!\n" );
790 /* Make sure that the window is associated with the calling threads
791 * message queue. It must share the same perQ data.
794 if ( pCurMsgQ
->pQData
!= pMsgQ
->pQData
)
797 /* Save current active window */
798 prev
= PERQDATA_GetActiveWnd( pMsgQ
->pQData
);
800 WINPOS_SetActiveWindow( hwnd
, 0, 0 );
803 /* Unlock the queues before returning */
805 QUEUE_Unlock( pMsgQ
);
808 WIN_ReleaseWndPtr(wndPtr
);
813 /*******************************************************************
814 * GetForegroundWindow (USER.608)
816 HWND16 WINAPI
GetForegroundWindow16(void)
818 return (HWND16
)GetForegroundWindow();
822 /*******************************************************************
823 * SetForegroundWindow (USER.609)
825 BOOL16 WINAPI
SetForegroundWindow16( HWND16 hwnd
)
827 return SetForegroundWindow( hwnd
);
831 /*******************************************************************
832 * GetForegroundWindow (USER32.@)
834 HWND WINAPI
GetForegroundWindow(void)
838 /* Get the foreground window (active window of hActiveQueue) */
841 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
843 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
845 QUEUE_Unlock( pActiveQueue
);
851 /*******************************************************************
852 * SetForegroundWindow (USER32.@)
854 BOOL WINAPI
SetForegroundWindow( HWND hwnd
)
856 return WINPOS_ChangeActiveWindow( hwnd
, FALSE
);
860 /*******************************************************************
861 * AllowSetForegroundWindow (USER32.@)
863 BOOL WINAPI
AllowSetForegroundWindow( DWORD procid
)
865 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
866 * implemented, then fix this function. */
871 /*******************************************************************
872 * LockSetForegroundWindow (USER32.@)
874 BOOL WINAPI
LockSetForegroundWindow( UINT lockcode
)
876 /* FIXME: If Win98/2000 style SetForegroundWindow behavior is
877 * implemented, then fix this function. */
882 /*******************************************************************
883 * GetShellWindow (USER.600)
885 HWND16 WINAPI
GetShellWindow16(void)
887 return GetShellWindow();
890 /*******************************************************************
891 * SetShellWindow (USER32.@)
893 HWND WINAPI
SetShellWindow(HWND hwndshell
)
894 { WARN("(hWnd=%08x) semi stub\n",hwndshell
);
896 hGlobalShellWindow
= WIN_GetFullHandle( hwndshell
);
897 return hGlobalShellWindow
;
901 /*******************************************************************
902 * GetShellWindow (USER32.@)
904 HWND WINAPI
GetShellWindow(void)
905 { WARN("(hWnd=%x) semi stub\n",hGlobalShellWindow
);
907 return hGlobalShellWindow
;
911 /***********************************************************************
912 * BringWindowToTop (USER.45)
914 BOOL16 WINAPI
BringWindowToTop16( HWND16 hwnd
)
916 return BringWindowToTop(hwnd
);
920 /***********************************************************************
921 * BringWindowToTop (USER32.@)
923 BOOL WINAPI
BringWindowToTop( HWND hwnd
)
925 return SetWindowPos( hwnd
, HWND_TOP
, 0, 0, 0, 0, SWP_NOMOVE
|SWP_NOSIZE
);
929 /***********************************************************************
930 * MoveWindow (USER.56)
932 BOOL16 WINAPI
MoveWindow16( HWND16 hwnd
, INT16 x
, INT16 y
, INT16 cx
, INT16 cy
,
935 return MoveWindow(hwnd
,x
,y
,cx
,cy
,repaint
);
939 /***********************************************************************
940 * MoveWindow (USER32.@)
942 BOOL WINAPI
MoveWindow( HWND hwnd
, INT x
, INT y
, INT cx
, INT cy
,
945 int flags
= SWP_NOZORDER
| SWP_NOACTIVATE
;
946 if (!repaint
) flags
|= SWP_NOREDRAW
;
947 TRACE("%04x %d,%d %dx%d %d\n",
948 hwnd
, x
, y
, cx
, cy
, repaint
);
949 return SetWindowPos( hwnd
, 0, x
, y
, cx
, cy
, flags
);
952 /***********************************************************************
953 * WINPOS_InitInternalPos
955 static LPINTERNALPOS
WINPOS_InitInternalPos( WND
* wnd
, POINT pt
,
958 LPINTERNALPOS lpPos
= (LPINTERNALPOS
) GetPropA( wnd
->hwndSelf
,
962 /* this happens when the window is minimized/maximized
963 * for the first time (rectWindow is not adjusted yet) */
965 lpPos
= HeapAlloc( GetProcessHeap(), 0, sizeof(INTERNALPOS
) );
966 if( !lpPos
) return NULL
;
968 SetPropA( wnd
->hwndSelf
, atomInternalPos
, (HANDLE
)lpPos
);
969 lpPos
->hwndIconTitle
= 0; /* defer until needs to be shown */
970 CONV_RECT32TO16( &wnd
->rectWindow
, &lpPos
->rectNormal
);
971 *(UINT
*)&lpPos
->ptIconPos
= *(UINT
*)&lpPos
->ptMaxPos
= 0xFFFFFFFF;
974 if( wnd
->dwStyle
& WS_MINIMIZE
)
975 CONV_POINT32TO16( &pt
, &lpPos
->ptIconPos
);
976 else if( wnd
->dwStyle
& WS_MAXIMIZE
)
977 CONV_POINT32TO16( &pt
, &lpPos
->ptMaxPos
);
978 else if( restoreRect
)
979 CONV_RECT32TO16( restoreRect
, &lpPos
->rectNormal
);
984 /***********************************************************************
985 * WINPOS_RedrawIconTitle
987 BOOL
WINPOS_RedrawIconTitle( HWND hWnd
)
989 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hWnd
, atomInternalPos
);
992 if( lpPos
->hwndIconTitle
)
994 SendMessageA( lpPos
->hwndIconTitle
, WM_SHOWWINDOW
, TRUE
, 0);
995 InvalidateRect( lpPos
->hwndIconTitle
, NULL
, TRUE
);
1002 /***********************************************************************
1003 * WINPOS_ShowIconTitle
1005 BOOL
WINPOS_ShowIconTitle( HWND hwnd
, BOOL bShow
)
1007 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
1009 if( lpPos
&& !(GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MANAGED
))
1011 HWND title
= lpPos
->hwndIconTitle
;
1013 TRACE("0x%04x %i\n", hwnd
, (bShow
!= 0) );
1016 lpPos
->hwndIconTitle
= title
= ICONTITLE_Create( hwnd
);
1019 if (!IsWindowVisible(title
))
1021 SendMessageA( title
, WM_SHOWWINDOW
, TRUE
, 0 );
1022 SetWindowPos( title
, 0, 0, 0, 0, 0, SWP_NOSIZE
| SWP_NOMOVE
|
1023 SWP_NOACTIVATE
| SWP_NOZORDER
| SWP_SHOWWINDOW
);
1026 else ShowWindow( title
, SW_HIDE
);
1031 /*******************************************************************
1032 * WINPOS_GetMinMaxInfo
1034 * Get the minimized and maximized information for a window.
1036 void WINPOS_GetMinMaxInfo( HWND hwnd
, POINT
*maxSize
, POINT
*maxPos
,
1037 POINT
*minTrack
, POINT
*maxTrack
)
1039 LPINTERNALPOS lpPos
;
1042 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1043 LONG exstyle
= GetWindowLongA( hwnd
, GWL_EXSTYLE
);
1045 /* Compute default values */
1047 MinMax
.ptMaxSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
1048 MinMax
.ptMaxSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
1049 MinMax
.ptMinTrackSize
.x
= GetSystemMetrics(SM_CXMINTRACK
);
1050 MinMax
.ptMinTrackSize
.y
= GetSystemMetrics(SM_CYMINTRACK
);
1051 MinMax
.ptMaxTrackSize
.x
= GetSystemMetrics(SM_CXSCREEN
);
1052 MinMax
.ptMaxTrackSize
.y
= GetSystemMetrics(SM_CYSCREEN
);
1054 if (HAS_DLGFRAME( style
, exstyle
))
1056 xinc
= GetSystemMetrics(SM_CXDLGFRAME
);
1057 yinc
= GetSystemMetrics(SM_CYDLGFRAME
);
1062 if (HAS_THICKFRAME(style
))
1064 xinc
+= GetSystemMetrics(SM_CXFRAME
);
1065 yinc
+= GetSystemMetrics(SM_CYFRAME
);
1067 if (style
& WS_BORDER
)
1069 xinc
+= GetSystemMetrics(SM_CXBORDER
);
1070 yinc
+= GetSystemMetrics(SM_CYBORDER
);
1073 MinMax
.ptMaxSize
.x
+= 2 * xinc
;
1074 MinMax
.ptMaxSize
.y
+= 2 * yinc
;
1076 lpPos
= (LPINTERNALPOS
)GetPropA( hwnd
, atomInternalPos
);
1077 if( lpPos
&& !EMPTYPOINT(lpPos
->ptMaxPos
) )
1078 CONV_POINT16TO32( &lpPos
->ptMaxPos
, &MinMax
.ptMaxPosition
);
1081 MinMax
.ptMaxPosition
.x
= -xinc
;
1082 MinMax
.ptMaxPosition
.y
= -yinc
;
1085 SendMessageA( hwnd
, WM_GETMINMAXINFO
, 0, (LPARAM
)&MinMax
);
1087 /* Some sanity checks */
1089 TRACE("%ld %ld / %ld %ld / %ld %ld / %ld %ld\n",
1090 MinMax
.ptMaxSize
.x
, MinMax
.ptMaxSize
.y
,
1091 MinMax
.ptMaxPosition
.x
, MinMax
.ptMaxPosition
.y
,
1092 MinMax
.ptMaxTrackSize
.x
, MinMax
.ptMaxTrackSize
.y
,
1093 MinMax
.ptMinTrackSize
.x
, MinMax
.ptMinTrackSize
.y
);
1094 MinMax
.ptMaxTrackSize
.x
= max( MinMax
.ptMaxTrackSize
.x
,
1095 MinMax
.ptMinTrackSize
.x
);
1096 MinMax
.ptMaxTrackSize
.y
= max( MinMax
.ptMaxTrackSize
.y
,
1097 MinMax
.ptMinTrackSize
.y
);
1099 if (maxSize
) *maxSize
= MinMax
.ptMaxSize
;
1100 if (maxPos
) *maxPos
= MinMax
.ptMaxPosition
;
1101 if (minTrack
) *minTrack
= MinMax
.ptMinTrackSize
;
1102 if (maxTrack
) *maxTrack
= MinMax
.ptMaxTrackSize
;
1105 /***********************************************************************
1106 * ShowWindowAsync (USER32.@)
1108 * doesn't wait; returns immediately.
1109 * used by threads to toggle windows in other (possibly hanging) threads
1111 BOOL WINAPI
ShowWindowAsync( HWND hwnd
, INT cmd
)
1113 /* FIXME: does ShowWindow() return immediately ? */
1114 return ShowWindow(hwnd
, cmd
);
1118 /***********************************************************************
1119 * ShowWindow (USER.42)
1121 BOOL16 WINAPI
ShowWindow16( HWND16 hwnd
, INT16 cmd
)
1123 return ShowWindow(hwnd
,cmd
);
1127 /***********************************************************************
1128 * ShowWindow (USER32.@)
1130 BOOL WINAPI
ShowWindow( HWND hwnd
, INT cmd
)
1132 return USER_Driver
.pShowWindow( hwnd
, cmd
);
1136 /***********************************************************************
1137 * GetInternalWindowPos (USER.460)
1139 UINT16 WINAPI
GetInternalWindowPos16( HWND16 hwnd
, LPRECT16 rectWnd
,
1142 WINDOWPLACEMENT16 wndpl
;
1143 if (GetWindowPlacement16( hwnd
, &wndpl
))
1145 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1146 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1147 return wndpl
.showCmd
;
1153 /***********************************************************************
1154 * GetInternalWindowPos (USER32.@)
1156 UINT WINAPI
GetInternalWindowPos( HWND hwnd
, LPRECT rectWnd
,
1159 WINDOWPLACEMENT wndpl
;
1160 if (GetWindowPlacement( hwnd
, &wndpl
))
1162 if (rectWnd
) *rectWnd
= wndpl
.rcNormalPosition
;
1163 if (ptIcon
) *ptIcon
= wndpl
.ptMinPosition
;
1164 return wndpl
.showCmd
;
1169 /***********************************************************************
1170 * GetWindowPlacement (USER.370)
1172 BOOL16 WINAPI
GetWindowPlacement16( HWND16 hwnd
, WINDOWPLACEMENT16
*wndpl
)
1174 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
1175 LPINTERNALPOS lpPos
;
1177 if(!pWnd
) return FALSE
;
1179 lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
1180 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
1181 wndpl
->length
= sizeof(*wndpl
);
1182 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1183 wndpl
->showCmd
= SW_SHOWMINIMIZED
;
1185 wndpl
->showCmd
= ( pWnd
->dwStyle
& WS_MAXIMIZE
)
1186 ? SW_SHOWMAXIMIZED
: SW_SHOWNORMAL
;
1187 if( pWnd
->flags
& WIN_RESTORE_MAX
)
1188 wndpl
->flags
= WPF_RESTORETOMAXIMIZED
;
1191 wndpl
->ptMinPosition
= lpPos
->ptIconPos
;
1192 wndpl
->ptMaxPosition
= lpPos
->ptMaxPos
;
1193 wndpl
->rcNormalPosition
= lpPos
->rectNormal
;
1195 WIN_ReleaseWndPtr(pWnd
);
1200 /***********************************************************************
1201 * GetWindowPlacement (USER32.@)
1204 * Fails if wndpl->length of Win95 (!) apps is invalid.
1206 BOOL WINAPI
GetWindowPlacement( HWND hwnd
, WINDOWPLACEMENT
*pwpl32
)
1210 WINDOWPLACEMENT16 wpl
;
1211 wpl
.length
= sizeof(wpl
);
1212 if( GetWindowPlacement16( hwnd
, &wpl
) )
1214 pwpl32
->length
= sizeof(*pwpl32
);
1215 pwpl32
->flags
= wpl
.flags
;
1216 pwpl32
->showCmd
= wpl
.showCmd
;
1217 CONV_POINT16TO32( &wpl
.ptMinPosition
, &pwpl32
->ptMinPosition
);
1218 CONV_POINT16TO32( &wpl
.ptMaxPosition
, &pwpl32
->ptMaxPosition
);
1219 CONV_RECT16TO32( &wpl
.rcNormalPosition
, &pwpl32
->rcNormalPosition
);
1227 /***********************************************************************
1228 * WINPOS_SetPlacement
1230 static BOOL
WINPOS_SetPlacement( HWND hwnd
, const WINDOWPLACEMENT16
*wndpl
,
1233 WND
*pWnd
= WIN_FindWndPtr( hwnd
);
1236 LPINTERNALPOS lpPos
= (LPINTERNALPOS
)WINPOS_InitInternalPos( pWnd
,
1237 *(LPPOINT
)&pWnd
->rectWindow
.left
, &pWnd
->rectWindow
);
1239 if( flags
& PLACE_MIN
) lpPos
->ptIconPos
= wndpl
->ptMinPosition
;
1240 if( flags
& PLACE_MAX
) lpPos
->ptMaxPos
= wndpl
->ptMaxPosition
;
1241 if( flags
& PLACE_RECT
) lpPos
->rectNormal
= wndpl
->rcNormalPosition
;
1243 if( pWnd
->dwStyle
& WS_MINIMIZE
)
1245 WINPOS_ShowIconTitle( pWnd
->hwndSelf
, FALSE
);
1246 if( wndpl
->flags
& WPF_SETMINPOSITION
&& !EMPTYPOINT(lpPos
->ptIconPos
))
1247 SetWindowPos( hwnd
, 0, lpPos
->ptIconPos
.x
, lpPos
->ptIconPos
.y
,
1248 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1250 else if( pWnd
->dwStyle
& WS_MAXIMIZE
)
1252 if( !EMPTYPOINT(lpPos
->ptMaxPos
) )
1253 SetWindowPos( hwnd
, 0, lpPos
->ptMaxPos
.x
, lpPos
->ptMaxPos
.y
,
1254 0, 0, SWP_NOSIZE
| SWP_NOZORDER
| SWP_NOACTIVATE
);
1256 else if( flags
& PLACE_RECT
)
1257 SetWindowPos( hwnd
, 0, lpPos
->rectNormal
.left
, lpPos
->rectNormal
.top
,
1258 lpPos
->rectNormal
.right
- lpPos
->rectNormal
.left
,
1259 lpPos
->rectNormal
.bottom
- lpPos
->rectNormal
.top
,
1260 SWP_NOZORDER
| SWP_NOACTIVATE
);
1262 ShowWindow( hwnd
, wndpl
->showCmd
);
1263 if( IsWindow(hwnd
) && pWnd
->dwStyle
& WS_MINIMIZE
)
1265 if( pWnd
->dwStyle
& WS_VISIBLE
) WINPOS_ShowIconTitle( pWnd
->hwndSelf
, TRUE
);
1267 /* SDK: ...valid only the next time... */
1268 if( wndpl
->flags
& WPF_RESTORETOMAXIMIZED
) pWnd
->flags
|= WIN_RESTORE_MAX
;
1270 WIN_ReleaseWndPtr(pWnd
);
1277 /***********************************************************************
1278 * SetWindowPlacement (USER.371)
1280 BOOL16 WINAPI
SetWindowPlacement16(HWND16 hwnd
, const WINDOWPLACEMENT16
*wndpl
)
1282 return WINPOS_SetPlacement( hwnd
, wndpl
,
1283 PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1286 /***********************************************************************
1287 * SetWindowPlacement (USER32.@)
1290 * Fails if wndpl->length of Win95 (!) apps is invalid.
1292 BOOL WINAPI
SetWindowPlacement( HWND hwnd
, const WINDOWPLACEMENT
*pwpl32
)
1296 WINDOWPLACEMENT16 wpl
;
1298 wpl
.length
= sizeof(WINDOWPLACEMENT16
);
1299 wpl
.flags
= pwpl32
->flags
;
1300 wpl
.showCmd
= pwpl32
->showCmd
;
1301 wpl
.ptMinPosition
.x
= pwpl32
->ptMinPosition
.x
;
1302 wpl
.ptMinPosition
.y
= pwpl32
->ptMinPosition
.y
;
1303 wpl
.ptMaxPosition
.x
= pwpl32
->ptMaxPosition
.x
;
1304 wpl
.ptMaxPosition
.y
= pwpl32
->ptMaxPosition
.y
;
1305 wpl
.rcNormalPosition
.left
= pwpl32
->rcNormalPosition
.left
;
1306 wpl
.rcNormalPosition
.top
= pwpl32
->rcNormalPosition
.top
;
1307 wpl
.rcNormalPosition
.right
= pwpl32
->rcNormalPosition
.right
;
1308 wpl
.rcNormalPosition
.bottom
= pwpl32
->rcNormalPosition
.bottom
;
1310 return WINPOS_SetPlacement( hwnd
, &wpl
, PLACE_MIN
| PLACE_MAX
| PLACE_RECT
);
1316 /***********************************************************************
1317 * SetInternalWindowPos (USER.461)
1319 void WINAPI
SetInternalWindowPos16( HWND16 hwnd
, UINT16 showCmd
,
1320 LPRECT16 rect
, LPPOINT16 pt
)
1322 if( IsWindow16(hwnd
) )
1324 WINDOWPLACEMENT16 wndpl
;
1327 wndpl
.length
= sizeof(wndpl
);
1328 wndpl
.showCmd
= showCmd
;
1329 wndpl
.flags
= flags
= 0;
1334 wndpl
.flags
|= WPF_SETMINPOSITION
;
1335 wndpl
.ptMinPosition
= *pt
;
1339 flags
|= PLACE_RECT
;
1340 wndpl
.rcNormalPosition
= *rect
;
1342 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1346 /***********************************************************************
1347 * AnimateWindow (USER32.@)
1348 * Shows/Hides a window with an animation
1351 BOOL WINAPI
AnimateWindow(HWND hwnd
, DWORD dwTime
, DWORD dwFlags
)
1353 FIXME("partial stub\n");
1355 /* If trying to show/hide and it's already *
1356 * shown/hidden or invalid window, fail with *
1357 * invalid parameter */
1358 if(!IsWindow(hwnd
) ||
1359 (IsWindowVisible(hwnd
) && !(dwFlags
& AW_HIDE
)) ||
1360 (!IsWindowVisible(hwnd
) && (dwFlags
& AW_HIDE
)))
1362 SetLastError(ERROR_INVALID_PARAMETER
);
1366 ShowWindow(hwnd
, (dwFlags
& AW_HIDE
) ? SW_HIDE
: ((dwFlags
& AW_ACTIVATE
) ? SW_SHOW
: SW_SHOWNA
));
1371 /***********************************************************************
1372 * SetInternalWindowPos (USER32.@)
1374 void WINAPI
SetInternalWindowPos( HWND hwnd
, UINT showCmd
,
1375 LPRECT rect
, LPPOINT pt
)
1377 if( IsWindow(hwnd
) )
1379 WINDOWPLACEMENT16 wndpl
;
1382 wndpl
.length
= sizeof(wndpl
);
1383 wndpl
.showCmd
= showCmd
;
1384 wndpl
.flags
= flags
= 0;
1389 wndpl
.flags
|= WPF_SETMINPOSITION
;
1390 CONV_POINT32TO16( pt
, &wndpl
.ptMinPosition
);
1394 flags
|= PLACE_RECT
;
1395 CONV_RECT32TO16( rect
, &wndpl
.rcNormalPosition
);
1397 WINPOS_SetPlacement( hwnd
, &wndpl
, flags
);
1401 /*******************************************************************
1402 * WINPOS_SetActiveWindow
1404 * SetActiveWindow() back-end. This is the only function that
1405 * can assign active status to a window. It must be called only
1406 * for the top level windows.
1408 BOOL
WINPOS_SetActiveWindow( HWND hWnd
, BOOL fMouse
, BOOL fChangeFocus
)
1410 WND
* wndPtr
=0, *wndTemp
;
1411 HQUEUE16 hOldActiveQueue
, hNewActiveQueue
;
1412 MESSAGEQUEUE
*pOldActiveQueue
= 0, *pNewActiveQueue
= 0;
1414 HWND hwndActive
= 0;
1417 TRACE("(%04x, %d, %d)\n", hWnd
, fMouse
, fChangeFocus
);
1419 /* Get current active window from the active queue */
1422 pOldActiveQueue
= QUEUE_Lock( hActiveQueue
);
1423 if ( pOldActiveQueue
)
1424 hwndActive
= PERQDATA_GetActiveWnd( pOldActiveQueue
->pQData
);
1427 if ((wndPtr
= WIN_FindWndPtr(hWnd
)))
1428 hWnd
= wndPtr
->hwndSelf
; /* make it a full handle */
1430 /* paranoid checks */
1431 if( hWnd
== GetDesktopWindow() || (bRet
= (hWnd
== hwndActive
)) )
1434 /* if (wndPtr && (GetFastQueue16() != wndPtr->hmemTaskQ))
1437 hOldActiveQueue
= hActiveQueue
;
1439 if( (wndTemp
= WIN_FindWndPtr(hwndActive
)) )
1441 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1442 WIN_ReleaseWndPtr(wndTemp
);
1445 TRACE("no current active window.\n");
1447 /* call CBT hook chain */
1448 if (HOOK_IsHooked( WH_CBT
))
1450 CBTACTIVATESTRUCT cbt
;
1451 cbt
.fMouse
= fMouse
;
1452 cbt
.hWndActive
= hwndActive
;
1453 if (HOOK_CallHooksA( WH_CBT
, HCBT_ACTIVATE
, hWnd
, (LPARAM
)&cbt
)) goto CLEANUP_END
;
1456 /* set prev active wnd to current active wnd and send notification */
1457 if ((hwndPrevActive
= hwndActive
) && IsWindow(hwndPrevActive
))
1459 MESSAGEQUEUE
*pTempActiveQueue
= 0;
1461 if (!SendMessageA( hwndPrevActive
, WM_NCACTIVATE
, FALSE
, 0 ))
1463 if (GetSysModalWindow16() != hWnd
)
1465 /* disregard refusal if hWnd is sysmodal */
1468 SendMessageA( hwndPrevActive
, WM_ACTIVATE
,
1469 MAKEWPARAM( WA_INACTIVE
, wIconized
),
1472 /* check if something happened during message processing
1473 * (global active queue may have changed)
1475 pTempActiveQueue
= QUEUE_Lock( hActiveQueue
);
1476 if(!pTempActiveQueue
)
1479 hwndActive
= PERQDATA_GetActiveWnd( pTempActiveQueue
->pQData
);
1480 QUEUE_Unlock( pTempActiveQueue
);
1481 if( hwndPrevActive
!= hwndActive
)
1485 /* Set new active window in the message queue */
1489 pNewActiveQueue
= QUEUE_Lock( wndPtr
->hmemTaskQ
);
1490 if ( pNewActiveQueue
)
1491 PERQDATA_SetActiveWnd( pNewActiveQueue
->pQData
, hwndActive
);
1493 else /* have to do this or MDI frame activation goes to hell */
1494 if( pOldActiveQueue
)
1495 PERQDATA_SetActiveWnd( pOldActiveQueue
->pQData
, 0 );
1497 /* send palette messages */
1498 if (hWnd
&& SendMessageW( hWnd
, WM_QUERYNEWPALETTE
, 0, 0L))
1499 SendMessageW( HWND_BROADCAST
, WM_PALETTEISCHANGING
, (WPARAM
)hWnd
, 0 );
1501 /* if prev wnd is minimized redraw icon title */
1502 if( IsIconic( hwndPrevActive
) ) WINPOS_RedrawIconTitle(hwndPrevActive
);
1504 /* managed windows will get ConfigureNotify event */
1505 if (wndPtr
&& !(wndPtr
->dwStyle
& WS_CHILD
) && !(wndPtr
->dwExStyle
& WS_EX_MANAGED
))
1507 /* check Z-order and bring hWnd to the top */
1508 HWND tmp
= GetTopWindow(0);
1509 while (tmp
&& !(GetWindowLongA( tmp
, GWL_STYLE
) & WS_VISIBLE
))
1510 tmp
= GetWindow( tmp
, GW_HWNDNEXT
);
1513 SetWindowPos(hWnd
, HWND_TOP
, 0,0,0,0,
1514 SWP_NOSIZE
| SWP_NOMOVE
| SWP_NOACTIVATE
);
1515 if (!IsWindow(hWnd
))
1519 /* Get a handle to the new active queue */
1520 hNewActiveQueue
= wndPtr
? wndPtr
->hmemTaskQ
: 0;
1522 /* send WM_ACTIVATEAPP if necessary */
1523 if (hOldActiveQueue
!= hNewActiveQueue
)
1526 DWORD old_thread
= GetWindowThreadProcessId( hwndPrevActive
, NULL
);
1527 DWORD new_thread
= GetWindowThreadProcessId( hwndActive
, NULL
);
1529 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
1531 for (phwnd
= list
; *phwnd
; phwnd
++)
1533 if (!IsWindow( *phwnd
)) continue;
1534 if (GetWindowThreadProcessId( *phwnd
, NULL
) == old_thread
)
1535 SendMessageW( *phwnd
, WM_ACTIVATEAPP
, 0, new_thread
);
1537 HeapFree( GetProcessHeap(), 0, list
);
1540 hActiveQueue
= hNewActiveQueue
;
1542 if ((list
= WIN_ListChildren( GetDesktopWindow() )))
1544 for (phwnd
= list
; *phwnd
; phwnd
++)
1546 if (!IsWindow( *phwnd
)) continue;
1547 if (GetWindowThreadProcessId( *phwnd
, NULL
) == new_thread
)
1548 SendMessageW( *phwnd
, WM_ACTIVATEAPP
, 1, old_thread
);
1550 HeapFree( GetProcessHeap(), 0, list
);
1553 if (hWnd
&& !IsWindow(hWnd
)) goto CLEANUP
;
1558 /* walk up to the first unowned window */
1559 HWND tmp
= GetAncestor( hWnd
, GA_ROOTOWNER
);
1560 wndTemp
= WIN_FindWndPtr( tmp
);
1561 /* and set last active owned popup */
1562 wndTemp
->hwndLastActive
= hWnd
;
1564 wIconized
= HIWORD(wndTemp
->dwStyle
& WS_MINIMIZE
);
1565 WIN_ReleaseWndPtr(wndTemp
);
1566 SendMessageA( hWnd
, WM_NCACTIVATE
, TRUE
, 0 );
1567 SendMessageA( hWnd
, WM_ACTIVATE
,
1568 MAKEWPARAM( (fMouse
) ? WA_CLICKACTIVE
: WA_ACTIVE
, wIconized
),
1569 (LPARAM
)hwndPrevActive
);
1570 if( !IsWindow(hWnd
) ) goto CLEANUP
;
1573 /* change focus if possible */
1576 if ( pNewActiveQueue
)
1578 HWND hOldFocus
= PERQDATA_GetFocusWnd( pNewActiveQueue
->pQData
);
1580 if ( hOldFocus
&& GetAncestor( hOldFocus
, GA_ROOT
) != hwndActive
)
1581 FOCUS_SwitchFocus( pNewActiveQueue
, hOldFocus
,
1582 (wndPtr
&& (wndPtr
->dwStyle
& WS_MINIMIZE
))?
1586 if ( pOldActiveQueue
&&
1587 ( !pNewActiveQueue
||
1588 pNewActiveQueue
->pQData
!= pOldActiveQueue
->pQData
) )
1590 HWND hOldFocus
= PERQDATA_GetFocusWnd( pOldActiveQueue
->pQData
);
1592 FOCUS_SwitchFocus( pOldActiveQueue
, hOldFocus
, 0 );
1596 if( !hwndPrevActive
&& wndPtr
)
1598 if (USER_Driver
.pForceWindowRaise
) USER_Driver
.pForceWindowRaise( wndPtr
->hwndSelf
);
1601 /* if active wnd is minimized redraw icon title */
1602 if( IsIconic(hwndActive
) ) WINPOS_RedrawIconTitle(hwndActive
);
1604 bRet
= (hWnd
== hwndActive
); /* Success? */
1606 CLEANUP
: /* Unlock the message queues before returning */
1608 if ( pNewActiveQueue
)
1609 QUEUE_Unlock( pNewActiveQueue
);
1613 if ( pOldActiveQueue
)
1614 QUEUE_Unlock( pOldActiveQueue
);
1616 WIN_ReleaseWndPtr(wndPtr
);
1620 /*******************************************************************
1621 * WINPOS_ActivateOtherWindow
1623 * Activates window other than pWnd.
1625 BOOL
WINPOS_ActivateOtherWindow(HWND hwnd
)
1629 HWND hwndActive
= 0;
1633 /* Get current active window from the active queue */
1636 MESSAGEQUEUE
*pActiveQueue
= QUEUE_Lock( hActiveQueue
);
1639 hwndActive
= PERQDATA_GetActiveWnd( pActiveQueue
->pQData
);
1640 QUEUE_Unlock( pActiveQueue
);
1644 pWnd
= WIN_FindWndPtr( hwnd
);
1645 hwnd
= pWnd
->hwndSelf
;
1647 if( hwnd
== hwndPrevActive
)
1650 if( hwndActive
!= hwnd
&&
1651 ( hwndActive
|| QUEUE_IsExitingQueue(pWnd
->hmemTaskQ
)) )
1653 WIN_ReleaseWndPtr( pWnd
);
1657 owner
= GetWindow( hwnd
, GW_OWNER
);
1658 if( !(pWnd
->dwStyle
& WS_POPUP
) || !owner
||
1659 !WINPOS_CanActivate((hwndTo
= GetAncestor( owner
, GA_ROOT
))) )
1661 HWND tmp
= GetAncestor( hwnd
, GA_ROOT
);
1662 hwndTo
= hwndPrevActive
;
1664 while( !WINPOS_CanActivate(hwndTo
) )
1666 /* by now owned windows should've been taken care of */
1667 tmp
= hwndTo
= GetWindow( tmp
, GW_HWNDNEXT
);
1668 if( !hwndTo
) break;
1671 WIN_ReleaseWndPtr( pWnd
);
1673 bRet
= WINPOS_SetActiveWindow( hwndTo
, FALSE
, TRUE
);
1679 /*******************************************************************
1680 * WINPOS_ChangeActiveWindow
1683 BOOL
WINPOS_ChangeActiveWindow( HWND hWnd
, BOOL mouseMsg
)
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
);
1701 return WINPOS_SetActiveWindow( 0, mouseMsg
, TRUE
);
1703 if (!(wndPtr
= WIN_FindWndPtr(hWnd
))) return FALSE
;
1704 hWnd
= wndPtr
->hwndSelf
;
1706 /* child windows get WM_CHILDACTIVATE message */
1707 if( (wndPtr
->dwStyle
& (WS_CHILD
| WS_POPUP
)) == WS_CHILD
)
1709 WIN_ReleaseWndPtr(wndPtr
);
1710 return SendMessageA(hWnd
, WM_CHILDACTIVATE
, 0, 0L);
1713 if( hWnd
== hwndActive
)
1719 if( !WINPOS_SetActiveWindow(hWnd
,mouseMsg
,TRUE
) )
1727 WIN_ReleaseWndPtr(wndPtr
);
1732 /***********************************************************************
1733 * WINPOS_SendNCCalcSize
1735 * Send a WM_NCCALCSIZE message to a window.
1736 * All parameters are read-only except newClientRect.
1737 * oldWindowRect, oldClientRect and winpos must be non-NULL only
1738 * when calcValidRect is TRUE.
1740 LONG
WINPOS_SendNCCalcSize( HWND hwnd
, BOOL calcValidRect
,
1741 RECT
*newWindowRect
, RECT
*oldWindowRect
,
1742 RECT
*oldClientRect
, WINDOWPOS
*winpos
,
1743 RECT
*newClientRect
)
1745 NCCALCSIZE_PARAMS params
;
1746 WINDOWPOS winposCopy
;
1749 params
.rgrc
[0] = *newWindowRect
;
1752 winposCopy
= *winpos
;
1753 params
.rgrc
[1] = *oldWindowRect
;
1754 params
.rgrc
[2] = *oldClientRect
;
1755 params
.lppos
= &winposCopy
;
1757 result
= SendMessageA( hwnd
, WM_NCCALCSIZE
, calcValidRect
,
1759 TRACE("%d,%d-%d,%d\n",
1760 params
.rgrc
[0].left
, params
.rgrc
[0].top
,
1761 params
.rgrc
[0].right
, params
.rgrc
[0].bottom
);
1763 /* If the application send back garbage, ignore it */
1764 if (params
.rgrc
[0].left
<= params
.rgrc
[0].right
&& params
.rgrc
[0].top
<= params
.rgrc
[0].bottom
)
1765 *newClientRect
= params
.rgrc
[0];
1771 /***********************************************************************
1772 * WINPOS_HandleWindowPosChanging16
1774 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1776 LONG
WINPOS_HandleWindowPosChanging16( HWND hwnd
, WINDOWPOS16
*winpos
)
1778 POINT maxSize
, minTrack
;
1779 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1781 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1782 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1784 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1785 if (maxSize
.x
< winpos
->cx
) winpos
->cx
= maxSize
.x
;
1786 if (maxSize
.y
< winpos
->cy
) winpos
->cy
= maxSize
.y
;
1787 if (!(style
& WS_MINIMIZE
))
1789 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1790 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1797 /***********************************************************************
1798 * WINPOS_HandleWindowPosChanging
1800 * Default handling for a WM_WINDOWPOSCHANGING. Called from DefWindowProc().
1802 LONG
WINPOS_HandleWindowPosChanging( HWND hwnd
, WINDOWPOS
*winpos
)
1804 POINT maxSize
, minTrack
;
1805 LONG style
= GetWindowLongA( hwnd
, GWL_STYLE
);
1807 if (winpos
->flags
& SWP_NOSIZE
) return 0;
1808 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
1810 WINPOS_GetMinMaxInfo( hwnd
, &maxSize
, NULL
, &minTrack
, NULL
);
1811 winpos
->cx
= min( winpos
->cx
, maxSize
.x
);
1812 winpos
->cy
= min( winpos
->cy
, maxSize
.y
);
1813 if (!(style
& WS_MINIMIZE
))
1815 if (winpos
->cx
< minTrack
.x
) winpos
->cx
= minTrack
.x
;
1816 if (winpos
->cy
< minTrack
.y
) winpos
->cy
= minTrack
.y
;
1822 /***********************************************************************
1823 * SetWindowPos (USER.232)
1825 BOOL16 WINAPI
SetWindowPos16( HWND16 hwnd
, HWND16 hwndInsertAfter
,
1826 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
, WORD flags
)
1828 return SetWindowPos(hwnd
,(INT
)(INT16
)hwndInsertAfter
,x
,y
,cx
,cy
,flags
);
1831 /***********************************************************************
1832 * SetWindowPos (USER32.@)
1834 BOOL WINAPI
SetWindowPos( HWND hwnd
, HWND hwndInsertAfter
,
1835 INT x
, INT y
, INT cx
, INT cy
, UINT flags
)
1840 winpos
.hwndInsertAfter
= hwndInsertAfter
;
1845 winpos
.flags
= flags
;
1846 return USER_Driver
.pSetWindowPos( &winpos
);
1850 /***********************************************************************
1851 * BeginDeferWindowPos (USER.259)
1853 HDWP16 WINAPI
BeginDeferWindowPos16( INT16 count
)
1855 return BeginDeferWindowPos( count
);
1859 /***********************************************************************
1860 * BeginDeferWindowPos (USER32.@)
1862 HDWP WINAPI
BeginDeferWindowPos( INT count
)
1869 SetLastError(ERROR_INVALID_PARAMETER
);
1872 /* Windows allows zero count, in which case it allocates context for 8 moves */
1873 if (count
== 0) count
= 8;
1875 handle
= USER_HEAP_ALLOC( sizeof(DWP
) + (count
-1)*sizeof(WINDOWPOS
) );
1876 if (!handle
) return 0;
1877 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( handle
);
1878 pDWP
->actualCount
= 0;
1879 pDWP
->suggestedCount
= count
;
1881 pDWP
->wMagic
= DWP_MAGIC
;
1882 pDWP
->hwndParent
= 0;
1887 /***********************************************************************
1888 * DeferWindowPos (USER.260)
1890 HDWP16 WINAPI
DeferWindowPos16( HDWP16 hdwp
, HWND16 hwnd
, HWND16 hwndAfter
,
1891 INT16 x
, INT16 y
, INT16 cx
, INT16 cy
,
1894 return DeferWindowPos( hdwp
, hwnd
, (INT
)(INT16
)hwndAfter
,
1895 x
, y
, cx
, cy
, flags
);
1899 /***********************************************************************
1900 * DeferWindowPos (USER32.@)
1902 HDWP WINAPI
DeferWindowPos( HDWP hdwp
, HWND hwnd
, HWND hwndAfter
,
1903 INT x
, INT y
, INT cx
, INT cy
,
1908 HDWP newhdwp
= hdwp
,retvalue
;
1912 hwnd
= WIN_GetFullHandle( hwnd
);
1913 if (hwnd
== GetDesktopWindow()) return 0;
1915 if (!(pDWP
= USER_HEAP_LIN_ADDR( hdwp
))) return 0;
1917 if (!(pWnd
= WIN_FindWndPtr( hwnd
))) return 0;
1919 /* Numega Bounds Checker Demo dislikes the following code.
1920 In fact, I've not been able to find any "same parent" requirement in any docu
1924 /* All the windows of a DeferWindowPos() must have the same parent */
1925 parent
= pWnd
->parent
->hwndSelf
;
1926 if (pDWP
->actualCount
== 0) pDWP
->hwndParent
= parent
;
1927 else if (parent
!= pDWP
->hwndParent
)
1929 USER_HEAP_FREE( hdwp
);
1935 for (i
= 0; i
< pDWP
->actualCount
; i
++)
1937 if (pDWP
->winPos
[i
].hwnd
== hwnd
)
1939 /* Merge with the other changes */
1940 if (!(flags
& SWP_NOZORDER
))
1942 pDWP
->winPos
[i
].hwndInsertAfter
= hwndAfter
;
1944 if (!(flags
& SWP_NOMOVE
))
1946 pDWP
->winPos
[i
].x
= x
;
1947 pDWP
->winPos
[i
].y
= y
;
1949 if (!(flags
& SWP_NOSIZE
))
1951 pDWP
->winPos
[i
].cx
= cx
;
1952 pDWP
->winPos
[i
].cy
= cy
;
1954 pDWP
->winPos
[i
].flags
&= flags
| ~(SWP_NOSIZE
| SWP_NOMOVE
|
1955 SWP_NOZORDER
| SWP_NOREDRAW
|
1956 SWP_NOACTIVATE
| SWP_NOCOPYBITS
|
1958 pDWP
->winPos
[i
].flags
|= flags
& (SWP_SHOWWINDOW
| SWP_HIDEWINDOW
|
1964 if (pDWP
->actualCount
>= pDWP
->suggestedCount
)
1966 newhdwp
= USER_HEAP_REALLOC( hdwp
,
1967 sizeof(DWP
) + pDWP
->suggestedCount
*sizeof(WINDOWPOS
) );
1973 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( newhdwp
);
1974 pDWP
->suggestedCount
++;
1976 pDWP
->winPos
[pDWP
->actualCount
].hwnd
= hwnd
;
1977 pDWP
->winPos
[pDWP
->actualCount
].hwndInsertAfter
= hwndAfter
;
1978 pDWP
->winPos
[pDWP
->actualCount
].x
= x
;
1979 pDWP
->winPos
[pDWP
->actualCount
].y
= y
;
1980 pDWP
->winPos
[pDWP
->actualCount
].cx
= cx
;
1981 pDWP
->winPos
[pDWP
->actualCount
].cy
= cy
;
1982 pDWP
->winPos
[pDWP
->actualCount
].flags
= flags
;
1983 pDWP
->actualCount
++;
1986 WIN_ReleaseWndPtr(pWnd
);
1991 /***********************************************************************
1992 * EndDeferWindowPos (USER.261)
1994 BOOL16 WINAPI
EndDeferWindowPos16( HDWP16 hdwp
)
1996 return EndDeferWindowPos( hdwp
);
2000 /***********************************************************************
2001 * EndDeferWindowPos (USER32.@)
2003 BOOL WINAPI
EndDeferWindowPos( HDWP hdwp
)
2010 pDWP
= (DWP
*) USER_HEAP_LIN_ADDR( hdwp
);
2011 if (!pDWP
) return FALSE
;
2012 for (i
= 0, winpos
= pDWP
->winPos
; i
< pDWP
->actualCount
; i
++, winpos
++)
2014 if (!(res
= USER_Driver
.pSetWindowPos( winpos
))) break;
2016 USER_HEAP_FREE( hdwp
);
2021 /***********************************************************************
2022 * TileChildWindows (USER.199)
2024 void WINAPI
TileChildWindows16( HWND16 parent
, WORD action
)
2026 FIXME("(%04x, %d): stub\n", parent
, action
);
2029 /***********************************************************************
2030 * CascadeChildWindows (USER.198)
2032 void WINAPI
CascadeChildWindows16( HWND16 parent
, WORD action
)
2034 FIXME("(%04x, %d): stub\n", parent
, action
);
2037 /***********************************************************************
2038 * SetProgmanWindow (USER32.@)
2040 HRESULT WINAPI
SetProgmanWindow ( HWND hwnd
)
2042 hGlobalProgmanWindow
= hwnd
;
2043 return hGlobalProgmanWindow
;
2046 /***********************************************************************
2047 * GetProgmanWindow (USER32.@)
2049 HRESULT WINAPI
GetProgmanWindow ( )
2051 return hGlobalProgmanWindow
;
2054 /***********************************************************************
2055 * SetShellWindowEx (USER32.@)
2056 * hwndProgman = Progman[Program Manager]
2057 * |-> SHELLDLL_DefView
2058 * hwndListView = | |-> SysListView32
2059 * | | |-> tooltips_class32
2065 HRESULT WINAPI
SetShellWindowEx ( HWND hwndProgman
, HWND hwndListView
)
2067 FIXME("0x%08x 0x%08x stub\n",hwndProgman
,hwndListView
);
2068 hGlobalShellWindow
= hwndProgman
;
2069 return hGlobalShellWindow
;
2073 /***********************************************************************
2074 * SetTaskmanWindow (USER32.@)
2076 * hwnd = MSTaskSwWClass
2077 * |-> SysTabControl32
2079 HRESULT WINAPI
SetTaskmanWindow ( HWND hwnd
)
2081 hGlobalTaskmanWindow
= hwnd
;
2082 return hGlobalTaskmanWindow
;
2085 /***********************************************************************
2086 * GetTaskmanWindow (USER32.@)
2088 HRESULT WINAPI
GetTaskmanWindow ( )
2090 return hGlobalTaskmanWindow
;