2 * Default window procedure
4 * Copyright 1993, 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include "wine/port.h"
33 #include "user_private.h"
35 #include "wine/unicode.h"
36 #include "wine/server.h"
37 #include "wine/exception.h"
38 #include "wine/debug.h"
40 WINE_DEFAULT_DEBUG_CHANNEL(win);
42 /* bits in the dwKeyData */
43 #define KEYDATA_ALT 0x2000
44 #define KEYDATA_PREVSTATE 0x4000
46 #define DRAG_FILE 0x454C4946
48 static short iF10Key = 0;
49 static short iMenuSysKey = 0;
50 static const WCHAR imm32W[] = { 'i','m','m','3','2','\0' };
52 /***********************************************************************
53 * DEFWND_HandleWindowPosChanged
55 * Handle the WM_WINDOWPOSCHANGED message.
57 static void DEFWND_HandleWindowPosChanged( HWND hwnd, const WINDOWPOS *winpos )
60 WND *wndPtr = WIN_GetPtr( hwnd );
62 rect = wndPtr->rectClient;
63 WIN_ReleasePtr( wndPtr );
65 if (!(winpos->flags & SWP_NOCLIENTMOVE))
66 SendMessageW( hwnd, WM_MOVE, 0, MAKELONG(rect.left, rect.top));
68 if (!(winpos->flags & SWP_NOCLIENTSIZE) || (winpos->flags & SWP_STATECHANGED))
72 SendMessageW( hwnd, WM_SIZE, SIZE_MINIMIZED, 0 );
76 WPARAM wp = IsZoomed( hwnd ) ? SIZE_MAXIMIZED : SIZE_RESTORED;
78 SendMessageW( hwnd, WM_SIZE, wp, MAKELONG(rect.right-rect.left, rect.bottom-rect.top) );
84 /***********************************************************************
87 * Set the window text.
89 static void DEFWND_SetTextA( HWND hwnd, LPCSTR text )
96 count = MultiByteToWideChar( CP_ACP, 0, text, -1, NULL, 0 );
98 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
99 if ((textW = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
101 HeapFree(GetProcessHeap(), 0, wndPtr->text);
102 wndPtr->text = textW;
103 MultiByteToWideChar( CP_ACP, 0, text, -1, textW, count );
104 SERVER_START_REQ( set_window_text )
106 req->handle = wine_server_user_handle( hwnd );
107 wine_server_add_data( req, textW, (count-1) * sizeof(WCHAR) );
108 wine_server_call( req );
113 ERR("Not enough memory for window text\n");
114 WIN_ReleasePtr( wndPtr );
116 USER_Driver->pSetWindowText( hwnd, textW );
119 /***********************************************************************
122 * Set the window text.
124 static void DEFWND_SetTextW( HWND hwnd, LPCWSTR text )
126 static const WCHAR empty_string[] = {0};
130 if (!text) text = empty_string;
131 count = strlenW(text) + 1;
133 if (!(wndPtr = WIN_GetPtr( hwnd ))) return;
134 HeapFree(GetProcessHeap(), 0, wndPtr->text);
135 if ((wndPtr->text = HeapAlloc(GetProcessHeap(), 0, count * sizeof(WCHAR))))
137 strcpyW( wndPtr->text, text );
138 SERVER_START_REQ( set_window_text )
140 req->handle = wine_server_user_handle( hwnd );
141 wine_server_add_data( req, wndPtr->text, (count-1) * sizeof(WCHAR) );
142 wine_server_call( req );
147 ERR("Not enough memory for window text\n");
149 WIN_ReleasePtr( wndPtr );
151 USER_Driver->pSetWindowText( hwnd, text );
154 /***********************************************************************
155 * DEFWND_ControlColor
157 * Default colors for control painting.
159 HBRUSH DEFWND_ControlColor( HDC hDC, UINT ctlType )
161 if( ctlType == CTLCOLOR_SCROLLBAR)
163 HBRUSH hb = GetSysColorBrush(COLOR_SCROLLBAR);
164 COLORREF bk = GetSysColor(COLOR_3DHILIGHT);
165 SetTextColor( hDC, GetSysColor(COLOR_3DFACE));
166 SetBkColor( hDC, bk);
168 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
169 * we better use 0x55aa bitmap brush to make scrollbar's background
170 * look different from the window background.
172 if (bk == GetSysColor(COLOR_WINDOW))
173 return SYSCOLOR_55AABrush;
175 UnrealizeObject( hb );
179 SetTextColor( hDC, GetSysColor(COLOR_WINDOWTEXT));
181 if ((ctlType == CTLCOLOR_EDIT) || (ctlType == CTLCOLOR_LISTBOX))
182 SetBkColor( hDC, GetSysColor(COLOR_WINDOW) );
184 SetBkColor( hDC, GetSysColor(COLOR_3DFACE) );
185 return GetSysColorBrush(COLOR_3DFACE);
187 return GetSysColorBrush(COLOR_WINDOW);
191 /***********************************************************************
194 * This method handles the default behavior for the WM_PRINT message.
196 static void DEFWND_Print( HWND hwnd, HDC hdc, ULONG uFlags)
201 if ( (uFlags & PRF_CHECKVISIBLE) &&
202 !IsWindowVisible(hwnd) )
206 * Unimplemented flags.
208 if ( (uFlags & PRF_CHILDREN) ||
209 (uFlags & PRF_OWNED) ||
210 (uFlags & PRF_NONCLIENT) )
212 WARN("WM_PRINT message with unsupported flags\n");
218 if ( uFlags & PRF_ERASEBKGND)
219 SendMessageW(hwnd, WM_ERASEBKGND, (WPARAM)hdc, 0);
224 if ( uFlags & PRF_CLIENT)
225 SendMessageW(hwnd, WM_PRINTCLIENT, (WPARAM)hdc, uFlags);
230 * helpers for calling IMM32
232 * WM_IME_* messages are generated only by IMM32,
233 * so I assume imm32 is already LoadLibrary-ed.
235 static HWND DEFWND_ImmGetDefaultIMEWnd( HWND hwnd )
237 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
238 HWND (WINAPI *pFunc)(HWND);
243 ERR( "cannot get IMM32 handle\n" );
247 pFunc = (void*)GetProcAddress(hInstIMM,"ImmGetDefaultIMEWnd");
249 hwndRet = (*pFunc)( hwnd );
254 static BOOL DEFWND_ImmIsUIMessageA( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
256 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
257 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
262 ERR( "cannot get IMM32 handle\n" );
266 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageA");
268 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
273 static BOOL DEFWND_ImmIsUIMessageW( HWND hwndIME, UINT msg, WPARAM wParam, LPARAM lParam )
275 HINSTANCE hInstIMM = GetModuleHandleW( imm32W );
276 BOOL (WINAPI *pFunc)(HWND,UINT,WPARAM,LPARAM);
281 ERR( "cannot get IMM32 handle\n" );
285 pFunc = (void*)GetProcAddress(hInstIMM,"ImmIsUIMessageW");
287 fRet = (*pFunc)( hwndIME, msg, wParam, lParam );
294 /***********************************************************************
297 * Default window procedure for messages that are the same in Ansi and Unicode.
299 static LRESULT DEFWND_DefWinProc( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
304 return NC_HandleNCPaint( hwnd, (HRGN)wParam );
309 pt.x = (short)LOWORD(lParam);
310 pt.y = (short)HIWORD(lParam);
311 return NC_HandleNCHitTest( hwnd, pt );
315 return NC_HandleNCCalcSize( hwnd, (RECT *)lParam );
317 case WM_WINDOWPOSCHANGING:
318 return WINPOS_HandleWindowPosChanging( hwnd, (WINDOWPOS *)lParam );
320 case WM_WINDOWPOSCHANGED:
321 DEFWND_HandleWindowPosChanged( hwnd, (const WINDOWPOS *)lParam );
327 iF10Key = iMenuSysKey = 0;
330 case WM_NCLBUTTONDOWN:
331 return NC_HandleNCLButtonDown( hwnd, wParam, lParam );
333 case WM_LBUTTONDBLCLK:
334 return NC_HandleNCLButtonDblClk( hwnd, HTCLIENT, lParam );
336 case WM_NCLBUTTONDBLCLK:
337 return NC_HandleNCLButtonDblClk( hwnd, wParam, lParam );
339 case WM_NCRBUTTONDOWN:
340 /* in Windows, capture is taken when right-clicking on the caption bar */
341 if (wParam==HTCAPTION)
351 if (hwnd == GetCapture())
352 /* release capture if we took it on WM_NCRBUTTONDOWN */
355 pt.x = (short)LOWORD(lParam);
356 pt.y = (short)HIWORD(lParam);
357 ClientToScreen(hwnd, &pt);
358 SendMessageW( hwnd, WM_CONTEXTMENU, (WPARAM)hwnd, MAKELPARAM(pt.x, pt.y) );
364 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
365 * in Windows), but what _should_ we do? According to MSDN :
366 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
367 * message to the window". When is it appropriate?
372 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
373 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
378 WND *wndPtr = WIN_GetPtr( hwnd );
379 HMENU hMenu = wndPtr->hSysMenu;
380 WIN_ReleasePtr( wndPtr );
381 if (!hMenu) return 0;
382 pt.x = (short)LOWORD(lParam);
383 pt.y = (short)HIWORD(lParam);
384 hitcode = NC_HandleNCHitTest(hwnd, pt);
386 /* Track system popup if click was in the caption area. */
387 if (hitcode==HTCAPTION || hitcode==HTSYSMENU)
388 TrackPopupMenu(GetSystemMenu(hwnd, FALSE),
389 TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
390 pt.x, pt.y, 0, hwnd, NULL);
394 case WM_POPUPSYSTEMMENU:
396 /* This is an undocumented message used by the windows taskbar to
397 display the system menu of windows that belong to other processes. */
398 HMENU menu = GetSystemMenu(hwnd, FALSE);
401 TrackPopupMenu(menu, TPM_LEFTBUTTON|TPM_RIGHTBUTTON,
402 LOWORD(lParam), HIWORD(lParam), 0, hwnd, NULL);
407 return NC_HandleNCActivate( hwnd, wParam, lParam );
411 WND *wndPtr = WIN_GetPtr( hwnd );
412 if (!wndPtr) return 0;
413 HeapFree( GetProcessHeap(), 0, wndPtr->text );
415 HeapFree( GetProcessHeap(), 0, wndPtr->pScroll );
416 wndPtr->pScroll = NULL;
417 WIN_ReleasePtr( wndPtr );
422 DEFWND_Print(hwnd, (HDC)wParam, lParam);
429 HDC hdc = BeginPaint( hwnd, &ps );
433 if (IsIconic(hwnd) && ((hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON))) )
438 GetClientRect( hwnd, &rc );
439 x = (rc.right - rc.left - GetSystemMetrics(SM_CXICON))/2;
440 y = (rc.bottom - rc.top - GetSystemMetrics(SM_CYICON))/2;
441 TRACE("Painting class icon: vis rect=(%s)\n",
442 wine_dbgstr_rect(&ps.rcPaint));
443 DrawIcon( hdc, x, y, hIcon );
445 EndPaint( hwnd, &ps );
451 RedrawWindow ( hwnd, NULL, 0, RDW_ERASENOW | RDW_ERASE | RDW_ALLCHILDREN );
455 if (wParam) WIN_SetStyle( hwnd, WS_VISIBLE, 0 );
458 RedrawWindow( hwnd, NULL, 0, RDW_ALLCHILDREN | RDW_VALIDATE );
459 WIN_SetStyle( hwnd, 0, WS_VISIBLE );
464 DestroyWindow( hwnd );
467 case WM_MOUSEACTIVATE:
468 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
470 LONG ret = SendMessageW( GetParent(hwnd), WM_MOUSEACTIVATE, wParam, lParam );
474 /* Caption clicks are handled by NC_HandleNCLButtonDown() */
478 /* The default action in Windows is to set the keyboard focus to
479 * the window, if it's being activated and not minimized */
480 if (LOWORD(wParam) != WA_INACTIVE) {
481 if (!IsIconic(hwnd)) SetFocus(hwnd);
486 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
487 return SendMessageW( GetParent(hwnd), WM_MOUSEWHEEL, wParam, lParam );
491 case WM_ICONERASEBKGND:
494 HDC hdc = (HDC)wParam;
495 HBRUSH hbr = (HBRUSH)GetClassLongPtrW( hwnd, GCLP_HBRBACKGROUND );
498 if (GetClassLongW( hwnd, GCL_STYLE ) & CS_PARENTDC)
500 /* can't use GetClipBox with a parent DC or we fill the whole parent */
501 GetClientRect( hwnd, &rect );
502 DPtoLP( hdc, (LPPOINT)&rect, 2 );
504 else GetClipBox( hdc, &rect );
505 FillRect( hdc, &rect, hbr );
512 case WM_CTLCOLORMSGBOX:
513 case WM_CTLCOLOREDIT:
514 case WM_CTLCOLORLISTBOX:
517 case WM_CTLCOLORSTATIC:
518 case WM_CTLCOLORSCROLLBAR:
519 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, msg - WM_CTLCOLORMSGBOX );
522 return (LRESULT)DEFWND_ControlColor( (HDC)wParam, HIWORD(lParam) );
525 if (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD)
527 /* with the exception of the border around a resizable wnd,
528 * give the parent first chance to set the cursor */
529 if ((LOWORD(lParam) < HTSIZEFIRST) || (LOWORD(lParam) > HTSIZELAST))
531 if (SendMessageW(GetParent(hwnd), WM_SETCURSOR, wParam, lParam)) return TRUE;
534 NC_HandleSetCursor( hwnd, wParam, lParam );
538 return NC_HandleSysCommand( hwnd, wParam, lParam );
541 if(wParam == VK_F10) iF10Key = VK_F10;
545 if( HIWORD(lParam) & KEYDATA_ALT )
547 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
548 if ( (wParam == VK_MENU || wParam == VK_LMENU
549 || wParam == VK_RMENU) && !iMenuSysKey )
556 if( wParam == VK_F4 ) /* try to close the window */
558 HWND top = GetAncestor( hwnd, GA_ROOT );
559 if (!(GetClassLongW( top, GCL_STYLE ) & CS_NOCLOSE))
560 PostMessageW( top, WM_SYSCOMMAND, SC_CLOSE, 0 );
563 else if( wParam == VK_F10 )
565 else if( wParam == VK_ESCAPE && (GetKeyState(VK_SHIFT) & 0x8000))
566 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, ' ' );
571 /* Press and release F10 or ALT */
572 if (((wParam == VK_MENU || wParam == VK_LMENU || wParam == VK_RMENU)
573 && iMenuSysKey) || ((wParam == VK_F10) && iF10Key))
574 SendMessageW( GetAncestor( hwnd, GA_ROOT ), WM_SYSCOMMAND, SC_KEYMENU, 0L );
575 iMenuSysKey = iF10Key = 0;
581 if (wParam == '\r' && IsIconic(hwnd))
583 PostMessageW( hwnd, WM_SYSCOMMAND, SC_RESTORE, 0L );
586 if ((HIWORD(lParam) & KEYDATA_ALT) && wParam)
588 if (wParam == '\t' || wParam == '\x1b') break;
589 if (wParam == ' ' && (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CHILD))
590 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
592 SendMessageW( hwnd, WM_SYSCOMMAND, SC_KEYMENU, wParam );
594 else /* check for Ctrl-Esc */
595 if (wParam != '\x1b') MessageBeep(0);
601 LONG style = GetWindowLongW( hwnd, GWL_STYLE );
603 if (!lParam) return 0; /* sent from ShowWindow */
604 if ((style & WS_VISIBLE) && wParam) return 0;
605 if (!(style & WS_VISIBLE) && !wParam) return 0;
606 if (!GetWindow( hwnd, GW_OWNER )) return 0;
607 if (!(pWnd = WIN_GetPtr( hwnd ))) return 0;
608 if (pWnd == WND_OTHER_PROCESS) return 0;
611 if (!(pWnd->flags & WIN_NEEDS_SHOW_OWNEDPOPUP))
613 WIN_ReleasePtr( pWnd );
616 pWnd->flags &= ~WIN_NEEDS_SHOW_OWNEDPOPUP;
618 else pWnd->flags |= WIN_NEEDS_SHOW_OWNEDPOPUP;
619 WIN_ReleasePtr( pWnd );
620 ShowWindow( hwnd, wParam ? SW_SHOWNOACTIVATE : SW_HIDE );
626 MENU_EndMenu( hwnd );
627 if (GetCapture() == hwnd) ReleaseCapture();
637 case WM_QUERYDROPOBJECT:
638 return (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_ACCEPTFILES) != 0;
640 case WM_QUERYDRAGICON:
644 HICON hIcon = (HICON)GetClassLongPtrW( hwnd, GCLP_HICON );
645 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
646 if (hIcon) return (LRESULT)hIcon;
647 for(len=1; len<64; len++)
648 if((hIcon = LoadIconW(instance, MAKEINTRESOURCEW(len))))
649 return (LRESULT)hIcon;
650 return (LRESULT)LoadIconW(0, (LPWSTR)IDI_APPLICATION);
654 case WM_ISACTIVEICON:
656 WND *wndPtr = WIN_GetPtr( hwnd );
657 BOOL ret = (wndPtr->flags & WIN_NCACTIVATED) != 0;
658 WIN_ReleasePtr( wndPtr );
662 case WM_NOTIFYFORMAT:
663 if (IsWindowUnicode(hwnd)) return NFR_UNICODE;
664 else return NFR_ANSI;
667 case WM_QUERYENDSESSION:
673 WND *wndPtr = WIN_GetPtr( hwnd );
678 ret = wndPtr->hIconSmall;
679 wndPtr->hIconSmall = (HICON)lParam;
683 wndPtr->hIcon = (HICON)lParam;
689 WIN_ReleasePtr( wndPtr );
691 USER_Driver->pSetWindowIcon( hwnd, wParam, (HICON)lParam );
693 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
694 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
702 WND *wndPtr = WIN_GetPtr( hwnd );
707 ret = wndPtr->hIconSmall;
713 ret = wndPtr->hIconSmall;
714 if (!ret) ret = (HICON)GetClassLongPtrW( hwnd, GCLP_HICONSM );
715 /* FIXME: should have a default here if class icon is null */
721 WIN_ReleasePtr( wndPtr );
726 SendMessageW( GetParent(hwnd), msg, wParam, lParam );
731 HWND parent = GetParent(hwnd);
733 HOOK_CallHooks(WH_SHELL, HSHELL_APPCOMMAND, wParam, lParam, TRUE);
735 SendMessageW( parent, msg, wParam, lParam );
742 hi.cbSize = sizeof(HELPINFO);
743 GetCursorPos( &hi.MousePos );
744 if (MENU_IsMenuActive())
746 hi.iContextType = HELPINFO_MENUITEM;
747 hi.hItemHandle = MENU_IsMenuActive();
748 hi.iCtrlId = MenuItemFromPoint( hwnd, hi.hItemHandle, hi.MousePos );
749 hi.dwContextId = GetMenuContextHelpId( hi.hItemHandle );
753 hi.iContextType = HELPINFO_WINDOW;
754 hi.hItemHandle = hwnd;
755 hi.iCtrlId = GetWindowLongPtrA( hwnd, GWLP_ID );
756 hi.dwContextId = GetWindowContextHelpId( hwnd );
758 SendMessageW( hwnd, WM_HELP, 0, (LPARAM)&hi );
762 case WM_INPUTLANGCHANGEREQUEST:
763 ActivateKeyboardLayout( (HKL)lParam, 0 );
766 case WM_INPUTLANGCHANGE:
769 HWND *win_array = WIN_ListChildren( hwnd );
773 while (win_array[count])
774 SendMessageW( win_array[count++], WM_INPUTLANGCHANGE, wParam, lParam);
775 HeapFree(GetProcessHeap(),0,win_array);
784 static LPARAM DEFWND_GetTextA( WND *wndPtr, LPSTR dest, WPARAM wParam )
792 if (!WideCharToMultiByte( CP_ACP, 0, wndPtr->text, -1,
793 dest, wParam, NULL, NULL )) dest[wParam-1] = 0;
794 result = strlen( dest );
806 /***********************************************************************
807 * DefWindowProcA (USER32.@)
809 * See DefWindowProcW.
811 LRESULT WINAPI DefWindowProcA( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
816 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
818 if (!IsWindow( hwnd )) return 0;
819 ERR( "called for other process window %p\n", hwnd );
824 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
831 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
832 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
833 * may have child window IDs instead of window name */
834 if (HIWORD(cs->lpszName))
835 DEFWND_SetTextA( hwnd, cs->lpszName );
840 case WM_GETTEXTLENGTH:
842 WND *wndPtr = WIN_GetPtr( hwnd );
843 if (wndPtr && wndPtr->text)
844 result = WideCharToMultiByte( CP_ACP, 0, wndPtr->text, strlenW(wndPtr->text),
845 NULL, 0, NULL, NULL );
846 WIN_ReleasePtr( wndPtr );
853 LPSTR dest = (LPSTR)lParam;
854 WND *wndPtr = WIN_GetPtr( hwnd );
857 result = DEFWND_GetTextA( wndPtr, dest, wParam );
859 WIN_ReleasePtr( wndPtr );
864 DEFWND_SetTextA( hwnd, (LPCSTR)lParam );
865 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
866 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
867 result = 1; /* success. FIXME: check text length */
871 if (HIBYTE(wParam)) PostMessageA( hwnd, WM_CHAR, HIBYTE(wParam), lParam );
872 PostMessageA( hwnd, WM_CHAR, LOBYTE(wParam), lParam );
876 result = PostMessageA( hwnd, WM_KEYDOWN, wParam, lParam );
880 result = PostMessageA( hwnd, WM_KEYUP, wParam, lParam );
883 case WM_IME_STARTCOMPOSITION:
884 case WM_IME_COMPOSITION:
885 case WM_IME_ENDCOMPOSITION:
891 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
893 result = SendMessageA( hwndIME, msg, wParam, lParam );
896 case WM_IME_SETCONTEXT:
900 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
902 result = DEFWND_ImmIsUIMessageA( hwndIME, msg, wParam, lParam );
908 CHAR ch = LOWORD(wParam);
910 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
911 wParam = MAKEWPARAM( wch, HIWORD(wParam) );
915 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
919 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );
924 static LPARAM DEFWND_GetTextW( WND *wndPtr, LPWSTR dest, WPARAM wParam )
932 lstrcpynW( dest, wndPtr->text, wParam );
933 result = strlenW( dest );
946 /***********************************************************************
947 * DefWindowProcW (USER32.@) Calls default window message handler
949 * Calls default window procedure for messages not processed
953 * Return value is dependent upon the message.
955 LRESULT WINAPI DefWindowProcW(
956 HWND hwnd, /* [in] window procedure receiving message */
957 UINT msg, /* [in] message identifier */
958 WPARAM wParam, /* [in] first message parameter */
959 LPARAM lParam ) /* [in] second message parameter */
964 if (!(full_handle = WIN_IsCurrentProcess( hwnd )))
966 if (!IsWindow( hwnd )) return 0;
967 ERR( "called for other process window %p\n", hwnd );
971 SPY_EnterMessage( SPY_DEFWNDPROC, hwnd, msg, wParam, lParam );
978 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
979 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
980 * may have child window IDs instead of window name */
981 if (HIWORD(cs->lpszName))
982 DEFWND_SetTextW( hwnd, cs->lpszName );
987 case WM_GETTEXTLENGTH:
989 WND *wndPtr = WIN_GetPtr( hwnd );
990 if (wndPtr && wndPtr->text) result = (LRESULT)strlenW(wndPtr->text);
991 WIN_ReleasePtr( wndPtr );
998 LPWSTR dest = (LPWSTR)lParam;
999 WND *wndPtr = WIN_GetPtr( hwnd );
1002 result = DEFWND_GetTextW( wndPtr, dest, wParam );
1003 WIN_ReleasePtr( wndPtr );
1008 DEFWND_SetTextW( hwnd, (LPCWSTR)lParam );
1009 if( (GetWindowLongW( hwnd, GWL_STYLE ) & WS_CAPTION) == WS_CAPTION )
1010 NC_HandleNCPaint( hwnd , (HRGN)1 ); /* Repaint caption */
1011 result = 1; /* success. FIXME: check text length */
1015 PostMessageW( hwnd, WM_CHAR, wParam, lParam );
1018 case WM_IME_KEYDOWN:
1019 result = PostMessageW( hwnd, WM_KEYDOWN, wParam, lParam );
1023 result = PostMessageW( hwnd, WM_KEYUP, wParam, lParam );
1026 case WM_IME_SETCONTEXT:
1030 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1032 result = DEFWND_ImmIsUIMessageW( hwndIME, msg, wParam, lParam );
1036 case WM_IME_STARTCOMPOSITION:
1037 case WM_IME_COMPOSITION:
1038 case WM_IME_ENDCOMPOSITION:
1044 hwndIME = DEFWND_ImmGetDefaultIMEWnd( hwnd );
1046 result = SendMessageW( hwndIME, msg, wParam, lParam );
1051 result = DEFWND_DefWinProc( hwnd, msg, wParam, lParam );
1054 SPY_ExitMessage( SPY_RESULT_DEFWND, hwnd, msg, result, wParam, lParam );