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 *****************************************************************/
42 GetSysColor(int nIndex
)
44 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
46 return gpsi
->argbSystem
[nIndex
];
49 SetLastError(ERROR_INVALID_PARAMETER
);
59 GetSysColorBrush(int nIndex
)
61 if(nIndex
>= 0 && nIndex
< NUM_SYSCOLORS
)
63 return gpsi
->ahbrSystem
[nIndex
];
66 SetLastError(ERROR_INVALID_PARAMETER
);
77 CONST INT
*lpaElements
,
78 CONST COLORREF
*lpaRgbValues
)
80 return NtUserSetSysColors(cElements
, lpaElements
, lpaRgbValues
, 0);
85 DefSetText(HWND hWnd
, PCWSTR String
, BOOL Ansi
)
88 LARGE_STRING lsString
;
93 RtlInitLargeAnsiString((PLARGE_ANSI_STRING
)&lsString
, (PCSZ
)String
, 0);
95 RtlInitLargeUnicodeString((PLARGE_UNICODE_STRING
)&lsString
, String
, 0);
97 Ret
= NtUserDefSetText(hWnd
, (String
? &lsString
: NULL
));
100 IntNotifyWinEvent(EVENT_OBJECT_NAMECHANGE
, hWnd
, OBJID_WINDOW
, CHILDID_SELF
, 0);
106 UserGetInsideRectNC(PWND Wnd
, RECT
*rect
)
112 ExStyle
= Wnd
->ExStyle
;
114 rect
->top
= rect
->left
= 0;
115 rect
->right
= Wnd
->rcWindow
.right
- Wnd
->rcWindow
.left
;
116 rect
->bottom
= Wnd
->rcWindow
.bottom
- Wnd
->rcWindow
.top
;
118 if (Style
& WS_ICONIC
)
123 /* Remove frame from rectangle */
124 if (UserHasThickFrameStyle(Style
, ExStyle
))
126 InflateRect(rect
, -GetSystemMetrics(SM_CXFRAME
), -GetSystemMetrics(SM_CYFRAME
));
130 if (UserHasDlgFrameStyle(Style
, ExStyle
))
132 InflateRect(rect
, -GetSystemMetrics(SM_CXDLGFRAME
), -GetSystemMetrics(SM_CYDLGFRAME
));
133 /* FIXME: this isn't in NC_AdjustRect? why not? */
134 if (ExStyle
& WS_EX_DLGMODALFRAME
)
135 InflateRect( rect
, -1, 0 );
139 if (UserHasThinFrameStyle(Style
, ExStyle
))
141 InflateRect(rect
, -GetSystemMetrics(SM_CXBORDER
), -GetSystemMetrics(SM_CYBORDER
));
145 /* We have additional border information if the window
146 * is a child (but not an MDI child) */
147 if ((Style
& WS_CHILD
) && !(ExStyle
& WS_EX_MDICHILD
))
149 if (ExStyle
& WS_EX_CLIENTEDGE
)
150 InflateRect (rect
, -GetSystemMetrics(SM_CXEDGE
), -GetSystemMetrics(SM_CYEDGE
));
151 if (ExStyle
& WS_EX_STATICEDGE
)
152 InflateRect (rect
, -GetSystemMetrics(SM_CXBORDER
), -GetSystemMetrics(SM_CYBORDER
));
157 DefWndHandleSetCursor(HWND hWnd
, WPARAM wParam
, LPARAM lParam
, ULONG Style
)
159 /* Not for child windows. */
160 if (hWnd
!= (HWND
)wParam
)
165 switch((INT_PTR
) LOWORD(lParam
))
169 WORD Msg
= HIWORD(lParam
);
170 if (Msg
== WM_LBUTTONDOWN
|| Msg
== WM_MBUTTONDOWN
||
171 Msg
== WM_RBUTTONDOWN
|| Msg
== WM_XBUTTONDOWN
)
180 HICON hCursor
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HCURSOR
);
192 if (Style
& WS_MAXIMIZE
)
196 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZEWE
)));
202 if (Style
& WS_MAXIMIZE
)
206 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENS
)));
212 if (Style
& WS_MAXIMIZE
)
216 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENWSE
)));
222 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MAXIMIZE
)
226 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_SIZENESW
)));
229 return((LRESULT
)SetCursor(LoadCursorW(0, IDC_ARROW
)));
232 /***********************************************************************
233 * DefWndTrackScrollBar
235 * Track a mouse button press on the horizontal or vertical scroll-bar.
238 DefWndTrackScrollBar(HWND Wnd
, WPARAM wParam
, POINT Pt
)
242 if (SC_HSCROLL
== (wParam
& 0xfff0))
244 if (HTHSCROLL
!= (wParam
& 0x0f))
250 else /* SC_VSCROLL */
252 if (HTVSCROLL
!= (wParam
& 0x0f))
258 ScrollTrackScrollBar(Wnd
, ScrollBar
, Pt
);
261 LRESULT WINAPI
DoAppSwitch( WPARAM wParam
, LPARAM lParam
);
264 DefWndHandleSysCommand(HWND hWnd
, WPARAM wParam
, LPARAM lParam
)
269 if (!IsWindowEnabled( hWnd
)) return 0;
271 if (ISITHOOKED(WH_CBT
))
273 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
274 if (lResult
) return 0;
277 switch (wParam
& 0xfff0)
281 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
285 if (hWnd
== GetActiveWindow())
286 ShowOwnedPopups(hWnd
,FALSE
);
287 ShowWindow( hWnd
, SW_MINIMIZE
);
291 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
292 ShowOwnedPopups(hWnd
,TRUE
);
293 ShowWindow( hWnd
, SW_MAXIMIZE
);
297 if (IsIconic(hWnd
) && hWnd
== GetActiveWindow())
298 ShowOwnedPopups(hWnd
,TRUE
);
299 ShowWindow( hWnd
, SW_RESTORE
);
303 return SendMessageW(hWnd
, WM_CLOSE
, 0, 0);
308 Pt
.x
= (short)LOWORD(lParam
);
309 Pt
.y
= (short)HIWORD(lParam
);
310 MenuTrackMouseMenuBar(hWnd
, wParam
& 0x000f, Pt
);
314 MenuTrackKbdMenuBar(hWnd
, wParam
, (WCHAR
)lParam
);
319 Pt
.x
= (short)LOWORD(lParam
);
320 Pt
.y
= (short)HIWORD(lParam
);
321 DefWndTrackScrollBar(hWnd
, wParam
, Pt
);
326 WinExec( "taskman.exe", SW_SHOWNORMAL
);
330 NtUserMessageCall( hWnd
, WM_SYSCOMMAND
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, FALSE
);
335 DoAppSwitch( wParam
, lParam
);
340 HWND hwnd
, hWndLastActive
;
344 pWnd
= ValidateHwnd(hwnd
);
347 hWndLastActive
= GetLastActivePopup(hwnd
);
350 hwnd
= hWndLastActive
;
351 pWnd
= ValidateHwnd(hwnd
);
353 SetForegroundWindow(hwnd
);
354 if (pWnd
->style
& WS_MINIMIZE
)
356 PostMessage(hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0);
363 FIXME("Unimplemented DefWndHandleSysCommand wParam 0x%x\n",wParam
);
370 /***********************************************************************
373 * Default colors for control painting.
376 DefWndControlColor(HDC hDC
, UINT ctlType
)
378 if (ctlType
== CTLCOLOR_SCROLLBAR
)
380 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
381 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
382 SetTextColor(hDC
, GetSysColor(COLOR_3DFACE
));
385 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
386 * we better use 0x55aa bitmap brush to make scrollbar's background
387 * look different from the window background.
389 if ( bk
== GetSysColor(COLOR_WINDOW
))
390 return gpsi
->hbrGray
;
392 UnrealizeObject( hb
);
396 SetTextColor(hDC
, GetSysColor(COLOR_WINDOWTEXT
));
398 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
400 SetBkColor(hDC
, GetSysColor(COLOR_WINDOW
));
404 SetBkColor(hDC
, GetSysColor(COLOR_3DFACE
));
405 return GetSysColorBrush(COLOR_3DFACE
);
408 return GetSysColorBrush(COLOR_WINDOW
);
411 static void DefWndPrint( HWND hwnd
, HDC hdc
, ULONG uFlags
)
416 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
417 !IsWindowVisible(hwnd
) )
421 * Unimplemented flags.
423 if ( (uFlags
& PRF_CHILDREN
) ||
424 (uFlags
& PRF_OWNED
) ||
425 (uFlags
& PRF_NONCLIENT
) )
427 FIXME("WM_PRINT message with unsupported flags\n");
433 if ( uFlags
& PRF_ERASEBKGND
)
434 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
439 if ( uFlags
& PRF_CLIENT
)
440 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, uFlags
);
444 UserSendUiUpdateMsg(HWND hwnd
, LPARAM lParam
)
446 SendMessageW(hwnd
, WM_UPDATEUISTATE
, (WPARAM
)lParam
, 0);
452 DefWndSetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
454 HICON hIcon
, hIconSmall
, hIconOld
;
456 if ( wParam
> ICON_SMALL2
)
458 SetLastError(ERROR_INVALID_PARAMETER
);
461 hIconSmall
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
462 hIcon
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
464 hIconOld
= wParam
== ICON_BIG
? hIcon
: hIconSmall
;
469 hIcon
= (HICON
)lParam
;
472 hIconSmall
= (HICON
)lParam
;
475 ERR("FIXME: Set ICON_SMALL2 support!\n");
480 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
, hIcon
);
481 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
, hIconSmall
);
483 if ((pWnd
->style
& WS_CAPTION
) == WS_CAPTION
)
484 DefWndNCPaint(UserHMGetHandle(pWnd
), HRGN_WINDOW
, -1); /* Repaint caption */
486 return (LRESULT
)hIconOld
;
490 DefWndGetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
493 if ( wParam
> ICON_SMALL2
)
495 SetLastError(ERROR_INVALID_PARAMETER
);
501 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
505 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
510 return (LRESULT
)hIconRet
;
514 DefWndScreenshot(HWND hWnd
)
526 hdc
= GetWindowDC(hWnd
);
527 GetWindowRect(hWnd
, &rect
);
528 w
= rect
.right
- rect
.left
;
529 h
= rect
.bottom
- rect
.top
;
531 hbitmap
= CreateCompatibleBitmap(hdc
, w
, h
);
532 hdc2
= CreateCompatibleDC(hdc
);
533 SelectObject(hdc2
, hbitmap
);
535 BitBlt(hdc2
, 0, 0, w
, h
,
539 SetClipboardData(CF_BITMAP
, hbitmap
);
541 ReleaseDC(hWnd
, hdc
);
542 ReleaseDC(hWnd
, hdc2
);
550 User32DefWindowProc(HWND hWnd
,
559 pWnd
= ValidateHwnd(hWnd
);
567 return DefWndNCPaint(hWnd
, (HRGN
)wParam
, -1);
572 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
575 case WM_POPUPSYSTEMMENU
:
577 /* This is an undocumented message used by the windows taskbar to
578 display the system menu of windows that belong to other processes. */
579 HMENU menu
= GetSystemMenu(hWnd
, FALSE
);
582 TrackPopupMenu(menu
, TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
583 LOWORD(lParam
), HIWORD(lParam
), 0, hWnd
, NULL
);
589 return DefWndNCActivate(hWnd
, wParam
, lParam
);
595 Point
.x
= GET_X_LPARAM(lParam
);
596 Point
.y
= GET_Y_LPARAM(lParam
);
597 return (DefWndNCHitTest(hWnd
, Point
));
603 iF10Key
= iMenuSysKey
= 0;
606 case WM_NCLBUTTONDOWN
:
608 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
611 case WM_LBUTTONDBLCLK
:
612 return (DefWndNCLButtonDblClk(hWnd
, HTCLIENT
, lParam
));
614 case WM_NCLBUTTONDBLCLK
:
616 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
619 case WM_NCRBUTTONDOWN
:
620 return NC_HandleNCRButtonDown( hWnd
, wParam
, lParam
);
626 Pt
.x
= GET_X_LPARAM(lParam
);
627 Pt
.y
= GET_Y_LPARAM(lParam
);
628 ClientToScreen(hWnd
, &Pt
);
629 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
632 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
636 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
643 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
644 * in Windows), but what _should_ we do? According to MSDN :
645 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
646 * message to the window". When is it appropriate?
652 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
656 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
660 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
669 Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
671 Pt
.x
= GET_X_LPARAM(lParam
);
672 Pt
.y
= GET_Y_LPARAM(lParam
);
673 if (Style
& WS_CHILD
)
675 ScreenToClient(GetParent(hWnd
), &Pt
);
678 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
680 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
685 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
687 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongPtrW(hWnd
, GWL_STYLE
),
688 GetClassLongPtrW(hWnd
, GCL_STYLE
), HitCode
);
690 if(HitCode
== HTCAPTION
)
691 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
693 Flags
= TPM_LEFTBUTTON
;
695 TrackPopupMenu(SystemMenu
, Flags
,
696 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
705 DefWndPrint(hWnd
, (HDC
)wParam
, lParam
);
709 case WM_SYSCOLORCHANGE
:
711 /* force to redraw non-client area */
712 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
713 /* Use InvalidateRect to redraw client area, enable
714 * erase to redraw all subcontrols otherwise send the
715 * WM_SYSCOLORCHANGE to child windows/controls is required
717 InvalidateRect(hWnd
,NULL
,TRUE
);
727 /* If already in Paint and Client area is not empty just return. */
728 if (pWnd
->state2
& WNDS2_STARTPAINT
&& !IsRectEmpty(&pWnd
->rcClient
))
730 ERR("In Paint and Client area is not empty!\n");
734 hDC
= BeginPaint(hWnd
, &Ps
);
739 if (IsIconic(hWnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hWnd
, GCLP_HICON
))))
743 GetClientRect(hWnd
, &ClientRect
);
744 x
= (ClientRect
.right
- ClientRect
.left
-
745 GetSystemMetrics(SM_CXICON
)) / 2;
746 y
= (ClientRect
.bottom
- ClientRect
.top
-
747 GetSystemMetrics(SM_CYICON
)) / 2;
748 DrawIcon(hDC
, x
, y
, hIcon
);
759 case WM_MOUSEACTIVATE
:
760 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
762 LONG Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
763 if (Ret
) return (Ret
);
765 return ( (HIWORD(lParam
) == WM_LBUTTONDOWN
&& LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
);
768 /* The default action in Windows is to set the keyboard focus to
769 * the window, if it's being activated and not minimized */
770 if (LOWORD(wParam
) != WA_INACTIVE
&&
771 !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
773 //ERR("WM_ACTIVATE %p\n",hWnd);
779 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
780 return SendMessageW( GetParent(hWnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
784 case WM_ICONERASEBKGND
:
787 HBRUSH hBrush
= (HBRUSH
)GetClassLongPtrW(hWnd
, GCL_HBRBACKGROUND
);
793 if (GetClassLongPtrW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
795 /* can't use GetClipBox with a parent DC or we fill the whole parent */
796 GetClientRect(hWnd
, &Rect
);
797 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
801 GetClipBox((HDC
)wParam
, &Rect
);
803 FillRect((HDC
)wParam
, &Rect
, hBrush
);
807 case WM_CTLCOLORMSGBOX
:
808 case WM_CTLCOLOREDIT
:
809 case WM_CTLCOLORLISTBOX
:
812 case WM_CTLCOLORSTATIC
:
813 case WM_CTLCOLORSCROLLBAR
:
814 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
817 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
821 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
823 if (Style
& WS_CHILD
)
825 /* with the exception of the border around a resizable wnd,
826 * give the parent first chance to set the cursor */
827 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
829 HWND parent
= GetParent( hWnd
);
832 if (parent
!= GetDesktopWindow() &&
833 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
))
838 if (parent
!= GetDesktopWindow() &&
839 SendMessageA( parent
, WM_SETCURSOR
, wParam
, lParam
))
844 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
848 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
851 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
856 if (HIWORD(lParam
) & KF_ALTDOWN
)
857 { /* Previous state, if the key was down before this message,
858 this is a cheap way to ignore autorepeat keys. */
859 if ( !(HIWORD(lParam
) & KF_REPEAT
) )
861 if ( ( wParam
== VK_MENU
||
862 wParam
== VK_LMENU
||
863 wParam
== VK_RMENU
) && !iMenuSysKey
)
871 if (wParam
== VK_F4
) /* Try to close the window */
873 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
874 if (!(GetClassLongPtrW(top
, GCL_STYLE
) & CS_NOCLOSE
))
875 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
877 else if (wParam
== VK_SNAPSHOT
) // Alt-VK_SNAPSHOT?
880 while (GetParent(hwnd
) != NULL
)
882 hwnd
= GetParent(hwnd
);
884 DefWndScreenshot(hwnd
);
886 else if ( wParam
== VK_ESCAPE
|| wParam
== VK_TAB
) // Alt-Tab/ESC Alt-Shift-Tab/ESC
889 HWND Active
= GetActiveWindow(); // Noticed MDI problem.
892 FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n");
895 wParamTmp
= GetKeyState(VK_SHIFT
) & 0x8000 ? SC_PREVWINDOW
: SC_NEXTWINDOW
;
896 SendMessageW( Active
, WM_SYSCOMMAND
, wParamTmp
, wParam
);
899 else if( wParam
== VK_F10
)
901 if (GetKeyState(VK_SHIFT
) & 0x8000)
902 SendMessageW( hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, MAKELPARAM(-1, -1) );
911 /* Press and release F10 or ALT */
912 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
913 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
914 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
915 iMenuSysKey
= iF10Key
= 0;
922 if (wParam
== VK_RETURN
&& IsIconic(hWnd
))
924 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
927 if ((HIWORD(lParam
) & KF_ALTDOWN
) && wParam
)
929 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
930 if (wParam
== VK_SPACE
&& (GetWindowLongPtrW( hWnd
, GWL_STYLE
) & WS_CHILD
))
931 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
933 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
935 else /* check for Ctrl-Esc */
936 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
943 /* FIXME: Check for a desktop. */
944 //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
945 MENU_EndMenu( hWnd
);
946 if (GetCapture() == hWnd
)
960 case WM_QUERYDROPOBJECT
:
962 if (GetWindowLongPtrW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
969 case WM_QUERYDRAGICON
:
974 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HICON
);
977 return ((LRESULT
)hIcon
);
979 for (Len
= 1; Len
< 64; Len
++)
981 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
983 return((LRESULT
)hIcon
);
986 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
989 case WM_ISACTIVEICON
:
992 isai
= (pWnd
->state
& WNDS_ACTIVEFRAME
) != 0;
996 case WM_NOTIFYFORMAT
:
998 if (lParam
== NF_QUERY
)
999 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1005 return DefWndSetIcon(pWnd
, wParam
, lParam
);
1010 return DefWndGetIcon(pWnd
, wParam
, lParam
);
1017 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1021 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1028 THRDCARETINFO CaretInfo
;
1031 case 0xffff: /* Caret timer */
1032 /* switch showing byte in win32k and get information about the caret */
1033 if(NtUserxSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1035 DrawCaret(hWnd
, &CaretInfo
);
1043 case WM_QUERYENDSESSION
:
1048 case WM_INPUTLANGCHANGEREQUEST
:
1052 if(wParam
& INPUTLANGCHANGE_BACKWARD
1053 && wParam
& INPUTLANGCHANGE_FORWARD
)
1058 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1060 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1061 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1062 else NewHkl
= (HKL
) lParam
;
1064 NtUserActivateKeyboardLayout(NewHkl
, 0);
1069 case WM_INPUTLANGCHANGE
:
1072 HWND
*win_array
= WIN_ListChildren( hWnd
);
1076 while (win_array
[count
])
1077 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
1078 HeapFree(GetProcessHeap(),0,win_array
);
1082 case WM_QUERYUISTATE
:
1085 PWND Wnd
= ValidateHwnd(hWnd
);
1089 Ret
|= UISF_HIDEFOCUS
;
1091 Ret
|= UISF_HIDEACCEL
;
1096 case WM_CHANGEUISTATE
:
1098 BOOL AlwaysShowCues
= FALSE
;
1099 WORD Action
= LOWORD(wParam
);
1100 WORD Flags
= HIWORD(wParam
);
1103 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1107 Wnd
= ValidateHwnd(hWnd
);
1108 if (!Wnd
|| lParam
!= 0)
1111 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1114 if (Flags
& UISF_ACTIVE
)
1116 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1119 if (Action
== UIS_INITIALIZE
)
1121 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1125 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1126 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1128 /* We need to update wParam in case we need to send out messages */
1129 wParam
= MAKEWPARAM(Action
, Flags
);
1135 /* See if we actually need to change something */
1136 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1138 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1141 /* Don't need to do anything... */
1145 /* See if we actually need to change something */
1146 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1148 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1151 /* Don't need to do anything... */
1155 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1159 if ((Wnd
->style
& WS_CHILD
) && Wnd
->spwndParent
!= NULL
)
1161 /* We're a child window and we need to pass this message down until
1162 we reach the root */
1163 hWnd
= UserHMGetHandle((PWND
)DesktopPtrToUser(Wnd
->spwndParent
));
1167 /* We're a top level window, we need to change the UI state */
1168 Msg
= WM_UPDATEUISTATE
;
1172 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1174 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1177 case WM_UPDATEUISTATE
:
1180 BOOL AlwaysShowCues
= FALSE
;
1181 WORD Action
= LOWORD(wParam
);
1182 WORD Flags
= HIWORD(wParam
);
1185 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1189 Wnd
= ValidateHwnd(hWnd
);
1190 if (!Wnd
|| lParam
!= 0)
1193 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1196 if (Flags
& UISF_ACTIVE
)
1198 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1201 if (Action
== UIS_INITIALIZE
)
1203 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1207 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1208 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1210 /* We need to update wParam for broadcasting the update */
1211 wParam
= MAKEWPARAM(Action
, Flags
);
1217 /* See if we actually need to change something */
1218 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1220 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1223 /* Don't need to do anything... */
1228 /* See if we actually need to change something */
1229 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1231 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1234 /* Don't need to do anything... */
1239 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1243 /* Pack the information and call win32k */
1246 if (!NtUserxUpdateUiState(hWnd
, Flags
| ((DWORD
)Action
<< 3)))
1250 /* Always broadcast the update to all children */
1251 EnumChildWindows(hWnd
,
1252 UserSendUiUpdateMsg
,
1258 /* Move to Win32k !*/
1260 if (!lParam
) break; // Call when it is necessary.
1263 case WM_CLIENTSHUTDOWN
:
1266 case WM_WINDOWPOSCHANGING
:
1267 case WM_WINDOWPOSCHANGED
:
1271 NtUserMessageCall( hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, !bUnicode
);
1280 * helpers for calling IMM32 (from Wine 10/22/2008)
1282 * WM_IME_* messages are generated only by IMM32,
1283 * so I assume imm32 is already LoadLibrary-ed.
1286 DefWndImmGetDefaultIMEWnd(HWND hwnd
)
1288 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1289 HWND (WINAPI
*pFunc
)(HWND
);
1294 ERR("cannot get IMM32 handle\n");
1298 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmGetDefaultIMEWnd");
1300 hwndRet
= (*pFunc
)(hwnd
);
1307 DefWndImmIsUIMessageA(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1309 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1310 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1315 ERR("cannot get IMM32 handle\n");
1319 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageA");
1321 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1328 DefWndImmIsUIMessageW(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1330 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1331 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1336 ERR("cannot get IMM32 handle\n");
1340 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageW");
1342 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1349 RealDefWindowProcA(HWND hWnd
,
1357 Wnd
= ValidateHwnd(hWnd
);
1360 Msg
!= WM_CTLCOLORMSGBOX
&&
1361 Msg
!= WM_CTLCOLORBTN
&&
1362 Msg
!= WM_CTLCOLORDLG
&&
1363 Msg
!= WM_CTLCOLORSTATIC
)
1366 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1372 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
1376 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
1377 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
1378 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
1384 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1385 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1386 * may have child window IDs instead of window name */
1387 if (HIWORD(cs
->lpszName
))
1389 DefSetText(hWnd
, (PCWSTR
)cs
->lpszName
, TRUE
);
1396 case WM_GETTEXTLENGTH
:
1401 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1403 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1405 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1407 Wnd
->strName
.Length
)))
1409 Result
= (LRESULT
) len
;
1420 PSTR outbuf
= (PSTR
)lParam
;
1423 if (Wnd
!= NULL
&& wParam
!= 0)
1425 if (Wnd
->strName
.Buffer
!= NULL
)
1426 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1432 if (Wnd
->strName
.Length
!= 0)
1434 copy
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1435 Result
= WideCharToMultiByte(CP_ACP
,
1443 outbuf
[Result
] = '\0';
1454 DefSetText(hWnd
, (PCWSTR
)lParam
, TRUE
);
1456 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1458 /* FIXME: this is not 100% correct */
1459 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
1461 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
1465 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1472 case WM_IME_KEYDOWN
:
1474 Result
= PostMessageA(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
1480 Result
= PostMessageA(hWnd
, WM_KEYUP
, wParam
, lParam
);
1487 PostMessageA(hWnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
1488 PostMessageA(hWnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
1492 case WM_IME_STARTCOMPOSITION
:
1493 case WM_IME_COMPOSITION
:
1494 case WM_IME_ENDCOMPOSITION
:
1500 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1502 Result
= SendMessageA(hwndIME
, Msg
, wParam
, lParam
);
1506 case WM_IME_SETCONTEXT
:
1510 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1512 Result
= DefWndImmIsUIMessageA(hwndIME
, Msg
, wParam
, lParam
);
1518 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1521 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
1527 RealDefWindowProcW(HWND hWnd
,
1535 Wnd
= ValidateHwnd(hWnd
);
1538 Msg
!= WM_CTLCOLORMSGBOX
&&
1539 Msg
!= WM_CTLCOLORBTN
&&
1540 Msg
!= WM_CTLCOLORDLG
&&
1541 Msg
!= WM_CTLCOLORSTATIC
)
1544 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1550 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
1554 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
1555 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
1556 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
1562 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
1563 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1564 * may have child window IDs instead of window name */
1565 if (HIWORD(cs
->lpszName
))
1567 DefSetText(hWnd
, cs
->lpszName
, FALSE
);
1574 case WM_GETTEXTLENGTH
:
1579 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1581 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1583 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1585 Wnd
->strName
.Length
)))
1587 Result
= (LRESULT
) (Wnd
->strName
.Length
/ sizeof(WCHAR
));
1598 PWSTR outbuf
= (PWSTR
)lParam
;
1600 if (Wnd
!= NULL
&& wParam
!= 0)
1602 if (Wnd
->strName
.Buffer
!= NULL
)
1603 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1609 if (Wnd
->strName
.Length
!= 0)
1611 Result
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1612 RtlCopyMemory(outbuf
,
1614 Result
* sizeof(WCHAR
));
1615 outbuf
[Result
] = L
'\0';
1626 DefSetText(hWnd
, (PCWSTR
)lParam
, FALSE
);
1628 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1630 /* FIXME: this is not 100% correct */
1631 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
1633 SendMessage(hWnd
, WM_NCUAHDRAWCAPTION
,0,0);
1637 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
1646 PostMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
1651 case WM_IME_KEYDOWN
:
1653 Result
= PostMessageW(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
1659 Result
= PostMessageW(hWnd
, WM_KEYUP
, wParam
, lParam
);
1663 case WM_IME_STARTCOMPOSITION
:
1664 case WM_IME_COMPOSITION
:
1665 case WM_IME_ENDCOMPOSITION
:
1671 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1673 Result
= SendMessageW(hwndIME
, Msg
, wParam
, lParam
);
1677 case WM_IME_SETCONTEXT
:
1681 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1683 Result
= DefWndImmIsUIMessageW(hwndIME
, Msg
, wParam
, lParam
);
1688 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
1690 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
1696 DefWindowProcA(HWND hWnd
,
1701 BOOL Hook
, msgOverride
= FALSE
;
1706 Hook
= BeginIfHookedUserApiHook();
1709 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
1710 if(msgOverride
== FALSE
)
1716 /* Bypass SEH and go direct. */
1717 if (!Hook
|| !msgOverride
)
1718 return RealDefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
1722 Result
= guah
.DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
1724 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1735 DefWindowProcW(HWND hWnd
,
1740 BOOL Hook
, msgOverride
= FALSE
;
1745 Hook
= BeginIfHookedUserApiHook();
1748 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
1749 if(msgOverride
== FALSE
)
1755 /* Bypass SEH and go direct. */
1756 if (!Hook
|| !msgOverride
)
1757 return RealDefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
1761 Result
= guah
.DefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
1763 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)