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 *****************************************************************/
40 GetSysColor(int nIndex
)
42 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
44 return gpsi
->argbSystem
[nIndex
];
47 SetLastError(ERROR_INVALID_PARAMETER
);
55 GetSysColorBrush(int nIndex
)
57 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
59 return gpsi
->ahbrSystem
[nIndex
];
62 SetLastError(ERROR_INVALID_PARAMETER
);
73 CONST INT
*lpaElements
,
74 CONST COLORREF
*lpaRgbValues
)
76 return NtUserSetSysColors(cElements
, lpaElements
, lpaRgbValues
, 0);
81 DefSetText(HWND hWnd
, PCWSTR String
, BOOL Ansi
)
84 LARGE_STRING lsString
;
89 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)&lsString
, (PCSZ
)String
, 0);
91 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)&lsString
, String
, 0);
93 Ret
= NtUserDefSetText(hWnd
, (String
? &lsString
: NULL
));
96 IntNotifyWinEvent(EVENT_OBJECT_NAMECHANGE
, hWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
102 UserGetInsideRectNC(PWND Wnd
, RECT
*rect
)
108 ExStyle
= Wnd
->ExStyle
;
110 rect
->top
= rect
->left
= 0;
111 rect
->right
= Wnd
->rcWindow
.right
- Wnd
->rcWindow
.left
;
112 rect
->bottom
= Wnd
->rcWindow
.bottom
- Wnd
->rcWindow
.top
;
114 if (Style
& WS_ICONIC
)
119 /* Remove frame from rectangle */
120 if (UserHasThickFrameStyle(Style
, ExStyle
))
122 InflateRect(rect
, -GetSystemMetrics(SM_CXFRAME
),
123 -GetSystemMetrics(SM_CYFRAME
));
127 if (UserHasDlgFrameStyle(Style
, ExStyle
))
129 InflateRect(rect
, -GetSystemMetrics(SM_CXDLGFRAME
),
130 -GetSystemMetrics(SM_CYDLGFRAME
));
131 /* FIXME: this isn't in NC_AdjustRect? why not? */
132 if (ExStyle
& WS_EX_DLGMODALFRAME
)
133 InflateRect( rect
, -1, 0 );
137 if (UserHasThinFrameStyle(Style
, ExStyle
))
139 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
),
140 -GetSystemMetrics(SM_CYBORDER
));
148 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
150 LONG Style
= GetWindowLongPtr(hWnd
, GWL_STYLE
);
151 /* Content can be redrawn after a change. */
154 if (!(Style
& WS_VISIBLE
)) /* Not Visible */
156 SetWindowLongPtr(hWnd
, GWL_STYLE
, WS_VISIBLE
);
159 else /* Content cannot be redrawn after a change. */
161 if (Style
& WS_VISIBLE
) /* Visible */
163 RedrawWindow( hWnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
164 Style
&= ~WS_VISIBLE
;
165 SetWindowLongPtr(hWnd
, GWL_STYLE
, Style
); /* clear bits */
173 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, ULONG Style
)
175 /* Not for child windows. */
176 if (hWnd
!= (HWND
)wParam
)
181 switch((INT_PTR
) LOWORD(lParam
))
185 WORD Msg
= HIWORD(lParam
);
186 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
187 Msg
== WM_RBUTTONDOWN
|| Msg
== WM_XBUTTONDOWN
)
196 HICON hCursor
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HCURSOR
);
208 if (Style
& WS_MAXIMIZE
)
212 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
218 if (Style
& WS_MAXIMIZE
)
222 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
228 if (Style
& WS_MAXIMIZE
)
232 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
238 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
)
242 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
245 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
249 DefWndStartSizeMove(HWND hWnd
, PWND Wnd
, WPARAM wParam
, POINT
*capturePoint
)
255 ULONG Style
= Wnd
->style
;
257 rectWindow
= Wnd
->rcWindow
;
259 if ((wParam
& 0xfff0) == SC_MOVE
)
261 /* Move pointer at the center of the caption */
263 UserGetInsideRectNC(Wnd
, &rect
);
264 if (Style
& WS_SYSMENU
)
265 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
266 if (Style
& WS_MINIMIZEBOX
)
267 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
268 if (Style
& WS_MAXIMIZEBOX
)
269 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
270 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
271 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
280 if (!GetMessageW(&msg
, NULL
, 0, 0)) break; //return 0;
281 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
286 hittest
= DefWndNCHitTest(hWnd
, msg
.pt
);
287 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
299 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
300 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
304 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
305 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
309 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
310 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
314 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
315 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
322 TranslateMessage( &msg
);
323 DispatchMessageW( &msg
);
329 SetCursorPos( pt
.x
, pt
.y
);
330 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
), Style
);
334 #define ON_LEFT_BORDER(hit) \
335 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
336 #define ON_RIGHT_BORDER(hit) \
337 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
338 #define ON_TOP_BORDER(hit) \
339 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
340 #define ON_BOTTOM_BORDER(hit) \
341 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
344 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
345 ULONG width
, ULONG height
)
347 static HBRUSH hDraggingRectBrush
= NULL
;
350 if(!hDraggingRectBrush
)
352 static HBITMAP hDraggingPattern
= NULL
;
353 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
355 hDraggingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
356 hDraggingRectBrush
= CreatePatternBrush(hDraggingPattern
);
359 hbrush
= SelectObject( hdc
, hDraggingRectBrush
);
360 PatBlt( hdc
, rect
->left
, rect
->top
,
361 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
362 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
363 rect
->bottom
- rect
->top
- height
, PATINVERT
);
364 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
365 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
366 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
367 rect
->bottom
- rect
->top
- height
, PATINVERT
);
368 SelectObject( hdc
, hbrush
);
372 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
376 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
), GetSystemMetrics(SM_CYFRAME
));
380 UserDrawWindowFrame(hdc
, rect
, 1, 1);
385 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
389 RECT sizingRect
, mouseRect
, origRect
, clipRect
, unmodRect
;
391 LONG hittest
= (LONG
)(wParam
& 0x0f);
392 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
393 POINT minTrack
, maxTrack
;
394 POINT capturePoint
, pt
;
395 ULONG Style
, ExStyle
;
399 DWORD dwPoint
= GetMessagePos();
400 BOOL DragFullWindows
= FALSE
;
401 HWND hWndParent
= NULL
;
404 Wnd
= ValidateHwnd(hwnd
);
409 ExStyle
= Wnd
->ExStyle
;
410 iconic
= (Style
& WS_MINIMIZE
) != 0;
412 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
414 pt
.x
= GET_X_LPARAM(dwPoint
);
415 pt
.y
= GET_Y_LPARAM(dwPoint
);
418 if ((Style
& WS_MAXIMIZE
) || !IsWindowVisible(hwnd
))
423 thickframe
= UserHasThickFrameStyle(Style
, ExStyle
) && !(Style
& WS_MINIMIZE
);
424 if ((wParam
& 0xfff0) == SC_MOVE
)
428 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
441 if (hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
))
443 hittest
+= (HTLEFT
- WMSZ_LEFT
);
448 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
457 /* Get min/max info */
459 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
460 sizingRect
= Wnd
->rcWindow
;
461 if (Style
& WS_CHILD
)
463 hWndParent
= GetParent(hwnd
);
464 MapWindowPoints( 0, hWndParent
, (LPPOINT
)&sizingRect
, 2 );
465 unmodRect
= sizingRect
;
466 GetClientRect(hWndParent
, &mouseRect
);
467 clipRect
= mouseRect
;
468 MapWindowPoints(hWndParent
, HWND_DESKTOP
, (LPPOINT
)&clipRect
, 2);
472 if(!(ExStyle
& WS_EX_TOPMOST
))
474 SystemParametersInfoW(SPI_GETWORKAREA
, 0, &clipRect
, 0);
475 mouseRect
= clipRect
;
479 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
480 clipRect
= mouseRect
;
482 unmodRect
= sizingRect
;
484 ClipCursor(&clipRect
);
486 origRect
= sizingRect
;
487 if (ON_LEFT_BORDER(hittest
))
489 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
490 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
492 else if (ON_RIGHT_BORDER(hittest
))
494 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
495 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
497 if (ON_TOP_BORDER(hittest
))
499 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
500 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
502 else if (ON_BOTTOM_BORDER(hittest
))
504 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
505 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
507 if (Style
& WS_CHILD
)
509 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
512 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
513 NtUserxSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, hwnd
);
514 if (GetCapture() != hwnd
) SetCapture( hwnd
);
516 if (Style
& WS_CHILD
)
518 /* Retrieve a default cache DC (without using the window style) */
519 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
525 DesktopRgn
= CreateRectRgnIndirect(&clipRect
);
528 SelectObject(hdc
, DesktopRgn
);
530 if( iconic
) /* create a cursor for dragging */
532 HICON hIcon
= (HICON
)GetClassLongPtrW(hwnd
, GCL_HICON
);
533 if(!hIcon
) hIcon
= (HICON
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
534 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
535 if( !hDragCursor
) iconic
= FALSE
;
538 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
539 if( !iconic
&& !DragFullWindows
)
541 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
548 if (!GetMessageW(&msg
, 0, 0, 0)) break;
549 if (CallMsgFilterW( &msg
, MSGF_SIZE
)) continue;
551 /* Exit on button-up, Return, or Esc */
552 if ((msg
.message
== WM_LBUTTONUP
) ||
553 ((msg
.message
== WM_KEYDOWN
) &&
554 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
556 if (msg
.message
== WM_PAINT
)
558 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
559 UpdateWindow( msg
.hwnd
);
560 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
564 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
566 TranslateMessage( &msg
);
567 DispatchMessageW( &msg
);
568 continue; /* We are not interested in other messages */
573 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
575 case VK_UP
: pt
.y
-= 8; break;
576 case VK_DOWN
: pt
.y
+= 8; break;
577 case VK_LEFT
: pt
.x
-= 8; break;
578 case VK_RIGHT
: pt
.x
+= 8; break;
581 pt
.x
= max( pt
.x
, mouseRect
.left
);
582 pt
.x
= min( pt
.x
, mouseRect
.right
);
583 pt
.y
= max( pt
.y
, mouseRect
.top
);
584 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
586 dx
= pt
.x
- capturePoint
.x
;
587 dy
= pt
.y
- capturePoint
.y
;
595 if( iconic
) /* ok, no system popup tracking */
597 hOldCursor
= SetCursor(hDragCursor
);
602 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
605 RECT newRect
= unmodRect
;
606 WPARAM wpSizingHit
= 0;
608 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
609 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
610 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
611 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
612 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
613 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
616 /* determine the hit location */
617 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
618 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
620 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
625 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
627 /* To avoid any deadlocks, all the locks on the windows
628 structures must be suspended before the SetWindowPos */
629 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
630 newRect
.right
- newRect
.left
,
631 newRect
.bottom
- newRect
.top
,
632 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
635 sizingRect
= newRect
;
644 if( moved
) /* restore cursors, show icon title later on */
647 SetCursor( hOldCursor
);
649 DestroyCursor( hDragCursor
);
651 else if(!DragFullWindows
)
652 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
654 if (Style
& WS_CHILD
)
655 ReleaseDC( hWndParent
, hdc
);
661 DeleteObject(DesktopRgn
);
665 if (ISITHOOKED(WH_CBT
))
668 NtUserMessageCall( hwnd
, WM_CBT
, HCBT_MOVESIZE
, (LPARAM
)&sizingRect
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
669 if (lResult
) moved
= FALSE
;
672 NtUserxSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, NULL
);
673 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
674 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
676 /* window moved or resized */
679 /* if the moving/resizing isn't canceled call SetWindowPos
680 * with the new position or the new size of the window
682 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
684 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
686 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
687 sizingRect
.right
- sizingRect
.left
,
688 sizingRect
.bottom
- sizingRect
.top
,
689 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
691 else { /* restore previous size/position */
693 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
694 origRect
.right
- origRect
.left
,
695 origRect
.bottom
- origRect
.top
,
696 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
701 if( Style
& WS_MINIMIZE
)
703 /* Single click brings up the system menu when iconized */
707 if( Style
& WS_SYSMENU
)
708 SendMessageA( hwnd
, WM_SYSCOMMAND
,
709 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
715 /***********************************************************************
716 * DefWndTrackScrollBar
718 * Track a mouse button press on the horizontal or vertical scroll-bar.
721 DefWndTrackScrollBar(HWND Wnd
, WPARAM wParam
, POINT Pt
)
725 if (SC_HSCROLL
== (wParam
& 0xfff0))
727 if (HTHSCROLL
!= (wParam
& 0x0f))
733 else /* SC_VSCROLL */
735 if (HTVSCROLL
!= (wParam
& 0x0f))
741 ScrollTrackScrollBar(Wnd
, ScrollBar
, Pt
);
744 LRESULT WINAPI
DoAppSwitch( WPARAM wParam
, LPARAM lParam
);
747 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
749 // WINDOWPLACEMENT wp;
753 if (!IsWindowEnabled( hWnd
)) return 0;
755 if (ISITHOOKED(WH_CBT
))
757 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
758 if (lResult
) return 0;
761 switch (wParam
& 0xfff0)
765 DefWndDoSizeMove(hWnd
, wParam
);
768 if (hWnd
== GetActiveWindow())
769 ShowOwnedPopups(hWnd
,FALSE
);
770 ShowWindow( hWnd
, SW_MINIMIZE
);
774 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
775 ShowOwnedPopups(hWnd
,TRUE
);
776 ShowWindow( hWnd
, SW_MAXIMIZE
);
780 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
781 ShowOwnedPopups(hWnd
,TRUE
);
782 ShowWindow( hWnd
, SW_RESTORE
);
786 return SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
790 Pt
.x
= (short)LOWORD(lParam
);
791 Pt
.y
= (short)HIWORD(lParam
);
792 MenuTrackMouseMenuBar(hWnd
, wParam
& 0x000f, Pt
);
796 MenuTrackKbdMenuBar(hWnd
, wParam
, (WCHAR
)lParam
);
801 Pt
.x
= (short)LOWORD(lParam
);
802 Pt
.y
= (short)HIWORD(lParam
);
803 DefWndTrackScrollBar(hWnd
, wParam
, Pt
);
808 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
813 DoAppSwitch( wParam
, lParam
);
818 HWND hwnd
, hWndLastActive
;
822 pWnd
= ValidateHwnd(hwnd
);
825 hWndLastActive
= GetLastActivePopup(hwnd
);
828 hwnd
= hWndLastActive
;
829 pWnd
= ValidateHwnd(hwnd
);
831 SetForegroundWindow(hwnd
);
832 if (pWnd
->style
& WS_MINIMIZE
)
834 PostMessage(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
841 FIXME("Unimplemented DefWndHandleSysCommand wParam 0x%x\n",wParam
);
849 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
851 POINT maxTrack
, minTrack
;
852 LONG style
= GetWindowLongPtrA(hWnd
, GWL_STYLE
);
854 if (Pos
->flags
& SWP_NOSIZE
) return 0;
855 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
857 WinPosGetMinMaxInfo(hWnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
858 Pos
->cx
= min(Pos
->cx
, maxTrack
.x
);
859 Pos
->cy
= min(Pos
->cy
, maxTrack
.y
);
860 if (!(style
& WS_MINIMIZE
))
862 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
863 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
868 Pos
->cx
= max(Pos
->cx
, 0);
869 Pos
->cy
= max(Pos
->cy
, 0);
875 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
879 GetClientRect(hWnd
, &Rect
);
880 MapWindowPoints(hWnd
, (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
?
881 GetParent(hWnd
) : NULL
), (LPPOINT
) &Rect
, 2);
883 if (! (Pos
->flags
& SWP_NOCLIENTMOVE
))
885 SendMessageW(hWnd
, WM_MOVE
, 0, MAKELONG(Rect
.left
, Rect
.top
));
888 if (! (Pos
->flags
& SWP_NOCLIENTSIZE
))
890 WPARAM wp
= SIZE_RESTORED
;
895 else if (IsIconic(hWnd
))
899 SendMessageW(hWnd
, WM_SIZE
, wp
,
900 MAKELONG(Rect
.right
- Rect
.left
, Rect
.bottom
- Rect
.top
));
906 /***********************************************************************
909 * Default colors for control painting.
912 DefWndControlColor(HDC hDC
, UINT ctlType
)
914 if (ctlType
== CTLCOLOR_SCROLLBAR
)
916 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
917 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
918 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
921 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
922 * we better use 0x55aa bitmap brush to make scrollbar's background
923 * look different from the window background.
925 if ( bk
== GetSysColor(COLOR_WINDOW
))
926 return gpsi
->hbrGray
;
928 UnrealizeObject( hb
);
932 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
934 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
936 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
940 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
941 return GetSysColorBrush(COLOR_3DFACE
);
944 return GetSysColorBrush(COLOR_WINDOW
);
947 static void DefWndPrint( HWND hwnd
, HDC hdc
, ULONG uFlags
)
952 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
953 !IsWindowVisible(hwnd
) )
957 * Unimplemented flags.
959 if ( (uFlags
& PRF_CHILDREN
) ||
960 (uFlags
& PRF_OWNED
) ||
961 (uFlags
& PRF_NONCLIENT
) )
963 FIXME("WM_PRINT message with unsupported flags\n");
969 if ( uFlags
& PRF_ERASEBKGND
)
970 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
975 if ( uFlags
& PRF_CLIENT
)
976 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, uFlags
);
980 UserSendUiUpdateMsg(HWND hwnd
, LPARAM lParam
)
982 SendMessageW(hwnd
, WM_UPDATEUISTATE
, (WPARAM
)lParam
, 0);
988 DefWndSetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
990 HICON hIcon
, hIconSmall
, hIconOld
;
992 if ( wParam
> ICON_SMALL2
)
994 SetLastError(ERROR_INVALID_PARAMETER
);
997 hIconSmall
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
998 hIcon
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
1000 hIconOld
= wParam
== ICON_BIG
? hIcon
: hIconSmall
;
1005 hIcon
= (HICON
)lParam
;
1008 hIconSmall
= (HICON
)lParam
;
1011 ERR("FIXME: Set ICON_SMALL2 support!\n");
1016 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
, hIcon
);
1017 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
, hIconSmall
);
1019 if ((pWnd
->style
& WS_CAPTION
) == WS_CAPTION
)
1020 DefWndNCPaint(UserHMGetHandle(pWnd
), HRGN_WINDOW
, -1); /* Repaint caption */
1022 return (LRESULT
)hIconOld
;
1026 DefWndGetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
1029 if ( wParam
> ICON_SMALL2
)
1031 SetLastError(ERROR_INVALID_PARAMETER
);
1037 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
1041 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
1046 return (LRESULT
)hIconRet
;
1050 DefWndScreenshot(HWND hWnd
)
1059 OpenClipboard(hWnd
);
1062 hdc
= GetWindowDC(hWnd
);
1063 GetWindowRect(hWnd
, &rect
);
1064 w
= rect
.right
- rect
.left
;
1065 h
= rect
.bottom
- rect
.top
;
1067 hbitmap
= CreateCompatibleBitmap(hdc
, w
, h
);
1068 hdc2
= CreateCompatibleDC(hdc
);
1069 SelectObject(hdc2
, hbitmap
);
1071 BitBlt(hdc2
, 0, 0, w
, h
,
1075 SetClipboardData(CF_BITMAP
, hbitmap
);
1077 ReleaseDC(hWnd
, hdc
);
1078 ReleaseDC(hWnd
, hdc2
);
1087 User32DefWindowProc(HWND hWnd
,
1096 pWnd
= ValidateHwnd(hWnd
);
1097 if (!pWnd
) return 0;
1104 return DefWndNCPaint(hWnd
, (HRGN
)wParam
, -1);
1109 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
1112 case WM_POPUPSYSTEMMENU
:
1114 /* This is an undocumented message used by the windows taskbar to
1115 display the system menu of windows that belong to other processes. */
1116 HMENU menu
= GetSystemMenu(hWnd
, FALSE
);
1119 TrackPopupMenu(menu
, TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
1120 LOWORD(lParam
), HIWORD(lParam
), 0, hWnd
, NULL
);
1126 return DefWndNCActivate(hWnd
, wParam
, lParam
);
1132 Point
.x
= GET_X_LPARAM(lParam
);
1133 Point
.y
= GET_Y_LPARAM(lParam
);
1134 return (DefWndNCHitTest(hWnd
, Point
));
1137 case WM_LBUTTONDOWN
:
1138 case WM_RBUTTONDOWN
:
1139 case WM_MBUTTONDOWN
:
1140 iF10Key
= iMenuSysKey
= 0;
1143 case WM_NCLBUTTONDOWN
:
1145 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
1148 case WM_LBUTTONDBLCLK
:
1149 return (DefWndNCLButtonDblClk(hWnd
, HTCLIENT
, lParam
));
1151 case WM_NCLBUTTONDBLCLK
:
1153 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
1156 case WM_WINDOWPOSCHANGING
:
1158 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1161 case WM_WINDOWPOSCHANGED
:
1163 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
1166 case WM_NCRBUTTONDOWN
:
1167 return NC_HandleNCRButtonDown( hWnd
, wParam
, lParam
);
1172 if (hWnd
== GetCapture())
1176 Pt
.x
= GET_X_LPARAM(lParam
);
1177 Pt
.y
= GET_Y_LPARAM(lParam
);
1178 ClientToScreen(hWnd
, &Pt
);
1179 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1182 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1186 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1191 case WM_NCRBUTTONUP
:
1193 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
1194 * in Windows), but what _should_ we do? According to MSDN :
1195 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
1196 * message to the window". When is it appropriate?
1200 case WM_CONTEXTMENU
:
1202 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1206 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1210 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1219 Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1221 Pt
.x
= GET_X_LPARAM(lParam
);
1222 Pt
.y
= GET_Y_LPARAM(lParam
);
1223 if (Style
& WS_CHILD
)
1225 ScreenToClient(GetParent(hWnd
), &Pt
);
1228 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1230 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1235 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
1237 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongPtrW(hWnd
, GWL_STYLE
),
1238 GetClassLongPtrW(hWnd
, GCL_STYLE
), HitCode
);
1240 if(HitCode
== HTCAPTION
)
1241 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
1243 Flags
= TPM_LEFTBUTTON
;
1245 TrackPopupMenu(SystemMenu
, Flags
,
1246 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1255 DefWndPrint(hWnd
, (HDC
)wParam
, lParam
);
1259 case WM_SYSCOLORCHANGE
:
1261 /* force to redraw non-client area */
1262 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1263 /* Use InvalidateRect to redraw client area, enable
1264 * erase to redraw all subcontrols otherwise send the
1265 * WM_SYSCOLORCHANGE to child windows/controls is required
1267 InvalidateRect(hWnd
,NULL
,TRUE
);
1277 /* If already in Paint and Client area is not empty just return. */
1278 if (pWnd
->state2
& WNDS2_STARTPAINT
&& !IsRectEmpty(&pWnd
->rcClient
))
1280 ERR("In Paint and Client area is not empty!\n");
1284 hDC
= BeginPaint(hWnd
, &Ps
);
1289 if (IsIconic(hWnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hWnd
, GCLP_HICON
))))
1293 GetClientRect(hWnd
, &ClientRect
);
1294 x
= (ClientRect
.right
- ClientRect
.left
-
1295 GetSystemMetrics(SM_CXICON
)) / 2;
1296 y
= (ClientRect
.bottom
- ClientRect
.top
-
1297 GetSystemMetrics(SM_CYICON
)) / 2;
1298 DrawIcon(hDC
, x
, y
, hIcon
);
1300 EndPaint(hWnd
, &Ps
);
1308 hRgn = CreateRectRgn(0, 0, 0, 0);
1309 if (GetUpdateRgn(hWnd, hRgn, FALSE) != NULLREGION)
1311 RedrawWindow(hWnd, NULL, hRgn,
1312 RDW_ERASENOW | RDW_ERASE | RDW_FRAME |
1321 LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
1322 if (wParam) SetWindowLongPtr(hWnd, GWL_STYLE, Style | WS_VISIBLE);
1325 RedrawWindow(hWnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE);
1326 Style &= ~WS_VISIBLE;
1327 SetWindowLongPtr(hWnd, GWL_STYLE, Style);
1333 DestroyWindow(hWnd
);
1336 case WM_MOUSEACTIVATE
:
1337 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1339 LONG Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
1340 if (Ret
) return (Ret
);
1342 return ( (HIWORD(lParam
) == WM_LBUTTONDOWN
&& LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
);
1345 /* The default action in Windows is to set the keyboard focus to
1346 * the window, if it's being activated and not minimized */
1347 if (LOWORD(wParam
) != WA_INACTIVE
&&
1348 !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1350 //ERR("WM_ACTIVATE %p\n",hWnd);
1356 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1357 return SendMessageW( GetParent(hWnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
1361 case WM_ICONERASEBKGND
:
1364 HBRUSH hBrush
= (HBRUSH
)GetClassLongPtrW(hWnd
, GCL_HBRBACKGROUND
);
1370 if (GetClassLongPtrW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1372 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1373 GetClientRect(hWnd
, &Rect
);
1374 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1378 GetClipBox((HDC
)wParam
, &Rect
);
1380 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1384 case WM_CTLCOLORMSGBOX
:
1385 case WM_CTLCOLOREDIT
:
1386 case WM_CTLCOLORLISTBOX
:
1387 case WM_CTLCOLORBTN
:
1388 case WM_CTLCOLORDLG
:
1389 case WM_CTLCOLORSTATIC
:
1390 case WM_CTLCOLORSCROLLBAR
:
1391 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1394 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
1398 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1400 if (Style
& WS_CHILD
)
1402 /* with the exception of the border around a resizable wnd,
1403 * give the parent first chance to set the cursor */
1404 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1406 HWND parent
= GetParent( hWnd
);
1409 if (parent
!= GetDesktopWindow() &&
1410 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
))
1415 if (parent
!= GetDesktopWindow() &&
1416 SendMessageA( parent
, WM_SETCURSOR
, wParam
, lParam
))
1421 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1425 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
1428 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
1433 if (HIWORD(lParam
) & KF_ALTDOWN
)
1434 { /* Previous state, if the key was down before this message,
1435 this is a cheap way to ignore autorepeat keys. */
1436 if ( !(HIWORD(lParam
) & KF_REPEAT
) )
1438 if ( ( wParam
== VK_MENU
||
1439 wParam
== VK_LMENU
||
1440 wParam
== VK_RMENU
) && !iMenuSysKey
)
1448 if (wParam
== VK_F4
) /* Try to close the window */
1450 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1451 if (!(GetClassLongPtrW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1452 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1454 else if (wParam
== VK_SNAPSHOT
) // Alt-VK_SNAPSHOT?
1457 while (GetParent(hwnd
) != NULL
)
1459 hwnd
= GetParent(hwnd
);
1461 DefWndScreenshot(hwnd
);
1463 else if ( wParam
== VK_ESCAPE
|| wParam
== VK_TAB
) // Alt-Tab/ESC Alt-Shift-Tab/ESC
1466 HWND Active
= GetActiveWindow(); // Noticed MDI problem.
1469 FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n");
1472 wParamTmp
= GetKeyState(VK_SHIFT
) & 0x8000 ? SC_PREVWINDOW
: SC_NEXTWINDOW
;
1473 SendMessageW( Active
, WM_SYSCOMMAND
, wParamTmp
, wParam
);
1476 else if( wParam
== VK_F10
)
1478 if (GetKeyState(VK_SHIFT
) & 0x8000)
1479 SendMessageW( hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, MAKELPARAM(-1, -1) );
1488 /* Press and release F10 or ALT */
1489 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
1490 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
1491 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
1492 iMenuSysKey
= iF10Key
= 0;
1499 if (wParam
== VK_RETURN
&& IsIconic(hWnd
))
1501 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
1504 if ((HIWORD(lParam
) & KF_ALTDOWN
) && wParam
)
1506 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
1507 if (wParam
== VK_SPACE
&& (GetWindowLongPtrW( hWnd
, GWL_STYLE
) & WS_CHILD
))
1508 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
1510 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
1512 else /* check for Ctrl-Esc */
1513 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
1520 /* FIXME: Check for a desktop. */
1521 //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
1522 MENU_EndMenu( hWnd
);
1523 if (GetCapture() == hWnd
)
1537 case WM_QUERYDROPOBJECT
:
1539 if (GetWindowLongPtrW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1546 case WM_QUERYDRAGICON
:
1551 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HICON
);
1554 return ((LRESULT
)hIcon
);
1556 for (Len
= 1; Len
< 64; Len
++)
1558 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1560 return((LRESULT
)hIcon
);
1563 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1566 case WM_ISACTIVEICON
:
1569 isai
= (pWnd
->state
& WNDS_ACTIVEFRAME
) != 0;
1573 case WM_NOTIFYFORMAT
:
1575 if (lParam
== NF_QUERY
)
1576 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1582 return DefWndSetIcon(pWnd
, wParam
, lParam
);
1587 return DefWndGetIcon(pWnd
, wParam
, lParam
);
1594 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1598 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1605 THRDCARETINFO CaretInfo
;
1608 case 0xffff: /* Caret timer */
1609 /* switch showing byte in win32k and get information about the caret */
1610 if(NtUserxSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1612 DrawCaret(hWnd
, &CaretInfo
);
1620 case WM_QUERYENDSESSION
:
1625 case WM_INPUTLANGCHANGEREQUEST
:
1629 if(wParam
& INPUTLANGCHANGE_BACKWARD
1630 && wParam
& INPUTLANGCHANGE_FORWARD
)
1635 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1637 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1638 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1639 else NewHkl
= (HKL
) lParam
;
1641 NtUserActivateKeyboardLayout(NewHkl
, 0);
1646 case WM_INPUTLANGCHANGE
:
1649 HWND
*win_array
= WIN_ListChildren( hWnd
);
1653 while (win_array
[count
])
1654 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
1655 HeapFree(GetProcessHeap(),0,win_array
);
1659 case WM_QUERYUISTATE
:
1662 PWND Wnd
= ValidateHwnd(hWnd
);
1666 Ret
|= UISF_HIDEFOCUS
;
1668 Ret
|= UISF_HIDEACCEL
;
1673 case WM_CHANGEUISTATE
:
1675 BOOL AlwaysShowCues
= FALSE
;
1676 WORD Action
= LOWORD(wParam
);
1677 WORD Flags
= HIWORD(wParam
);
1680 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1684 Wnd
= ValidateHwnd(hWnd
);
1685 if (!Wnd
|| lParam
!= 0)
1688 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1691 if (Flags
& UISF_ACTIVE
)
1693 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1696 if (Action
== UIS_INITIALIZE
)
1698 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1702 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1703 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1705 /* We need to update wParam in case we need to send out messages */
1706 wParam
= MAKEWPARAM(Action
, Flags
);
1712 /* See if we actually need to change something */
1713 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1715 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1718 /* Don't need to do anything... */
1722 /* See if we actually need to change something */
1723 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1725 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1728 /* Don't need to do anything... */
1732 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1736 if ((Wnd
->style
& WS_CHILD
) && Wnd
->spwndParent
!= NULL
)
1738 /* We're a child window and we need to pass this message down until
1739 we reach the root */
1740 hWnd
= UserHMGetHandle((PWND
)DesktopPtrToUser(Wnd
->spwndParent
));
1744 /* We're a top level window, we need to change the UI state */
1745 Msg
= WM_UPDATEUISTATE
;
1749 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1751 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1754 case WM_UPDATEUISTATE
:
1757 BOOL AlwaysShowCues
= FALSE
;
1758 WORD Action
= LOWORD(wParam
);
1759 WORD Flags
= HIWORD(wParam
);
1762 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1766 Wnd
= ValidateHwnd(hWnd
);
1767 if (!Wnd
|| lParam
!= 0)
1770 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1773 if (Flags
& UISF_ACTIVE
)
1775 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1778 if (Action
== UIS_INITIALIZE
)
1780 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1784 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1785 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1787 /* We need to update wParam for broadcasting the update */
1788 wParam
= MAKEWPARAM(Action
, Flags
);
1794 /* See if we actually need to change something */
1795 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1797 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1800 /* Don't need to do anything... */
1805 /* See if we actually need to change something */
1806 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1808 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1811 /* Don't need to do anything... */
1816 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1820 /* Pack the information and call win32k */
1823 if (!NtUserxUpdateUiState(hWnd
, Flags
| ((DWORD
)Action
<< 3)))
1827 /* Always broadcast the update to all children */
1828 EnumChildWindows(hWnd
,
1829 UserSendUiUpdateMsg
,
1835 /* Move to win32k !*/
1837 if (!lParam
) break; // Call when it is necessary.
1840 case WM_CLIENTSHUTDOWN
:
1845 NtUserMessageCall( hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, !bUnicode
);
1854 * helpers for calling IMM32 (from Wine 10/22/2008)
1856 * WM_IME_* messages are generated only by IMM32,
1857 * so I assume imm32 is already LoadLibrary-ed.
1860 DefWndImmGetDefaultIMEWnd(HWND hwnd
)
1862 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1863 HWND (WINAPI
*pFunc
)(HWND
);
1868 ERR("cannot get IMM32 handle\n");
1872 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmGetDefaultIMEWnd");
1874 hwndRet
= (*pFunc
)(hwnd
);
1881 DefWndImmIsUIMessageA(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1883 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1884 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1889 ERR("cannot get IMM32 handle\n");
1893 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageA");
1895 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1902 DefWndImmIsUIMessageW(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1904 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1905 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1910 ERR("cannot get IMM32 handle\n");
1914 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageW");
1916 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1923 RealDefWindowProcA(HWND hWnd
,
1931 Wnd
= ValidateHwnd(hWnd
);
1934 Msg
!= WM_CTLCOLORMSGBOX
&&
1935 Msg
!= WM_CTLCOLORBTN
&&
1936 Msg
!= WM_CTLCOLORDLG
&&
1937 Msg
!= WM_CTLCOLORSTATIC
)
1940 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1946 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
1950 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
1951 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
1952 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
1958 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1959 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1960 * may have child window IDs instead of window name */
1961 if (HIWORD(cs
->lpszName
))
1963 DefSetText(hWnd
, (PCWSTR
)cs
->lpszName
, TRUE
);
1970 case WM_GETTEXTLENGTH
:
1975 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1977 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1979 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1981 Wnd
->strName
.Length
)))
1983 Result
= (LRESULT
) len
;
1994 PSTR outbuf
= (PSTR
)lParam
;
1997 if (Wnd
!= NULL
&& wParam
!= 0)
1999 if (Wnd
->strName
.Buffer
!= NULL
)
2000 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2006 if (Wnd
->strName
.Length
!= 0)
2008 copy
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2009 Result
= WideCharToMultiByte(CP_ACP
,
2017 outbuf
[Result
] = '\0';
2028 DefSetText(hWnd
, (PCWSTR
)lParam
, TRUE
);
2030 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2032 /* FIXME: this is not 100% correct */
2033 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2035 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2039 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2046 case WM_IME_KEYDOWN
:
2048 Result
= PostMessageA(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2054 Result
= PostMessageA(hWnd
, WM_KEYUP
, wParam
, lParam
);
2061 PostMessageA(hWnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
2062 PostMessageA(hWnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
2066 case WM_IME_STARTCOMPOSITION
:
2067 case WM_IME_COMPOSITION
:
2068 case WM_IME_ENDCOMPOSITION
:
2074 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2076 Result
= SendMessageA(hwndIME
, Msg
, wParam
, lParam
);
2080 case WM_IME_SETCONTEXT
:
2084 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2086 Result
= DefWndImmIsUIMessageA(hwndIME
, Msg
, wParam
, lParam
);
2092 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
2095 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2101 RealDefWindowProcW(HWND hWnd
,
2109 Wnd
= ValidateHwnd(hWnd
);
2112 Msg
!= WM_CTLCOLORMSGBOX
&&
2113 Msg
!= WM_CTLCOLORBTN
&&
2114 Msg
!= WM_CTLCOLORDLG
&&
2115 Msg
!= WM_CTLCOLORSTATIC
)
2118 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
2124 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
2128 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
2129 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
2130 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
2136 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
2137 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
2138 * may have child window IDs instead of window name */
2139 if (HIWORD(cs
->lpszName
))
2141 DefSetText(hWnd
, cs
->lpszName
, FALSE
);
2148 case WM_GETTEXTLENGTH
:
2153 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
2155 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2157 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
2159 Wnd
->strName
.Length
)))
2161 Result
= (LRESULT
) (Wnd
->strName
.Length
/ sizeof(WCHAR
));
2172 PWSTR outbuf
= (PWSTR
)lParam
;
2174 if (Wnd
!= NULL
&& wParam
!= 0)
2176 if (Wnd
->strName
.Buffer
!= NULL
)
2177 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2183 if (Wnd
->strName
.Length
!= 0)
2185 Result
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2186 RtlCopyMemory(outbuf
,
2188 Result
* sizeof(WCHAR
));
2189 outbuf
[Result
] = L
'\0';
2200 DefSetText(hWnd
, (PCWSTR
)lParam
, FALSE
);
2202 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2204 /* FIXME: this is not 100% correct */
2205 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2207 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2211 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2220 PostMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
2225 case WM_IME_KEYDOWN
:
2227 Result
= PostMessageW(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2233 Result
= PostMessageW(hWnd
, WM_KEYUP
, wParam
, lParam
);
2237 case WM_IME_STARTCOMPOSITION
:
2238 case WM_IME_COMPOSITION
:
2239 case WM_IME_ENDCOMPOSITION
:
2245 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2247 Result
= SendMessageW(hwndIME
, Msg
, wParam
, lParam
);
2251 case WM_IME_SETCONTEXT
:
2255 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2257 Result
= DefWndImmIsUIMessageW(hwndIME
, Msg
, wParam
, lParam
);
2262 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
2264 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2270 DefWindowProcA(HWND hWnd
,
2275 BOOL Hook
, msgOverride
= FALSE
;
2280 Hook
= BeginIfHookedUserApiHook();
2283 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2284 if(msgOverride
== FALSE
)
2290 /* Bypass SEH and go direct. */
2291 if (!Hook
|| !msgOverride
)
2292 return RealDefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2296 Result
= guah
.DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2298 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2309 DefWindowProcW(HWND hWnd
,
2314 BOOL Hook
, msgOverride
= FALSE
;
2319 Hook
= BeginIfHookedUserApiHook();
2322 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2323 if(msgOverride
== FALSE
)
2329 /* Bypass SEH and go direct. */
2330 if (!Hook
|| !msgOverride
)
2331 return RealDefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2335 Result
= guah
.DefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2337 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)