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);
451 UserPaintCaption(HWND hwnd
)
453 /* FIXME: this is not 100% correct */
456 * When themes are not enabled we can go on and paint the non client area.
457 * However if we do that with themes enabled we will draw a classic frame.
458 * This is sovled by sending a themes specific message to notify the themes
459 * engine that the caption needs to be redrawn
461 if(gpsi
->dwSRVIFlags
& SRVINFO_APIHOOK
)
463 SendMessage(hwnd
, WM_NCUAHDRAWCAPTION
,0,0);
467 DefWndNCPaint(hwnd
, HRGN_WINDOW
, -1);
473 DefWndSetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
475 HICON hIcon
, hIconSmall
, hIconOld
;
477 if ( wParam
> ICON_SMALL2
)
479 SetLastError(ERROR_INVALID_PARAMETER
);
482 hIconSmall
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
483 hIcon
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
485 hIconOld
= wParam
== ICON_BIG
? hIcon
: hIconSmall
;
490 hIcon
= (HICON
)lParam
;
493 hIconSmall
= (HICON
)lParam
;
496 ERR("FIXME: Set ICON_SMALL2 support!\n");
501 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
, hIcon
);
502 NtUserSetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
, hIconSmall
);
504 if ((pWnd
->style
& WS_CAPTION
) == WS_CAPTION
)
505 UserPaintCaption(UserHMGetHandle(pWnd
)); /* Repaint caption */
507 return (LRESULT
)hIconOld
;
511 DefWndGetIcon(PWND pWnd
, WPARAM wParam
, LPARAM lParam
)
514 if ( wParam
> ICON_SMALL2
)
516 SetLastError(ERROR_INVALID_PARAMETER
);
522 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconProp
);
526 hIconRet
= UserGetProp(UserHMGetHandle(pWnd
), gpsi
->atomIconSmProp
);
531 return (LRESULT
)hIconRet
;
535 DefWndScreenshot(HWND hWnd
)
547 hdc
= GetWindowDC(hWnd
);
548 GetWindowRect(hWnd
, &rect
);
549 w
= rect
.right
- rect
.left
;
550 h
= rect
.bottom
- rect
.top
;
552 hbitmap
= CreateCompatibleBitmap(hdc
, w
, h
);
553 hdc2
= CreateCompatibleDC(hdc
);
554 SelectObject(hdc2
, hbitmap
);
556 BitBlt(hdc2
, 0, 0, w
, h
,
560 SetClipboardData(CF_BITMAP
, hbitmap
);
562 ReleaseDC(hWnd
, hdc
);
563 ReleaseDC(hWnd
, hdc2
);
571 User32DefWindowProc(HWND hWnd
,
580 pWnd
= ValidateHwnd(hWnd
);
588 return DefWndNCPaint(hWnd
, (HRGN
)wParam
, -1);
593 return DefWndNCCalcSize(hWnd
, (BOOL
)wParam
, (RECT
*)lParam
);
596 case WM_POPUPSYSTEMMENU
:
598 /* This is an undocumented message used by the windows taskbar to
599 display the system menu of windows that belong to other processes. */
600 HMENU menu
= GetSystemMenu(hWnd
, FALSE
);
603 TrackPopupMenu(menu
, TPM_LEFTBUTTON
|TPM_RIGHTBUTTON
,
604 LOWORD(lParam
), HIWORD(lParam
), 0, hWnd
, NULL
);
610 return DefWndNCActivate(hWnd
, wParam
, lParam
);
616 Point
.x
= GET_X_LPARAM(lParam
);
617 Point
.y
= GET_Y_LPARAM(lParam
);
618 return (DefWndNCHitTest(hWnd
, Point
));
624 iF10Key
= iMenuSysKey
= 0;
627 case WM_NCLBUTTONDOWN
:
629 return (DefWndNCLButtonDown(hWnd
, wParam
, lParam
));
632 case WM_LBUTTONDBLCLK
:
633 return (DefWndNCLButtonDblClk(hWnd
, HTCLIENT
, lParam
));
635 case WM_NCLBUTTONDBLCLK
:
637 return (DefWndNCLButtonDblClk(hWnd
, wParam
, lParam
));
640 case WM_NCRBUTTONDOWN
:
641 return NC_HandleNCRButtonDown( hWnd
, wParam
, lParam
);
647 Pt
.x
= GET_X_LPARAM(lParam
);
648 Pt
.y
= GET_Y_LPARAM(lParam
);
649 ClientToScreen(hWnd
, &Pt
);
650 lParam
= MAKELPARAM(Pt
.x
, Pt
.y
);
653 SendMessageW(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
657 SendMessageA(hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, lParam
);
664 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
665 * in Windows), but what _should_ we do? According to MSDN :
666 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
667 * message to the window". When is it appropriate?
673 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
677 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
681 SendMessageA(GetParent(hWnd
), WM_CONTEXTMENU
, wParam
, lParam
);
690 Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
692 Pt
.x
= GET_X_LPARAM(lParam
);
693 Pt
.y
= GET_Y_LPARAM(lParam
);
694 if (Style
& WS_CHILD
)
696 ScreenToClient(GetParent(hWnd
), &Pt
);
699 HitCode
= DefWndNCHitTest(hWnd
, Pt
);
701 if (HitCode
== HTCAPTION
|| HitCode
== HTSYSMENU
)
706 if((SystemMenu
= GetSystemMenu(hWnd
, FALSE
)))
708 MenuInitSysMenuPopup(SystemMenu
, GetWindowLongPtrW(hWnd
, GWL_STYLE
),
709 GetClassLongPtrW(hWnd
, GCL_STYLE
), HitCode
);
711 if(HitCode
== HTCAPTION
)
712 Flags
= TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
;
714 Flags
= TPM_LEFTBUTTON
;
716 TrackPopupMenu(SystemMenu
, Flags
,
717 Pt
.x
, Pt
.y
, 0, hWnd
, NULL
);
726 DefWndPrint(hWnd
, (HDC
)wParam
, lParam
);
730 case WM_SYSCOLORCHANGE
:
732 /* force to redraw non-client area */
733 DefWndNCPaint(hWnd
, HRGN_WINDOW
, -1);
734 /* Use InvalidateRect to redraw client area, enable
735 * erase to redraw all subcontrols otherwise send the
736 * WM_SYSCOLORCHANGE to child windows/controls is required
738 InvalidateRect(hWnd
,NULL
,TRUE
);
748 /* If already in Paint and Client area is not empty just return. */
749 if (pWnd
->state2
& WNDS2_STARTPAINT
&& !IsRectEmpty(&pWnd
->rcClient
))
751 ERR("In Paint and Client area is not empty!\n");
755 hDC
= BeginPaint(hWnd
, &Ps
);
760 if (IsIconic(hWnd
) && ((hIcon
= (HICON
)GetClassLongPtrW( hWnd
, GCLP_HICON
))))
764 GetClientRect(hWnd
, &ClientRect
);
765 x
= (ClientRect
.right
- ClientRect
.left
-
766 GetSystemMetrics(SM_CXICON
)) / 2;
767 y
= (ClientRect
.bottom
- ClientRect
.top
-
768 GetSystemMetrics(SM_CYICON
)) / 2;
769 DrawIcon(hDC
, x
, y
, hIcon
);
780 case WM_MOUSEACTIVATE
:
781 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
783 LONG Ret
= SendMessageW(GetParent(hWnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
784 if (Ret
) return (Ret
);
786 return ( (HIWORD(lParam
) == WM_LBUTTONDOWN
&& LOWORD(lParam
) == HTCAPTION
) ? MA_NOACTIVATE
: MA_ACTIVATE
);
789 /* The default action in Windows is to set the keyboard focus to
790 * the window, if it's being activated and not minimized */
791 if (LOWORD(wParam
) != WA_INACTIVE
&&
792 !(GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_MINIMIZE
))
794 //ERR("WM_ACTIVATE %p\n",hWnd);
800 if (GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CHILD
)
801 return SendMessageW( GetParent(hWnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
805 case WM_ICONERASEBKGND
:
808 HBRUSH hBrush
= (HBRUSH
)GetClassLongPtrW(hWnd
, GCL_HBRBACKGROUND
);
814 if (GetClassLongPtrW(hWnd
, GCL_STYLE
) & CS_PARENTDC
)
816 /* can't use GetClipBox with a parent DC or we fill the whole parent */
817 GetClientRect(hWnd
, &Rect
);
818 DPtoLP((HDC
)wParam
, (LPPOINT
)&Rect
, 2);
822 GetClipBox((HDC
)wParam
, &Rect
);
824 FillRect((HDC
)wParam
, &Rect
, hBrush
);
828 case WM_CTLCOLORMSGBOX
:
829 case WM_CTLCOLOREDIT
:
830 case WM_CTLCOLORLISTBOX
:
833 case WM_CTLCOLORSTATIC
:
834 case WM_CTLCOLORSCROLLBAR
:
835 return (LRESULT
) DefWndControlColor((HDC
)wParam
, Msg
- WM_CTLCOLORMSGBOX
);
838 return (LRESULT
) DefWndControlColor((HDC
)wParam
, HIWORD(lParam
));
842 LONG_PTR Style
= GetWindowLongPtrW(hWnd
, GWL_STYLE
);
844 if (Style
& WS_CHILD
)
846 /* with the exception of the border around a resizable wnd,
847 * give the parent first chance to set the cursor */
848 if (LOWORD(lParam
) < HTLEFT
|| LOWORD(lParam
) > HTBOTTOMRIGHT
)
850 HWND parent
= GetParent( hWnd
);
853 if (parent
!= GetDesktopWindow() &&
854 SendMessageW( parent
, WM_SETCURSOR
, wParam
, lParam
))
859 if (parent
!= GetDesktopWindow() &&
860 SendMessageA( parent
, WM_SETCURSOR
, wParam
, lParam
))
865 return (DefWndHandleSetCursor(hWnd
, wParam
, lParam
, Style
));
869 return (DefWndHandleSysCommand(hWnd
, wParam
, lParam
));
872 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
877 if (HIWORD(lParam
) & KF_ALTDOWN
)
878 { /* Previous state, if the key was down before this message,
879 this is a cheap way to ignore autorepeat keys. */
880 if ( !(HIWORD(lParam
) & KF_REPEAT
) )
882 if ( ( wParam
== VK_MENU
||
883 wParam
== VK_LMENU
||
884 wParam
== VK_RMENU
) && !iMenuSysKey
)
892 if (wParam
== VK_F4
) /* Try to close the window */
894 HWND top
= GetAncestor(hWnd
, GA_ROOT
);
895 if (!(GetClassLongPtrW(top
, GCL_STYLE
) & CS_NOCLOSE
))
896 PostMessageW(top
, WM_SYSCOMMAND
, SC_CLOSE
, 0);
898 else if (wParam
== VK_SNAPSHOT
) // Alt-VK_SNAPSHOT?
901 while (GetParent(hwnd
) != NULL
)
903 hwnd
= GetParent(hwnd
);
905 DefWndScreenshot(hwnd
);
907 else if ( wParam
== VK_ESCAPE
|| wParam
== VK_TAB
) // Alt-Tab/ESC Alt-Shift-Tab/ESC
910 HWND Active
= GetActiveWindow(); // Noticed MDI problem.
913 FIXME("WM_SYSKEYDOWN VK_ESCAPE no active\n");
916 wParamTmp
= GetKeyState(VK_SHIFT
) & 0x8000 ? SC_PREVWINDOW
: SC_NEXTWINDOW
;
917 SendMessageW( Active
, WM_SYSCOMMAND
, wParamTmp
, wParam
);
920 else if( wParam
== VK_F10
)
922 if (GetKeyState(VK_SHIFT
) & 0x8000)
923 SendMessageW( hWnd
, WM_CONTEXTMENU
, (WPARAM
)hWnd
, MAKELPARAM(-1, -1) );
932 /* Press and release F10 or ALT */
933 if (((wParam
== VK_MENU
|| wParam
== VK_LMENU
|| wParam
== VK_RMENU
)
934 && iMenuSysKey
) || ((wParam
== VK_F10
) && iF10Key
))
935 SendMessageW( GetAncestor( hWnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
936 iMenuSysKey
= iF10Key
= 0;
943 if (wParam
== VK_RETURN
&& IsIconic(hWnd
))
945 PostMessageW( hWnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
948 if ((HIWORD(lParam
) & KF_ALTDOWN
) && wParam
)
950 if (wParam
== VK_TAB
|| wParam
== VK_ESCAPE
) break;
951 if (wParam
== VK_SPACE
&& (GetWindowLongPtrW( hWnd
, GWL_STYLE
) & WS_CHILD
))
952 SendMessageW( GetParent(hWnd
), Msg
, wParam
, lParam
);
954 SendMessageW( hWnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
956 else /* check for Ctrl-Esc */
957 if (wParam
!= VK_ESCAPE
) MessageBeep(0);
964 /* FIXME: Check for a desktop. */
965 //if (!(GetWindowLongPtrW( hWnd, GWL_STYLE ) & WS_CHILD)) EndMenu();
966 MENU_EndMenu( hWnd
);
967 if (GetCapture() == hWnd
)
981 case WM_QUERYDROPOBJECT
:
983 if (GetWindowLongPtrW(hWnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
)
990 case WM_QUERYDRAGICON
:
995 hIcon
= (HICON
)GetClassLongPtrW(hWnd
, GCL_HICON
);
998 return ((LRESULT
)hIcon
);
1000 for (Len
= 1; Len
< 64; Len
++)
1002 if ((hIcon
= LoadIconW(NULL
, MAKEINTRESOURCEW(Len
))) != NULL
)
1004 return((LRESULT
)hIcon
);
1007 return ((LRESULT
)LoadIconW(0, IDI_APPLICATION
));
1010 case WM_ISACTIVEICON
:
1013 isai
= (pWnd
->state
& WNDS_ACTIVEFRAME
) != 0;
1017 case WM_NOTIFYFORMAT
:
1019 if (lParam
== NF_QUERY
)
1020 return IsWindowUnicode(hWnd
) ? NFR_UNICODE
: NFR_ANSI
;
1026 return DefWndSetIcon(pWnd
, wParam
, lParam
);
1031 return DefWndGetIcon(pWnd
, wParam
, lParam
);
1038 SendMessageW(GetParent(hWnd
), Msg
, wParam
, lParam
);
1042 SendMessageA(GetParent(hWnd
), Msg
, wParam
, lParam
);
1049 THRDCARETINFO CaretInfo
;
1052 case 0xffff: /* Caret timer */
1053 /* switch showing byte in win32k and get information about the caret */
1054 if(NtUserxSwitchCaretShowing(&CaretInfo
) && (CaretInfo
.hWnd
== hWnd
))
1056 DrawCaret(hWnd
, &CaretInfo
);
1064 case WM_QUERYENDSESSION
:
1069 case WM_INPUTLANGCHANGEREQUEST
:
1073 if(wParam
& INPUTLANGCHANGE_BACKWARD
1074 && wParam
& INPUTLANGCHANGE_FORWARD
)
1079 //FIXME: What to do with INPUTLANGCHANGE_SYSCHARSET ?
1081 if(wParam
& INPUTLANGCHANGE_BACKWARD
) NewHkl
= (HKL
) HKL_PREV
;
1082 else if(wParam
& INPUTLANGCHANGE_FORWARD
) NewHkl
= (HKL
) HKL_NEXT
;
1083 else NewHkl
= (HKL
) lParam
;
1085 NtUserActivateKeyboardLayout(NewHkl
, 0);
1090 case WM_INPUTLANGCHANGE
:
1093 HWND
*win_array
= WIN_ListChildren( hWnd
);
1097 while (win_array
[count
])
1098 SendMessageW( win_array
[count
++], WM_INPUTLANGCHANGE
, wParam
, lParam
);
1099 HeapFree(GetProcessHeap(),0,win_array
);
1103 case WM_QUERYUISTATE
:
1106 PWND Wnd
= ValidateHwnd(hWnd
);
1110 Ret
|= UISF_HIDEFOCUS
;
1112 Ret
|= UISF_HIDEACCEL
;
1117 case WM_CHANGEUISTATE
:
1119 BOOL AlwaysShowCues
= FALSE
;
1120 WORD Action
= LOWORD(wParam
);
1121 WORD Flags
= HIWORD(wParam
);
1124 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1128 Wnd
= ValidateHwnd(hWnd
);
1129 if (!Wnd
|| lParam
!= 0)
1132 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1135 if (Flags
& UISF_ACTIVE
)
1137 WARN("WM_CHANGEUISTATE does not yet support UISF_ACTIVE!\n");
1140 if (Action
== UIS_INITIALIZE
)
1142 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1146 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1147 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1149 /* We need to update wParam in case we need to send out messages */
1150 wParam
= MAKEWPARAM(Action
, Flags
);
1156 /* See if we actually need to change something */
1157 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1159 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1162 /* Don't need to do anything... */
1166 /* See if we actually need to change something */
1167 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1169 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1172 /* Don't need to do anything... */
1176 WARN("WM_CHANGEUISTATE: Unsupported Action 0x%x\n", Action
);
1180 if ((Wnd
->style
& WS_CHILD
) && Wnd
->spwndParent
!= NULL
)
1182 /* We're a child window and we need to pass this message down until
1183 we reach the root */
1184 hWnd
= UserHMGetHandle((PWND
)DesktopPtrToUser(Wnd
->spwndParent
));
1188 /* We're a top level window, we need to change the UI state */
1189 Msg
= WM_UPDATEUISTATE
;
1193 return SendMessageW(hWnd
, Msg
, wParam
, lParam
);
1195 return SendMessageA(hWnd
, Msg
, wParam
, lParam
);
1198 case WM_UPDATEUISTATE
:
1201 BOOL AlwaysShowCues
= FALSE
;
1202 WORD Action
= LOWORD(wParam
);
1203 WORD Flags
= HIWORD(wParam
);
1206 SystemParametersInfoW(SPI_GETKEYBOARDCUES
, 0, &AlwaysShowCues
, 0);
1210 Wnd
= ValidateHwnd(hWnd
);
1211 if (!Wnd
|| lParam
!= 0)
1214 if (Flags
& ~(UISF_HIDEFOCUS
| UISF_HIDEACCEL
| UISF_ACTIVE
))
1217 if (Flags
& UISF_ACTIVE
)
1219 WARN("WM_UPDATEUISTATE does not yet support UISF_ACTIVE!\n");
1222 if (Action
== UIS_INITIALIZE
)
1224 PDESKTOPINFO Desk
= GetThreadDesktopInfo();
1228 Action
= Desk
->LastInputWasKbd
? UIS_CLEAR
: UIS_SET
;
1229 Flags
= UISF_HIDEFOCUS
| UISF_HIDEACCEL
;
1231 /* We need to update wParam for broadcasting the update */
1232 wParam
= MAKEWPARAM(Action
, Flags
);
1238 /* See if we actually need to change something */
1239 if ((Flags
& UISF_HIDEFOCUS
) && !Wnd
->HideFocus
)
1241 if ((Flags
& UISF_HIDEACCEL
) && !Wnd
->HideAccel
)
1244 /* Don't need to do anything... */
1249 /* See if we actually need to change something */
1250 if ((Flags
& UISF_HIDEFOCUS
) && Wnd
->HideFocus
)
1252 if ((Flags
& UISF_HIDEACCEL
) && Wnd
->HideAccel
)
1255 /* Don't need to do anything... */
1260 WARN("WM_UPDATEUISTATE: Unsupported Action 0x%x\n", Action
);
1264 /* Pack the information and call win32k */
1267 if (!NtUserxUpdateUiState(hWnd
, Flags
| ((DWORD
)Action
<< 3)))
1271 /* Always broadcast the update to all children */
1272 EnumChildWindows(hWnd
,
1273 UserSendUiUpdateMsg
,
1279 /* Move to Win32k !*/
1281 if (!lParam
) break; // Call when it is necessary.
1284 case WM_CLIENTSHUTDOWN
:
1287 case WM_WINDOWPOSCHANGING
:
1288 case WM_WINDOWPOSCHANGED
:
1292 NtUserMessageCall( hWnd
, Msg
, wParam
, lParam
, (ULONG_PTR
)&lResult
, FNID_DEFWINDOWPROC
, !bUnicode
);
1301 * helpers for calling IMM32 (from Wine 10/22/2008)
1303 * WM_IME_* messages are generated only by IMM32,
1304 * so I assume imm32 is already LoadLibrary-ed.
1307 DefWndImmGetDefaultIMEWnd(HWND hwnd
)
1309 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1310 HWND (WINAPI
*pFunc
)(HWND
);
1315 ERR("cannot get IMM32 handle\n");
1319 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmGetDefaultIMEWnd");
1321 hwndRet
= (*pFunc
)(hwnd
);
1328 DefWndImmIsUIMessageA(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
, "ImmIsUIMessageA");
1342 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1349 DefWndImmIsUIMessageW(HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1351 HINSTANCE hInstIMM
= GetModuleHandleW(L
"imm32\0");
1352 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
1357 ERR("cannot get IMM32 handle\n");
1361 pFunc
= (void*) GetProcAddress(hInstIMM
, "ImmIsUIMessageW");
1363 fRet
= (*pFunc
)(hwndIME
, msg
, wParam
, lParam
);
1370 RealDefWindowProcA(HWND hWnd
,
1378 Wnd
= ValidateHwnd(hWnd
);
1381 Msg
!= WM_CTLCOLORMSGBOX
&&
1382 Msg
!= WM_CTLCOLORBTN
&&
1383 Msg
!= WM_CTLCOLORDLG
&&
1384 Msg
!= WM_CTLCOLORSTATIC
)
1387 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1393 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
1397 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
1398 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
1399 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
1405 LPCREATESTRUCTA cs
= (LPCREATESTRUCTA
)lParam
;
1406 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1407 * may have child window IDs instead of window name */
1408 if (HIWORD(cs
->lpszName
))
1410 DefSetText(hWnd
, (PCWSTR
)cs
->lpszName
, TRUE
);
1417 case WM_GETTEXTLENGTH
:
1422 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1424 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1426 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1428 Wnd
->strName
.Length
)))
1430 Result
= (LRESULT
) len
;
1441 PSTR outbuf
= (PSTR
)lParam
;
1444 if (Wnd
!= NULL
&& wParam
!= 0)
1446 if (Wnd
->strName
.Buffer
!= NULL
)
1447 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1453 if (Wnd
->strName
.Length
!= 0)
1455 copy
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1456 Result
= WideCharToMultiByte(CP_ACP
,
1464 outbuf
[Result
] = '\0';
1475 DefSetText(hWnd
, (PCWSTR
)lParam
, TRUE
);
1477 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1478 UserPaintCaption(hWnd
);
1483 case WM_IME_KEYDOWN
:
1485 Result
= PostMessageA(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
1491 Result
= PostMessageA(hWnd
, WM_KEYUP
, wParam
, lParam
);
1498 PostMessageA(hWnd
, WM_CHAR
, HIBYTE(wParam
), lParam
);
1499 PostMessageA(hWnd
, WM_CHAR
, LOBYTE(wParam
), lParam
);
1503 case WM_IME_STARTCOMPOSITION
:
1504 case WM_IME_COMPOSITION
:
1505 case WM_IME_ENDCOMPOSITION
:
1511 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1513 Result
= SendMessageA(hwndIME
, Msg
, wParam
, lParam
);
1517 case WM_IME_SETCONTEXT
:
1521 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1523 Result
= DefWndImmIsUIMessageA(hwndIME
, Msg
, wParam
, lParam
);
1529 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, FALSE
);
1532 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
1538 RealDefWindowProcW(HWND hWnd
,
1546 Wnd
= ValidateHwnd(hWnd
);
1549 Msg
!= WM_CTLCOLORMSGBOX
&&
1550 Msg
!= WM_CTLCOLORBTN
&&
1551 Msg
!= WM_CTLCOLORDLG
&&
1552 Msg
!= WM_CTLCOLORSTATIC
)
1555 SPY_EnterMessage(SPY_DEFWNDPROC
, hWnd
, Msg
, wParam
, lParam
);
1561 Wnd
->style
& (WS_HSCROLL
| WS_VSCROLL
) )
1565 SCROLLINFO si
= {sizeof si
, SIF_ALL
, 0, 100, 0, 0, 0};
1566 SetScrollInfo( hWnd
, SB_HORZ
, &si
, FALSE
);
1567 SetScrollInfo( hWnd
, SB_VERT
, &si
, FALSE
);
1573 LPCREATESTRUCTW cs
= (LPCREATESTRUCTW
)lParam
;
1574 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
1575 * may have child window IDs instead of window name */
1576 if (HIWORD(cs
->lpszName
))
1578 DefSetText(hWnd
, cs
->lpszName
, FALSE
);
1585 case WM_GETTEXTLENGTH
:
1590 if (Wnd
!= NULL
&& Wnd
->strName
.Length
!= 0)
1592 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1594 NT_SUCCESS(RtlUnicodeToMultiByteSize(&len
,
1596 Wnd
->strName
.Length
)))
1598 Result
= (LRESULT
) (Wnd
->strName
.Length
/ sizeof(WCHAR
));
1609 PWSTR outbuf
= (PWSTR
)lParam
;
1611 if (Wnd
!= NULL
&& wParam
!= 0)
1613 if (Wnd
->strName
.Buffer
!= NULL
)
1614 buf
= DesktopPtrToUser(Wnd
->strName
.Buffer
);
1620 if (Wnd
->strName
.Length
!= 0)
1622 Result
= min(Wnd
->strName
.Length
/ sizeof(WCHAR
), wParam
- 1);
1623 RtlCopyMemory(outbuf
,
1625 Result
* sizeof(WCHAR
));
1626 outbuf
[Result
] = L
'\0';
1637 DefSetText(hWnd
, (PCWSTR
)lParam
, FALSE
);
1639 if ((GetWindowLongPtrW(hWnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1640 UserPaintCaption(hWnd
);
1647 PostMessageW(hWnd
, WM_CHAR
, wParam
, lParam
);
1652 case WM_IME_KEYDOWN
:
1654 Result
= PostMessageW(hWnd
, WM_KEYDOWN
, wParam
, lParam
);
1660 Result
= PostMessageW(hWnd
, WM_KEYUP
, wParam
, lParam
);
1664 case WM_IME_STARTCOMPOSITION
:
1665 case WM_IME_COMPOSITION
:
1666 case WM_IME_ENDCOMPOSITION
:
1672 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1674 Result
= SendMessageW(hwndIME
, Msg
, wParam
, lParam
);
1678 case WM_IME_SETCONTEXT
:
1682 hwndIME
= DefWndImmGetDefaultIMEWnd(hWnd
);
1684 Result
= DefWndImmIsUIMessageW(hwndIME
, Msg
, wParam
, lParam
);
1689 Result
= User32DefWindowProc(hWnd
, Msg
, wParam
, lParam
, TRUE
);
1691 SPY_ExitMessage(SPY_RESULT_DEFWND
, hWnd
, Msg
, Result
, wParam
, lParam
);
1697 DefWindowProcA(HWND hWnd
,
1702 BOOL Hook
, msgOverride
= FALSE
;
1707 Hook
= BeginIfHookedUserApiHook();
1710 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
1711 if(msgOverride
== FALSE
)
1717 /* Bypass SEH and go direct. */
1718 if (!Hook
|| !msgOverride
)
1719 return RealDefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
1723 Result
= guah
.DefWindowProcA(hWnd
, Msg
, wParam
, lParam
);
1725 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)
1736 DefWindowProcW(HWND hWnd
,
1741 BOOL Hook
, msgOverride
= FALSE
;
1746 Hook
= BeginIfHookedUserApiHook();
1749 msgOverride
= IsMsgOverride(Msg
, &guah
.DefWndProcArray
);
1750 if(msgOverride
== FALSE
)
1756 /* Bypass SEH and go direct. */
1757 if (!Hook
|| !msgOverride
)
1758 return RealDefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
1762 Result
= guah
.DefWindowProcW(hWnd
, Msg
, wParam
, lParam
);
1764 _SEH2_EXCEPT(EXCEPTION_EXECUTE_HANDLER
)