user: Added fast 32->16 mapping for button and scrollbar messages.
[wine/multimedia.git] / dlls / user / winproc.c
blobe53def24042e5e9e79fa7d188e9dcb0ba34153d0
1 /*
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
22 #include "config.h"
23 #include "wine/port.h"
25 #include <assert.h>
26 #include <stdarg.h>
27 #include <string.h>
29 #include "windef.h"
30 #include "winbase.h"
31 #include "wingdi.h"
32 #include "wownt32.h"
33 #include "wine/winbase16.h"
34 #include "wine/winuser16.h"
35 #include "controls.h"
36 #include "win.h"
37 #include "winproc.h"
38 #include "user_private.h"
39 #include "dde.h"
40 #include "winternl.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 */
53 } WINDOWPROC;
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 =
64 0, 0, &winproc_cs,
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 )
85 unsigned int i;
87 for (i = 0; i < winproc_used; i++)
89 if (winproc_array[i].proc16 == func) return &winproc_array[i];
91 return NULL;
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 )
98 unsigned int i;
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];
106 return NULL;
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 )
127 WINDOWPROC *proc;
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++];
142 proc->procA = funcA;
143 proc->procW = funcW;
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 );
152 return proc;
156 #ifdef __i386__
158 #include "pshpack1.h"
160 /* Window procedure 16-to-32-bit thunk */
161 typedef struct
163 BYTE popl_eax; /* popl %eax (return address) */
164 BYTE pushl_func; /* pushl $proc */
165 WINDOWPROC *proc;
166 BYTE pushl_eax; /* pushl %eax */
167 BYTE ljmp; /* ljmp relay*/
168 DWORD relay_offset; /* __wine_call_wndproc */
169 WORD relay_sel;
170 } WINPROC_THUNK;
172 #include "poppack.h"
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;
199 UINT i;
201 if (proc->proc16) return proc->proc16;
203 EnterCriticalSection( &winproc_cs );
205 if (!thunk_array) /* allocate the array and its selector */
207 LDT_ENTRY entry;
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 */
230 thunk->proc = 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) );
237 done:
238 LeaveCriticalSection( &winproc_cs );
239 return proc->proc16;
242 #else /* __i386__ */
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 )
251 return 0;
254 #endif /* __i386__ */
257 #ifdef __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
260 * call them. */
261 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
262 WPARAM wParam, LPARAM lParam );
263 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
264 "pushl %ebp\n\t"
265 "movl %esp,%ebp\n\t"
266 "pushl %edi\n\t"
267 "pushl %esi\n\t"
268 "pushl %ebx\n\t"
269 "subl $12,%esp\n\t"
270 "pushl 24(%ebp)\n\t"
271 "pushl 20(%ebp)\n\t"
272 "pushl 16(%ebp)\n\t"
273 "pushl 12(%ebp)\n\t"
274 "movl 8(%ebp),%eax\n\t"
275 "call *%eax\n\t"
276 "leal -12(%ebp),%esp\n\t"
277 "popl %ebx\n\t"
278 "popl %esi\n\t"
279 "popl %edi\n\t"
280 "leave\n\t"
281 "ret" );
282 #else
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;
293 to->top = from->top;
294 to->right = from->right;
295 to->bottom = from->bottom;
298 static void RECT32to16( const RECT *from, RECT16 *to )
300 to->left = from->left;
301 to->top = from->top;
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);
338 to->x = from->x;
339 to->y = from->y;
340 to->cx = from->cx;
341 to->cy = from->cy;
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);
350 to->x = from->x;
351 to->y = from->y;
352 to->cx = from->cx;
353 to->cy = from->cy;
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);
364 to->cy = from->cy;
365 to->cx = from->cx;
366 to->y = from->y;
367 to->x = from->x;
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);
379 to->cy = from->cy;
380 to->cx = from->cx;
381 to->y = from->y;
382 to->x = from->x;
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);
393 to->x = from->x;
394 to->y = from->y;
395 to->cx = from->cx;
396 to->cy = from->cy;
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);
404 to->x = from->x;
405 to->y = from->y;
406 to->cx = from->cx;
407 to->cy = from->cy;
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 )
416 CHAR ch[2];
417 WCHAR wch;
419 ch[0] = (wParam >> 8);
420 ch[1] = wParam & 0xff;
421 if (len > 1 && ch[0])
422 RtlMultiByteToUnicodeN( &wch, sizeof(wch), NULL, ch, 2 );
423 else
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 )
430 WCHAR wch = wParam;
431 BYTE ch[2];
433 RtlUnicodeToMultiByteN( (LPSTR)ch, len, &len, &wch, sizeof(wch) );
434 if (len == 2)
435 return MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wParam) );
436 else
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 )
443 WNDPROC proc = arg;
445 USER_CheckNotLock();
447 hwnd = WIN_GetFullHandle( hwnd );
448 if (TRACE_ON(relay))
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 );
454 if (TRACE_ON(relay))
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 );
457 return *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 )
463 WNDPROC proc = arg;
464 LRESULT ret;
466 USER_CheckNotLock();
468 hwnd = WIN_GetFullHandle( hwnd );
469 if (TRACE_ON(relay))
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 );
476 if (TRACE_ON(relay))
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 );
479 return ret;
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;
487 CONTEXT86 context;
488 size_t size = 0;
489 struct
491 WORD params[5];
492 union
494 CREATESTRUCT16 cs16;
495 DRAWITEMSTRUCT16 dis16;
496 COMPAREITEMSTRUCT16 cis16;
497 } u;
498 } args;
500 USER_CheckNotLock();
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;
513 if (lParam)
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. */
521 switch (msg)
523 case WM_CREATE:
524 case WM_NCCREATE:
525 size = sizeof(CREATESTRUCT16); break;
526 case WM_DRAWITEM:
527 size = sizeof(DRAWITEMSTRUCT16); break;
528 case WM_COMPAREITEM:
529 size = sizeof(COMPAREITEMSTRUCT16); break;
531 if (size)
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) );
545 return *result;
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 );
554 return LOWORD(ret);
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 /**********************************************************************
587 * WINPROC_GetProc16
589 * Get a window procedure pointer that can be passed to the Windows program.
591 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
593 WINDOWPROC *ptr;
595 if (unicode) ptr = alloc_winproc( NULL, proc );
596 else ptr = alloc_winproc( proc, NULL );
598 if (!ptr) return 0;
599 return alloc_win16_thunk( ptr );
603 /**********************************************************************
604 * WINPROC_GetProc
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;
613 if (unicode)
615 if (ptr->procW) return ptr->procW;
616 return proc;
618 else
620 if (ptr->procA) return ptr->procA;
621 return proc;
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 )
637 WINDOWPROC *proc;
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++];
652 proc->proc16 = func;
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 /**********************************************************************
667 * WINPROC_AllocProc
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 )
677 WINDOWPROC *proc;
679 if (!(proc = alloc_winproc( funcA, funcW ))) return NULL;
680 return proc_to_handle( proc );
684 /**********************************************************************
685 * WINPROC_IsUnicode
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));
709 else
710 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
715 static UINT convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
717 HANDLE dst;
718 UINT sz = GlobalSize16(src);
719 LPSTR ptr16, ptr32;
721 if (!(dst = GlobalAlloc(flags, sz)))
722 return 0;
723 ptr16 = GlobalLock16(src);
724 ptr32 = GlobalLock(dst);
725 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
726 GlobalUnlock16(src);
727 GlobalUnlock(dst);
729 return (UINT)dst;
732 static HANDLE16 convert_handle_32_to_16(UINT src, unsigned int flags)
734 HANDLE16 dst;
735 UINT sz = GlobalSize((HANDLE)src);
736 LPSTR ptr16, ptr32;
738 if (!(dst = GlobalAlloc16(flags, sz)))
739 return 0;
740 ptr32 = GlobalLock((HANDLE)src);
741 ptr16 = GlobalLock16(dst);
742 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
743 GlobalUnlock((HANDLE)src);
744 GlobalUnlock16(dst);
746 return dst;
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);
761 switch(msg32)
763 case EM_GETSEL:
764 case EM_GETRECT:
765 case EM_SETRECT:
766 case EM_SETRECTNP:
767 case EM_SCROLL:
768 case EM_LINESCROLL:
769 case EM_SCROLLCARET:
770 case EM_GETMODIFY:
771 case EM_SETMODIFY:
772 case EM_GETLINECOUNT:
773 case EM_LINEINDEX:
774 case EM_SETHANDLE:
775 case EM_GETHANDLE:
776 case EM_GETTHUMB:
777 case EM_LINELENGTH:
778 case EM_REPLACESEL:
779 case EM_GETLINE:
780 case EM_LIMITTEXT:
781 case EM_CANUNDO:
782 case EM_UNDO:
783 case EM_FMTLINES:
784 case EM_LINEFROMCHAR:
785 case EM_SETTABSTOPS:
786 case EM_SETPASSWORDCHAR:
787 case EM_EMPTYUNDOBUFFER:
788 case EM_GETFIRSTVISIBLELINE:
789 case EM_SETREADONLY:
790 case EM_SETWORDBREAKPROC:
791 case EM_GETWORDBREAKPROC:
792 case EM_GETPASSWORDCHAR:
793 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
794 return 0;
796 case LB_CARETOFF:
797 case LB_CARETON:
798 case LB_DELETESTRING:
799 case LB_GETANCHORINDEX:
800 case LB_GETCARETINDEX:
801 case LB_GETCOUNT:
802 case LB_GETCURSEL:
803 case LB_GETHORIZONTALEXTENT:
804 case LB_GETITEMDATA:
805 case LB_GETITEMHEIGHT:
806 case LB_GETSEL:
807 case LB_GETSELCOUNT:
808 case LB_GETTEXTLEN:
809 case LB_GETTOPINDEX:
810 case LB_RESETCONTENT:
811 case LB_SELITEMRANGE:
812 case LB_SELITEMRANGEEX:
813 case LB_SETANCHORINDEX:
814 case LB_SETCARETINDEX:
815 case LB_SETCOLUMNWIDTH:
816 case LB_SETCURSEL:
817 case LB_SETHORIZONTALEXTENT:
818 case LB_SETITEMDATA:
819 case LB_SETITEMHEIGHT:
820 case LB_SETSEL:
821 case LB_SETTOPINDEX:
822 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
823 return 0;
824 case CB_DELETESTRING:
825 case CB_GETCOUNT:
826 case CB_GETLBTEXTLEN:
827 case CB_LIMITTEXT:
828 case CB_RESETCONTENT:
829 case CB_SETEDITSEL:
830 case CB_GETCURSEL:
831 case CB_SETCURSEL:
832 case CB_SHOWDROPDOWN:
833 case CB_SETITEMDATA:
834 case CB_SETITEMHEIGHT:
835 case CB_GETITEMHEIGHT:
836 case CB_SETEXTENDEDUI:
837 case CB_GETEXTENDEDUI:
838 case CB_GETDROPPEDSTATE:
839 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
840 return 0;
841 case CB_GETEDITSEL:
842 *pmsg16 = CB_GETEDITSEL16;
843 return 1;
845 case LB_ADDSTRING:
846 case LB_FINDSTRING:
847 case LB_FINDSTRINGEXACT:
848 case LB_INSERTSTRING:
849 case LB_SELECTSTRING:
850 case LB_DIR:
851 case LB_ADDFILE:
852 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
853 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
854 return 1;
856 case CB_ADDSTRING:
857 case CB_FINDSTRING:
858 case CB_FINDSTRINGEXACT:
859 case CB_INSERTSTRING:
860 case CB_SELECTSTRING:
861 case CB_DIR:
862 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
863 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
864 return 1;
866 case LB_GETITEMRECT:
868 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
869 if (!rect) return -1;
870 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
871 *plparam = MapLS( rect );
873 *pmsg16 = LB_GETITEMRECT16;
874 return 1;
875 case LB_GETSELITEMS:
877 LPARAM *items; /* old LPARAM first, then *pwparam16 x INT16 entries */
879 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
880 if (!(items = HeapAlloc( GetProcessHeap(), 0,
881 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
882 *items++ = *plparam; /* Store the previous lParam */
883 *plparam = MapLS( items );
885 *pmsg16 = LB_GETSELITEMS16;
886 return 1;
887 case LB_SETTABSTOPS:
888 if (wParam32)
890 INT i;
891 LPINT16 stops;
892 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
893 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
894 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
895 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
896 *plparam = MapLS( stops );
897 return 1;
899 *pmsg16 = LB_SETTABSTOPS16;
900 return 0;
902 case CB_GETDROPPEDCONTROLRECT:
904 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
905 if (!rect) return -1;
906 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
907 *plparam = (LPARAM)MapLS(rect);
909 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
910 return 1;
912 case LB_GETTEXT:
913 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
914 *pmsg16 = LB_GETTEXT16;
915 return 1;
917 case CB_GETLBTEXT:
918 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
919 *pmsg16 = CB_GETLBTEXT16;
920 return 1;
922 case EM_SETSEL:
923 *pwparam16 = 0;
924 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
925 *pmsg16 = EM_SETSEL16;
926 return 0;
928 case WM_ACTIVATE:
929 case WM_CHARTOITEM:
930 case WM_COMMAND:
931 case WM_VKEYTOITEM:
932 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
933 return 0;
934 case WM_HSCROLL:
935 case WM_VSCROLL:
936 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
937 return 0;
938 case WM_CTLCOLORMSGBOX:
939 case WM_CTLCOLOREDIT:
940 case WM_CTLCOLORLISTBOX:
941 case WM_CTLCOLORBTN:
942 case WM_CTLCOLORDLG:
943 case WM_CTLCOLORSCROLLBAR:
944 case WM_CTLCOLORSTATIC:
945 *pmsg16 = WM_CTLCOLOR;
946 *plparam = MAKELPARAM( (HWND16)*plparam,
947 (WORD)msg32 - WM_CTLCOLORMSGBOX );
948 return 0;
949 case WM_MENUSELECT:
950 if(HIWORD(wParam32) & MF_POPUP)
952 HMENU hmenu;
953 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
955 if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
956 *pwparam16=HMENU_16(hmenu);
959 /* fall through */
960 case WM_MENUCHAR:
961 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
962 return 0;
963 case WM_PARENTNOTIFY:
964 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
965 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
966 /* else nothing to do */
967 return 0;
968 case WM_ACTIVATEAPP:
969 if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
970 return 0;
971 case WM_PAINT:
972 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
974 *pmsg16 = WM_PAINTICON;
975 *pwparam16 = 1;
977 return 0;
978 case WM_ERASEBKGND:
979 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
980 *pmsg16 = WM_ICONERASEBKGND;
981 return 0;
982 case WM_PAINTCLIPBOARD:
983 case WM_SIZECLIPBOARD:
984 FIXME_(msg)("message %04x needs translation\n", msg32 );
985 return -1;
986 /* following messages should not be sent to 16-bit apps */
987 case WM_SIZING:
988 case WM_MOVING:
989 case WM_CAPTURECHANGED:
990 case WM_STYLECHANGING:
991 case WM_STYLECHANGED:
992 return -1;
993 default: /* No translation needed */
994 return 0;
999 /**********************************************************************
1000 * WINPROC_UnmapMsg32ATo16
1002 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
1004 static void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1005 WPARAM16 wParam16, LPARAM lParam16, LRESULT *result )
1007 switch(msg)
1009 case LB_ADDFILE:
1010 case LB_ADDSTRING:
1011 case LB_DIR:
1012 case LB_FINDSTRING:
1013 case LB_FINDSTRINGEXACT:
1014 case LB_INSERTSTRING:
1015 case LB_SELECTSTRING:
1016 case LB_GETTEXT:
1017 case CB_ADDSTRING:
1018 case CB_FINDSTRING:
1019 case CB_FINDSTRINGEXACT:
1020 case CB_INSERTSTRING:
1021 case CB_SELECTSTRING:
1022 case CB_DIR:
1023 case CB_GETLBTEXT:
1024 UnMapLS( (SEGPTR)lParam16 );
1025 break;
1026 case LB_SETTABSTOPS:
1028 void *ptr = MapSL( lParam16 );
1029 UnMapLS( lParam16 );
1030 HeapFree( GetProcessHeap(), 0, ptr );
1032 break;
1033 case CB_GETDROPPEDCONTROLRECT:
1034 case LB_GETITEMRECT:
1036 RECT *r32;
1037 RECT16 *rect = MapSL(lParam16);
1038 UnMapLS( lParam16 );
1039 lParam16 = *(LPARAM *)(rect + 1);
1040 r32 = (RECT *)lParam16;
1041 r32->left = rect->left;
1042 r32->top = rect->top;
1043 r32->right = rect->right;
1044 r32->bottom = rect->bottom;
1045 HeapFree( GetProcessHeap(), 0, rect );
1047 break;
1048 case LB_GETSELITEMS:
1050 INT i;
1051 LPINT16 items = MapSL(lParam16);
1052 UnMapLS( lParam16 );
1053 lParam16 = *((LPARAM *)items - 1);
1054 for (i = 0; i < wParam16; i++) *((LPINT)lParam16 + i) = items[i];
1055 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
1057 break;
1059 case CB_GETEDITSEL:
1060 if( wParam )
1061 *((PUINT)(wParam)) = LOWORD(*result);
1062 if( lParam )
1063 *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: substract 1? */
1064 break;
1069 /**********************************************************************
1070 * WINPROC_CallProcAtoW
1072 * Call a window procedure, translating args from Ansi to Unicode.
1074 LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
1075 LPARAM lParam, LRESULT *result, void *arg )
1077 LRESULT ret = 0;
1079 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1080 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1082 switch(msg)
1084 case WM_NCCREATE:
1085 case WM_CREATE:
1087 WCHAR *ptr, buffer[512];
1088 CREATESTRUCTA *csA = (CREATESTRUCTA *)lParam;
1089 CREATESTRUCTW csW = *(CREATESTRUCTW *)csA;
1090 MDICREATESTRUCTW mdi_cs;
1091 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
1093 if (HIWORD(csA->lpszClass))
1095 class_lenA = strlen(csA->lpszClass) + 1;
1096 RtlMultiByteToUnicodeSize( &class_lenW, csA->lpszClass, class_lenA );
1098 if (HIWORD(csA->lpszName))
1100 name_lenA = strlen(csA->lpszName) + 1;
1101 RtlMultiByteToUnicodeSize( &name_lenW, csA->lpszName, name_lenA );
1104 if (!(ptr = get_buffer( buffer, sizeof(buffer), class_lenW + name_lenW ))) break;
1106 if (class_lenW)
1108 csW.lpszClass = ptr;
1109 RtlMultiByteToUnicodeN( ptr, class_lenW, NULL, csA->lpszClass, class_lenA );
1111 if (name_lenW)
1113 csW.lpszName = ptr + class_lenW/sizeof(WCHAR);
1114 RtlMultiByteToUnicodeN( ptr + class_lenW/sizeof(WCHAR), name_lenW, NULL,
1115 csA->lpszName, name_lenA );
1118 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1120 mdi_cs = *(MDICREATESTRUCTW *)csA->lpCreateParams;
1121 mdi_cs.szTitle = csW.lpszName;
1122 mdi_cs.szClass = csW.lpszClass;
1123 csW.lpCreateParams = &mdi_cs;
1126 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
1127 free_buffer( buffer, ptr );
1129 break;
1131 case WM_MDICREATE:
1133 WCHAR *ptr, buffer[512];
1134 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
1135 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1136 MDICREATESTRUCTW csW;
1138 memcpy( &csW, csA, sizeof(csW) );
1140 if (HIWORD(csA->szTitle))
1142 title_lenA = strlen(csA->szTitle) + 1;
1143 RtlMultiByteToUnicodeSize( &title_lenW, csA->szTitle, title_lenA );
1145 if (HIWORD(csA->szClass))
1147 class_lenA = strlen(csA->szClass) + 1;
1148 RtlMultiByteToUnicodeSize( &class_lenW, csA->szClass, class_lenA );
1151 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenW + class_lenW ))) break;
1153 if (title_lenW)
1155 csW.szTitle = ptr;
1156 RtlMultiByteToUnicodeN( ptr, title_lenW, NULL, csA->szTitle, title_lenA );
1158 if (class_lenW)
1160 csW.szClass = ptr + title_lenW/sizeof(WCHAR);
1161 RtlMultiByteToUnicodeN( ptr + title_lenW/sizeof(WCHAR), class_lenW, NULL,
1162 csA->szClass, class_lenA );
1164 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
1165 free_buffer( buffer, ptr );
1167 break;
1169 case WM_GETTEXT:
1170 case WM_ASKCBFORMATNAME:
1172 WCHAR *ptr, buffer[512];
1173 LPSTR str = (LPSTR)lParam;
1174 DWORD len = wParam * sizeof(WCHAR);
1176 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
1177 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1178 if (*result && wParam)
1180 RtlUnicodeToMultiByteN( str, wParam - 1, &len, ptr, strlenW(ptr) * sizeof(WCHAR) );
1181 str[len] = 0;
1182 *result = len;
1184 free_buffer( buffer, ptr );
1186 break;
1188 case LB_ADDSTRING:
1189 case LB_INSERTSTRING:
1190 case LB_FINDSTRING:
1191 case LB_FINDSTRINGEXACT:
1192 case LB_SELECTSTRING:
1193 case CB_ADDSTRING:
1194 case CB_INSERTSTRING:
1195 case CB_FINDSTRING:
1196 case CB_FINDSTRINGEXACT:
1197 case CB_SELECTSTRING:
1198 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
1200 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1201 break;
1203 /* fall through */
1204 case WM_SETTEXT:
1205 case WM_WININICHANGE:
1206 case WM_DEVMODECHANGE:
1207 case CB_DIR:
1208 case LB_DIR:
1209 case LB_ADDFILE:
1210 case EM_REPLACESEL:
1211 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
1212 else
1214 WCHAR *ptr, buffer[512];
1215 LPCSTR strA = (LPCSTR)lParam;
1216 DWORD lenW, lenA = strlen(strA) + 1;
1218 RtlMultiByteToUnicodeSize( &lenW, strA, lenA );
1219 if ((ptr = get_buffer( buffer, sizeof(buffer), lenW )))
1221 RtlMultiByteToUnicodeN( ptr, lenW, NULL, strA, lenA );
1222 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1223 free_buffer( buffer, ptr );
1226 break;
1228 case LB_GETTEXT:
1229 case CB_GETLBTEXT:
1230 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
1232 WCHAR buffer[512]; /* FIXME: fixed sized buffer */
1234 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1235 if (*result >= 0)
1237 DWORD len;
1238 RtlUnicodeToMultiByteN( (LPSTR)lParam, ~0u, &len,
1239 buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
1240 *result = len - 1;
1243 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1244 break;
1246 case EM_GETLINE:
1248 WCHAR *ptr, buffer[512];
1249 WORD len = *(WORD *)lParam;
1251 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
1252 *((WORD *)ptr) = len; /* store the length */
1253 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1254 if (*result)
1256 DWORD reslen;
1257 RtlUnicodeToMultiByteN( (LPSTR)lParam, len, &reslen, ptr, *result * sizeof(WCHAR) );
1258 if (reslen < len) ((LPSTR)lParam)[reslen] = 0;
1259 *result = reslen;
1261 free_buffer( buffer, ptr );
1263 break;
1265 case WM_GETDLGCODE:
1266 if (lParam)
1268 MSG newmsg = *(MSG *)lParam;
1269 switch(newmsg.message)
1271 case WM_CHAR:
1272 case WM_DEADCHAR:
1273 case WM_SYSCHAR:
1274 case WM_SYSDEADCHAR:
1275 newmsg.wParam = map_wparam_char_AtoW( newmsg.wParam, 1 );
1276 break;
1277 case WM_IME_CHAR:
1278 newmsg.wParam = map_wparam_char_AtoW( newmsg.wParam, 2 );
1279 break;
1281 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1283 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1284 break;
1286 case WM_CHARTOITEM:
1287 case WM_MENUCHAR:
1288 case WM_CHAR:
1289 case WM_DEADCHAR:
1290 case WM_SYSCHAR:
1291 case WM_SYSDEADCHAR:
1292 case EM_SETPASSWORDCHAR:
1293 ret = callback( hwnd, msg, map_wparam_char_AtoW(wParam,1), lParam, result, arg );
1294 break;
1296 case WM_IME_CHAR:
1297 ret = callback( hwnd, msg, map_wparam_char_AtoW(wParam,2), lParam, result, arg );
1298 break;
1300 case WM_GETTEXTLENGTH:
1301 case CB_GETLBTEXTLEN:
1302 case LB_GETTEXTLEN:
1303 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1304 if (*result >= 0)
1306 WCHAR *ptr, buffer[512];
1307 LRESULT tmp;
1308 DWORD len = *result + 1;
1309 /* Determine respective GETTEXT message */
1310 UINT msgGetText = (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
1311 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
1312 /* wParam differs between the messages */
1313 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? len : wParam;
1315 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
1317 if (callback == call_window_proc) /* FIXME: hack */
1318 callback( hwnd, msgGetText, wp, (LPARAM)ptr, &tmp, arg );
1319 else
1320 tmp = SendMessageW( hwnd, msgGetText, wp, (LPARAM)ptr );
1321 RtlUnicodeToMultiByteSize( &len, ptr, tmp * sizeof(WCHAR) );
1322 *result = len;
1323 free_buffer( buffer, ptr );
1325 break;
1327 case WM_PAINTCLIPBOARD:
1328 case WM_SIZECLIPBOARD:
1329 FIXME_(msg)( "message %s (0x%x) needs translation, please report\n",
1330 SPY_GetMsgName(msg, hwnd), msg );
1331 break;
1333 default:
1334 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1335 break;
1337 return ret;
1341 /**********************************************************************
1342 * WINPROC_CallProcWtoA
1344 * Call a window procedure, translating args from Unicode to Ansi.
1346 static LRESULT WINPROC_CallProcWtoA( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
1347 LPARAM lParam, LRESULT *result, void *arg )
1349 LRESULT ret = 0;
1351 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1352 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1354 switch(msg)
1356 case WM_NCCREATE:
1357 case WM_CREATE:
1358 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
1359 * at this point.
1361 char buffer[1024], *cls, *name;
1362 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
1363 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
1364 MDICREATESTRUCTA mdi_cs;
1365 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
1367 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
1368 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
1370 if (csW->lpszName)
1372 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
1373 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
1375 else
1376 name_lenW = name_lenA = 0;
1378 if (!(cls = get_buffer( buffer, sizeof(buffer), class_lenA + name_lenA + 2 ))) break;
1380 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
1381 cls[class_lenA] = 0;
1382 csA.lpszClass = cls;
1384 if (csW->lpszName)
1386 name = cls + class_lenA + 1;
1387 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
1388 name[name_lenA] = 0;
1389 csA.lpszName = name;
1392 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1394 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
1395 mdi_cs.szTitle = csA.lpszName;
1396 mdi_cs.szClass = csA.lpszClass;
1397 csA.lpCreateParams = &mdi_cs;
1400 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1401 free_buffer( buffer, cls );
1403 break;
1405 case WM_GETTEXT:
1406 case WM_ASKCBFORMATNAME:
1408 char *ptr, buffer[512];
1409 DWORD len = wParam * 2;
1411 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
1412 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1413 if (*result && len)
1415 RtlMultiByteToUnicodeN( (LPWSTR)lParam, wParam*sizeof(WCHAR), &len, ptr, strlen(ptr)+1 );
1416 *result = len/sizeof(WCHAR) - 1; /* do not count terminating null */
1417 ((LPWSTR)lParam)[*result] = 0;
1419 free_buffer( buffer, ptr );
1421 break;
1423 case LB_ADDSTRING:
1424 case LB_INSERTSTRING:
1425 case LB_FINDSTRING:
1426 case LB_FINDSTRINGEXACT:
1427 case LB_SELECTSTRING:
1428 case CB_ADDSTRING:
1429 case CB_INSERTSTRING:
1430 case CB_FINDSTRING:
1431 case CB_FINDSTRINGEXACT:
1432 case CB_SELECTSTRING:
1433 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
1435 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1436 break;
1438 /* fall through */
1439 case WM_SETTEXT:
1440 case WM_WININICHANGE:
1441 case WM_DEVMODECHANGE:
1442 case CB_DIR:
1443 case LB_DIR:
1444 case LB_ADDFILE:
1445 case EM_REPLACESEL:
1446 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
1447 else
1449 char *ptr, buffer[512];
1450 LPCWSTR strW = (LPCWSTR)lParam;
1451 DWORD lenA, lenW = (strlenW(strW) + 1) * sizeof(WCHAR);
1453 RtlUnicodeToMultiByteSize( &lenA, strW, lenW );
1454 if ((ptr = get_buffer( buffer, sizeof(buffer), lenA )))
1456 RtlUnicodeToMultiByteN( ptr, lenA, NULL, strW, lenW );
1457 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1458 free_buffer( buffer, ptr );
1461 break;
1463 case WM_MDICREATE:
1465 char *ptr, buffer[1024];
1466 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
1467 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1468 MDICREATESTRUCTA csA;
1470 memcpy( &csA, csW, sizeof(csA) );
1472 if (HIWORD(csW->szTitle))
1474 title_lenW = (strlenW(csW->szTitle) + 1) * sizeof(WCHAR);
1475 RtlUnicodeToMultiByteSize( &title_lenA, csW->szTitle, title_lenW );
1477 if (HIWORD(csW->szClass))
1479 class_lenW = (strlenW(csW->szClass) + 1) * sizeof(WCHAR);
1480 RtlUnicodeToMultiByteSize( &class_lenA, csW->szClass, class_lenW );
1483 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenA + class_lenA ))) break;
1485 if (title_lenA)
1487 RtlUnicodeToMultiByteN( ptr, title_lenA, NULL, csW->szTitle, title_lenW );
1488 csA.szTitle = ptr;
1490 if (class_lenA)
1492 RtlUnicodeToMultiByteN( ptr + title_lenA, class_lenA, NULL, csW->szClass, class_lenW );
1493 csA.szClass = ptr + title_lenA;
1495 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1496 free_buffer( buffer, ptr );
1498 break;
1500 case LB_GETTEXT:
1501 case CB_GETLBTEXT:
1502 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
1504 char buffer[512]; /* FIXME: fixed sized buffer */
1506 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1507 if (*result >= 0)
1509 DWORD len;
1510 RtlMultiByteToUnicodeN( (LPWSTR)lParam, ~0u, &len, buffer, strlen(buffer) + 1 );
1511 *result = len / sizeof(WCHAR) - 1;
1514 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1515 break;
1517 case EM_GETLINE:
1519 char *ptr, buffer[512];
1520 WORD len = *(WORD *)lParam;
1522 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * 2 ))) break;
1523 *((WORD *)ptr) = len * 2; /* store the length */
1524 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1525 if (*result)
1527 DWORD reslen;
1528 RtlMultiByteToUnicodeN( (LPWSTR)lParam, len*sizeof(WCHAR), &reslen, ptr, *result );
1529 *result = reslen / sizeof(WCHAR);
1530 if (*result < len) ((LPWSTR)lParam)[*result] = 0;
1532 free_buffer( buffer, ptr );
1534 break;
1536 case WM_GETDLGCODE:
1537 if (lParam)
1539 MSG newmsg = *(MSG *)lParam;
1540 switch(newmsg.message)
1542 case WM_CHAR:
1543 case WM_DEADCHAR:
1544 case WM_SYSCHAR:
1545 case WM_SYSDEADCHAR:
1546 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 1 );
1547 break;
1548 case WM_IME_CHAR:
1549 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 2 );
1550 break;
1552 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1554 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1555 break;
1557 case WM_CHARTOITEM:
1558 case WM_MENUCHAR:
1559 case WM_CHAR:
1560 case WM_DEADCHAR:
1561 case WM_SYSCHAR:
1562 case WM_SYSDEADCHAR:
1563 case EM_SETPASSWORDCHAR:
1564 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,1), lParam, result, arg );
1565 break;
1567 case WM_IME_CHAR:
1568 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,2), lParam, result, arg );
1569 break;
1571 case WM_PAINTCLIPBOARD:
1572 case WM_SIZECLIPBOARD:
1573 FIXME_(msg)( "message %s (%04x) needs translation, please report\n",
1574 SPY_GetMsgName(msg, hwnd), msg );
1575 break;
1577 default:
1578 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1579 break;
1582 return ret;
1586 /**********************************************************************
1587 * WINPROC_CallProc16To32A
1589 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
1590 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
1592 LRESULT ret = 0;
1593 HWND hwnd32 = WIN_Handle32( hwnd );
1595 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1596 hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
1598 switch(msg)
1600 case WM_NCCREATE:
1601 case WM_CREATE:
1603 CREATESTRUCT16 *cs16 = MapSL(lParam);
1604 CREATESTRUCTA cs;
1605 MDICREATESTRUCTA mdi_cs;
1607 CREATESTRUCT16to32A( cs16, &cs );
1608 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
1610 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
1611 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
1612 cs.lpCreateParams = &mdi_cs;
1614 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1615 CREATESTRUCT32Ato16( &cs, cs16 );
1617 break;
1618 case WM_MDICREATE:
1620 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
1621 MDICREATESTRUCTA cs;
1623 MDICREATESTRUCT16to32A( cs16, &cs );
1624 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1625 MDICREATESTRUCT32Ato16( &cs, cs16 );
1627 break;
1628 case WM_MDIACTIVATE:
1629 if (lParam)
1630 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
1631 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1632 else /* message sent to MDI client */
1633 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1634 break;
1635 case WM_MDIGETACTIVE:
1637 BOOL maximized = FALSE;
1638 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
1639 *result = MAKELRESULT( LOWORD(*result), maximized );
1641 break;
1642 case WM_MDISETMENU:
1643 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
1644 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
1645 result, arg );
1646 break;
1647 case WM_GETMINMAXINFO:
1649 MINMAXINFO16 *mmi16 = MapSL(lParam);
1650 MINMAXINFO mmi;
1652 MINMAXINFO16to32( mmi16, &mmi );
1653 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
1654 MINMAXINFO32to16( &mmi, mmi16 );
1656 break;
1657 case WM_WINDOWPOSCHANGING:
1658 case WM_WINDOWPOSCHANGED:
1660 WINDOWPOS16 *winpos16 = MapSL(lParam);
1661 WINDOWPOS winpos;
1663 WINDOWPOS16to32( winpos16, &winpos );
1664 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
1665 WINDOWPOS32to16( &winpos, winpos16 );
1667 break;
1668 case WM_NCCALCSIZE:
1670 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
1671 NCCALCSIZE_PARAMS nc;
1672 WINDOWPOS winpos;
1674 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
1675 if (wParam)
1677 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
1678 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
1679 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
1680 nc.lppos = &winpos;
1682 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
1683 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
1684 if (wParam)
1686 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
1687 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
1688 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
1691 break;
1692 case WM_COMPAREITEM:
1694 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
1695 COMPAREITEMSTRUCT cis;
1696 cis.CtlType = cis16->CtlType;
1697 cis.CtlID = cis16->CtlID;
1698 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
1699 cis.itemID1 = cis16->itemID1;
1700 cis.itemData1 = cis16->itemData1;
1701 cis.itemID2 = cis16->itemID2;
1702 cis.itemData2 = cis16->itemData2;
1703 cis.dwLocaleId = 0; /* FIXME */
1704 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
1706 break;
1707 case WM_DELETEITEM:
1709 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
1710 DELETEITEMSTRUCT dis;
1711 dis.CtlType = dis16->CtlType;
1712 dis.CtlID = dis16->CtlID;
1713 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
1714 dis.itemData = dis16->itemData;
1715 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1717 break;
1718 case WM_MEASUREITEM:
1720 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1721 MEASUREITEMSTRUCT mis;
1722 mis.CtlType = mis16->CtlType;
1723 mis.CtlID = mis16->CtlID;
1724 mis.itemID = mis16->itemID;
1725 mis.itemWidth = mis16->itemWidth;
1726 mis.itemHeight = mis16->itemHeight;
1727 mis.itemData = mis16->itemData;
1728 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
1729 mis16->itemWidth = (UINT16)mis.itemWidth;
1730 mis16->itemHeight = (UINT16)mis.itemHeight;
1732 break;
1733 case WM_DRAWITEM:
1735 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1736 DRAWITEMSTRUCT dis;
1737 dis.CtlType = dis16->CtlType;
1738 dis.CtlID = dis16->CtlID;
1739 dis.itemID = dis16->itemID;
1740 dis.itemAction = dis16->itemAction;
1741 dis.itemState = dis16->itemState;
1742 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1743 : WIN_Handle32( dis16->hwndItem );
1744 dis.hDC = HDC_32(dis16->hDC);
1745 dis.itemData = dis16->itemData;
1746 dis.rcItem.left = dis16->rcItem.left;
1747 dis.rcItem.top = dis16->rcItem.top;
1748 dis.rcItem.right = dis16->rcItem.right;
1749 dis.rcItem.bottom = dis16->rcItem.bottom;
1750 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1752 break;
1753 case WM_COPYDATA:
1755 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
1756 COPYDATASTRUCT cds;
1757 cds.dwData = cds16->dwData;
1758 cds.cbData = cds16->cbData;
1759 cds.lpData = MapSL(cds16->lpData);
1760 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
1762 break;
1763 case WM_GETDLGCODE:
1764 if (lParam)
1766 MSG16 *msg16 = MapSL(lParam);
1767 MSG msg32;
1768 msg32.hwnd = WIN_Handle32( msg16->hwnd );
1769 msg32.message = msg16->message;
1770 msg32.wParam = msg16->wParam;
1771 msg32.lParam = msg16->lParam;
1772 msg32.time = msg16->time;
1773 msg32.pt.x = msg16->pt.x;
1774 msg32.pt.y = msg16->pt.y;
1775 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
1777 else
1778 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1779 break;
1780 case WM_NEXTMENU:
1782 MDINEXTMENU next;
1783 next.hmenuIn = (HMENU)lParam;
1784 next.hmenuNext = 0;
1785 next.hwndNext = 0;
1786 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
1787 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
1789 break;
1790 case WM_ACTIVATE:
1791 case WM_CHARTOITEM:
1792 case WM_COMMAND:
1793 case WM_VKEYTOITEM:
1794 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1795 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1796 break;
1797 case WM_HSCROLL:
1798 case WM_VSCROLL:
1799 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1800 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
1801 break;
1802 case WM_CTLCOLOR:
1803 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
1804 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
1805 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
1806 result, arg );
1807 break;
1808 case WM_GETTEXT:
1809 case WM_SETTEXT:
1810 case WM_WININICHANGE:
1811 case WM_DEVMODECHANGE:
1812 case WM_ASKCBFORMATNAME:
1813 case WM_NOTIFY:
1814 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
1815 break;
1816 case WM_MENUCHAR:
1817 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1818 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1819 break;
1820 case WM_MENUSELECT:
1821 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
1823 HMENU hmenu = HMENU_32(HIWORD(lParam));
1824 UINT pos = MENU_FindSubMenu( &hmenu, HMENU_32(wParam) );
1825 if (pos == 0xffff) pos = 0; /* NO_SELECTED_ITEM */
1826 wParam = pos;
1828 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1829 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1830 break;
1831 case WM_PARENTNOTIFY:
1832 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
1833 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1834 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1835 else
1836 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1837 break;
1838 case WM_ACTIVATEAPP:
1839 /* We need this when SetActiveWindow sends a Sendmessage16() to
1840 * a 32bit window. Might be superflous with 32bit interprocess
1841 * message queues. */
1842 ret = callback( hwnd32, msg, wParam, HTASK_32(lParam), result, arg );
1843 break;
1844 case WM_DDE_INITIATE:
1845 case WM_DDE_TERMINATE:
1846 case WM_DDE_UNADVISE:
1847 case WM_DDE_REQUEST:
1848 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1849 break;
1850 case WM_DDE_ADVISE:
1851 case WM_DDE_DATA:
1852 case WM_DDE_POKE:
1854 HANDLE16 lo16 = LOWORD(lParam);
1855 UINT lo32 = 0;
1856 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
1857 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
1858 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1860 break; /* FIXME don't know how to free allocated memory (handle) !! */
1861 case WM_DDE_ACK:
1863 UINT lo = LOWORD(lParam);
1864 UINT hi = HIWORD(lParam);
1865 int flag = 0;
1866 char buf[2];
1868 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1869 if (GlobalSize16(hi) != 0) flag |= 2;
1870 switch (flag)
1872 case 0:
1873 if (hi)
1875 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1876 hi = 0;
1878 break;
1879 case 1:
1880 break; /* atom, nothing to do */
1881 case 3:
1882 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1883 /* fall thru */
1884 case 2:
1885 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1886 break;
1888 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
1889 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1891 break; /* FIXME don't know how to free allocated memory (handle) !! */
1892 case WM_DDE_EXECUTE:
1893 lParam = convert_handle_16_to_32( lParam, GMEM_DDESHARE );
1894 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1895 break; /* FIXME don't know how to free allocated memory (handle) !! */
1896 case WM_PAINTCLIPBOARD:
1897 case WM_SIZECLIPBOARD:
1898 FIXME_(msg)( "message %04x needs translation\n", msg );
1899 break;
1900 default:
1901 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1902 break;
1904 return ret;
1908 /**********************************************************************
1909 * __wine_call_wndproc (USER.1010)
1911 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
1912 WINDOWPROC *proc )
1914 LRESULT result;
1916 if (proc->procA)
1917 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
1918 else
1919 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
1920 return result;
1924 /**********************************************************************
1925 * WINPROC_CallProc32ATo16
1927 * Call a 16-bit window procedure, translating the 32-bit args.
1929 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
1930 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
1932 LRESULT ret = 0;
1934 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1935 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1937 switch(msg)
1939 case WM_NCCREATE:
1940 case WM_CREATE:
1942 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
1943 CREATESTRUCT16 cs;
1944 MDICREATESTRUCT16 mdi_cs16;
1945 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
1947 CREATESTRUCT32Ato16( cs32, &cs );
1948 cs.lpszName = MapLS( cs32->lpszName );
1949 cs.lpszClass = MapLS( cs32->lpszClass );
1951 if (mdi_child)
1953 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
1954 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
1955 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
1956 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
1957 cs.lpCreateParams = MapLS( &mdi_cs16 );
1959 lParam = MapLS( &cs );
1960 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1961 UnMapLS( lParam );
1962 UnMapLS( cs.lpszName );
1963 UnMapLS( cs.lpszClass );
1964 if (mdi_child)
1966 UnMapLS( cs.lpCreateParams );
1967 UnMapLS( mdi_cs16.szTitle );
1968 UnMapLS( mdi_cs16.szClass );
1971 break;
1972 case WM_MDICREATE:
1974 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
1975 MDICREATESTRUCT16 cs;
1977 MDICREATESTRUCT32Ato16( cs32, &cs );
1978 cs.szTitle = MapLS( cs32->szTitle );
1979 cs.szClass = MapLS( cs32->szClass );
1980 lParam = MapLS( &cs );
1981 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1982 UnMapLS( lParam );
1983 UnMapLS( cs.szTitle );
1984 UnMapLS( cs.szClass );
1986 break;
1987 case WM_MDIACTIVATE:
1988 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1989 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
1990 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
1991 else
1992 ret = callback( HWND_16(hwnd), msg, HWND_16( (HWND)wParam ), 0, result, arg );
1993 break;
1994 case WM_MDIGETACTIVE:
1995 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1996 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
1997 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
1998 break;
1999 case WM_MDISETMENU:
2000 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
2001 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
2002 break;
2003 case WM_GETMINMAXINFO:
2005 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
2006 MINMAXINFO16 mmi;
2008 MINMAXINFO32to16( mmi32, &mmi );
2009 lParam = MapLS( &mmi );
2010 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2011 UnMapLS( lParam );
2012 MINMAXINFO16to32( &mmi, mmi32 );
2014 break;
2015 case WM_NCCALCSIZE:
2017 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
2018 NCCALCSIZE_PARAMS16 nc;
2019 WINDOWPOS16 winpos;
2021 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
2022 if (wParam)
2024 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
2025 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
2026 WINDOWPOS32to16( nc32->lppos, &winpos );
2027 nc.lppos = MapLS( &winpos );
2029 lParam = MapLS( &nc );
2030 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2031 UnMapLS( lParam );
2032 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
2033 if (wParam)
2035 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
2036 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
2037 WINDOWPOS16to32( &winpos, nc32->lppos );
2038 UnMapLS( nc.lppos );
2041 break;
2042 case WM_WINDOWPOSCHANGING:
2043 case WM_WINDOWPOSCHANGED:
2045 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
2046 WINDOWPOS16 winpos;
2048 WINDOWPOS32to16( winpos32, &winpos );
2049 lParam = MapLS( &winpos );
2050 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2051 UnMapLS( lParam );
2052 WINDOWPOS16to32( &winpos, winpos32 );
2054 break;
2055 case WM_COMPAREITEM:
2057 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
2058 COMPAREITEMSTRUCT16 cis;
2059 cis.CtlType = cis32->CtlType;
2060 cis.CtlID = cis32->CtlID;
2061 cis.hwndItem = HWND_16( cis32->hwndItem );
2062 cis.itemID1 = cis32->itemID1;
2063 cis.itemData1 = cis32->itemData1;
2064 cis.itemID2 = cis32->itemID2;
2065 cis.itemData2 = cis32->itemData2;
2066 lParam = MapLS( &cis );
2067 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2068 UnMapLS( lParam );
2070 break;
2071 case WM_DELETEITEM:
2073 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
2074 DELETEITEMSTRUCT16 dis;
2075 dis.CtlType = dis32->CtlType;
2076 dis.CtlID = dis32->CtlID;
2077 dis.itemID = dis32->itemID;
2078 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
2079 : HWND_16( dis32->hwndItem );
2080 dis.itemData = dis32->itemData;
2081 lParam = MapLS( &dis );
2082 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2083 UnMapLS( lParam );
2085 break;
2086 case WM_DRAWITEM:
2088 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
2089 DRAWITEMSTRUCT16 dis;
2090 dis.CtlType = dis32->CtlType;
2091 dis.CtlID = dis32->CtlID;
2092 dis.itemID = dis32->itemID;
2093 dis.itemAction = dis32->itemAction;
2094 dis.itemState = dis32->itemState;
2095 dis.hwndItem = HWND_16( dis32->hwndItem );
2096 dis.hDC = HDC_16(dis32->hDC);
2097 dis.itemData = dis32->itemData;
2098 dis.rcItem.left = dis32->rcItem.left;
2099 dis.rcItem.top = dis32->rcItem.top;
2100 dis.rcItem.right = dis32->rcItem.right;
2101 dis.rcItem.bottom = dis32->rcItem.bottom;
2102 lParam = MapLS( &dis );
2103 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2104 UnMapLS( lParam );
2106 break;
2107 case WM_MEASUREITEM:
2109 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
2110 MEASUREITEMSTRUCT16 mis;
2111 mis.CtlType = mis32->CtlType;
2112 mis.CtlID = mis32->CtlID;
2113 mis.itemID = mis32->itemID;
2114 mis.itemWidth = mis32->itemWidth;
2115 mis.itemHeight = mis32->itemHeight;
2116 mis.itemData = mis32->itemData;
2117 lParam = MapLS( &mis );
2118 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2119 UnMapLS( lParam );
2120 mis32->itemWidth = mis.itemWidth;
2121 mis32->itemHeight = mis.itemHeight;
2123 break;
2124 case WM_COPYDATA:
2126 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
2127 COPYDATASTRUCT16 cds;
2129 cds.dwData = cds32->dwData;
2130 cds.cbData = cds32->cbData;
2131 cds.lpData = MapLS( cds32->lpData );
2132 lParam = MapLS( &cds );
2133 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2134 UnMapLS( lParam );
2135 UnMapLS( cds.lpData );
2137 break;
2138 case WM_GETDLGCODE:
2139 if (lParam)
2141 MSG *msg32 = (MSG *)lParam;
2142 MSG16 msg16;
2144 msg16.hwnd = HWND_16( msg32->hwnd );
2145 msg16.message = msg32->message;
2146 msg16.wParam = msg32->wParam;
2147 msg16.lParam = msg32->lParam;
2148 msg16.time = msg32->time;
2149 msg16.pt.x = msg32->pt.x;
2150 msg16.pt.y = msg32->pt.y;
2151 lParam = MapLS( &msg16 );
2152 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2153 UnMapLS( lParam );
2155 else
2156 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2157 break;
2158 case WM_NEXTMENU:
2160 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2161 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
2162 next->hmenuNext = HMENU_32( LOWORD(*result) );
2163 next->hwndNext = WIN_Handle32( HIWORD(*result) );
2164 *result = 0;
2166 break;
2167 case WM_GETTEXT:
2168 case WM_ASKCBFORMATNAME:
2169 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
2170 /* fall through */
2171 case WM_NOTIFY:
2172 case WM_SETTEXT:
2173 case WM_WININICHANGE:
2174 case WM_DEVMODECHANGE:
2175 lParam = MapLS( (void *)lParam );
2176 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2177 UnMapLS( lParam );
2178 break;
2179 case WM_DDE_INITIATE:
2180 case WM_DDE_TERMINATE:
2181 case WM_DDE_UNADVISE:
2182 case WM_DDE_REQUEST:
2183 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam), lParam, result, arg );
2184 break;
2185 case WM_DDE_ADVISE:
2186 case WM_DDE_DATA:
2187 case WM_DDE_POKE:
2189 UINT_PTR lo32, hi;
2190 HANDLE16 lo16 = 0;
2192 UnpackDDElParam( msg, lParam, &lo32, &hi );
2193 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
2194 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
2195 MAKELPARAM(lo16, hi), result, arg );
2197 break; /* FIXME don't know how to free allocated memory (handle) !! */
2198 case WM_DDE_ACK:
2200 UINT_PTR lo, hi;
2201 int flag = 0;
2202 char buf[2];
2204 UnpackDDElParam( msg, lParam, &lo, &hi );
2206 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
2207 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
2208 switch (flag)
2210 case 0:
2211 if (hi)
2213 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2214 hi = 0;
2216 break;
2217 case 1:
2218 break; /* atom, nothing to do */
2219 case 3:
2220 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
2221 /* fall thru */
2222 case 2:
2223 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
2224 break;
2226 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
2227 MAKELPARAM(lo, hi), result, arg );
2229 break; /* FIXME don't know how to free allocated memory (handle) !! */
2230 case WM_DDE_EXECUTE:
2231 lParam = convert_handle_32_to_16(lParam, GMEM_DDESHARE);
2232 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2233 break; /* FIXME don't know how to free allocated memory (handle) !! */
2234 case SBM_SETRANGE:
2235 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
2236 break;
2237 case SBM_GETRANGE:
2238 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
2239 *(LPINT)wParam = LOWORD(*result);
2240 *(LPINT)lParam = HIWORD(*result);
2241 break;
2242 case BM_GETCHECK:
2243 case BM_SETCHECK:
2244 case BM_GETSTATE:
2245 case BM_SETSTATE:
2246 case BM_SETSTYLE:
2247 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
2248 break;
2249 default:
2251 UINT16 msg16;
2252 WPARAM16 wParam16;
2253 LPARAM lParam16 = lParam;
2254 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &wParam16, &lParam16 ) != -1)
2256 ret = callback( HWND_16(hwnd), msg16, wParam16, lParam16, result, arg );
2257 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, wParam16, lParam16, result );
2260 break;
2262 return ret;
2266 /**********************************************************************
2267 * CallWindowProc (USER.122)
2269 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2270 WPARAM16 wParam, LPARAM lParam )
2272 WINDOWPROC *proc;
2273 LRESULT result;
2275 if (!func) return 0;
2277 if (!(proc = handle16_to_proc( func )))
2278 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
2279 else if (proc->procA)
2280 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2281 else if (proc->procW)
2282 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
2283 else
2284 call_window_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2286 return result;
2290 /**********************************************************************
2291 * CallWindowProcA (USER32.@)
2293 * The CallWindowProc() function invokes the windows procedure _func_,
2294 * with _hwnd_ as the target window, the message specified by _msg_, and
2295 * the message parameters _wParam_ and _lParam_.
2297 * Some kinds of argument conversion may be done, I'm not sure what.
2299 * CallWindowProc() may be used for windows subclassing. Use
2300 * SetWindowLong() to set a new windows procedure for windows of the
2301 * subclass, and handle subclassed messages in the new windows
2302 * procedure. The new windows procedure may then use CallWindowProc()
2303 * with _func_ set to the parent class's windows procedure to dispatch
2304 * the message to the superclass.
2306 * RETURNS
2308 * The return value is message dependent.
2310 * CONFORMANCE
2312 * ECMA-234, Win32
2314 LRESULT WINAPI CallWindowProcA(
2315 WNDPROC func, /* [in] window procedure */
2316 HWND hwnd, /* [in] target window */
2317 UINT msg, /* [in] message */
2318 WPARAM wParam, /* [in] message dependent parameter */
2319 LPARAM lParam /* [in] message dependent parameter */
2321 WINDOWPROC *proc;
2322 LRESULT result;
2324 if (!func) return 0;
2326 if (!(proc = handle_to_proc( func )))
2327 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2328 else if (proc->procA)
2329 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2330 else if (proc->procW)
2331 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procW );
2332 else
2333 WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2334 return result;
2338 /**********************************************************************
2339 * CallWindowProcW (USER32.@)
2341 * See CallWindowProcA.
2343 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2344 WPARAM wParam, LPARAM lParam )
2346 WINDOWPROC *proc;
2347 LRESULT result;
2349 if (!func) return 0;
2351 if (!(proc = handle_to_proc( func )))
2352 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2353 else if (proc->procW)
2354 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2355 else if (proc->procA)
2356 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2357 else
2358 WINPROC_CallProcWtoA( call_window_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2359 return result;
2363 /**********************************************************************
2364 * WINPROC_CallDlgProc16
2366 INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
2368 WINDOWPROC *proc;
2369 LRESULT result;
2370 INT_PTR ret;
2372 if (!func) return 0;
2374 if (!(proc = handle16_to_proc( (WNDPROC16)func )))
2376 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, func );
2378 else if (proc->procA)
2380 ret = WINPROC_CallProc16To32A( call_dialog_proc, hwnd, msg, wParam, lParam,
2381 &result, proc->procA );
2382 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2384 else if (proc->procW)
2386 ret = WINPROC_CallProc16To32A( call_dialog_proc_AtoW, hwnd, msg, wParam, lParam,
2387 &result, proc->procW );
2388 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2390 else
2392 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2394 return ret;
2398 /**********************************************************************
2399 * WINPROC_CallDlgProcA
2401 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2403 WINDOWPROC *proc;
2404 LRESULT result;
2405 INT_PTR ret;
2407 if (!func) return 0;
2409 if (!(proc = handle_to_proc( (WNDPROC)func )))
2410 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2411 else if (proc->procA)
2412 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2413 else if (proc->procW)
2415 ret = WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procW );
2416 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2418 else
2420 ret = WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2421 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2423 return ret;
2427 /**********************************************************************
2428 * WINPROC_CallDlgProcW
2430 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2432 WINDOWPROC *proc;
2433 LRESULT result;
2434 INT_PTR ret;
2436 if (!func) return 0;
2438 if (!(proc = handle_to_proc( (WNDPROC)func )))
2439 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2440 else if (proc->procW)
2441 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2442 else if (proc->procA)
2444 ret = WINPROC_CallProcWtoA( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2445 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2447 else
2449 ret = WINPROC_CallProcWtoA( call_dialog_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2450 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2452 return ret;