3 * COPYRIGHT: See COPYING in the top level directory
4 * PROJECT: ReactOS user32.dll
5 * FILE: lib/user32/windows/window.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
);
20 #define WM_SETVISIBLE 9
22 #ifndef WM_QUERYDROPOBJECT
23 #define WM_QUERYDROPOBJECT 0x022B
26 LRESULT
DefWndNCPaint(HWND hWnd
, HRGN hRgn
, BOOL Active
);
27 LRESULT
DefWndNCCalcSize(HWND hWnd
, BOOL CalcSizeStruct
, RECT
*Rect
);
28 LRESULT
DefWndNCActivate(HWND hWnd
, WPARAM wParam
);
29 LRESULT
DefWndNCHitTest(HWND hWnd
, POINT Point
);
30 LRESULT
DefWndNCLButtonDown(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
31 LRESULT
DefWndNCLButtonDblClk(HWND hWnd
, WPARAM wParam
, LPARAM lParam
);
32 void FASTCALL
MenuInitSysMenuPopup(HMENU Menu
, DWORD Style
, DWORD ClsStyle
, LONG HitTest
);
34 /* GLOBALS *******************************************************************/
36 COLORREF SysColors
[NUM_SYSCOLORS
] = {0};
37 HPEN SysPens
[NUM_SYSCOLORS
] = {0};
38 HBRUSH SysBrushes
[NUM_SYSCOLORS
] = {0};
40 /* Bits in the dwKeyData */
41 #define KEYDATA_ALT 0x2000
42 #define KEYDATA_PREVSTATE 0x4000
44 static short iF10Key
= 0;
45 static short iMenuSysKey
= 0;
47 /* FUNCTIONS *****************************************************************/
50 InitStockObjects(void)
52 /* FIXME - Instead of copying the stuff to usermode we should map the tables to
53 userland. The current implementation has one big flaw: the system color
54 table doesn't get updated when another process changes them. That's why
55 we should rather map the table into usermode. But it only affects the
56 SysColors table - the pens, brushes and stock objects are not affected
57 as their handles never change. But it'd be faster to map them, too. */
58 if(SysBrushes
[0] == NULL
)
60 /* only initialize once */
61 (void)NtUserGetSysColors(SysColors
, NUM_SYSCOLORS
);
62 (void)NtUserGetSysColorPens(SysPens
, NUM_SYSCOLORS
);
63 (void)NtUserGetSysColorBrushes(SysBrushes
, NUM_SYSCOLORS
);
71 GetSysColor(int nIndex
)
73 if(nIndex
>= 0 && nIndex
<= NUM_SYSCOLORS
)
75 return SysColors
[nIndex
];
78 SetLastError(ERROR_INVALID_PARAMETER
);
86 GetSysColorPen(int nIndex
)
88 if(nIndex
>= 0 && nIndex
<= NUM_SYSCOLORS
)
90 return SysPens
[nIndex
];
93 SetLastError(ERROR_INVALID_PARAMETER
);
101 GetSysColorBrush(int nIndex
)
103 if(nIndex
>= 0 && nIndex
<= NUM_SYSCOLORS
)
105 return SysBrushes
[nIndex
];
108 SetLastError(ERROR_INVALID_PARAMETER
);
119 CONST INT
*lpaElements
,
120 CONST COLORREF
*lpaRgbValues
)
129 ChangeSysColors
.Elements
= (INT
*)lpaElements
;
130 ChangeSysColors
.Colors
= (COLORREF
*)lpaRgbValues
;
134 Ret
= NtUserSetSysColors(&ChangeSysColors
, cElements
);
137 /* FIXME - just change it in the usermode structure, too, instead of asking win32k again */
138 (void)NtUserGetSysColors(SysColors
, NUM_SYSCOLORS
);
143 SetLastError(ERROR_INVALID_PARAMETER
);
151 UserGetInsideRectNC(PWINDOW Wnd
, RECT
*rect
)
157 ExStyle
= Wnd
->ExStyle
;
159 rect
->top
= rect
->left
= 0;
160 rect
->right
= Wnd
->WindowRect
.right
- Wnd
->WindowRect
.left
;
161 rect
->bottom
= Wnd
->WindowRect
.bottom
- Wnd
->WindowRect
.top
;
163 if (Style
& WS_ICONIC
)
168 /* Remove frame from rectangle */
169 if (UserHasThickFrameStyle(Style
, ExStyle
))
171 InflateRect(rect
, -GetSystemMetrics(SM_CXFRAME
),
172 -GetSystemMetrics(SM_CYFRAME
));
176 if (UserHasDlgFrameStyle(Style
, ExStyle
))
178 InflateRect(rect
, -GetSystemMetrics(SM_CXDLGFRAME
),
179 -GetSystemMetrics(SM_CYDLGFRAME
));
180 /* FIXME: this isn't in NC_AdjustRect? why not? */
181 if (ExStyle
& WS_EX_DLGMODALFRAME
)
182 InflateRect( rect
, -1, 0 );
186 if (UserHasThinFrameStyle(Style
, ExStyle
))
188 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
),
189 -GetSystemMetrics(SM_CYBORDER
));
197 DefWndSetRedraw(HWND hWnd
, WPARAM wParam
)
199 LONG Style
= GetWindowLong(hWnd
, GWL_STYLE
);
200 /* Content can be redrawn after a change. */
203 if (!(Style
& WS_VISIBLE
)) /* Not Visible */
205 SetWindowLong(hWnd
, GWL_STYLE
, WS_VISIBLE
);
208 else /* Content cannot be redrawn after a change. */
210 if (Style
& WS_VISIBLE
) /* Visible */
212 RedrawWindow( hWnd
, NULL
, 0, RDW_ALLCHILDREN
| RDW_VALIDATE
);
213 Style
&= ~WS_VISIBLE
;
214 SetWindowLong(hWnd
, GWL_STYLE
, Style
); /* clear bits */
222 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, ULONG Style
)
224 /* Not for child windows. */
225 if (hWnd
!= (HWND
)wParam
)
230 switch((INT_PTR
) LOWORD(lParam
))
234 WORD Msg
= HIWORD(lParam
);
235 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
236 Msg
== WM_RBUTTONDOWN
|| Msg
== WM_XBUTTONDOWN
)
245 HICON hCursor
= (HICON
)GetClassLongW(hWnd
, GCL_HCURSOR
);
257 if (Style
& WS_MAXIMIZE
)
261 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
267 if (Style
& WS_MAXIMIZE
)
271 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
277 if (Style
& WS_MAXIMIZE
)
281 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
287 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
)
291 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
294 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
298 DefWndStartSizeMove(HWND hWnd
, PWINDOW Wnd
, WPARAM wParam
, POINT
*capturePoint
)
304 ULONG Style
= Wnd
->Style
;
306 rectWindow
= Wnd
->WindowRect
;
308 if ((wParam
& 0xfff0) == SC_MOVE
)
310 /* Move pointer at the center of the caption */
312 UserGetInsideRectNC(Wnd
, &rect
);
313 if (Style
& WS_SYSMENU
)
314 rect
.left
+= GetSystemMetrics(SM_CXSIZE
) + 1;
315 if (Style
& WS_MINIMIZEBOX
)
316 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
317 if (Style
& WS_MAXIMIZEBOX
)
318 rect
.right
-= GetSystemMetrics(SM_CXSIZE
) + 1;
319 pt
.x
= rectWindow
.left
+ (rect
.right
- rect
.left
) / 2;
320 pt
.y
= rectWindow
.top
+ rect
.top
+ GetSystemMetrics(SM_CYSIZE
)/2;
329 if (GetMessageW(&msg
, NULL
, 0, 0) <= 0)
334 hittest
= DefWndNCHitTest(hWnd
, msg
.pt
);
335 if ((hittest
< HTLEFT
) || (hittest
> HTBOTTOMRIGHT
))
347 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
348 pt
.y
= rectWindow
.top
+ GetSystemMetrics(SM_CYFRAME
) / 2;
352 pt
.x
=(rectWindow
.left
+rectWindow
.right
)/2;
353 pt
.y
= rectWindow
.bottom
- GetSystemMetrics(SM_CYFRAME
) / 2;
357 pt
.x
= rectWindow
.left
+ GetSystemMetrics(SM_CXFRAME
) / 2;
358 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
362 pt
.x
= rectWindow
.right
- GetSystemMetrics(SM_CXFRAME
) / 2;
363 pt
.y
=(rectWindow
.top
+rectWindow
.bottom
)/2;
366 case VK_ESCAPE
: return 0;
372 SetCursorPos( pt
.x
, pt
.y
);
373 DefWndHandleSetCursor(hWnd
, (WPARAM
)hWnd
, MAKELONG(hittest
, WM_MOUSEMOVE
), Style
);
377 #define ON_LEFT_BORDER(hit) \
378 (((hit) == HTLEFT) || ((hit) == HTTOPLEFT) || ((hit) == HTBOTTOMLEFT))
379 #define ON_RIGHT_BORDER(hit) \
380 (((hit) == HTRIGHT) || ((hit) == HTTOPRIGHT) || ((hit) == HTBOTTOMRIGHT))
381 #define ON_TOP_BORDER(hit) \
382 (((hit) == HTTOP) || ((hit) == HTTOPLEFT) || ((hit) == HTTOPRIGHT))
383 #define ON_BOTTOM_BORDER(hit) \
384 (((hit) == HTBOTTOM) || ((hit) == HTBOTTOMLEFT) || ((hit) == HTBOTTOMRIGHT))
387 UserDrawWindowFrame(HDC hdc
, const RECT
*rect
,
388 ULONG width
, ULONG height
)
390 static HBRUSH hDraggingRectBrush
= NULL
;
393 if(!hDraggingRectBrush
)
395 static HBITMAP hDraggingPattern
= NULL
;
396 const DWORD Pattern
[4] = {0x5555AAAA, 0x5555AAAA, 0x5555AAAA, 0x5555AAAA};
398 hDraggingPattern
= CreateBitmap(8, 8, 1, 1, Pattern
);
399 hDraggingRectBrush
= CreatePatternBrush(hDraggingPattern
);
402 hbrush
= SelectObject( hdc
, hDraggingRectBrush
);
403 PatBlt( hdc
, rect
->left
, rect
->top
,
404 rect
->right
- rect
->left
- width
, height
, PATINVERT
);
405 PatBlt( hdc
, rect
->left
, rect
->top
+ height
, width
,
406 rect
->bottom
- rect
->top
- height
, PATINVERT
);
407 PatBlt( hdc
, rect
->left
+ width
, rect
->bottom
- 1,
408 rect
->right
- rect
->left
- width
, -height
, PATINVERT
);
409 PatBlt( hdc
, rect
->right
- 1, rect
->top
, -width
,
410 rect
->bottom
- rect
->top
- height
, PATINVERT
);
411 SelectObject( hdc
, hbrush
);
415 UserDrawMovingFrame(HDC hdc
, RECT
*rect
, BOOL thickframe
)
419 UserDrawWindowFrame(hdc
, rect
, GetSystemMetrics(SM_CXFRAME
), GetSystemMetrics(SM_CYFRAME
));
423 UserDrawWindowFrame(hdc
, rect
, 1, 1);
428 DefWndDoSizeMove(HWND hwnd
, WORD wParam
)
432 RECT sizingRect
, mouseRect
, origRect
, clipRect
, unmodRect
;
434 LONG hittest
= (LONG
)(wParam
& 0x0f);
435 HCURSOR hDragCursor
= 0, hOldCursor
= 0;
436 POINT minTrack
, maxTrack
;
437 POINT capturePoint
, pt
;
438 ULONG Style
, ExStyle
;
442 DWORD dwPoint
= GetMessagePos();
443 BOOL DragFullWindows
= FALSE
;
444 HWND hWndParent
= NULL
;
447 Wnd
= ValidateHwnd(hwnd
);
452 ExStyle
= Wnd
->ExStyle
;
453 iconic
= (Style
& WS_MINIMIZE
) != 0;
455 SystemParametersInfoA(SPI_GETDRAGFULLWINDOWS
, 0, &DragFullWindows
, 0);
457 pt
.x
= GET_X_LPARAM(dwPoint
);
458 pt
.y
= GET_Y_LPARAM(dwPoint
);
461 if ((Style
& WS_MAXIMIZE
) || !IsWindowVisible(hwnd
))
466 thickframe
= UserHasThickFrameStyle(Style
, ExStyle
) && !(Style
& WS_MINIMIZE
);
467 if ((wParam
& 0xfff0) == SC_MOVE
)
471 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
484 if (hittest
&& ((wParam
& 0xfff0) != SC_MOUSEMENU
))
486 hittest
+= (HTLEFT
- WMSZ_LEFT
);
491 hittest
= DefWndStartSizeMove(hwnd
, Wnd
, wParam
, &capturePoint
);
500 /* Get min/max info */
502 WinPosGetMinMaxInfo(hwnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
503 sizingRect
= Wnd
->WindowRect
;
504 if (Style
& WS_CHILD
)
506 hWndParent
= GetParent(hwnd
);
507 MapWindowPoints( 0, hWndParent
, (LPPOINT
)&sizingRect
, 2 );
508 unmodRect
= sizingRect
;
509 GetClientRect(hWndParent
, &mouseRect
);
510 clipRect
= mouseRect
;
511 MapWindowPoints(hWndParent
, HWND_DESKTOP
, (LPPOINT
)&clipRect
, 2);
515 if(!(ExStyle
& WS_EX_TOPMOST
))
517 SystemParametersInfoW(SPI_GETWORKAREA
, 0, &clipRect
, 0);
518 mouseRect
= clipRect
;
522 SetRect(&mouseRect
, 0, 0, GetSystemMetrics(SM_CXSCREEN
), GetSystemMetrics(SM_CYSCREEN
));
523 clipRect
= mouseRect
;
525 unmodRect
= sizingRect
;
527 ClipCursor(&clipRect
);
529 origRect
= sizingRect
;
530 if (ON_LEFT_BORDER(hittest
))
532 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.right
-maxTrack
.x
);
533 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.right
-minTrack
.x
);
535 else if (ON_RIGHT_BORDER(hittest
))
537 mouseRect
.left
= max( mouseRect
.left
, sizingRect
.left
+minTrack
.x
);
538 mouseRect
.right
= min( mouseRect
.right
, sizingRect
.left
+maxTrack
.x
);
540 if (ON_TOP_BORDER(hittest
))
542 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.bottom
-maxTrack
.y
);
543 mouseRect
.bottom
= min( mouseRect
.bottom
,sizingRect
.bottom
-minTrack
.y
);
545 else if (ON_BOTTOM_BORDER(hittest
))
547 mouseRect
.top
= max( mouseRect
.top
, sizingRect
.top
+minTrack
.y
);
548 mouseRect
.bottom
= min( mouseRect
.bottom
, sizingRect
.top
+maxTrack
.y
);
550 if (Style
& WS_CHILD
)
552 MapWindowPoints( hWndParent
, 0, (LPPOINT
)&mouseRect
, 2 );
555 SendMessageA( hwnd
, WM_ENTERSIZEMOVE
, 0, 0 );
556 (void)NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, hwnd
);
557 if (GetCapture() != hwnd
) SetCapture( hwnd
);
559 if (Style
& WS_CHILD
)
561 /* Retrieve a default cache DC (without using the window style) */
562 hdc
= GetDCEx(hWndParent
, 0, DCX_CACHE
);
568 DesktopRgn
= CreateRectRgnIndirect(&clipRect
);
571 SelectObject(hdc
, DesktopRgn
);
573 if( iconic
) /* create a cursor for dragging */
575 HICON hIcon
= (HICON
)GetClassLongW(hwnd
, GCL_HICON
);
576 if(!hIcon
) hIcon
= (HICON
)SendMessageW( hwnd
, WM_QUERYDRAGICON
, 0, 0L);
577 if( hIcon
) hDragCursor
= CursorIconToCursor( hIcon
, TRUE
);
578 if( !hDragCursor
) iconic
= FALSE
;
581 /* invert frame if WIN31_LOOK to indicate mouse click on caption */
582 if( !iconic
&& !DragFullWindows
)
584 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
591 if (GetMessageW(&msg
, 0, 0, 0) <= 0)
594 /* Exit on button-up, Return, or Esc */
595 if ((msg
.message
== WM_LBUTTONUP
) ||
596 ((msg
.message
== WM_KEYDOWN
) &&
597 ((msg
.wParam
== VK_RETURN
) || (msg
.wParam
== VK_ESCAPE
)))) break;
599 if (msg
.message
== WM_PAINT
)
601 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
602 UpdateWindow( msg
.hwnd
);
603 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
607 if ((msg
.message
!= WM_KEYDOWN
) && (msg
.message
!= WM_MOUSEMOVE
))
608 continue; /* We are not interested in other messages */
612 if (msg
.message
== WM_KEYDOWN
) switch(msg
.wParam
)
614 case VK_UP
: pt
.y
-= 8; break;
615 case VK_DOWN
: pt
.y
+= 8; break;
616 case VK_LEFT
: pt
.x
-= 8; break;
617 case VK_RIGHT
: pt
.x
+= 8; break;
620 pt
.x
= max( pt
.x
, mouseRect
.left
);
621 pt
.x
= min( pt
.x
, mouseRect
.right
);
622 pt
.y
= max( pt
.y
, mouseRect
.top
);
623 pt
.y
= min( pt
.y
, mouseRect
.bottom
);
625 dx
= pt
.x
- capturePoint
.x
;
626 dy
= pt
.y
- capturePoint
.y
;
634 if( iconic
) /* ok, no system popup tracking */
636 hOldCursor
= SetCursor(hDragCursor
);
641 if (msg
.message
== WM_KEYDOWN
) SetCursorPos( pt
.x
, pt
.y
);
644 RECT newRect
= unmodRect
;
645 WPARAM wpSizingHit
= 0;
647 if (hittest
== HTCAPTION
) OffsetRect( &newRect
, dx
, dy
);
648 if (ON_LEFT_BORDER(hittest
)) newRect
.left
+= dx
;
649 else if (ON_RIGHT_BORDER(hittest
)) newRect
.right
+= dx
;
650 if (ON_TOP_BORDER(hittest
)) newRect
.top
+= dy
;
651 else if (ON_BOTTOM_BORDER(hittest
)) newRect
.bottom
+= dy
;
652 if(!iconic
&& !DragFullWindows
) UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
655 /* determine the hit location */
656 if (hittest
>= HTLEFT
&& hittest
<= HTBOTTOMRIGHT
)
657 wpSizingHit
= WMSZ_LEFT
+ (hittest
- HTLEFT
);
659 SendMessageA( hwnd
, WM_SIZING
, wpSizingHit
, (LPARAM
)&newRect
);
664 UserDrawMovingFrame( hdc
, &newRect
, thickframe
);
666 /* To avoid any deadlocks, all the locks on the windows
667 structures must be suspended before the SetWindowPos */
668 SetWindowPos( hwnd
, 0, newRect
.left
, newRect
.top
,
669 newRect
.right
- newRect
.left
,
670 newRect
.bottom
- newRect
.top
,
671 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
674 sizingRect
= newRect
;
683 if( moved
) /* restore cursors, show icon title later on */
686 SetCursor( hOldCursor
);
688 DestroyCursor( hDragCursor
);
690 else if(!DragFullWindows
)
691 UserDrawMovingFrame( hdc
, &sizingRect
, thickframe
);
693 if (Style
& WS_CHILD
)
694 ReleaseDC( hWndParent
, hdc
);
700 DeleteObject(DesktopRgn
);
703 (void)NtUserSetGUIThreadHandle(MSQ_STATE_MOVESIZE
, NULL
);
704 SendMessageA( hwnd
, WM_EXITSIZEMOVE
, 0, 0 );
705 SendMessageA( hwnd
, WM_SETVISIBLE
, !IsIconic(hwnd
), 0L);
707 /* window moved or resized */
710 /* if the moving/resizing isn't canceled call SetWindowPos
711 * with the new position or the new size of the window
713 if (!((msg
.message
== WM_KEYDOWN
) && (msg
.wParam
== VK_ESCAPE
)) )
715 /* NOTE: SWP_NOACTIVATE prevents document window activation in Word 6 */
717 SetWindowPos( hwnd
, 0, sizingRect
.left
, sizingRect
.top
,
718 sizingRect
.right
- sizingRect
.left
,
719 sizingRect
.bottom
- sizingRect
.top
,
720 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
722 else { /* restore previous size/position */
724 SetWindowPos( hwnd
, 0, origRect
.left
, origRect
.top
,
725 origRect
.right
- origRect
.left
,
726 origRect
.bottom
- origRect
.top
,
727 ( hittest
== HTCAPTION
) ? SWP_NOSIZE
: 0 );
732 if( Style
& WS_MINIMIZE
)
734 /* Single click brings up the system menu when iconized */
738 if( Style
& WS_SYSMENU
)
739 SendMessageA( hwnd
, WM_SYSCOMMAND
,
740 SC_MOUSEMENU
+ HTSYSMENU
, MAKELONG(pt
.x
,pt
.y
));
746 /***********************************************************************
747 * DefWndTrackScrollBar
749 * Track a mouse button press on the horizontal or vertical scroll-bar.
752 DefWndTrackScrollBar(HWND Wnd
, WPARAM wParam
, POINT Pt
)
756 if (SC_HSCROLL
== (wParam
& 0xfff0))
758 if (HTHSCROLL
!= (wParam
& 0x0f))
764 else /* SC_VSCROLL */
766 if (HTVSCROLL
!= (wParam
& 0x0f))
772 ScrollTrackScrollBar(Wnd
, ScrollBar
, Pt
);
777 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
782 switch (wParam
& 0xfff0)
786 DefWndDoSizeMove(hWnd
, wParam
);
789 wp
.length
= sizeof(WINDOWPLACEMENT
);
790 if(GetWindowPlacement(hWnd
, &wp
))
792 wp
.showCmd
= SW_MINIMIZE
;
793 SetWindowPlacement(hWnd
, &wp
);
797 wp
.length
= sizeof(WINDOWPLACEMENT
);
798 if(GetWindowPlacement(hWnd
, &wp
))
800 wp
.showCmd
= SW_MAXIMIZE
;
801 SetWindowPlacement(hWnd
, &wp
);
805 wp
.length
= sizeof(WINDOWPLACEMENT
);
806 if(GetWindowPlacement(hWnd
, &wp
))
808 wp
.showCmd
= SW_RESTORE
;
809 SetWindowPlacement(hWnd
, &wp
);
813 SendMessageA(hWnd
, WM_CLOSE
, 0, 0);
817 Pt
.x
= (short)LOWORD(lParam
);
818 Pt
.y
= (short)HIWORD(lParam
);
819 MenuTrackMouseMenuBar(hWnd
, wParam
& 0x000f, Pt
);
823 MenuTrackKbdMenuBar(hWnd
, wParam
, (WCHAR
)lParam
);
828 Pt
.x
= (short)LOWORD(lParam
);
829 Pt
.y
= (short)HIWORD(lParam
);
830 DefWndTrackScrollBar(hWnd
, wParam
, Pt
);
835 /* FIXME: Implement */
844 DefWndHandleWindowPosChanging(HWND hWnd
, WINDOWPOS
* Pos
)
846 POINT maxTrack
, minTrack
;
847 LONG style
= GetWindowLongA(hWnd
, GWL_STYLE
);
849 if (Pos
->flags
& SWP_NOSIZE
) return 0;
850 if ((style
& WS_THICKFRAME
) || ((style
& (WS_POPUP
| WS_CHILD
)) == 0))
852 WinPosGetMinMaxInfo(hWnd
, NULL
, NULL
, &minTrack
, &maxTrack
);
853 Pos
->cx
= min(Pos
->cx
, maxTrack
.x
);
854 Pos
->cy
= min(Pos
->cy
, maxTrack
.y
);
855 if (!(style
& WS_MINIMIZE
))
857 if (Pos
->cx
< minTrack
.x
) Pos
->cx
= minTrack
.x
;
858 if (Pos
->cy
< minTrack
.y
) Pos
->cy
= minTrack
.y
;
863 Pos
->cx
= max(Pos
->cx
, 0);
864 Pos
->cy
= max(Pos
->cy
, 0);
869 /* Undocumented flags. */
870 #define SWP_NOCLIENTMOVE 0x0800
871 #define SWP_NOCLIENTSIZE 0x1000
874 DefWndHandleWindowPosChanged(HWND hWnd
, WINDOWPOS
* Pos
)
878 GetClientRect(hWnd
, &Rect
);
879 MapWindowPoints(hWnd
, (GetWindowLongW(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 (CTLCOLOR_SCROLLBAR
== ctlType
)
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
))
926 static const WORD wPattern55AA
[] =
928 0x5555, 0xaaaa, 0x5555, 0xaaaa,
929 0x5555, 0xaaaa, 0x5555, 0xaaaa
931 static HBITMAP hPattern55AABitmap
= NULL
;
932 static HBRUSH hPattern55AABrush
= NULL
;
933 if (hPattern55AABrush
== NULL
)
935 hPattern55AABitmap
= CreateBitmap(8, 8, 1, 1, wPattern55AA
);
936 hPattern55AABrush
= CreatePatternBrush(hPattern55AABitmap
);
938 return hPattern55AABrush
;
944 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
946 if ((CTLCOLOR_EDIT
== ctlType
) || (CTLCOLOR_LISTBOX
== ctlType
))
948 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
952 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
953 return GetSysColorBrush(COLOR_3DFACE
);
956 return GetSysColorBrush(COLOR_WINDOW
);
959 static void DefWndPrint( HWND hwnd
, HDC hdc
, ULONG uFlags
)
964 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
965 !IsWindowVisible(hwnd
) )
969 * Unimplemented flags.
971 if ( (uFlags
& PRF_CHILDREN
) ||
972 (uFlags
& PRF_OWNED
) ||
973 (uFlags
& PRF_NONCLIENT
) )
975 FIXME("WM_PRINT message with unsupported flags\n");
981 if ( uFlags
& PRF_ERASEBKGND
)
982 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
987 if ( uFlags
& PRF_CLIENT
)
988 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
992 UserSendUiUpdateMsg(HWND hwnd
, LPARAM lParam
)
994 SendMessageW(hwnd
, WM_UPDATEUISTATE
, (WPARAM
)lParam
, 0);
1000 DefWndScreenshot(HWND hWnd
)
1009 OpenClipboard(hWnd
);
1012 hdc
= GetWindowDC(hWnd
);
1013 GetWindowRect(hWnd
, &rect
);
1014 w
= rect
.right
- rect
.left
;
1015 h
= rect
.bottom
- rect
.top
;
1017 hbitmap
= CreateCompatibleBitmap(hdc
, w
, h
);
1018 hdc2
= CreateCompatibleDC(hdc
);
1019 SelectObject(hdc2
, hbitmap
);
1021 BitBlt(hdc2
, 0, 0, w
, h
,
1025 SetClipboardData(CF_BITMAP
, hbitmap
);
1027 ReleaseDC(hWnd
, hdc
);
1028 ReleaseDC(hWnd
, hdc2
);
1037 User32DefWindowProc(HWND hWnd
,
1047 return DefWndNCPaint(hWnd
, (HRGN
)wParam
, -1);
1052 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
1057 return DefWndNCActivate(hWnd
, wParam
);
1063 Point
.x
= GET_X_LPARAM(lParam
);
1064 Point
.y
= GET_Y_LPARAM(lParam
);
1065 return (DefWndNCHitTest(hWnd
, Point
));
1068 case WM_LBUTTONDOWN
:
1069 case WM_RBUTTONDOWN
:
1070 case WM_MBUTTONDOWN
:
1071 iF10Key
= iMenuSysKey
= 0;
1074 case WM_NCLBUTTONDOWN
:
1076 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
1079 case WM_LBUTTONDBLCLK
:
1080 return (DefWndNCLButtonDblClk(hWnd
, HTCLIENT
, lParam
));
1082 case WM_NCLBUTTONDBLCLK
:
1084 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
1087 case WM_WINDOWPOSCHANGING
:
1089 return (DefWndHandleWindowPosChanging(hWnd
, (WINDOWPOS
*)lParam
));
1092 case WM_WINDOWPOSCHANGED
:
1094 return (DefWndHandleWindowPosChanged(hWnd
, (WINDOWPOS
*)lParam
));
1097 case WM_NCRBUTTONDOWN
:
1099 /* in Windows, capture is taken when right-clicking on the caption bar */
1100 if (wParam
== HTCAPTION
)
1110 if (hWnd
== GetCapture())
1114 Pt
.x
= GET_X_LPARAM(lParam
);
1115 Pt
.y
= GET_Y_LPARAM(lParam
);
1116 ClientToScreen(hWnd
, &Pt
);
1117 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
1120 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1124 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
1129 case WM_NCRBUTTONUP
:
1131 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
1132 * in Windows), but what _should_ we do? According to MSDN :
1133 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
1134 * message to the window". When is it appropriate?
1138 case WM_CONTEXTMENU
:
1140 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1144 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1148 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
1157 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1159 Pt
.x
= GET_X_LPARAM(lParam
);
1160 Pt
.y
= GET_Y_LPARAM(lParam
);
1161 if (Style
& WS_CHILD
)
1163 ScreenToClient(GetParent(hWnd
), &Pt
);
1166 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
1168 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
1173 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
1175 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongW(hWnd
, GWL_STYLE
),
1176 GetClassLongW(hWnd
, GCL_STYLE
), HitCode
);
1178 if(HitCode
== HTCAPTION
)
1179 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
1181 Flags
= TPM_LEFTBUTTON
;
1183 TrackPopupMenu(SystemMenu
, Flags
,
1184 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
1193 DefWndPrint(hWnd
, (HDC
)wParam
, lParam
);
1201 HDC hDC
= BeginPaint(hWnd
, &Ps
);
1205 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
&&
1206 (hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
)) != NULL
)
1210 GetClientRect(hWnd
, &ClientRect
);
1211 x
= (ClientRect
.right
- ClientRect
.left
-
1212 GetSystemMetrics(SM_CXICON
)) / 2;
1213 y
= (ClientRect
.bottom
- ClientRect
.top
-
1214 GetSystemMetrics(SM_CYICON
)) / 2;
1215 DrawIcon(hDC
, x
, y
, hIcon
);
1217 EndPaint(hWnd
, &Ps
);
1225 hRgn
= CreateRectRgn(0, 0, 0, 0);
1226 if (GetUpdateRgn(hWnd
, hRgn
, FALSE
) != NULLREGION
)
1228 RedrawWindow(hWnd
, NULL
, hRgn
,
1229 RDW_ERASENOW
| RDW_ERASE
| RDW_FRAME
|
1238 DefWndSetRedraw(hWnd
, wParam
);
1244 DestroyWindow(hWnd
);
1248 case WM_MOUSEACTIVATE
:
1250 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1255 Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1260 Ret
= SendMessageA(GetParent(hWnd
), WM_MOUSEACTIVATE
,
1268 return ((LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
);
1273 /* Check if the window is minimized. */
1274 if (LOWORD(wParam
) != WA_INACTIVE
&&
1275 !(GetWindowLongW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
1284 if (GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CHILD
)
1288 return (SendMessageW(GetParent(hWnd
), WM_MOUSEWHEEL
,
1293 return (SendMessageA(GetParent(hWnd
), WM_MOUSEWHEEL
,
1301 case WM_ICONERASEBKGND
:
1304 HBRUSH hBrush
= (HBRUSH
)GetClassLongW(hWnd
, GCL_HBRBACKGROUND
);
1310 if (GetClassLongW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
1312 /* can't use GetClipBox with a parent DC or we fill the whole parent */
1313 GetClientRect(hWnd
, &Rect
);
1314 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
1318 GetClipBox((HDC
)wParam
, &Rect
);
1320 FillRect((HDC
)wParam
, &Rect
, hBrush
);
1324 case WM_CTLCOLORMSGBOX
:
1325 case WM_CTLCOLOREDIT
:
1326 case WM_CTLCOLORLISTBOX
:
1327 case WM_CTLCOLORBTN
:
1328 case WM_CTLCOLORDLG
:
1329 case WM_CTLCOLORSTATIC
:
1330 case WM_CTLCOLORSCROLLBAR
:
1331 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
1334 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
1338 ULONG Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1340 if (Style
& WS_CHILD
)
1342 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
1347 bResult
= SendMessageW(GetParent(hWnd
), WM_SETCURSOR
,
1352 bResult
= SendMessageA(GetParent(hWnd
), WM_SETCURSOR
,
1361 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
1365 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
1368 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
1371 /* FIXME: This is also incomplete. */
1374 if (HIWORD(lParam
) & KEYDATA_ALT
)
1376 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
1377 if ( (wParam
== VK_MENU
|| wParam
== VK_LMENU
1378 || wParam
== VK_RMENU
) && !iMenuSysKey
)
1385 if (wParam
== VK_F4
) /* Try to close the window */
1387 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
1388 if (!(GetClassLongW(top
, GCL_STYLE
) & CS_NOCLOSE
))
1391 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1393 PostMessageA(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
1396 else if (wParam
== VK_SNAPSHOT
)
1399 while (GetParent(hwnd
) != NULL
)
1401 hwnd
= GetParent(hwnd
);
1403 DefWndScreenshot(hwnd
);
1406 else if( wParam
== VK_F10
)
1408 else if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
1409 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, ' ' );
1416 /* Press and release F10 or ALT */
1417 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
1418 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
1419 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
1420 iMenuSysKey
= iF10Key
= 0;
1427 if (wParam
== '\r' && IsIconic(hWnd
))
1429 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
1432 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
1434 if (wParam
== '\t' || wParam
== '\x1b') break;
1435 if (wParam
== ' ' && (GetWindowLongW( hWnd
, GWL_STYLE
) & WS_CHILD
))
1436 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
1438 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
1440 else /* check for Ctrl-Esc */
1441 if (wParam
!= '\x1b') MessageBeep(0);
1450 if (!lParam
) return 0;
1451 Style
= GetWindowLongW(hWnd
, GWL_STYLE
);
1452 if ((Style
& WS_VISIBLE
) && wParam
) return 0;
1453 if (!(Style
& WS_VISIBLE
) && !wParam
) return 0;
1454 if (!GetWindow(hWnd
, GW_OWNER
)) return 0;
1455 Ret
= NtUserCallTwoParam((DWORD
) hWnd
, (DWORD
) wParam
, TWOPARAM_ROUTINE_ROS_SHOWWINDOW
);
1458 if( Ret
== -1) return 0;
1461 ShowWindow(hWnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
1468 /* FIXME: Check for a desktop. */
1469 if (!(GetWindowLongW( hWnd
, GWL_STYLE
) & WS_CHILD
)) EndMenu();
1470 if (GetCapture() == hWnd
)
1484 case WM_QUERYDROPOBJECT
:
1486 if (GetWindowLongW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
1493 case WM_QUERYDRAGICON
:
1498 hIcon
= (HICON
)GetClassLongW(hWnd
, GCL_HICON
);
1501 return ((LRESULT
)hIcon
);
1503 for (Len
= 1; Len
< 64; Len
++)
1505 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1507 return((LRESULT
)hIcon
);
1510 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1513 /* FIXME: WM_ISACTIVEICON */
1515 case WM_NOTIFYFORMAT
:
1517 if (lParam
== NF_QUERY
)
1518 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1524 INT Index
= (wParam
!= 0) ? GCL_HICON
: GCL_HICONSM
;
1525 HICON hOldIcon
= (HICON
)GetClassLongW(hWnd
, Index
);
1526 SetClassLongW(hWnd
, Index
, lParam
);
1527 SetWindowPos(hWnd
, 0, 0, 0, 0, 0,
1528 SWP_FRAMECHANGED
| SWP_NOSIZE
| SWP_NOMOVE
|
1529 SWP_NOACTIVATE
| SWP_NOZORDER
);
1530 return ((LRESULT
)hOldIcon
);
1535 INT Index
= (wParam
== ICON_BIG
) ? GCL_HICON
: GCL_HICONSM
;
1536 return (GetClassLongW(hWnd
, Index
));
1543 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1547 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1554 THRDCARETINFO CaretInfo
;
1557 case 0xffff: /* Caret timer */
1558 /* switch showing byte in win32k and get information about the caret */
1559 if(NtUserSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1561 DrawCaret(hWnd
, &CaretInfo
);
1569 case WM_QUERYENDSESSION
:
1574 case WM_INPUTLANGCHANGEREQUEST
:
1578 if(wParam
& INPUTLANGCHANGE_BACKWARD
1579 && wParam
& INPUTLANGCHANGE_FORWARD
)
1584 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1586 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1587 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1588 else NewHkl
= (HKL
) lParam
;
1590 NtUserActivateKeyboardLayout(NewHkl
, 0);
1595 case WM_INPUTLANGCHANGE
:
1597 //FIXME: What to do?
1602 if (wParam
) PostQuitMessage(0);
1605 case WM_QUERYUISTATE
:
1608 PWINDOW Wnd
= ValidateHwnd(hWnd
);
1612 Ret
|= UISF_HIDEFOCUS
;
1614 Ret
|= UISF_HIDEACCEL
;
1619 case WM_CHANGEUISTATE
:
1621 BOOL AlwaysShowCues
= TRUE
;
1622 WORD Action
= LOWORD(wParam
);
1623 WORD Flags
= HIWORD(wParam
);
1626 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1630 Wnd
= ValidateHwnd(hWnd
);
1631 if (!Wnd
|| lParam
!= 0)
1634 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1637 if (Flags
& UISF_ACTIVE
)
1639 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1642 if (Action
== UIS_INITIALIZE
)
1644 PDESKTOP Desk
= GetThreadDesktopInfo();
1648 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1649 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1651 /* We need to update wParam in case we need to send out messages */
1652 wParam
= MAKEWPARAM(Action
, Flags
);
1658 /* See if we actually need to change something */
1659 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1661 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1664 /* Don't need to do anything... */
1668 /* See if we actually need to change something */
1669 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1671 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1674 /* Don't need to do anything... */
1678 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1682 if ((Wnd
->Style
& WS_CHILD
) && Wnd
->Parent
!= NULL
)
1684 /* We're a child window and we need to pass this message down until
1685 we reach the root */
1686 hWnd
= UserHMGetHandle((PWINDOW
)DesktopPtrToUser(Wnd
->Parent
));
1690 /* We're a top level window, we need to change the UI state */
1691 Msg
= WM_UPDATEUISTATE
;
1695 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1697 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1700 case WM_UPDATEUISTATE
:
1703 BOOL AlwaysShowCues
= TRUE
;
1704 WORD Action
= LOWORD(wParam
);
1705 WORD Flags
= HIWORD(wParam
);
1708 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1712 Wnd
= ValidateHwnd(hWnd
);
1713 if (!Wnd
|| lParam
!= 0)
1716 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1719 if (Flags
& UISF_ACTIVE
)
1721 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1724 if (Action
== UIS_INITIALIZE
)
1726 PDESKTOP Desk
= GetThreadDesktopInfo();
1730 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1731 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1733 /* We need to update wParam for broadcasting the update */
1734 wParam
= MAKEWPARAM(Action
, Flags
);
1740 /* See if we actually need to change something */
1741 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1743 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1746 /* Don't need to do anything... */
1751 /* See if we actually need to change something */
1752 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1754 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1757 /* Don't need to do anything... */
1762 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1766 /* Pack the information and call win32k */
1769 if (!NtUserCallTwoParam((DWORD
)hWnd
, (DWORD
)Flags
| ((DWORD
)Action
<< 3), TWOPARAM_ROUTINE_ROS_UPDATEUISTATE
))
1773 /* Always broadcast the update to all children */
1774 EnumChildWindows(hWnd
,
1775 UserSendUiUpdateMsg
,
1787 DefWindowProcA(HWND hWnd
,
1795 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1800 ANSI_STRING AnsiString
;
1801 UNICODE_STRING UnicodeString
;
1802 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1803 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1804 * may have child window IDs instead of window name */
1808 RtlInitAnsiString(&AnsiString
, (LPSTR
)cs
->lpszName
);
1809 RtlAnsiStringToUnicodeString(&UnicodeString
, &AnsiString
, TRUE
);
1810 NtUserDefSetText(hWnd
, &UnicodeString
);
1811 RtlFreeUnicodeString(&UnicodeString
);
1814 NtUserDefSetText(hWnd
, NULL
);
1820 case WM_GETTEXTLENGTH
:
1825 Wnd
= ValidateHwnd(hWnd
);
1826 if (Wnd
!= NULL
&& Wnd
->WindowName
.Length
!= 0)
1828 buf
= DesktopPtrToUser(Wnd
->WindowName
.Buffer
);
1830 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1832 Wnd
->WindowName
.Length
)))
1834 Result
= (LRESULT
)len
;
1843 PSTR outbuf
= (PSTR
)lParam
;
1846 Wnd
= ValidateHwnd(hWnd
);
1847 if (Wnd
!= NULL
&& wParam
!= 0)
1849 if (Wnd
->WindowName
.Buffer
!= NULL
)
1850 buf
= DesktopPtrToUser(Wnd
->WindowName
.Buffer
);
1856 if (Wnd
->WindowName
.Length
!= 0)
1858 copy
= min(Wnd
->WindowName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1859 Result
= WideCharToMultiByte(CP_ACP
,
1867 outbuf
[Result
] = '\0';
1878 ANSI_STRING AnsiString
;
1879 UNICODE_STRING UnicodeString
;
1883 RtlInitAnsiString(&AnsiString
, (LPSTR
)lParam
);
1884 RtlAnsiStringToUnicodeString(&UnicodeString
, &AnsiString
, TRUE
);
1885 NtUserDefSetText(hWnd
, &UnicodeString
);
1886 RtlFreeUnicodeString(&UnicodeString
);
1889 NtUserDefSetText(hWnd
, NULL
);
1891 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1893 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
1900 /* FIXME: Implement these. */
1902 case WM_IME_KEYDOWN
:
1904 case WM_IME_STARTCOMPOSITION
:
1905 case WM_IME_COMPOSITION
:
1906 case WM_IME_ENDCOMPOSITION
:
1908 case WM_IME_SETCONTEXT
:
1909 FIXME("FIXME: WM_IME_* conversion isn't implemented yet!");
1912 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1915 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
1921 DefWindowProcW(HWND hWnd
,
1929 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1934 UNICODE_STRING UnicodeString
;
1935 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
1936 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1937 * may have child window IDs instead of window name */
1940 RtlInitUnicodeString(&UnicodeString
, (LPWSTR
)cs
->lpszName
);
1942 NtUserDefSetText( hWnd
, (cs
->lpszName
? &UnicodeString
: NULL
));
1947 case WM_GETTEXTLENGTH
:
1952 Wnd
= ValidateHwnd(hWnd
);
1953 if (Wnd
!= NULL
&& Wnd
->WindowName
.Length
!= 0)
1955 buf
= DesktopPtrToUser(Wnd
->WindowName
.Buffer
);
1957 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1959 Wnd
->WindowName
.Length
)))
1961 Result
= (LRESULT
)len
;
1970 PWSTR outbuf
= (PWSTR
)lParam
;
1972 Wnd
= ValidateHwnd(hWnd
);
1973 if (Wnd
!= NULL
&& wParam
!= 0)
1975 if (Wnd
->WindowName
.Buffer
!= NULL
)
1976 buf
= DesktopPtrToUser(Wnd
->WindowName
.Buffer
);
1982 if (Wnd
->WindowName
.Length
!= 0)
1984 Result
= min(Wnd
->WindowName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1985 RtlCopyMemory(outbuf
,
1987 Result
* sizeof(WCHAR
));
1988 outbuf
[Result
] = L
'\0';
1999 UNICODE_STRING UnicodeString
;
2002 RtlInitUnicodeString(&UnicodeString
, (LPWSTR
)lParam
);
2004 NtUserDefSetText(hWnd
, (lParam
? &UnicodeString
: NULL
));
2006 if ((GetWindowLongW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
2008 DefWndNCPaint(hWnd
, (HRGN
)1, -1);
2016 SendMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
2021 case WM_IME_SETCONTEXT
:
2024 FIXME("FIXME: WM_IME_SETCONTEXT is not implemented!");
2030 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
2032 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);