3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: dll/win32/user32/windows/defwnd.c
6 * PURPOSE: Window management
7 * PROGRAMMER: Casper S. Hornstrup (chorns@users.sourceforge.net)
9 * 06-06-2001 CSH Created
12 /* INCLUDES ******************************************************************/
16 #include <wine/debug.h>
17 WINE_DEFAULT_DEBUG_CHANNEL(user32
);
19 LRESULT
DefWndNCPaint(HWND hWnd
, HRGN hRgn
, BOOL Active
);
20 LRESULT
DefWndNCCalcSize(HWND hWnd
, BOOL CalcSizeStruct
, RECT
*Rect
);
21 LRESULT
DefWndNCActivate(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
22 LRESULT
DefWndNCHitTest(HWND hWnd
, POINT Point
);
23 LRESULT
DefWndNCLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
24 LRESULT
DefWndNCLButtonDblClk(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
25 LRESULT
NC_HandleNCRButtonDown( HWND hwnd
, WPARAM wParam
, LPARAM lParam
);
26 void FASTCALL
MenuInitSysMenuPopup(HMENU Menu
, DWORD Style
, DWORD ClsStyle
, LONG HitTest
);
27 void MENU_EndMenu( HWND
);
29 /* GLOBALS *******************************************************************/
31 static short iF10Key
= 0;
32 static short iMenuSysKey
= 0;
34 /* FUNCTIONS *****************************************************************/
42 GetSysColor(int nIndex
)
44 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
46 return gpsi
->argbSystem
[nIndex
];
49 SetLastError(ERROR_INVALID_PARAMETER
);
59 GetSysColorBrush(int nIndex
)
61 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
63 return gpsi
->ahbrSystem
[nIndex
];
66 SetLastError(ERROR_INVALID_PARAMETER
);
77 CONST INT
*lpaElements
,
78 CONST COLORREF
*lpaRgbValues
)
80 return NtUserSetSysColors(cElements
, lpaElements
, lpaRgbValues
, 0);
85 DefSetText(HWND hWnd
, PCWSTR String
, BOOL Ansi
)
88 LARGE_STRING lsString
;
93 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)&lsString
, (PCSZ
)String
, 0);
95 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)&lsString
, String
, 0);
97 Ret
= NtUserDefSetText(hWnd
, (String
? &lsString
: NULL
));
100 IntNotifyWinEvent(EVENT_OBJECT_NAMECHANGE
, hWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
106 UserGetInsideRectNC(PWND Wnd
, RECT
*rect
)
112 ExStyle
= Wnd
->ExStyle
;
114 rect
->top
= rect
->left
= 0;
115 rect
->right
= Wnd
->rcWindow
.right
- Wnd
->rcWindow
.left
;
116 rect
->bottom
= Wnd
->rcWindow
.bottom
- Wnd
->rcWindow
.top
;
118 if (Style
& WS_ICONIC
)
123 /* Remove frame from rectangle */
124 if (UserHasThickFrameStyle(Style
, ExStyle
))
126 InflateRect(rect
, -GetSystemMetrics(SM_CXFRAME
),
127 -GetSystemMetrics(SM_CYFRAME
));
131 if (UserHasDlgFrameStyle(Style
, ExStyle
))
133 InflateRect(rect
, -GetSystemMetrics(SM_CXDLGFRAME
),
134 -GetSystemMetrics(SM_CYDLGFRAME
));
135 /* FIXME: this isn't in NC_AdjustRect? why not? */
136 if (ExStyle
& WS_EX_DLGMODALFRAME
)
137 InflateRect( rect
, -1, 0 );
141 if (UserHasThinFrameStyle(Style
, ExStyle
))
143 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
),
144 -GetSystemMetrics(SM_CYBORDER
));
152 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
154 LONG Style
= GetWindowLongPtr(hWnd
, GWL_STYLE
);
155 /* Content can be redrawn after a change. */
158 if (!(Style
& WS_VISIBLE
)) /* Not Visible */
160 SetWindowLongPtr(hWnd
, GWL_STYLE
, WS_VISIBLE
);
163 else /* Content cannot be redrawn after a change. */
165 if (Style
& WS_VISIBLE
) /* Visible */
167 RedrawWindow( hWnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
168 Style
&= ~WS_VISIBLE
;
169 SetWindowLongPtr(hWnd
, GWL_STYLE
, Style
); /* clear bits */
177 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, ULONG Style
)
179 /* Not for child windows. */
180 if (hWnd
!= (HWND
)wParam
)
185 switch((INT_PTR
) LOWORD(lParam
))
189 WORD Msg
= HIWORD(lParam
);
190 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
191 Msg
== WM_RBUTTONDOWN
|| Msg
== WM_XBUTTONDOWN
)
200 HICON hCursor
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HCURSOR
);
212 if (Style
& WS_MAXIMIZE
)
216 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
222 if (Style
& WS_MAXIMIZE
)
226 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
232 if (Style
& WS_MAXIMIZE
)
236 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
242 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
)
246 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
249 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
253 DefWndStartSizeMove(HWND hWnd
, PWND Wnd
, WPARAM wParam
, POINT
*capturePoint
)
259 ULONG Style
= Wnd
->style
;
261 rectWindow
= Wnd
->rcWindow
;
263 if ((wParam
& 0xfff0) == SC_MOVE
)
265 /* Move pointer at the center of the caption */
267 UserGetInsideRectNC(Wnd
, &rect
);
268 if (Style
& WS_SYSMENU
)
269 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
270 if (Style
& WS_MINIMIZEBOX
)
271 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
272 if (Style
& WS_MAXIMIZEBOX
)
273 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
274 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
275 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
284 if (!GetMessageW(&msg
, NULL
, 0, 0)) break; //return 0;
285 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
290 hittest
= DefWndNCHitTest(hWnd
, msg
.pt
);
291 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
303 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
304 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
308 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
309 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
313 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
314 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
318 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
319 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
326 TranslateMessage( &msg
);
327 DispatchMessageW( &msg
);
333 SetCursorPos( pt
.x
, pt
.y
);
334 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
), Style
);
338 #define ON_LEFT_BORDER(hit) \
339 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
340 #define ON_RIGHT_BORDER(hit) \
341 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
342 #define ON_TOP_BORDER(hit) \
343 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
344 #define ON_BOTTOM_BORDER(hit) \
345 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
348 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
349 ULONG width
, ULONG height
)
351 static HBRUSH hDraggingRectBrush
= NULL
;
354 if(!hDraggingRectBrush
)
356 static HBITMAP hDraggingPattern
= NULL
;
357 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
359 hDraggingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
360 hDraggingRectBrush
= CreatePatternBrush(hDraggingPattern
);
363 hbrush
= SelectObject( hdc
, hDraggingRectBrush
);
364 PatBlt( hdc
, rect
->left
, rect
->top
,
365 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
366 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
367 rect
->bottom
- rect
->top
- height
, PATINVERT
);
368 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
369 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
370 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
371 rect
->bottom
- rect
->top
- height
, PATINVERT
);
372 SelectObject( hdc
, hbrush
);
376 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
380 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
), GetSystemMetrics(SM_CYFRAME
));
384 UserDrawWindowFrame(hdc
, rect
, 1, 1);
389 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
393 RECT sizingRect
, mouseRect
, origRect
, clipRect
, unmodRect
;
395 LONG hittest
= (LONG
)(wParam
& 0x0f);
396 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
397 POINT minTrack
, maxTrack
;
398 POINT capturePoint
, pt
;
399 ULONG Style
, ExStyle
;
403 DWORD dwPoint
= GetMessagePos();
404 BOOL DragFullWindows
= FALSE
;
405 HWND hWndParent
= NULL
;
408 Wnd
= ValidateHwnd(hwnd
);
413 ExStyle
= Wnd
->ExStyle
;
414 iconic
= (Style
& WS_MINIMIZE
) != 0;
416 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
418 pt
.x
= GET_X_LPARAM(dwPoint
);
419 pt
.y
= GET_Y_LPARAM(dwPoint
);
422 if ((Style
& WS_MAXIMIZE
) || !IsWindowVisible(hwnd
))
427 thickframe
= UserHasThickFrameStyle(Style
, ExStyle
) && !(Style
& WS_MINIMIZE
);
428 if ((wParam
& 0xfff0) == SC_MOVE
)
432 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
445 if (hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
))
447 hittest
+= (HTLEFT
- WMSZ_LEFT
);
452 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
461 /* Get min/max info */
463 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
464 sizingRect
= Wnd
->rcWindow
;
465 if (Style
& WS_CHILD
)
467 hWndParent
= GetParent(hwnd
);
468 MapWindowPoints( 0, hWndParent
, (LPPOINT
)&sizingRect
, 2 );
469 unmodRect
= sizingRect
;
470 GetClientRect(hWndParent
, &mouseRect
);
471 clipRect
= mouseRect
;
472 MapWindowPoints(hWndParent
, HWND_DESKTOP
, (LPPOINT
)&clipRect
, 2);
476 if(!(ExStyle
& WS_EX_TOPMOST
))
478 SystemParametersInfoW(SPI_GETWORKAREA
, 0, &clipRect
, 0);
479 mouseRect
= clipRect
;
483 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
484 clipRect
= mouseRect
;
486 unmodRect
= sizingRect
;
488 ClipCursor(&clipRect
);
490 origRect
= sizingRect
;
491 if (ON_LEFT_BORDER(hittest
))
493 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
494 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
496 else if (ON_RIGHT_BORDER(hittest
))
498 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
499 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
501 if (ON_TOP_BORDER(hittest
))
503 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
504 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
506 else if (ON_BOTTOM_BORDER(hittest
))
508 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
509 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
511 if (Style
& WS_CHILD
)
513 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
516 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
517 NtUserxSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, hwnd
);
518 if (GetCapture() != hwnd
) SetCapture( hwnd
);
520 if (Style
& WS_CHILD
)
522 /* Retrieve a default cache DC (without using the window style) */
523 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
529 DesktopRgn
= CreateRectRgnIndirect(&clipRect
);
532 SelectObject(hdc
, DesktopRgn
);
534 if( iconic
) /* create a cursor for dragging */
536 HICON hIcon
= (HICON
)GetClassLongPtrW(hwnd
, GCL_HICON
);
537 if(!hIcon
) hIcon
= (HICON
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
538 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
539 if( !hDragCursor
) iconic
= FALSE
;
542 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
543 if( !iconic
&& !DragFullWindows
)
545 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
552 if (!GetMessageW(&msg
, 0, 0, 0)) break;
553 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
555 /* Exit on button-up, Return, or Esc */
556 if ((msg
.message
== WM_LBUTTONUP
) ||
557 ((msg
.message
== WM_KEYDOWN
) &&
558 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
560 if (msg
.message
== WM_PAINT
)
562 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
563 UpdateWindow( msg
.hwnd
);
564 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
568 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
570 TranslateMessage( &msg
);
571 DispatchMessageW( &msg
);
572 continue; /* We are not interested in other messages */
577 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
579 case VK_UP
: pt
.y
-= 8; break;
580 case VK_DOWN
: pt
.y
+= 8; break;
581 case VK_LEFT
: pt
.x
-= 8; break;
582 case VK_RIGHT
: pt
.x
+= 8; break;
585 pt
.x
= max( pt
.x
, mouseRect
.left
);
586 pt
.x
= min( pt
.x
, mouseRect
.right
);
587 pt
.y
= max( pt
.y
, mouseRect
.top
);
588 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
590 dx
= pt
.x
- capturePoint
.x
;
591 dy
= pt
.y
- capturePoint
.y
;
599 if( iconic
) /* ok, no system popup tracking */
601 hOldCursor
= SetCursor(hDragCursor
);
606 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
609 RECT newRect
= unmodRect
;
610 WPARAM wpSizingHit
= 0;
612 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
613 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
614 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
615 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
616 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
617 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
620 /* determine the hit location */
621 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
622 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
624 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
629 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
631 /* To avoid any deadlocks, all the locks on the windows
632 structures must be suspended before the SetWindowPos */
633 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
634 newRect
.right
- newRect
.left
,
635 newRect
.bottom
- newRect
.top
,
636 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
639 sizingRect
= newRect
;
648 if( moved
) /* restore cursors, show icon title later on */
651 SetCursor( hOldCursor
);
653 DestroyCursor( hDragCursor
);
655 else if(!DragFullWindows
)
656 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
658 if (Style
& WS_CHILD
)
659 ReleaseDC( hWndParent
, hdc
);
665 DeleteObject(DesktopRgn
);
669 if (ISITHOOKED(WH_CBT
))
672 NtUserMessageCall( hwnd
, WM_CBT
, HCBT_MOVESIZE
, (LPARAM
)&sizingRect
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
673 if (lResult
) moved
= FALSE
;
676 NtUserxSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, NULL
);
677 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
678 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
680 /* window moved or resized */
683 /* if the moving/resizing isn't canceled call SetWindowPos
684 * with the new position or the new size of the window
686 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
688 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
690 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
691 sizingRect
.right
- sizingRect
.left
,
692 sizingRect
.bottom
- sizingRect
.top
,
693 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
695 else { /* restore previous size/position */
697 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
698 origRect
.right
- origRect
.left
,
699 origRect
.bottom
- origRect
.top
,
700 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
705 if( Style
& WS_MINIMIZE
)
707 /* Single click brings up the system menu when iconized */
711 if( Style
& WS_SYSMENU
)
712 SendMessageA( hwnd
, WM_SYSCOMMAND
,
713 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
719 /***********************************************************************
720 * DefWndTrackScrollBar
722 * Track a mouse button press on the horizontal or vertical scroll-bar.
725 DefWndTrackScrollBar(HWND Wnd
, WPARAM wParam
, POINT Pt
)
729 if (SC_HSCROLL
== (wParam
& 0xfff0))
731 if (HTHSCROLL
!= (wParam
& 0x0f))
737 else /* SC_VSCROLL */
739 if (HTVSCROLL
!= (wParam
& 0x0f))
745 ScrollTrackScrollBar(Wnd
, ScrollBar
, Pt
);
748 LRESULT WINAPI
DoAppSwitch( WPARAM wParam
, LPARAM lParam
);
751 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
753 // WINDOWPLACEMENT wp;
757 if (!IsWindowEnabled( hWnd
)) return 0;
759 if (ISITHOOKED(WH_CBT
))
761 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
762 if (lResult
) return 0;
765 switch (wParam
& 0xfff0)
769 DefWndDoSizeMove(hWnd
, wParam
);
772 if (hWnd
== GetActiveWindow())
773 ShowOwnedPopups(hWnd
,FALSE
);
774 ShowWindow( hWnd
, SW_MINIMIZE
);
778 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
779 ShowOwnedPopups(hWnd
,TRUE
);
780 ShowWindow( hWnd
, SW_MAXIMIZE
);
784 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
785 ShowOwnedPopups(hWnd
,TRUE
);
786 ShowWindow( hWnd
, SW_RESTORE
);
790 return SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
794 Pt
.x
= (short)LOWORD(lParam
);
795 Pt
.y
= (short)HIWORD(lParam
);
796 MenuTrackMouseMenuBar(hWnd
, wParam
& 0x000f, Pt
);
800 MenuTrackKbdMenuBar(hWnd
, wParam
, (WCHAR
)lParam
);
805 Pt
.x
= (short)LOWORD(lParam
);
806 Pt
.y
= (short)HIWORD(lParam
);
807 DefWndTrackScrollBar(hWnd
, wParam
, Pt
);
812 WinExec( "taskman.exe", SW_SHOWNORMAL
);
816 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
821 DoAppSwitch( wParam
, lParam
);
826 HWND hwnd
, hWndLastActive
;
830 pWnd
= ValidateHwnd(hwnd
);
833 hWndLastActive
= GetLastActivePopup(hwnd
);
836 hwnd
= hWndLastActive
;
837 pWnd
= ValidateHwnd(hwnd
);
839 SetForegroundWindow(hwnd
);
840 if (pWnd
->style
& WS_MINIMIZE
)
842 PostMessage(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
849 FIXME("Unimplemented DefWndHandleSysCommand wParam 0x%x\n",wParam
);
857 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
859 POINT maxTrack
, minTrack
;
860 LONG style
= GetWindowLongPtrA(hWnd
, GWL_STYLE
);
862 if (Pos
->flags
& SWP_NOSIZE
) return 0;
863 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
865 WinPosGetMinMaxInfo(hWnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
866 Pos
->cx
= min(Pos
->cx
, maxTrack
.x
);
867 Pos
->cy
= min(Pos
->cy
, maxTrack
.y
);
868 if (!(style
& WS_MINIMIZE
))
870 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
871 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
876 Pos
->cx
= max(Pos
->cx
, 0);
877 Pos
->cy
= max(Pos
->cy
, 0);
883 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
887 GetClientRect(hWnd
, &Rect
);
888 MapWindowPoints(hWnd
, (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
?
889 GetParent(hWnd
) : NULL
), (LPPOINT
) &Rect
, 2);
891 if (! (Pos
->flags
& SWP_NOCLIENTMOVE
))
893 SendMessageW(hWnd
, WM_MOVE
, 0, MAKELONG(Rect
.left
, Rect
.top
));
896 if (! (Pos
->flags
& SWP_NOCLIENTSIZE
))
898 WPARAM wp
= SIZE_RESTORED
;
903 else if (IsIconic(hWnd
))
907 SendMessageW(hWnd
, WM_SIZE
, wp
,
908 MAKELONG(Rect
.right
- Rect
.left
, Rect
.bottom
- Rect
.top
));
914 /***********************************************************************
917 * Default colors for control painting.
920 DefWndControlColor(HDC hDC
, UINT ctlType
)
922 if (ctlType
== CTLCOLOR_SCROLLBAR
)
924 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
925 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
926 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
929 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
930 * we better use 0x55aa bitmap brush to make scrollbar's background
931 * look different from the window background.
933 if ( bk
== GetSysColor(COLOR_WINDOW
))
934 return gpsi
->hbrGray
;
936 UnrealizeObject( hb
);
940 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
942 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
944 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
948 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
949 return GetSysColorBrush(COLOR_3DFACE
);
952 return GetSysColorBrush(COLOR_WINDOW
);
955 static void DefWndPrint( HWND hwnd
, HDC hdc
, ULONG uFlags
)
960 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
961 !IsWindowVisible(hwnd
) )
965 * Unimplemented flags.
967 if ( (uFlags
& PRF_CHILDREN
) ||
968 (uFlags
& PRF_OWNED
) ||
969 (uFlags
& PRF_NONCLIENT
) )
971 FIXME("WM_PRINT message with unsupported flags\n");
977 if ( uFlags
& PRF_ERASEBKGND
)
978 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
983 if ( uFlags
& PRF_CLIENT
)
984 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, uFlags
);
988 UserSendUiUpdateMsg(HWND hwnd
, LPARAM lParam
)
990 SendMessageW(hwnd
, WM_UPDATEUISTATE
, (WPARAM
)lParam
, 0);
996 DefWndSetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
998 HICON hIcon
, hIconSmall
, hIconOld
;
1000 if ( wParam
> ICON_SMALL2
)
1002 SetLastError(ERROR_INVALID_PARAMETER
);
1005 hIconSmall
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
1006 hIcon
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
1008 hIconOld
= wParam
== ICON_BIG
? hIcon
: hIconSmall
;
1013 hIcon
= (HICON
)lParam
;
1016 hIconSmall
= (HICON
)lParam
;
1019 ERR("FIXME: Set ICON_SMALL2 support!\n");
1024 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
, hIcon
);
1025 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
, hIconSmall
);
1027 if ((pWnd
->style
& WS_CAPTION
) == WS_CAPTION
)
1028 DefWndNCPaint(UserHMGetHandle(pWnd
), HRGN_WINDOW
, -1); /* Repaint caption */
1030 return (LRESULT
)hIconOld
;
1034 DefWndGetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
1037 if ( wParam
> ICON_SMALL2
)
1039 SetLastError(ERROR_INVALID_PARAMETER
);
1045 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
1049 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
1054 return (LRESULT
)hIconRet
;
1058 DefWndScreenshot(HWND hWnd
)
1067 OpenClipboard(hWnd
);
1070 hdc
= GetWindowDC(hWnd
);
1071 GetWindowRect(hWnd
, &rect
);
1072 w
= rect
.right
- rect
.left
;
1073 h
= rect
.bottom
- rect
.top
;
1075 hbitmap
= CreateCompatibleBitmap(hdc
, w
, h
);
1076 hdc2
= CreateCompatibleDC(hdc
);
1077 SelectObject(hdc2
, hbitmap
);
1079 BitBlt(hdc2
, 0, 0, w
, h
,
1083 SetClipboardData(CF_BITMAP
, hbitmap
);
1085 ReleaseDC(hWnd
, hdc
);
1086 ReleaseDC(hWnd
, hdc2
);
1095 User32DefWindowProc(HWND hWnd
,
1104 pWnd
= ValidateHwnd(hWnd
);
1105 if (!pWnd
) return 0;
1112 return DefWndNCPaint(hWnd
, (HRGN
)wParam
, -1);
1117 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
1120 case WM_POPUPSYSTEMMENU
:
1122 /* This is an undocumented message used by the windows taskbar to
1123 display the system menu of windows that belong to other processes. */
1124 HMENU menu
= GetSystemMenu(hWnd
, FALSE
);
1127 TrackPopupMenu(menu
, TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
1128 LOWORD(lParam
), HIWORD(lParam
), 0, hWnd
, NULL
);
1134 return DefWndNCActivate(hWnd
, wParam
, lParam
);
1140 Point
.x
= GET_X_LPARAM(lParam
);
1141 Point
.y
= GET_Y_LPARAM(lParam
);
1142 return (DefWndNCHitTest(hWnd
, Point
));
1145 case WM_LBUTTONDOWN
:
1146 case WM_RBUTTONDOWN
:
1147 case WM_MBUTTONDOWN
:
1148 iF10Key
= iMenuSysKey
= 0;
1151 case WM_NCLBUTTONDOWN
:
1153 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
1156 case WM_LBUTTONDBLCLK
:
1157 return (DefWndNCLButtonDblClk(hWnd
, HTCLIENT
, lParam
));
1159 case WM_NCLBUTTONDBLCLK
:
1161 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
1164 case WM_WINDOWPOSCHANGING
:
1166 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1169 case WM_WINDOWPOSCHANGED
:
1171 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
1174 case WM_NCRBUTTONDOWN
:
1175 return NC_HandleNCRButtonDown( hWnd
, wParam
, lParam
);
1180 if (hWnd
== GetCapture())
1184 Pt
.x
= GET_X_LPARAM(lParam
);
1185 Pt
.y
= GET_Y_LPARAM(lParam
);
1186 ClientToScreen(hWnd
, &Pt
);
1187 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1190 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1194 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1199 case WM_NCRBUTTONUP
:
1201 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
1202 * in Windows), but what _should_ we do? According to MSDN :
1203 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
1204 * message to the window". When is it appropriate?
1208 case WM_CONTEXTMENU
:
1210 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1214 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1218 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1227 Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1229 Pt
.x
= GET_X_LPARAM(lParam
);
1230 Pt
.y
= GET_Y_LPARAM(lParam
);
1231 if (Style
& WS_CHILD
)
1233 ScreenToClient(GetParent(hWnd
), &Pt
);
1236 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1238 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1243 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
1245 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongPtrW(hWnd
, GWL_STYLE
),
1246 GetClassLongPtrW(hWnd
, GCL_STYLE
), HitCode
);
1248 if(HitCode
== HTCAPTION
)
1249 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
1251 Flags
= TPM_LEFTBUTTON
;
1253 TrackPopupMenu(SystemMenu
, Flags
,
1254 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1263 DefWndPrint(hWnd
, (HDC
)wParam
, lParam
);
1267 case WM_SYSCOLORCHANGE
:
1269 /* force to redraw non-client area */
1270 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1271 /* Use InvalidateRect to redraw client area, enable
1272 * erase to redraw all subcontrols otherwise send the
1273 * WM_SYSCOLORCHANGE to child windows/controls is required
1275 InvalidateRect(hWnd
,NULL
,TRUE
);
1285 /* If already in Paint and Client area is not empty just return. */
1286 if (pWnd
->state2
& WNDS2_STARTPAINT
&& !IsRectEmpty(&pWnd
->rcClient
))
1288 ERR("In Paint and Client area is not empty!\n");
1292 hDC
= BeginPaint(hWnd
, &Ps
);
1297 if (IsIconic(hWnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hWnd
, GCLP_HICON
))))
1301 GetClientRect(hWnd
, &ClientRect
);
1302 x
= (ClientRect
.right
- ClientRect
.left
-
1303 GetSystemMetrics(SM_CXICON
)) / 2;
1304 y
= (ClientRect
.bottom
- ClientRect
.top
-
1305 GetSystemMetrics(SM_CYICON
)) / 2;
1306 DrawIcon(hDC
, x
, y
, hIcon
);
1308 EndPaint(hWnd
, &Ps
);
1316 hRgn = CreateRectRgn(0, 0, 0, 0);
1317 if (GetUpdateRgn(hWnd, hRgn, FALSE) != NULLREGION)
1319 RedrawWindow(hWnd, NULL, hRgn,
1320 RDW_ERASENOW | RDW_ERASE | RDW_FRAME |
1329 LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
1330 if (wParam) SetWindowLongPtr(hWnd, GWL_STYLE, Style | WS_VISIBLE);
1333 RedrawWindow(hWnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE);
1334 Style &= ~WS_VISIBLE;
1335 SetWindowLongPtr(hWnd, GWL_STYLE, Style);
1341 DestroyWindow(hWnd
);
1344 case WM_MOUSEACTIVATE
:
1345 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1347 LONG Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
1348 if (Ret
) return (Ret
);
1350 return ( (HIWORD(lParam
) == WM_LBUTTONDOWN
&& LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
);
1353 /* The default action in Windows is to set the keyboard focus to
1354 * the window, if it's being activated and not minimized */
1355 if (LOWORD(wParam
) != WA_INACTIVE
&&
1356 !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1358 //ERR("WM_ACTIVATE %p\n",hWnd);
1364 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1365 return SendMessageW( GetParent(hWnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
1369 case WM_ICONERASEBKGND
:
1372 HBRUSH hBrush
= (HBRUSH
)GetClassLongPtrW(hWnd
, GCL_HBRBACKGROUND
);
1378 if (GetClassLongPtrW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1380 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1381 GetClientRect(hWnd
, &Rect
);
1382 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1386 GetClipBox((HDC
)wParam
, &Rect
);
1388 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1392 case WM_CTLCOLORMSGBOX
:
1393 case WM_CTLCOLOREDIT
:
1394 case WM_CTLCOLORLISTBOX
:
1395 case WM_CTLCOLORBTN
:
1396 case WM_CTLCOLORDLG
:
1397 case WM_CTLCOLORSTATIC
:
1398 case WM_CTLCOLORSCROLLBAR
:
1399 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1402 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
1406 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1408 if (Style
& WS_CHILD
)
1410 /* with the exception of the border around a resizable wnd,
1411 * give the parent first chance to set the cursor */
1412 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1414 HWND parent
= GetParent( hWnd
);
1417 if (parent
!= GetDesktopWindow() &&
1418 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
))
1423 if (parent
!= GetDesktopWindow() &&
1424 SendMessageA( parent
, WM_SETCURSOR
, wParam
, lParam
))
1429 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1433 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
1436 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
1441 if (HIWORD(lParam
) & KF_ALTDOWN
)
1442 { /* Previous state, if the key was down before this message,
1443 this is a cheap way to ignore autorepeat keys. */
1444 if ( !(HIWORD(lParam
) & KF_REPEAT
) )
1446 if ( ( wParam
== VK_MENU
||
1447 wParam
== VK_LMENU
||
1448 wParam
== VK_RMENU
) && !iMenuSysKey
)
1456 if (wParam
== VK_F4
) /* Try to close the window */
1458 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1459 if (!(GetClassLongPtrW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1460 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1462 else if (wParam
== VK_SNAPSHOT
) // Alt-VK_SNAPSHOT?
1465 while (GetParent(hwnd
) != NULL
)
1467 hwnd
= GetParent(hwnd
);
1469 DefWndScreenshot(hwnd
);
1471 else if ( wParam
== VK_ESCAPE
|| wParam
== VK_TAB
) // Alt-Tab/ESC Alt-Shift-Tab/ESC
1474 HWND Active
= GetActiveWindow(); // Noticed MDI problem.
1477 FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n");
1480 wParamTmp
= GetKeyState(VK_SHIFT
) & 0x8000 ? SC_PREVWINDOW
: SC_NEXTWINDOW
;
1481 SendMessageW( Active
, WM_SYSCOMMAND
, wParamTmp
, wParam
);
1484 else if( wParam
== VK_F10
)
1486 if (GetKeyState(VK_SHIFT
) & 0x8000)
1487 SendMessageW( hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, MAKELPARAM(-1, -1) );
1496 /* Press and release F10 or ALT */
1497 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
1498 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
1499 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
1500 iMenuSysKey
= iF10Key
= 0;
1507 if (wParam
== VK_RETURN
&& IsIconic(hWnd
))
1509 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
1512 if ((HIWORD(lParam
) & KF_ALTDOWN
) && wParam
)
1514 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
1515 if (wParam
== VK_SPACE
&& (GetWindowLongPtrW( hWnd
, GWL_STYLE
) & WS_CHILD
))
1516 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
1518 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
1520 else /* check for Ctrl-Esc */
1521 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
1528 /* FIXME: Check for a desktop. */
1529 //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
1530 MENU_EndMenu( hWnd
);
1531 if (GetCapture() == hWnd
)
1545 case WM_QUERYDROPOBJECT
:
1547 if (GetWindowLongPtrW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1554 case WM_QUERYDRAGICON
:
1559 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HICON
);
1562 return ((LRESULT
)hIcon
);
1564 for (Len
= 1; Len
< 64; Len
++)
1566 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1568 return((LRESULT
)hIcon
);
1571 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1574 case WM_ISACTIVEICON
:
1577 isai
= (pWnd
->state
& WNDS_ACTIVEFRAME
) != 0;
1581 case WM_NOTIFYFORMAT
:
1583 if (lParam
== NF_QUERY
)
1584 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1590 return DefWndSetIcon(pWnd
, wParam
, lParam
);
1595 return DefWndGetIcon(pWnd
, wParam
, lParam
);
1602 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1606 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1613 THRDCARETINFO CaretInfo
;
1616 case 0xffff: /* Caret timer */
1617 /* switch showing byte in win32k and get information about the caret */
1618 if(NtUserxSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1620 DrawCaret(hWnd
, &CaretInfo
);
1628 case WM_QUERYENDSESSION
:
1633 case WM_INPUTLANGCHANGEREQUEST
:
1637 if(wParam
& INPUTLANGCHANGE_BACKWARD
1638 && wParam
& INPUTLANGCHANGE_FORWARD
)
1643 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1645 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1646 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1647 else NewHkl
= (HKL
) lParam
;
1649 NtUserActivateKeyboardLayout(NewHkl
, 0);
1654 case WM_INPUTLANGCHANGE
:
1657 HWND
*win_array
= WIN_ListChildren( hWnd
);
1661 while (win_array
[count
])
1662 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
1663 HeapFree(GetProcessHeap(),0,win_array
);
1667 case WM_QUERYUISTATE
:
1670 PWND Wnd
= ValidateHwnd(hWnd
);
1674 Ret
|= UISF_HIDEFOCUS
;
1676 Ret
|= UISF_HIDEACCEL
;
1681 case WM_CHANGEUISTATE
:
1683 BOOL AlwaysShowCues
= FALSE
;
1684 WORD Action
= LOWORD(wParam
);
1685 WORD Flags
= HIWORD(wParam
);
1688 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1692 Wnd
= ValidateHwnd(hWnd
);
1693 if (!Wnd
|| lParam
!= 0)
1696 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1699 if (Flags
& UISF_ACTIVE
)
1701 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1704 if (Action
== UIS_INITIALIZE
)
1706 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1710 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1711 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1713 /* We need to update wParam in case we need to send out messages */
1714 wParam
= MAKEWPARAM(Action
, Flags
);
1720 /* See if we actually need to change something */
1721 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1723 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1726 /* Don't need to do anything... */
1730 /* See if we actually need to change something */
1731 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1733 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1736 /* Don't need to do anything... */
1740 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1744 if ((Wnd
->style
& WS_CHILD
) && Wnd
->spwndParent
!= NULL
)
1746 /* We're a child window and we need to pass this message down until
1747 we reach the root */
1748 hWnd
= UserHMGetHandle((PWND
)DesktopPtrToUser(Wnd
->spwndParent
));
1752 /* We're a top level window, we need to change the UI state */
1753 Msg
= WM_UPDATEUISTATE
;
1757 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1759 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1762 case WM_UPDATEUISTATE
:
1765 BOOL AlwaysShowCues
= FALSE
;
1766 WORD Action
= LOWORD(wParam
);
1767 WORD Flags
= HIWORD(wParam
);
1770 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1774 Wnd
= ValidateHwnd(hWnd
);
1775 if (!Wnd
|| lParam
!= 0)
1778 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1781 if (Flags
& UISF_ACTIVE
)
1783 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1786 if (Action
== UIS_INITIALIZE
)
1788 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1792 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1793 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1795 /* We need to update wParam for broadcasting the update */
1796 wParam
= MAKEWPARAM(Action
, Flags
);
1802 /* See if we actually need to change something */
1803 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1805 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1808 /* Don't need to do anything... */
1813 /* See if we actually need to change something */
1814 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1816 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1819 /* Don't need to do anything... */
1824 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1828 /* Pack the information and call win32k */
1831 if (!NtUserxUpdateUiState(hWnd
, Flags
| ((DWORD
)Action
<< 3)))
1835 /* Always broadcast the update to all children */
1836 EnumChildWindows(hWnd
,
1837 UserSendUiUpdateMsg
,
1843 /* Move to win32k !*/
1845 if (!lParam
) break; // Call when it is necessary.
1848 case WM_CLIENTSHUTDOWN
:
1853 NtUserMessageCall( hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, !bUnicode
);
1862 * helpers for calling IMM32 (from Wine 10/22/2008)
1864 * WM_IME_* messages are generated only by IMM32,
1865 * so I assume imm32 is already LoadLibrary-ed.
1868 DefWndImmGetDefaultIMEWnd(HWND hwnd
)
1870 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1871 HWND (WINAPI
*pFunc
)(HWND
);
1876 ERR("cannot get IMM32 handle\n");
1880 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmGetDefaultIMEWnd");
1882 hwndRet
= (*pFunc
)(hwnd
);
1889 DefWndImmIsUIMessageA(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1891 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1892 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1897 ERR("cannot get IMM32 handle\n");
1901 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageA");
1903 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1910 DefWndImmIsUIMessageW(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1912 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1913 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1918 ERR("cannot get IMM32 handle\n");
1922 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageW");
1924 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1931 RealDefWindowProcA(HWND hWnd
,
1939 Wnd
= ValidateHwnd(hWnd
);
1942 Msg
!= WM_CTLCOLORMSGBOX
&&
1943 Msg
!= WM_CTLCOLORBTN
&&
1944 Msg
!= WM_CTLCOLORDLG
&&
1945 Msg
!= WM_CTLCOLORSTATIC
)
1948 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1954 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
1958 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
1959 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
1960 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
1966 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1967 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1968 * may have child window IDs instead of window name */
1969 if (HIWORD(cs
->lpszName
))
1971 DefSetText(hWnd
, (PCWSTR
)cs
->lpszName
, TRUE
);
1978 case WM_GETTEXTLENGTH
:
1983 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1985 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1987 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1989 Wnd
->strName
.Length
)))
1991 Result
= (LRESULT
) len
;
2002 PSTR outbuf
= (PSTR
)lParam
;
2005 if (Wnd
!= NULL
&& wParam
!= 0)
2007 if (Wnd
->strName
.Buffer
!= NULL
)
2008 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2014 if (Wnd
->strName
.Length
!= 0)
2016 copy
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2017 Result
= WideCharToMultiByte(CP_ACP
,
2025 outbuf
[Result
] = '\0';
2036 DefSetText(hWnd
, (PCWSTR
)lParam
, TRUE
);
2038 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2040 /* FIXME: this is not 100% correct */
2041 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2043 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2047 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2054 case WM_IME_KEYDOWN
:
2056 Result
= PostMessageA(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2062 Result
= PostMessageA(hWnd
, WM_KEYUP
, wParam
, lParam
);
2069 PostMessageA(hWnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
2070 PostMessageA(hWnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
2074 case WM_IME_STARTCOMPOSITION
:
2075 case WM_IME_COMPOSITION
:
2076 case WM_IME_ENDCOMPOSITION
:
2082 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2084 Result
= SendMessageA(hwndIME
, Msg
, wParam
, lParam
);
2088 case WM_IME_SETCONTEXT
:
2092 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2094 Result
= DefWndImmIsUIMessageA(hwndIME
, Msg
, wParam
, lParam
);
2100 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
2103 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2109 RealDefWindowProcW(HWND hWnd
,
2117 Wnd
= ValidateHwnd(hWnd
);
2120 Msg
!= WM_CTLCOLORMSGBOX
&&
2121 Msg
!= WM_CTLCOLORBTN
&&
2122 Msg
!= WM_CTLCOLORDLG
&&
2123 Msg
!= WM_CTLCOLORSTATIC
)
2126 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
2132 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
2136 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
2137 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
2138 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
2144 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
2145 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
2146 * may have child window IDs instead of window name */
2147 if (HIWORD(cs
->lpszName
))
2149 DefSetText(hWnd
, cs
->lpszName
, FALSE
);
2156 case WM_GETTEXTLENGTH
:
2161 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
2163 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2165 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
2167 Wnd
->strName
.Length
)))
2169 Result
= (LRESULT
) (Wnd
->strName
.Length
/ sizeof(WCHAR
));
2180 PWSTR outbuf
= (PWSTR
)lParam
;
2182 if (Wnd
!= NULL
&& wParam
!= 0)
2184 if (Wnd
->strName
.Buffer
!= NULL
)
2185 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2191 if (Wnd
->strName
.Length
!= 0)
2193 Result
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2194 RtlCopyMemory(outbuf
,
2196 Result
* sizeof(WCHAR
));
2197 outbuf
[Result
] = L
'\0';
2208 DefSetText(hWnd
, (PCWSTR
)lParam
, FALSE
);
2210 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2212 /* FIXME: this is not 100% correct */
2213 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2215 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2219 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2228 PostMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
2233 case WM_IME_KEYDOWN
:
2235 Result
= PostMessageW(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2241 Result
= PostMessageW(hWnd
, WM_KEYUP
, wParam
, lParam
);
2245 case WM_IME_STARTCOMPOSITION
:
2246 case WM_IME_COMPOSITION
:
2247 case WM_IME_ENDCOMPOSITION
:
2253 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2255 Result
= SendMessageW(hwndIME
, Msg
, wParam
, lParam
);
2259 case WM_IME_SETCONTEXT
:
2263 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2265 Result
= DefWndImmIsUIMessageW(hwndIME
, Msg
, wParam
, lParam
);
2270 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
2272 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2278 DefWindowProcA(HWND hWnd
,
2283 BOOL Hook
, msgOverride
= FALSE
;
2288 Hook
= BeginIfHookedUserApiHook();
2291 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2292 if(msgOverride
== FALSE
)
2298 /* Bypass SEH and go direct. */
2299 if (!Hook
|| !msgOverride
)
2300 return RealDefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2304 Result
= guah
.DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2306 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2317 DefWindowProcW(HWND hWnd
,
2322 BOOL Hook
, msgOverride
= FALSE
;
2327 Hook
= BeginIfHookedUserApiHook();
2330 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2331 if(msgOverride
== FALSE
)
2337 /* Bypass SEH and go direct. */
2338 if (!Hook
|| !msgOverride
)
2339 return RealDefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2343 Result
= guah
.DefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2345 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)