2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 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 "wine/winbase16.h"
34 #include "wine/winuser16.h"
38 #include "user_private.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DECLARE_DEBUG_CHANNEL(msg);
45 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 WINE_DEFAULT_DEBUG_CHANNEL(win);
48 typedef struct tagWINDOWPROC
50 WNDPROC16 proc16; /* 16-bit window proc */
51 WNDPROC procA; /* ASCII window proc */
52 WNDPROC procW; /* Unicode window proc */
55 #define WINPROC_HANDLE (~0UL >> 16)
56 #define MAX_WINPROCS 8192
58 static WINDOWPROC winproc_array[MAX_WINPROCS];
59 static UINT winproc_used;
61 static CRITICAL_SECTION winproc_cs;
62 static CRITICAL_SECTION_DEBUG critsect_debug =
65 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
66 0, 0, { (DWORD_PTR)(__FILE__ ": winproc_cs") }
68 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
70 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
72 if (size >= need) return static_buffer;
73 return HeapAlloc( GetProcessHeap(), 0, need );
76 static inline void free_buffer( void *static_buffer, void *buffer )
78 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
81 /* find an existing winproc for a given 16-bit function and type */
82 /* FIXME: probably should do something more clever than a linear search */
83 static inline WINDOWPROC *find_winproc16( WNDPROC16 func )
87 for (i = 0; i < winproc_used; i++)
89 if (winproc_array[i].proc16 == func) return &winproc_array[i];
94 /* find an existing winproc for a given function and type */
95 /* FIXME: probably should do something more clever than a linear search */
96 static inline WINDOWPROC *find_winproc( WNDPROC funcA, WNDPROC funcW )
100 for (i = 0; i < winproc_used; i++)
102 if (funcA && winproc_array[i].procA != funcA) continue;
103 if (funcW && winproc_array[i].procW != funcW) continue;
104 return &winproc_array[i];
109 /* return the window proc for a given handle, or NULL for an invalid handle */
110 static inline WINDOWPROC *handle_to_proc( WNDPROC handle )
112 UINT index = LOWORD(handle);
113 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return NULL;
114 if (index >= winproc_used) return NULL;
115 return &winproc_array[index];
118 /* create a handle for a given window proc */
119 static inline WNDPROC proc_to_handle( WINDOWPROC *proc )
121 return (WNDPROC)(ULONG_PTR)((proc - winproc_array) | (WINPROC_HANDLE << 16));
124 /* allocate and initialize a new winproc */
125 static inline WINDOWPROC *alloc_winproc( WNDPROC funcA, WNDPROC funcW )
129 /* check if the function is already a win proc */
130 if (funcA && (proc = handle_to_proc( funcA ))) return proc;
131 if (funcW && (proc = handle_to_proc( funcW ))) return proc;
132 if (!funcA && !funcW) return NULL;
134 EnterCriticalSection( &winproc_cs );
136 /* check if we already have a winproc for that function */
137 if (!(proc = find_winproc( funcA, funcW )))
139 if (winproc_used < MAX_WINPROCS)
141 proc = &winproc_array[winproc_used++];
144 TRACE( "allocated %p for %p/%p (%d/%d used)\n",
145 proc_to_handle(proc), funcA, funcW, winproc_used, MAX_WINPROCS );
147 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA, funcW );
149 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc), funcA, funcW );
151 LeaveCriticalSection( &winproc_cs );
158 #include "pshpack1.h"
160 /* Window procedure 16-to-32-bit thunk */
163 BYTE popl_eax; /* popl %eax (return address) */
164 BYTE pushl_func; /* pushl $proc */
166 BYTE pushl_eax; /* pushl %eax */
167 BYTE ljmp; /* ljmp relay*/
168 DWORD relay_offset; /* __wine_call_wndproc */
174 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
176 static WINPROC_THUNK *thunk_array;
177 static UINT thunk_selector;
178 static UINT thunk_used;
180 /* return the window proc for a given handle, or NULL for an invalid handle */
181 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
183 if (HIWORD(handle) == thunk_selector)
185 UINT index = LOWORD(handle) / sizeof(WINPROC_THUNK);
186 /* check alignment */
187 if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return NULL;
188 /* check array limits */
189 if (index >= thunk_used) return NULL;
190 return thunk_array[index].proc;
192 return handle_to_proc( (WNDPROC)handle );
195 /* allocate a 16-bit thunk for an existing window proc */
196 static WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
198 static FARPROC16 relay;
201 if (proc->proc16) return proc->proc16;
203 EnterCriticalSection( &winproc_cs );
205 if (!thunk_array) /* allocate the array and its selector */
209 if (!(thunk_selector = wine_ldt_alloc_entries(1))) goto done;
210 if (!(thunk_array = VirtualAlloc( NULL, MAX_THUNKS * sizeof(WINPROC_THUNK), MEM_COMMIT,
211 PAGE_EXECUTE_READWRITE ))) goto done;
212 wine_ldt_set_base( &entry, thunk_array );
213 wine_ldt_set_limit( &entry, MAX_THUNKS * sizeof(WINPROC_THUNK) - 1 );
214 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
215 wine_ldt_set_entry( thunk_selector, &entry );
216 relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
219 /* check if it already exists */
220 for (i = 0; i < thunk_used; i++) if (thunk_array[i].proc == proc) break;
222 if (i == thunk_used) /* create a new one */
224 WINPROC_THUNK *thunk;
226 if (thunk_used >= MAX_THUNKS) goto done;
227 thunk = &thunk_array[thunk_used++];
228 thunk->popl_eax = 0x58; /* popl %eax */
229 thunk->pushl_func = 0x68; /* pushl $proc */
231 thunk->pushl_eax = 0x50; /* pushl %eax */
232 thunk->ljmp = 0xea; /* ljmp relay*/
233 thunk->relay_offset = OFFSETOF(relay);
234 thunk->relay_sel = SELECTOROF(relay);
236 proc->proc16 = (WNDPROC16)MAKESEGPTR( thunk_selector, i * sizeof(WINPROC_THUNK) );
238 LeaveCriticalSection( &winproc_cs );
244 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
246 return handle_to_proc( (WNDPROC)handle );
249 static inline WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
254 #endif /* __i386__ */
258 /* Some window procedures modify register they shouldn't, or are not
259 * properly declared stdcall; so we need a small assembly wrapper to
261 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
262 WPARAM wParam, LPARAM lParam );
263 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
274 "movl 8(%ebp),%eax\n\t"
276 "leal -12(%ebp),%esp\n\t"
283 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
284 WPARAM wParam, LPARAM lParam )
286 return proc( hwnd, msg, wParam, lParam );
288 #endif /* __i386__ */
290 static void RECT16to32( const RECT16 *from, RECT *to )
292 to->left = from->left;
294 to->right = from->right;
295 to->bottom = from->bottom;
298 static void RECT32to16( const RECT *from, RECT16 *to )
300 to->left = from->left;
302 to->right = from->right;
303 to->bottom = from->bottom;
306 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
308 to->ptReserved.x = from->ptReserved.x;
309 to->ptReserved.y = from->ptReserved.y;
310 to->ptMaxSize.x = from->ptMaxSize.x;
311 to->ptMaxSize.y = from->ptMaxSize.y;
312 to->ptMaxPosition.x = from->ptMaxPosition.x;
313 to->ptMaxPosition.y = from->ptMaxPosition.y;
314 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
315 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
316 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
317 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
320 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
322 to->ptReserved.x = from->ptReserved.x;
323 to->ptReserved.y = from->ptReserved.y;
324 to->ptMaxSize.x = from->ptMaxSize.x;
325 to->ptMaxSize.y = from->ptMaxSize.y;
326 to->ptMaxPosition.x = from->ptMaxPosition.x;
327 to->ptMaxPosition.y = from->ptMaxPosition.y;
328 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
329 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
330 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
331 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
334 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
336 to->hwnd = HWND_16(from->hwnd);
337 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
342 to->flags = from->flags;
345 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
347 to->hwnd = WIN_Handle32(from->hwnd);
348 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
349 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
354 to->flags = from->flags;
357 /* The strings are not copied */
358 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
360 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
361 to->hInstance = HINSTANCE_16(from->hInstance);
362 to->hMenu = HMENU_16(from->hMenu);
363 to->hwndParent = HWND_16(from->hwndParent);
368 to->style = from->style;
369 to->dwExStyle = from->dwExStyle;
372 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
375 to->lpCreateParams = (LPVOID)from->lpCreateParams;
376 to->hInstance = HINSTANCE_32(from->hInstance);
377 to->hMenu = HMENU_32(from->hMenu);
378 to->hwndParent = WIN_Handle32(from->hwndParent);
383 to->style = from->style;
384 to->dwExStyle = from->dwExStyle;
385 to->lpszName = MapSL(from->lpszName);
386 to->lpszClass = MapSL(from->lpszClass);
389 /* The strings are not copied */
390 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
392 to->hOwner = HINSTANCE_16(from->hOwner);
397 to->style = from->style;
398 to->lParam = from->lParam;
401 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
403 to->hOwner = HINSTANCE_32(from->hOwner);
408 to->style = from->style;
409 to->lParam = from->lParam;
410 to->szTitle = MapSL(from->szTitle);
411 to->szClass = MapSL(from->szClass);
414 static WPARAM map_wparam_char_AtoW( WPARAM wParam, DWORD len )
419 ch[0] = (wParam >> 8);
420 ch[1] = wParam & 0xff;
421 if (len > 1 && ch[0])
422 RtlMultiByteToUnicodeN( &wch, sizeof(wch), NULL, ch, 2 );
424 RtlMultiByteToUnicodeN( &wch, sizeof(wch), NULL, ch + 1, 1 );
425 return MAKEWPARAM( wch, HIWORD(wParam) );
428 static WPARAM map_wparam_char_WtoA( WPARAM wParam, DWORD len )
433 RtlUnicodeToMultiByteN( (LPSTR)ch, len, &len, &wch, sizeof(wch) );
435 return MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wParam) );
437 return MAKEWPARAM( ch[0], HIWORD(wParam) );
440 /* call a 32-bit window procedure */
441 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
447 hwnd = WIN_GetFullHandle( hwnd );
449 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
450 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
452 *result = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
455 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
456 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, *result );
460 /* call a 32-bit dialog procedure */
461 static LRESULT call_dialog_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
468 hwnd = WIN_GetFullHandle( hwnd );
470 DPRINTF( "%04lx:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
471 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
473 ret = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
474 *result = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
477 DPRINTF( "%04lx:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx result=%08lx\n",
478 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, ret, *result );
482 /* call a 16-bit window procedure */
483 static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
484 LRESULT *result, void *arg )
486 WNDPROC16 proc = arg;
495 DRAWITEMSTRUCT16 dis16;
496 COMPAREITEMSTRUCT16 cis16;
502 /* Window procedures want ax = hInstance, ds = es = ss */
504 memset(&context, 0, sizeof(context));
505 context.SegDs = context.SegEs = SELECTOROF(NtCurrentTeb()->WOW32Reserved);
506 context.SegFs = wine_get_fs();
507 context.SegGs = wine_get_gs();
508 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
509 context.SegCs = SELECTOROF(proc);
510 context.Eip = OFFSETOF(proc);
511 context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + (WORD)&((STACK16FRAME*)0)->bp;
515 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
516 work if structures passed in lParam are placed in the stack/data
517 segment. Programmers easily make the mistake of converting lParam
518 to a near rather than a far pointer, since Windows apparently
519 allows this. We copy the structures to the 16 bit stack; this is
520 ugly but makes these programs work. */
525 size = sizeof(CREATESTRUCT16); break;
527 size = sizeof(DRAWITEMSTRUCT16); break;
529 size = sizeof(COMPAREITEMSTRUCT16); break;
533 memcpy( &args.u, MapSL(lParam), size );
534 lParam = (SEGPTR)NtCurrentTeb()->WOW32Reserved - size;
538 args.params[4] = hwnd;
539 args.params[3] = msg;
540 args.params[2] = wParam;
541 args.params[1] = HIWORD(lParam);
542 args.params[0] = LOWORD(lParam);
543 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
544 *result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
548 /* call a 16-bit dialog procedure */
549 static LRESULT call_dialog_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
550 LRESULT *result, void *arg )
552 LRESULT ret = call_window_proc16( hwnd, msg, wp, lp, result, arg );
553 *result = GetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT );
557 /* helper callback for 32W->16 conversion */
558 static LRESULT call_window_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
559 LRESULT *result, void *arg )
561 return WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wp, lp, result, arg );
564 /* helper callback for 32W->16 conversion */
565 static LRESULT call_dialog_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
566 LRESULT *result, void *arg )
568 return WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wp, lp, result, arg );
571 /* helper callback for 16->32W conversion */
572 static LRESULT call_window_proc_AtoW( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
573 LRESULT *result, void *arg )
575 return WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wp, lp, result, arg );
578 /* helper callback for 16->32W conversion */
579 static LRESULT call_dialog_proc_AtoW( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
580 LRESULT *result, void *arg )
582 return WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wp, lp, result, arg );
586 /**********************************************************************
589 * Get a window procedure pointer that can be passed to the Windows program.
591 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
595 if (unicode) ptr = alloc_winproc( NULL, proc );
596 else ptr = alloc_winproc( proc, NULL );
599 return alloc_win16_thunk( ptr );
603 /**********************************************************************
606 * Get a window procedure pointer that can be passed to the Windows program.
608 WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode )
610 WINDOWPROC *ptr = handle_to_proc( proc );
612 if (!ptr) return proc;
615 if (ptr->procW) return ptr->procW;
620 if (ptr->procA) return ptr->procA;
626 /**********************************************************************
627 * WINPROC_AllocProc16
629 * Allocate a window procedure for a window or class.
631 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
632 * lot of windows, it will usually only have a limited number of window procedures, so the
633 * array won't grow too large, and this way we avoid the need to track allocations per window.
635 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
639 if (!func) return NULL;
641 /* check if the function is already a win proc */
642 if (!(proc = handle16_to_proc( func )))
644 EnterCriticalSection( &winproc_cs );
646 /* then check if we already have a winproc for that function */
647 if (!(proc = find_winproc16( func )))
649 if (winproc_used < MAX_WINPROCS)
651 proc = &winproc_array[winproc_used++];
653 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
654 proc_to_handle(proc), func, winproc_used, MAX_WINPROCS );
656 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
658 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc), func );
660 LeaveCriticalSection( &winproc_cs );
662 return proc_to_handle( proc );
666 /**********************************************************************
669 * Allocate a window procedure for a window or class.
671 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
672 * lot of windows, it will usually only have a limited number of window procedures, so the
673 * array won't grow too large, and this way we avoid the need to track allocations per window.
675 WNDPROC WINPROC_AllocProc( WNDPROC funcA, WNDPROC funcW )
679 if (!(proc = alloc_winproc( funcA, funcW ))) return NULL;
680 return proc_to_handle( proc );
684 /**********************************************************************
687 * Return the window procedure type, or the default value if not a winproc handle.
689 BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val )
691 WINDOWPROC *ptr = handle_to_proc( proc );
693 if (!ptr) return def_val;
694 if (ptr->procA && ptr->procW) return def_val; /* can be both */
695 return (ptr->procW != NULL);
699 /**********************************************************************
700 * WINPROC_TestLBForStr
702 * Return TRUE if the lparam is a string
704 inline static BOOL WINPROC_TestLBForStr( HWND hwnd, UINT msg )
706 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
707 if (msg <= CB_MSGMAX)
708 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
710 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
715 static UINT convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
718 UINT sz = GlobalSize16(src);
721 if (!(dst = GlobalAlloc(flags, sz)))
723 ptr16 = GlobalLock16(src);
724 ptr32 = GlobalLock(dst);
725 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
732 static HANDLE16 convert_handle_32_to_16(UINT src, unsigned int flags)
735 UINT sz = GlobalSize((HANDLE)src);
738 if (!(dst = GlobalAlloc16(flags, sz)))
740 ptr32 = GlobalLock((HANDLE)src);
741 ptr16 = GlobalLock16(dst);
742 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
743 GlobalUnlock((HANDLE)src);
750 /**********************************************************************
751 * WINPROC_MapMsg32ATo16
753 * Map a message from 32-bit Ansi to 16-bit.
754 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
756 static INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
757 UINT16 *pmsg16, WPARAM16 *pwparam16, LPARAM *plparam )
759 *pmsg16 = (UINT16)msg32;
760 *pwparam16 = (WPARAM16)LOWORD(wParam32);
767 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
771 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
773 case WM_CTLCOLORMSGBOX:
774 case WM_CTLCOLOREDIT:
775 case WM_CTLCOLORLISTBOX:
778 case WM_CTLCOLORSCROLLBAR:
779 case WM_CTLCOLORSTATIC:
780 *pmsg16 = WM_CTLCOLOR;
781 *plparam = MAKELPARAM( (HWND16)*plparam,
782 (WORD)msg32 - WM_CTLCOLORMSGBOX );
785 if(HIWORD(wParam32) & MF_POPUP)
788 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
790 if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
791 *pwparam16=HMENU_16(hmenu);
796 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
798 case WM_PARENTNOTIFY:
799 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
800 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
801 /* else nothing to do */
804 if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
807 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
809 *pmsg16 = WM_PAINTICON;
814 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
815 *pmsg16 = WM_ICONERASEBKGND;
817 case WM_PAINTCLIPBOARD:
818 case WM_SIZECLIPBOARD:
819 FIXME_(msg)("message %04x needs translation\n", msg32 );
821 /* following messages should not be sent to 16-bit apps */
824 case WM_CAPTURECHANGED:
825 case WM_STYLECHANGING:
826 case WM_STYLECHANGED:
828 default: /* No translation needed */
834 /**********************************************************************
835 * WINPROC_CallProcAtoW
837 * Call a window procedure, translating args from Ansi to Unicode.
839 LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
840 LPARAM lParam, LRESULT *result, void *arg )
844 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
845 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
852 WCHAR *ptr, buffer[512];
853 CREATESTRUCTA *csA = (CREATESTRUCTA *)lParam;
854 CREATESTRUCTW csW = *(CREATESTRUCTW *)csA;
855 MDICREATESTRUCTW mdi_cs;
856 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
858 if (HIWORD(csA->lpszClass))
860 class_lenA = strlen(csA->lpszClass) + 1;
861 RtlMultiByteToUnicodeSize( &class_lenW, csA->lpszClass, class_lenA );
863 if (HIWORD(csA->lpszName))
865 name_lenA = strlen(csA->lpszName) + 1;
866 RtlMultiByteToUnicodeSize( &name_lenW, csA->lpszName, name_lenA );
869 if (!(ptr = get_buffer( buffer, sizeof(buffer), class_lenW + name_lenW ))) break;
874 RtlMultiByteToUnicodeN( ptr, class_lenW, NULL, csA->lpszClass, class_lenA );
878 csW.lpszName = ptr + class_lenW/sizeof(WCHAR);
879 RtlMultiByteToUnicodeN( ptr + class_lenW/sizeof(WCHAR), name_lenW, NULL,
880 csA->lpszName, name_lenA );
883 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
885 mdi_cs = *(MDICREATESTRUCTW *)csA->lpCreateParams;
886 mdi_cs.szTitle = csW.lpszName;
887 mdi_cs.szClass = csW.lpszClass;
888 csW.lpCreateParams = &mdi_cs;
891 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
892 free_buffer( buffer, ptr );
898 WCHAR *ptr, buffer[512];
899 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
900 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
901 MDICREATESTRUCTW csW;
903 memcpy( &csW, csA, sizeof(csW) );
905 if (HIWORD(csA->szTitle))
907 title_lenA = strlen(csA->szTitle) + 1;
908 RtlMultiByteToUnicodeSize( &title_lenW, csA->szTitle, title_lenA );
910 if (HIWORD(csA->szClass))
912 class_lenA = strlen(csA->szClass) + 1;
913 RtlMultiByteToUnicodeSize( &class_lenW, csA->szClass, class_lenA );
916 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenW + class_lenW ))) break;
921 RtlMultiByteToUnicodeN( ptr, title_lenW, NULL, csA->szTitle, title_lenA );
925 csW.szClass = ptr + title_lenW/sizeof(WCHAR);
926 RtlMultiByteToUnicodeN( ptr + title_lenW/sizeof(WCHAR), class_lenW, NULL,
927 csA->szClass, class_lenA );
929 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
930 free_buffer( buffer, ptr );
935 case WM_ASKCBFORMATNAME:
937 WCHAR *ptr, buffer[512];
938 LPSTR str = (LPSTR)lParam;
939 DWORD len = wParam * sizeof(WCHAR);
941 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
942 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
943 if (*result && wParam)
945 RtlUnicodeToMultiByteN( str, wParam - 1, &len, ptr, strlenW(ptr) * sizeof(WCHAR) );
949 free_buffer( buffer, ptr );
954 case LB_INSERTSTRING:
956 case LB_FINDSTRINGEXACT:
957 case LB_SELECTSTRING:
959 case CB_INSERTSTRING:
961 case CB_FINDSTRINGEXACT:
962 case CB_SELECTSTRING:
963 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
965 ret = callback( hwnd, msg, wParam, lParam, result, arg );
970 case WM_WININICHANGE:
971 case WM_DEVMODECHANGE:
976 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
979 WCHAR *ptr, buffer[512];
980 LPCSTR strA = (LPCSTR)lParam;
981 DWORD lenW, lenA = strlen(strA) + 1;
983 RtlMultiByteToUnicodeSize( &lenW, strA, lenA );
984 if ((ptr = get_buffer( buffer, sizeof(buffer), lenW )))
986 RtlMultiByteToUnicodeN( ptr, lenW, NULL, strA, lenA );
987 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
988 free_buffer( buffer, ptr );
995 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
997 WCHAR buffer[512]; /* FIXME: fixed sized buffer */
999 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1003 RtlUnicodeToMultiByteN( (LPSTR)lParam, ~0u, &len,
1004 buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
1008 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1013 WCHAR *ptr, buffer[512];
1014 WORD len = *(WORD *)lParam;
1016 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
1017 *((WORD *)ptr) = len; /* store the length */
1018 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1022 RtlUnicodeToMultiByteN( (LPSTR)lParam, len, &reslen, ptr, *result * sizeof(WCHAR) );
1023 if (reslen < len) ((LPSTR)lParam)[reslen] = 0;
1026 free_buffer( buffer, ptr );
1033 MSG newmsg = *(MSG *)lParam;
1034 switch(newmsg.message)
1039 case WM_SYSDEADCHAR:
1040 newmsg.wParam = map_wparam_char_AtoW( newmsg.wParam, 1 );
1043 newmsg.wParam = map_wparam_char_AtoW( newmsg.wParam, 2 );
1046 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1048 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1056 case WM_SYSDEADCHAR:
1057 case EM_SETPASSWORDCHAR:
1058 ret = callback( hwnd, msg, map_wparam_char_AtoW(wParam,1), lParam, result, arg );
1062 ret = callback( hwnd, msg, map_wparam_char_AtoW(wParam,2), lParam, result, arg );
1065 case WM_GETTEXTLENGTH:
1066 case CB_GETLBTEXTLEN:
1068 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1071 WCHAR *ptr, buffer[512];
1073 DWORD len = *result + 1;
1074 /* Determine respective GETTEXT message */
1075 UINT msgGetText = (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
1076 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
1077 /* wParam differs between the messages */
1078 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? len : wParam;
1080 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
1082 if (callback == call_window_proc) /* FIXME: hack */
1083 callback( hwnd, msgGetText, wp, (LPARAM)ptr, &tmp, arg );
1085 tmp = SendMessageW( hwnd, msgGetText, wp, (LPARAM)ptr );
1086 RtlUnicodeToMultiByteSize( &len, ptr, tmp * sizeof(WCHAR) );
1088 free_buffer( buffer, ptr );
1092 case WM_PAINTCLIPBOARD:
1093 case WM_SIZECLIPBOARD:
1094 FIXME_(msg)( "message %s (0x%x) needs translation, please report\n",
1095 SPY_GetMsgName(msg, hwnd), msg );
1099 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1106 /**********************************************************************
1107 * WINPROC_CallProcWtoA
1109 * Call a window procedure, translating args from Unicode to Ansi.
1111 static LRESULT WINPROC_CallProcWtoA( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
1112 LPARAM lParam, LRESULT *result, void *arg )
1116 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1117 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1123 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
1126 char buffer[1024], *cls, *name;
1127 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
1128 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
1129 MDICREATESTRUCTA mdi_cs;
1130 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
1132 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
1133 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
1137 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
1138 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
1141 name_lenW = name_lenA = 0;
1143 if (!(cls = get_buffer( buffer, sizeof(buffer), class_lenA + name_lenA + 2 ))) break;
1145 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
1146 cls[class_lenA] = 0;
1147 csA.lpszClass = cls;
1151 name = cls + class_lenA + 1;
1152 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
1153 name[name_lenA] = 0;
1154 csA.lpszName = name;
1157 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1159 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
1160 mdi_cs.szTitle = csA.lpszName;
1161 mdi_cs.szClass = csA.lpszClass;
1162 csA.lpCreateParams = &mdi_cs;
1165 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1166 free_buffer( buffer, cls );
1171 case WM_ASKCBFORMATNAME:
1173 char *ptr, buffer[512];
1174 DWORD len = wParam * 2;
1176 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
1177 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1180 RtlMultiByteToUnicodeN( (LPWSTR)lParam, wParam*sizeof(WCHAR), &len, ptr, strlen(ptr)+1 );
1181 *result = len/sizeof(WCHAR) - 1; /* do not count terminating null */
1182 ((LPWSTR)lParam)[*result] = 0;
1184 free_buffer( buffer, ptr );
1189 case LB_INSERTSTRING:
1191 case LB_FINDSTRINGEXACT:
1192 case LB_SELECTSTRING:
1194 case CB_INSERTSTRING:
1196 case CB_FINDSTRINGEXACT:
1197 case CB_SELECTSTRING:
1198 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
1200 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1205 case WM_WININICHANGE:
1206 case WM_DEVMODECHANGE:
1211 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
1214 char *ptr, buffer[512];
1215 LPCWSTR strW = (LPCWSTR)lParam;
1216 DWORD lenA, lenW = (strlenW(strW) + 1) * sizeof(WCHAR);
1218 RtlUnicodeToMultiByteSize( &lenA, strW, lenW );
1219 if ((ptr = get_buffer( buffer, sizeof(buffer), lenA )))
1221 RtlUnicodeToMultiByteN( ptr, lenA, NULL, strW, lenW );
1222 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1223 free_buffer( buffer, ptr );
1230 char *ptr, buffer[1024];
1231 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
1232 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1233 MDICREATESTRUCTA csA;
1235 memcpy( &csA, csW, sizeof(csA) );
1237 if (HIWORD(csW->szTitle))
1239 title_lenW = (strlenW(csW->szTitle) + 1) * sizeof(WCHAR);
1240 RtlUnicodeToMultiByteSize( &title_lenA, csW->szTitle, title_lenW );
1242 if (HIWORD(csW->szClass))
1244 class_lenW = (strlenW(csW->szClass) + 1) * sizeof(WCHAR);
1245 RtlUnicodeToMultiByteSize( &class_lenA, csW->szClass, class_lenW );
1248 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenA + class_lenA ))) break;
1252 RtlUnicodeToMultiByteN( ptr, title_lenA, NULL, csW->szTitle, title_lenW );
1257 RtlUnicodeToMultiByteN( ptr + title_lenA, class_lenA, NULL, csW->szClass, class_lenW );
1258 csA.szClass = ptr + title_lenA;
1260 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1261 free_buffer( buffer, ptr );
1267 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
1269 char buffer[512]; /* FIXME: fixed sized buffer */
1271 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1275 RtlMultiByteToUnicodeN( (LPWSTR)lParam, ~0u, &len, buffer, strlen(buffer) + 1 );
1276 *result = len / sizeof(WCHAR) - 1;
1279 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1284 char *ptr, buffer[512];
1285 WORD len = *(WORD *)lParam;
1287 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * 2 ))) break;
1288 *((WORD *)ptr) = len * 2; /* store the length */
1289 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1293 RtlMultiByteToUnicodeN( (LPWSTR)lParam, len*sizeof(WCHAR), &reslen, ptr, *result );
1294 *result = reslen / sizeof(WCHAR);
1295 if (*result < len) ((LPWSTR)lParam)[*result] = 0;
1297 free_buffer( buffer, ptr );
1304 MSG newmsg = *(MSG *)lParam;
1305 switch(newmsg.message)
1310 case WM_SYSDEADCHAR:
1311 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 1 );
1314 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 2 );
1317 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1319 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1327 case WM_SYSDEADCHAR:
1328 case EM_SETPASSWORDCHAR:
1329 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,1), lParam, result, arg );
1333 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,2), lParam, result, arg );
1336 case WM_PAINTCLIPBOARD:
1337 case WM_SIZECLIPBOARD:
1338 FIXME_(msg)( "message %s (%04x) needs translation, please report\n",
1339 SPY_GetMsgName(msg, hwnd), msg );
1343 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1351 /**********************************************************************
1352 * WINPROC_CallProc16To32A
1354 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
1355 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
1358 HWND hwnd32 = WIN_Handle32( hwnd );
1360 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1361 hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
1368 CREATESTRUCT16 *cs16 = MapSL(lParam);
1370 MDICREATESTRUCTA mdi_cs;
1372 CREATESTRUCT16to32A( cs16, &cs );
1373 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
1375 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
1376 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
1377 cs.lpCreateParams = &mdi_cs;
1379 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1380 CREATESTRUCT32Ato16( &cs, cs16 );
1385 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
1386 MDICREATESTRUCTA cs;
1388 MDICREATESTRUCT16to32A( cs16, &cs );
1389 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1390 MDICREATESTRUCT32Ato16( &cs, cs16 );
1393 case WM_MDIACTIVATE:
1395 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
1396 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1397 else /* message sent to MDI client */
1398 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1400 case WM_MDIGETACTIVE:
1402 BOOL maximized = FALSE;
1403 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
1404 *result = MAKELRESULT( LOWORD(*result), maximized );
1408 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
1409 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
1412 case WM_GETMINMAXINFO:
1414 MINMAXINFO16 *mmi16 = MapSL(lParam);
1417 MINMAXINFO16to32( mmi16, &mmi );
1418 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
1419 MINMAXINFO32to16( &mmi, mmi16 );
1422 case WM_WINDOWPOSCHANGING:
1423 case WM_WINDOWPOSCHANGED:
1425 WINDOWPOS16 *winpos16 = MapSL(lParam);
1428 WINDOWPOS16to32( winpos16, &winpos );
1429 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
1430 WINDOWPOS32to16( &winpos, winpos16 );
1435 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
1436 NCCALCSIZE_PARAMS nc;
1439 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
1442 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
1443 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
1444 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
1447 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
1448 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
1451 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
1452 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
1453 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
1457 case WM_COMPAREITEM:
1459 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
1460 COMPAREITEMSTRUCT cis;
1461 cis.CtlType = cis16->CtlType;
1462 cis.CtlID = cis16->CtlID;
1463 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
1464 cis.itemID1 = cis16->itemID1;
1465 cis.itemData1 = cis16->itemData1;
1466 cis.itemID2 = cis16->itemID2;
1467 cis.itemData2 = cis16->itemData2;
1468 cis.dwLocaleId = 0; /* FIXME */
1469 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
1474 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
1475 DELETEITEMSTRUCT dis;
1476 dis.CtlType = dis16->CtlType;
1477 dis.CtlID = dis16->CtlID;
1478 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
1479 dis.itemData = dis16->itemData;
1480 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1483 case WM_MEASUREITEM:
1485 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1486 MEASUREITEMSTRUCT mis;
1487 mis.CtlType = mis16->CtlType;
1488 mis.CtlID = mis16->CtlID;
1489 mis.itemID = mis16->itemID;
1490 mis.itemWidth = mis16->itemWidth;
1491 mis.itemHeight = mis16->itemHeight;
1492 mis.itemData = mis16->itemData;
1493 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
1494 mis16->itemWidth = (UINT16)mis.itemWidth;
1495 mis16->itemHeight = (UINT16)mis.itemHeight;
1500 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1502 dis.CtlType = dis16->CtlType;
1503 dis.CtlID = dis16->CtlID;
1504 dis.itemID = dis16->itemID;
1505 dis.itemAction = dis16->itemAction;
1506 dis.itemState = dis16->itemState;
1507 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1508 : WIN_Handle32( dis16->hwndItem );
1509 dis.hDC = HDC_32(dis16->hDC);
1510 dis.itemData = dis16->itemData;
1511 dis.rcItem.left = dis16->rcItem.left;
1512 dis.rcItem.top = dis16->rcItem.top;
1513 dis.rcItem.right = dis16->rcItem.right;
1514 dis.rcItem.bottom = dis16->rcItem.bottom;
1515 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1520 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
1522 cds.dwData = cds16->dwData;
1523 cds.cbData = cds16->cbData;
1524 cds.lpData = MapSL(cds16->lpData);
1525 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
1531 MSG16 *msg16 = MapSL(lParam);
1533 msg32.hwnd = WIN_Handle32( msg16->hwnd );
1534 msg32.message = msg16->message;
1535 msg32.wParam = msg16->wParam;
1536 msg32.lParam = msg16->lParam;
1537 msg32.time = msg16->time;
1538 msg32.pt.x = msg16->pt.x;
1539 msg32.pt.y = msg16->pt.y;
1540 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
1543 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1548 next.hmenuIn = (HMENU)lParam;
1551 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
1552 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
1559 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1560 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1564 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1565 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
1568 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
1569 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
1570 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
1575 case WM_WININICHANGE:
1576 case WM_DEVMODECHANGE:
1577 case WM_ASKCBFORMATNAME:
1579 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
1582 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1583 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1586 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
1588 HMENU hmenu = HMENU_32(HIWORD(lParam));
1589 UINT pos = MENU_FindSubMenu( &hmenu, HMENU_32(wParam) );
1590 if (pos == 0xffff) pos = 0; /* NO_SELECTED_ITEM */
1593 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1594 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1596 case WM_PARENTNOTIFY:
1597 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
1598 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1599 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1601 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1603 case WM_ACTIVATEAPP:
1604 /* We need this when SetActiveWindow sends a Sendmessage16() to
1605 * a 32bit window. Might be superflous with 32bit interprocess
1606 * message queues. */
1607 ret = callback( hwnd32, msg, wParam, HTASK_32(lParam), result, arg );
1609 case WM_DDE_INITIATE:
1610 case WM_DDE_TERMINATE:
1611 case WM_DDE_UNADVISE:
1612 case WM_DDE_REQUEST:
1613 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1619 HANDLE16 lo16 = LOWORD(lParam);
1621 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
1622 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
1623 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1625 break; /* FIXME don't know how to free allocated memory (handle) !! */
1628 UINT lo = LOWORD(lParam);
1629 UINT hi = HIWORD(lParam);
1633 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1634 if (GlobalSize16(hi) != 0) flag |= 2;
1640 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1645 break; /* atom, nothing to do */
1647 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1650 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1653 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
1654 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1656 break; /* FIXME don't know how to free allocated memory (handle) !! */
1657 case WM_DDE_EXECUTE:
1658 lParam = convert_handle_16_to_32( lParam, GMEM_DDESHARE );
1659 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1660 break; /* FIXME don't know how to free allocated memory (handle) !! */
1661 case WM_PAINTCLIPBOARD:
1662 case WM_SIZECLIPBOARD:
1663 FIXME_(msg)( "message %04x needs translation\n", msg );
1666 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1673 /**********************************************************************
1674 * __wine_call_wndproc (USER.1010)
1676 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
1682 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
1684 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
1689 /**********************************************************************
1690 * WINPROC_CallProc32ATo16
1692 * Call a 16-bit window procedure, translating the 32-bit args.
1694 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
1695 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
1699 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1700 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1707 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
1709 MDICREATESTRUCT16 mdi_cs16;
1710 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
1712 CREATESTRUCT32Ato16( cs32, &cs );
1713 cs.lpszName = MapLS( cs32->lpszName );
1714 cs.lpszClass = MapLS( cs32->lpszClass );
1718 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
1719 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
1720 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
1721 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
1722 cs.lpCreateParams = MapLS( &mdi_cs16 );
1724 lParam = MapLS( &cs );
1725 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1727 UnMapLS( cs.lpszName );
1728 UnMapLS( cs.lpszClass );
1731 UnMapLS( cs.lpCreateParams );
1732 UnMapLS( mdi_cs16.szTitle );
1733 UnMapLS( mdi_cs16.szClass );
1739 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
1740 MDICREATESTRUCT16 cs;
1742 MDICREATESTRUCT32Ato16( cs32, &cs );
1743 cs.szTitle = MapLS( cs32->szTitle );
1744 cs.szClass = MapLS( cs32->szClass );
1745 lParam = MapLS( &cs );
1746 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1748 UnMapLS( cs.szTitle );
1749 UnMapLS( cs.szClass );
1752 case WM_MDIACTIVATE:
1753 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1754 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
1755 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
1757 ret = callback( HWND_16(hwnd), msg, HWND_16( (HWND)wParam ), 0, result, arg );
1759 case WM_MDIGETACTIVE:
1760 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1761 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
1762 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
1765 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
1766 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
1768 case WM_GETMINMAXINFO:
1770 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
1773 MINMAXINFO32to16( mmi32, &mmi );
1774 lParam = MapLS( &mmi );
1775 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1777 MINMAXINFO16to32( &mmi, mmi32 );
1782 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
1783 NCCALCSIZE_PARAMS16 nc;
1786 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
1789 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
1790 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
1791 WINDOWPOS32to16( nc32->lppos, &winpos );
1792 nc.lppos = MapLS( &winpos );
1794 lParam = MapLS( &nc );
1795 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1797 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
1800 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
1801 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
1802 WINDOWPOS16to32( &winpos, nc32->lppos );
1803 UnMapLS( nc.lppos );
1807 case WM_WINDOWPOSCHANGING:
1808 case WM_WINDOWPOSCHANGED:
1810 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
1813 WINDOWPOS32to16( winpos32, &winpos );
1814 lParam = MapLS( &winpos );
1815 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1817 WINDOWPOS16to32( &winpos, winpos32 );
1820 case WM_COMPAREITEM:
1822 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
1823 COMPAREITEMSTRUCT16 cis;
1824 cis.CtlType = cis32->CtlType;
1825 cis.CtlID = cis32->CtlID;
1826 cis.hwndItem = HWND_16( cis32->hwndItem );
1827 cis.itemID1 = cis32->itemID1;
1828 cis.itemData1 = cis32->itemData1;
1829 cis.itemID2 = cis32->itemID2;
1830 cis.itemData2 = cis32->itemData2;
1831 lParam = MapLS( &cis );
1832 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1838 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
1839 DELETEITEMSTRUCT16 dis;
1840 dis.CtlType = dis32->CtlType;
1841 dis.CtlID = dis32->CtlID;
1842 dis.itemID = dis32->itemID;
1843 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1844 : HWND_16( dis32->hwndItem );
1845 dis.itemData = dis32->itemData;
1846 lParam = MapLS( &dis );
1847 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1853 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
1854 DRAWITEMSTRUCT16 dis;
1855 dis.CtlType = dis32->CtlType;
1856 dis.CtlID = dis32->CtlID;
1857 dis.itemID = dis32->itemID;
1858 dis.itemAction = dis32->itemAction;
1859 dis.itemState = dis32->itemState;
1860 dis.hwndItem = HWND_16( dis32->hwndItem );
1861 dis.hDC = HDC_16(dis32->hDC);
1862 dis.itemData = dis32->itemData;
1863 dis.rcItem.left = dis32->rcItem.left;
1864 dis.rcItem.top = dis32->rcItem.top;
1865 dis.rcItem.right = dis32->rcItem.right;
1866 dis.rcItem.bottom = dis32->rcItem.bottom;
1867 lParam = MapLS( &dis );
1868 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1872 case WM_MEASUREITEM:
1874 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
1875 MEASUREITEMSTRUCT16 mis;
1876 mis.CtlType = mis32->CtlType;
1877 mis.CtlID = mis32->CtlID;
1878 mis.itemID = mis32->itemID;
1879 mis.itemWidth = mis32->itemWidth;
1880 mis.itemHeight = mis32->itemHeight;
1881 mis.itemData = mis32->itemData;
1882 lParam = MapLS( &mis );
1883 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1885 mis32->itemWidth = mis.itemWidth;
1886 mis32->itemHeight = mis.itemHeight;
1891 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
1892 COPYDATASTRUCT16 cds;
1894 cds.dwData = cds32->dwData;
1895 cds.cbData = cds32->cbData;
1896 cds.lpData = MapLS( cds32->lpData );
1897 lParam = MapLS( &cds );
1898 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1900 UnMapLS( cds.lpData );
1906 MSG *msg32 = (MSG *)lParam;
1909 msg16.hwnd = HWND_16( msg32->hwnd );
1910 msg16.message = msg32->message;
1911 msg16.wParam = msg32->wParam;
1912 msg16.lParam = msg32->lParam;
1913 msg16.time = msg32->time;
1914 msg16.pt.x = msg32->pt.x;
1915 msg16.pt.y = msg32->pt.y;
1916 lParam = MapLS( &msg16 );
1917 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1921 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1925 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1926 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
1927 next->hmenuNext = HMENU_32( LOWORD(*result) );
1928 next->hwndNext = WIN_Handle32( HIWORD(*result) );
1933 case WM_ASKCBFORMATNAME:
1934 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
1938 case WM_WININICHANGE:
1939 case WM_DEVMODECHANGE:
1940 lParam = MapLS( (void *)lParam );
1941 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1944 case WM_DDE_INITIATE:
1945 case WM_DDE_TERMINATE:
1946 case WM_DDE_UNADVISE:
1947 case WM_DDE_REQUEST:
1948 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam), lParam, result, arg );
1957 UnpackDDElParam( msg, lParam, &lo32, &hi );
1958 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
1959 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
1960 MAKELPARAM(lo16, hi), result, arg );
1962 break; /* FIXME don't know how to free allocated memory (handle) !! */
1969 UnpackDDElParam( msg, lParam, &lo, &hi );
1971 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
1972 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
1978 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1983 break; /* atom, nothing to do */
1985 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1988 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
1991 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
1992 MAKELPARAM(lo, hi), result, arg );
1994 break; /* FIXME don't know how to free allocated memory (handle) !! */
1995 case WM_DDE_EXECUTE:
1996 lParam = convert_handle_32_to_16(lParam, GMEM_DDESHARE);
1997 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1998 break; /* FIXME don't know how to free allocated memory (handle) !! */
2000 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
2003 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
2004 *(LPINT)wParam = LOWORD(*result);
2005 *(LPINT)lParam = HIWORD(*result);
2012 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
2020 case EM_SCROLLCARET:
2023 case EM_GETLINECOUNT:
2035 case EM_LINEFROMCHAR:
2036 case EM_SETTABSTOPS:
2037 case EM_SETPASSWORDCHAR:
2038 case EM_EMPTYUNDOBUFFER:
2039 case EM_GETFIRSTVISIBLELINE:
2040 case EM_SETREADONLY:
2041 case EM_SETWORDBREAKPROC:
2042 case EM_GETWORDBREAKPROC:
2043 case EM_GETPASSWORDCHAR:
2044 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
2047 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
2051 case LB_DELETESTRING:
2052 case LB_GETANCHORINDEX:
2053 case LB_GETCARETINDEX:
2056 case LB_GETHORIZONTALEXTENT:
2057 case LB_GETITEMDATA:
2058 case LB_GETITEMHEIGHT:
2060 case LB_GETSELCOUNT:
2062 case LB_GETTOPINDEX:
2063 case LB_RESETCONTENT:
2064 case LB_SELITEMRANGE:
2065 case LB_SELITEMRANGEEX:
2066 case LB_SETANCHORINDEX:
2067 case LB_SETCARETINDEX:
2068 case LB_SETCOLUMNWIDTH:
2070 case LB_SETHORIZONTALEXTENT:
2071 case LB_SETITEMDATA:
2072 case LB_SETITEMHEIGHT:
2074 case LB_SETTOPINDEX:
2075 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
2079 case LB_FINDSTRINGEXACT:
2080 case LB_INSERTSTRING:
2081 case LB_SELECTSTRING:
2085 lParam = MapLS( (LPSTR)lParam );
2086 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
2089 case LB_GETSELITEMS:
2091 INT *items32 = (INT *)lParam;
2092 INT16 *items, buffer[512];
2095 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
2096 if (!(items = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
2097 lParam = MapLS( items );
2098 ret = callback( HWND_16(hwnd), LB_GETSELITEMS16, wParam, lParam, result, arg );
2100 for (i = 0; i < wParam; i++) items32[i] = items[i];
2101 free_buffer( buffer, items );
2104 case LB_SETTABSTOPS:
2107 INT *stops32 = (INT *)lParam;
2108 INT16 *stops, buffer[512];
2111 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
2112 if (!(stops = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
2113 for (i = 0; i < wParam; i++) stops[i] = stops32[i];
2114 lParam = MapLS( stops );
2115 ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
2117 free_buffer( buffer, stops );
2119 else ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
2121 case CB_DELETESTRING:
2123 case CB_GETLBTEXTLEN:
2125 case CB_RESETCONTENT:
2129 case CB_SHOWDROPDOWN:
2130 case CB_SETITEMDATA:
2131 case CB_SETITEMHEIGHT:
2132 case CB_GETITEMHEIGHT:
2133 case CB_SETEXTENDEDUI:
2134 case CB_GETEXTENDEDUI:
2135 case CB_GETDROPPEDSTATE:
2136 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
2139 ret = callback( HWND_16(hwnd), CB_GETEDITSEL16, wParam, lParam, result, arg );
2140 if (wParam) *((PUINT)(wParam)) = LOWORD(*result);
2141 if (lParam) *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: substract 1? */
2145 case CB_FINDSTRINGEXACT:
2146 case CB_INSERTSTRING:
2147 case CB_SELECTSTRING:
2150 lParam = MapLS( (LPSTR)lParam );
2151 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
2154 case LB_GETITEMRECT:
2155 case CB_GETDROPPEDCONTROLRECT:
2157 RECT *r32 = (RECT *)lParam;
2159 lParam = MapLS( &rect );
2160 ret = callback( HWND_16(hwnd),
2161 (msg == LB_GETITEMRECT) ? LB_GETITEMRECT16 : CB_GETDROPPEDCONTROLRECT16,
2162 wParam, lParam, result, arg );
2164 RECT16to32( &rect, r32 );
2171 LPARAM lParam16 = lParam;
2172 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &wParam16, &lParam16 ) != -1)
2174 ret = callback( HWND_16(hwnd), msg16, wParam16, lParam16, result, arg );
2183 /**********************************************************************
2184 * CallWindowProc (USER.122)
2186 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2187 WPARAM16 wParam, LPARAM lParam )
2192 if (!func) return 0;
2194 if (!(proc = handle16_to_proc( func )))
2195 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
2196 else if (proc->procA)
2197 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2198 else if (proc->procW)
2199 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
2201 call_window_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2207 /**********************************************************************
2208 * CallWindowProcA (USER32.@)
2210 * The CallWindowProc() function invokes the windows procedure _func_,
2211 * with _hwnd_ as the target window, the message specified by _msg_, and
2212 * the message parameters _wParam_ and _lParam_.
2214 * Some kinds of argument conversion may be done, I'm not sure what.
2216 * CallWindowProc() may be used for windows subclassing. Use
2217 * SetWindowLong() to set a new windows procedure for windows of the
2218 * subclass, and handle subclassed messages in the new windows
2219 * procedure. The new windows procedure may then use CallWindowProc()
2220 * with _func_ set to the parent class's windows procedure to dispatch
2221 * the message to the superclass.
2225 * The return value is message dependent.
2231 LRESULT WINAPI CallWindowProcA(
2232 WNDPROC func, /* [in] window procedure */
2233 HWND hwnd, /* [in] target window */
2234 UINT msg, /* [in] message */
2235 WPARAM wParam, /* [in] message dependent parameter */
2236 LPARAM lParam /* [in] message dependent parameter */
2241 if (!func) return 0;
2243 if (!(proc = handle_to_proc( func )))
2244 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2245 else if (proc->procA)
2246 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2247 else if (proc->procW)
2248 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procW );
2250 WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2255 /**********************************************************************
2256 * CallWindowProcW (USER32.@)
2258 * See CallWindowProcA.
2260 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2261 WPARAM wParam, LPARAM lParam )
2266 if (!func) return 0;
2268 if (!(proc = handle_to_proc( func )))
2269 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2270 else if (proc->procW)
2271 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2272 else if (proc->procA)
2273 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2275 WINPROC_CallProcWtoA( call_window_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2280 /**********************************************************************
2281 * WINPROC_CallDlgProc16
2283 INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
2289 if (!func) return 0;
2291 if (!(proc = handle16_to_proc( (WNDPROC16)func )))
2293 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, func );
2295 else if (proc->procA)
2297 ret = WINPROC_CallProc16To32A( call_dialog_proc, hwnd, msg, wParam, lParam,
2298 &result, proc->procA );
2299 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2301 else if (proc->procW)
2303 ret = WINPROC_CallProc16To32A( call_dialog_proc_AtoW, hwnd, msg, wParam, lParam,
2304 &result, proc->procW );
2305 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2309 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2315 /**********************************************************************
2316 * WINPROC_CallDlgProcA
2318 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2324 if (!func) return 0;
2326 if (!(proc = handle_to_proc( (WNDPROC)func )))
2327 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2328 else if (proc->procA)
2329 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2330 else if (proc->procW)
2332 ret = WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procW );
2333 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2337 ret = WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2338 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2344 /**********************************************************************
2345 * WINPROC_CallDlgProcW
2347 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2353 if (!func) return 0;
2355 if (!(proc = handle_to_proc( (WNDPROC)func )))
2356 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2357 else if (proc->procW)
2358 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2359 else if (proc->procA)
2361 ret = WINPROC_CallProcWtoA( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2362 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2366 ret = WINPROC_CallProcWtoA( call_dialog_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2367 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );