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 void FASTCALL
MenuInitSysMenuPopup(HMENU Menu
, DWORD Style
, DWORD ClsStyle
, LONG HitTest
);
26 void MENU_EndMenu( HWND
);
28 /* GLOBALS *******************************************************************/
30 static short iF10Key
= 0;
31 static short iMenuSysKey
= 0;
33 /* FUNCTIONS *****************************************************************/
39 GetSysColor(int nIndex
)
41 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
43 return gpsi
->argbSystem
[nIndex
];
46 SetLastError(ERROR_INVALID_PARAMETER
);
54 GetSysColorBrush(int nIndex
)
56 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
58 return gpsi
->ahbrSystem
[nIndex
];
61 SetLastError(ERROR_INVALID_PARAMETER
);
72 CONST INT
*lpaElements
,
73 CONST COLORREF
*lpaRgbValues
)
75 return NtUserSetSysColors(cElements
, lpaElements
, lpaRgbValues
, 0);
80 DefSetText(HWND hWnd
, PCWSTR String
, BOOL Ansi
)
83 LARGE_STRING lsString
;
88 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)&lsString
, (PCSZ
)String
, 0);
90 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)&lsString
, String
, 0);
92 Ret
= NtUserDefSetText(hWnd
, (String
? &lsString
: NULL
));
95 IntNotifyWinEvent(EVENT_OBJECT_NAMECHANGE
, hWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
101 UserGetInsideRectNC(PWND Wnd
, RECT
*rect
)
107 ExStyle
= Wnd
->ExStyle
;
109 rect
->top
= rect
->left
= 0;
110 rect
->right
= Wnd
->rcWindow
.right
- Wnd
->rcWindow
.left
;
111 rect
->bottom
= Wnd
->rcWindow
.bottom
- Wnd
->rcWindow
.top
;
113 if (Style
& WS_ICONIC
)
118 /* Remove frame from rectangle */
119 if (UserHasThickFrameStyle(Style
, ExStyle
))
121 InflateRect(rect
, -GetSystemMetrics(SM_CXFRAME
),
122 -GetSystemMetrics(SM_CYFRAME
));
126 if (UserHasDlgFrameStyle(Style
, ExStyle
))
128 InflateRect(rect
, -GetSystemMetrics(SM_CXDLGFRAME
),
129 -GetSystemMetrics(SM_CYDLGFRAME
));
130 /* FIXME: this isn't in NC_AdjustRect? why not? */
131 if (ExStyle
& WS_EX_DLGMODALFRAME
)
132 InflateRect( rect
, -1, 0 );
136 if (UserHasThinFrameStyle(Style
, ExStyle
))
138 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
),
139 -GetSystemMetrics(SM_CYBORDER
));
147 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
149 LONG Style
= GetWindowLongPtr(hWnd
, GWL_STYLE
);
150 /* Content can be redrawn after a change. */
153 if (!(Style
& WS_VISIBLE
)) /* Not Visible */
155 SetWindowLongPtr(hWnd
, GWL_STYLE
, WS_VISIBLE
);
158 else /* Content cannot be redrawn after a change. */
160 if (Style
& WS_VISIBLE
) /* Visible */
162 RedrawWindow( hWnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
163 Style
&= ~WS_VISIBLE
;
164 SetWindowLongPtr(hWnd
, GWL_STYLE
, Style
); /* clear bits */
172 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, ULONG Style
)
174 /* Not for child windows. */
175 if (hWnd
!= (HWND
)wParam
)
180 switch((INT_PTR
) LOWORD(lParam
))
184 WORD Msg
= HIWORD(lParam
);
185 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
186 Msg
== WM_RBUTTONDOWN
|| Msg
== WM_XBUTTONDOWN
)
195 HICON hCursor
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HCURSOR
);
207 if (Style
& WS_MAXIMIZE
)
211 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
217 if (Style
& WS_MAXIMIZE
)
221 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
227 if (Style
& WS_MAXIMIZE
)
231 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
237 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
)
241 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
244 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
248 DefWndStartSizeMove(HWND hWnd
, PWND Wnd
, WPARAM wParam
, POINT
*capturePoint
)
254 ULONG Style
= Wnd
->style
;
256 rectWindow
= Wnd
->rcWindow
;
258 if ((wParam
& 0xfff0) == SC_MOVE
)
260 /* Move pointer at the center of the caption */
262 UserGetInsideRectNC(Wnd
, &rect
);
263 if (Style
& WS_SYSMENU
)
264 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
265 if (Style
& WS_MINIMIZEBOX
)
266 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
267 if (Style
& WS_MAXIMIZEBOX
)
268 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
269 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
270 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
279 if (!GetMessageW(&msg
, NULL
, 0, 0)) break; //return 0;
280 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
285 hittest
= DefWndNCHitTest(hWnd
, msg
.pt
);
286 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
298 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
299 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
303 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
304 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
308 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
309 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
313 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
314 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
321 TranslateMessage( &msg
);
322 DispatchMessageW( &msg
);
328 SetCursorPos( pt
.x
, pt
.y
);
329 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
), Style
);
333 #define ON_LEFT_BORDER(hit) \
334 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
335 #define ON_RIGHT_BORDER(hit) \
336 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
337 #define ON_TOP_BORDER(hit) \
338 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
339 #define ON_BOTTOM_BORDER(hit) \
340 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
343 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
344 ULONG width
, ULONG height
)
346 static HBRUSH hDraggingRectBrush
= NULL
;
349 if(!hDraggingRectBrush
)
351 static HBITMAP hDraggingPattern
= NULL
;
352 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
354 hDraggingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
355 hDraggingRectBrush
= CreatePatternBrush(hDraggingPattern
);
358 hbrush
= SelectObject( hdc
, hDraggingRectBrush
);
359 PatBlt( hdc
, rect
->left
, rect
->top
,
360 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
361 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
362 rect
->bottom
- rect
->top
- height
, PATINVERT
);
363 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
364 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
365 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
366 rect
->bottom
- rect
->top
- height
, PATINVERT
);
367 SelectObject( hdc
, hbrush
);
371 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
375 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
), GetSystemMetrics(SM_CYFRAME
));
379 UserDrawWindowFrame(hdc
, rect
, 1, 1);
384 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
388 RECT sizingRect
, mouseRect
, origRect
, clipRect
, unmodRect
;
390 LONG hittest
= (LONG
)(wParam
& 0x0f);
391 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
392 POINT minTrack
, maxTrack
;
393 POINT capturePoint
, pt
;
394 ULONG Style
, ExStyle
;
398 DWORD dwPoint
= GetMessagePos();
399 BOOL DragFullWindows
= FALSE
;
400 HWND hWndParent
= NULL
;
403 Wnd
= ValidateHwnd(hwnd
);
408 ExStyle
= Wnd
->ExStyle
;
409 iconic
= (Style
& WS_MINIMIZE
) != 0;
411 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
413 pt
.x
= GET_X_LPARAM(dwPoint
);
414 pt
.y
= GET_Y_LPARAM(dwPoint
);
417 if ((Style
& WS_MAXIMIZE
) || !IsWindowVisible(hwnd
))
422 thickframe
= UserHasThickFrameStyle(Style
, ExStyle
) && !(Style
& WS_MINIMIZE
);
423 if ((wParam
& 0xfff0) == SC_MOVE
)
427 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
440 if (hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
))
442 hittest
+= (HTLEFT
- WMSZ_LEFT
);
447 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
456 /* Get min/max info */
458 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
459 sizingRect
= Wnd
->rcWindow
;
460 if (Style
& WS_CHILD
)
462 hWndParent
= GetParent(hwnd
);
463 MapWindowPoints( 0, hWndParent
, (LPPOINT
)&sizingRect
, 2 );
464 unmodRect
= sizingRect
;
465 GetClientRect(hWndParent
, &mouseRect
);
466 clipRect
= mouseRect
;
467 MapWindowPoints(hWndParent
, HWND_DESKTOP
, (LPPOINT
)&clipRect
, 2);
471 if(!(ExStyle
& WS_EX_TOPMOST
))
473 SystemParametersInfoW(SPI_GETWORKAREA
, 0, &clipRect
, 0);
474 mouseRect
= clipRect
;
478 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
479 clipRect
= mouseRect
;
481 unmodRect
= sizingRect
;
483 ClipCursor(&clipRect
);
485 origRect
= sizingRect
;
486 if (ON_LEFT_BORDER(hittest
))
488 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
489 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
491 else if (ON_RIGHT_BORDER(hittest
))
493 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
494 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
496 if (ON_TOP_BORDER(hittest
))
498 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
499 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
501 else if (ON_BOTTOM_BORDER(hittest
))
503 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
504 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
506 if (Style
& WS_CHILD
)
508 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
511 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
512 NtUserxSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, hwnd
);
513 if (GetCapture() != hwnd
) SetCapture( hwnd
);
515 if (Style
& WS_CHILD
)
517 /* Retrieve a default cache DC (without using the window style) */
518 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
524 DesktopRgn
= CreateRectRgnIndirect(&clipRect
);
527 SelectObject(hdc
, DesktopRgn
);
529 if( iconic
) /* create a cursor for dragging */
531 HICON hIcon
= (HICON
)GetClassLongPtrW(hwnd
, GCL_HICON
);
532 if(!hIcon
) hIcon
= (HICON
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
533 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
534 if( !hDragCursor
) iconic
= FALSE
;
537 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
538 if( !iconic
&& !DragFullWindows
)
540 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
547 if (!GetMessageW(&msg
, 0, 0, 0)) break;
548 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
550 /* Exit on button-up, Return, or Esc */
551 if ((msg
.message
== WM_LBUTTONUP
) ||
552 ((msg
.message
== WM_KEYDOWN
) &&
553 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
555 if (msg
.message
== WM_PAINT
)
557 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
558 UpdateWindow( msg
.hwnd
);
559 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
563 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
565 TranslateMessage( &msg
);
566 DispatchMessageW( &msg
);
567 continue; /* We are not interested in other messages */
572 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
574 case VK_UP
: pt
.y
-= 8; break;
575 case VK_DOWN
: pt
.y
+= 8; break;
576 case VK_LEFT
: pt
.x
-= 8; break;
577 case VK_RIGHT
: pt
.x
+= 8; break;
580 pt
.x
= max( pt
.x
, mouseRect
.left
);
581 pt
.x
= min( pt
.x
, mouseRect
.right
);
582 pt
.y
= max( pt
.y
, mouseRect
.top
);
583 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
585 dx
= pt
.x
- capturePoint
.x
;
586 dy
= pt
.y
- capturePoint
.y
;
594 if( iconic
) /* ok, no system popup tracking */
596 hOldCursor
= SetCursor(hDragCursor
);
601 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
604 RECT newRect
= unmodRect
;
605 WPARAM wpSizingHit
= 0;
607 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
608 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
609 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
610 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
611 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
612 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
615 /* determine the hit location */
616 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
617 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
619 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
624 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
626 /* To avoid any deadlocks, all the locks on the windows
627 structures must be suspended before the SetWindowPos */
628 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
629 newRect
.right
- newRect
.left
,
630 newRect
.bottom
- newRect
.top
,
631 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
634 sizingRect
= newRect
;
643 if( moved
) /* restore cursors, show icon title later on */
646 SetCursor( hOldCursor
);
648 DestroyCursor( hDragCursor
);
650 else if(!DragFullWindows
)
651 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
653 if (Style
& WS_CHILD
)
654 ReleaseDC( hWndParent
, hdc
);
660 DeleteObject(DesktopRgn
);
664 if (ISITHOOKED(WH_CBT
))
667 NtUserMessageCall( hwnd
, WM_CBT
, HCBT_MOVESIZE
, (LPARAM
)&sizingRect
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
668 if (lResult
) moved
= FALSE
;
671 NtUserxSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, NULL
);
672 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
673 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
675 /* window moved or resized */
678 /* if the moving/resizing isn't canceled call SetWindowPos
679 * with the new position or the new size of the window
681 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
683 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
685 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
686 sizingRect
.right
- sizingRect
.left
,
687 sizingRect
.bottom
- sizingRect
.top
,
688 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
690 else { /* restore previous size/position */
692 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
693 origRect
.right
- origRect
.left
,
694 origRect
.bottom
- origRect
.top
,
695 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
700 if( Style
& WS_MINIMIZE
)
702 /* Single click brings up the system menu when iconized */
706 if( Style
& WS_SYSMENU
)
707 SendMessageA( hwnd
, WM_SYSCOMMAND
,
708 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
714 /***********************************************************************
715 * DefWndTrackScrollBar
717 * Track a mouse button press on the horizontal or vertical scroll-bar.
720 DefWndTrackScrollBar(HWND Wnd
, WPARAM wParam
, POINT Pt
)
724 if (SC_HSCROLL
== (wParam
& 0xfff0))
726 if (HTHSCROLL
!= (wParam
& 0x0f))
732 else /* SC_VSCROLL */
734 if (HTVSCROLL
!= (wParam
& 0x0f))
740 ScrollTrackScrollBar(Wnd
, ScrollBar
, Pt
);
743 LRESULT WINAPI
DoAppSwitch( WPARAM wParam
, LPARAM lParam
);
746 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
748 // WINDOWPLACEMENT wp;
752 if (!IsWindowEnabled( hWnd
)) return 0;
754 if (ISITHOOKED(WH_CBT
))
756 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
757 if (lResult
) return 0;
760 switch (wParam
& 0xfff0)
764 DefWndDoSizeMove(hWnd
, wParam
);
767 if (hWnd
== GetActiveWindow())
768 ShowOwnedPopups(hWnd
,FALSE
);
769 ShowWindow( hWnd
, SW_MINIMIZE
);
773 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
774 ShowOwnedPopups(hWnd
,TRUE
);
775 ShowWindow( hWnd
, SW_MAXIMIZE
);
779 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
780 ShowOwnedPopups(hWnd
,TRUE
);
781 ShowWindow( hWnd
, SW_RESTORE
);
785 return SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
789 Pt
.x
= (short)LOWORD(lParam
);
790 Pt
.y
= (short)HIWORD(lParam
);
791 MenuTrackMouseMenuBar(hWnd
, wParam
& 0x000f, Pt
);
795 MenuTrackKbdMenuBar(hWnd
, wParam
, (WCHAR
)lParam
);
800 Pt
.x
= (short)LOWORD(lParam
);
801 Pt
.y
= (short)HIWORD(lParam
);
802 DefWndTrackScrollBar(hWnd
, wParam
, Pt
);
807 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
812 DoAppSwitch( wParam
, lParam
);
817 HWND hwnd
, hWndLastActive
;
821 pWnd
= ValidateHwnd(hwnd
);
824 hWndLastActive
= GetLastActivePopup(hwnd
);
827 hwnd
= hWndLastActive
;
828 pWnd
= ValidateHwnd(hwnd
);
830 SetForegroundWindow(hwnd
);
831 if (pWnd
->style
& WS_MINIMIZE
)
833 PostMessage(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
840 FIXME("Unimplemented DefWndHandleSysCommand wParam 0x%x\n",wParam
);
848 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
850 POINT maxTrack
, minTrack
;
851 LONG style
= GetWindowLongPtrA(hWnd
, GWL_STYLE
);
853 if (Pos
->flags
& SWP_NOSIZE
) return 0;
854 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
856 WinPosGetMinMaxInfo(hWnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
857 Pos
->cx
= min(Pos
->cx
, maxTrack
.x
);
858 Pos
->cy
= min(Pos
->cy
, maxTrack
.y
);
859 if (!(style
& WS_MINIMIZE
))
861 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
862 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
867 Pos
->cx
= max(Pos
->cx
, 0);
868 Pos
->cy
= max(Pos
->cy
, 0);
874 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
878 GetClientRect(hWnd
, &Rect
);
879 MapWindowPoints(hWnd
, (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
?
880 GetParent(hWnd
) : NULL
), (LPPOINT
) &Rect
, 2);
882 if (! (Pos
->flags
& SWP_NOCLIENTMOVE
))
884 SendMessageW(hWnd
, WM_MOVE
, 0, MAKELONG(Rect
.left
, Rect
.top
));
887 if (! (Pos
->flags
& SWP_NOCLIENTSIZE
))
889 WPARAM wp
= SIZE_RESTORED
;
894 else if (IsIconic(hWnd
))
898 SendMessageW(hWnd
, WM_SIZE
, wp
,
899 MAKELONG(Rect
.right
- Rect
.left
, Rect
.bottom
- Rect
.top
));
905 /***********************************************************************
908 * Default colors for control painting.
911 DefWndControlColor(HDC hDC
, UINT ctlType
)
913 if (ctlType
== CTLCOLOR_SCROLLBAR
)
915 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
916 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
917 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
920 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
921 * we better use 0x55aa bitmap brush to make scrollbar's background
922 * look different from the window background.
924 if ( bk
== GetSysColor(COLOR_WINDOW
))
925 return gpsi
->hbrGray
;
927 UnrealizeObject( hb
);
931 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
933 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
935 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
939 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
940 return GetSysColorBrush(COLOR_3DFACE
);
943 return GetSysColorBrush(COLOR_WINDOW
);
946 static void DefWndPrint( HWND hwnd
, HDC hdc
, ULONG uFlags
)
951 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
952 !IsWindowVisible(hwnd
) )
956 * Unimplemented flags.
958 if ( (uFlags
& PRF_CHILDREN
) ||
959 (uFlags
& PRF_OWNED
) ||
960 (uFlags
& PRF_NONCLIENT
) )
962 FIXME("WM_PRINT message with unsupported flags\n");
968 if ( uFlags
& PRF_ERASEBKGND
)
969 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
974 if ( uFlags
& PRF_CLIENT
)
975 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, uFlags
);
979 UserSendUiUpdateMsg(HWND hwnd
, LPARAM lParam
)
981 SendMessageW(hwnd
, WM_UPDATEUISTATE
, (WPARAM
)lParam
, 0);
987 DefWndScreenshot(HWND hWnd
)
999 hdc
= GetWindowDC(hWnd
);
1000 GetWindowRect(hWnd
, &rect
);
1001 w
= rect
.right
- rect
.left
;
1002 h
= rect
.bottom
- rect
.top
;
1004 hbitmap
= CreateCompatibleBitmap(hdc
, w
, h
);
1005 hdc2
= CreateCompatibleDC(hdc
);
1006 SelectObject(hdc2
, hbitmap
);
1008 BitBlt(hdc2
, 0, 0, w
, h
,
1012 SetClipboardData(CF_BITMAP
, hbitmap
);
1014 ReleaseDC(hWnd
, hdc
);
1015 ReleaseDC(hWnd
, hdc2
);
1024 User32DefWindowProc(HWND hWnd
,
1033 pWnd
= ValidateHwnd(hWnd
);
1034 if (!pWnd
) return 0;
1041 return DefWndNCPaint(hWnd
, (HRGN
)wParam
, -1);
1046 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
1049 case WM_POPUPSYSTEMMENU
:
1051 /* This is an undocumented message used by the windows taskbar to
1052 display the system menu of windows that belong to other processes. */
1053 HMENU menu
= GetSystemMenu(hWnd
, FALSE
);
1056 TrackPopupMenu(menu
, TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
1057 LOWORD(lParam
), HIWORD(lParam
), 0, hWnd
, NULL
);
1063 return DefWndNCActivate(hWnd
, wParam
, lParam
);
1069 Point
.x
= GET_X_LPARAM(lParam
);
1070 Point
.y
= GET_Y_LPARAM(lParam
);
1071 return (DefWndNCHitTest(hWnd
, Point
));
1074 case WM_LBUTTONDOWN
:
1075 case WM_RBUTTONDOWN
:
1076 case WM_MBUTTONDOWN
:
1077 iF10Key
= iMenuSysKey
= 0;
1080 case WM_NCLBUTTONDOWN
:
1082 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
1085 case WM_LBUTTONDBLCLK
:
1086 return (DefWndNCLButtonDblClk(hWnd
, HTCLIENT
, lParam
));
1088 case WM_NCLBUTTONDBLCLK
:
1090 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
1093 case WM_WINDOWPOSCHANGING
:
1095 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1098 case WM_WINDOWPOSCHANGED
:
1100 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
1103 case WM_NCRBUTTONDOWN
:
1105 /* in Windows, capture is taken when right-clicking on the caption bar */
1106 if (wParam
== HTCAPTION
)
1116 if (hWnd
== GetCapture())
1120 Pt
.x
= GET_X_LPARAM(lParam
);
1121 Pt
.y
= GET_Y_LPARAM(lParam
);
1122 ClientToScreen(hWnd
, &Pt
);
1123 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1126 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1130 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1135 case WM_NCRBUTTONUP
:
1137 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
1138 * in Windows), but what _should_ we do? According to MSDN :
1139 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
1140 * message to the window". When is it appropriate?
1144 case WM_CONTEXTMENU
:
1146 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1150 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1154 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1163 Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1165 Pt
.x
= GET_X_LPARAM(lParam
);
1166 Pt
.y
= GET_Y_LPARAM(lParam
);
1167 if (Style
& WS_CHILD
)
1169 ScreenToClient(GetParent(hWnd
), &Pt
);
1172 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1174 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1179 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
1181 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongPtrW(hWnd
, GWL_STYLE
),
1182 GetClassLongPtrW(hWnd
, GCL_STYLE
), HitCode
);
1184 if(HitCode
== HTCAPTION
)
1185 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
1187 Flags
= TPM_LEFTBUTTON
;
1189 TrackPopupMenu(SystemMenu
, Flags
,
1190 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1199 DefWndPrint(hWnd
, (HDC
)wParam
, lParam
);
1203 case WM_SYSCOLORCHANGE
:
1205 /* force to redraw non-client area */
1206 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1207 /* Use InvalidateRect to redraw client area, enable
1208 * erase to redraw all subcontrols otherwise send the
1209 * WM_SYSCOLORCHANGE to child windows/controls is required
1211 InvalidateRect(hWnd
,NULL
,TRUE
);
1221 /* If already in Paint and Client area is not empty just return. */
1222 if (pWnd
->state2
& WNDS2_STARTPAINT
&& !IsRectEmpty(&pWnd
->rcClient
))
1224 ERR("In Paint and Client area is not empty!\n");
1228 hDC
= BeginPaint(hWnd
, &Ps
);
1233 if (IsIconic(hWnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hWnd
, GCLP_HICON
))))
1237 GetClientRect(hWnd
, &ClientRect
);
1238 x
= (ClientRect
.right
- ClientRect
.left
-
1239 GetSystemMetrics(SM_CXICON
)) / 2;
1240 y
= (ClientRect
.bottom
- ClientRect
.top
-
1241 GetSystemMetrics(SM_CYICON
)) / 2;
1242 DrawIcon(hDC
, x
, y
, hIcon
);
1244 EndPaint(hWnd
, &Ps
);
1252 hRgn = CreateRectRgn(0, 0, 0, 0);
1253 if (GetUpdateRgn(hWnd, hRgn, FALSE) != NULLREGION)
1255 RedrawWindow(hWnd, NULL, hRgn,
1256 RDW_ERASENOW | RDW_ERASE | RDW_FRAME |
1265 LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
1266 if (wParam) SetWindowLongPtr(hWnd, GWL_STYLE, Style | WS_VISIBLE);
1269 RedrawWindow(hWnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE);
1270 Style &= ~WS_VISIBLE;
1271 SetWindowLongPtr(hWnd, GWL_STYLE, Style);
1277 DestroyWindow(hWnd
);
1280 case WM_MOUSEACTIVATE
:
1281 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1283 LONG Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
1284 if (Ret
) return (Ret
);
1286 return ( (HIWORD(lParam
) == WM_LBUTTONDOWN
&& LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
);
1289 /* The default action in Windows is to set the keyboard focus to
1290 * the window, if it's being activated and not minimized */
1291 if (LOWORD(wParam
) != WA_INACTIVE
&&
1292 !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1294 //ERR("WM_ACTIVATE %p\n",hWnd);
1300 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1301 return SendMessageW( GetParent(hWnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
1305 case WM_ICONERASEBKGND
:
1308 HBRUSH hBrush
= (HBRUSH
)GetClassLongPtrW(hWnd
, GCL_HBRBACKGROUND
);
1314 if (GetClassLongPtrW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1316 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1317 GetClientRect(hWnd
, &Rect
);
1318 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1322 GetClipBox((HDC
)wParam
, &Rect
);
1324 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1328 case WM_CTLCOLORMSGBOX
:
1329 case WM_CTLCOLOREDIT
:
1330 case WM_CTLCOLORLISTBOX
:
1331 case WM_CTLCOLORBTN
:
1332 case WM_CTLCOLORDLG
:
1333 case WM_CTLCOLORSTATIC
:
1334 case WM_CTLCOLORSCROLLBAR
:
1335 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1338 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
1342 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1344 if (Style
& WS_CHILD
)
1346 /* with the exception of the border around a resizable wnd,
1347 * give the parent first chance to set the cursor */
1348 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1350 HWND parent
= GetParent( hWnd
);
1353 if (parent
!= GetDesktopWindow() &&
1354 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
))
1359 if (parent
!= GetDesktopWindow() &&
1360 SendMessageA( parent
, WM_SETCURSOR
, wParam
, lParam
))
1365 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1369 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
1372 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
1377 if (HIWORD(lParam
) & KF_ALTDOWN
)
1378 { /* Previous state, if the key was down before this message,
1379 this is a cheap way to ignore autorepeat keys. */
1380 if ( !(HIWORD(lParam
) & KF_REPEAT
) )
1382 if ( ( wParam
== VK_MENU
||
1383 wParam
== VK_LMENU
||
1384 wParam
== VK_RMENU
) && !iMenuSysKey
)
1392 if (wParam
== VK_F4
) /* Try to close the window */
1394 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1395 if (!(GetClassLongPtrW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1396 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1398 else if (wParam
== VK_SNAPSHOT
) // Alt-VK_SNAPSHOT?
1401 while (GetParent(hwnd
) != NULL
)
1403 hwnd
= GetParent(hwnd
);
1405 DefWndScreenshot(hwnd
);
1407 else if ( wParam
== VK_ESCAPE
|| wParam
== VK_TAB
) // Alt-Tab/ESC Alt-Shift-Tab/ESC
1410 HWND Active
= GetActiveWindow(); // Noticed MDI problem.
1413 FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n");
1416 wParamTmp
= GetKeyState(VK_SHIFT
) & 0x8000 ? SC_PREVWINDOW
: SC_NEXTWINDOW
;
1417 SendMessageW( Active
, WM_SYSCOMMAND
, wParamTmp
, wParam
);
1420 else if( wParam
== VK_F10
)
1422 if (GetKeyState(VK_SHIFT
) & 0x8000)
1423 SendMessageW( hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, MAKELPARAM(-1, -1) );
1432 /* Press and release F10 or ALT */
1433 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
1434 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
1435 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
1436 iMenuSysKey
= iF10Key
= 0;
1443 if (wParam
== VK_RETURN
&& IsIconic(hWnd
))
1445 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
1448 if ((HIWORD(lParam
) & KF_ALTDOWN
) && wParam
)
1450 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
1451 if (wParam
== VK_SPACE
&& (GetWindowLongPtrW( hWnd
, GWL_STYLE
) & WS_CHILD
))
1452 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
1454 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
1456 else /* check for Ctrl-Esc */
1457 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
1464 /* FIXME: Check for a desktop. */
1465 //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
1466 MENU_EndMenu( hWnd
);
1467 if (GetCapture() == hWnd
)
1481 case WM_QUERYDROPOBJECT
:
1483 if (GetWindowLongPtrW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1490 case WM_QUERYDRAGICON
:
1495 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HICON
);
1498 return ((LRESULT
)hIcon
);
1500 for (Len
= 1; Len
< 64; Len
++)
1502 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1504 return((LRESULT
)hIcon
);
1507 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1510 case WM_ISACTIVEICON
:
1513 isai
= (pWnd
->state
& WNDS_ACTIVEFRAME
) != 0;
1517 case WM_NOTIFYFORMAT
:
1519 if (lParam
== NF_QUERY
)
1520 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1526 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1527 HICON hOldIcon
= (HICON
)GetClassLongPtrW(hWnd
, Index
);
1528 SetClassLongPtrW(hWnd
, Index
, lParam
);
1529 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1530 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1531 SWP_NOACTIVATE
| SWP_NOZORDER
);
1532 return ((LRESULT
)hOldIcon
);
1537 INT Index
= (wParam
== ICON_BIG
) ? GCL_HICON
: GCL_HICONSM
;
1538 return (GetClassLongPtrW(hWnd
, Index
));
1545 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1549 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1556 THRDCARETINFO CaretInfo
;
1559 case 0xffff: /* Caret timer */
1560 /* switch showing byte in win32k and get information about the caret */
1561 if(NtUserxSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1563 DrawCaret(hWnd
, &CaretInfo
);
1571 case WM_QUERYENDSESSION
:
1576 case WM_INPUTLANGCHANGEREQUEST
:
1580 if(wParam
& INPUTLANGCHANGE_BACKWARD
1581 && wParam
& INPUTLANGCHANGE_FORWARD
)
1586 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1588 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1589 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1590 else NewHkl
= (HKL
) lParam
;
1592 NtUserActivateKeyboardLayout(NewHkl
, 0);
1597 case WM_INPUTLANGCHANGE
:
1600 HWND
*win_array
= WIN_ListChildren( hWnd
);
1604 while (win_array
[count
])
1605 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
1606 HeapFree(GetProcessHeap(),0,win_array
);
1610 case WM_QUERYUISTATE
:
1613 PWND Wnd
= ValidateHwnd(hWnd
);
1617 Ret
|= UISF_HIDEFOCUS
;
1619 Ret
|= UISF_HIDEACCEL
;
1624 case WM_CHANGEUISTATE
:
1626 BOOL AlwaysShowCues
= FALSE
;
1627 WORD Action
= LOWORD(wParam
);
1628 WORD Flags
= HIWORD(wParam
);
1631 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1635 Wnd
= ValidateHwnd(hWnd
);
1636 if (!Wnd
|| lParam
!= 0)
1639 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1642 if (Flags
& UISF_ACTIVE
)
1644 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1647 if (Action
== UIS_INITIALIZE
)
1649 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1653 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1654 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1656 /* We need to update wParam in case we need to send out messages */
1657 wParam
= MAKEWPARAM(Action
, Flags
);
1663 /* See if we actually need to change something */
1664 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1666 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1669 /* Don't need to do anything... */
1673 /* See if we actually need to change something */
1674 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1676 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1679 /* Don't need to do anything... */
1683 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1687 if ((Wnd
->style
& WS_CHILD
) && Wnd
->spwndParent
!= NULL
)
1689 /* We're a child window and we need to pass this message down until
1690 we reach the root */
1691 hWnd
= UserHMGetHandle((PWND
)DesktopPtrToUser(Wnd
->spwndParent
));
1695 /* We're a top level window, we need to change the UI state */
1696 Msg
= WM_UPDATEUISTATE
;
1700 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1702 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1705 case WM_UPDATEUISTATE
:
1708 BOOL AlwaysShowCues
= FALSE
;
1709 WORD Action
= LOWORD(wParam
);
1710 WORD Flags
= HIWORD(wParam
);
1713 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1717 Wnd
= ValidateHwnd(hWnd
);
1718 if (!Wnd
|| lParam
!= 0)
1721 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1724 if (Flags
& UISF_ACTIVE
)
1726 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1729 if (Action
== UIS_INITIALIZE
)
1731 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1735 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1736 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1738 /* We need to update wParam for broadcasting the update */
1739 wParam
= MAKEWPARAM(Action
, Flags
);
1745 /* See if we actually need to change something */
1746 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1748 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1751 /* Don't need to do anything... */
1756 /* See if we actually need to change something */
1757 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1759 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1762 /* Don't need to do anything... */
1767 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1771 /* Pack the information and call win32k */
1774 if (!NtUserxUpdateUiState(hWnd
, Flags
| ((DWORD
)Action
<< 3)))
1778 /* Always broadcast the update to all children */
1779 EnumChildWindows(hWnd
,
1780 UserSendUiUpdateMsg
,
1786 /* Move to win32k !*/
1788 if (!lParam
) break; // Call when it is necessary.
1791 case WM_CLIENTSHUTDOWN
:
1796 NtUserMessageCall( hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, !bUnicode
);
1805 * helpers for calling IMM32 (from Wine 10/22/2008)
1807 * WM_IME_* messages are generated only by IMM32,
1808 * so I assume imm32 is already LoadLibrary-ed.
1811 DefWndImmGetDefaultIMEWnd(HWND hwnd
)
1813 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1814 HWND (WINAPI
*pFunc
)(HWND
);
1819 ERR("cannot get IMM32 handle\n");
1823 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmGetDefaultIMEWnd");
1825 hwndRet
= (*pFunc
)(hwnd
);
1832 DefWndImmIsUIMessageA(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1834 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1835 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1840 ERR("cannot get IMM32 handle\n");
1844 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageA");
1846 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1853 DefWndImmIsUIMessageW(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1855 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1856 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1861 ERR("cannot get IMM32 handle\n");
1865 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageW");
1867 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1874 RealDefWindowProcA(HWND hWnd
,
1882 Wnd
= ValidateHwnd(hWnd
);
1885 Msg
!= WM_CTLCOLORMSGBOX
&&
1886 Msg
!= WM_CTLCOLORBTN
&&
1887 Msg
!= WM_CTLCOLORDLG
&&
1888 Msg
!= WM_CTLCOLORSTATIC
)
1891 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1898 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1899 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1900 * may have child window IDs instead of window name */
1901 if (HIWORD(cs
->lpszName
))
1903 DefSetText(hWnd
, (PCWSTR
)cs
->lpszName
, TRUE
);
1910 case WM_GETTEXTLENGTH
:
1915 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1917 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1919 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1921 Wnd
->strName
.Length
)))
1923 Result
= (LRESULT
) len
;
1934 PSTR outbuf
= (PSTR
)lParam
;
1937 if (Wnd
!= NULL
&& wParam
!= 0)
1939 if (Wnd
->strName
.Buffer
!= NULL
)
1940 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1946 if (Wnd
->strName
.Length
!= 0)
1948 copy
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1949 Result
= WideCharToMultiByte(CP_ACP
,
1957 outbuf
[Result
] = '\0';
1968 DefSetText(hWnd
, (PCWSTR
)lParam
, TRUE
);
1970 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1972 /* FIXME: this is not 100% correct */
1973 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
1975 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
1979 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1986 case WM_IME_KEYDOWN
:
1988 Result
= PostMessageA(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
1994 Result
= PostMessageA(hWnd
, WM_KEYUP
, wParam
, lParam
);
2001 PostMessageA(hWnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
2002 PostMessageA(hWnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
2006 case WM_IME_STARTCOMPOSITION
:
2007 case WM_IME_COMPOSITION
:
2008 case WM_IME_ENDCOMPOSITION
:
2014 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2016 Result
= SendMessageA(hwndIME
, Msg
, wParam
, lParam
);
2020 case WM_IME_SETCONTEXT
:
2024 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2026 Result
= DefWndImmIsUIMessageA(hwndIME
, Msg
, wParam
, lParam
);
2032 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
2035 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2041 RealDefWindowProcW(HWND hWnd
,
2049 Wnd
= ValidateHwnd(hWnd
);
2052 Msg
!= WM_CTLCOLORMSGBOX
&&
2053 Msg
!= WM_CTLCOLORBTN
&&
2054 Msg
!= WM_CTLCOLORDLG
&&
2055 Msg
!= WM_CTLCOLORSTATIC
)
2058 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
2065 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
2066 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
2067 * may have child window IDs instead of window name */
2068 if (HIWORD(cs
->lpszName
))
2070 DefSetText(hWnd
, cs
->lpszName
, FALSE
);
2077 case WM_GETTEXTLENGTH
:
2082 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
2084 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2086 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
2088 Wnd
->strName
.Length
)))
2090 Result
= (LRESULT
) (Wnd
->strName
.Length
/ sizeof(WCHAR
));
2101 PWSTR outbuf
= (PWSTR
)lParam
;
2103 if (Wnd
!= NULL
&& wParam
!= 0)
2105 if (Wnd
->strName
.Buffer
!= NULL
)
2106 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2112 if (Wnd
->strName
.Length
!= 0)
2114 Result
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2115 RtlCopyMemory(outbuf
,
2117 Result
* sizeof(WCHAR
));
2118 outbuf
[Result
] = L
'\0';
2129 DefSetText(hWnd
, (PCWSTR
)lParam
, FALSE
);
2131 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2133 /* FIXME: this is not 100% correct */
2134 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2136 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2140 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2149 PostMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
2154 case WM_IME_KEYDOWN
:
2156 Result
= PostMessageW(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2162 Result
= PostMessageW(hWnd
, WM_KEYUP
, wParam
, lParam
);
2166 case WM_IME_STARTCOMPOSITION
:
2167 case WM_IME_COMPOSITION
:
2168 case WM_IME_ENDCOMPOSITION
:
2174 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2176 Result
= SendMessageW(hwndIME
, Msg
, wParam
, lParam
);
2180 case WM_IME_SETCONTEXT
:
2184 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2186 Result
= DefWndImmIsUIMessageW(hwndIME
, Msg
, wParam
, lParam
);
2191 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
2193 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2199 DefWindowProcA(HWND hWnd
,
2204 BOOL Hook
, msgOverride
= FALSE
;
2209 Hook
= BeginIfHookedUserApiHook();
2212 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2213 if(msgOverride
== FALSE
)
2219 /* Bypass SEH and go direct. */
2220 if (!Hook
|| !msgOverride
)
2221 return RealDefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2225 Result
= guah
.DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2227 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2238 DefWindowProcW(HWND hWnd
,
2243 BOOL Hook
, msgOverride
= FALSE
;
2248 Hook
= BeginIfHookedUserApiHook();
2251 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2252 if(msgOverride
== FALSE
)
2258 /* Bypass SEH and go direct. */
2259 if (!Hook
|| !msgOverride
)
2260 return RealDefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2264 Result
= guah
.DefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2266 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)