d3dx8: Implement D3DXMatrixOrthoOffCenterLH.
[wine/wine-gecko.git] / dlls / user32 / winproc.c
blob7d6fa36c316259e5d0ce809631fa12f362249a20
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 "wownt32.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "controls.h"
35 #include "win.h"
36 #include "user_private.h"
37 #include "dde.h"
38 #include "winternl.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DECLARE_DEBUG_CHANNEL(msg);
43 WINE_DECLARE_DEBUG_CHANNEL(relay);
44 WINE_DEFAULT_DEBUG_CHANNEL(win);
46 typedef struct tagWINDOWPROC
48 WNDPROC16 proc16; /* 16-bit window proc */
49 WNDPROC procA; /* ASCII window proc */
50 WNDPROC procW; /* Unicode window proc */
51 } WINDOWPROC;
53 #define WINPROC_HANDLE (~0UL >> 16)
54 #define MAX_WINPROCS 8192
55 #define BUILTIN_WINPROCS 8 /* first BUILTIN_WINPROCS entries are reserved for builtin procs */
57 WNDPROC EDIT_winproc_handle = 0;
59 static WINDOWPROC winproc_array[MAX_WINPROCS];
60 static UINT builtin_used;
61 static UINT winproc_used = BUILTIN_WINPROCS;
63 static CRITICAL_SECTION winproc_cs;
64 static CRITICAL_SECTION_DEBUG critsect_debug =
66 0, 0, &winproc_cs,
67 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
68 0, 0, { (DWORD_PTR)(__FILE__ ": winproc_cs") }
70 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
72 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
74 if (size >= need) return static_buffer;
75 return HeapAlloc( GetProcessHeap(), 0, need );
78 static inline void free_buffer( void *static_buffer, void *buffer )
80 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
83 /* find an existing winproc for a given 16-bit function and type */
84 /* FIXME: probably should do something more clever than a linear search */
85 static inline WINDOWPROC *find_winproc16( WNDPROC16 func )
87 unsigned int i;
89 for (i = BUILTIN_WINPROCS; i < winproc_used; i++)
91 if (winproc_array[i].proc16 == func) return &winproc_array[i];
93 return NULL;
96 /* find an existing winproc for a given function and type */
97 /* FIXME: probably should do something more clever than a linear search */
98 static inline WINDOWPROC *find_winproc( WNDPROC funcA, WNDPROC funcW )
100 unsigned int i;
102 for (i = 0; i < builtin_used; i++)
104 /* match either proc, some apps confuse A and W */
105 if (funcA && winproc_array[i].procA != funcA && winproc_array[i].procW != funcA) continue;
106 if (funcW && winproc_array[i].procA != funcW && winproc_array[i].procW != funcW) continue;
107 return &winproc_array[i];
109 for (i = BUILTIN_WINPROCS; i < winproc_used; i++)
111 if (funcA && winproc_array[i].procA != funcA) continue;
112 if (funcW && winproc_array[i].procW != funcW) continue;
113 return &winproc_array[i];
115 return NULL;
118 /* return the window proc for a given handle, or NULL for an invalid handle */
119 static inline WINDOWPROC *handle_to_proc( WNDPROC handle )
121 UINT index = LOWORD(handle);
122 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return NULL;
123 if (index >= winproc_used) return NULL;
124 return &winproc_array[index];
127 /* create a handle for a given window proc */
128 static inline WNDPROC proc_to_handle( WINDOWPROC *proc )
130 return (WNDPROC)(ULONG_PTR)((proc - winproc_array) | (WINPROC_HANDLE << 16));
133 /* allocate and initialize a new winproc */
134 static inline WINDOWPROC *alloc_winproc( WNDPROC funcA, WNDPROC funcW )
136 WINDOWPROC *proc;
138 /* check if the function is already a win proc */
139 if (funcA && (proc = handle_to_proc( funcA ))) return proc;
140 if (funcW && (proc = handle_to_proc( funcW ))) return proc;
141 if (!funcA && !funcW) return NULL;
143 EnterCriticalSection( &winproc_cs );
145 /* check if we already have a winproc for that function */
146 if (!(proc = find_winproc( funcA, funcW )))
148 if (funcA && funcW)
150 assert( builtin_used < BUILTIN_WINPROCS );
151 proc = &winproc_array[builtin_used++];
152 proc->procA = funcA;
153 proc->procW = funcW;
154 TRACE( "allocated %p for builtin %p/%p (%d/%d used)\n",
155 proc_to_handle(proc), funcA, funcW, builtin_used, BUILTIN_WINPROCS );
157 else if (winproc_used < MAX_WINPROCS)
159 proc = &winproc_array[winproc_used++];
160 proc->procA = funcA;
161 proc->procW = funcW;
162 TRACE( "allocated %p for %c %p (%d/%d used)\n",
163 proc_to_handle(proc), funcA ? 'A' : 'W', funcA ? funcA : funcW,
164 winproc_used, MAX_WINPROCS );
166 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA, funcW );
168 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc), funcA, funcW );
170 LeaveCriticalSection( &winproc_cs );
171 return proc;
175 #ifdef __i386__
177 #include "pshpack1.h"
179 /* Window procedure 16-to-32-bit thunk */
180 typedef struct
182 BYTE popl_eax; /* popl %eax (return address) */
183 BYTE pushl_func; /* pushl $proc */
184 WINDOWPROC *proc;
185 BYTE pushl_eax; /* pushl %eax */
186 BYTE ljmp; /* ljmp relay*/
187 DWORD relay_offset; /* __wine_call_wndproc */
188 WORD relay_sel;
189 } WINPROC_THUNK;
191 #include "poppack.h"
193 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
195 static WINPROC_THUNK *thunk_array;
196 static UINT thunk_selector;
197 static UINT thunk_used;
199 /* return the window proc for a given handle, or NULL for an invalid handle */
200 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
202 if (HIWORD(handle) == thunk_selector)
204 UINT index = LOWORD(handle) / sizeof(WINPROC_THUNK);
205 /* check alignment */
206 if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return NULL;
207 /* check array limits */
208 if (index >= thunk_used) return NULL;
209 return thunk_array[index].proc;
211 return handle_to_proc( (WNDPROC)handle );
214 /* allocate a 16-bit thunk for an existing window proc */
215 static WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
217 static FARPROC16 relay;
218 UINT i;
220 if (proc->proc16) return proc->proc16;
222 EnterCriticalSection( &winproc_cs );
224 if (!thunk_array) /* allocate the array and its selector */
226 LDT_ENTRY entry;
228 if (!(thunk_selector = wine_ldt_alloc_entries(1))) goto done;
229 if (!(thunk_array = VirtualAlloc( NULL, MAX_THUNKS * sizeof(WINPROC_THUNK), MEM_COMMIT,
230 PAGE_EXECUTE_READWRITE ))) goto done;
231 wine_ldt_set_base( &entry, thunk_array );
232 wine_ldt_set_limit( &entry, MAX_THUNKS * sizeof(WINPROC_THUNK) - 1 );
233 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
234 wine_ldt_set_entry( thunk_selector, &entry );
235 relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
238 /* check if it already exists */
239 for (i = 0; i < thunk_used; i++) if (thunk_array[i].proc == proc) break;
241 if (i == thunk_used) /* create a new one */
243 WINPROC_THUNK *thunk;
245 if (thunk_used >= MAX_THUNKS) goto done;
246 thunk = &thunk_array[thunk_used++];
247 thunk->popl_eax = 0x58; /* popl %eax */
248 thunk->pushl_func = 0x68; /* pushl $proc */
249 thunk->proc = proc;
250 thunk->pushl_eax = 0x50; /* pushl %eax */
251 thunk->ljmp = 0xea; /* ljmp relay*/
252 thunk->relay_offset = OFFSETOF(relay);
253 thunk->relay_sel = SELECTOROF(relay);
255 proc->proc16 = (WNDPROC16)MAKESEGPTR( thunk_selector, i * sizeof(WINPROC_THUNK) );
256 done:
257 LeaveCriticalSection( &winproc_cs );
258 return proc->proc16;
261 #else /* __i386__ */
263 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
265 return handle_to_proc( (WNDPROC)handle );
268 static inline WNDPROC16 alloc_win16_thunk( WINDOWPROC *proc )
270 return 0;
273 #endif /* __i386__ */
276 #ifdef __i386__
277 /* Some window procedures modify register they shouldn't, or are not
278 * properly declared stdcall; so we need a small assembly wrapper to
279 * call them. */
280 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
281 WPARAM wParam, LPARAM lParam );
282 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
283 "pushl %ebp\n\t"
284 "movl %esp,%ebp\n\t"
285 "pushl %edi\n\t"
286 "pushl %esi\n\t"
287 "pushl %ebx\n\t"
288 "subl $12,%esp\n\t"
289 "pushl 24(%ebp)\n\t"
290 "pushl 20(%ebp)\n\t"
291 "pushl 16(%ebp)\n\t"
292 "pushl 12(%ebp)\n\t"
293 "movl 8(%ebp),%eax\n\t"
294 "call *%eax\n\t"
295 "leal -12(%ebp),%esp\n\t"
296 "popl %ebx\n\t"
297 "popl %esi\n\t"
298 "popl %edi\n\t"
299 "leave\n\t"
300 "ret" )
301 #else
302 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
303 WPARAM wParam, LPARAM lParam )
305 return proc( hwnd, msg, wParam, lParam );
307 #endif /* __i386__ */
309 static void RECT16to32( const RECT16 *from, RECT *to )
311 to->left = from->left;
312 to->top = from->top;
313 to->right = from->right;
314 to->bottom = from->bottom;
317 static void RECT32to16( const RECT *from, RECT16 *to )
319 to->left = from->left;
320 to->top = from->top;
321 to->right = from->right;
322 to->bottom = from->bottom;
325 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
327 to->ptReserved.x = from->ptReserved.x;
328 to->ptReserved.y = from->ptReserved.y;
329 to->ptMaxSize.x = from->ptMaxSize.x;
330 to->ptMaxSize.y = from->ptMaxSize.y;
331 to->ptMaxPosition.x = from->ptMaxPosition.x;
332 to->ptMaxPosition.y = from->ptMaxPosition.y;
333 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
334 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
335 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
336 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
339 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
341 to->ptReserved.x = from->ptReserved.x;
342 to->ptReserved.y = from->ptReserved.y;
343 to->ptMaxSize.x = from->ptMaxSize.x;
344 to->ptMaxSize.y = from->ptMaxSize.y;
345 to->ptMaxPosition.x = from->ptMaxPosition.x;
346 to->ptMaxPosition.y = from->ptMaxPosition.y;
347 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
348 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
349 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
350 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
353 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
355 to->hwnd = HWND_16(from->hwnd);
356 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
357 to->x = from->x;
358 to->y = from->y;
359 to->cx = from->cx;
360 to->cy = from->cy;
361 to->flags = from->flags;
364 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
366 to->hwnd = WIN_Handle32(from->hwnd);
367 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
368 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
369 to->x = from->x;
370 to->y = from->y;
371 to->cx = from->cx;
372 to->cy = from->cy;
373 to->flags = from->flags;
376 /* The strings are not copied */
377 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
379 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
380 to->hInstance = HINSTANCE_16(from->hInstance);
381 to->hMenu = HMENU_16(from->hMenu);
382 to->hwndParent = HWND_16(from->hwndParent);
383 to->cy = from->cy;
384 to->cx = from->cx;
385 to->y = from->y;
386 to->x = from->x;
387 to->style = from->style;
388 to->dwExStyle = from->dwExStyle;
391 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
394 to->lpCreateParams = (LPVOID)from->lpCreateParams;
395 to->hInstance = HINSTANCE_32(from->hInstance);
396 to->hMenu = HMENU_32(from->hMenu);
397 to->hwndParent = WIN_Handle32(from->hwndParent);
398 to->cy = from->cy;
399 to->cx = from->cx;
400 to->y = from->y;
401 to->x = from->x;
402 to->style = from->style;
403 to->dwExStyle = from->dwExStyle;
404 to->lpszName = MapSL(from->lpszName);
405 to->lpszClass = MapSL(from->lpszClass);
408 /* The strings are not copied */
409 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
411 to->hOwner = HINSTANCE_16(from->hOwner);
412 to->x = from->x;
413 to->y = from->y;
414 to->cx = from->cx;
415 to->cy = from->cy;
416 to->style = from->style;
417 to->lParam = from->lParam;
420 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
422 to->hOwner = HINSTANCE_32(from->hOwner);
423 to->x = from->x;
424 to->y = from->y;
425 to->cx = from->cx;
426 to->cy = from->cy;
427 to->style = from->style;
428 to->lParam = from->lParam;
429 to->szTitle = MapSL(from->szTitle);
430 to->szClass = MapSL(from->szClass);
433 static WPARAM map_wparam_char_WtoA( WPARAM wParam, DWORD len )
435 WCHAR wch = wParam;
436 BYTE ch[2];
438 RtlUnicodeToMultiByteN( (LPSTR)ch, len, &len, &wch, sizeof(wch) );
439 if (len == 2)
440 return MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(wParam) );
441 else
442 return MAKEWPARAM( ch[0], HIWORD(wParam) );
445 /* call a 32-bit window procedure */
446 static LRESULT call_window_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
448 WNDPROC proc = arg;
450 USER_CheckNotLock();
452 hwnd = WIN_GetFullHandle( hwnd );
453 if (TRACE_ON(relay))
454 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
455 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
457 *result = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
459 if (TRACE_ON(relay))
460 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
461 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, *result );
462 return *result;
465 /* call a 32-bit dialog procedure */
466 static LRESULT call_dialog_proc( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp, LRESULT *result, void *arg )
468 WNDPROC proc = arg;
469 LRESULT ret;
471 USER_CheckNotLock();
473 hwnd = WIN_GetFullHandle( hwnd );
474 if (TRACE_ON(relay))
475 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
476 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp );
478 ret = WINPROC_wrapper( proc, hwnd, msg, wp, lp );
479 *result = GetWindowLongPtrW( hwnd, DWLP_MSGRESULT );
481 if (TRACE_ON(relay))
482 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
483 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wp, lp, ret, *result );
484 return ret;
487 /* call a 16-bit window procedure */
488 static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
489 LRESULT *result, void *arg )
491 WNDPROC16 proc = arg;
492 CONTEXT86 context;
493 size_t size = 0;
494 struct
496 WORD params[5];
497 union
499 CREATESTRUCT16 cs16;
500 DRAWITEMSTRUCT16 dis16;
501 COMPAREITEMSTRUCT16 cis16;
502 } u;
503 } args;
505 USER_CheckNotLock();
507 /* Window procedures want ax = hInstance, ds = es = ss */
509 memset(&context, 0, sizeof(context));
510 context.SegDs = context.SegEs = SELECTOROF(NtCurrentTeb()->WOW32Reserved);
511 context.SegFs = wine_get_fs();
512 context.SegGs = wine_get_gs();
513 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
514 context.SegCs = SELECTOROF(proc);
515 context.Eip = OFFSETOF(proc);
516 context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME, bp);
518 if (lParam)
520 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
521 work if structures passed in lParam are placed in the stack/data
522 segment. Programmers easily make the mistake of converting lParam
523 to a near rather than a far pointer, since Windows apparently
524 allows this. We copy the structures to the 16 bit stack; this is
525 ugly but makes these programs work. */
526 switch (msg)
528 case WM_CREATE:
529 case WM_NCCREATE:
530 size = sizeof(CREATESTRUCT16); break;
531 case WM_DRAWITEM:
532 size = sizeof(DRAWITEMSTRUCT16); break;
533 case WM_COMPAREITEM:
534 size = sizeof(COMPAREITEMSTRUCT16); break;
536 if (size)
538 memcpy( &args.u, MapSL(lParam), size );
539 lParam = PtrToUlong(NtCurrentTeb()->WOW32Reserved) - size;
543 args.params[4] = hwnd;
544 args.params[3] = msg;
545 args.params[2] = wParam;
546 args.params[1] = HIWORD(lParam);
547 args.params[0] = LOWORD(lParam);
548 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
549 *result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
550 return *result;
553 /* call a 16-bit dialog procedure */
554 static LRESULT call_dialog_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
555 LRESULT *result, void *arg )
557 LRESULT ret = call_window_proc16( hwnd, msg, wp, lp, result, arg );
558 *result = GetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT );
559 return LOWORD(ret);
562 /* helper callback for 32W->16 conversion */
563 static LRESULT call_window_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
564 LRESULT *result, void *arg )
566 return WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wp, lp, result, arg );
569 /* helper callback for 32W->16 conversion */
570 static LRESULT call_dialog_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
571 LRESULT *result, void *arg )
573 return WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wp, lp, result, arg );
576 /* helper callback for 16->32W conversion */
577 static LRESULT call_window_proc_AtoW( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
578 LRESULT *result, void *arg )
580 return WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wp, lp, result,
581 arg, WMCHAR_MAP_CALLWINDOWPROC );
584 /* helper callback for 16->32W conversion */
585 static LRESULT call_dialog_proc_AtoW( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
586 LRESULT *result, void *arg )
588 return WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wp, lp, result,
589 arg, WMCHAR_MAP_CALLWINDOWPROC );
593 /**********************************************************************
594 * WINPROC_GetProc16
596 * Get a window procedure pointer that can be passed to the Windows program.
598 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
600 WINDOWPROC *ptr;
602 if (unicode) ptr = alloc_winproc( NULL, proc );
603 else ptr = alloc_winproc( proc, NULL );
605 if (!ptr) return 0;
606 return alloc_win16_thunk( ptr );
610 /**********************************************************************
611 * WINPROC_GetProc
613 * Get a window procedure pointer that can be passed to the Windows program.
615 WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode )
617 WINDOWPROC *ptr = handle_to_proc( proc );
619 if (!ptr) return proc;
620 if (unicode)
622 if (ptr->procW) return ptr->procW;
623 return proc;
625 else
627 if (ptr->procA) return ptr->procA;
628 return proc;
633 /**********************************************************************
634 * WINPROC_AllocProc16
636 * Allocate a window procedure for a window or class.
638 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
639 * lot of windows, it will usually only have a limited number of window procedures, so the
640 * array won't grow too large, and this way we avoid the need to track allocations per window.
642 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
644 WINDOWPROC *proc;
646 if (!func) return NULL;
648 /* check if the function is already a win proc */
649 if (!(proc = handle16_to_proc( func )))
651 EnterCriticalSection( &winproc_cs );
653 /* then check if we already have a winproc for that function */
654 if (!(proc = find_winproc16( func )))
656 if (winproc_used < MAX_WINPROCS)
658 proc = &winproc_array[winproc_used++];
659 proc->proc16 = func;
660 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
661 proc_to_handle(proc), func, winproc_used, MAX_WINPROCS );
663 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
665 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc), func );
667 LeaveCriticalSection( &winproc_cs );
669 return proc_to_handle( proc );
673 /**********************************************************************
674 * WINPROC_AllocProc
676 * Allocate a window procedure for a window or class.
678 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
679 * lot of windows, it will usually only have a limited number of window procedures, so the
680 * array won't grow too large, and this way we avoid the need to track allocations per window.
682 WNDPROC WINPROC_AllocProc( WNDPROC funcA, WNDPROC funcW )
684 WINDOWPROC *proc;
686 if (!(proc = alloc_winproc( funcA, funcW ))) return NULL;
687 return proc_to_handle( proc );
691 /**********************************************************************
692 * WINPROC_IsUnicode
694 * Return the window procedure type, or the default value if not a winproc handle.
696 BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val )
698 WINDOWPROC *ptr = handle_to_proc( proc );
700 if (!ptr) return def_val;
701 if (ptr->procA && ptr->procW) return def_val; /* can be both */
702 return (ptr->procW != NULL);
706 /**********************************************************************
707 * WINPROC_TestLBForStr
709 * Return TRUE if the lparam is a string
711 static inline BOOL WINPROC_TestLBForStr( HWND hwnd, UINT msg )
713 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
714 if (msg <= CB_MSGMAX)
715 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
716 else
717 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
722 static UINT_PTR convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
724 HANDLE dst;
725 UINT sz = GlobalSize16(src);
726 LPSTR ptr16, ptr32;
728 if (!(dst = GlobalAlloc(flags, sz)))
729 return 0;
730 ptr16 = GlobalLock16(src);
731 ptr32 = GlobalLock(dst);
732 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
733 GlobalUnlock16(src);
734 GlobalUnlock(dst);
736 return (UINT_PTR)dst;
739 static HANDLE16 convert_handle_32_to_16(UINT_PTR src, unsigned int flags)
741 HANDLE16 dst;
742 UINT sz = GlobalSize((HANDLE)src);
743 LPSTR ptr16, ptr32;
745 if (!(dst = GlobalAlloc16(flags, sz)))
746 return 0;
747 ptr32 = GlobalLock((HANDLE)src);
748 ptr16 = GlobalLock16(dst);
749 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
750 GlobalUnlock((HANDLE)src);
751 GlobalUnlock16(dst);
753 return dst;
757 /**********************************************************************
758 * WINPROC_CallProcAtoW
760 * Call a window procedure, translating args from Ansi to Unicode.
762 LRESULT WINPROC_CallProcAtoW( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
763 LPARAM lParam, LRESULT *result, void *arg, enum wm_char_mapping mapping )
765 LRESULT ret = 0;
767 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
768 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
770 switch(msg)
772 case WM_NCCREATE:
773 case WM_CREATE:
775 WCHAR *ptr, buffer[512];
776 CREATESTRUCTA *csA = (CREATESTRUCTA *)lParam;
777 CREATESTRUCTW csW = *(CREATESTRUCTW *)csA;
778 MDICREATESTRUCTW mdi_cs;
779 DWORD name_lenA = 0, name_lenW = 0, class_lenA = 0, class_lenW = 0;
781 if (HIWORD(csA->lpszClass))
783 class_lenA = strlen(csA->lpszClass) + 1;
784 RtlMultiByteToUnicodeSize( &class_lenW, csA->lpszClass, class_lenA );
786 if (HIWORD(csA->lpszName))
788 name_lenA = strlen(csA->lpszName) + 1;
789 RtlMultiByteToUnicodeSize( &name_lenW, csA->lpszName, name_lenA );
792 if (!(ptr = get_buffer( buffer, sizeof(buffer), class_lenW + name_lenW ))) break;
794 if (class_lenW)
796 csW.lpszClass = ptr;
797 RtlMultiByteToUnicodeN( ptr, class_lenW, NULL, csA->lpszClass, class_lenA );
799 if (name_lenW)
801 csW.lpszName = ptr + class_lenW/sizeof(WCHAR);
802 RtlMultiByteToUnicodeN( ptr + class_lenW/sizeof(WCHAR), name_lenW, NULL,
803 csA->lpszName, name_lenA );
806 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
808 mdi_cs = *(MDICREATESTRUCTW *)csA->lpCreateParams;
809 mdi_cs.szTitle = csW.lpszName;
810 mdi_cs.szClass = csW.lpszClass;
811 csW.lpCreateParams = &mdi_cs;
814 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
815 free_buffer( buffer, ptr );
817 break;
819 case WM_MDICREATE:
821 WCHAR *ptr, buffer[512];
822 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
823 MDICREATESTRUCTA *csA = (MDICREATESTRUCTA *)lParam;
824 MDICREATESTRUCTW csW;
826 memcpy( &csW, csA, sizeof(csW) );
828 if (HIWORD(csA->szTitle))
830 title_lenA = strlen(csA->szTitle) + 1;
831 RtlMultiByteToUnicodeSize( &title_lenW, csA->szTitle, title_lenA );
833 if (HIWORD(csA->szClass))
835 class_lenA = strlen(csA->szClass) + 1;
836 RtlMultiByteToUnicodeSize( &class_lenW, csA->szClass, class_lenA );
839 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenW + class_lenW ))) break;
841 if (title_lenW)
843 csW.szTitle = ptr;
844 RtlMultiByteToUnicodeN( ptr, title_lenW, NULL, csA->szTitle, title_lenA );
846 if (class_lenW)
848 csW.szClass = ptr + title_lenW/sizeof(WCHAR);
849 RtlMultiByteToUnicodeN( ptr + title_lenW/sizeof(WCHAR), class_lenW, NULL,
850 csA->szClass, class_lenA );
852 ret = callback( hwnd, msg, wParam, (LPARAM)&csW, result, arg );
853 free_buffer( buffer, ptr );
855 break;
857 case WM_GETTEXT:
858 case WM_ASKCBFORMATNAME:
860 WCHAR *ptr, buffer[512];
861 LPSTR str = (LPSTR)lParam;
862 DWORD len = wParam * sizeof(WCHAR);
864 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
865 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
866 if (wParam)
868 len = 0;
869 if (*result)
870 RtlUnicodeToMultiByteN( str, wParam - 1, &len, ptr, strlenW(ptr) * sizeof(WCHAR) );
871 str[len] = 0;
872 *result = len;
874 free_buffer( buffer, ptr );
876 break;
878 case LB_ADDSTRING:
879 case LB_INSERTSTRING:
880 case LB_FINDSTRING:
881 case LB_FINDSTRINGEXACT:
882 case LB_SELECTSTRING:
883 case CB_ADDSTRING:
884 case CB_INSERTSTRING:
885 case CB_FINDSTRING:
886 case CB_FINDSTRINGEXACT:
887 case CB_SELECTSTRING:
888 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
890 ret = callback( hwnd, msg, wParam, lParam, result, arg );
891 break;
893 /* fall through */
894 case WM_SETTEXT:
895 case WM_WININICHANGE:
896 case WM_DEVMODECHANGE:
897 case CB_DIR:
898 case LB_DIR:
899 case LB_ADDFILE:
900 case EM_REPLACESEL:
901 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
902 else
904 WCHAR *ptr, buffer[512];
905 LPCSTR strA = (LPCSTR)lParam;
906 DWORD lenW, lenA = strlen(strA) + 1;
908 RtlMultiByteToUnicodeSize( &lenW, strA, lenA );
909 if ((ptr = get_buffer( buffer, sizeof(buffer), lenW )))
911 RtlMultiByteToUnicodeN( ptr, lenW, NULL, strA, lenA );
912 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
913 free_buffer( buffer, ptr );
916 break;
918 case LB_GETTEXT:
919 case CB_GETLBTEXT:
920 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
922 WCHAR buffer[512]; /* FIXME: fixed sized buffer */
924 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
925 if (*result >= 0)
927 DWORD len;
928 RtlUnicodeToMultiByteN( (LPSTR)lParam, ~0u, &len,
929 buffer, (strlenW(buffer) + 1) * sizeof(WCHAR) );
930 *result = len - 1;
933 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
934 break;
936 case EM_GETLINE:
938 WCHAR *ptr, buffer[512];
939 WORD len = *(WORD *)lParam;
941 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
942 *((WORD *)ptr) = len; /* store the length */
943 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
944 if (*result)
946 DWORD reslen;
947 RtlUnicodeToMultiByteN( (LPSTR)lParam, len, &reslen, ptr, *result * sizeof(WCHAR) );
948 if (reslen < len) ((LPSTR)lParam)[reslen] = 0;
949 *result = reslen;
951 free_buffer( buffer, ptr );
953 break;
955 case WM_GETDLGCODE:
956 if (lParam)
958 MSG newmsg = *(MSG *)lParam;
959 if (map_wparam_AtoW( newmsg.message, &newmsg.wParam, WMCHAR_MAP_NOMAPPING ))
960 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
962 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
963 break;
965 case WM_CHARTOITEM:
966 case WM_MENUCHAR:
967 case WM_CHAR:
968 case WM_DEADCHAR:
969 case WM_SYSCHAR:
970 case WM_SYSDEADCHAR:
971 case EM_SETPASSWORDCHAR:
972 case WM_IME_CHAR:
973 if (map_wparam_AtoW( msg, &wParam, mapping ))
974 ret = callback( hwnd, msg, wParam, lParam, result, arg );
975 break;
977 case WM_GETTEXTLENGTH:
978 case CB_GETLBTEXTLEN:
979 case LB_GETTEXTLEN:
980 ret = callback( hwnd, msg, wParam, lParam, result, arg );
981 if (*result >= 0)
983 WCHAR *ptr, buffer[512];
984 LRESULT tmp;
985 DWORD len = *result + 1;
986 /* Determine respective GETTEXT message */
987 UINT msgGetText = (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
988 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
989 /* wParam differs between the messages */
990 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? len : wParam;
992 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * sizeof(WCHAR) ))) break;
994 if (callback == call_window_proc) /* FIXME: hack */
995 callback( hwnd, msgGetText, wp, (LPARAM)ptr, &tmp, arg );
996 else
997 tmp = SendMessageW( hwnd, msgGetText, wp, (LPARAM)ptr );
998 RtlUnicodeToMultiByteSize( &len, ptr, tmp * sizeof(WCHAR) );
999 *result = len;
1000 free_buffer( buffer, ptr );
1002 break;
1004 case WM_PAINTCLIPBOARD:
1005 case WM_SIZECLIPBOARD:
1006 FIXME_(msg)( "message %s (0x%x) needs translation, please report\n",
1007 SPY_GetMsgName(msg, hwnd), msg );
1008 break;
1010 default:
1011 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1012 break;
1014 return ret;
1018 /**********************************************************************
1019 * WINPROC_CallProcWtoA
1021 * Call a window procedure, translating args from Unicode to Ansi.
1023 static LRESULT WINPROC_CallProcWtoA( winproc_callback_t callback, HWND hwnd, UINT msg, WPARAM wParam,
1024 LPARAM lParam, LRESULT *result, void *arg )
1026 LRESULT ret = 0;
1028 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1029 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1031 switch(msg)
1033 case WM_NCCREATE:
1034 case WM_CREATE:
1035 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
1036 * at this point.
1038 char buffer[1024], *cls, *name;
1039 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
1040 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
1041 MDICREATESTRUCTA mdi_cs;
1042 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
1044 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
1045 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
1047 if (csW->lpszName)
1049 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
1050 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
1052 else
1053 name_lenW = name_lenA = 0;
1055 if (!(cls = get_buffer( buffer, sizeof(buffer), class_lenA + name_lenA + 2 ))) break;
1057 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
1058 cls[class_lenA] = 0;
1059 csA.lpszClass = cls;
1061 if (csW->lpszName)
1063 name = cls + class_lenA + 1;
1064 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
1065 name[name_lenA] = 0;
1066 csA.lpszName = name;
1069 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1071 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
1072 mdi_cs.szTitle = csA.lpszName;
1073 mdi_cs.szClass = csA.lpszClass;
1074 csA.lpCreateParams = &mdi_cs;
1077 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1078 free_buffer( buffer, cls );
1080 break;
1082 case WM_GETTEXT:
1083 case WM_ASKCBFORMATNAME:
1085 char *ptr, buffer[512];
1086 DWORD len = wParam * 2;
1088 if (!(ptr = get_buffer( buffer, sizeof(buffer), len ))) break;
1089 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1090 if (len)
1092 if (*result)
1094 RtlMultiByteToUnicodeN( (LPWSTR)lParam, wParam*sizeof(WCHAR), &len, ptr, strlen(ptr)+1 );
1095 *result = len/sizeof(WCHAR) - 1; /* do not count terminating null */
1097 ((LPWSTR)lParam)[*result] = 0;
1099 free_buffer( buffer, ptr );
1101 break;
1103 case LB_ADDSTRING:
1104 case LB_INSERTSTRING:
1105 case LB_FINDSTRING:
1106 case LB_FINDSTRINGEXACT:
1107 case LB_SELECTSTRING:
1108 case CB_ADDSTRING:
1109 case CB_INSERTSTRING:
1110 case CB_FINDSTRING:
1111 case CB_FINDSTRINGEXACT:
1112 case CB_SELECTSTRING:
1113 if (!lParam || !WINPROC_TestLBForStr( hwnd, msg ))
1115 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1116 break;
1118 /* fall through */
1119 case WM_SETTEXT:
1120 case WM_WININICHANGE:
1121 case WM_DEVMODECHANGE:
1122 case CB_DIR:
1123 case LB_DIR:
1124 case LB_ADDFILE:
1125 case EM_REPLACESEL:
1126 if (!lParam) ret = callback( hwnd, msg, wParam, lParam, result, arg );
1127 else
1129 char *ptr, buffer[512];
1130 LPCWSTR strW = (LPCWSTR)lParam;
1131 DWORD lenA, lenW = (strlenW(strW) + 1) * sizeof(WCHAR);
1133 RtlUnicodeToMultiByteSize( &lenA, strW, lenW );
1134 if ((ptr = get_buffer( buffer, sizeof(buffer), lenA )))
1136 RtlUnicodeToMultiByteN( ptr, lenA, NULL, strW, lenW );
1137 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1138 free_buffer( buffer, ptr );
1141 break;
1143 case WM_MDICREATE:
1145 char *ptr, buffer[1024];
1146 DWORD title_lenA = 0, title_lenW = 0, class_lenA = 0, class_lenW = 0;
1147 MDICREATESTRUCTW *csW = (MDICREATESTRUCTW *)lParam;
1148 MDICREATESTRUCTA csA;
1150 memcpy( &csA, csW, sizeof(csA) );
1152 if (HIWORD(csW->szTitle))
1154 title_lenW = (strlenW(csW->szTitle) + 1) * sizeof(WCHAR);
1155 RtlUnicodeToMultiByteSize( &title_lenA, csW->szTitle, title_lenW );
1157 if (HIWORD(csW->szClass))
1159 class_lenW = (strlenW(csW->szClass) + 1) * sizeof(WCHAR);
1160 RtlUnicodeToMultiByteSize( &class_lenA, csW->szClass, class_lenW );
1163 if (!(ptr = get_buffer( buffer, sizeof(buffer), title_lenA + class_lenA ))) break;
1165 if (title_lenA)
1167 RtlUnicodeToMultiByteN( ptr, title_lenA, NULL, csW->szTitle, title_lenW );
1168 csA.szTitle = ptr;
1170 if (class_lenA)
1172 RtlUnicodeToMultiByteN( ptr + title_lenA, class_lenA, NULL, csW->szClass, class_lenW );
1173 csA.szClass = ptr + title_lenA;
1175 ret = callback( hwnd, msg, wParam, (LPARAM)&csA, result, arg );
1176 free_buffer( buffer, ptr );
1178 break;
1180 case LB_GETTEXT:
1181 case CB_GETLBTEXT:
1182 if (lParam && WINPROC_TestLBForStr( hwnd, msg ))
1184 char buffer[512]; /* FIXME: fixed sized buffer */
1186 ret = callback( hwnd, msg, wParam, (LPARAM)buffer, result, arg );
1187 if (*result >= 0)
1189 DWORD len;
1190 RtlMultiByteToUnicodeN( (LPWSTR)lParam, ~0u, &len, buffer, strlen(buffer) + 1 );
1191 *result = len / sizeof(WCHAR) - 1;
1194 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1195 break;
1197 case EM_GETLINE:
1199 char *ptr, buffer[512];
1200 WORD len = *(WORD *)lParam;
1202 if (!(ptr = get_buffer( buffer, sizeof(buffer), len * 2 ))) break;
1203 *((WORD *)ptr) = len * 2; /* store the length */
1204 ret = callback( hwnd, msg, wParam, (LPARAM)ptr, result, arg );
1205 if (*result)
1207 DWORD reslen;
1208 RtlMultiByteToUnicodeN( (LPWSTR)lParam, len*sizeof(WCHAR), &reslen, ptr, *result );
1209 *result = reslen / sizeof(WCHAR);
1210 if (*result < len) ((LPWSTR)lParam)[*result] = 0;
1212 free_buffer( buffer, ptr );
1214 break;
1216 case WM_GETDLGCODE:
1217 if (lParam)
1219 MSG newmsg = *(MSG *)lParam;
1220 switch(newmsg.message)
1222 case WM_CHAR:
1223 case WM_DEADCHAR:
1224 case WM_SYSCHAR:
1225 case WM_SYSDEADCHAR:
1226 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 1 );
1227 break;
1228 case WM_IME_CHAR:
1229 newmsg.wParam = map_wparam_char_WtoA( newmsg.wParam, 2 );
1230 break;
1232 ret = callback( hwnd, msg, wParam, (LPARAM)&newmsg, result, arg );
1234 else ret = callback( hwnd, msg, wParam, lParam, result, arg );
1235 break;
1237 case WM_CHAR:
1239 WCHAR wch = wParam;
1240 char ch[2];
1241 DWORD len;
1243 RtlUnicodeToMultiByteN( ch, 2, &len, &wch, sizeof(wch) );
1244 ret = callback( hwnd, msg, (BYTE)ch[0], lParam, result, arg );
1245 if (len == 2) ret = callback( hwnd, msg, (BYTE)ch[1], lParam, result, arg );
1247 break;
1249 case WM_CHARTOITEM:
1250 case WM_MENUCHAR:
1251 case WM_DEADCHAR:
1252 case WM_SYSCHAR:
1253 case WM_SYSDEADCHAR:
1254 case EM_SETPASSWORDCHAR:
1255 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,1), lParam, result, arg );
1256 break;
1258 case WM_IME_CHAR:
1259 ret = callback( hwnd, msg, map_wparam_char_WtoA(wParam,2), lParam, result, arg );
1260 break;
1262 case WM_PAINTCLIPBOARD:
1263 case WM_SIZECLIPBOARD:
1264 FIXME_(msg)( "message %s (%04x) needs translation, please report\n",
1265 SPY_GetMsgName(msg, hwnd), msg );
1266 break;
1268 default:
1269 ret = callback( hwnd, msg, wParam, lParam, result, arg );
1270 break;
1273 return ret;
1277 /**********************************************************************
1278 * WINPROC_CallProc16To32A
1280 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
1281 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
1283 LRESULT ret = 0;
1284 HWND hwnd32 = WIN_Handle32( hwnd );
1286 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1287 hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
1289 switch(msg)
1291 case WM_NCCREATE:
1292 case WM_CREATE:
1294 CREATESTRUCT16 *cs16 = MapSL(lParam);
1295 CREATESTRUCTA cs;
1296 MDICREATESTRUCTA mdi_cs;
1298 CREATESTRUCT16to32A( cs16, &cs );
1299 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
1301 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
1302 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
1303 cs.lpCreateParams = &mdi_cs;
1305 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1306 CREATESTRUCT32Ato16( &cs, cs16 );
1308 break;
1309 case WM_MDICREATE:
1311 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
1312 MDICREATESTRUCTA cs;
1314 MDICREATESTRUCT16to32A( cs16, &cs );
1315 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
1316 MDICREATESTRUCT32Ato16( &cs, cs16 );
1318 break;
1319 case WM_MDIACTIVATE:
1320 if (lParam)
1321 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
1322 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1323 else /* message sent to MDI client */
1324 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1325 break;
1326 case WM_MDIGETACTIVE:
1328 BOOL maximized = FALSE;
1329 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
1330 *result = MAKELRESULT( LOWORD(*result), maximized );
1332 break;
1333 case WM_MDISETMENU:
1334 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
1335 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
1336 result, arg );
1337 break;
1338 case WM_GETMINMAXINFO:
1340 MINMAXINFO16 *mmi16 = MapSL(lParam);
1341 MINMAXINFO mmi;
1343 MINMAXINFO16to32( mmi16, &mmi );
1344 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
1345 MINMAXINFO32to16( &mmi, mmi16 );
1347 break;
1348 case WM_WINDOWPOSCHANGING:
1349 case WM_WINDOWPOSCHANGED:
1351 WINDOWPOS16 *winpos16 = MapSL(lParam);
1352 WINDOWPOS winpos;
1354 WINDOWPOS16to32( winpos16, &winpos );
1355 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
1356 WINDOWPOS32to16( &winpos, winpos16 );
1358 break;
1359 case WM_NCCALCSIZE:
1361 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
1362 NCCALCSIZE_PARAMS nc;
1363 WINDOWPOS winpos;
1365 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
1366 if (wParam)
1368 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
1369 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
1370 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
1371 nc.lppos = &winpos;
1373 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
1374 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
1375 if (wParam)
1377 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
1378 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
1379 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
1382 break;
1383 case WM_COMPAREITEM:
1385 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
1386 COMPAREITEMSTRUCT cis;
1387 cis.CtlType = cis16->CtlType;
1388 cis.CtlID = cis16->CtlID;
1389 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
1390 cis.itemID1 = cis16->itemID1;
1391 cis.itemData1 = cis16->itemData1;
1392 cis.itemID2 = cis16->itemID2;
1393 cis.itemData2 = cis16->itemData2;
1394 cis.dwLocaleId = 0; /* FIXME */
1395 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
1397 break;
1398 case WM_DELETEITEM:
1400 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
1401 DELETEITEMSTRUCT dis;
1402 dis.CtlType = dis16->CtlType;
1403 dis.CtlID = dis16->CtlID;
1404 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
1405 dis.itemData = dis16->itemData;
1406 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1408 break;
1409 case WM_MEASUREITEM:
1411 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
1412 MEASUREITEMSTRUCT mis;
1413 mis.CtlType = mis16->CtlType;
1414 mis.CtlID = mis16->CtlID;
1415 mis.itemID = mis16->itemID;
1416 mis.itemWidth = mis16->itemWidth;
1417 mis.itemHeight = mis16->itemHeight;
1418 mis.itemData = mis16->itemData;
1419 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
1420 mis16->itemWidth = (UINT16)mis.itemWidth;
1421 mis16->itemHeight = (UINT16)mis.itemHeight;
1423 break;
1424 case WM_DRAWITEM:
1426 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
1427 DRAWITEMSTRUCT dis;
1428 dis.CtlType = dis16->CtlType;
1429 dis.CtlID = dis16->CtlID;
1430 dis.itemID = dis16->itemID;
1431 dis.itemAction = dis16->itemAction;
1432 dis.itemState = dis16->itemState;
1433 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1434 : WIN_Handle32( dis16->hwndItem );
1435 dis.hDC = HDC_32(dis16->hDC);
1436 dis.itemData = dis16->itemData;
1437 dis.rcItem.left = dis16->rcItem.left;
1438 dis.rcItem.top = dis16->rcItem.top;
1439 dis.rcItem.right = dis16->rcItem.right;
1440 dis.rcItem.bottom = dis16->rcItem.bottom;
1441 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
1443 break;
1444 case WM_COPYDATA:
1446 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
1447 COPYDATASTRUCT cds;
1448 cds.dwData = cds16->dwData;
1449 cds.cbData = cds16->cbData;
1450 cds.lpData = MapSL(cds16->lpData);
1451 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
1453 break;
1454 case WM_GETDLGCODE:
1455 if (lParam)
1457 MSG16 *msg16 = MapSL(lParam);
1458 MSG msg32;
1459 msg32.hwnd = WIN_Handle32( msg16->hwnd );
1460 msg32.message = msg16->message;
1461 msg32.wParam = msg16->wParam;
1462 msg32.lParam = msg16->lParam;
1463 msg32.time = msg16->time;
1464 msg32.pt.x = msg16->pt.x;
1465 msg32.pt.y = msg16->pt.y;
1466 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
1468 else
1469 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1470 break;
1471 case WM_NEXTMENU:
1473 MDINEXTMENU next;
1474 next.hmenuIn = (HMENU)lParam;
1475 next.hmenuNext = 0;
1476 next.hwndNext = 0;
1477 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
1478 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
1480 break;
1481 case WM_ACTIVATE:
1482 case WM_CHARTOITEM:
1483 case WM_COMMAND:
1484 case WM_VKEYTOITEM:
1485 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1486 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1487 break;
1488 case WM_HSCROLL:
1489 case WM_VSCROLL:
1490 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1491 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
1492 break;
1493 case WM_CTLCOLOR:
1494 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
1495 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
1496 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
1497 result, arg );
1498 break;
1499 case WM_GETTEXT:
1500 case WM_SETTEXT:
1501 case WM_WININICHANGE:
1502 case WM_DEVMODECHANGE:
1503 case WM_ASKCBFORMATNAME:
1504 case WM_NOTIFY:
1505 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
1506 break;
1507 case WM_MENUCHAR:
1508 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1509 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1510 break;
1511 case WM_MENUSELECT:
1512 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
1514 HMENU hmenu = HMENU_32(HIWORD(lParam));
1515 UINT pos = MENU_FindSubMenu( &hmenu, HMENU_32(wParam) );
1516 if (pos == 0xffff) pos = 0; /* NO_SELECTED_ITEM */
1517 wParam = pos;
1519 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
1520 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
1521 break;
1522 case WM_PARENTNOTIFY:
1523 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
1524 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
1525 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
1526 else
1527 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1528 break;
1529 case WM_ACTIVATEAPP:
1530 /* We need this when SetActiveWindow sends a Sendmessage16() to
1531 * a 32bit window. Might be superflous with 32bit interprocess
1532 * message queues. */
1533 if (lParam) lParam = HTASK_32(lParam);
1534 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1535 break;
1536 case WM_DDE_INITIATE:
1537 case WM_DDE_TERMINATE:
1538 case WM_DDE_UNADVISE:
1539 case WM_DDE_REQUEST:
1540 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1541 break;
1542 case WM_DDE_ADVISE:
1543 case WM_DDE_DATA:
1544 case WM_DDE_POKE:
1546 HANDLE16 lo16 = LOWORD(lParam);
1547 UINT_PTR lo32 = 0;
1548 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
1549 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
1550 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1552 break; /* FIXME don't know how to free allocated memory (handle) !! */
1553 case WM_DDE_ACK:
1555 UINT_PTR lo = LOWORD(lParam);
1556 UINT_PTR hi = HIWORD(lParam);
1557 int flag = 0;
1558 char buf[2];
1560 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1561 if (GlobalSize16(hi) != 0) flag |= 2;
1562 switch (flag)
1564 case 0:
1565 if (hi)
1567 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1568 hi = 0;
1570 break;
1571 case 1:
1572 break; /* atom, nothing to do */
1573 case 3:
1574 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
1575 /* fall thru */
1576 case 2:
1577 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1578 break;
1580 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
1581 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
1583 break; /* FIXME don't know how to free allocated memory (handle) !! */
1584 case WM_DDE_EXECUTE:
1585 lParam = convert_handle_16_to_32( lParam, GMEM_DDESHARE );
1586 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1587 break; /* FIXME don't know how to free allocated memory (handle) !! */
1588 case WM_PAINTCLIPBOARD:
1589 case WM_SIZECLIPBOARD:
1590 FIXME_(msg)( "message %04x needs translation\n", msg );
1591 break;
1592 default:
1593 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
1594 break;
1596 return ret;
1600 /**********************************************************************
1601 * __wine_call_wndproc (USER.1010)
1603 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
1604 WINDOWPROC *proc )
1606 LRESULT result;
1608 if (proc->procA)
1609 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
1610 else
1611 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
1612 return result;
1616 /**********************************************************************
1617 * WINPROC_CallProc32ATo16
1619 * Call a 16-bit window procedure, translating the 32-bit args.
1621 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
1622 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
1624 LRESULT ret = 0;
1626 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1627 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
1629 switch(msg)
1631 case WM_NCCREATE:
1632 case WM_CREATE:
1634 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
1635 CREATESTRUCT16 cs;
1636 MDICREATESTRUCT16 mdi_cs16;
1637 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
1639 CREATESTRUCT32Ato16( cs32, &cs );
1640 cs.lpszName = MapLS( cs32->lpszName );
1641 cs.lpszClass = MapLS( cs32->lpszClass );
1643 if (mdi_child)
1645 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
1646 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
1647 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
1648 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
1649 cs.lpCreateParams = MapLS( &mdi_cs16 );
1651 lParam = MapLS( &cs );
1652 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1653 UnMapLS( lParam );
1654 UnMapLS( cs.lpszName );
1655 UnMapLS( cs.lpszClass );
1656 if (mdi_child)
1658 UnMapLS( cs.lpCreateParams );
1659 UnMapLS( mdi_cs16.szTitle );
1660 UnMapLS( mdi_cs16.szClass );
1663 break;
1664 case WM_MDICREATE:
1666 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
1667 MDICREATESTRUCT16 cs;
1669 MDICREATESTRUCT32Ato16( cs32, &cs );
1670 cs.szTitle = MapLS( cs32->szTitle );
1671 cs.szClass = MapLS( cs32->szClass );
1672 lParam = MapLS( &cs );
1673 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1674 UnMapLS( lParam );
1675 UnMapLS( cs.szTitle );
1676 UnMapLS( cs.szClass );
1678 break;
1679 case WM_MDIACTIVATE:
1680 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1681 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
1682 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
1683 else
1684 ret = callback( HWND_16(hwnd), msg, HWND_16( (HWND)wParam ), 0, result, arg );
1685 break;
1686 case WM_MDIGETACTIVE:
1687 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1688 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
1689 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
1690 break;
1691 case WM_MDISETMENU:
1692 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
1693 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
1694 break;
1695 case WM_GETMINMAXINFO:
1697 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
1698 MINMAXINFO16 mmi;
1700 MINMAXINFO32to16( mmi32, &mmi );
1701 lParam = MapLS( &mmi );
1702 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1703 UnMapLS( lParam );
1704 MINMAXINFO16to32( &mmi, mmi32 );
1706 break;
1707 case WM_NCCALCSIZE:
1709 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
1710 NCCALCSIZE_PARAMS16 nc;
1711 WINDOWPOS16 winpos;
1713 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
1714 if (wParam)
1716 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
1717 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
1718 WINDOWPOS32to16( nc32->lppos, &winpos );
1719 nc.lppos = MapLS( &winpos );
1721 lParam = MapLS( &nc );
1722 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1723 UnMapLS( lParam );
1724 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
1725 if (wParam)
1727 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
1728 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
1729 WINDOWPOS16to32( &winpos, nc32->lppos );
1730 UnMapLS( nc.lppos );
1733 break;
1734 case WM_WINDOWPOSCHANGING:
1735 case WM_WINDOWPOSCHANGED:
1737 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
1738 WINDOWPOS16 winpos;
1740 WINDOWPOS32to16( winpos32, &winpos );
1741 lParam = MapLS( &winpos );
1742 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1743 UnMapLS( lParam );
1744 WINDOWPOS16to32( &winpos, winpos32 );
1746 break;
1747 case WM_COMPAREITEM:
1749 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
1750 COMPAREITEMSTRUCT16 cis;
1751 cis.CtlType = cis32->CtlType;
1752 cis.CtlID = cis32->CtlID;
1753 cis.hwndItem = HWND_16( cis32->hwndItem );
1754 cis.itemID1 = cis32->itemID1;
1755 cis.itemData1 = cis32->itemData1;
1756 cis.itemID2 = cis32->itemID2;
1757 cis.itemData2 = cis32->itemData2;
1758 lParam = MapLS( &cis );
1759 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1760 UnMapLS( lParam );
1762 break;
1763 case WM_DELETEITEM:
1765 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
1766 DELETEITEMSTRUCT16 dis;
1767 dis.CtlType = dis32->CtlType;
1768 dis.CtlID = dis32->CtlID;
1769 dis.itemID = dis32->itemID;
1770 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1771 : HWND_16( dis32->hwndItem );
1772 dis.itemData = dis32->itemData;
1773 lParam = MapLS( &dis );
1774 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1775 UnMapLS( lParam );
1777 break;
1778 case WM_DRAWITEM:
1780 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
1781 DRAWITEMSTRUCT16 dis;
1782 dis.CtlType = dis32->CtlType;
1783 dis.CtlID = dis32->CtlID;
1784 dis.itemID = dis32->itemID;
1785 dis.itemAction = dis32->itemAction;
1786 dis.itemState = dis32->itemState;
1787 dis.hwndItem = HWND_16( dis32->hwndItem );
1788 dis.hDC = HDC_16(dis32->hDC);
1789 dis.itemData = dis32->itemData;
1790 dis.rcItem.left = dis32->rcItem.left;
1791 dis.rcItem.top = dis32->rcItem.top;
1792 dis.rcItem.right = dis32->rcItem.right;
1793 dis.rcItem.bottom = dis32->rcItem.bottom;
1794 lParam = MapLS( &dis );
1795 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1796 UnMapLS( lParam );
1798 break;
1799 case WM_MEASUREITEM:
1801 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
1802 MEASUREITEMSTRUCT16 mis;
1803 mis.CtlType = mis32->CtlType;
1804 mis.CtlID = mis32->CtlID;
1805 mis.itemID = mis32->itemID;
1806 mis.itemWidth = mis32->itemWidth;
1807 mis.itemHeight = mis32->itemHeight;
1808 mis.itemData = mis32->itemData;
1809 lParam = MapLS( &mis );
1810 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1811 UnMapLS( lParam );
1812 mis32->itemWidth = mis.itemWidth;
1813 mis32->itemHeight = mis.itemHeight;
1815 break;
1816 case WM_COPYDATA:
1818 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
1819 COPYDATASTRUCT16 cds;
1821 cds.dwData = cds32->dwData;
1822 cds.cbData = cds32->cbData;
1823 cds.lpData = MapLS( cds32->lpData );
1824 lParam = MapLS( &cds );
1825 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1826 UnMapLS( lParam );
1827 UnMapLS( cds.lpData );
1829 break;
1830 case WM_GETDLGCODE:
1831 if (lParam)
1833 MSG *msg32 = (MSG *)lParam;
1834 MSG16 msg16;
1836 msg16.hwnd = HWND_16( msg32->hwnd );
1837 msg16.message = msg32->message;
1838 msg16.wParam = msg32->wParam;
1839 msg16.lParam = msg32->lParam;
1840 msg16.time = msg32->time;
1841 msg16.pt.x = msg32->pt.x;
1842 msg16.pt.y = msg32->pt.y;
1843 lParam = MapLS( &msg16 );
1844 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1845 UnMapLS( lParam );
1847 else
1848 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1849 break;
1850 case WM_NEXTMENU:
1852 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1853 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
1854 next->hmenuNext = HMENU_32( LOWORD(*result) );
1855 next->hwndNext = WIN_Handle32( HIWORD(*result) );
1856 *result = 0;
1858 break;
1859 case WM_GETTEXT:
1860 case WM_ASKCBFORMATNAME:
1861 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
1862 /* fall through */
1863 case WM_NOTIFY:
1864 case WM_SETTEXT:
1865 case WM_WININICHANGE:
1866 case WM_DEVMODECHANGE:
1867 lParam = MapLS( (void *)lParam );
1868 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1869 UnMapLS( lParam );
1870 break;
1871 case WM_ACTIVATE:
1872 case WM_CHARTOITEM:
1873 case WM_COMMAND:
1874 case WM_VKEYTOITEM:
1875 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ),
1876 result, arg );
1877 break;
1878 case WM_HSCROLL:
1879 case WM_VSCROLL:
1880 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( HIWORD(wParam), (HWND16)lParam ),
1881 result, arg );
1882 break;
1883 case WM_CTLCOLORMSGBOX:
1884 case WM_CTLCOLOREDIT:
1885 case WM_CTLCOLORLISTBOX:
1886 case WM_CTLCOLORBTN:
1887 case WM_CTLCOLORDLG:
1888 case WM_CTLCOLORSCROLLBAR:
1889 case WM_CTLCOLORSTATIC:
1890 ret = callback( HWND_16(hwnd), WM_CTLCOLOR, wParam,
1891 MAKELPARAM( (HWND16)lParam, msg - WM_CTLCOLORMSGBOX ), result, arg );
1892 break;
1893 case WM_MENUSELECT:
1894 if(HIWORD(wParam) & MF_POPUP)
1896 HMENU hmenu;
1897 if ((HIWORD(wParam) != 0xffff) || lParam)
1899 if ((hmenu = GetSubMenu( (HMENU)lParam, LOWORD(wParam) )))
1901 ret = callback( HWND_16(hwnd), msg, HMENU_16(hmenu),
1902 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1903 break;
1907 /* fall through */
1908 case WM_MENUCHAR:
1909 ret = callback( HWND_16(hwnd), msg, wParam,
1910 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1911 break;
1912 case WM_PARENTNOTIFY:
1913 if ((LOWORD(wParam) == WM_CREATE) || (LOWORD(wParam) == WM_DESTROY))
1914 ret = callback( HWND_16(hwnd), msg, wParam,
1915 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ), result, arg );
1916 else
1917 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1918 break;
1919 case WM_ACTIVATEAPP:
1920 ret = callback( HWND_16(hwnd), msg, wParam, HTASK_16( (HANDLE)lParam ), result, arg );
1921 break;
1922 case WM_PAINT:
1923 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
1924 ret = callback( HWND_16(hwnd), WM_PAINTICON, 1, lParam, result, arg );
1925 else
1926 ret = callback( HWND_16(hwnd), WM_PAINT, wParam, lParam, result, arg );
1927 break;
1928 case WM_ERASEBKGND:
1929 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON )) msg = WM_ICONERASEBKGND;
1930 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1931 break;
1932 case WM_DDE_INITIATE:
1933 case WM_DDE_TERMINATE:
1934 case WM_DDE_UNADVISE:
1935 case WM_DDE_REQUEST:
1936 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam), lParam, result, arg );
1937 break;
1938 case WM_DDE_ADVISE:
1939 case WM_DDE_DATA:
1940 case WM_DDE_POKE:
1942 UINT_PTR lo32, hi;
1943 HANDLE16 lo16 = 0;
1945 UnpackDDElParam( msg, lParam, &lo32, &hi );
1946 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
1947 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
1948 MAKELPARAM(lo16, hi), result, arg );
1950 break; /* FIXME don't know how to free allocated memory (handle) !! */
1951 case WM_DDE_ACK:
1953 UINT_PTR lo, hi;
1954 int flag = 0;
1955 char buf[2];
1957 UnpackDDElParam( msg, lParam, &lo, &hi );
1959 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
1960 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
1961 switch (flag)
1963 case 0:
1964 if (hi)
1966 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1967 hi = 0;
1969 break;
1970 case 1:
1971 break; /* atom, nothing to do */
1972 case 3:
1973 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
1974 /* fall thru */
1975 case 2:
1976 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
1977 break;
1979 ret = callback( HWND_16(hwnd), msg, HWND_16((HWND)wParam),
1980 MAKELPARAM(lo, hi), result, arg );
1982 break; /* FIXME don't know how to free allocated memory (handle) !! */
1983 case WM_DDE_EXECUTE:
1984 lParam = convert_handle_32_to_16(lParam, GMEM_DDESHARE);
1985 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1986 break; /* FIXME don't know how to free allocated memory (handle) !! */
1987 case SBM_SETRANGE:
1988 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
1989 break;
1990 case SBM_GETRANGE:
1991 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
1992 *(LPINT)wParam = LOWORD(*result);
1993 *(LPINT)lParam = HIWORD(*result);
1994 break;
1995 case BM_GETCHECK:
1996 case BM_SETCHECK:
1997 case BM_GETSTATE:
1998 case BM_SETSTATE:
1999 case BM_SETSTYLE:
2000 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
2001 break;
2002 case EM_GETSEL:
2003 case EM_GETRECT:
2004 case EM_SETRECT:
2005 case EM_SETRECTNP:
2006 case EM_SCROLL:
2007 case EM_LINESCROLL:
2008 case EM_SCROLLCARET:
2009 case EM_GETMODIFY:
2010 case EM_SETMODIFY:
2011 case EM_GETLINECOUNT:
2012 case EM_LINEINDEX:
2013 case EM_SETHANDLE:
2014 case EM_GETHANDLE:
2015 case EM_GETTHUMB:
2016 case EM_LINELENGTH:
2017 case EM_REPLACESEL:
2018 case EM_GETLINE:
2019 case EM_LIMITTEXT:
2020 case EM_CANUNDO:
2021 case EM_UNDO:
2022 case EM_FMTLINES:
2023 case EM_LINEFROMCHAR:
2024 case EM_SETTABSTOPS:
2025 case EM_SETPASSWORDCHAR:
2026 case EM_EMPTYUNDOBUFFER:
2027 case EM_GETFIRSTVISIBLELINE:
2028 case EM_SETREADONLY:
2029 case EM_SETWORDBREAKPROC:
2030 case EM_GETWORDBREAKPROC:
2031 case EM_GETPASSWORDCHAR:
2032 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
2033 break;
2034 case EM_SETSEL:
2035 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
2036 break;
2037 case LB_CARETOFF:
2038 case LB_CARETON:
2039 case LB_DELETESTRING:
2040 case LB_GETANCHORINDEX:
2041 case LB_GETCARETINDEX:
2042 case LB_GETCOUNT:
2043 case LB_GETCURSEL:
2044 case LB_GETHORIZONTALEXTENT:
2045 case LB_GETITEMDATA:
2046 case LB_GETITEMHEIGHT:
2047 case LB_GETSEL:
2048 case LB_GETSELCOUNT:
2049 case LB_GETTEXTLEN:
2050 case LB_GETTOPINDEX:
2051 case LB_RESETCONTENT:
2052 case LB_SELITEMRANGE:
2053 case LB_SELITEMRANGEEX:
2054 case LB_SETANCHORINDEX:
2055 case LB_SETCARETINDEX:
2056 case LB_SETCOLUMNWIDTH:
2057 case LB_SETCURSEL:
2058 case LB_SETHORIZONTALEXTENT:
2059 case LB_SETITEMDATA:
2060 case LB_SETITEMHEIGHT:
2061 case LB_SETSEL:
2062 case LB_SETTOPINDEX:
2063 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
2064 break;
2065 case LB_ADDSTRING:
2066 case LB_FINDSTRING:
2067 case LB_FINDSTRINGEXACT:
2068 case LB_INSERTSTRING:
2069 case LB_SELECTSTRING:
2070 case LB_GETTEXT:
2071 case LB_DIR:
2072 case LB_ADDFILE:
2073 lParam = MapLS( (LPSTR)lParam );
2074 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
2075 UnMapLS( lParam );
2076 break;
2077 case LB_GETSELITEMS:
2079 INT *items32 = (INT *)lParam;
2080 INT16 *items, buffer[512];
2081 unsigned int i;
2083 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
2084 if (!(items = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
2085 lParam = MapLS( items );
2086 ret = callback( HWND_16(hwnd), LB_GETSELITEMS16, wParam, lParam, result, arg );
2087 UnMapLS( lParam );
2088 for (i = 0; i < wParam; i++) items32[i] = items[i];
2089 free_buffer( buffer, items );
2091 break;
2092 case LB_SETTABSTOPS:
2093 if (wParam)
2095 INT *stops32 = (INT *)lParam;
2096 INT16 *stops, buffer[512];
2097 unsigned int i;
2099 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
2100 if (!(stops = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
2101 for (i = 0; i < wParam; i++) stops[i] = stops32[i];
2102 lParam = MapLS( stops );
2103 ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
2104 UnMapLS( lParam );
2105 free_buffer( buffer, stops );
2107 else ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
2108 break;
2109 case CB_DELETESTRING:
2110 case CB_GETCOUNT:
2111 case CB_GETLBTEXTLEN:
2112 case CB_LIMITTEXT:
2113 case CB_RESETCONTENT:
2114 case CB_SETEDITSEL:
2115 case CB_GETCURSEL:
2116 case CB_SETCURSEL:
2117 case CB_SHOWDROPDOWN:
2118 case CB_SETITEMDATA:
2119 case CB_SETITEMHEIGHT:
2120 case CB_GETITEMHEIGHT:
2121 case CB_SETEXTENDEDUI:
2122 case CB_GETEXTENDEDUI:
2123 case CB_GETDROPPEDSTATE:
2124 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
2125 break;
2126 case CB_GETEDITSEL:
2127 ret = callback( HWND_16(hwnd), CB_GETEDITSEL16, wParam, lParam, result, arg );
2128 if (wParam) *((PUINT)(wParam)) = LOWORD(*result);
2129 if (lParam) *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: substract 1? */
2130 break;
2131 case CB_ADDSTRING:
2132 case CB_FINDSTRING:
2133 case CB_FINDSTRINGEXACT:
2134 case CB_INSERTSTRING:
2135 case CB_SELECTSTRING:
2136 case CB_DIR:
2137 case CB_GETLBTEXT:
2138 lParam = MapLS( (LPSTR)lParam );
2139 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
2140 UnMapLS( lParam );
2141 break;
2142 case LB_GETITEMRECT:
2143 case CB_GETDROPPEDCONTROLRECT:
2145 RECT *r32 = (RECT *)lParam;
2146 RECT16 rect;
2147 lParam = MapLS( &rect );
2148 ret = callback( HWND_16(hwnd),
2149 (msg == LB_GETITEMRECT) ? LB_GETITEMRECT16 : CB_GETDROPPEDCONTROLRECT16,
2150 wParam, lParam, result, arg );
2151 UnMapLS( lParam );
2152 RECT16to32( &rect, r32 );
2154 break;
2155 case WM_PAINTCLIPBOARD:
2156 case WM_SIZECLIPBOARD:
2157 FIXME_(msg)( "message %04x needs translation\n", msg );
2158 break;
2159 /* the following messages should not be sent to 16-bit apps */
2160 case WM_SIZING:
2161 case WM_MOVING:
2162 case WM_CAPTURECHANGED:
2163 case WM_STYLECHANGING:
2164 case WM_STYLECHANGED:
2165 break;
2166 default:
2167 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
2168 break;
2170 return ret;
2174 /**********************************************************************
2175 * WINPROC_call_window
2177 * Call the window procedure of the specified window.
2179 BOOL WINPROC_call_window( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2180 LRESULT *result, BOOL unicode, enum wm_char_mapping mapping )
2182 WND *wndPtr;
2183 WINDOWPROC *proc;
2185 if (!(wndPtr = WIN_GetPtr( hwnd ))) return FALSE;
2186 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP) return FALSE;
2187 if (wndPtr->tid != GetCurrentThreadId())
2189 WIN_ReleasePtr( wndPtr );
2190 return FALSE;
2192 proc = handle_to_proc( wndPtr->winproc );
2193 WIN_ReleasePtr( wndPtr );
2195 if (!proc) return TRUE;
2197 if (unicode)
2199 if (proc->procW)
2200 call_window_proc( hwnd, msg, wParam, lParam, result, proc->procW );
2201 else if (proc->procA)
2202 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procA );
2203 else
2204 WINPROC_CallProcWtoA( call_window_proc_Ato16, hwnd, msg, wParam, lParam, result, proc->proc16 );
2206 else
2208 if (proc->procA)
2209 call_window_proc( hwnd, msg, wParam, lParam, result, proc->procA );
2210 else if (proc->procW)
2211 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, result, proc->procW, mapping );
2212 else
2213 WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wParam, lParam, result, proc->proc16 );
2215 return TRUE;
2219 /**********************************************************************
2220 * CallWindowProc (USER.122)
2222 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2223 WPARAM16 wParam, LPARAM lParam )
2225 WINDOWPROC *proc;
2226 LRESULT result;
2228 if (!func) return 0;
2230 if (!(proc = handle16_to_proc( func )))
2231 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
2232 else if (proc->procA)
2233 WINPROC_CallProc16To32A( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2234 else if (proc->procW)
2235 WINPROC_CallProc16To32A( call_window_proc_AtoW, hwnd, msg, wParam, lParam, &result, proc->procW );
2236 else
2237 call_window_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2239 return result;
2243 /**********************************************************************
2244 * CallWindowProcA (USER32.@)
2246 * The CallWindowProc() function invokes the windows procedure _func_,
2247 * with _hwnd_ as the target window, the message specified by _msg_, and
2248 * the message parameters _wParam_ and _lParam_.
2250 * Some kinds of argument conversion may be done, I'm not sure what.
2252 * CallWindowProc() may be used for windows subclassing. Use
2253 * SetWindowLong() to set a new windows procedure for windows of the
2254 * subclass, and handle subclassed messages in the new windows
2255 * procedure. The new windows procedure may then use CallWindowProc()
2256 * with _func_ set to the parent class's windows procedure to dispatch
2257 * the message to the superclass.
2259 * RETURNS
2261 * The return value is message dependent.
2263 * CONFORMANCE
2265 * ECMA-234, Win32
2267 LRESULT WINAPI CallWindowProcA(
2268 WNDPROC func, /* [in] window procedure */
2269 HWND hwnd, /* [in] target window */
2270 UINT msg, /* [in] message */
2271 WPARAM wParam, /* [in] message dependent parameter */
2272 LPARAM lParam /* [in] message dependent parameter */
2274 WINDOWPROC *proc;
2275 LRESULT result;
2277 if (!func) return 0;
2279 if (!(proc = handle_to_proc( func )))
2280 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2281 else if (proc->procA)
2282 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2283 else if (proc->procW)
2284 WINPROC_CallProcAtoW( call_window_proc, hwnd, msg, wParam, lParam, &result,
2285 proc->procW, WMCHAR_MAP_CALLWINDOWPROC );
2286 else
2287 WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2288 return result;
2292 /**********************************************************************
2293 * CallWindowProcW (USER32.@)
2295 * See CallWindowProcA.
2297 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2298 WPARAM wParam, LPARAM lParam )
2300 WINDOWPROC *proc;
2301 LRESULT result;
2303 if (!func) return 0;
2305 if (!(proc = handle_to_proc( func )))
2306 call_window_proc( hwnd, msg, wParam, lParam, &result, func );
2307 else if (proc->procW)
2308 call_window_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2309 else if (proc->procA)
2310 WINPROC_CallProcWtoA( call_window_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2311 else
2312 WINPROC_CallProcWtoA( call_window_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2313 return result;
2317 /**********************************************************************
2318 * WINPROC_CallDlgProc16
2320 INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
2322 WINDOWPROC *proc;
2323 LRESULT result;
2324 INT_PTR ret;
2326 if (!func) return 0;
2328 if (!(proc = handle16_to_proc( (WNDPROC16)func )))
2330 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, func );
2332 else if (proc->procA)
2334 ret = WINPROC_CallProc16To32A( call_dialog_proc, hwnd, msg, wParam, lParam,
2335 &result, proc->procA );
2336 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2338 else if (proc->procW)
2340 ret = WINPROC_CallProc16To32A( call_dialog_proc_AtoW, hwnd, msg, wParam, lParam,
2341 &result, proc->procW );
2342 SetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT, result );
2344 else
2346 ret = call_dialog_proc16( hwnd, msg, wParam, lParam, &result, proc->proc16 );
2348 return ret;
2352 /**********************************************************************
2353 * WINPROC_CallDlgProcA
2355 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2357 WINDOWPROC *proc;
2358 LRESULT result;
2359 INT_PTR ret;
2361 if (!func) return 0;
2363 if (!(proc = handle_to_proc( func )))
2364 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2365 else if (proc->procA)
2366 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procA );
2367 else if (proc->procW)
2369 ret = WINPROC_CallProcAtoW( call_dialog_proc, hwnd, msg, wParam, lParam, &result,
2370 proc->procW, WMCHAR_MAP_CALLWINDOWPROC );
2371 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2373 else
2375 ret = WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2376 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2378 return ret;
2382 /**********************************************************************
2383 * WINPROC_CallDlgProcW
2385 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
2387 WINDOWPROC *proc;
2388 LRESULT result;
2389 INT_PTR ret;
2391 if (!func) return 0;
2393 if (!(proc = handle_to_proc( func )))
2394 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, func );
2395 else if (proc->procW)
2396 ret = call_dialog_proc( hwnd, msg, wParam, lParam, &result, proc->procW );
2397 else if (proc->procA)
2399 ret = WINPROC_CallProcWtoA( call_dialog_proc, hwnd, msg, wParam, lParam, &result, proc->procA );
2400 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2402 else
2404 ret = WINPROC_CallProcWtoA( call_dialog_proc_Ato16, hwnd, msg, wParam, lParam, &result, proc->proc16 );
2405 SetWindowLongPtrW( hwnd, DWLP_MSGRESULT, result );
2407 return ret;