user: Added fast 32->16 mapping for the edit control messages.
[wine/multimedia.git] / dlls / user / winproc.c
blobd7b2f495381e05f7c2ef9157e1b6b0354a555b19
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 LB_CARETOFF:
764 case LB_CARETON:
765 case LB_DELETESTRING:
766 case LB_GETANCHORINDEX:
767 case LB_GETCARETINDEX:
768 case LB_GETCOUNT:
769 case LB_GETCURSEL:
770 case LB_GETHORIZONTALEXTENT:
771 case LB_GETITEMDATA:
772 case LB_GETITEMHEIGHT:
773 case LB_GETSEL:
774 case LB_GETSELCOUNT:
775 case LB_GETTEXTLEN:
776 case LB_GETTOPINDEX:
777 case LB_RESETCONTENT:
778 case LB_SELITEMRANGE:
779 case LB_SELITEMRANGEEX:
780 case LB_SETANCHORINDEX:
781 case LB_SETCARETINDEX:
782 case LB_SETCOLUMNWIDTH:
783 case LB_SETCURSEL:
784 case LB_SETHORIZONTALEXTENT:
785 case LB_SETITEMDATA:
786 case LB_SETITEMHEIGHT:
787 case LB_SETSEL:
788 case LB_SETTOPINDEX:
789 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
790 return 0;
791 case CB_DELETESTRING:
792 case CB_GETCOUNT:
793 case CB_GETLBTEXTLEN:
794 case CB_LIMITTEXT:
795 case CB_RESETCONTENT:
796 case CB_SETEDITSEL:
797 case CB_GETCURSEL:
798 case CB_SETCURSEL:
799 case CB_SHOWDROPDOWN:
800 case CB_SETITEMDATA:
801 case CB_SETITEMHEIGHT:
802 case CB_GETITEMHEIGHT:
803 case CB_SETEXTENDEDUI:
804 case CB_GETEXTENDEDUI:
805 case CB_GETDROPPEDSTATE:
806 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
807 return 0;
808 case CB_GETEDITSEL:
809 *pmsg16 = CB_GETEDITSEL16;
810 return 1;
812 case LB_ADDSTRING:
813 case LB_FINDSTRING:
814 case LB_FINDSTRINGEXACT:
815 case LB_INSERTSTRING:
816 case LB_SELECTSTRING:
817 case LB_DIR:
818 case LB_ADDFILE:
819 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
820 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
821 return 1;
823 case CB_ADDSTRING:
824 case CB_FINDSTRING:
825 case CB_FINDSTRINGEXACT:
826 case CB_INSERTSTRING:
827 case CB_SELECTSTRING:
828 case CB_DIR:
829 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
830 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
831 return 1;
833 case LB_GETITEMRECT:
835 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
836 if (!rect) return -1;
837 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
838 *plparam = MapLS( rect );
840 *pmsg16 = LB_GETITEMRECT16;
841 return 1;
842 case LB_GETSELITEMS:
844 LPARAM *items; /* old LPARAM first, then *pwparam16 x INT16 entries */
846 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
847 if (!(items = HeapAlloc( GetProcessHeap(), 0,
848 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
849 *items++ = *plparam; /* Store the previous lParam */
850 *plparam = MapLS( items );
852 *pmsg16 = LB_GETSELITEMS16;
853 return 1;
854 case LB_SETTABSTOPS:
855 if (wParam32)
857 INT i;
858 LPINT16 stops;
859 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
860 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
861 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
862 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
863 *plparam = MapLS( stops );
864 return 1;
866 *pmsg16 = LB_SETTABSTOPS16;
867 return 0;
869 case CB_GETDROPPEDCONTROLRECT:
871 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
872 if (!rect) return -1;
873 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
874 *plparam = (LPARAM)MapLS(rect);
876 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
877 return 1;
879 case LB_GETTEXT:
880 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
881 *pmsg16 = LB_GETTEXT16;
882 return 1;
884 case CB_GETLBTEXT:
885 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
886 *pmsg16 = CB_GETLBTEXT16;
887 return 1;
889 case WM_ACTIVATE:
890 case WM_CHARTOITEM:
891 case WM_COMMAND:
892 case WM_VKEYTOITEM:
893 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
894 return 0;
895 case WM_HSCROLL:
896 case WM_VSCROLL:
897 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
898 return 0;
899 case WM_CTLCOLORMSGBOX:
900 case WM_CTLCOLOREDIT:
901 case WM_CTLCOLORLISTBOX:
902 case WM_CTLCOLORBTN:
903 case WM_CTLCOLORDLG:
904 case WM_CTLCOLORSCROLLBAR:
905 case WM_CTLCOLORSTATIC:
906 *pmsg16 = WM_CTLCOLOR;
907 *plparam = MAKELPARAM( (HWND16)*plparam,
908 (WORD)msg32 - WM_CTLCOLORMSGBOX );
909 return 0;
910 case WM_MENUSELECT:
911 if(HIWORD(wParam32) & MF_POPUP)
913 HMENU hmenu;
914 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
916 if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
917 *pwparam16=HMENU_16(hmenu);
920 /* fall through */
921 case WM_MENUCHAR:
922 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
923 return 0;
924 case WM_PARENTNOTIFY:
925 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
926 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
927 /* else nothing to do */
928 return 0;
929 case WM_ACTIVATEAPP:
930 if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
931 return 0;
932 case WM_PAINT:
933 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
935 *pmsg16 = WM_PAINTICON;
936 *pwparam16 = 1;
938 return 0;
939 case WM_ERASEBKGND:
940 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
941 *pmsg16 = WM_ICONERASEBKGND;
942 return 0;
943 case WM_PAINTCLIPBOARD:
944 case WM_SIZECLIPBOARD:
945 FIXME_(msg)("message %04x needs translation\n", msg32 );
946 return -1;
947 /* following messages should not be sent to 16-bit apps */
948 case WM_SIZING:
949 case WM_MOVING:
950 case WM_CAPTURECHANGED:
951 case WM_STYLECHANGING:
952 case WM_STYLECHANGED:
953 return -1;
954 default: /* No translation needed */
955 return 0;
960 /**********************************************************************
961 * WINPROC_UnmapMsg32ATo16
963 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
965 static void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
966 WPARAM16 wParam16, LPARAM lParam16, LRESULT *result )
968 switch(msg)
970 case LB_ADDFILE:
971 case LB_ADDSTRING:
972 case LB_DIR:
973 case LB_FINDSTRING:
974 case LB_FINDSTRINGEXACT:
975 case LB_INSERTSTRING:
976 case LB_SELECTSTRING:
977 case LB_GETTEXT:
978 case CB_ADDSTRING:
979 case CB_FINDSTRING:
980 case CB_FINDSTRINGEXACT:
981 case CB_INSERTSTRING:
982 case CB_SELECTSTRING:
983 case CB_DIR:
984 case CB_GETLBTEXT:
985 UnMapLS( (SEGPTR)lParam16 );
986 break;
987 case LB_SETTABSTOPS:
989 void *ptr = MapSL( lParam16 );
990 UnMapLS( lParam16 );
991 HeapFree( GetProcessHeap(), 0, ptr );
993 break;
994 case CB_GETDROPPEDCONTROLRECT:
995 case LB_GETITEMRECT:
997 RECT *r32;
998 RECT16 *rect = MapSL(lParam16);
999 UnMapLS( lParam16 );
1000 lParam16 = *(LPARAM *)(rect + 1);
1001 r32 = (RECT *)lParam16;
1002 r32->left = rect->left;
1003 r32->top = rect->top;
1004 r32->right = rect->right;
1005 r32->bottom = rect->bottom;
1006 HeapFree( GetProcessHeap(), 0, rect );
1008 break;
1009 case LB_GETSELITEMS:
1011 INT i;
1012 LPINT16 items = MapSL(lParam16);
1013 UnMapLS( lParam16 );
1014 lParam16 = *((LPARAM *)items - 1);
1015 for (i = 0; i < wParam16; i++) *((LPINT)lParam16 + i) = items[i];
1016 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
1018 break;
1020 case CB_GETEDITSEL:
1021 if( wParam )
1022 *((PUINT)(wParam)) = LOWORD(*result);
1023 if( lParam )
1024 *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: substract 1? */
1025 break;
1030 /**********************************************************************
1031 * WINPROC_CallProcAtoW
1033 * Call a window procedure, translating args from Ansi to Unicode.
1035 LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
1036 LPARAM lParam, LRESULT *result, void *arg )
1038 LRESULT ret = 0;
1040 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1041 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1043 switch(msg)
1045 case WM_NCCREATE:
1046 case WM_CREATE:
1048 WCHAR *ptr, buffer[512];
1049 CREATESTRUCTA *csA = (CREATESTRUCTA *)lParam;
1050 CREATESTRUCTW csW = *(CREATESTRUCTW *)csA;
1051 MDICREATESTRUCTW mdi_cs;
1052 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
1054 if (HIWORD(csA->lpszClass))
1056 class_lenA = strlen(csA->lpszClass) + 1;
1057 RtlMultiByteToUnicodeSize( &class_lenW, csA->lpszClass, class_lenA );
1059 if (HIWORD(csA->lpszName))
1061 name_lenA = strlen(csA->lpszName) + 1;
1062 RtlMultiByteToUnicodeSize( &name_lenW, csA->lpszName, name_lenA );
1065 if (!(ptr = get_buffer( buffer, sizeof(buffer), class_lenW + name_lenW ))) break;
1067 if (class_lenW)
1069 csW.lpszClass = ptr;
1070 RtlMultiByteToUnicodeN( ptr, class_lenW, NULL, csA->lpszClass, class_lenA );
1072 if (name_lenW)
1074 csW.lpszName = ptr + class_lenW/sizeof(WCHAR);
1075 RtlMultiByteToUnicodeN( ptr + class_lenW/sizeof(WCHAR), name_lenW, NULL,
1076 csA->lpszName, name_lenA );
1079 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1081 mdi_cs = *(MDICREATESTRUCTW *)csA->lpCreateParams;
1082 mdi_cs.szTitle = csW.lpszName;
1083 mdi_cs.szClass = csW.lpszClass;
1084 csW.lpCreateParams = &mdi_cs;
1087 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
1088 free_buffer( buffer, ptr );
1090 break;
1092 case WM_MDICREATE:
1094 WCHAR *ptr, buffer[512];
1095 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
1096 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
1097 MDICREATESTRUCTW csW;
1099 memcpy( &csW, csA, sizeof(csW) );
1101 if (HIWORD(csA->szTitle))
1103 title_lenA = strlen(csA->szTitle) + 1;
1104 RtlMultiByteToUnicodeSize( &title_lenW, csA->szTitle, title_lenA );
1106 if (HIWORD(csA->szClass))
1108 class_lenA = strlen(csA->szClass) + 1;
1109 RtlMultiByteToUnicodeSize( &class_lenW, csA->szClass, class_lenA );
1112 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenW + class_lenW ))) break;
1114 if (title_lenW)
1116 csW.szTitle = ptr;
1117 RtlMultiByteToUnicodeN( ptr, title_lenW, NULL, csA->szTitle, title_lenA );
1119 if (class_lenW)
1121 csW.szClass = ptr + title_lenW/sizeof(WCHAR);
1122 RtlMultiByteToUnicodeN( ptr + title_lenW/sizeof(WCHAR), class_lenW, NULL,
1123 csA->szClass, class_lenA );
1125 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
1126 free_buffer( buffer, ptr );
1128 break;
1130 case WM_GETTEXT:
1131 case WM_ASKCBFORMATNAME:
1133 WCHAR *ptr, buffer[512];
1134 LPSTR str = (LPSTR)lParam;
1135 DWORD len = wParam * sizeof(WCHAR);
1137 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
1138 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1139 if (*result && wParam)
1141 RtlUnicodeToMultiByteN( str, wParam - 1, &len, ptr, strlenW(ptr) * sizeof(WCHAR) );
1142 str[len] = 0;
1143 *result = len;
1145 free_buffer( buffer, ptr );
1147 break;
1149 case LB_ADDSTRING:
1150 case LB_INSERTSTRING:
1151 case LB_FINDSTRING:
1152 case LB_FINDSTRINGEXACT:
1153 case LB_SELECTSTRING:
1154 case CB_ADDSTRING:
1155 case CB_INSERTSTRING:
1156 case CB_FINDSTRING:
1157 case CB_FINDSTRINGEXACT:
1158 case CB_SELECTSTRING:
1159 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
1161 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1162 break;
1164 /* fall through */
1165 case WM_SETTEXT:
1166 case WM_WININICHANGE:
1167 case WM_DEVMODECHANGE:
1168 case CB_DIR:
1169 case LB_DIR:
1170 case LB_ADDFILE:
1171 case EM_REPLACESEL:
1172 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
1173 else
1175 WCHAR *ptr, buffer[512];
1176 LPCSTR strA = (LPCSTR)lParam;
1177 DWORD lenW, lenA = strlen(strA) + 1;
1179 RtlMultiByteToUnicodeSize( &lenW, strA, lenA );
1180 if ((ptr = get_buffer( buffer, sizeof(buffer), lenW )))
1182 RtlMultiByteToUnicodeN( ptr, lenW, NULL, strA, lenA );
1183 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1184 free_buffer( buffer, ptr );
1187 break;
1189 case LB_GETTEXT:
1190 case CB_GETLBTEXT:
1191 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
1193 WCHAR buffer[512]; /* FIXME: fixed sized buffer */
1195 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1196 if (*result >= 0)
1198 DWORD len;
1199 RtlUnicodeToMultiByteN( (LPSTR)lParam, ~0u, &len,
1200 buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
1201 *result = len - 1;
1204 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1205 break;
1207 case EM_GETLINE:
1209 WCHAR *ptr, buffer[512];
1210 WORD len = *(WORD *)lParam;
1212 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
1213 *((WORD *)ptr) = len; /* store the length */
1214 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1215 if (*result)
1217 DWORD reslen;
1218 RtlUnicodeToMultiByteN( (LPSTR)lParam, len, &reslen, ptr, *result * sizeof(WCHAR) );
1219 if (reslen < len) ((LPSTR)lParam)[reslen] = 0;
1220 *result = reslen;
1222 free_buffer( buffer, ptr );
1224 break;
1226 case WM_GETDLGCODE:
1227 if (lParam)
1229 MSG newmsg = *(MSG *)lParam;
1230 switch(newmsg.message)
1232 case WM_CHAR:
1233 case WM_DEADCHAR:
1234 case WM_SYSCHAR:
1235 case WM_SYSDEADCHAR:
1236 newmsg.wParam = map_wparam_char_AtoW( newmsg.wParam, 1 );
1237 break;
1238 case WM_IME_CHAR:
1239 newmsg.wParam = map_wparam_char_AtoW( newmsg.wParam, 2 );
1240 break;
1242 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1244 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1245 break;
1247 case WM_CHARTOITEM:
1248 case WM_MENUCHAR:
1249 case WM_CHAR:
1250 case WM_DEADCHAR:
1251 case WM_SYSCHAR:
1252 case WM_SYSDEADCHAR:
1253 case EM_SETPASSWORDCHAR:
1254 ret = callback( hwnd, msg, map_wparam_char_AtoW(wParam,1), lParam, result, arg );
1255 break;
1257 case WM_IME_CHAR:
1258 ret = callback( hwnd, msg, map_wparam_char_AtoW(wParam,2), lParam, result, arg );
1259 break;
1261 case WM_GETTEXTLENGTH:
1262 case CB_GETLBTEXTLEN:
1263 case LB_GETTEXTLEN:
1264 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1265 if (*result >= 0)
1267 WCHAR *ptr, buffer[512];
1268 LRESULT tmp;
1269 DWORD len = *result + 1;
1270 /* Determine respective GETTEXT message */
1271 UINT msgGetText = (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
1272 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
1273 /* wParam differs between the messages */
1274 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? len : wParam;
1276 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
1278 if (callback == call_window_proc) /* FIXME: hack */
1279 callback( hwnd, msgGetText, wp, (LPARAM)ptr, &tmp, arg );
1280 else
1281 tmp = SendMessageW( hwnd, msgGetText, wp, (LPARAM)ptr );
1282 RtlUnicodeToMultiByteSize( &len, ptr, tmp * sizeof(WCHAR) );
1283 *result = len;
1284 free_buffer( buffer, ptr );
1286 break;
1288 case WM_PAINTCLIPBOARD:
1289 case WM_SIZECLIPBOARD:
1290 FIXME_(msg)( "message %s (0x%x) needs translation, please report\n",
1291 SPY_GetMsgName(msg, hwnd), msg );
1292 break;
1294 default:
1295 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1296 break;
1298 return ret;
1302 /**********************************************************************
1303 * WINPROC_CallProcWtoA
1305 * Call a window procedure, translating args from Unicode to Ansi.
1307 static LRESULT WINPROC_CallProcWtoA( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
1308 LPARAM lParam, LRESULT *result, void *arg )
1310 LRESULT ret = 0;
1312 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1313 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1315 switch(msg)
1317 case WM_NCCREATE:
1318 case WM_CREATE:
1319 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
1320 * at this point.
1322 char buffer[1024], *cls, *name;
1323 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
1324 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
1325 MDICREATESTRUCTA mdi_cs;
1326 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
1328 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
1329 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
1331 if (csW->lpszName)
1333 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
1334 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
1336 else
1337 name_lenW = name_lenA = 0;
1339 if (!(cls = get_buffer( buffer, sizeof(buffer), class_lenA + name_lenA + 2 ))) break;
1341 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
1342 cls[class_lenA] = 0;
1343 csA.lpszClass = cls;
1345 if (csW->lpszName)
1347 name = cls + class_lenA + 1;
1348 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
1349 name[name_lenA] = 0;
1350 csA.lpszName = name;
1353 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1355 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
1356 mdi_cs.szTitle = csA.lpszName;
1357 mdi_cs.szClass = csA.lpszClass;
1358 csA.lpCreateParams = &mdi_cs;
1361 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1362 free_buffer( buffer, cls );
1364 break;
1366 case WM_GETTEXT:
1367 case WM_ASKCBFORMATNAME:
1369 char *ptr, buffer[512];
1370 DWORD len = wParam * 2;
1372 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
1373 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1374 if (*result && len)
1376 RtlMultiByteToUnicodeN( (LPWSTR)lParam, wParam*sizeof(WCHAR), &len, ptr, strlen(ptr)+1 );
1377 *result = len/sizeof(WCHAR) - 1; /* do not count terminating null */
1378 ((LPWSTR)lParam)[*result] = 0;
1380 free_buffer( buffer, ptr );
1382 break;
1384 case LB_ADDSTRING:
1385 case LB_INSERTSTRING:
1386 case LB_FINDSTRING:
1387 case LB_FINDSTRINGEXACT:
1388 case LB_SELECTSTRING:
1389 case CB_ADDSTRING:
1390 case CB_INSERTSTRING:
1391 case CB_FINDSTRING:
1392 case CB_FINDSTRINGEXACT:
1393 case CB_SELECTSTRING:
1394 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
1396 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1397 break;
1399 /* fall through */
1400 case WM_SETTEXT:
1401 case WM_WININICHANGE:
1402 case WM_DEVMODECHANGE:
1403 case CB_DIR:
1404 case LB_DIR:
1405 case LB_ADDFILE:
1406 case EM_REPLACESEL:
1407 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
1408 else
1410 char *ptr, buffer[512];
1411 LPCWSTR strW = (LPCWSTR)lParam;
1412 DWORD lenA, lenW = (strlenW(strW) + 1) * sizeof(WCHAR);
1414 RtlUnicodeToMultiByteSize( &lenA, strW, lenW );
1415 if ((ptr = get_buffer( buffer, sizeof(buffer), lenA )))
1417 RtlUnicodeToMultiByteN( ptr, lenA, NULL, strW, lenW );
1418 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1419 free_buffer( buffer, ptr );
1422 break;
1424 case WM_MDICREATE:
1426 char *ptr, buffer[1024];
1427 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
1428 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1429 MDICREATESTRUCTA csA;
1431 memcpy( &csA, csW, sizeof(csA) );
1433 if (HIWORD(csW->szTitle))
1435 title_lenW = (strlenW(csW->szTitle) + 1) * sizeof(WCHAR);
1436 RtlUnicodeToMultiByteSize( &title_lenA, csW->szTitle, title_lenW );
1438 if (HIWORD(csW->szClass))
1440 class_lenW = (strlenW(csW->szClass) + 1) * sizeof(WCHAR);
1441 RtlUnicodeToMultiByteSize( &class_lenA, csW->szClass, class_lenW );
1444 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenA + class_lenA ))) break;
1446 if (title_lenA)
1448 RtlUnicodeToMultiByteN( ptr, title_lenA, NULL, csW->szTitle, title_lenW );
1449 csA.szTitle = ptr;
1451 if (class_lenA)
1453 RtlUnicodeToMultiByteN( ptr + title_lenA, class_lenA, NULL, csW->szClass, class_lenW );
1454 csA.szClass = ptr + title_lenA;
1456 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1457 free_buffer( buffer, ptr );
1459 break;
1461 case LB_GETTEXT:
1462 case CB_GETLBTEXT:
1463 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
1465 char buffer[512]; /* FIXME: fixed sized buffer */
1467 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1468 if (*result >= 0)
1470 DWORD len;
1471 RtlMultiByteToUnicodeN( (LPWSTR)lParam, ~0u, &len, buffer, strlen(buffer) + 1 );
1472 *result = len / sizeof(WCHAR) - 1;
1475 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1476 break;
1478 case EM_GETLINE:
1480 char *ptr, buffer[512];
1481 WORD len = *(WORD *)lParam;
1483 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * 2 ))) break;
1484 *((WORD *)ptr) = len * 2; /* store the length */
1485 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1486 if (*result)
1488 DWORD reslen;
1489 RtlMultiByteToUnicodeN( (LPWSTR)lParam, len*sizeof(WCHAR), &reslen, ptr, *result );
1490 *result = reslen / sizeof(WCHAR);
1491 if (*result < len) ((LPWSTR)lParam)[*result] = 0;
1493 free_buffer( buffer, ptr );
1495 break;
1497 case WM_GETDLGCODE:
1498 if (lParam)
1500 MSG newmsg = *(MSG *)lParam;
1501 switch(newmsg.message)
1503 case WM_CHAR:
1504 case WM_DEADCHAR:
1505 case WM_SYSCHAR:
1506 case WM_SYSDEADCHAR:
1507 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 1 );
1508 break;
1509 case WM_IME_CHAR:
1510 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 2 );
1511 break;
1513 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1515 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1516 break;
1518 case WM_CHARTOITEM:
1519 case WM_MENUCHAR:
1520 case WM_CHAR:
1521 case WM_DEADCHAR:
1522 case WM_SYSCHAR:
1523 case WM_SYSDEADCHAR:
1524 case EM_SETPASSWORDCHAR:
1525 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,1), lParam, result, arg );
1526 break;
1528 case WM_IME_CHAR:
1529 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,2), lParam, result, arg );
1530 break;
1532 case WM_PAINTCLIPBOARD:
1533 case WM_SIZECLIPBOARD:
1534 FIXME_(msg)( "message %s (%04x) needs translation, please report\n",
1535 SPY_GetMsgName(msg, hwnd), msg );
1536 break;
1538 default:
1539 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1540 break;
1543 return ret;
1547 /**********************************************************************
1548 * WINPROC_CallProc16To32A
1550 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
1551 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
1553 LRESULT ret = 0;
1554 HWND hwnd32 = WIN_Handle32( hwnd );
1556 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1557 hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
1559 switch(msg)
1561 case WM_NCCREATE:
1562 case WM_CREATE:
1564 CREATESTRUCT16 *cs16 = MapSL(lParam);
1565 CREATESTRUCTA cs;
1566 MDICREATESTRUCTA mdi_cs;
1568 CREATESTRUCT16to32A( cs16, &cs );
1569 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
1571 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
1572 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
1573 cs.lpCreateParams = &mdi_cs;
1575 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1576 CREATESTRUCT32Ato16( &cs, cs16 );
1578 break;
1579 case WM_MDICREATE:
1581 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
1582 MDICREATESTRUCTA cs;
1584 MDICREATESTRUCT16to32A( cs16, &cs );
1585 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1586 MDICREATESTRUCT32Ato16( &cs, cs16 );
1588 break;
1589 case WM_MDIACTIVATE:
1590 if (lParam)
1591 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
1592 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1593 else /* message sent to MDI client */
1594 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1595 break;
1596 case WM_MDIGETACTIVE:
1598 BOOL maximized = FALSE;
1599 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
1600 *result = MAKELRESULT( LOWORD(*result), maximized );
1602 break;
1603 case WM_MDISETMENU:
1604 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
1605 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
1606 result, arg );
1607 break;
1608 case WM_GETMINMAXINFO:
1610 MINMAXINFO16 *mmi16 = MapSL(lParam);
1611 MINMAXINFO mmi;
1613 MINMAXINFO16to32( mmi16, &mmi );
1614 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
1615 MINMAXINFO32to16( &mmi, mmi16 );
1617 break;
1618 case WM_WINDOWPOSCHANGING:
1619 case WM_WINDOWPOSCHANGED:
1621 WINDOWPOS16 *winpos16 = MapSL(lParam);
1622 WINDOWPOS winpos;
1624 WINDOWPOS16to32( winpos16, &winpos );
1625 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
1626 WINDOWPOS32to16( &winpos, winpos16 );
1628 break;
1629 case WM_NCCALCSIZE:
1631 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
1632 NCCALCSIZE_PARAMS nc;
1633 WINDOWPOS winpos;
1635 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
1636 if (wParam)
1638 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
1639 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
1640 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
1641 nc.lppos = &winpos;
1643 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
1644 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
1645 if (wParam)
1647 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
1648 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
1649 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
1652 break;
1653 case WM_COMPAREITEM:
1655 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
1656 COMPAREITEMSTRUCT cis;
1657 cis.CtlType = cis16->CtlType;
1658 cis.CtlID = cis16->CtlID;
1659 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
1660 cis.itemID1 = cis16->itemID1;
1661 cis.itemData1 = cis16->itemData1;
1662 cis.itemID2 = cis16->itemID2;
1663 cis.itemData2 = cis16->itemData2;
1664 cis.dwLocaleId = 0; /* FIXME */
1665 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
1667 break;
1668 case WM_DELETEITEM:
1670 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
1671 DELETEITEMSTRUCT dis;
1672 dis.CtlType = dis16->CtlType;
1673 dis.CtlID = dis16->CtlID;
1674 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
1675 dis.itemData = dis16->itemData;
1676 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1678 break;
1679 case WM_MEASUREITEM:
1681 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1682 MEASUREITEMSTRUCT mis;
1683 mis.CtlType = mis16->CtlType;
1684 mis.CtlID = mis16->CtlID;
1685 mis.itemID = mis16->itemID;
1686 mis.itemWidth = mis16->itemWidth;
1687 mis.itemHeight = mis16->itemHeight;
1688 mis.itemData = mis16->itemData;
1689 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
1690 mis16->itemWidth = (UINT16)mis.itemWidth;
1691 mis16->itemHeight = (UINT16)mis.itemHeight;
1693 break;
1694 case WM_DRAWITEM:
1696 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1697 DRAWITEMSTRUCT dis;
1698 dis.CtlType = dis16->CtlType;
1699 dis.CtlID = dis16->CtlID;
1700 dis.itemID = dis16->itemID;
1701 dis.itemAction = dis16->itemAction;
1702 dis.itemState = dis16->itemState;
1703 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1704 : WIN_Handle32( dis16->hwndItem );
1705 dis.hDC = HDC_32(dis16->hDC);
1706 dis.itemData = dis16->itemData;
1707 dis.rcItem.left = dis16->rcItem.left;
1708 dis.rcItem.top = dis16->rcItem.top;
1709 dis.rcItem.right = dis16->rcItem.right;
1710 dis.rcItem.bottom = dis16->rcItem.bottom;
1711 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1713 break;
1714 case WM_COPYDATA:
1716 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
1717 COPYDATASTRUCT cds;
1718 cds.dwData = cds16->dwData;
1719 cds.cbData = cds16->cbData;
1720 cds.lpData = MapSL(cds16->lpData);
1721 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
1723 break;
1724 case WM_GETDLGCODE:
1725 if (lParam)
1727 MSG16 *msg16 = MapSL(lParam);
1728 MSG msg32;
1729 msg32.hwnd = WIN_Handle32( msg16->hwnd );
1730 msg32.message = msg16->message;
1731 msg32.wParam = msg16->wParam;
1732 msg32.lParam = msg16->lParam;
1733 msg32.time = msg16->time;
1734 msg32.pt.x = msg16->pt.x;
1735 msg32.pt.y = msg16->pt.y;
1736 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
1738 else
1739 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1740 break;
1741 case WM_NEXTMENU:
1743 MDINEXTMENU next;
1744 next.hmenuIn = (HMENU)lParam;
1745 next.hmenuNext = 0;
1746 next.hwndNext = 0;
1747 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
1748 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
1750 break;
1751 case WM_ACTIVATE:
1752 case WM_CHARTOITEM:
1753 case WM_COMMAND:
1754 case WM_VKEYTOITEM:
1755 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1756 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1757 break;
1758 case WM_HSCROLL:
1759 case WM_VSCROLL:
1760 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1761 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
1762 break;
1763 case WM_CTLCOLOR:
1764 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
1765 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
1766 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
1767 result, arg );
1768 break;
1769 case WM_GETTEXT:
1770 case WM_SETTEXT:
1771 case WM_WININICHANGE:
1772 case WM_DEVMODECHANGE:
1773 case WM_ASKCBFORMATNAME:
1774 case WM_NOTIFY:
1775 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
1776 break;
1777 case WM_MENUCHAR:
1778 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1779 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1780 break;
1781 case WM_MENUSELECT:
1782 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
1784 HMENU hmenu = HMENU_32(HIWORD(lParam));
1785 UINT pos = MENU_FindSubMenu( &hmenu, HMENU_32(wParam) );
1786 if (pos == 0xffff) pos = 0; /* NO_SELECTED_ITEM */
1787 wParam = pos;
1789 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1790 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1791 break;
1792 case WM_PARENTNOTIFY:
1793 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
1794 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1795 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1796 else
1797 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1798 break;
1799 case WM_ACTIVATEAPP:
1800 /* We need this when SetActiveWindow sends a Sendmessage16() to
1801 * a 32bit window. Might be superflous with 32bit interprocess
1802 * message queues. */
1803 ret = callback( hwnd32, msg, wParam, HTASK_32(lParam), result, arg );
1804 break;
1805 case WM_DDE_INITIATE:
1806 case WM_DDE_TERMINATE:
1807 case WM_DDE_UNADVISE:
1808 case WM_DDE_REQUEST:
1809 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1810 break;
1811 case WM_DDE_ADVISE:
1812 case WM_DDE_DATA:
1813 case WM_DDE_POKE:
1815 HANDLE16 lo16 = LOWORD(lParam);
1816 UINT lo32 = 0;
1817 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
1818 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
1819 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1821 break; /* FIXME don't know how to free allocated memory (handle) !! */
1822 case WM_DDE_ACK:
1824 UINT lo = LOWORD(lParam);
1825 UINT hi = HIWORD(lParam);
1826 int flag = 0;
1827 char buf[2];
1829 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1830 if (GlobalSize16(hi) != 0) flag |= 2;
1831 switch (flag)
1833 case 0:
1834 if (hi)
1836 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1837 hi = 0;
1839 break;
1840 case 1:
1841 break; /* atom, nothing to do */
1842 case 3:
1843 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1844 /* fall thru */
1845 case 2:
1846 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1847 break;
1849 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
1850 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1852 break; /* FIXME don't know how to free allocated memory (handle) !! */
1853 case WM_DDE_EXECUTE:
1854 lParam = convert_handle_16_to_32( lParam, GMEM_DDESHARE );
1855 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1856 break; /* FIXME don't know how to free allocated memory (handle) !! */
1857 case WM_PAINTCLIPBOARD:
1858 case WM_SIZECLIPBOARD:
1859 FIXME_(msg)( "message %04x needs translation\n", msg );
1860 break;
1861 default:
1862 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1863 break;
1865 return ret;
1869 /**********************************************************************
1870 * __wine_call_wndproc (USER.1010)
1872 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
1873 WINDOWPROC *proc )
1875 LRESULT result;
1877 if (proc->procA)
1878 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
1879 else
1880 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
1881 return result;
1885 /**********************************************************************
1886 * WINPROC_CallProc32ATo16
1888 * Call a 16-bit window procedure, translating the 32-bit args.
1890 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
1891 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
1893 LRESULT ret = 0;
1895 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1896 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1898 switch(msg)
1900 case WM_NCCREATE:
1901 case WM_CREATE:
1903 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
1904 CREATESTRUCT16 cs;
1905 MDICREATESTRUCT16 mdi_cs16;
1906 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
1908 CREATESTRUCT32Ato16( cs32, &cs );
1909 cs.lpszName = MapLS( cs32->lpszName );
1910 cs.lpszClass = MapLS( cs32->lpszClass );
1912 if (mdi_child)
1914 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
1915 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
1916 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
1917 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
1918 cs.lpCreateParams = MapLS( &mdi_cs16 );
1920 lParam = MapLS( &cs );
1921 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1922 UnMapLS( lParam );
1923 UnMapLS( cs.lpszName );
1924 UnMapLS( cs.lpszClass );
1925 if (mdi_child)
1927 UnMapLS( cs.lpCreateParams );
1928 UnMapLS( mdi_cs16.szTitle );
1929 UnMapLS( mdi_cs16.szClass );
1932 break;
1933 case WM_MDICREATE:
1935 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
1936 MDICREATESTRUCT16 cs;
1938 MDICREATESTRUCT32Ato16( cs32, &cs );
1939 cs.szTitle = MapLS( cs32->szTitle );
1940 cs.szClass = MapLS( cs32->szClass );
1941 lParam = MapLS( &cs );
1942 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1943 UnMapLS( lParam );
1944 UnMapLS( cs.szTitle );
1945 UnMapLS( cs.szClass );
1947 break;
1948 case WM_MDIACTIVATE:
1949 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1950 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
1951 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
1952 else
1953 ret = callback( HWND_16(hwnd), msg, HWND_16( (HWND)wParam ), 0, result, arg );
1954 break;
1955 case WM_MDIGETACTIVE:
1956 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1957 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
1958 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
1959 break;
1960 case WM_MDISETMENU:
1961 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
1962 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
1963 break;
1964 case WM_GETMINMAXINFO:
1966 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
1967 MINMAXINFO16 mmi;
1969 MINMAXINFO32to16( mmi32, &mmi );
1970 lParam = MapLS( &mmi );
1971 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1972 UnMapLS( lParam );
1973 MINMAXINFO16to32( &mmi, mmi32 );
1975 break;
1976 case WM_NCCALCSIZE:
1978 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
1979 NCCALCSIZE_PARAMS16 nc;
1980 WINDOWPOS16 winpos;
1982 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
1983 if (wParam)
1985 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
1986 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
1987 WINDOWPOS32to16( nc32->lppos, &winpos );
1988 nc.lppos = MapLS( &winpos );
1990 lParam = MapLS( &nc );
1991 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1992 UnMapLS( lParam );
1993 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
1994 if (wParam)
1996 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
1997 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
1998 WINDOWPOS16to32( &winpos, nc32->lppos );
1999 UnMapLS( nc.lppos );
2002 break;
2003 case WM_WINDOWPOSCHANGING:
2004 case WM_WINDOWPOSCHANGED:
2006 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
2007 WINDOWPOS16 winpos;
2009 WINDOWPOS32to16( winpos32, &winpos );
2010 lParam = MapLS( &winpos );
2011 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2012 UnMapLS( lParam );
2013 WINDOWPOS16to32( &winpos, winpos32 );
2015 break;
2016 case WM_COMPAREITEM:
2018 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
2019 COMPAREITEMSTRUCT16 cis;
2020 cis.CtlType = cis32->CtlType;
2021 cis.CtlID = cis32->CtlID;
2022 cis.hwndItem = HWND_16( cis32->hwndItem );
2023 cis.itemID1 = cis32->itemID1;
2024 cis.itemData1 = cis32->itemData1;
2025 cis.itemID2 = cis32->itemID2;
2026 cis.itemData2 = cis32->itemData2;
2027 lParam = MapLS( &cis );
2028 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2029 UnMapLS( lParam );
2031 break;
2032 case WM_DELETEITEM:
2034 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
2035 DELETEITEMSTRUCT16 dis;
2036 dis.CtlType = dis32->CtlType;
2037 dis.CtlID = dis32->CtlID;
2038 dis.itemID = dis32->itemID;
2039 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
2040 : HWND_16( dis32->hwndItem );
2041 dis.itemData = dis32->itemData;
2042 lParam = MapLS( &dis );
2043 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2044 UnMapLS( lParam );
2046 break;
2047 case WM_DRAWITEM:
2049 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
2050 DRAWITEMSTRUCT16 dis;
2051 dis.CtlType = dis32->CtlType;
2052 dis.CtlID = dis32->CtlID;
2053 dis.itemID = dis32->itemID;
2054 dis.itemAction = dis32->itemAction;
2055 dis.itemState = dis32->itemState;
2056 dis.hwndItem = HWND_16( dis32->hwndItem );
2057 dis.hDC = HDC_16(dis32->hDC);
2058 dis.itemData = dis32->itemData;
2059 dis.rcItem.left = dis32->rcItem.left;
2060 dis.rcItem.top = dis32->rcItem.top;
2061 dis.rcItem.right = dis32->rcItem.right;
2062 dis.rcItem.bottom = dis32->rcItem.bottom;
2063 lParam = MapLS( &dis );
2064 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2065 UnMapLS( lParam );
2067 break;
2068 case WM_MEASUREITEM:
2070 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
2071 MEASUREITEMSTRUCT16 mis;
2072 mis.CtlType = mis32->CtlType;
2073 mis.CtlID = mis32->CtlID;
2074 mis.itemID = mis32->itemID;
2075 mis.itemWidth = mis32->itemWidth;
2076 mis.itemHeight = mis32->itemHeight;
2077 mis.itemData = mis32->itemData;
2078 lParam = MapLS( &mis );
2079 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2080 UnMapLS( lParam );
2081 mis32->itemWidth = mis.itemWidth;
2082 mis32->itemHeight = mis.itemHeight;
2084 break;
2085 case WM_COPYDATA:
2087 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
2088 COPYDATASTRUCT16 cds;
2090 cds.dwData = cds32->dwData;
2091 cds.cbData = cds32->cbData;
2092 cds.lpData = MapLS( cds32->lpData );
2093 lParam = MapLS( &cds );
2094 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2095 UnMapLS( lParam );
2096 UnMapLS( cds.lpData );
2098 break;
2099 case WM_GETDLGCODE:
2100 if (lParam)
2102 MSG *msg32 = (MSG *)lParam;
2103 MSG16 msg16;
2105 msg16.hwnd = HWND_16( msg32->hwnd );
2106 msg16.message = msg32->message;
2107 msg16.wParam = msg32->wParam;
2108 msg16.lParam = msg32->lParam;
2109 msg16.time = msg32->time;
2110 msg16.pt.x = msg32->pt.x;
2111 msg16.pt.y = msg32->pt.y;
2112 lParam = MapLS( &msg16 );
2113 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2114 UnMapLS( lParam );
2116 else
2117 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2118 break;
2119 case WM_NEXTMENU:
2121 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2122 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
2123 next->hmenuNext = HMENU_32( LOWORD(*result) );
2124 next->hwndNext = WIN_Handle32( HIWORD(*result) );
2125 *result = 0;
2127 break;
2128 case WM_GETTEXT:
2129 case WM_ASKCBFORMATNAME:
2130 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
2131 /* fall through */
2132 case WM_NOTIFY:
2133 case WM_SETTEXT:
2134 case WM_WININICHANGE:
2135 case WM_DEVMODECHANGE:
2136 lParam = MapLS( (void *)lParam );
2137 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2138 UnMapLS( lParam );
2139 break;
2140 case WM_DDE_INITIATE:
2141 case WM_DDE_TERMINATE:
2142 case WM_DDE_UNADVISE:
2143 case WM_DDE_REQUEST:
2144 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam), lParam, result, arg );
2145 break;
2146 case WM_DDE_ADVISE:
2147 case WM_DDE_DATA:
2148 case WM_DDE_POKE:
2150 UINT_PTR lo32, hi;
2151 HANDLE16 lo16 = 0;
2153 UnpackDDElParam( msg, lParam, &lo32, &hi );
2154 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
2155 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
2156 MAKELPARAM(lo16, hi), result, arg );
2158 break; /* FIXME don't know how to free allocated memory (handle) !! */
2159 case WM_DDE_ACK:
2161 UINT_PTR lo, hi;
2162 int flag = 0;
2163 char buf[2];
2165 UnpackDDElParam( msg, lParam, &lo, &hi );
2167 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
2168 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
2169 switch (flag)
2171 case 0:
2172 if (hi)
2174 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2175 hi = 0;
2177 break;
2178 case 1:
2179 break; /* atom, nothing to do */
2180 case 3:
2181 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
2182 /* fall thru */
2183 case 2:
2184 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
2185 break;
2187 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
2188 MAKELPARAM(lo, hi), result, arg );
2190 break; /* FIXME don't know how to free allocated memory (handle) !! */
2191 case WM_DDE_EXECUTE:
2192 lParam = convert_handle_32_to_16(lParam, GMEM_DDESHARE);
2193 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2194 break; /* FIXME don't know how to free allocated memory (handle) !! */
2195 case SBM_SETRANGE:
2196 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
2197 break;
2198 case SBM_GETRANGE:
2199 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
2200 *(LPINT)wParam = LOWORD(*result);
2201 *(LPINT)lParam = HIWORD(*result);
2202 break;
2203 case BM_GETCHECK:
2204 case BM_SETCHECK:
2205 case BM_GETSTATE:
2206 case BM_SETSTATE:
2207 case BM_SETSTYLE:
2208 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
2209 break;
2210 case EM_GETSEL:
2211 case EM_GETRECT:
2212 case EM_SETRECT:
2213 case EM_SETRECTNP:
2214 case EM_SCROLL:
2215 case EM_LINESCROLL:
2216 case EM_SCROLLCARET:
2217 case EM_GETMODIFY:
2218 case EM_SETMODIFY:
2219 case EM_GETLINECOUNT:
2220 case EM_LINEINDEX:
2221 case EM_SETHANDLE:
2222 case EM_GETHANDLE:
2223 case EM_GETTHUMB:
2224 case EM_LINELENGTH:
2225 case EM_REPLACESEL:
2226 case EM_GETLINE:
2227 case EM_LIMITTEXT:
2228 case EM_CANUNDO:
2229 case EM_UNDO:
2230 case EM_FMTLINES:
2231 case EM_LINEFROMCHAR:
2232 case EM_SETTABSTOPS:
2233 case EM_SETPASSWORDCHAR:
2234 case EM_EMPTYUNDOBUFFER:
2235 case EM_GETFIRSTVISIBLELINE:
2236 case EM_SETREADONLY:
2237 case EM_SETWORDBREAKPROC:
2238 case EM_GETWORDBREAKPROC:
2239 case EM_GETPASSWORDCHAR:
2240 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
2241 break;
2242 case EM_SETSEL:
2243 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
2244 break;
2245 default:
2247 UINT16 msg16;
2248 WPARAM16 wParam16;
2249 LPARAM lParam16 = lParam;
2250 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &wParam16, &lParam16 ) != -1)
2252 ret = callback( HWND_16(hwnd), msg16, wParam16, lParam16, result, arg );
2253 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, wParam16, lParam16, result );
2256 break;
2258 return ret;
2262 /**********************************************************************
2263 * CallWindowProc (USER.122)
2265 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2266 WPARAM16 wParam, LPARAM lParam )
2268 WINDOWPROC *proc;
2269 LRESULT result;
2271 if (!func) return 0;
2273 if (!(proc = handle16_to_proc( func )))
2274 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
2275 else if (proc->procA)
2276 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2277 else if (proc->procW)
2278 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
2279 else
2280 call_window_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2282 return result;
2286 /**********************************************************************
2287 * CallWindowProcA (USER32.@)
2289 * The CallWindowProc() function invokes the windows procedure _func_,
2290 * with _hwnd_ as the target window, the message specified by _msg_, and
2291 * the message parameters _wParam_ and _lParam_.
2293 * Some kinds of argument conversion may be done, I'm not sure what.
2295 * CallWindowProc() may be used for windows subclassing. Use
2296 * SetWindowLong() to set a new windows procedure for windows of the
2297 * subclass, and handle subclassed messages in the new windows
2298 * procedure. The new windows procedure may then use CallWindowProc()
2299 * with _func_ set to the parent class's windows procedure to dispatch
2300 * the message to the superclass.
2302 * RETURNS
2304 * The return value is message dependent.
2306 * CONFORMANCE
2308 * ECMA-234, Win32
2310 LRESULT WINAPI CallWindowProcA(
2311 WNDPROC func, /* [in] window procedure */
2312 HWND hwnd, /* [in] target window */
2313 UINT msg, /* [in] message */
2314 WPARAM wParam, /* [in] message dependent parameter */
2315 LPARAM lParam /* [in] message dependent parameter */
2317 WINDOWPROC *proc;
2318 LRESULT result;
2320 if (!func) return 0;
2322 if (!(proc = handle_to_proc( func )))
2323 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2324 else if (proc->procA)
2325 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2326 else if (proc->procW)
2327 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procW );
2328 else
2329 WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2330 return result;
2334 /**********************************************************************
2335 * CallWindowProcW (USER32.@)
2337 * See CallWindowProcA.
2339 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2340 WPARAM wParam, LPARAM lParam )
2342 WINDOWPROC *proc;
2343 LRESULT result;
2345 if (!func) return 0;
2347 if (!(proc = handle_to_proc( func )))
2348 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2349 else if (proc->procW)
2350 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2351 else if (proc->procA)
2352 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2353 else
2354 WINPROC_CallProcWtoA( call_window_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2355 return result;
2359 /**********************************************************************
2360 * WINPROC_CallDlgProc16
2362 INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
2364 WINDOWPROC *proc;
2365 LRESULT result;
2366 INT_PTR ret;
2368 if (!func) return 0;
2370 if (!(proc = handle16_to_proc( (WNDPROC16)func )))
2372 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, func );
2374 else if (proc->procA)
2376 ret = WINPROC_CallProc16To32A( call_dialog_proc, hwnd, msg, wParam, lParam,
2377 &result, proc->procA );
2378 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2380 else if (proc->procW)
2382 ret = WINPROC_CallProc16To32A( call_dialog_proc_AtoW, hwnd, msg, wParam, lParam,
2383 &result, proc->procW );
2384 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2386 else
2388 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2390 return ret;
2394 /**********************************************************************
2395 * WINPROC_CallDlgProcA
2397 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2399 WINDOWPROC *proc;
2400 LRESULT result;
2401 INT_PTR ret;
2403 if (!func) return 0;
2405 if (!(proc = handle_to_proc( (WNDPROC)func )))
2406 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2407 else if (proc->procA)
2408 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2409 else if (proc->procW)
2411 ret = WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procW );
2412 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2414 else
2416 ret = WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2417 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2419 return ret;
2423 /**********************************************************************
2424 * WINPROC_CallDlgProcW
2426 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2428 WINDOWPROC *proc;
2429 LRESULT result;
2430 INT_PTR ret;
2432 if (!func) return 0;
2434 if (!(proc = handle_to_proc( (WNDPROC)func )))
2435 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2436 else if (proc->procW)
2437 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2438 else if (proc->procA)
2440 ret = WINPROC_CallProcWtoA( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2441 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2443 else
2445 ret = WINPROC_CallProcWtoA( call_dialog_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2446 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2448 return ret;