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 WinExec( "taskman.exe", SW_SHOWNORMAL
);
812 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
817 DoAppSwitch( wParam
, lParam
);
822 HWND hwnd
, hWndLastActive
;
826 pWnd
= ValidateHwnd(hwnd
);
829 hWndLastActive
= GetLastActivePopup(hwnd
);
832 hwnd
= hWndLastActive
;
833 pWnd
= ValidateHwnd(hwnd
);
835 SetForegroundWindow(hwnd
);
836 if (pWnd
->style
& WS_MINIMIZE
)
838 PostMessage(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
845 FIXME("Unimplemented DefWndHandleSysCommand wParam 0x%x\n",wParam
);
853 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
855 POINT maxTrack
, minTrack
;
856 LONG style
= GetWindowLongPtrA(hWnd
, GWL_STYLE
);
858 if (Pos
->flags
& SWP_NOSIZE
) return 0;
859 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
861 WinPosGetMinMaxInfo(hWnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
862 Pos
->cx
= min(Pos
->cx
, maxTrack
.x
);
863 Pos
->cy
= min(Pos
->cy
, maxTrack
.y
);
864 if (!(style
& WS_MINIMIZE
))
866 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
867 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
872 Pos
->cx
= max(Pos
->cx
, 0);
873 Pos
->cy
= max(Pos
->cy
, 0);
879 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
883 GetClientRect(hWnd
, &Rect
);
884 MapWindowPoints(hWnd
, (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
?
885 GetParent(hWnd
) : NULL
), (LPPOINT
) &Rect
, 2);
887 if (! (Pos
->flags
& SWP_NOCLIENTMOVE
))
889 SendMessageW(hWnd
, WM_MOVE
, 0, MAKELONG(Rect
.left
, Rect
.top
));
892 if (! (Pos
->flags
& SWP_NOCLIENTSIZE
))
894 WPARAM wp
= SIZE_RESTORED
;
899 else if (IsIconic(hWnd
))
903 SendMessageW(hWnd
, WM_SIZE
, wp
,
904 MAKELONG(Rect
.right
- Rect
.left
, Rect
.bottom
- Rect
.top
));
910 /***********************************************************************
913 * Default colors for control painting.
916 DefWndControlColor(HDC hDC
, UINT ctlType
)
918 if (ctlType
== CTLCOLOR_SCROLLBAR
)
920 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
921 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
922 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
925 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
926 * we better use 0x55aa bitmap brush to make scrollbar's background
927 * look different from the window background.
929 if ( bk
== GetSysColor(COLOR_WINDOW
))
930 return gpsi
->hbrGray
;
932 UnrealizeObject( hb
);
936 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
938 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
940 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
944 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
945 return GetSysColorBrush(COLOR_3DFACE
);
948 return GetSysColorBrush(COLOR_WINDOW
);
951 static void DefWndPrint( HWND hwnd
, HDC hdc
, ULONG uFlags
)
956 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
957 !IsWindowVisible(hwnd
) )
961 * Unimplemented flags.
963 if ( (uFlags
& PRF_CHILDREN
) ||
964 (uFlags
& PRF_OWNED
) ||
965 (uFlags
& PRF_NONCLIENT
) )
967 FIXME("WM_PRINT message with unsupported flags\n");
973 if ( uFlags
& PRF_ERASEBKGND
)
974 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
979 if ( uFlags
& PRF_CLIENT
)
980 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, uFlags
);
984 UserSendUiUpdateMsg(HWND hwnd
, LPARAM lParam
)
986 SendMessageW(hwnd
, WM_UPDATEUISTATE
, (WPARAM
)lParam
, 0);
992 DefWndSetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
994 HICON hIcon
, hIconSmall
, hIconOld
;
996 if ( wParam
> ICON_SMALL2
)
998 SetLastError(ERROR_INVALID_PARAMETER
);
1001 hIconSmall
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
1002 hIcon
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
1004 hIconOld
= wParam
== ICON_BIG
? hIcon
: hIconSmall
;
1009 hIcon
= (HICON
)lParam
;
1012 hIconSmall
= (HICON
)lParam
;
1015 ERR("FIXME: Set ICON_SMALL2 support!\n");
1020 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
, hIcon
);
1021 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
, hIconSmall
);
1023 if ((pWnd
->style
& WS_CAPTION
) == WS_CAPTION
)
1024 DefWndNCPaint(UserHMGetHandle(pWnd
), HRGN_WINDOW
, -1); /* Repaint caption */
1026 return (LRESULT
)hIconOld
;
1030 DefWndGetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
1033 if ( wParam
> ICON_SMALL2
)
1035 SetLastError(ERROR_INVALID_PARAMETER
);
1041 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
1045 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
1050 return (LRESULT
)hIconRet
;
1054 DefWndScreenshot(HWND hWnd
)
1063 OpenClipboard(hWnd
);
1066 hdc
= GetWindowDC(hWnd
);
1067 GetWindowRect(hWnd
, &rect
);
1068 w
= rect
.right
- rect
.left
;
1069 h
= rect
.bottom
- rect
.top
;
1071 hbitmap
= CreateCompatibleBitmap(hdc
, w
, h
);
1072 hdc2
= CreateCompatibleDC(hdc
);
1073 SelectObject(hdc2
, hbitmap
);
1075 BitBlt(hdc2
, 0, 0, w
, h
,
1079 SetClipboardData(CF_BITMAP
, hbitmap
);
1081 ReleaseDC(hWnd
, hdc
);
1082 ReleaseDC(hWnd
, hdc2
);
1091 User32DefWindowProc(HWND hWnd
,
1100 pWnd
= ValidateHwnd(hWnd
);
1101 if (!pWnd
) return 0;
1108 return DefWndNCPaint(hWnd
, (HRGN
)wParam
, -1);
1113 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
1116 case WM_POPUPSYSTEMMENU
:
1118 /* This is an undocumented message used by the windows taskbar to
1119 display the system menu of windows that belong to other processes. */
1120 HMENU menu
= GetSystemMenu(hWnd
, FALSE
);
1123 TrackPopupMenu(menu
, TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
1124 LOWORD(lParam
), HIWORD(lParam
), 0, hWnd
, NULL
);
1130 return DefWndNCActivate(hWnd
, wParam
, lParam
);
1136 Point
.x
= GET_X_LPARAM(lParam
);
1137 Point
.y
= GET_Y_LPARAM(lParam
);
1138 return (DefWndNCHitTest(hWnd
, Point
));
1141 case WM_LBUTTONDOWN
:
1142 case WM_RBUTTONDOWN
:
1143 case WM_MBUTTONDOWN
:
1144 iF10Key
= iMenuSysKey
= 0;
1147 case WM_NCLBUTTONDOWN
:
1149 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
1152 case WM_LBUTTONDBLCLK
:
1153 return (DefWndNCLButtonDblClk(hWnd
, HTCLIENT
, lParam
));
1155 case WM_NCLBUTTONDBLCLK
:
1157 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
1160 case WM_WINDOWPOSCHANGING
:
1162 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1165 case WM_WINDOWPOSCHANGED
:
1167 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
1170 case WM_NCRBUTTONDOWN
:
1171 return NC_HandleNCRButtonDown( hWnd
, wParam
, lParam
);
1176 if (hWnd
== GetCapture())
1180 Pt
.x
= GET_X_LPARAM(lParam
);
1181 Pt
.y
= GET_Y_LPARAM(lParam
);
1182 ClientToScreen(hWnd
, &Pt
);
1183 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1186 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1190 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1195 case WM_NCRBUTTONUP
:
1197 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
1198 * in Windows), but what _should_ we do? According to MSDN :
1199 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
1200 * message to the window". When is it appropriate?
1204 case WM_CONTEXTMENU
:
1206 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1210 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1214 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1223 Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1225 Pt
.x
= GET_X_LPARAM(lParam
);
1226 Pt
.y
= GET_Y_LPARAM(lParam
);
1227 if (Style
& WS_CHILD
)
1229 ScreenToClient(GetParent(hWnd
), &Pt
);
1232 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1234 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1239 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
1241 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongPtrW(hWnd
, GWL_STYLE
),
1242 GetClassLongPtrW(hWnd
, GCL_STYLE
), HitCode
);
1244 if(HitCode
== HTCAPTION
)
1245 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
1247 Flags
= TPM_LEFTBUTTON
;
1249 TrackPopupMenu(SystemMenu
, Flags
,
1250 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1259 DefWndPrint(hWnd
, (HDC
)wParam
, lParam
);
1263 case WM_SYSCOLORCHANGE
:
1265 /* force to redraw non-client area */
1266 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1267 /* Use InvalidateRect to redraw client area, enable
1268 * erase to redraw all subcontrols otherwise send the
1269 * WM_SYSCOLORCHANGE to child windows/controls is required
1271 InvalidateRect(hWnd
,NULL
,TRUE
);
1281 /* If already in Paint and Client area is not empty just return. */
1282 if (pWnd
->state2
& WNDS2_STARTPAINT
&& !IsRectEmpty(&pWnd
->rcClient
))
1284 ERR("In Paint and Client area is not empty!\n");
1288 hDC
= BeginPaint(hWnd
, &Ps
);
1293 if (IsIconic(hWnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hWnd
, GCLP_HICON
))))
1297 GetClientRect(hWnd
, &ClientRect
);
1298 x
= (ClientRect
.right
- ClientRect
.left
-
1299 GetSystemMetrics(SM_CXICON
)) / 2;
1300 y
= (ClientRect
.bottom
- ClientRect
.top
-
1301 GetSystemMetrics(SM_CYICON
)) / 2;
1302 DrawIcon(hDC
, x
, y
, hIcon
);
1304 EndPaint(hWnd
, &Ps
);
1312 hRgn = CreateRectRgn(0, 0, 0, 0);
1313 if (GetUpdateRgn(hWnd, hRgn, FALSE) != NULLREGION)
1315 RedrawWindow(hWnd, NULL, hRgn,
1316 RDW_ERASENOW | RDW_ERASE | RDW_FRAME |
1325 LONG_PTR Style = GetWindowLongPtrW(hWnd, GWL_STYLE);
1326 if (wParam) SetWindowLongPtr(hWnd, GWL_STYLE, Style | WS_VISIBLE);
1329 RedrawWindow(hWnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE);
1330 Style &= ~WS_VISIBLE;
1331 SetWindowLongPtr(hWnd, GWL_STYLE, Style);
1337 DestroyWindow(hWnd
);
1340 case WM_MOUSEACTIVATE
:
1341 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1343 LONG Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
1344 if (Ret
) return (Ret
);
1346 return ( (HIWORD(lParam
) == WM_LBUTTONDOWN
&& LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
);
1349 /* The default action in Windows is to set the keyboard focus to
1350 * the window, if it's being activated and not minimized */
1351 if (LOWORD(wParam
) != WA_INACTIVE
&&
1352 !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1354 //ERR("WM_ACTIVATE %p\n",hWnd);
1360 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1361 return SendMessageW( GetParent(hWnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
1365 case WM_ICONERASEBKGND
:
1368 HBRUSH hBrush
= (HBRUSH
)GetClassLongPtrW(hWnd
, GCL_HBRBACKGROUND
);
1374 if (GetClassLongPtrW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1376 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1377 GetClientRect(hWnd
, &Rect
);
1378 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1382 GetClipBox((HDC
)wParam
, &Rect
);
1384 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1388 case WM_CTLCOLORMSGBOX
:
1389 case WM_CTLCOLOREDIT
:
1390 case WM_CTLCOLORLISTBOX
:
1391 case WM_CTLCOLORBTN
:
1392 case WM_CTLCOLORDLG
:
1393 case WM_CTLCOLORSTATIC
:
1394 case WM_CTLCOLORSCROLLBAR
:
1395 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1398 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
1402 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
1404 if (Style
& WS_CHILD
)
1406 /* with the exception of the border around a resizable wnd,
1407 * give the parent first chance to set the cursor */
1408 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1410 HWND parent
= GetParent( hWnd
);
1413 if (parent
!= GetDesktopWindow() &&
1414 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
))
1419 if (parent
!= GetDesktopWindow() &&
1420 SendMessageA( parent
, WM_SETCURSOR
, wParam
, lParam
))
1425 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1429 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
1432 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
1437 if (HIWORD(lParam
) & KF_ALTDOWN
)
1438 { /* Previous state, if the key was down before this message,
1439 this is a cheap way to ignore autorepeat keys. */
1440 if ( !(HIWORD(lParam
) & KF_REPEAT
) )
1442 if ( ( wParam
== VK_MENU
||
1443 wParam
== VK_LMENU
||
1444 wParam
== VK_RMENU
) && !iMenuSysKey
)
1452 if (wParam
== VK_F4
) /* Try to close the window */
1454 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1455 if (!(GetClassLongPtrW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1456 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1458 else if (wParam
== VK_SNAPSHOT
) // Alt-VK_SNAPSHOT?
1461 while (GetParent(hwnd
) != NULL
)
1463 hwnd
= GetParent(hwnd
);
1465 DefWndScreenshot(hwnd
);
1467 else if ( wParam
== VK_ESCAPE
|| wParam
== VK_TAB
) // Alt-Tab/ESC Alt-Shift-Tab/ESC
1470 HWND Active
= GetActiveWindow(); // Noticed MDI problem.
1473 FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n");
1476 wParamTmp
= GetKeyState(VK_SHIFT
) & 0x8000 ? SC_PREVWINDOW
: SC_NEXTWINDOW
;
1477 SendMessageW( Active
, WM_SYSCOMMAND
, wParamTmp
, wParam
);
1480 else if( wParam
== VK_F10
)
1482 if (GetKeyState(VK_SHIFT
) & 0x8000)
1483 SendMessageW( hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, MAKELPARAM(-1, -1) );
1492 /* Press and release F10 or ALT */
1493 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
1494 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
1495 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
1496 iMenuSysKey
= iF10Key
= 0;
1503 if (wParam
== VK_RETURN
&& IsIconic(hWnd
))
1505 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
1508 if ((HIWORD(lParam
) & KF_ALTDOWN
) && wParam
)
1510 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
1511 if (wParam
== VK_SPACE
&& (GetWindowLongPtrW( hWnd
, GWL_STYLE
) & WS_CHILD
))
1512 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
1514 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
1516 else /* check for Ctrl-Esc */
1517 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
1524 /* FIXME: Check for a desktop. */
1525 //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
1526 MENU_EndMenu( hWnd
);
1527 if (GetCapture() == hWnd
)
1541 case WM_QUERYDROPOBJECT
:
1543 if (GetWindowLongPtrW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1550 case WM_QUERYDRAGICON
:
1555 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HICON
);
1558 return ((LRESULT
)hIcon
);
1560 for (Len
= 1; Len
< 64; Len
++)
1562 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1564 return((LRESULT
)hIcon
);
1567 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1570 case WM_ISACTIVEICON
:
1573 isai
= (pWnd
->state
& WNDS_ACTIVEFRAME
) != 0;
1577 case WM_NOTIFYFORMAT
:
1579 if (lParam
== NF_QUERY
)
1580 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1586 return DefWndSetIcon(pWnd
, wParam
, lParam
);
1591 return DefWndGetIcon(pWnd
, wParam
, lParam
);
1598 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1602 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1609 THRDCARETINFO CaretInfo
;
1612 case 0xffff: /* Caret timer */
1613 /* switch showing byte in win32k and get information about the caret */
1614 if(NtUserxSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1616 DrawCaret(hWnd
, &CaretInfo
);
1624 case WM_QUERYENDSESSION
:
1629 case WM_INPUTLANGCHANGEREQUEST
:
1633 if(wParam
& INPUTLANGCHANGE_BACKWARD
1634 && wParam
& INPUTLANGCHANGE_FORWARD
)
1639 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1641 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1642 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1643 else NewHkl
= (HKL
) lParam
;
1645 NtUserActivateKeyboardLayout(NewHkl
, 0);
1650 case WM_INPUTLANGCHANGE
:
1653 HWND
*win_array
= WIN_ListChildren( hWnd
);
1657 while (win_array
[count
])
1658 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
1659 HeapFree(GetProcessHeap(),0,win_array
);
1663 case WM_QUERYUISTATE
:
1666 PWND Wnd
= ValidateHwnd(hWnd
);
1670 Ret
|= UISF_HIDEFOCUS
;
1672 Ret
|= UISF_HIDEACCEL
;
1677 case WM_CHANGEUISTATE
:
1679 BOOL AlwaysShowCues
= FALSE
;
1680 WORD Action
= LOWORD(wParam
);
1681 WORD Flags
= HIWORD(wParam
);
1684 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1688 Wnd
= ValidateHwnd(hWnd
);
1689 if (!Wnd
|| lParam
!= 0)
1692 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1695 if (Flags
& UISF_ACTIVE
)
1697 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1700 if (Action
== UIS_INITIALIZE
)
1702 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1706 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1707 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1709 /* We need to update wParam in case we need to send out messages */
1710 wParam
= MAKEWPARAM(Action
, Flags
);
1716 /* See if we actually need to change something */
1717 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1719 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1722 /* Don't need to do anything... */
1726 /* See if we actually need to change something */
1727 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1729 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1732 /* Don't need to do anything... */
1736 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1740 if ((Wnd
->style
& WS_CHILD
) && Wnd
->spwndParent
!= NULL
)
1742 /* We're a child window and we need to pass this message down until
1743 we reach the root */
1744 hWnd
= UserHMGetHandle((PWND
)DesktopPtrToUser(Wnd
->spwndParent
));
1748 /* We're a top level window, we need to change the UI state */
1749 Msg
= WM_UPDATEUISTATE
;
1753 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1755 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1758 case WM_UPDATEUISTATE
:
1761 BOOL AlwaysShowCues
= FALSE
;
1762 WORD Action
= LOWORD(wParam
);
1763 WORD Flags
= HIWORD(wParam
);
1766 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1770 Wnd
= ValidateHwnd(hWnd
);
1771 if (!Wnd
|| lParam
!= 0)
1774 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1777 if (Flags
& UISF_ACTIVE
)
1779 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1782 if (Action
== UIS_INITIALIZE
)
1784 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1788 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1789 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1791 /* We need to update wParam for broadcasting the update */
1792 wParam
= MAKEWPARAM(Action
, Flags
);
1798 /* See if we actually need to change something */
1799 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1801 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1804 /* Don't need to do anything... */
1809 /* See if we actually need to change something */
1810 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1812 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1815 /* Don't need to do anything... */
1820 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1824 /* Pack the information and call win32k */
1827 if (!NtUserxUpdateUiState(hWnd
, Flags
| ((DWORD
)Action
<< 3)))
1831 /* Always broadcast the update to all children */
1832 EnumChildWindows(hWnd
,
1833 UserSendUiUpdateMsg
,
1839 /* Move to win32k !*/
1841 if (!lParam
) break; // Call when it is necessary.
1844 case WM_CLIENTSHUTDOWN
:
1849 NtUserMessageCall( hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, !bUnicode
);
1858 * helpers for calling IMM32 (from Wine 10/22/2008)
1860 * WM_IME_* messages are generated only by IMM32,
1861 * so I assume imm32 is already LoadLibrary-ed.
1864 DefWndImmGetDefaultIMEWnd(HWND hwnd
)
1866 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1867 HWND (WINAPI
*pFunc
)(HWND
);
1872 ERR("cannot get IMM32 handle\n");
1876 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmGetDefaultIMEWnd");
1878 hwndRet
= (*pFunc
)(hwnd
);
1885 DefWndImmIsUIMessageA(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1887 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1888 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1893 ERR("cannot get IMM32 handle\n");
1897 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageA");
1899 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1906 DefWndImmIsUIMessageW(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1908 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1909 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1914 ERR("cannot get IMM32 handle\n");
1918 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageW");
1920 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1927 RealDefWindowProcA(HWND hWnd
,
1935 Wnd
= ValidateHwnd(hWnd
);
1938 Msg
!= WM_CTLCOLORMSGBOX
&&
1939 Msg
!= WM_CTLCOLORBTN
&&
1940 Msg
!= WM_CTLCOLORDLG
&&
1941 Msg
!= WM_CTLCOLORSTATIC
)
1944 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1950 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
1954 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
1955 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
1956 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
1962 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1963 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1964 * may have child window IDs instead of window name */
1965 if (HIWORD(cs
->lpszName
))
1967 DefSetText(hWnd
, (PCWSTR
)cs
->lpszName
, TRUE
);
1974 case WM_GETTEXTLENGTH
:
1979 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1981 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1983 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1985 Wnd
->strName
.Length
)))
1987 Result
= (LRESULT
) len
;
1998 PSTR outbuf
= (PSTR
)lParam
;
2001 if (Wnd
!= NULL
&& wParam
!= 0)
2003 if (Wnd
->strName
.Buffer
!= NULL
)
2004 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2010 if (Wnd
->strName
.Length
!= 0)
2012 copy
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2013 Result
= WideCharToMultiByte(CP_ACP
,
2021 outbuf
[Result
] = '\0';
2032 DefSetText(hWnd
, (PCWSTR
)lParam
, TRUE
);
2034 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2036 /* FIXME: this is not 100% correct */
2037 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2039 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2043 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2050 case WM_IME_KEYDOWN
:
2052 Result
= PostMessageA(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2058 Result
= PostMessageA(hWnd
, WM_KEYUP
, wParam
, lParam
);
2065 PostMessageA(hWnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
2066 PostMessageA(hWnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
2070 case WM_IME_STARTCOMPOSITION
:
2071 case WM_IME_COMPOSITION
:
2072 case WM_IME_ENDCOMPOSITION
:
2078 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2080 Result
= SendMessageA(hwndIME
, Msg
, wParam
, lParam
);
2084 case WM_IME_SETCONTEXT
:
2088 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2090 Result
= DefWndImmIsUIMessageA(hwndIME
, Msg
, wParam
, lParam
);
2096 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
2099 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2105 RealDefWindowProcW(HWND hWnd
,
2113 Wnd
= ValidateHwnd(hWnd
);
2116 Msg
!= WM_CTLCOLORMSGBOX
&&
2117 Msg
!= WM_CTLCOLORBTN
&&
2118 Msg
!= WM_CTLCOLORDLG
&&
2119 Msg
!= WM_CTLCOLORSTATIC
)
2122 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
2128 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
2132 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
2133 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
2134 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
2140 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
2141 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
2142 * may have child window IDs instead of window name */
2143 if (HIWORD(cs
->lpszName
))
2145 DefSetText(hWnd
, cs
->lpszName
, FALSE
);
2152 case WM_GETTEXTLENGTH
:
2157 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
2159 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2161 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
2163 Wnd
->strName
.Length
)))
2165 Result
= (LRESULT
) (Wnd
->strName
.Length
/ sizeof(WCHAR
));
2176 PWSTR outbuf
= (PWSTR
)lParam
;
2178 if (Wnd
!= NULL
&& wParam
!= 0)
2180 if (Wnd
->strName
.Buffer
!= NULL
)
2181 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
2187 if (Wnd
->strName
.Length
!= 0)
2189 Result
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
2190 RtlCopyMemory(outbuf
,
2192 Result
* sizeof(WCHAR
));
2193 outbuf
[Result
] = L
'\0';
2204 DefSetText(hWnd
, (PCWSTR
)lParam
, FALSE
);
2206 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2208 /* FIXME: this is not 100% correct */
2209 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
2211 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
2215 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
2224 PostMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
2229 case WM_IME_KEYDOWN
:
2231 Result
= PostMessageW(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
2237 Result
= PostMessageW(hWnd
, WM_KEYUP
, wParam
, lParam
);
2241 case WM_IME_STARTCOMPOSITION
:
2242 case WM_IME_COMPOSITION
:
2243 case WM_IME_ENDCOMPOSITION
:
2249 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2251 Result
= SendMessageW(hwndIME
, Msg
, wParam
, lParam
);
2255 case WM_IME_SETCONTEXT
:
2259 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
2261 Result
= DefWndImmIsUIMessageW(hwndIME
, Msg
, wParam
, lParam
);
2266 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
2268 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
2274 DefWindowProcA(HWND hWnd
,
2279 BOOL Hook
, msgOverride
= FALSE
;
2284 Hook
= BeginIfHookedUserApiHook();
2287 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2288 if(msgOverride
== FALSE
)
2294 /* Bypass SEH and go direct. */
2295 if (!Hook
|| !msgOverride
)
2296 return RealDefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2300 Result
= guah
.DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
2302 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
2313 DefWindowProcW(HWND hWnd
,
2318 BOOL Hook
, msgOverride
= FALSE
;
2323 Hook
= BeginIfHookedUserApiHook();
2326 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
2327 if(msgOverride
== FALSE
)
2333 /* Bypass SEH and go direct. */
2334 if (!Hook
|| !msgOverride
)
2335 return RealDefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2339 Result
= guah
.DefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
2341 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)