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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
34 #include "user_private.h"
38 #include "wine/unicode.h"
39 #include "wine/winuser16.h"
40 #include "wine/server.h"
41 #include "wine/debug.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(win
);
45 /* bits in the dwKeyData */
46 #define KEYDATA_ALT 0x2000
47 #define KEYDATA_PREVSTATE 0x4000
49 static short iF10Key
= 0;
50 static short iMenuSysKey
= 0;
51 static const WCHAR imm32W
[] = { 'i','m','m','3','2','\0' };
53 /***********************************************************************
54 * DEFWND_HandleWindowPosChanged
56 * Handle the WM_WINDOWPOSCHANGED message.
58 static void DEFWND_HandleWindowPosChanged( HWND hwnd
, UINT flags
)
61 WND
*wndPtr
= WIN_GetPtr( hwnd
);
63 rect
= wndPtr
->rectClient
;
64 WIN_ReleasePtr( wndPtr
);
66 if (!(flags
& SWP_NOCLIENTMOVE
))
67 SendMessageW( hwnd
, WM_MOVE
, 0, MAKELONG(rect
.left
, rect
.top
));
69 if (!(flags
& SWP_NOCLIENTSIZE
))
71 WPARAM wp
= SIZE_RESTORED
;
72 if (IsZoomed(hwnd
)) wp
= SIZE_MAXIMIZED
;
73 else if (IsIconic(hwnd
)) wp
= SIZE_MINIMIZED
;
75 SendMessageW( hwnd
, WM_SIZE
, wp
, MAKELONG(rect
.right
-rect
.left
, rect
.bottom
-rect
.top
) );
80 /***********************************************************************
83 * Set the window text.
85 static void DEFWND_SetTextA( HWND hwnd
, LPCSTR text
)
92 count
= MultiByteToWideChar( CP_ACP
, 0, text
, -1, NULL
, 0 );
94 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
95 if ((textW
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
97 HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
99 MultiByteToWideChar( CP_ACP
, 0, text
, -1, textW
, count
);
100 SERVER_START_REQ( set_window_text
)
103 wine_server_add_data( req
, textW
, (count
-1) * sizeof(WCHAR
) );
104 wine_server_call( req
);
109 ERR("Not enough memory for window text\n");
110 WIN_ReleasePtr( wndPtr
);
112 if (USER_Driver
.pSetWindowText
) USER_Driver
.pSetWindowText( hwnd
, textW
);
115 /***********************************************************************
118 * Set the window text.
120 static void DEFWND_SetTextW( HWND hwnd
, LPCWSTR text
)
122 static const WCHAR empty_string
[] = {0};
126 if (!text
) text
= empty_string
;
127 count
= strlenW(text
) + 1;
129 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return;
130 HeapFree(GetProcessHeap(), 0, wndPtr
->text
);
131 if ((wndPtr
->text
= HeapAlloc(GetProcessHeap(), 0, count
* sizeof(WCHAR
))))
133 strcpyW( wndPtr
->text
, text
);
134 SERVER_START_REQ( set_window_text
)
137 wine_server_add_data( req
, wndPtr
->text
, (count
-1) * sizeof(WCHAR
) );
138 wine_server_call( req
);
143 ERR("Not enough memory for window text\n");
145 WIN_ReleasePtr( wndPtr
);
147 if (USER_Driver
.pSetWindowText
) USER_Driver
.pSetWindowText( hwnd
, text
);
150 /***********************************************************************
151 * DEFWND_ControlColor
153 * Default colors for control painting.
155 HBRUSH
DEFWND_ControlColor( HDC hDC
, UINT ctlType
)
157 if( ctlType
== CTLCOLOR_SCROLLBAR
)
159 HBRUSH hb
= GetSysColorBrush(COLOR_SCROLLBAR
);
160 COLORREF bk
= GetSysColor(COLOR_3DHILIGHT
);
161 SetTextColor( hDC
, GetSysColor(COLOR_3DFACE
));
162 SetBkColor( hDC
, bk
);
164 /* if COLOR_WINDOW happens to be the same as COLOR_3DHILIGHT
165 * we better use 0x55aa bitmap brush to make scrollbar's background
166 * look different from the window background.
168 if (bk
== GetSysColor(COLOR_WINDOW
))
169 return UITOOLS_GetPattern55AABrush();
171 UnrealizeObject( hb
);
175 SetTextColor( hDC
, GetSysColor(COLOR_WINDOWTEXT
));
177 if ((ctlType
== CTLCOLOR_EDIT
) || (ctlType
== CTLCOLOR_LISTBOX
))
178 SetBkColor( hDC
, GetSysColor(COLOR_WINDOW
) );
180 SetBkColor( hDC
, GetSysColor(COLOR_3DFACE
) );
181 return GetSysColorBrush(COLOR_3DFACE
);
183 return GetSysColorBrush(COLOR_WINDOW
);
187 /***********************************************************************
190 static void DEFWND_SetRedraw( HWND hwnd
, WPARAM wParam
)
192 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
193 BOOL bVisible
= wndPtr
->dwStyle
& WS_VISIBLE
;
195 TRACE("%p %i\n", hwnd
, (wParam
!=0) );
201 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
| WS_VISIBLE
);
206 if( wndPtr
->dwStyle
& WS_MINIMIZE
) wParam
= RDW_VALIDATE
;
207 else wParam
= RDW_ALLCHILDREN
| RDW_VALIDATE
;
209 RedrawWindow( hwnd
, NULL
, 0, wParam
);
210 WIN_SetStyle( hwnd
, wndPtr
->dwStyle
& ~WS_VISIBLE
);
212 WIN_ReleaseWndPtr( wndPtr
);
215 /***********************************************************************
218 * This method handles the default behavior for the WM_PRINT message.
220 static void DEFWND_Print( HWND hwnd
, HDC hdc
, ULONG uFlags
)
225 if ( (uFlags
& PRF_CHECKVISIBLE
) &&
226 !IsWindowVisible(hwnd
) )
230 * Unimplemented flags.
232 if ( (uFlags
& PRF_CHILDREN
) ||
233 (uFlags
& PRF_OWNED
) ||
234 (uFlags
& PRF_NONCLIENT
) )
236 WARN("WM_PRINT message with unsupported flags\n");
242 if ( uFlags
& PRF_ERASEBKGND
)
243 SendMessageW(hwnd
, WM_ERASEBKGND
, (WPARAM
)hdc
, 0);
248 if ( uFlags
& PRF_CLIENT
)
249 SendMessageW(hwnd
, WM_PRINTCLIENT
, (WPARAM
)hdc
, PRF_CLIENT
);
254 * helpers for calling IMM32
256 * WM_IME_* messages are generated only by IMM32,
257 * so I assume imm32 is already LoadLibrary-ed.
259 static HWND
DEFWND_ImmGetDefaultIMEWnd( HWND hwnd
)
261 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
262 HWND (WINAPI
*pFunc
)(HWND
);
267 ERR( "cannot get IMM32 handle\n" );
271 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmGetDefaultIMEWnd");
273 hwndRet
= (*pFunc
)( hwnd
);
278 static BOOL
DEFWND_ImmIsUIMessageA( HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
280 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
281 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
286 ERR( "cannot get IMM32 handle\n" );
290 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmIsUIMessageA");
292 fRet
= (*pFunc
)( hwndIME
, msg
, wParam
, lParam
);
297 static BOOL
DEFWND_ImmIsUIMessageW( HWND hwndIME
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
299 HINSTANCE hInstIMM
= GetModuleHandleW( imm32W
);
300 BOOL (WINAPI
*pFunc
)(HWND
,UINT
,WPARAM
,LPARAM
);
305 ERR( "cannot get IMM32 handle\n" );
309 pFunc
= (void*)GetProcAddress(hInstIMM
,"ImmIsUIMessageW");
311 fRet
= (*pFunc
)( hwndIME
, msg
, wParam
, lParam
);
318 /***********************************************************************
321 * Default window procedure for messages that are the same in Win16 and Win32.
323 static LRESULT
DEFWND_DefWinProc( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
328 return NC_HandleNCPaint( hwnd
, (HRGN
)wParam
);
333 pt
.x
= (short)LOWORD(lParam
);
334 pt
.y
= (short)HIWORD(lParam
);
335 return NC_HandleNCHitTest( hwnd
, pt
);
341 iF10Key
= iMenuSysKey
= 0;
344 case WM_NCLBUTTONDOWN
:
345 return NC_HandleNCLButtonDown( hwnd
, wParam
, lParam
);
347 case WM_LBUTTONDBLCLK
:
348 case WM_NCLBUTTONDBLCLK
:
349 return NC_HandleNCLButtonDblClk( hwnd
, wParam
, lParam
);
351 case WM_NCRBUTTONDOWN
:
352 /* in Windows, capture is taken when right-clicking on the caption bar */
353 if (wParam
==HTCAPTION
)
363 if (hwnd
== GetCapture())
364 /* release capture if we took it on WM_NCRBUTTONDOWN */
367 pt
.x
= (short)LOWORD(lParam
);
368 pt
.y
= (short)HIWORD(lParam
);
369 ClientToScreen(hwnd
, &pt
);
370 SendMessageW( hwnd
, WM_CONTEXTMENU
, (WPARAM
)hwnd
, MAKELPARAM(pt
.x
, pt
.y
) );
376 * FIXME : we must NOT send WM_CONTEXTMENU on a WM_NCRBUTTONUP (checked
377 * in Windows), but what _should_ we do? According to MSDN :
378 * "If it is appropriate to do so, the system sends the WM_SYSCOMMAND
379 * message to the window". When is it appropriate?
384 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
385 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
390 WND
*wndPtr
= WIN_GetPtr( hwnd
);
391 HMENU hMenu
= wndPtr
->hSysMenu
;
392 WIN_ReleasePtr( wndPtr
);
393 if (!hMenu
) return 0;
394 pt
.x
= (short)LOWORD(lParam
);
395 pt
.y
= (short)HIWORD(lParam
);
396 hitcode
= NC_HandleNCHitTest(hwnd
, pt
);
398 /* Track system popup if click was in the caption area. */
399 if (hitcode
==HTCAPTION
|| hitcode
==HTSYSMENU
)
400 TrackPopupMenu(GetSystemMenu(hwnd
, FALSE
),
401 TPM_LEFTBUTTON
| TPM_RIGHTBUTTON
,
402 pt
.x
, pt
.y
, 0, hwnd
, NULL
);
407 return NC_HandleNCActivate( hwnd
, wParam
);
411 WND
*wndPtr
= WIN_GetPtr( hwnd
);
412 if (!wndPtr
) return 0;
413 HeapFree( GetProcessHeap(), 0, wndPtr
->text
);
415 HeapFree( GetProcessHeap(), 0, wndPtr
->pVScroll
);
416 HeapFree( GetProcessHeap(), 0, wndPtr
->pHScroll
);
417 wndPtr
->pVScroll
= wndPtr
->pHScroll
= NULL
;
418 WIN_ReleasePtr( wndPtr
);
423 DEFWND_Print(hwnd
, (HDC
)wParam
, lParam
);
430 HDC hdc
= BeginPaint( hwnd
, &ps
);
434 if (IsIconic(hwnd
) && ((hIcon
= (HICON
)GetClassLongW( hwnd
, GCL_HICON
))) )
439 GetClientRect( hwnd
, &rc
);
440 x
= (rc
.right
- rc
.left
- GetSystemMetrics(SM_CXICON
))/2;
441 y
= (rc
.bottom
- rc
.top
- GetSystemMetrics(SM_CYICON
))/2;
442 TRACE("Painting class icon: vis rect=(%ld,%ld - %ld,%ld)\n",
443 ps
.rcPaint
.left
, ps
.rcPaint
.top
, ps
.rcPaint
.right
, ps
.rcPaint
.bottom
);
444 DrawIcon( hdc
, x
, y
, hIcon
);
446 EndPaint( hwnd
, &ps
);
452 RedrawWindow ( hwnd
, NULL
, 0, RDW_ERASENOW
| RDW_ERASE
| RDW_ALLCHILDREN
);
456 DEFWND_SetRedraw( hwnd
, wParam
);
460 DestroyWindow( hwnd
);
463 case WM_MOUSEACTIVATE
:
464 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
466 LONG ret
= SendMessageW( GetParent(hwnd
), WM_MOUSEACTIVATE
, wParam
, lParam
);
470 /* Caption clicks are handled by the NC_HandleNCLButtonDown() */
471 return (LOWORD(lParam
) >= HTCLIENT
) ? MA_ACTIVATE
: MA_NOACTIVATE
;
474 /* The default action in Windows is to set the keyboard focus to
475 * the window, if it's being activated and not minimized */
476 if (LOWORD(wParam
) != WA_INACTIVE
) {
477 if (!IsIconic(hwnd
)) SetFocus(hwnd
);
482 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
483 return SendMessageW( GetParent(hwnd
), WM_MOUSEWHEEL
, wParam
, lParam
);
487 case WM_ICONERASEBKGND
:
490 HDC hdc
= (HDC
)wParam
;
491 HBRUSH hbr
= (HBRUSH
)GetClassLongW( hwnd
, GCL_HBRBACKGROUND
);
494 if (GetClassLongW( hwnd
, GCL_STYLE
) & CS_PARENTDC
)
496 /* can't use GetClipBox with a parent DC or we fill the whole parent */
497 GetClientRect( hwnd
, &rect
);
498 DPtoLP( hdc
, (LPPOINT
)&rect
, 2 );
500 else GetClipBox( hdc
, &rect
);
501 FillRect( hdc
, &rect
, hbr
);
508 case WM_CTLCOLORMSGBOX
:
509 case WM_CTLCOLOREDIT
:
510 case WM_CTLCOLORLISTBOX
:
513 case WM_CTLCOLORSTATIC
:
514 case WM_CTLCOLORSCROLLBAR
:
515 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, msg
- WM_CTLCOLORMSGBOX
);
518 return (LRESULT
)DEFWND_ControlColor( (HDC
)wParam
, HIWORD(lParam
) );
521 if (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)
523 /* with the exception of the border around a resizable wnd,
524 * give the parent first chance to set the cursor */
525 if ((LOWORD(lParam
) < HTSIZEFIRST
) || (LOWORD(lParam
) > HTSIZELAST
))
527 if (SendMessageW(GetParent(hwnd
), WM_SETCURSOR
, wParam
, lParam
)) return TRUE
;
530 NC_HandleSetCursor( hwnd
, wParam
, lParam
);
534 return NC_HandleSysCommand( hwnd
, wParam
, lParam
);
537 if(wParam
== VK_F10
) iF10Key
= VK_F10
;
541 if( HIWORD(lParam
) & KEYDATA_ALT
)
543 /* if( HIWORD(lParam) & ~KEYDATA_PREVSTATE ) */
544 if( wParam
== VK_MENU
&& !iMenuSysKey
)
551 if( wParam
== VK_F4
) /* try to close the window */
553 HWND top
= GetAncestor( hwnd
, GA_ROOT
);
554 if (!(GetClassLongW( top
, GCL_STYLE
) & CS_NOCLOSE
))
555 PostMessageW( top
, WM_SYSCOMMAND
, SC_CLOSE
, 0 );
558 else if( wParam
== VK_F10
)
560 else if( wParam
== VK_ESCAPE
&& (GetKeyState(VK_SHIFT
) & 0x8000))
561 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, ' ' );
566 /* Press and release F10 or ALT */
567 if (((wParam
== VK_MENU
) && iMenuSysKey
) ||
568 ((wParam
== VK_F10
) && iF10Key
))
569 SendMessageW( GetAncestor( hwnd
, GA_ROOT
), WM_SYSCOMMAND
, SC_KEYMENU
, 0L );
570 iMenuSysKey
= iF10Key
= 0;
576 if (wParam
== '\r' && IsIconic(hwnd
))
578 PostMessageW( hwnd
, WM_SYSCOMMAND
, SC_RESTORE
, 0L );
581 if ((HIWORD(lParam
) & KEYDATA_ALT
) && wParam
)
583 if (wParam
== '\t' || wParam
== '\x1b') break;
584 if (wParam
== ' ' && (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
))
585 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
587 SendMessageW( hwnd
, WM_SYSCOMMAND
, SC_KEYMENU
, wParam
);
589 else /* check for Ctrl-Esc */
590 if (wParam
!= '\x1b') MessageBeep(0);
596 LONG style
= GetWindowLongW( hwnd
, GWL_STYLE
);
597 if (!lParam
) return 0; /* sent from ShowWindow */
598 if (!(style
& WS_POPUP
)) return 0;
599 if ((style
& WS_VISIBLE
) && wParam
) return 0;
600 if (!(style
& WS_VISIBLE
) && !wParam
) return 0;
601 if (!GetWindow( hwnd
, GW_OWNER
)) return 0;
602 ShowWindow( hwnd
, wParam
? SW_SHOWNOACTIVATE
: SW_HIDE
);
607 if (!(GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CHILD
)) EndMenu();
608 if (GetCapture() == hwnd
) ReleaseCapture();
618 case WM_QUERYDROPOBJECT
:
619 return (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_ACCEPTFILES
) != 0;
621 case WM_QUERYDRAGICON
:
625 HICON hIcon
= (HICON
)GetClassLongW( hwnd
, GCL_HICON
);
626 HINSTANCE instance
= (HINSTANCE
)GetWindowLongPtrW( hwnd
, GWLP_HINSTANCE
);
627 if (hIcon
) return (LRESULT
)hIcon
;
628 for(len
=1; len
<64; len
++)
629 if((hIcon
= LoadIconW(instance
, MAKEINTRESOURCEW(len
))))
630 return (LRESULT
)hIcon
;
631 return (LRESULT
)LoadIconW(0, (LPWSTR
)IDI_APPLICATION
);
635 case WM_ISACTIVEICON
:
637 WND
*wndPtr
= WIN_GetPtr( hwnd
);
638 BOOL ret
= (wndPtr
->flags
& WIN_NCACTIVATED
) != 0;
639 WIN_ReleasePtr( wndPtr
);
643 case WM_NOTIFYFORMAT
:
644 if (IsWindowUnicode(hwnd
)) return NFR_UNICODE
;
645 else return NFR_ANSI
;
648 case WM_QUERYENDSESSION
:
654 WND
*wndPtr
= WIN_GetPtr( hwnd
);
659 ret
= wndPtr
->hIconSmall
;
660 wndPtr
->hIconSmall
= (HICON
)lParam
;
664 wndPtr
->hIcon
= (HICON
)lParam
;
670 WIN_ReleasePtr( wndPtr
);
672 if (USER_Driver
.pSetWindowIcon
)
673 USER_Driver
.pSetWindowIcon( hwnd
, wParam
, (HICON
)lParam
);
675 SetWindowPos(hwnd
, 0, 0, 0, 0, 0, SWP_FRAMECHANGED
| SWP_NOSIZE
|
676 SWP_NOMOVE
| SWP_NOACTIVATE
| SWP_NOZORDER
);
684 WND
*wndPtr
= WIN_GetPtr( hwnd
);
689 ret
= wndPtr
->hIconSmall
;
695 ret
= wndPtr
->hIconSmall
;
696 if (!ret
) ret
= (HICON
)GetClassLongA( hwnd
, GCL_HICONSM
);
697 /* FIXME: should have a default here if class icon is null */
703 WIN_ReleasePtr( wndPtr
);
708 SendMessageW( GetParent(hwnd
), msg
, wParam
, lParam
);
717 /***********************************************************************
718 * DefWindowProc (USER.107)
720 LRESULT WINAPI
DefWindowProc16( HWND16 hwnd16
, UINT16 msg
, WPARAM16 wParam
,
724 HWND hwnd
= WIN_Handle32( hwnd16
);
726 if (!WIN_IsCurrentProcess( hwnd
))
728 if (!IsWindow( hwnd
)) return 0;
729 ERR( "called for other process window %p\n", hwnd
);
732 SPY_EnterMessage( SPY_DEFWNDPROC16
, hwnd
, msg
, wParam
, lParam
);
738 CREATESTRUCT16
*cs
= MapSL(lParam
);
739 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
740 * may have child window IDs instead of window name */
741 if (HIWORD(cs
->lpszName
))
742 DEFWND_SetTextA( hwnd
, MapSL(cs
->lpszName
) );
750 RECT16
*rect16
= MapSL(lParam
);
752 rect32
.left
= rect16
->left
;
753 rect32
.top
= rect16
->top
;
754 rect32
.right
= rect16
->right
;
755 rect32
.bottom
= rect16
->bottom
;
756 result
= NC_HandleNCCalcSize( hwnd
, &rect32
);
757 rect16
->left
= rect32
.left
;
758 rect16
->top
= rect32
.top
;
759 rect16
->right
= rect32
.right
;
760 rect16
->bottom
= rect32
.bottom
;
764 case WM_WINDOWPOSCHANGING
:
765 result
= WINPOS_HandleWindowPosChanging16( hwnd
, MapSL(lParam
) );
768 case WM_WINDOWPOSCHANGED
:
770 WINDOWPOS16
* winPos
= MapSL(lParam
);
771 DEFWND_HandleWindowPosChanged( hwnd
, winPos
->flags
);
777 result
= DefWindowProcA( hwnd
, msg
, wParam
, (LPARAM
)MapSL(lParam
) );
781 result
= DefWindowProcA( hwnd
, msg
, wParam
, lParam
);
785 SPY_ExitMessage( SPY_RESULT_DEFWND16
, hwnd
, msg
, result
, wParam
, lParam
);
790 /***********************************************************************
791 * DefWindowProcA (USER32.@)
794 LRESULT WINAPI
DefWindowProcA( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
799 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
801 if (!IsWindow( hwnd
)) return 0;
802 ERR( "called for other process window %p\n", hwnd
);
807 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
813 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
814 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
815 * may have child window IDs instead of window name */
816 if (HIWORD(cs
->lpszName
))
817 DEFWND_SetTextA( hwnd
, cs
->lpszName
);
823 result
= NC_HandleNCCalcSize( hwnd
, (RECT
*)lParam
);
826 case WM_WINDOWPOSCHANGING
:
827 result
= WINPOS_HandleWindowPosChanging( hwnd
, (WINDOWPOS
*)lParam
);
830 case WM_WINDOWPOSCHANGED
:
832 WINDOWPOS
* winPos
= (WINDOWPOS
*)lParam
;
833 DEFWND_HandleWindowPosChanged( hwnd
, winPos
->flags
);
837 case WM_GETTEXTLENGTH
:
839 WND
*wndPtr
= WIN_GetPtr( hwnd
);
840 if (wndPtr
&& wndPtr
->text
)
841 result
= WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, strlenW(wndPtr
->text
),
842 NULL
, 0, NULL
, NULL
);
843 WIN_ReleasePtr( wndPtr
);
850 LPSTR dest
= (LPSTR
)lParam
;
851 WND
*wndPtr
= WIN_GetPtr( hwnd
);
856 if (!WideCharToMultiByte( CP_ACP
, 0, wndPtr
->text
, -1,
857 dest
, wParam
, NULL
, NULL
)) dest
[wParam
-1] = 0;
858 result
= strlen( dest
);
861 WIN_ReleasePtr( wndPtr
);
866 DEFWND_SetTextA( hwnd
, (LPCSTR
)lParam
);
867 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
868 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
869 result
= 1; /* success. FIXME: check text length */
872 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
875 CHAR chChar1
= (CHAR
)( (wParam
>>8) & 0xff );
876 CHAR chChar2
= (CHAR
)( wParam
& 0xff );
879 SendMessageA( hwnd
, WM_CHAR
, (WPARAM
)chChar1
, lParam
);
880 SendMessageA( hwnd
, WM_CHAR
, (WPARAM
)chChar2
, lParam
);
884 result
= SendMessageA( hwnd
, WM_KEYDOWN
, wParam
, lParam
);
887 result
= SendMessageA( hwnd
, WM_KEYUP
, wParam
, lParam
);
890 case WM_IME_STARTCOMPOSITION
:
891 case WM_IME_COMPOSITION
:
892 case WM_IME_ENDCOMPOSITION
:
897 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
899 result
= SendMessageA( hwndIME
, msg
, wParam
, lParam
);
902 case WM_IME_SETCONTEXT
:
906 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
908 result
= DEFWND_ImmIsUIMessageA( hwndIME
, msg
, wParam
, lParam
);
912 case WM_INPUTLANGCHANGEREQUEST
:
913 /* notify about the switch only if it's really our current layout */
914 if ((HKL
)lParam
== GetKeyboardLayout(0))
915 result
= SendMessageA( hwnd
, WM_INPUTLANGCHANGE
, wParam
, lParam
);
922 BYTE ch
= LOWORD(wParam
);
924 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
925 wParam
= MAKEWPARAM( wch
, HIWORD(wParam
) );
929 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
933 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);
938 /***********************************************************************
939 * DefWindowProcW (USER32.@) Calls default window message handler
941 * Calls default window procedure for messages not processed
945 * Return value is dependent upon the message.
947 LRESULT WINAPI
DefWindowProcW(
948 HWND hwnd
, /* [in] window procedure receiving message */
949 UINT msg
, /* [in] message identifier */
950 WPARAM wParam
, /* [in] first message parameter */
951 LPARAM lParam
) /* [in] second message parameter */
956 if (!(full_handle
= WIN_IsCurrentProcess( hwnd
)))
958 if (!IsWindow( hwnd
)) return 0;
959 ERR( "called for other process window %p\n", hwnd
);
963 SPY_EnterMessage( SPY_DEFWNDPROC
, hwnd
, msg
, wParam
, lParam
);
969 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
970 /* check for string, as static icons, bitmaps (SS_ICON, SS_BITMAP)
971 * may have child window IDs instead of window name */
972 if (HIWORD(cs
->lpszName
))
973 DEFWND_SetTextW( hwnd
, cs
->lpszName
);
979 result
= NC_HandleNCCalcSize( hwnd
, (RECT
*)lParam
);
982 case WM_WINDOWPOSCHANGING
:
983 result
= WINPOS_HandleWindowPosChanging( hwnd
, (WINDOWPOS
*)lParam
);
986 case WM_WINDOWPOSCHANGED
:
988 WINDOWPOS
* winPos
= (WINDOWPOS
*)lParam
;
989 DEFWND_HandleWindowPosChanged( hwnd
, winPos
->flags
);
993 case WM_GETTEXTLENGTH
:
995 WND
*wndPtr
= WIN_GetPtr( hwnd
);
996 if (wndPtr
&& wndPtr
->text
) result
= (LRESULT
)strlenW(wndPtr
->text
);
997 WIN_ReleasePtr( wndPtr
);
1004 LPWSTR dest
= (LPWSTR
)lParam
;
1005 WND
*wndPtr
= WIN_GetPtr( hwnd
);
1010 lstrcpynW( dest
, wndPtr
->text
, wParam
);
1011 result
= strlenW( dest
);
1013 else dest
[0] = '\0';
1014 WIN_ReleasePtr( wndPtr
);
1019 DEFWND_SetTextW( hwnd
, (LPCWSTR
)lParam
);
1020 if( (GetWindowLongW( hwnd
, GWL_STYLE
) & WS_CAPTION
) == WS_CAPTION
)
1021 NC_HandleNCPaint( hwnd
, (HRGN
)1 ); /* Repaint caption */
1022 result
= 1; /* success. FIXME: check text length */
1025 /* for far east users (IMM32) - <hidenori@a2.ctktv.ne.jp> */
1027 SendMessageW( hwnd
, WM_CHAR
, wParam
, lParam
);
1029 case WM_IME_SETCONTEXT
:
1033 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
1035 result
= DEFWND_ImmIsUIMessageW( hwndIME
, msg
, wParam
, lParam
);
1039 case WM_IME_STARTCOMPOSITION
:
1040 case WM_IME_COMPOSITION
:
1041 case WM_IME_ENDCOMPOSITION
:
1046 hwndIME
= DEFWND_ImmGetDefaultIMEWnd( hwnd
);
1048 result
= SendMessageW( hwndIME
, msg
, wParam
, lParam
);
1052 case WM_INPUTLANGCHANGEREQUEST
:
1053 /* notify about the switch only if it's really our current layout */
1054 if ((HKL
)lParam
== GetKeyboardLayout(0))
1055 result
= SendMessageW( hwnd
, WM_INPUTLANGCHANGE
, wParam
, lParam
);
1061 result
= DEFWND_DefWinProc( hwnd
, msg
, wParam
, lParam
);
1064 SPY_ExitMessage( SPY_RESULT_DEFWND
, hwnd
, msg
, result
, wParam
, lParam
);