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"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
36 #include "user_private.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DECLARE_DEBUG_CHANNEL(msg);
43 WINE_DECLARE_DEBUG_CHANNEL(relay);
44 WINE_DEFAULT_DEBUG_CHANNEL(win);
46 typedef struct tagWINDOWPROC
48 WNDPROC16 proc16; /* 16-bit window proc */
49 WNDPROC procA; /* ASCII window proc */
50 WNDPROC procW; /* Unicode window proc */
53 #define WINPROC_HANDLE (~0u >> 16)
54 #define MAX_WINPROCS 8192
55 #define BUILTIN_WINPROCS 9 /* first BUILTIN_WINPROCS entries are reserved for builtin procs */
56 #define MAX_WINPROC_RECURSION 64
58 WNDPROC EDIT_winproc_handle = 0;
60 static WINDOWPROC winproc_array[MAX_WINPROCS];
61 static UINT builtin_used;
62 static UINT winproc_used = BUILTIN_WINPROCS;
64 static CRITICAL_SECTION winproc_cs;
65 static CRITICAL_SECTION_DEBUG critsect_debug =
68 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
69 0, 0, { (DWORD_PTR)(__FILE__ ": winproc_cs") }
71 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
73 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
75 if (size >= need) return static_buffer;
76 return HeapAlloc( GetProcessHeap(), 0, need );
79 static inline void free_buffer( void *static_buffer, void *buffer )
81 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
84 /* find an existing winproc for a given 16-bit function and type */
85 /* FIXME: probably should do something more clever than a linear search */
86 static inline WINDOWPROC *find_winproc16( WNDPROC16 func )
90 for (i = BUILTIN_WINPROCS; i < winproc_used; i++)
92 if (winproc_array[i].proc16 == func) return &winproc_array[i];
97 /* find an existing winproc for a given function and type */
98 /* FIXME: probably should do something more clever than a linear search */
99 static inline WINDOWPROC *find_winproc( WNDPROC funcA, WNDPROC funcW )
103 for (i = 0; i < builtin_used; i++)
105 /* match either proc, some apps confuse A and W */
106 if (funcA && winproc_array[i].procA != funcA && winproc_array[i].procW != funcA) continue;
107 if (funcW && winproc_array[i].procA != funcW && winproc_array[i].procW != funcW) continue;
108 return &winproc_array[i];
110 for (i = BUILTIN_WINPROCS; i < winproc_used; i++)
112 if (funcA && winproc_array[i].procA != funcA) continue;
113 if (funcW && winproc_array[i].procW != funcW) continue;
114 return &winproc_array[i];
119 /* return the window proc for a given handle, or NULL for an invalid handle */
120 static inline WINDOWPROC *handle_to_proc( WNDPROC handle )
122 UINT index = LOWORD(handle);
123 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return NULL;
124 if (index >= winproc_used) return NULL;
125 return &winproc_array[index];
128 /* create a handle for a given window proc */
129 static inline WNDPROC proc_to_handle( WINDOWPROC *proc )
131 return (WNDPROC)(ULONG_PTR)((proc - winproc_array) | (WINPROC_HANDLE << 16));
134 /* allocate and initialize a new winproc */
135 static inline WINDOWPROC *alloc_winproc( WNDPROC funcA, WNDPROC funcW )
139 /* check if the function is already a win proc */
140 if (funcA && (proc = handle_to_proc( funcA ))) return proc;
141 if (funcW && (proc = handle_to_proc( funcW ))) return proc;
142 if (!funcA && !funcW) return NULL;
144 EnterCriticalSection( &winproc_cs );
146 /* check if we already have a winproc for that function */
147 if (!(proc = find_winproc( funcA, funcW )))
151 assert( builtin_used < BUILTIN_WINPROCS );
152 proc = &winproc_array[builtin_used++];
155 TRACE( "allocated %p for builtin %p/%p (%d/%d used)\n",
156 proc_to_handle(proc), funcA, funcW, builtin_used, BUILTIN_WINPROCS );
158 else if (winproc_used < MAX_WINPROCS)
160 proc = &winproc_array[winproc_used++];
163 TRACE( "allocated %p for %c %p (%d/%d used)\n",
164 proc_to_handle(proc), funcA ? 'A' : 'W', funcA ? funcA : funcW,
165 winproc_used, MAX_WINPROCS );
167 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA, funcW );
169 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc), funcA, funcW );
171 LeaveCriticalSection( &winproc_cs );
178 #include "pshpack1.h"
180 /* Window procedure 16-to-32-bit thunk */
183 BYTE popl_eax; /* popl %eax (return address) */
184 BYTE pushl_func; /* pushl $proc */
186 BYTE pushl_eax; /* pushl %eax */
187 BYTE ljmp; /* ljmp relay*/
188 DWORD relay_offset; /* __wine_call_wndproc */
194 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
196 static WINPROC_THUNK *thunk_array;
197 static UINT thunk_selector;
198 static UINT thunk_used;
200 /* return the window proc for a given handle, or NULL for an invalid handle */
201 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
203 if (HIWORD(handle) == thunk_selector)
205 UINT index = LOWORD(handle) / sizeof(WINPROC_THUNK);
206 /* check alignment */
207 if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return NULL;
208 /* check array limits */
209 if (index >= thunk_used) return NULL;
210 return thunk_array[index].proc;
212 return handle_to_proc( (WNDPROC)handle );
215 /* allocate a 16-bit thunk for an existing window proc */
216 static WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
218 static FARPROC16 relay;
221 if (proc->proc16) return proc->proc16;
223 EnterCriticalSection( &winproc_cs );
225 if (!thunk_array) /* allocate the array and its selector */
229 if (!(thunk_selector = wine_ldt_alloc_entries(1))) goto done;
230 if (!(thunk_array = VirtualAlloc( NULL, MAX_THUNKS * sizeof(WINPROC_THUNK), MEM_COMMIT,
231 PAGE_EXECUTE_READWRITE ))) goto done;
232 wine_ldt_set_base( &entry, thunk_array );
233 wine_ldt_set_limit( &entry, MAX_THUNKS * sizeof(WINPROC_THUNK) - 1 );
234 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
235 wine_ldt_set_entry( thunk_selector, &entry );
236 relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
239 /* check if it already exists */
240 for (i = 0; i < thunk_used; i++) if (thunk_array[i].proc == proc) break;
242 if (i == thunk_used) /* create a new one */
244 WINPROC_THUNK *thunk;
246 if (thunk_used >= MAX_THUNKS) goto done;
247 thunk = &thunk_array[thunk_used++];
248 thunk->popl_eax = 0x58; /* popl %eax */
249 thunk->pushl_func = 0x68; /* pushl $proc */
251 thunk->pushl_eax = 0x50; /* pushl %eax */
252 thunk->ljmp = 0xea; /* ljmp relay*/
253 thunk->relay_offset = OFFSETOF(relay);
254 thunk->relay_sel = SELECTOROF(relay);
256 proc->proc16 = (WNDPROC16)MAKESEGPTR( thunk_selector, i * sizeof(WINPROC_THUNK) );
258 LeaveCriticalSection( &winproc_cs );
264 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
266 return handle_to_proc( (WNDPROC)handle );
269 static inline WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
274 #endif /* __i386__ */
278 /* Some window procedures modify register they shouldn't, or are not
279 * properly declared stdcall; so we need a small assembly wrapper to
281 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
282 WPARAM wParam, LPARAM lParam );
283 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
285 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
286 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
288 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
290 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
292 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
294 __ASM_CFI(".cfi_rel_offset %ebx,-12\n\t")
300 "movl 8(%ebp),%eax\n\t"
302 "leal -12(%ebp),%esp\n\t"
304 __ASM_CFI(".cfi_same_value %ebx\n\t")
306 __ASM_CFI(".cfi_same_value %esi\n\t")
308 __ASM_CFI(".cfi_same_value %edi\n\t")
310 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
311 __ASM_CFI(".cfi_same_value %ebp\n\t")
314 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
315 WPARAM wParam, LPARAM lParam )
317 return proc( hwnd, msg, wParam, lParam );
319 #endif /* __i386__ */
321 static void RECT16to32( const RECT16 *from, RECT *to )
323 to->left = from->left;
325 to->right = from->right;
326 to->bottom = from->bottom;
329 static void RECT32to16( const RECT *from, RECT16 *to )
331 to->left = from->left;
333 to->right = from->right;
334 to->bottom = from->bottom;
337 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
339 to->ptReserved.x = from->ptReserved.x;
340 to->ptReserved.y = from->ptReserved.y;
341 to->ptMaxSize.x = from->ptMaxSize.x;
342 to->ptMaxSize.y = from->ptMaxSize.y;
343 to->ptMaxPosition.x = from->ptMaxPosition.x;
344 to->ptMaxPosition.y = from->ptMaxPosition.y;
345 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
346 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
347 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
348 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
351 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
353 to->ptReserved.x = from->ptReserved.x;
354 to->ptReserved.y = from->ptReserved.y;
355 to->ptMaxSize.x = from->ptMaxSize.x;
356 to->ptMaxSize.y = from->ptMaxSize.y;
357 to->ptMaxPosition.x = from->ptMaxPosition.x;
358 to->ptMaxPosition.y = from->ptMaxPosition.y;
359 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
360 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
361 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
362 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
365 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
367 to->hwnd = HWND_16(from->hwnd);
368 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
373 to->flags = from->flags;
376 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
378 to->hwnd = WIN_Handle32(from->hwnd);
379 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
380 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
385 to->flags = from->flags;
388 /* The strings are not copied */
389 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
391 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
392 to->hInstance = HINSTANCE_16(from->hInstance);
393 to->hMenu = HMENU_16(from->hMenu);
394 to->hwndParent = HWND_16(from->hwndParent);
399 to->style = from->style;
400 to->dwExStyle = from->dwExStyle;
403 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
406 to->lpCreateParams = (LPVOID)from->lpCreateParams;
407 to->hInstance = HINSTANCE_32(from->hInstance);
408 to->hMenu = HMENU_32(from->hMenu);
409 to->hwndParent = WIN_Handle32(from->hwndParent);
414 to->style = from->style;
415 to->dwExStyle = from->dwExStyle;
416 to->lpszName = MapSL(from->lpszName);
417 to->lpszClass = MapSL(from->lpszClass);
420 /* The strings are not copied */
421 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
423 to->hOwner = HINSTANCE_16(from->hOwner);
428 to->style = from->style;
429 to->lParam = from->lParam;
432 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
434 to->hOwner = HINSTANCE_32(from->hOwner);
439 to->style = from->style;
440 to->lParam = from->lParam;
441 to->szTitle = MapSL(from->szTitle);
442 to->szClass = MapSL(from->szClass);
445 static WPARAM map_wparam_char_WtoA( WPARAM wParam, DWORD len )
450 RtlUnicodeToMultiByteN( (LPSTR)ch, len, &len, &wch, sizeof(wch) );
452 return MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wParam) );
454 return MAKEWPARAM( ch[0], HIWORD(wParam) );
457 /* call a 32-bit window procedure */
458 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
464 hwnd = WIN_GetFullHandle( hwnd );
466 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
467 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
469 *result = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
472 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
473 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, *result );
477 /* call a 32-bit dialog procedure */
478 static LRESULT call_dialog_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
485 hwnd = WIN_GetFullHandle( hwnd );
487 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
488 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
490 ret = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
491 *result = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
494 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
495 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, ret, *result );
499 /* call a 16-bit window procedure */
500 static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
501 LRESULT *result, void *arg )
503 WNDPROC16 proc = arg;
512 DRAWITEMSTRUCT16 dis16;
513 COMPAREITEMSTRUCT16 cis16;
519 /* Window procedures want ax = hInstance, ds = es = ss */
521 memset(&context, 0, sizeof(context));
522 context.SegDs = context.SegEs = SELECTOROF(NtCurrentTeb()->WOW32Reserved);
523 context.SegFs = wine_get_fs();
524 context.SegGs = wine_get_gs();
525 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
526 context.SegCs = SELECTOROF(proc);
527 context.Eip = OFFSETOF(proc);
528 context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME, bp);
532 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
533 work if structures passed in lParam are placed in the stack/data
534 segment. Programmers easily make the mistake of converting lParam
535 to a near rather than a far pointer, since Windows apparently
536 allows this. We copy the structures to the 16 bit stack; this is
537 ugly but makes these programs work. */
542 size = sizeof(CREATESTRUCT16); break;
544 size = sizeof(DRAWITEMSTRUCT16); break;
546 size = sizeof(COMPAREITEMSTRUCT16); break;
550 memcpy( &args.u, MapSL(lParam), size );
551 lParam = PtrToUlong(NtCurrentTeb()->WOW32Reserved) - size;
555 args.params[4] = hwnd;
556 args.params[3] = msg;
557 args.params[2] = wParam;
558 args.params[1] = HIWORD(lParam);
559 args.params[0] = LOWORD(lParam);
560 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
561 *result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
565 /* call a 16-bit dialog procedure */
566 static LRESULT call_dialog_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
567 LRESULT *result, void *arg )
569 LRESULT ret = call_window_proc16( hwnd, msg, wp, lp, result, arg );
570 *result = GetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT );
574 /* helper callback for 32W->16 conversion */
575 static LRESULT call_window_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
576 LRESULT *result, void *arg )
578 return WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wp, lp, result, arg );
581 /* helper callback for 32W->16 conversion */
582 static LRESULT call_dialog_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
583 LRESULT *result, void *arg )
585 return WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wp, lp, result, arg );
588 /* helper callback for 16->32W conversion */
589 static LRESULT call_window_proc_AtoW( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
590 LRESULT *result, void *arg )
592 return WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wp, lp, result,
593 arg, WMCHAR_MAP_CALLWINDOWPROC );
597 /**********************************************************************
600 * Get a window procedure pointer that can be passed to the Windows program.
602 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
606 if (unicode) ptr = alloc_winproc( NULL, proc );
607 else ptr = alloc_winproc( proc, NULL );
610 return alloc_win16_thunk( ptr );
614 /**********************************************************************
617 * Get a window procedure pointer that can be passed to the Windows program.
619 WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode )
621 WINDOWPROC *ptr = handle_to_proc( proc );
623 if (!ptr) return proc;
626 if (ptr->procW) return ptr->procW;
631 if (ptr->procA) return ptr->procA;
637 /**********************************************************************
638 * WINPROC_AllocProc16
640 * Allocate a window procedure for a window or class.
642 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
643 * lot of windows, it will usually only have a limited number of window procedures, so the
644 * array won't grow too large, and this way we avoid the need to track allocations per window.
646 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
650 if (!func) return NULL;
652 /* check if the function is already a win proc */
653 if (!(proc = handle16_to_proc( func )))
655 EnterCriticalSection( &winproc_cs );
657 /* then check if we already have a winproc for that function */
658 if (!(proc = find_winproc16( func )))
660 if (winproc_used < MAX_WINPROCS)
662 proc = &winproc_array[winproc_used++];
664 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
665 proc_to_handle(proc), func, winproc_used, MAX_WINPROCS );
667 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
669 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc), func );
671 LeaveCriticalSection( &winproc_cs );
673 return proc_to_handle( proc );
677 /**********************************************************************
680 * Allocate a window procedure for a window or class.
682 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
683 * lot of windows, it will usually only have a limited number of window procedures, so the
684 * array won't grow too large, and this way we avoid the need to track allocations per window.
686 WNDPROC WINPROC_AllocProc( WNDPROC funcA, WNDPROC funcW )
690 if (!(proc = alloc_winproc( funcA, funcW ))) return NULL;
691 return proc_to_handle( proc );
695 /**********************************************************************
698 * Return the window procedure type, or the default value if not a winproc handle.
700 BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val )
702 WINDOWPROC *ptr = handle_to_proc( proc );
704 if (!ptr) return def_val;
705 if (ptr->procA && ptr->procW) return def_val; /* can be both */
706 return (ptr->procW != NULL);
710 /**********************************************************************
711 * WINPROC_TestLBForStr
713 * Return TRUE if the lparam is a string
715 static inline BOOL WINPROC_TestLBForStr( HWND hwnd, UINT msg )
717 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
718 if (msg <= CB_MSGMAX)
719 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
721 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
726 static UINT_PTR convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
729 UINT sz = GlobalSize16(src);
732 if (!(dst = GlobalAlloc(flags, sz)))
734 ptr16 = GlobalLock16(src);
735 ptr32 = GlobalLock(dst);
736 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
740 return (UINT_PTR)dst;
743 static HANDLE16 convert_handle_32_to_16(UINT_PTR src, unsigned int flags)
746 UINT sz = GlobalSize((HANDLE)src);
749 if (!(dst = GlobalAlloc16(flags, sz)))
751 ptr32 = GlobalLock((HANDLE)src);
752 ptr16 = GlobalLock16(dst);
753 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
754 GlobalUnlock((HANDLE)src);
761 /**********************************************************************
762 * WINPROC_CallProcAtoW
764 * Call a window procedure, translating args from Ansi to Unicode.
766 LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
767 LPARAM lParam, LRESULT *result, void *arg, enum wm_char_mapping mapping )
771 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
772 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
779 WCHAR *ptr, buffer[512];
780 CREATESTRUCTA *csA = (CREATESTRUCTA *)lParam;
781 CREATESTRUCTW csW = *(CREATESTRUCTW *)csA;
782 MDICREATESTRUCTW mdi_cs;
783 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
785 if (!IS_INTRESOURCE(csA->lpszClass))
787 class_lenA = strlen(csA->lpszClass) + 1;
788 RtlMultiByteToUnicodeSize( &class_lenW, csA->lpszClass, class_lenA );
790 if (!IS_INTRESOURCE(csA->lpszName))
792 name_lenA = strlen(csA->lpszName) + 1;
793 RtlMultiByteToUnicodeSize( &name_lenW, csA->lpszName, name_lenA );
796 if (!(ptr = get_buffer( buffer, sizeof(buffer), class_lenW + name_lenW ))) break;
801 RtlMultiByteToUnicodeN( ptr, class_lenW, NULL, csA->lpszClass, class_lenA );
805 csW.lpszName = ptr + class_lenW/sizeof(WCHAR);
806 RtlMultiByteToUnicodeN( ptr + class_lenW/sizeof(WCHAR), name_lenW, NULL,
807 csA->lpszName, name_lenA );
810 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
812 mdi_cs = *(MDICREATESTRUCTW *)csA->lpCreateParams;
813 mdi_cs.szTitle = csW.lpszName;
814 mdi_cs.szClass = csW.lpszClass;
815 csW.lpCreateParams = &mdi_cs;
818 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
819 free_buffer( buffer, ptr );
825 WCHAR *ptr, buffer[512];
826 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
827 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
828 MDICREATESTRUCTW csW;
830 memcpy( &csW, csA, sizeof(csW) );
832 if (!IS_INTRESOURCE(csA->szTitle))
834 title_lenA = strlen(csA->szTitle) + 1;
835 RtlMultiByteToUnicodeSize( &title_lenW, csA->szTitle, title_lenA );
837 if (!IS_INTRESOURCE(csA->szClass))
839 class_lenA = strlen(csA->szClass) + 1;
840 RtlMultiByteToUnicodeSize( &class_lenW, csA->szClass, class_lenA );
843 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenW + class_lenW ))) break;
848 RtlMultiByteToUnicodeN( ptr, title_lenW, NULL, csA->szTitle, title_lenA );
852 csW.szClass = ptr + title_lenW/sizeof(WCHAR);
853 RtlMultiByteToUnicodeN( ptr + title_lenW/sizeof(WCHAR), class_lenW, NULL,
854 csA->szClass, class_lenA );
856 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
857 free_buffer( buffer, ptr );
862 case WM_ASKCBFORMATNAME:
864 WCHAR *ptr, buffer[512];
865 LPSTR str = (LPSTR)lParam;
866 DWORD len = wParam * sizeof(WCHAR);
868 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
869 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
874 RtlUnicodeToMultiByteN( str, wParam - 1, &len, ptr, strlenW(ptr) * sizeof(WCHAR) );
878 free_buffer( buffer, ptr );
883 case LB_INSERTSTRING:
885 case LB_FINDSTRINGEXACT:
886 case LB_SELECTSTRING:
888 case CB_INSERTSTRING:
890 case CB_FINDSTRINGEXACT:
891 case CB_SELECTSTRING:
892 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
894 ret = callback( hwnd, msg, wParam, lParam, result, arg );
899 case WM_WININICHANGE:
900 case WM_DEVMODECHANGE:
905 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
908 WCHAR *ptr, buffer[512];
909 LPCSTR strA = (LPCSTR)lParam;
910 DWORD lenW, lenA = strlen(strA) + 1;
912 RtlMultiByteToUnicodeSize( &lenW, strA, lenA );
913 if ((ptr = get_buffer( buffer, sizeof(buffer), lenW )))
915 RtlMultiByteToUnicodeN( ptr, lenW, NULL, strA, lenA );
916 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
917 free_buffer( buffer, ptr );
924 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
926 WCHAR buffer[512]; /* FIXME: fixed sized buffer */
928 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
932 RtlUnicodeToMultiByteN( (LPSTR)lParam, ~0u, &len,
933 buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
937 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
942 WCHAR *ptr, buffer[512];
943 WORD len = *(WORD *)lParam;
945 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
946 *((WORD *)ptr) = len; /* store the length */
947 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
951 RtlUnicodeToMultiByteN( (LPSTR)lParam, len, &reslen, ptr, *result * sizeof(WCHAR) );
952 if (reslen < len) ((LPSTR)lParam)[reslen] = 0;
955 free_buffer( buffer, ptr );
962 MSG newmsg = *(MSG *)lParam;
963 if (map_wparam_AtoW( newmsg.message, &newmsg.wParam, WMCHAR_MAP_NOMAPPING ))
964 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
966 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
975 case EM_SETPASSWORDCHAR:
977 if (map_wparam_AtoW( msg, &wParam, mapping ))
978 ret = callback( hwnd, msg, wParam, lParam, result, arg );
981 case WM_GETTEXTLENGTH:
982 case CB_GETLBTEXTLEN:
984 ret = callback( hwnd, msg, wParam, lParam, result, arg );
987 WCHAR *ptr, buffer[512];
989 DWORD len = *result + 1;
990 /* Determine respective GETTEXT message */
991 UINT msgGetText = (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
992 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
993 /* wParam differs between the messages */
994 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? len : wParam;
996 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
998 if (callback == call_window_proc) /* FIXME: hack */
999 callback( hwnd, msgGetText, wp, (LPARAM)ptr, &tmp, arg );
1001 tmp = SendMessageW( hwnd, msgGetText, wp, (LPARAM)ptr );
1002 RtlUnicodeToMultiByteSize( &len, ptr, tmp * sizeof(WCHAR) );
1004 free_buffer( buffer, ptr );
1008 case WM_PAINTCLIPBOARD:
1009 case WM_SIZECLIPBOARD:
1010 FIXME_(msg)( "message %s (0x%x) needs translation, please report\n",
1011 SPY_GetMsgName(msg, hwnd), msg );
1015 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1022 /**********************************************************************
1023 * WINPROC_CallProcWtoA
1025 * Call a window procedure, translating args from Unicode to Ansi.
1027 static LRESULT WINPROC_CallProcWtoA( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
1028 LPARAM lParam, LRESULT *result, void *arg )
1032 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1033 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1040 char buffer[1024], *cls;
1041 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
1042 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
1043 MDICREATESTRUCTA mdi_cs;
1044 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
1046 if (!IS_INTRESOURCE(csW->lpszClass))
1048 class_lenW = (strlenW(csW->lpszClass) + 1) * sizeof(WCHAR);
1049 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
1051 if (!IS_INTRESOURCE(csW->lpszName))
1053 name_lenW = (strlenW(csW->lpszName) + 1) * sizeof(WCHAR);
1054 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
1057 if (!(cls = get_buffer( buffer, sizeof(buffer), class_lenA + name_lenA ))) break;
1061 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
1062 csA.lpszClass = cls;
1066 char *name = cls + class_lenA;
1067 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
1068 csA.lpszName = name;
1071 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1073 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
1074 mdi_cs.szTitle = csA.lpszName;
1075 mdi_cs.szClass = csA.lpszClass;
1076 csA.lpCreateParams = &mdi_cs;
1079 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1080 free_buffer( buffer, cls );
1085 case WM_ASKCBFORMATNAME:
1087 char *ptr, buffer[512];
1088 DWORD len = wParam * 2;
1090 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
1091 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1096 RtlMultiByteToUnicodeN( (LPWSTR)lParam, wParam*sizeof(WCHAR), &len, ptr, strlen(ptr)+1 );
1097 *result = len/sizeof(WCHAR) - 1; /* do not count terminating null */
1099 ((LPWSTR)lParam)[*result] = 0;
1101 free_buffer( buffer, ptr );
1106 case LB_INSERTSTRING:
1108 case LB_FINDSTRINGEXACT:
1109 case LB_SELECTSTRING:
1111 case CB_INSERTSTRING:
1113 case CB_FINDSTRINGEXACT:
1114 case CB_SELECTSTRING:
1115 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
1117 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1122 case WM_WININICHANGE:
1123 case WM_DEVMODECHANGE:
1128 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
1131 char *ptr, buffer[512];
1132 LPCWSTR strW = (LPCWSTR)lParam;
1133 DWORD lenA, lenW = (strlenW(strW) + 1) * sizeof(WCHAR);
1135 RtlUnicodeToMultiByteSize( &lenA, strW, lenW );
1136 if ((ptr = get_buffer( buffer, sizeof(buffer), lenA )))
1138 RtlUnicodeToMultiByteN( ptr, lenA, NULL, strW, lenW );
1139 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1140 free_buffer( buffer, ptr );
1147 char *ptr, buffer[1024];
1148 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
1149 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1150 MDICREATESTRUCTA csA;
1152 memcpy( &csA, csW, sizeof(csA) );
1154 if (!IS_INTRESOURCE(csW->szTitle))
1156 title_lenW = (strlenW(csW->szTitle) + 1) * sizeof(WCHAR);
1157 RtlUnicodeToMultiByteSize( &title_lenA, csW->szTitle, title_lenW );
1159 if (!IS_INTRESOURCE(csW->szClass))
1161 class_lenW = (strlenW(csW->szClass) + 1) * sizeof(WCHAR);
1162 RtlUnicodeToMultiByteSize( &class_lenA, csW->szClass, class_lenW );
1165 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenA + class_lenA ))) break;
1169 RtlUnicodeToMultiByteN( ptr, title_lenA, NULL, csW->szTitle, title_lenW );
1174 RtlUnicodeToMultiByteN( ptr + title_lenA, class_lenA, NULL, csW->szClass, class_lenW );
1175 csA.szClass = ptr + title_lenA;
1177 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1178 free_buffer( buffer, ptr );
1184 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
1186 char buffer[512]; /* FIXME: fixed sized buffer */
1188 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1192 RtlMultiByteToUnicodeN( (LPWSTR)lParam, ~0u, &len, buffer, strlen(buffer) + 1 );
1193 *result = len / sizeof(WCHAR) - 1;
1196 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1201 char *ptr, buffer[512];
1202 WORD len = *(WORD *)lParam;
1204 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * 2 ))) break;
1205 *((WORD *)ptr) = len * 2; /* store the length */
1206 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1210 RtlMultiByteToUnicodeN( (LPWSTR)lParam, len*sizeof(WCHAR), &reslen, ptr, *result );
1211 *result = reslen / sizeof(WCHAR);
1212 if (*result < len) ((LPWSTR)lParam)[*result] = 0;
1214 free_buffer( buffer, ptr );
1221 MSG newmsg = *(MSG *)lParam;
1222 switch(newmsg.message)
1227 case WM_SYSDEADCHAR:
1228 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 1 );
1231 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 2 );
1234 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1236 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1245 RtlUnicodeToMultiByteN( ch, 2, &len, &wch, sizeof(wch) );
1246 ret = callback( hwnd, msg, (BYTE)ch[0], lParam, result, arg );
1247 if (len == 2) ret = callback( hwnd, msg, (BYTE)ch[1], lParam, result, arg );
1255 case WM_SYSDEADCHAR:
1256 case EM_SETPASSWORDCHAR:
1257 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,1), lParam, result, arg );
1261 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,2), lParam, result, arg );
1264 case WM_PAINTCLIPBOARD:
1265 case WM_SIZECLIPBOARD:
1266 FIXME_(msg)( "message %s (%04x) needs translation, please report\n",
1267 SPY_GetMsgName(msg, hwnd), msg );
1271 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1279 /**********************************************************************
1280 * WINPROC_CallProc16To32A
1282 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
1283 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
1286 HWND hwnd32 = WIN_Handle32( hwnd );
1288 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1289 hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
1296 CREATESTRUCT16 *cs16 = MapSL(lParam);
1298 MDICREATESTRUCTA mdi_cs;
1300 CREATESTRUCT16to32A( cs16, &cs );
1301 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
1303 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
1304 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
1305 cs.lpCreateParams = &mdi_cs;
1307 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1308 CREATESTRUCT32Ato16( &cs, cs16 );
1313 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
1314 MDICREATESTRUCTA cs;
1316 MDICREATESTRUCT16to32A( cs16, &cs );
1317 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1318 MDICREATESTRUCT32Ato16( &cs, cs16 );
1321 case WM_MDIACTIVATE:
1323 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
1324 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1325 else /* message sent to MDI client */
1326 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1328 case WM_MDIGETACTIVE:
1330 BOOL maximized = FALSE;
1331 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
1332 *result = MAKELRESULT( LOWORD(*result), maximized );
1336 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
1337 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
1340 case WM_GETMINMAXINFO:
1342 MINMAXINFO16 *mmi16 = MapSL(lParam);
1345 MINMAXINFO16to32( mmi16, &mmi );
1346 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
1347 MINMAXINFO32to16( &mmi, mmi16 );
1350 case WM_WINDOWPOSCHANGING:
1351 case WM_WINDOWPOSCHANGED:
1353 WINDOWPOS16 *winpos16 = MapSL(lParam);
1356 WINDOWPOS16to32( winpos16, &winpos );
1357 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
1358 WINDOWPOS32to16( &winpos, winpos16 );
1363 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
1364 NCCALCSIZE_PARAMS nc;
1367 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
1370 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
1371 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
1372 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
1375 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
1376 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
1379 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
1380 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
1381 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
1385 case WM_COMPAREITEM:
1387 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
1388 COMPAREITEMSTRUCT cis;
1389 cis.CtlType = cis16->CtlType;
1390 cis.CtlID = cis16->CtlID;
1391 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
1392 cis.itemID1 = cis16->itemID1;
1393 cis.itemData1 = cis16->itemData1;
1394 cis.itemID2 = cis16->itemID2;
1395 cis.itemData2 = cis16->itemData2;
1396 cis.dwLocaleId = 0; /* FIXME */
1397 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
1402 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
1403 DELETEITEMSTRUCT dis;
1404 dis.CtlType = dis16->CtlType;
1405 dis.CtlID = dis16->CtlID;
1406 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
1407 dis.itemData = dis16->itemData;
1408 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1411 case WM_MEASUREITEM:
1413 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1414 MEASUREITEMSTRUCT mis;
1415 mis.CtlType = mis16->CtlType;
1416 mis.CtlID = mis16->CtlID;
1417 mis.itemID = mis16->itemID;
1418 mis.itemWidth = mis16->itemWidth;
1419 mis.itemHeight = mis16->itemHeight;
1420 mis.itemData = mis16->itemData;
1421 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
1422 mis16->itemWidth = (UINT16)mis.itemWidth;
1423 mis16->itemHeight = (UINT16)mis.itemHeight;
1428 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1430 dis.CtlType = dis16->CtlType;
1431 dis.CtlID = dis16->CtlID;
1432 dis.itemID = dis16->itemID;
1433 dis.itemAction = dis16->itemAction;
1434 dis.itemState = dis16->itemState;
1435 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1436 : WIN_Handle32( dis16->hwndItem );
1437 dis.hDC = HDC_32(dis16->hDC);
1438 dis.itemData = dis16->itemData;
1439 dis.rcItem.left = dis16->rcItem.left;
1440 dis.rcItem.top = dis16->rcItem.top;
1441 dis.rcItem.right = dis16->rcItem.right;
1442 dis.rcItem.bottom = dis16->rcItem.bottom;
1443 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1448 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
1450 cds.dwData = cds16->dwData;
1451 cds.cbData = cds16->cbData;
1452 cds.lpData = MapSL(cds16->lpData);
1453 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
1459 MSG16 *msg16 = MapSL(lParam);
1461 msg32.hwnd = WIN_Handle32( msg16->hwnd );
1462 msg32.message = msg16->message;
1463 msg32.wParam = msg16->wParam;
1464 msg32.lParam = msg16->lParam;
1465 msg32.time = msg16->time;
1466 msg32.pt.x = msg16->pt.x;
1467 msg32.pt.y = msg16->pt.y;
1468 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
1471 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1476 next.hmenuIn = (HMENU)lParam;
1479 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
1480 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
1487 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1488 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1492 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1493 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
1496 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
1497 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
1498 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
1503 case WM_WININICHANGE:
1504 case WM_DEVMODECHANGE:
1505 case WM_ASKCBFORMATNAME:
1507 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
1510 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1511 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1514 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
1516 HMENU hmenu = HMENU_32(HIWORD(lParam));
1517 UINT pos = MENU_FindSubMenu( &hmenu, HMENU_32(wParam) );
1518 if (pos == 0xffff) pos = 0; /* NO_SELECTED_ITEM */
1521 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1522 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1524 case WM_PARENTNOTIFY:
1525 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
1526 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1527 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1529 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1531 case WM_ACTIVATEAPP:
1532 /* We need this when SetActiveWindow sends a Sendmessage16() to
1533 * a 32-bit window. Might be superfluous with 32-bit interprocess
1534 * message queues. */
1535 if (lParam) lParam = HTASK_32(lParam);
1536 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1538 case WM_DDE_INITIATE:
1539 case WM_DDE_TERMINATE:
1540 case WM_DDE_UNADVISE:
1541 case WM_DDE_REQUEST:
1542 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1548 HANDLE16 lo16 = LOWORD(lParam);
1550 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
1551 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
1552 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1554 break; /* FIXME don't know how to free allocated memory (handle) !! */
1557 UINT_PTR lo = LOWORD(lParam);
1558 UINT_PTR hi = HIWORD(lParam);
1562 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1563 if (GlobalSize16(hi) != 0) flag |= 2;
1569 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1574 break; /* atom, nothing to do */
1576 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
1579 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1582 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
1583 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1585 break; /* FIXME don't know how to free allocated memory (handle) !! */
1586 case WM_DDE_EXECUTE:
1587 lParam = convert_handle_16_to_32( lParam, GMEM_DDESHARE );
1588 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1589 break; /* FIXME don't know how to free allocated memory (handle) !! */
1590 case WM_PAINTCLIPBOARD:
1591 case WM_SIZECLIPBOARD:
1592 FIXME_(msg)( "message %04x needs translation\n", msg );
1595 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1602 /**********************************************************************
1603 * __wine_call_wndproc (USER.1010)
1605 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
1611 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
1613 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
1618 /**********************************************************************
1619 * WINPROC_CallProc32ATo16
1621 * Call a 16-bit window procedure, translating the 32-bit args.
1623 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
1624 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
1628 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1629 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1636 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
1638 MDICREATESTRUCT16 mdi_cs16;
1639 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
1641 CREATESTRUCT32Ato16( cs32, &cs );
1642 cs.lpszName = MapLS( cs32->lpszName );
1643 cs.lpszClass = MapLS( cs32->lpszClass );
1647 MDICREATESTRUCTA *mdi_cs = cs32->lpCreateParams;
1648 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
1649 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
1650 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
1651 cs.lpCreateParams = MapLS( &mdi_cs16 );
1653 lParam = MapLS( &cs );
1654 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1656 UnMapLS( cs.lpszName );
1657 UnMapLS( cs.lpszClass );
1660 UnMapLS( cs.lpCreateParams );
1661 UnMapLS( mdi_cs16.szTitle );
1662 UnMapLS( mdi_cs16.szClass );
1668 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
1669 MDICREATESTRUCT16 cs;
1671 MDICREATESTRUCT32Ato16( cs32, &cs );
1672 cs.szTitle = MapLS( cs32->szTitle );
1673 cs.szClass = MapLS( cs32->szClass );
1674 lParam = MapLS( &cs );
1675 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1677 UnMapLS( cs.szTitle );
1678 UnMapLS( cs.szClass );
1681 case WM_MDIACTIVATE:
1682 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1683 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
1684 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
1686 ret = callback( HWND_16(hwnd), msg, HWND_16( wParam ), 0, result, arg );
1688 case WM_MDIGETACTIVE:
1689 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1690 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
1691 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
1694 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
1695 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
1697 case WM_GETMINMAXINFO:
1699 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
1702 MINMAXINFO32to16( mmi32, &mmi );
1703 lParam = MapLS( &mmi );
1704 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1706 MINMAXINFO16to32( &mmi, mmi32 );
1711 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
1712 NCCALCSIZE_PARAMS16 nc;
1715 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
1718 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
1719 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
1720 WINDOWPOS32to16( nc32->lppos, &winpos );
1721 nc.lppos = MapLS( &winpos );
1723 lParam = MapLS( &nc );
1724 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1726 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
1729 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
1730 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
1731 WINDOWPOS16to32( &winpos, nc32->lppos );
1732 UnMapLS( nc.lppos );
1736 case WM_WINDOWPOSCHANGING:
1737 case WM_WINDOWPOSCHANGED:
1739 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
1742 WINDOWPOS32to16( winpos32, &winpos );
1743 lParam = MapLS( &winpos );
1744 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1746 WINDOWPOS16to32( &winpos, winpos32 );
1749 case WM_COMPAREITEM:
1751 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
1752 COMPAREITEMSTRUCT16 cis;
1753 cis.CtlType = cis32->CtlType;
1754 cis.CtlID = cis32->CtlID;
1755 cis.hwndItem = HWND_16( cis32->hwndItem );
1756 cis.itemID1 = cis32->itemID1;
1757 cis.itemData1 = cis32->itemData1;
1758 cis.itemID2 = cis32->itemID2;
1759 cis.itemData2 = cis32->itemData2;
1760 lParam = MapLS( &cis );
1761 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1767 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
1768 DELETEITEMSTRUCT16 dis;
1769 dis.CtlType = dis32->CtlType;
1770 dis.CtlID = dis32->CtlID;
1771 dis.itemID = dis32->itemID;
1772 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1773 : HWND_16( dis32->hwndItem );
1774 dis.itemData = dis32->itemData;
1775 lParam = MapLS( &dis );
1776 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1782 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
1783 DRAWITEMSTRUCT16 dis;
1784 dis.CtlType = dis32->CtlType;
1785 dis.CtlID = dis32->CtlID;
1786 dis.itemID = dis32->itemID;
1787 dis.itemAction = dis32->itemAction;
1788 dis.itemState = dis32->itemState;
1789 dis.hwndItem = HWND_16( dis32->hwndItem );
1790 dis.hDC = HDC_16(dis32->hDC);
1791 dis.itemData = dis32->itemData;
1792 dis.rcItem.left = dis32->rcItem.left;
1793 dis.rcItem.top = dis32->rcItem.top;
1794 dis.rcItem.right = dis32->rcItem.right;
1795 dis.rcItem.bottom = dis32->rcItem.bottom;
1796 lParam = MapLS( &dis );
1797 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1801 case WM_MEASUREITEM:
1803 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
1804 MEASUREITEMSTRUCT16 mis;
1805 mis.CtlType = mis32->CtlType;
1806 mis.CtlID = mis32->CtlID;
1807 mis.itemID = mis32->itemID;
1808 mis.itemWidth = mis32->itemWidth;
1809 mis.itemHeight = mis32->itemHeight;
1810 mis.itemData = mis32->itemData;
1811 lParam = MapLS( &mis );
1812 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1814 mis32->itemWidth = mis.itemWidth;
1815 mis32->itemHeight = mis.itemHeight;
1820 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
1821 COPYDATASTRUCT16 cds;
1823 cds.dwData = cds32->dwData;
1824 cds.cbData = cds32->cbData;
1825 cds.lpData = MapLS( cds32->lpData );
1826 lParam = MapLS( &cds );
1827 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1829 UnMapLS( cds.lpData );
1835 MSG *msg32 = (MSG *)lParam;
1838 msg16.hwnd = HWND_16( msg32->hwnd );
1839 msg16.message = msg32->message;
1840 msg16.wParam = msg32->wParam;
1841 msg16.lParam = msg32->lParam;
1842 msg16.time = msg32->time;
1843 msg16.pt.x = msg32->pt.x;
1844 msg16.pt.y = msg32->pt.y;
1845 lParam = MapLS( &msg16 );
1846 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1850 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1854 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1855 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
1856 next->hmenuNext = HMENU_32( LOWORD(*result) );
1857 next->hwndNext = WIN_Handle32( HIWORD(*result) );
1862 case WM_ASKCBFORMATNAME:
1863 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
1867 case WM_WININICHANGE:
1868 case WM_DEVMODECHANGE:
1869 lParam = MapLS( (void *)lParam );
1870 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1877 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ),
1882 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( HIWORD(wParam), (HWND16)lParam ),
1885 case WM_CTLCOLORMSGBOX:
1886 case WM_CTLCOLOREDIT:
1887 case WM_CTLCOLORLISTBOX:
1888 case WM_CTLCOLORBTN:
1889 case WM_CTLCOLORDLG:
1890 case WM_CTLCOLORSCROLLBAR:
1891 case WM_CTLCOLORSTATIC:
1892 ret = callback( HWND_16(hwnd), WM_CTLCOLOR, wParam,
1893 MAKELPARAM( (HWND16)lParam, msg - WM_CTLCOLORMSGBOX ), result, arg );
1896 if(HIWORD(wParam) & MF_POPUP)
1899 if ((HIWORD(wParam) != 0xffff) || lParam)
1901 if ((hmenu = GetSubMenu( (HMENU)lParam, LOWORD(wParam) )))
1903 ret = callback( HWND_16(hwnd), msg, HMENU_16(hmenu),
1904 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1911 ret = callback( HWND_16(hwnd), msg, wParam,
1912 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1914 case WM_PARENTNOTIFY:
1915 if ((LOWORD(wParam) == WM_CREATE) || (LOWORD(wParam) == WM_DESTROY))
1916 ret = callback( HWND_16(hwnd), msg, wParam,
1917 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ), result, arg );
1919 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1921 case WM_ACTIVATEAPP:
1922 ret = callback( HWND_16(hwnd), msg, wParam, HTASK_16( lParam ), result, arg );
1925 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
1926 ret = callback( HWND_16(hwnd), WM_PAINTICON, 1, lParam, result, arg );
1928 ret = callback( HWND_16(hwnd), WM_PAINT, wParam, lParam, result, arg );
1931 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON )) msg = WM_ICONERASEBKGND;
1932 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1934 case WM_DDE_INITIATE:
1935 case WM_DDE_TERMINATE:
1936 case WM_DDE_UNADVISE:
1937 case WM_DDE_REQUEST:
1938 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam), lParam, result, arg );
1947 UnpackDDElParam( msg, lParam, &lo32, &hi );
1948 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
1949 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1950 MAKELPARAM(lo16, hi), result, arg );
1952 break; /* FIXME don't know how to free allocated memory (handle) !! */
1959 UnpackDDElParam( msg, lParam, &lo, &hi );
1961 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
1962 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
1968 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1973 break; /* atom, nothing to do */
1975 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
1978 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
1981 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1982 MAKELPARAM(lo, hi), result, arg );
1984 break; /* FIXME don't know how to free allocated memory (handle) !! */
1985 case WM_DDE_EXECUTE:
1986 lParam = convert_handle_32_to_16(lParam, GMEM_DDESHARE);
1987 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1988 break; /* FIXME don't know how to free allocated memory (handle) !! */
1990 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
1993 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
1994 *(LPINT)wParam = LOWORD(*result);
1995 *(LPINT)lParam = HIWORD(*result);
2002 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
2010 case EM_SCROLLCARET:
2013 case EM_GETLINECOUNT:
2025 case EM_LINEFROMCHAR:
2026 case EM_SETTABSTOPS:
2027 case EM_SETPASSWORDCHAR:
2028 case EM_EMPTYUNDOBUFFER:
2029 case EM_GETFIRSTVISIBLELINE:
2030 case EM_SETREADONLY:
2031 case EM_SETWORDBREAKPROC:
2032 case EM_GETWORDBREAKPROC:
2033 case EM_GETPASSWORDCHAR:
2034 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
2037 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
2041 case LB_DELETESTRING:
2042 case LB_GETANCHORINDEX:
2043 case LB_GETCARETINDEX:
2046 case LB_GETHORIZONTALEXTENT:
2047 case LB_GETITEMDATA:
2048 case LB_GETITEMHEIGHT:
2050 case LB_GETSELCOUNT:
2052 case LB_GETTOPINDEX:
2053 case LB_RESETCONTENT:
2054 case LB_SELITEMRANGE:
2055 case LB_SELITEMRANGEEX:
2056 case LB_SETANCHORINDEX:
2057 case LB_SETCARETINDEX:
2058 case LB_SETCOLUMNWIDTH:
2060 case LB_SETHORIZONTALEXTENT:
2061 case LB_SETITEMDATA:
2062 case LB_SETITEMHEIGHT:
2064 case LB_SETTOPINDEX:
2065 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
2069 case LB_FINDSTRINGEXACT:
2070 case LB_INSERTSTRING:
2071 case LB_SELECTSTRING:
2075 lParam = MapLS( (LPSTR)lParam );
2076 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
2079 case LB_GETSELITEMS:
2081 INT *items32 = (INT *)lParam;
2082 INT16 *items, buffer[512];
2085 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
2086 if (!(items = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
2087 lParam = MapLS( items );
2088 ret = callback( HWND_16(hwnd), LB_GETSELITEMS16, wParam, lParam, result, arg );
2090 for (i = 0; i < wParam; i++) items32[i] = items[i];
2091 free_buffer( buffer, items );
2094 case LB_SETTABSTOPS:
2097 INT *stops32 = (INT *)lParam;
2098 INT16 *stops, buffer[512];
2101 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
2102 if (!(stops = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
2103 for (i = 0; i < wParam; i++) stops[i] = stops32[i];
2104 lParam = MapLS( stops );
2105 ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
2107 free_buffer( buffer, stops );
2109 else ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
2111 case CB_DELETESTRING:
2113 case CB_GETLBTEXTLEN:
2115 case CB_RESETCONTENT:
2119 case CB_SHOWDROPDOWN:
2120 case CB_SETITEMDATA:
2121 case CB_SETITEMHEIGHT:
2122 case CB_GETITEMHEIGHT:
2123 case CB_SETEXTENDEDUI:
2124 case CB_GETEXTENDEDUI:
2125 case CB_GETDROPPEDSTATE:
2126 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
2129 ret = callback( HWND_16(hwnd), CB_GETEDITSEL16, wParam, lParam, result, arg );
2130 if (wParam) *((PUINT)(wParam)) = LOWORD(*result);
2131 if (lParam) *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: substract 1? */
2135 case CB_FINDSTRINGEXACT:
2136 case CB_INSERTSTRING:
2137 case CB_SELECTSTRING:
2140 lParam = MapLS( (LPSTR)lParam );
2141 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
2144 case LB_GETITEMRECT:
2145 case CB_GETDROPPEDCONTROLRECT:
2147 RECT *r32 = (RECT *)lParam;
2149 lParam = MapLS( &rect );
2150 ret = callback( HWND_16(hwnd),
2151 (msg == LB_GETITEMRECT) ? LB_GETITEMRECT16 : CB_GETDROPPEDCONTROLRECT16,
2152 wParam, lParam, result, arg );
2154 RECT16to32( &rect, r32 );
2157 case WM_PAINTCLIPBOARD:
2158 case WM_SIZECLIPBOARD:
2159 FIXME_(msg)( "message %04x needs translation\n", msg );
2161 /* the following messages should not be sent to 16-bit apps */
2164 case WM_CAPTURECHANGED:
2165 case WM_STYLECHANGING:
2166 case WM_STYLECHANGED:
2169 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2176 /**********************************************************************
2177 * WINPROC_call_window
2179 * Call the window procedure of the specified window.
2181 BOOL WINPROC_call_window( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2182 LRESULT *result, BOOL unicode, enum wm_char_mapping mapping )
2184 struct user_thread_info *thread_info = get_user_thread_info();
2188 if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE;
2189 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
2190 if (wndPtr->tid != GetCurrentThreadId())
2192 WIN_ReleasePtr( wndPtr );
2195 proc = handle_to_proc( wndPtr->winproc );
2196 WIN_ReleasePtr( wndPtr );
2198 if (!proc) return TRUE;
2200 if (thread_info->recursion_count > MAX_WINPROC_RECURSION) return FALSE;
2201 thread_info->recursion_count++;
2206 call_window_proc( hwnd, msg, wParam, lParam, result, proc->procW );
2207 else if (proc->procA)
2208 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procA );
2210 WINPROC_CallProcWtoA( call_window_proc_Ato16, hwnd, msg, wParam, lParam, result, proc->proc16 );
2215 call_window_proc( hwnd, msg, wParam, lParam, result, proc->procA );
2216 else if (proc->procW)
2217 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procW, mapping );
2219 WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wParam, lParam, result, proc->proc16 );
2221 thread_info->recursion_count--;
2226 /**********************************************************************
2227 * CallWindowProc (USER.122)
2229 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2230 WPARAM16 wParam, LPARAM lParam )
2235 if (!func) return 0;
2237 if (!(proc = handle16_to_proc( func )))
2238 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
2239 else if (proc->procA)
2240 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2241 else if (proc->procW)
2242 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
2244 call_window_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2250 /**********************************************************************
2251 * CallWindowProcA (USER32.@)
2253 * The CallWindowProc() function invokes the windows procedure _func_,
2254 * with _hwnd_ as the target window, the message specified by _msg_, and
2255 * the message parameters _wParam_ and _lParam_.
2257 * Some kinds of argument conversion may be done, I'm not sure what.
2259 * CallWindowProc() may be used for windows subclassing. Use
2260 * SetWindowLong() to set a new windows procedure for windows of the
2261 * subclass, and handle subclassed messages in the new windows
2262 * procedure. The new windows procedure may then use CallWindowProc()
2263 * with _func_ set to the parent class's windows procedure to dispatch
2264 * the message to the superclass.
2268 * The return value is message dependent.
2274 LRESULT WINAPI CallWindowProcA(
2275 WNDPROC func, /* [in] window procedure */
2276 HWND hwnd, /* [in] target window */
2277 UINT msg, /* [in] message */
2278 WPARAM wParam, /* [in] message dependent parameter */
2279 LPARAM lParam /* [in] message dependent parameter */
2284 if (!func) return 0;
2286 if (!(proc = handle_to_proc( func )))
2287 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2288 else if (proc->procA)
2289 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2290 else if (proc->procW)
2291 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, &result,
2292 proc->procW, WMCHAR_MAP_CALLWINDOWPROC );
2294 WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2299 /**********************************************************************
2300 * CallWindowProcW (USER32.@)
2302 * See CallWindowProcA.
2304 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2305 WPARAM wParam, LPARAM lParam )
2310 if (!func) return 0;
2312 if (!(proc = handle_to_proc( func )))
2313 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2314 else if (proc->procW)
2315 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2316 else if (proc->procA)
2317 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2319 WINPROC_CallProcWtoA( call_window_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2324 /**********************************************************************
2325 * WINPROC_CallDlgProcA
2327 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2333 if (!func) return 0;
2335 if (!(proc = handle_to_proc( func )))
2336 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2337 else if (proc->procA)
2338 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2339 else if (proc->procW)
2341 ret = WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wParam, lParam, &result,
2342 proc->procW, WMCHAR_MAP_CALLWINDOWPROC );
2343 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2347 ret = WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2348 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2354 /**********************************************************************
2355 * WINPROC_CallDlgProcW
2357 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2363 if (!func) return 0;
2365 if (!(proc = handle_to_proc( func )))
2366 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2367 else if (proc->procW)
2368 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2369 else if (proc->procA)
2371 ret = WINPROC_CallProcWtoA( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2372 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2376 ret = WINPROC_CallProcWtoA( call_dialog_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2377 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2383 /**********************************************************************
2384 * UserRegisterWowHandlers (USER32.@)
2386 * NOTE: no attempt has been made to be compatible here,
2387 * the Windows function is most likely completely different.
2389 void WINAPI UserRegisterWowHandlers( const struct wow_handlers16 *new, struct wow_handlers32 *orig )
2391 orig->button_proc = ButtonWndProc_common;
2392 orig->combo_proc = ComboWndProc_common;
2393 wow_handlers = *new;
2396 struct wow_handlers16 wow_handlers =
2398 ButtonWndProc_common,
2399 ComboWndProc_common,