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
);
1220 /* If already in Paint and Client area is not empty just return. */
1221 if (pWnd
->state2
& WNDS2_STARTPAINT
&& !IsRectEmpty(&pWnd
->rcClient
))
1223 ERR("In Paint and Client area is not empty!\n");
1227 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1232 if (IsIconic(hWnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hWnd
, GCLP_HICON
))))
1236 GetClientRect(hWnd
, &ClientRect
);
1237 x
= (ClientRect
.right
- ClientRect
.left
-
1238 GetSystemMetrics(SM_CXICON
)) / 2;
1239 y
= (ClientRect
.bottom
- ClientRect
.top
-
1240 GetSystemMetrics(SM_CYICON
)) / 2;
1241 DrawIcon(hDC
, x
, y
, hIcon
);
1243 EndPaint(hWnd
, &Ps
);
1251 hRgn
= CreateRectRgn(0, 0, 0, 0);
1252 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1254 RedrawWindow(hWnd
, NULL
, hRgn
,
1255 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1264 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1265 if (wParam
) SetWindowLongPtr(hWnd
, GWL_STYLE
, Style
| WS_VISIBLE
);
1268 RedrawWindow(hWnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
1269 Style
&= ~WS_VISIBLE
;
1270 SetWindowLongPtr(hWnd
, GWL_STYLE
, Style
);
1277 DestroyWindow(hWnd
);
1281 case WM_MOUSEACTIVATE
:
1283 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1288 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1293 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1301 return ((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1306 /* Check if the window is minimized. */
1307 if (LOWORD(wParam
) != WA_INACTIVE
&&
1308 !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1317 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1321 return (SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1326 return (SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1334 case WM_ICONERASEBKGND
:
1337 HBRUSH hBrush
= (HBRUSH
)GetClassLongPtrW(hWnd
, GCL_HBRBACKGROUND
);
1343 if (GetClassLongPtrW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1345 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1346 GetClientRect(hWnd
, &Rect
);
1347 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1351 GetClipBox((HDC
)wParam
, &Rect
);
1353 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1357 case WM_CTLCOLORMSGBOX
:
1358 case WM_CTLCOLOREDIT
:
1359 case WM_CTLCOLORLISTBOX
:
1360 case WM_CTLCOLORBTN
:
1361 case WM_CTLCOLORDLG
:
1362 case WM_CTLCOLORSTATIC
:
1363 case WM_CTLCOLORSCROLLBAR
:
1364 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1367 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
1371 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1373 if (Style
& WS_CHILD
)
1375 /* with the exception of the border around a resizable wnd,
1376 * give the parent first chance to set the cursor */
1377 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1379 HWND parent
= GetParent( hWnd
);
1382 if (parent
!= GetDesktopWindow() &&
1383 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
))
1388 if (parent
!= GetDesktopWindow() &&
1389 SendMessageA( parent
, WM_SETCURSOR
, wParam
, lParam
))
1394 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1398 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
1401 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
1406 if (HIWORD(lParam
) & KF_ALTDOWN
)
1407 { /* Previous state, if the key was down before this message,
1408 this is a cheap way to ignore autorepeat keys. */
1409 if ( !(HIWORD(lParam
) & KF_REPEAT
) )
1411 if ( ( wParam
== VK_MENU
||
1412 wParam
== VK_LMENU
||
1413 wParam
== VK_RMENU
) && !iMenuSysKey
)
1421 if (wParam
== VK_F4
) /* Try to close the window */
1423 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1424 if (!(GetClassLongPtrW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1425 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1427 else if (wParam
== VK_SNAPSHOT
) // Alt-VK_SNAPSHOT?
1430 while (GetParent(hwnd
) != NULL
)
1432 hwnd
= GetParent(hwnd
);
1434 DefWndScreenshot(hwnd
);
1436 else if ( wParam
== VK_ESCAPE
|| wParam
== VK_TAB
) // Alt-Tab/ESC Alt-Shift-Tab/ESC
1439 HWND Active
= GetActiveWindow(); // Noticed MDI problem.
1442 FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n");
1445 wParamTmp
= GetKeyState(VK_SHIFT
) & 0x8000 ? SC_PREVWINDOW
: SC_NEXTWINDOW
;
1446 SendMessageW( Active
, WM_SYSCOMMAND
, wParamTmp
, wParam
);
1449 else if( wParam
== VK_F10
)
1451 if (GetKeyState(VK_SHIFT
) & 0x8000)
1452 SendMessageW( hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, MAKELPARAM(-1, -1) );
1461 /* Press and release F10 or ALT */
1462 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
1463 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
1464 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
1465 iMenuSysKey
= iF10Key
= 0;
1472 if (wParam
== VK_RETURN
&& IsIconic(hWnd
))
1474 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
1477 if ((HIWORD(lParam
) & KF_ALTDOWN
) && wParam
)
1479 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
1480 if (wParam
== VK_SPACE
&& (GetWindowLongPtrW( hWnd
, GWL_STYLE
) & WS_CHILD
))
1481 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
1483 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
1485 else /* check for Ctrl-Esc */
1486 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
1493 /* FIXME: Check for a desktop. */
1494 //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
1495 MENU_EndMenu( hWnd
);
1496 if (GetCapture() == hWnd
)
1510 case WM_QUERYDROPOBJECT
:
1512 if (GetWindowLongPtrW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1519 case WM_QUERYDRAGICON
:
1524 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HICON
);
1527 return ((LRESULT
)hIcon
);
1529 for (Len
= 1; Len
< 64; Len
++)
1531 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1533 return((LRESULT
)hIcon
);
1536 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1539 case WM_ISACTIVEICON
:
1542 isai
= (pWnd
->state
& WNDS_ACTIVEFRAME
) != 0;
1546 case WM_NOTIFYFORMAT
:
1548 if (lParam
== NF_QUERY
)
1549 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1555 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1556 HICON hOldIcon
= (HICON
)GetClassLongPtrW(hWnd
, Index
);
1557 SetClassLongPtrW(hWnd
, Index
, lParam
);
1558 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1559 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1560 SWP_NOACTIVATE
| SWP_NOZORDER
);
1561 return ((LRESULT
)hOldIcon
);
1566 INT Index
= (wParam
== ICON_BIG
) ? GCL_HICON
: GCL_HICONSM
;
1567 return (GetClassLongPtrW(hWnd
, Index
));
1574 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1578 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1585 THRDCARETINFO CaretInfo
;
1588 case 0xffff: /* Caret timer */
1589 /* switch showing byte in win32k and get information about the caret */
1590 if(NtUserxSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1592 DrawCaret(hWnd
, &CaretInfo
);
1600 case WM_QUERYENDSESSION
:
1605 case WM_INPUTLANGCHANGEREQUEST
:
1609 if(wParam
& INPUTLANGCHANGE_BACKWARD
1610 && wParam
& INPUTLANGCHANGE_FORWARD
)
1615 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1617 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1618 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1619 else NewHkl
= (HKL
) lParam
;
1621 NtUserActivateKeyboardLayout(NewHkl
, 0);
1626 case WM_INPUTLANGCHANGE
:
1629 HWND
*win_array
= WIN_ListChildren( hWnd
);
1633 while (win_array
[count
])
1634 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
1635 HeapFree(GetProcessHeap(),0,win_array
);
1639 case WM_QUERYUISTATE
:
1642 PWND Wnd
= ValidateHwnd(hWnd
);
1646 Ret
|= UISF_HIDEFOCUS
;
1648 Ret
|= UISF_HIDEACCEL
;
1653 case WM_CHANGEUISTATE
:
1655 BOOL AlwaysShowCues
= FALSE
;
1656 WORD Action
= LOWORD(wParam
);
1657 WORD Flags
= HIWORD(wParam
);
1660 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1664 Wnd
= ValidateHwnd(hWnd
);
1665 if (!Wnd
|| lParam
!= 0)
1668 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1671 if (Flags
& UISF_ACTIVE
)
1673 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1676 if (Action
== UIS_INITIALIZE
)
1678 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1682 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1683 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1685 /* We need to update wParam in case we need to send out messages */
1686 wParam
= MAKEWPARAM(Action
, Flags
);
1692 /* See if we actually need to change something */
1693 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1695 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1698 /* Don't need to do anything... */
1702 /* See if we actually need to change something */
1703 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1705 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1708 /* Don't need to do anything... */
1712 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1716 if ((Wnd
->style
& WS_CHILD
) && Wnd
->spwndParent
!= NULL
)
1718 /* We're a child window and we need to pass this message down until
1719 we reach the root */
1720 hWnd
= UserHMGetHandle((PWND
)DesktopPtrToUser(Wnd
->spwndParent
));
1724 /* We're a top level window, we need to change the UI state */
1725 Msg
= WM_UPDATEUISTATE
;
1729 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1731 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1734 case WM_UPDATEUISTATE
:
1737 BOOL AlwaysShowCues
= FALSE
;
1738 WORD Action
= LOWORD(wParam
);
1739 WORD Flags
= HIWORD(wParam
);
1742 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1746 Wnd
= ValidateHwnd(hWnd
);
1747 if (!Wnd
|| lParam
!= 0)
1750 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1753 if (Flags
& UISF_ACTIVE
)
1755 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1758 if (Action
== UIS_INITIALIZE
)
1760 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1764 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1765 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1767 /* We need to update wParam for broadcasting the update */
1768 wParam
= MAKEWPARAM(Action
, Flags
);
1774 /* See if we actually need to change something */
1775 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1777 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1780 /* Don't need to do anything... */
1785 /* See if we actually need to change something */
1786 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1788 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1791 /* Don't need to do anything... */
1796 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1800 /* Pack the information and call win32k */
1803 if (!NtUserxUpdateUiState(hWnd
, Flags
| ((DWORD
)Action
<< 3)))
1807 /* Always broadcast the update to all children */
1808 EnumChildWindows(hWnd
,
1809 UserSendUiUpdateMsg
,
1815 /* Move to win32k !*/
1817 if (!lParam
) break; // Call when it is necessary.
1818 case WM_CLIENTSHUTDOWN
:
1823 NtUserMessageCall( hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, !bUnicode
);
1832 * helpers for calling IMM32 (from Wine 10/22/2008)
1834 * WM_IME_* messages are generated only by IMM32,
1835 * so I assume imm32 is already LoadLibrary-ed.
1838 DefWndImmGetDefaultIMEWnd(HWND hwnd
)
1840 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1841 HWND (WINAPI
*pFunc
)(HWND
);
1846 ERR("cannot get IMM32 handle\n");
1850 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmGetDefaultIMEWnd");
1852 hwndRet
= (*pFunc
)(hwnd
);
1859 DefWndImmIsUIMessageA(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1861 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1862 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1867 ERR("cannot get IMM32 handle\n");
1871 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageA");
1873 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1880 DefWndImmIsUIMessageW(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1882 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1883 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1888 ERR("cannot get IMM32 handle\n");
1892 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageW");
1894 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1901 RealDefWindowProcA(HWND hWnd
,
1909 Wnd
= ValidateHwnd(hWnd
);
1912 Msg
!= WM_CTLCOLORMSGBOX
&&
1913 Msg
!= WM_CTLCOLORBTN
&&
1914 Msg
!= WM_CTLCOLORDLG
&&
1915 Msg
!= WM_CTLCOLORSTATIC
)
1918 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1925 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1926 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1927 * may have child window IDs instead of window name */
1928 if (HIWORD(cs
->lpszName
))
1930 DefSetText(hWnd
, (PCWSTR
)cs
->lpszName
, TRUE
);
1937 case WM_GETTEXTLENGTH
:
1942 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1944 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1946 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1948 Wnd
->strName
.Length
)))
1950 Result
= (LRESULT
) len
;
1961 PSTR outbuf
= (PSTR
)lParam
;
1964 if (Wnd
!= NULL
&& wParam
!= 0)
1966 if (Wnd
->strName
.Buffer
!= NULL
)
1967 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1973 if (Wnd
->strName
.Length
!= 0)
1975 copy
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1976 Result
= WideCharToMultiByte(CP_ACP
,
1984 outbuf
[Result
] = '\0';
1995 DefSetText(hWnd
, (PCWSTR
)lParam
, TRUE
);
1997 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1999 /* FIXME: this is not 100% correct */
2000 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2002 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2006 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2013 case WM_IME_KEYDOWN
:
2015 Result
= PostMessageA(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2021 Result
= PostMessageA(hWnd
, WM_KEYUP
, wParam
, lParam
);
2028 PostMessageA(hWnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
2029 PostMessageA(hWnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
2033 case WM_IME_STARTCOMPOSITION
:
2034 case WM_IME_COMPOSITION
:
2035 case WM_IME_ENDCOMPOSITION
:
2041 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2043 Result
= SendMessageA(hwndIME
, Msg
, wParam
, lParam
);
2047 case WM_IME_SETCONTEXT
:
2051 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2053 Result
= DefWndImmIsUIMessageA(hwndIME
, Msg
, wParam
, lParam
);
2059 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
2062 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2068 RealDefWindowProcW(HWND hWnd
,
2076 Wnd
= ValidateHwnd(hWnd
);
2079 Msg
!= WM_CTLCOLORMSGBOX
&&
2080 Msg
!= WM_CTLCOLORBTN
&&
2081 Msg
!= WM_CTLCOLORDLG
&&
2082 Msg
!= WM_CTLCOLORSTATIC
)
2085 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
2092 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
2093 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
2094 * may have child window IDs instead of window name */
2095 if (HIWORD(cs
->lpszName
))
2097 DefSetText(hWnd
, cs
->lpszName
, FALSE
);
2104 case WM_GETTEXTLENGTH
:
2109 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
2111 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2113 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
2115 Wnd
->strName
.Length
)))
2117 Result
= (LRESULT
) (Wnd
->strName
.Length
/ sizeof(WCHAR
));
2128 PWSTR outbuf
= (PWSTR
)lParam
;
2130 if (Wnd
!= NULL
&& wParam
!= 0)
2132 if (Wnd
->strName
.Buffer
!= NULL
)
2133 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2139 if (Wnd
->strName
.Length
!= 0)
2141 Result
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2142 RtlCopyMemory(outbuf
,
2144 Result
* sizeof(WCHAR
));
2145 outbuf
[Result
] = L
'\0';
2156 DefSetText(hWnd
, (PCWSTR
)lParam
, FALSE
);
2158 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2160 /* FIXME: this is not 100% correct */
2161 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2163 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2167 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2176 PostMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
2181 case WM_IME_KEYDOWN
:
2183 Result
= PostMessageW(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2189 Result
= PostMessageW(hWnd
, WM_KEYUP
, wParam
, lParam
);
2193 case WM_IME_STARTCOMPOSITION
:
2194 case WM_IME_COMPOSITION
:
2195 case WM_IME_ENDCOMPOSITION
:
2201 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2203 Result
= SendMessageW(hwndIME
, Msg
, wParam
, lParam
);
2207 case WM_IME_SETCONTEXT
:
2211 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2213 Result
= DefWndImmIsUIMessageW(hwndIME
, Msg
, wParam
, lParam
);
2218 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
2220 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2226 DefWindowProcA(HWND hWnd
,
2231 BOOL Hook
, msgOverride
= FALSE
;
2236 Hook
= BeginIfHookedUserApiHook();
2239 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2240 if(msgOverride
== FALSE
)
2246 /* Bypass SEH and go direct. */
2247 if (!Hook
|| !msgOverride
)
2248 return RealDefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2252 Result
= guah
.DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2254 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2265 DefWindowProcW(HWND hWnd
,
2270 BOOL Hook
, msgOverride
= FALSE
;
2275 Hook
= BeginIfHookedUserApiHook();
2278 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2279 if(msgOverride
== FALSE
)
2285 /* Bypass SEH and go direct. */
2286 if (!Hook
|| !msgOverride
)
2287 return RealDefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2291 Result
= guah
.DefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2293 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)