Moved private USER definitions to a new user_private.h header, and
[wine.git] / windows / winproc.c
blobbab70339bc05cb56c4618c79e03a4a51ba20f1c9
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
23 #include "wine/port.h"
25 #include <stdarg.h>
26 #include <string.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "wingdi.h"
31 #include "wownt32.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "stackframe.h"
35 #include "controls.h"
36 #include "heap.h"
37 #include "win.h"
38 #include "winproc.h"
39 #include "message.h"
40 #include "user_private.h"
41 #include "thread.h"
42 #include "dde.h"
43 #include "winternl.h"
44 #include "wine/unicode.h"
45 #include "wine/debug.h"
47 WINE_DECLARE_DEBUG_CHANNEL(msg);
48 WINE_DECLARE_DEBUG_CHANNEL(relay);
49 WINE_DEFAULT_DEBUG_CHANNEL(win);
51 #ifdef __i386__
53 #include "pshpack1.h"
55 /* Window procedure 16-to-32-bit thunk */
56 typedef struct
58 BYTE popl_eax; /* popl %eax (return address) */
59 BYTE pushl_func; /* pushl $proc */
60 WNDPROC proc;
61 BYTE pushl_eax; /* pushl %eax */
62 BYTE ljmp; /* ljmp relay*/
63 DWORD relay_offset; /* __wine_call_wndproc_32A/W */
64 WORD relay_sel;
65 } WINPROC_THUNK_FROM16;
67 /* Window procedure 32-to-16-bit thunk */
68 typedef struct
70 BYTE popl_eax; /* popl %eax (return address) */
71 BYTE pushl_func; /* pushl $proc */
72 WNDPROC16 proc;
73 BYTE pushl_eax; /* pushl %eax */
74 BYTE jmp; /* jmp relay (relative jump)*/
75 void (*relay)(); /* WINPROC_CallProc32ATo16() */
76 } WINPROC_THUNK_FROM32;
78 /* Simple jmp to call 32-bit procedure directly */
79 typedef struct
81 BYTE jmp; /* jmp proc (relative jump) */
82 WNDPROC proc;
83 } WINPROC_JUMP;
85 #include "poppack.h"
87 #else /* __i386__ */
89 typedef struct
91 WNDPROC proc;
92 } WINPROC_THUNK_FROM16;
94 typedef struct
96 WNDPROC16 proc;
97 } WINPROC_THUNK_FROM32;
99 typedef struct
101 WNDPROC proc;
102 } WINPROC_JUMP;
104 #endif /* __i386__ */
106 typedef union
108 WINPROC_THUNK_FROM16 t_from16;
109 WINPROC_THUNK_FROM32 t_from32;
110 } WINPROC_THUNK;
112 typedef struct tagWINDOWPROC
114 WINPROC_THUNK thunk; /* Thunk */
115 WINPROC_JUMP jmp; /* Jump */
116 BYTE type; /* Function type */
117 } WINDOWPROC;
119 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
120 UINT msg, WPARAM wParam,
121 LPARAM lParam );
122 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
123 UINT msg, WPARAM wParam,
124 LPARAM lParam );
126 #define MAX_WINPROCS (0x10000 / sizeof(WINDOWPROC))
128 static WINDOWPROC winproc_array[MAX_WINPROCS];
129 static UINT winproc_used;
131 static CRITICAL_SECTION winproc_cs;
132 static CRITICAL_SECTION_DEBUG critsect_debug =
134 0, 0, &winproc_cs,
135 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
136 0, 0, { 0, (DWORD)(__FILE__ ": winproc_cs") }
138 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
140 static BOOL is_valid_winproc( WINDOWPROC *proc )
142 /* check alignment */
143 if (((BYTE *)proc - (BYTE *)winproc_array) % sizeof(*proc)) return FALSE;
144 /* check array limits */
145 if (proc < winproc_array || proc >= winproc_array + winproc_used) return FALSE;
146 return (proc->type != WIN_PROC_INVALID);
149 /* find an existing winproc for a given function and type */
150 /* FIXME: probably should do something more clever than a linear search */
151 static inline WINDOWPROC *find_winproc( WNDPROC func, WINDOWPROCTYPE type )
153 unsigned int i;
155 if (type == WIN_PROC_16)
157 for (i = 0; i < winproc_used; i++)
159 if (winproc_array[i].type == type &&
160 winproc_array[i].thunk.t_from32.proc == (WNDPROC16)func)
161 return &winproc_array[i];
164 else
166 for (i = 0; i < winproc_used; i++)
168 if (winproc_array[i].type == type &&
169 winproc_array[i].thunk.t_from16.proc == func)
170 return &winproc_array[i];
173 return NULL;
176 /* initialize a new winproc */
177 static inline void set_winproc( WINDOWPROC *proc, WNDPROC func, WINDOWPROCTYPE type )
179 #ifdef __i386__
180 static FARPROC16 relay_32A, relay_32W;
182 switch(type)
184 case WIN_PROC_16:
185 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
186 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
187 proc->thunk.t_from32.proc = (WNDPROC16)func;
188 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
189 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
190 proc->thunk.t_from32.relay = /* relative jump */
191 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
192 (DWORD)(&proc->thunk.t_from32.relay + 1));
193 break;
194 case WIN_PROC_32A:
195 if (!relay_32A) relay_32A = GetProcAddress16( GetModuleHandle16("user"),
196 "__wine_call_wndproc_32A" );
197 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
198 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
199 proc->thunk.t_from16.proc = func;
200 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
201 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
202 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32A);
203 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32A);
204 proc->jmp.jmp = 0xe9;
205 /* Fixup relative jump */
206 proc->jmp.proc = (WNDPROC)((DWORD)func - (DWORD)(&proc->jmp.proc + 1));
207 break;
208 case WIN_PROC_32W:
209 if (!relay_32W) relay_32W = GetProcAddress16( GetModuleHandle16("user"),
210 "__wine_call_wndproc_32W" );
211 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
212 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
213 proc->thunk.t_from16.proc = func;
214 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
215 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
216 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32W);
217 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32W);
218 proc->jmp.jmp = 0xe9;
219 /* Fixup relative jump */
220 proc->jmp.proc = (WNDPROC)((char *)func - (char *)(&proc->jmp.proc + 1));
221 break;
222 default:
223 /* Should not happen */
224 break;
226 #else /* __i386__ */
227 switch(type)
229 case WIN_PROC_16:
230 proc->thunk.t_from32.proc = (WNDPROC16)func;
231 break;
232 case WIN_PROC_32A:
233 case WIN_PROC_32W:
234 proc->thunk.t_from16.proc = func;
235 break;
236 default:
237 /* Should not happen */
238 break;
240 #endif /* __i386__ */
242 proc->type = type;
245 static WORD get_winproc_selector(void)
247 static LONG winproc_selector;
248 WORD ret;
250 if (!(ret = winproc_selector))
252 LDT_ENTRY entry;
253 WORD sel = wine_ldt_alloc_entries(1);
254 wine_ldt_set_base( &entry, winproc_array );
255 wine_ldt_set_limit( &entry, sizeof(winproc_array) - 1 );
256 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
257 wine_ldt_set_entry( sel, &entry );
258 if (!(ret = InterlockedCompareExchange( &winproc_selector, sel, 0 ))) ret = sel;
259 else wine_ldt_free_entries( sel, 1 ); /* somebody beat us to it */
261 return ret;
265 #ifdef __i386__
266 /* Some window procedures modify register they shouldn't, or are not
267 * properly declared stdcall; so we need a small assembly wrapper to
268 * call them. */
269 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
270 WPARAM wParam, LPARAM lParam );
271 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
272 "pushl %ebp\n\t"
273 "movl %esp,%ebp\n\t"
274 "pushl %edi\n\t"
275 "pushl %esi\n\t"
276 "pushl %ebx\n\t"
277 "pushl 24(%ebp)\n\t"
278 "pushl 20(%ebp)\n\t"
279 "pushl 16(%ebp)\n\t"
280 "pushl 12(%ebp)\n\t"
281 "movl 8(%ebp),%eax\n\t"
282 "call *%eax\n\t"
283 "leal -12(%ebp),%esp\n\t"
284 "popl %ebx\n\t"
285 "popl %esi\n\t"
286 "popl %edi\n\t"
287 "leave\n\t"
288 "ret" );
289 #else
290 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
291 WPARAM wParam, LPARAM lParam )
293 return proc( hwnd, msg, wParam, lParam );
295 #endif /* __i386__ */
298 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
300 to->ptReserved.x = from->ptReserved.x;
301 to->ptReserved.y = from->ptReserved.y;
302 to->ptMaxSize.x = from->ptMaxSize.x;
303 to->ptMaxSize.y = from->ptMaxSize.y;
304 to->ptMaxPosition.x = from->ptMaxPosition.x;
305 to->ptMaxPosition.y = from->ptMaxPosition.y;
306 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
307 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
308 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
309 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
312 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
314 to->ptReserved.x = from->ptReserved.x;
315 to->ptReserved.y = from->ptReserved.y;
316 to->ptMaxSize.x = from->ptMaxSize.x;
317 to->ptMaxSize.y = from->ptMaxSize.y;
318 to->ptMaxPosition.x = from->ptMaxPosition.x;
319 to->ptMaxPosition.y = from->ptMaxPosition.y;
320 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
321 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
322 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
323 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
326 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
328 to->hwnd = HWND_16(from->hwnd);
329 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
330 to->x = from->x;
331 to->y = from->y;
332 to->cx = from->cx;
333 to->cy = from->cy;
334 to->flags = from->flags;
337 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
339 to->hwnd = WIN_Handle32(from->hwnd);
340 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
341 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
342 to->x = from->x;
343 to->y = from->y;
344 to->cx = from->cx;
345 to->cy = from->cy;
346 to->flags = from->flags;
349 /* The strings are not copied */
350 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
352 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
353 to->hInstance = HINSTANCE_16(from->hInstance);
354 to->hMenu = HMENU_16(from->hMenu);
355 to->hwndParent = HWND_16(from->hwndParent);
356 to->cy = from->cy;
357 to->cx = from->cx;
358 to->y = from->y;
359 to->x = from->x;
360 to->style = from->style;
361 to->dwExStyle = from->dwExStyle;
364 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
367 to->lpCreateParams = (LPVOID)from->lpCreateParams;
368 to->hInstance = HINSTANCE_32(from->hInstance);
369 to->hMenu = HMENU_32(from->hMenu);
370 to->hwndParent = WIN_Handle32(from->hwndParent);
371 to->cy = from->cy;
372 to->cx = from->cx;
373 to->y = from->y;
374 to->x = from->x;
375 to->style = from->style;
376 to->dwExStyle = from->dwExStyle;
379 /* The strings are not copied */
380 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
382 to->hOwner = HINSTANCE_16(from->hOwner);
383 to->x = from->x;
384 to->y = from->y;
385 to->cx = from->cx;
386 to->cy = from->cy;
387 to->style = from->style;
388 to->lParam = from->lParam;
391 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
393 to->hOwner = HINSTANCE_32(from->hOwner);
394 to->x = from->x;
395 to->y = from->y;
396 to->cx = from->cx;
397 to->cy = from->cy;
398 to->style = from->style;
399 to->lParam = from->lParam;
402 /**********************************************************************
403 * WINPROC_CallWndProc32
405 * Call a 32-bit WndProc.
407 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
408 WPARAM wParam, LPARAM lParam )
410 LRESULT retvalue;
411 int iWndsLocks;
413 hwnd = WIN_GetFullHandle( hwnd );
414 if (TRACE_ON(relay))
415 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
416 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam );
417 /* To avoid any deadlocks, all the locks on the windows structures
418 must be suspended before the control is passed to the application */
419 iWndsLocks = WIN_SuspendWndsLock();
420 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
421 WIN_RestoreWndsLock(iWndsLocks);
423 if (TRACE_ON(relay))
424 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
425 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
426 return retvalue;
429 /***********************************************************************
430 * WINPROC_CallWndProc16
432 * Call a 16-bit window procedure
434 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
435 UINT16 msg, WPARAM16 wParam,
436 LPARAM lParam )
438 CONTEXT86 context;
439 LRESULT ret;
440 WORD args[5];
441 DWORD offset = 0;
442 TEB *teb = NtCurrentTeb();
443 int iWndsLocks;
445 /* Window procedures want ax = hInstance, ds = es = ss */
447 memset(&context, 0, sizeof(context));
448 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
449 context.SegFs = wine_get_fs();
450 context.SegGs = wine_get_gs();
451 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
452 context.SegCs = SELECTOROF(proc);
453 context.Eip = OFFSETOF(proc);
454 context.Ebp = OFFSETOF(teb->cur_stack)
455 + (WORD)&((STACK16FRAME*)0)->bp;
457 if (lParam)
459 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
460 work if structures passed in lParam are placed in the stack/data
461 segment. Programmers easily make the mistake of converting lParam
462 to a near rather than a far pointer, since Windows apparently
463 allows this. We copy the structures to the 16 bit stack; this is
464 ugly but makes these programs work. */
465 switch (msg)
467 case WM_CREATE:
468 case WM_NCCREATE:
469 offset = sizeof(CREATESTRUCT16); break;
470 case WM_DRAWITEM:
471 offset = sizeof(DRAWITEMSTRUCT16); break;
472 case WM_COMPAREITEM:
473 offset = sizeof(COMPAREITEMSTRUCT16); break;
475 if (offset)
477 void *s = MapSL(lParam);
478 lParam = stack16_push( offset );
479 memcpy( MapSL(lParam), s, offset );
483 iWndsLocks = WIN_SuspendWndsLock();
485 args[4] = hwnd;
486 args[3] = msg;
487 args[2] = wParam;
488 args[1] = HIWORD(lParam);
489 args[0] = LOWORD(lParam);
490 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args), args, (DWORD *)&context );
491 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
493 if (offset) stack16_pop( offset );
495 WIN_RestoreWndsLock(iWndsLocks);
497 return ret;
501 /**********************************************************************
502 * WINPROC_GetPtr
504 * Return a pointer to the win proc.
506 static WINDOWPROC *WINPROC_GetPtr( WNDPROC handle )
508 BYTE *ptr;
509 WINDOWPROC *proc;
511 /* ptr cannot be < 64K */
512 if (!HIWORD(handle)) return NULL;
514 /* Check for a linear pointer */
516 ptr = (BYTE *)handle;
517 /* First check if it is the jmp address */
518 proc = (WINDOWPROC *)(ptr - FIELD_OFFSET(WINDOWPROC,jmp));
519 if (is_valid_winproc(proc)) return proc;
521 /* Now it must be the thunk address */
522 proc = (WINDOWPROC *)(ptr - FIELD_OFFSET(WINDOWPROC,thunk));
523 if (is_valid_winproc(proc)) return proc;
525 /* Check for a segmented pointer */
527 if (HIWORD(handle) == get_winproc_selector())
529 ptr = (BYTE *)winproc_array + LOWORD(handle);
530 /* It must be the thunk address */
531 proc = (WINDOWPROC *)(ptr - FIELD_OFFSET(WINDOWPROC,thunk));
532 if (is_valid_winproc(proc)) return proc;
534 return NULL;
538 /**********************************************************************
539 * WINPROC_GetProc
541 * Get a window procedure pointer that can be passed to the Windows program.
543 WNDPROC16 WINPROC_GetProc( WNDPROC proc, WINDOWPROCTYPE type )
545 WINDOWPROC *ptr = (WINDOWPROC *)proc;
547 if (!proc) return NULL;
548 if (type == WIN_PROC_16) /* We want a 16:16 address */
550 if (ptr->type == WIN_PROC_16)
551 return ptr->thunk.t_from32.proc;
552 else
553 return (WNDPROC16)MAKESEGPTR( get_winproc_selector(),
554 (char *)&ptr->thunk - (char *)winproc_array );
556 else /* We want a 32-bit address */
558 if (ptr->type == WIN_PROC_16)
559 return (WNDPROC16)&ptr->thunk;
560 else if (type != ptr->type)
561 /* Have to return the jmp address if types don't match */
562 return (WNDPROC16)&ptr->jmp;
563 else
564 /* Some Win16 programs want to get back the proc they set */
565 return (WNDPROC16)ptr->thunk.t_from16.proc;
570 /**********************************************************************
571 * WINPROC_AllocProc
573 * Allocate a window procedure for a window or class.
575 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
576 * lot of windows, it will usually only have a limited number of window procedures, so the
577 * array won't grow too large, and this way we avoid the need to track allocations per window.
579 WNDPROC WINPROC_AllocProc( WNDPROC func, WINDOWPROCTYPE type )
581 WINDOWPROC *proc;
583 if (!func) return NULL;
585 EnterCriticalSection( &winproc_cs );
587 /* check if the function is already a win proc */
588 if (!(proc = WINPROC_GetPtr( func )))
590 /* then check if we already have a winproc for that function */
591 if (!(proc = find_winproc( func, type )))
593 if (winproc_used >= MAX_WINPROCS)
594 FIXME( "too many winprocs, cannot allocate one for %p/%d\n", func, type );
595 else
597 proc = &winproc_array[winproc_used++];
598 set_winproc( proc, func, type );
599 TRACE( "allocated %p for %p/%d (%d/%d used)\n",
600 proc, func, type, winproc_used, MAX_WINPROCS );
603 else TRACE( "reusing %p for %p/%d\n", proc, func, type );
606 LeaveCriticalSection( &winproc_cs );
607 return (WNDPROC)proc;
611 /**********************************************************************
612 * WINPROC_GetProcType
614 * Return the window procedure type.
616 WINDOWPROCTYPE WINPROC_GetProcType( WNDPROC proc )
618 if (!proc) return WIN_PROC_INVALID;
619 return ((WINDOWPROC *)proc)->type;
621 /**********************************************************************
622 * WINPROC_TestCBForStr
624 * Return TRUE if the lparam is a string
626 inline static BOOL WINPROC_TestCBForStr( HWND hwnd )
628 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
629 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
631 /**********************************************************************
632 * WINPROC_TestLBForStr
634 * Return TRUE if the lparam is a string
636 inline static BOOL WINPROC_TestLBForStr( HWND hwnd )
638 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
639 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
642 /**********************************************************************
643 * WINPROC_MapMsg32ATo32W
645 * Map a message from Ansi to Unicode.
646 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
648 * FIXME:
649 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
650 * the first four bytes are the handle of the icon
651 * when the WM_SETTEXT message has been used to set the icon
653 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
655 switch(msg)
657 case WM_GETTEXT:
658 case WM_ASKCBFORMATNAME:
660 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
661 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
662 if (!ptr) return -1;
663 *ptr++ = *plparam; /* Store previous lParam */
664 *plparam = (LPARAM)ptr;
666 return 1;
667 /* lparam is string (0-terminated) */
668 case WM_SETTEXT:
669 case WM_WININICHANGE:
670 case WM_DEVMODECHANGE:
671 case CB_DIR:
672 case LB_DIR:
673 case LB_ADDFILE:
674 case EM_REPLACESEL:
676 DWORD len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, NULL, 0);
677 WCHAR *buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
678 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, buf, len);
679 *plparam = (LPARAM)buf;
680 return (*plparam ? 1 : -1);
682 case WM_GETTEXTLENGTH:
683 case CB_GETLBTEXTLEN:
684 case LB_GETTEXTLEN:
685 return 1; /* need to map result */
686 case WM_NCCREATE:
687 case WM_CREATE:
689 UNICODE_STRING usBuffer;
690 struct s
691 { CREATESTRUCTW cs; /* new structure */
692 LPCWSTR lpszName; /* allocated Name */
693 LPCWSTR lpszClass; /* allocated Class */
696 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
697 if (!xs) return -1;
698 xs->cs = *(CREATESTRUCTW *)*plparam;
699 if (HIWORD(xs->cs.lpszName))
701 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszName);
702 xs->lpszName = xs->cs.lpszName = usBuffer.Buffer;
704 if (HIWORD(xs->cs.lpszClass))
706 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszClass);
707 xs->lpszClass = xs->cs.lpszClass = usBuffer.Buffer;
710 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
712 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)HeapAlloc(GetProcessHeap(), 0,
713 sizeof(*mdi_cs));
714 *mdi_cs = *(MDICREATESTRUCTW *)xs->cs.lpCreateParams;
715 if (HIWORD(mdi_cs->szTitle))
717 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szTitle);
718 mdi_cs->szTitle = usBuffer.Buffer;
720 if (HIWORD(mdi_cs->szClass))
722 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szClass);
723 mdi_cs->szClass = usBuffer.Buffer;
725 xs->cs.lpCreateParams = mdi_cs;
728 *plparam = (LPARAM)xs;
730 return 1;
731 case WM_MDICREATE:
733 MDICREATESTRUCTW *cs =
734 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
735 if (!cs) return -1;
736 *cs = *(MDICREATESTRUCTW *)*plparam;
737 if (HIWORD(cs->szClass))
739 UNICODE_STRING usBuffer;
740 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szClass);
741 cs->szClass = usBuffer.Buffer;
743 if (HIWORD(cs->szTitle))
745 UNICODE_STRING usBuffer;
746 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szTitle);
747 cs->szTitle = usBuffer.Buffer;
749 *plparam = (LPARAM)cs;
751 return 1;
753 /* Listbox */
754 case LB_ADDSTRING:
755 case LB_INSERTSTRING:
756 case LB_FINDSTRING:
757 case LB_FINDSTRINGEXACT:
758 case LB_SELECTSTRING:
759 if(!*plparam) return 0;
760 if ( WINPROC_TestLBForStr( hwnd ))
762 UNICODE_STRING usBuffer;
763 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
764 *plparam = (LPARAM)usBuffer.Buffer;
766 return (*plparam ? 1 : -1);
768 case LB_GETTEXT: /* FIXME: fixed sized buffer */
769 { if ( WINPROC_TestLBForStr( hwnd ))
770 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
771 if (!ptr) return -1;
772 *ptr++ = *plparam; /* Store previous lParam */
773 *plparam = (LPARAM)ptr;
776 return 1;
778 /* Combobox */
779 case CB_ADDSTRING:
780 case CB_INSERTSTRING:
781 case CB_FINDSTRINGEXACT:
782 case CB_FINDSTRING:
783 case CB_SELECTSTRING:
784 if(!*plparam) return 0;
785 if ( WINPROC_TestCBForStr( hwnd ))
787 UNICODE_STRING usBuffer;
788 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
789 *plparam = (LPARAM)usBuffer.Buffer;
791 return (*plparam ? 1 : -1);
793 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
794 { if ( WINPROC_TestCBForStr( hwnd ))
795 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
796 if (!ptr) return -1;
797 *ptr++ = *plparam; /* Store previous lParam */
798 *plparam = (LPARAM)ptr;
801 return 1;
803 /* Multiline edit */
804 case EM_GETLINE:
805 { WORD len = (WORD)*plparam;
806 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
807 if (!ptr) return -1;
808 *ptr++ = *plparam; /* Store previous lParam */
809 *((WORD *) ptr) = len; /* Store the length */
810 *plparam = (LPARAM)ptr;
812 return 1;
814 case WM_CHARTOITEM:
815 case WM_MENUCHAR:
816 case WM_CHAR:
817 case WM_DEADCHAR:
818 case WM_SYSCHAR:
819 case WM_SYSDEADCHAR:
820 case EM_SETPASSWORDCHAR:
822 BYTE ch = LOWORD(*pwparam);
823 WCHAR wch;
824 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
825 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
827 return 0;
829 case WM_IME_CHAR:
831 BYTE ch[2];
832 WCHAR wch;
833 ch[0] = (*pwparam >> 8);
834 ch[1] = *pwparam & 0xff;
835 if (ch[0])
836 MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
837 else
838 MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
839 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
841 return 0;
843 case WM_PAINTCLIPBOARD:
844 case WM_SIZECLIPBOARD:
845 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
846 return -1;
847 default: /* No translation needed */
848 return 0;
853 /**********************************************************************
854 * WINPROC_UnmapMsg32ATo32W
856 * Unmap a message that was mapped from Ansi to Unicode.
858 LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
859 LRESULT result )
861 switch(msg)
863 case WM_GETTEXT:
864 case WM_ASKCBFORMATNAME:
866 LPARAM *ptr = (LPARAM *)lParam - 1;
867 if (!wParam) result = 0;
868 else if (!(result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
869 (LPSTR)*ptr, wParam, NULL, NULL )))
871 ((LPSTR)*ptr)[wParam-1] = 0;
872 result = wParam - 1;
874 else result--; /* do not count terminating null */
875 HeapFree( GetProcessHeap(), 0, ptr );
877 break;
878 case WM_GETTEXTLENGTH:
879 case CB_GETLBTEXTLEN:
880 case LB_GETTEXTLEN:
881 /* there may be one DBCS char for each Unicode char */
882 return result * 2;
883 case WM_NCCREATE:
884 case WM_CREATE:
886 struct s
887 { CREATESTRUCTW cs; /* new structure */
888 LPWSTR lpszName; /* allocated Name */
889 LPWSTR lpszClass; /* allocated Class */
891 struct s *xs = (struct s *)lParam;
892 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
893 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
895 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
897 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)xs->cs.lpCreateParams;
898 if (HIWORD(mdi_cs->szTitle))
899 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szTitle);
900 if (HIWORD(mdi_cs->szClass))
901 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szClass);
902 HeapFree(GetProcessHeap(), 0, mdi_cs);
904 HeapFree( GetProcessHeap(), 0, xs );
906 break;
908 case WM_MDICREATE:
910 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
911 if (HIWORD(cs->szTitle))
912 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
913 if (HIWORD(cs->szClass))
914 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
915 HeapFree( GetProcessHeap(), 0, cs );
917 break;
919 case WM_SETTEXT:
920 case WM_WININICHANGE:
921 case WM_DEVMODECHANGE:
922 case CB_DIR:
923 case LB_DIR:
924 case LB_ADDFILE:
925 case EM_REPLACESEL:
926 HeapFree( GetProcessHeap(), 0, (void *)lParam );
927 break;
929 /* Listbox */
930 case LB_ADDSTRING:
931 case LB_INSERTSTRING:
932 case LB_FINDSTRING:
933 case LB_FINDSTRINGEXACT:
934 case LB_SELECTSTRING:
935 if ( WINPROC_TestLBForStr( hwnd ))
936 HeapFree( GetProcessHeap(), 0, (void *)lParam );
937 break;
939 case LB_GETTEXT:
940 if ( WINPROC_TestLBForStr( hwnd ))
942 LPARAM *ptr = (LPARAM *)lParam - 1;
943 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
944 (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
945 HeapFree( GetProcessHeap(), 0, ptr );
947 break;
949 /* Combobox */
950 case CB_ADDSTRING:
951 case CB_INSERTSTRING:
952 case CB_FINDSTRING:
953 case CB_FINDSTRINGEXACT:
954 case CB_SELECTSTRING:
955 if ( WINPROC_TestCBForStr( hwnd ))
956 HeapFree( GetProcessHeap(), 0, (void *)lParam );
957 break;
959 case CB_GETLBTEXT:
960 if ( WINPROC_TestCBForStr( hwnd ))
962 LPARAM *ptr = (LPARAM *)lParam - 1;
963 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
964 (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
965 HeapFree( GetProcessHeap(), 0, ptr );
967 break;
969 /* Multiline edit */
970 case EM_GETLINE:
972 LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
973 WORD len = *(WORD *) lParam;
974 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, result,
975 (LPSTR)*ptr, len, NULL, NULL );
976 if (result < len) ((LPSTR)*ptr)[result] = 0;
977 HeapFree( GetProcessHeap(), 0, ptr );
979 break;
981 return result;
985 /**********************************************************************
986 * WINPROC_MapMsg32WTo32A
988 * Map a message from Unicode to Ansi.
989 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
991 static INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
993 switch(msg)
995 case WM_GETTEXT:
996 case WM_ASKCBFORMATNAME:
998 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
999 *pwparam + sizeof(LPARAM) );
1000 if (!ptr) return -1;
1001 *ptr++ = *plparam; /* Store previous lParam */
1002 *plparam = (LPARAM)ptr;
1004 return 1;
1006 case WM_SETTEXT:
1007 case WM_WININICHANGE:
1008 case WM_DEVMODECHANGE:
1009 case CB_DIR:
1010 case LB_DIR:
1011 case LB_ADDFILE:
1012 case EM_REPLACESEL:
1013 if(!*plparam) return 0;
1014 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
1015 return (*plparam ? 1 : -1);
1017 case WM_MDICREATE:
1019 MDICREATESTRUCTA *cs =
1020 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
1021 if (!cs) return -1;
1022 *cs = *(MDICREATESTRUCTA *)*plparam;
1023 if (HIWORD(cs->szTitle))
1024 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
1025 (LPCWSTR)cs->szTitle );
1026 if (HIWORD(cs->szClass))
1027 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
1028 (LPCWSTR)cs->szClass );
1029 *plparam = (LPARAM)cs;
1031 return 1;
1033 /* Listbox */
1034 case LB_ADDSTRING:
1035 case LB_INSERTSTRING:
1036 case LB_FINDSTRING:
1037 case LB_FINDSTRINGEXACT:
1038 case LB_SELECTSTRING:
1039 if(!*plparam) return 0;
1040 if ( WINPROC_TestLBForStr( hwnd ))
1041 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
1042 return (*plparam ? 1 : -1);
1044 case LB_GETTEXT: /* FIXME: fixed sized buffer */
1045 { if ( WINPROC_TestLBForStr( hwnd ))
1046 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
1047 if (!ptr) return -1;
1048 *ptr++ = *plparam; /* Store previous lParam */
1049 *plparam = (LPARAM)ptr;
1052 return 1;
1054 /* Combobox */
1055 case CB_ADDSTRING:
1056 case CB_INSERTSTRING:
1057 case CB_FINDSTRING:
1058 case CB_FINDSTRINGEXACT:
1059 case CB_SELECTSTRING:
1060 if(!*plparam) return 0;
1061 if ( WINPROC_TestCBForStr( hwnd ))
1062 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
1063 return (*plparam ? 1 : -1);
1065 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
1066 { if ( WINPROC_TestCBForStr( hwnd ))
1067 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
1068 if (!ptr) return -1;
1069 *ptr++ = *plparam; /* Store previous lParam */
1070 *plparam = (LPARAM)ptr;
1073 return 1;
1075 /* Multiline edit */
1076 case EM_GETLINE:
1077 { WORD len = (WORD)*plparam;
1078 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
1079 if (!ptr) return -1;
1080 *ptr++ = *plparam; /* Store previous lParam */
1081 *((WORD *) ptr) = len; /* Store the length */
1082 *plparam = (LPARAM)ptr;
1084 return 1;
1086 case WM_CHARTOITEM:
1087 case WM_MENUCHAR:
1088 case WM_CHAR:
1089 case WM_DEADCHAR:
1090 case WM_SYSCHAR:
1091 case WM_SYSDEADCHAR:
1092 case EM_SETPASSWORDCHAR:
1094 WCHAR wch = LOWORD(*pwparam);
1095 BYTE ch;
1096 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
1097 *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
1099 return 0;
1101 case WM_IME_CHAR:
1103 WCHAR wch = LOWORD(*pwparam);
1104 BYTE ch[2];
1106 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
1107 *pwparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(*pwparam) );
1108 else
1109 *pwparam = MAKEWPARAM( ch[0], HIWORD(*pwparam) );
1111 return 0;
1113 case WM_PAINTCLIPBOARD:
1114 case WM_SIZECLIPBOARD:
1115 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg, hwnd),msg );
1116 return -1;
1117 default: /* No translation needed */
1118 return 0;
1123 /**********************************************************************
1124 * WINPROC_UnmapMsg32WTo32A
1126 * Unmap a message that was mapped from Unicode to Ansi.
1128 static LRESULT WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result )
1130 switch(msg)
1132 case WM_GETTEXT:
1133 case WM_ASKCBFORMATNAME:
1135 LPARAM *ptr = (LPARAM *)lParam - 1;
1136 if (!wParam) result = 0;
1137 else if (!(result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1,
1138 (LPWSTR)*ptr, wParam )))
1140 ((LPWSTR)*ptr)[wParam-1] = 0;
1141 result = wParam - 1;
1143 else result--; /* do not count terminating null */
1144 HeapFree( GetProcessHeap(), 0, ptr );
1146 break;
1148 case WM_SETTEXT:
1149 case WM_WININICHANGE:
1150 case WM_DEVMODECHANGE:
1151 case CB_DIR:
1152 case LB_DIR:
1153 case LB_ADDFILE:
1154 case EM_REPLACESEL:
1155 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1156 break;
1158 case WM_MDICREATE:
1160 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1161 if (HIWORD(cs->szTitle))
1162 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1163 if (HIWORD(cs->szClass))
1164 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1165 HeapFree( GetProcessHeap(), 0, cs );
1167 break;
1169 /* Listbox */
1170 case LB_ADDSTRING:
1171 case LB_INSERTSTRING:
1172 case LB_FINDSTRING:
1173 case LB_FINDSTRINGEXACT:
1174 case LB_SELECTSTRING:
1175 if ( WINPROC_TestLBForStr( hwnd ))
1176 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1177 break;
1179 case LB_GETTEXT:
1180 if ( WINPROC_TestLBForStr( hwnd ))
1182 LPARAM *ptr = (LPARAM *)lParam - 1;
1183 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
1184 HeapFree( GetProcessHeap(), 0, ptr );
1186 break;
1188 /* Combobox */
1189 case CB_ADDSTRING:
1190 case CB_INSERTSTRING:
1191 case CB_FINDSTRING:
1192 case CB_FINDSTRINGEXACT:
1193 case CB_SELECTSTRING:
1194 if ( WINPROC_TestCBForStr( hwnd ))
1195 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1196 break;
1198 case CB_GETLBTEXT:
1199 if ( WINPROC_TestCBForStr( hwnd ))
1201 LPARAM *ptr = (LPARAM *)lParam - 1;
1202 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
1203 HeapFree( GetProcessHeap(), 0, ptr );
1205 break;
1207 /* Multiline edit */
1208 case EM_GETLINE:
1210 LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1211 WORD len = *(WORD *)ptr;
1212 if (len)
1214 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, result, (LPWSTR)*ptr, len );
1215 if (result < len) ((LPWSTR)*ptr)[result] = 0;
1217 HeapFree( GetProcessHeap(), 0, ptr );
1219 break;
1221 return result;
1224 static UINT convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
1226 HANDLE dst;
1227 UINT sz = GlobalSize16(src);
1228 LPSTR ptr16, ptr32;
1230 if (!(dst = GlobalAlloc(flags, sz)))
1231 return 0;
1232 ptr16 = GlobalLock16(src);
1233 ptr32 = GlobalLock(dst);
1234 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
1235 GlobalUnlock16(src);
1236 GlobalUnlock(dst);
1238 return (UINT)dst;
1241 /**********************************************************************
1242 * WINPROC_MapMsg16To32A
1244 * Map a message from 16- to 32-bit Ansi.
1245 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1247 INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1248 WPARAM *pwparam32, LPARAM *plparam )
1250 *pmsg32 = (UINT)msg16;
1251 *pwparam32 = (WPARAM)wParam16;
1252 switch(msg16)
1254 case WM_ACTIVATE:
1255 case WM_CHARTOITEM:
1256 case WM_COMMAND:
1257 case WM_VKEYTOITEM:
1258 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1259 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1260 return 0;
1261 case WM_HSCROLL:
1262 case WM_VSCROLL:
1263 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1264 *plparam = (LPARAM)WIN_Handle32( HIWORD(*plparam) );
1265 return 0;
1266 case WM_CTLCOLOR:
1267 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1268 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1269 *pwparam32 = (WPARAM)HDC_32(wParam16);
1270 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1271 return 0;
1272 case WM_COMPAREITEM:
1274 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1275 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1276 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1277 if (!cis) return -1;
1278 cis->CtlType = cis16->CtlType;
1279 cis->CtlID = cis16->CtlID;
1280 cis->hwndItem = WIN_Handle32( cis16->hwndItem );
1281 cis->itemID1 = cis16->itemID1;
1282 cis->itemData1 = cis16->itemData1;
1283 cis->itemID2 = cis16->itemID2;
1284 cis->itemData2 = cis16->itemData2;
1285 cis->dwLocaleId = 0; /* FIXME */
1286 *plparam = (LPARAM)cis;
1288 return 1;
1289 case WM_DELETEITEM:
1291 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1292 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1293 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1294 if (!dis) return -1;
1295 dis->CtlType = dis16->CtlType;
1296 dis->CtlID = dis16->CtlID;
1297 dis->hwndItem = WIN_Handle32( dis16->hwndItem );
1298 dis->itemData = dis16->itemData;
1299 *plparam = (LPARAM)dis;
1301 return 1;
1302 case WM_MEASUREITEM:
1304 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1305 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1306 HeapAlloc(GetProcessHeap(), 0,
1307 sizeof(*mis) + sizeof(LPARAM));
1308 if (!mis) return -1;
1309 mis->CtlType = mis16->CtlType;
1310 mis->CtlID = mis16->CtlID;
1311 mis->itemID = mis16->itemID;
1312 mis->itemWidth = mis16->itemWidth;
1313 mis->itemHeight = mis16->itemHeight;
1314 mis->itemData = mis16->itemData;
1315 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1316 *plparam = (LPARAM)mis;
1318 return 1;
1319 case WM_DRAWITEM:
1321 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1322 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1323 sizeof(*dis));
1324 if (!dis) return -1;
1325 dis->CtlType = dis16->CtlType;
1326 dis->CtlID = dis16->CtlID;
1327 dis->itemID = dis16->itemID;
1328 dis->itemAction = dis16->itemAction;
1329 dis->itemState = dis16->itemState;
1330 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1331 : WIN_Handle32( dis16->hwndItem );
1332 dis->hDC = HDC_32(dis16->hDC);
1333 dis->itemData = dis16->itemData;
1334 dis->rcItem.left = dis16->rcItem.left;
1335 dis->rcItem.top = dis16->rcItem.top;
1336 dis->rcItem.right = dis16->rcItem.right;
1337 dis->rcItem.bottom = dis16->rcItem.bottom;
1338 *plparam = (LPARAM)dis;
1340 return 1;
1341 case WM_GETMINMAXINFO:
1343 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1344 sizeof(*mmi) + sizeof(LPARAM));
1345 if (!mmi) return -1;
1346 MINMAXINFO16to32( MapSL(*plparam), mmi );
1347 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1348 *plparam = (LPARAM)mmi;
1350 return 1;
1351 case WM_GETTEXT:
1352 case WM_SETTEXT:
1353 case WM_WININICHANGE:
1354 case WM_DEVMODECHANGE:
1355 case WM_ASKCBFORMATNAME:
1356 *plparam = (LPARAM)MapSL(*plparam);
1357 return 0;
1358 case WM_MDICREATE:
1360 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1361 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1362 if (!cs) return -1;
1363 MDICREATESTRUCT16to32A( cs16, cs );
1364 cs->szTitle = MapSL(cs16->szTitle);
1365 cs->szClass = MapSL(cs16->szClass);
1366 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1367 *plparam = (LPARAM)cs;
1369 return 1;
1370 case WM_MDIGETACTIVE:
1371 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1372 *(BOOL*)(*plparam) = 0;
1373 return 1;
1374 case WM_MDISETMENU:
1375 if(wParam16==TRUE)
1376 *pmsg32=WM_MDIREFRESHMENU;
1377 *pwparam32 = (WPARAM)HMENU_32(LOWORD(*plparam));
1378 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1379 return 0;
1380 case WM_MENUCHAR:
1381 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1382 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1383 return 0;
1384 case WM_MENUSELECT:
1385 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1387 HMENU hmenu=HMENU_32(HIWORD(*plparam));
1388 UINT Pos=MENU_FindSubMenu( &hmenu, HMENU_32(wParam16));
1389 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1390 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1392 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1393 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1394 return 0;
1395 case WM_MDIACTIVATE:
1396 if( *plparam )
1398 *pwparam32 = (WPARAM)WIN_Handle32( HIWORD(*plparam) );
1399 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1401 else /* message sent to MDI client */
1402 *pwparam32 = wParam16;
1403 return 0;
1404 case WM_NCCALCSIZE:
1406 NCCALCSIZE_PARAMS16 *nc16;
1407 NCCALCSIZE_PARAMS *nc;
1409 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1410 sizeof(*nc) + sizeof(LPARAM) );
1411 if (!nc) return -1;
1412 nc16 = MapSL(*plparam);
1413 nc->rgrc[0].left = nc16->rgrc[0].left;
1414 nc->rgrc[0].top = nc16->rgrc[0].top;
1415 nc->rgrc[0].right = nc16->rgrc[0].right;
1416 nc->rgrc[0].bottom = nc16->rgrc[0].bottom;
1417 if (wParam16)
1419 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1420 sizeof(*nc->lppos) );
1421 nc->rgrc[1].left = nc16->rgrc[1].left;
1422 nc->rgrc[1].top = nc16->rgrc[1].top;
1423 nc->rgrc[1].right = nc16->rgrc[1].right;
1424 nc->rgrc[1].bottom = nc16->rgrc[1].bottom;
1425 nc->rgrc[2].left = nc16->rgrc[2].left;
1426 nc->rgrc[2].top = nc16->rgrc[2].top;
1427 nc->rgrc[2].right = nc16->rgrc[2].right;
1428 nc->rgrc[2].bottom = nc16->rgrc[2].bottom;
1429 if (nc->lppos) WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1431 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1432 *plparam = (LPARAM)nc;
1434 return 1;
1435 case WM_NCCREATE:
1436 case WM_CREATE:
1438 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1439 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1440 sizeof(*cs) + sizeof(LPARAM) );
1441 if (!cs) return -1;
1442 CREATESTRUCT16to32A( cs16, cs );
1443 cs->lpszName = MapSL(cs16->lpszName);
1444 cs->lpszClass = MapSL(cs16->lpszClass);
1446 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1448 MDICREATESTRUCT16 *mdi_cs16;
1449 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)HeapAlloc(GetProcessHeap(), 0,
1450 sizeof(*mdi_cs));
1451 if (!mdi_cs)
1453 HeapFree(GetProcessHeap(), 0, cs);
1454 return -1;
1456 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1457 MDICREATESTRUCT16to32A(mdi_cs16, mdi_cs);
1458 mdi_cs->szTitle = MapSL(mdi_cs16->szTitle);
1459 mdi_cs->szClass = MapSL(mdi_cs16->szClass);
1461 cs->lpCreateParams = mdi_cs;
1463 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1464 *plparam = (LPARAM)cs;
1466 return 1;
1467 case WM_PARENTNOTIFY:
1468 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1470 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1471 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1473 return 0;
1474 case WM_WINDOWPOSCHANGING:
1475 case WM_WINDOWPOSCHANGED:
1477 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1478 sizeof(*wp) + sizeof(LPARAM) );
1479 if (!wp) return -1;
1480 WINDOWPOS16to32( MapSL(*plparam), wp );
1481 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1482 *plparam = (LPARAM)wp;
1484 return 1;
1485 case WM_GETDLGCODE:
1486 if (*plparam)
1488 LPMSG16 msg16 = MapSL(*plparam);
1489 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1491 if (!msg32) return -1;
1492 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1493 msg32->lParam = msg16->lParam;
1494 msg32->time = msg16->time;
1495 msg32->pt.x = msg16->pt.x;
1496 msg32->pt.y = msg16->pt.y;
1497 /* this is right, right? */
1498 if (WINPROC_MapMsg16To32A( msg32->hwnd, msg16->message,msg16->wParam,
1499 &msg32->message,&msg32->wParam,
1500 &msg32->lParam)<0) {
1501 HeapFree( GetProcessHeap(), 0, msg32 );
1502 return -1;
1504 *plparam = (LPARAM)msg32;
1505 return 1;
1507 else return 0;
1508 case WM_NOTIFY:
1509 *plparam = (LPARAM)MapSL(*plparam);
1510 return 0;
1511 case WM_ACTIVATEAPP:
1512 /* We need this when SetActiveWindow sends a Sendmessage16() to
1513 * a 32bit window. Might be superflous with 32bit interprocess
1514 * message queues. */
1515 if (*plparam) *plparam = HTASK_32( *plparam );
1516 return 0;
1517 case WM_NEXTMENU:
1519 MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
1520 if (!next) return -1;
1521 next->hmenuIn = (HMENU)*plparam;
1522 next->hmenuNext = 0;
1523 next->hwndNext = 0;
1524 *plparam = (LPARAM)next;
1525 return 1;
1527 case WM_PAINTCLIPBOARD:
1528 case WM_SIZECLIPBOARD:
1529 FIXME_(msg)("message %04x needs translation\n",msg16 );
1530 return -1;
1531 case WM_DDE_INITIATE:
1532 case WM_DDE_TERMINATE:
1533 case WM_DDE_UNADVISE:
1534 case WM_DDE_REQUEST:
1535 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1536 return 0;
1537 case WM_DDE_ADVISE:
1538 case WM_DDE_DATA:
1539 case WM_DDE_POKE:
1541 HANDLE16 lo16;
1542 ATOM hi;
1543 UINT lo32 = 0;
1545 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1546 lo16 = LOWORD(*plparam);
1547 hi = HIWORD(*plparam);
1548 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE)))
1549 return -1;
1550 *plparam = PackDDElParam(msg16, lo32, hi);
1552 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1553 case WM_DDE_ACK:
1555 UINT lo, hi;
1556 int flag = 0;
1557 char buf[2];
1559 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1561 lo = LOWORD(*plparam);
1562 hi = HIWORD(*plparam);
1564 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1565 if (GlobalSize16(hi) != 0) flag |= 2;
1566 switch (flag)
1568 case 0:
1569 if (hi)
1571 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1572 hi = 0;
1574 break;
1575 case 1:
1576 break; /* atom, nothing to do */
1577 case 3:
1578 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1579 /* fall thru */
1580 case 2:
1581 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1582 break;
1584 *plparam = PackDDElParam(WM_DDE_ACK, lo, hi);
1586 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1587 case WM_DDE_EXECUTE:
1588 *plparam = convert_handle_16_to_32(*plparam, GMEM_DDESHARE);
1589 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1590 default: /* No translation needed */
1591 return 0;
1596 /**********************************************************************
1597 * WINPROC_UnmapMsg16To32A
1599 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1601 LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1602 LRESULT result )
1604 switch(msg)
1606 case WM_COMPAREITEM:
1607 case WM_DELETEITEM:
1608 case WM_DRAWITEM:
1609 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1610 break;
1611 case WM_MEASUREITEM:
1613 MEASUREITEMSTRUCT16 *mis16;
1614 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1615 lParam = *(LPARAM *)(mis + 1);
1616 mis16 = MapSL(lParam);
1617 mis16->itemWidth = (UINT16)mis->itemWidth;
1618 mis16->itemHeight = (UINT16)mis->itemHeight;
1619 HeapFree( GetProcessHeap(), 0, mis );
1621 break;
1622 case WM_GETMINMAXINFO:
1624 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1625 lParam = *(LPARAM *)(mmi + 1);
1626 MINMAXINFO32to16( mmi, MapSL(lParam));
1627 HeapFree( GetProcessHeap(), 0, mmi );
1629 break;
1630 case WM_MDICREATE:
1632 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1633 lParam = *(LPARAM *)(cs + 1);
1634 MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1635 HeapFree( GetProcessHeap(), 0, cs );
1637 break;
1638 case WM_MDIGETACTIVE:
1639 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1640 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1641 break;
1642 case WM_NCCALCSIZE:
1644 NCCALCSIZE_PARAMS16 *nc16;
1645 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1646 lParam = *(LPARAM *)(nc + 1);
1647 nc16 = MapSL(lParam);
1648 nc16->rgrc[0].left = nc->rgrc[0].left;
1649 nc16->rgrc[0].top = nc->rgrc[0].top;
1650 nc16->rgrc[0].right = nc->rgrc[0].right;
1651 nc16->rgrc[0].bottom = nc->rgrc[0].bottom;
1652 if (wParam)
1654 nc16->rgrc[1].left = nc->rgrc[1].left;
1655 nc16->rgrc[1].top = nc->rgrc[1].top;
1656 nc16->rgrc[1].right = nc->rgrc[1].right;
1657 nc16->rgrc[1].bottom = nc->rgrc[1].bottom;
1658 nc16->rgrc[2].left = nc->rgrc[2].left;
1659 nc16->rgrc[2].top = nc->rgrc[2].top;
1660 nc16->rgrc[2].right = nc->rgrc[2].right;
1661 nc16->rgrc[2].bottom = nc->rgrc[2].bottom;
1662 if (nc->lppos)
1664 WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1665 HeapFree( GetProcessHeap(), 0, nc->lppos );
1668 HeapFree( GetProcessHeap(), 0, nc );
1670 break;
1671 case WM_NCCREATE:
1672 case WM_CREATE:
1674 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1675 lParam = *(LPARAM *)(cs + 1);
1676 CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1678 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1679 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1681 HeapFree( GetProcessHeap(), 0, cs );
1683 break;
1684 case WM_WINDOWPOSCHANGING:
1685 case WM_WINDOWPOSCHANGED:
1687 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1688 lParam = *(LPARAM *)(wp + 1);
1689 WINDOWPOS32to16(wp, MapSL(lParam));
1690 HeapFree( GetProcessHeap(), 0, wp );
1692 break;
1693 case WM_GETDLGCODE:
1694 if (lParam)
1696 LPMSG msg32 = (LPMSG)lParam;
1698 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1699 result);
1700 HeapFree( GetProcessHeap(), 0, msg32 );
1702 break;
1703 case WM_NEXTMENU:
1705 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1706 result = MAKELONG( HMENU_16(next->hmenuNext), HWND_16(next->hwndNext) );
1707 HeapFree( GetProcessHeap(), 0, next );
1709 break;
1711 return result;
1715 /**********************************************************************
1716 * WINPROC_MapMsg16To32W
1718 * Map a message from 16- to 32-bit Unicode.
1719 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1721 INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1722 WPARAM *pwparam32, LPARAM *plparam )
1724 BYTE ch;
1725 WCHAR wch;
1727 *pmsg32=(UINT)msg16;
1728 *pwparam32 = (WPARAM)wParam16;
1729 switch(msg16)
1731 case WM_GETTEXT:
1732 case WM_SETTEXT:
1733 case WM_WININICHANGE:
1734 case WM_DEVMODECHANGE:
1735 case WM_ASKCBFORMATNAME:
1736 *plparam = (LPARAM)MapSL(*plparam);
1737 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1738 case WM_GETTEXTLENGTH:
1739 case CB_GETLBTEXTLEN:
1740 case LB_GETTEXTLEN:
1741 return 1; /* need to map result */
1742 case WM_NCCREATE:
1743 case WM_CREATE:
1745 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1746 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1747 sizeof(*cs) + sizeof(LPARAM) );
1748 if (!cs) return -1;
1749 CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1750 cs->lpszName = map_str_16_to_32W(cs16->lpszName);
1751 cs->lpszClass = map_str_16_to_32W(cs16->lpszClass);
1753 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1755 MDICREATESTRUCT16 *mdi_cs16;
1756 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)HeapAlloc(GetProcessHeap(), 0,
1757 sizeof(*mdi_cs));
1758 if (!mdi_cs)
1760 HeapFree(GetProcessHeap(), 0, cs);
1761 return -1;
1763 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1764 MDICREATESTRUCT16to32A(mdi_cs16, (MDICREATESTRUCTA *)mdi_cs);
1765 mdi_cs->szTitle = map_str_16_to_32W(mdi_cs16->szTitle);
1766 mdi_cs->szClass = map_str_16_to_32W(mdi_cs16->szClass);
1768 cs->lpCreateParams = mdi_cs;
1770 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1771 *plparam = (LPARAM)cs;
1773 return 1;
1774 case WM_MDICREATE:
1776 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1777 MDICREATESTRUCTW *cs =
1778 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1779 sizeof(*cs) + sizeof(LPARAM) );
1780 if (!cs) return -1;
1781 MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1782 cs->szTitle = map_str_16_to_32W(cs16->szTitle);
1783 cs->szClass = map_str_16_to_32W(cs16->szClass);
1784 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1785 *plparam = (LPARAM)cs;
1787 return 1;
1788 case WM_GETDLGCODE:
1789 if (*plparam)
1791 LPMSG16 msg16 = MapSL(*plparam);
1792 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1794 if (!msg32) return -1;
1795 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1796 msg32->lParam = msg16->lParam;
1797 msg32->time = msg16->time;
1798 msg32->pt.x = msg16->pt.x;
1799 msg32->pt.y = msg16->pt.y;
1800 /* this is right, right? */
1801 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1802 &msg32->message,&msg32->wParam,
1803 &msg32->lParam)<0) {
1804 HeapFree( GetProcessHeap(), 0, msg32 );
1805 return -1;
1807 *plparam = (LPARAM)msg32;
1808 return 1;
1810 else return 0;
1812 case WM_CHARTOITEM:
1813 ch = wParam16;
1814 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1815 *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
1816 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1817 return 0;
1818 case WM_MENUCHAR:
1819 ch = wParam16;
1820 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1821 *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
1822 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1823 return 0;
1824 case WM_CHAR:
1825 case WM_DEADCHAR:
1826 case WM_SYSCHAR:
1827 case WM_SYSDEADCHAR:
1828 ch = wParam16;
1829 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1830 *pwparam32 = wch;
1831 return 0;
1832 case WM_IME_CHAR:
1833 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1835 default: /* No Unicode translation needed */
1836 return WINPROC_MapMsg16To32A( hwnd, msg16, wParam16, pmsg32,
1837 pwparam32, plparam );
1842 /**********************************************************************
1843 * WINPROC_UnmapMsg16To32W
1845 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1847 LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1848 LRESULT result )
1850 switch(msg)
1852 case WM_GETTEXT:
1853 case WM_SETTEXT:
1854 case WM_GETTEXTLENGTH:
1855 case CB_GETLBTEXTLEN:
1856 case LB_GETTEXTLEN:
1857 case WM_ASKCBFORMATNAME:
1858 return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
1859 case WM_NCCREATE:
1860 case WM_CREATE:
1862 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1863 lParam = *(LPARAM *)(cs + 1);
1864 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1865 unmap_str_16_to_32W( cs->lpszName );
1866 unmap_str_16_to_32W( cs->lpszClass );
1868 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1870 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs->lpCreateParams;
1871 unmap_str_16_to_32W( mdi_cs->szTitle );
1872 unmap_str_16_to_32W( mdi_cs->szClass );
1873 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1875 HeapFree( GetProcessHeap(), 0, cs );
1877 break;
1878 case WM_MDICREATE:
1880 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1881 lParam = *(LPARAM *)(cs + 1);
1882 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1883 unmap_str_16_to_32W( cs->szTitle );
1884 unmap_str_16_to_32W( cs->szClass );
1885 HeapFree( GetProcessHeap(), 0, cs );
1887 break;
1888 case WM_GETDLGCODE:
1889 if (lParam)
1891 LPMSG msg32 = (LPMSG)lParam;
1893 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1894 result);
1895 HeapFree( GetProcessHeap(), 0, msg32 );
1897 break;
1898 default:
1899 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1901 return result;
1904 static HANDLE16 convert_handle_32_to_16(UINT src, unsigned int flags)
1906 HANDLE16 dst;
1907 UINT sz = GlobalSize((HANDLE)src);
1908 LPSTR ptr16, ptr32;
1910 if (!(dst = GlobalAlloc16(flags, sz)))
1911 return 0;
1912 ptr32 = GlobalLock((HANDLE)src);
1913 ptr16 = GlobalLock16(dst);
1914 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
1915 GlobalUnlock((HANDLE)src);
1916 GlobalUnlock16(dst);
1918 return dst;
1922 /**********************************************************************
1923 * WINPROC_MapMsg32ATo16
1925 * Map a message from 32-bit Ansi to 16-bit.
1926 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1928 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1929 UINT16 *pmsg16, WPARAM16 *pwparam16,
1930 LPARAM *plparam )
1932 *pmsg16 = (UINT16)msg32;
1933 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1934 switch(msg32)
1936 case SBM_SETRANGE:
1937 *pmsg16 = SBM_SETRANGE16;
1938 *plparam = MAKELPARAM(wParam32, *plparam);
1939 *pwparam16 = 0;
1940 return 0;
1942 case SBM_GETRANGE:
1943 *pmsg16 = SBM_GETRANGE16;
1944 return 1;
1946 case BM_GETCHECK:
1947 case BM_SETCHECK:
1948 case BM_GETSTATE:
1949 case BM_SETSTATE:
1950 case BM_SETSTYLE:
1951 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1952 return 0;
1954 case EM_GETSEL:
1955 case EM_GETRECT:
1956 case EM_SETRECT:
1957 case EM_SETRECTNP:
1958 case EM_SCROLL:
1959 case EM_LINESCROLL:
1960 case EM_SCROLLCARET:
1961 case EM_GETMODIFY:
1962 case EM_SETMODIFY:
1963 case EM_GETLINECOUNT:
1964 case EM_LINEINDEX:
1965 case EM_SETHANDLE:
1966 case EM_GETHANDLE:
1967 case EM_GETTHUMB:
1968 case EM_LINELENGTH:
1969 case EM_REPLACESEL:
1970 case EM_GETLINE:
1971 case EM_LIMITTEXT:
1972 case EM_CANUNDO:
1973 case EM_UNDO:
1974 case EM_FMTLINES:
1975 case EM_LINEFROMCHAR:
1976 case EM_SETTABSTOPS:
1977 case EM_SETPASSWORDCHAR:
1978 case EM_EMPTYUNDOBUFFER:
1979 case EM_GETFIRSTVISIBLELINE:
1980 case EM_SETREADONLY:
1981 case EM_SETWORDBREAKPROC:
1982 case EM_GETWORDBREAKPROC:
1983 case EM_GETPASSWORDCHAR:
1984 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1985 return 0;
1987 case LB_CARETOFF:
1988 case LB_CARETON:
1989 case LB_DELETESTRING:
1990 case LB_GETANCHORINDEX:
1991 case LB_GETCARETINDEX:
1992 case LB_GETCOUNT:
1993 case LB_GETCURSEL:
1994 case LB_GETHORIZONTALEXTENT:
1995 case LB_GETITEMDATA:
1996 case LB_GETITEMHEIGHT:
1997 case LB_GETSEL:
1998 case LB_GETSELCOUNT:
1999 case LB_GETTEXTLEN:
2000 case LB_GETTOPINDEX:
2001 case LB_RESETCONTENT:
2002 case LB_SELITEMRANGE:
2003 case LB_SELITEMRANGEEX:
2004 case LB_SETANCHORINDEX:
2005 case LB_SETCARETINDEX:
2006 case LB_SETCOLUMNWIDTH:
2007 case LB_SETCURSEL:
2008 case LB_SETHORIZONTALEXTENT:
2009 case LB_SETITEMDATA:
2010 case LB_SETITEMHEIGHT:
2011 case LB_SETSEL:
2012 case LB_SETTOPINDEX:
2013 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2014 return 0;
2015 case CB_DELETESTRING:
2016 case CB_GETCOUNT:
2017 case CB_GETLBTEXTLEN:
2018 case CB_LIMITTEXT:
2019 case CB_RESETCONTENT:
2020 case CB_SETEDITSEL:
2021 case CB_GETCURSEL:
2022 case CB_SETCURSEL:
2023 case CB_SHOWDROPDOWN:
2024 case CB_SETITEMDATA:
2025 case CB_SETITEMHEIGHT:
2026 case CB_GETITEMHEIGHT:
2027 case CB_SETEXTENDEDUI:
2028 case CB_GETEXTENDEDUI:
2029 case CB_GETDROPPEDSTATE:
2030 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
2031 return 0;
2032 case CB_GETEDITSEL:
2033 *pmsg16 = CB_GETEDITSEL16;
2034 return 1;
2036 case LB_ADDSTRING:
2037 case LB_FINDSTRING:
2038 case LB_FINDSTRINGEXACT:
2039 case LB_INSERTSTRING:
2040 case LB_SELECTSTRING:
2041 case LB_DIR:
2042 case LB_ADDFILE:
2043 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
2044 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2045 return 1;
2047 case CB_ADDSTRING:
2048 case CB_FINDSTRING:
2049 case CB_FINDSTRINGEXACT:
2050 case CB_INSERTSTRING:
2051 case CB_SELECTSTRING:
2052 case CB_DIR:
2053 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
2054 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
2055 return 1;
2057 case LB_GETITEMRECT:
2059 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
2060 if (!rect) return -1;
2061 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
2062 *plparam = MapLS( rect );
2064 *pmsg16 = LB_GETITEMRECT16;
2065 return 1;
2066 case LB_GETSELITEMS:
2068 LPARAM *items; /* old LPARAM first, then *pwparam16 x INT16 entries */
2070 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
2071 if (!(items = HeapAlloc( GetProcessHeap(), 0,
2072 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
2073 *items++ = *plparam; /* Store the previous lParam */
2074 *plparam = MapLS( items );
2076 *pmsg16 = LB_GETSELITEMS16;
2077 return 1;
2078 case LB_SETTABSTOPS:
2079 if (wParam32)
2081 INT i;
2082 LPINT16 stops;
2083 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
2084 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
2085 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
2086 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
2087 *plparam = MapLS( stops );
2088 return 1;
2090 *pmsg16 = LB_SETTABSTOPS16;
2091 return 0;
2093 case CB_GETDROPPEDCONTROLRECT:
2095 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
2096 if (!rect) return -1;
2097 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
2098 *plparam = (LPARAM)MapLS(rect);
2100 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
2101 return 1;
2103 case LB_GETTEXT:
2104 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
2105 *pmsg16 = LB_GETTEXT16;
2106 return 1;
2108 case CB_GETLBTEXT:
2109 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
2110 *pmsg16 = CB_GETLBTEXT16;
2111 return 1;
2113 case EM_SETSEL:
2114 *pwparam16 = 0;
2115 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
2116 *pmsg16 = EM_SETSEL16;
2117 return 0;
2119 case WM_ACTIVATE:
2120 case WM_CHARTOITEM:
2121 case WM_COMMAND:
2122 case WM_VKEYTOITEM:
2123 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2124 return 0;
2125 case WM_HSCROLL:
2126 case WM_VSCROLL:
2127 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
2128 return 0;
2129 case WM_CTLCOLORMSGBOX:
2130 case WM_CTLCOLOREDIT:
2131 case WM_CTLCOLORLISTBOX:
2132 case WM_CTLCOLORBTN:
2133 case WM_CTLCOLORDLG:
2134 case WM_CTLCOLORSCROLLBAR:
2135 case WM_CTLCOLORSTATIC:
2136 *pmsg16 = WM_CTLCOLOR;
2137 *plparam = MAKELPARAM( (HWND16)*plparam,
2138 (WORD)msg32 - WM_CTLCOLORMSGBOX );
2139 return 0;
2140 case WM_COMPAREITEM:
2142 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
2143 COMPAREITEMSTRUCT16 *cis = HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16));
2144 if (!cis) return -1;
2145 cis->CtlType = (UINT16)cis32->CtlType;
2146 cis->CtlID = (UINT16)cis32->CtlID;
2147 cis->hwndItem = HWND_16( cis32->hwndItem );
2148 cis->itemID1 = (UINT16)cis32->itemID1;
2149 cis->itemData1 = cis32->itemData1;
2150 cis->itemID2 = (UINT16)cis32->itemID2;
2151 cis->itemData2 = cis32->itemData2;
2152 *plparam = MapLS( cis );
2154 return 1;
2155 case WM_DELETEITEM:
2157 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
2158 DELETEITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16) );
2159 if (!dis) return -1;
2160 dis->CtlType = (UINT16)dis32->CtlType;
2161 dis->CtlID = (UINT16)dis32->CtlID;
2162 dis->itemID = (UINT16)dis32->itemID;
2163 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
2164 : HWND_16( dis32->hwndItem );
2165 dis->itemData = dis32->itemData;
2166 *plparam = MapLS( dis );
2168 return 1;
2169 case WM_DRAWITEM:
2171 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
2172 DRAWITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16) );
2173 if (!dis) return -1;
2174 dis->CtlType = (UINT16)dis32->CtlType;
2175 dis->CtlID = (UINT16)dis32->CtlID;
2176 dis->itemID = (UINT16)dis32->itemID;
2177 dis->itemAction = (UINT16)dis32->itemAction;
2178 dis->itemState = (UINT16)dis32->itemState;
2179 dis->hwndItem = HWND_16( dis32->hwndItem );
2180 dis->hDC = HDC_16(dis32->hDC);
2181 dis->itemData = dis32->itemData;
2182 dis->rcItem.left = dis32->rcItem.left;
2183 dis->rcItem.top = dis32->rcItem.top;
2184 dis->rcItem.right = dis32->rcItem.right;
2185 dis->rcItem.bottom = dis32->rcItem.bottom;
2186 *plparam = MapLS( dis );
2188 return 1;
2189 case WM_MEASUREITEM:
2191 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
2192 MEASUREITEMSTRUCT16 *mis = HeapAlloc( GetProcessHeap(), 0, sizeof(*mis)+sizeof(LPARAM));
2193 if (!mis) return -1;
2194 mis->CtlType = (UINT16)mis32->CtlType;
2195 mis->CtlID = (UINT16)mis32->CtlID;
2196 mis->itemID = (UINT16)mis32->itemID;
2197 mis->itemWidth = (UINT16)mis32->itemWidth;
2198 mis->itemHeight = (UINT16)mis32->itemHeight;
2199 mis->itemData = mis32->itemData;
2200 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
2201 *plparam = MapLS( mis );
2203 return 1;
2204 case WM_GETMINMAXINFO:
2206 MINMAXINFO16 *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM) );
2207 if (!mmi) return -1;
2208 MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
2209 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
2210 *plparam = MapLS( mmi );
2212 return 1;
2213 case WM_GETTEXT:
2214 case WM_ASKCBFORMATNAME:
2216 LPARAM *str; /* store LPARAM, then *pwparam16 char space */
2217 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
2218 if (!(str = HeapAlloc( GetProcessHeap(), 0, *pwparam16 + sizeof(LPARAM)))) return -1;
2219 *str++ = *plparam; /* Store the previous lParam */
2220 *plparam = MapLS( str );
2222 return 1;
2223 case WM_MDICREATE:
2225 MDICREATESTRUCT16 *cs;
2226 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
2228 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2229 MDICREATESTRUCT32Ato16( cs32, cs );
2230 cs->szTitle = MapLS( cs32->szTitle );
2231 cs->szClass = MapLS( cs32->szClass );
2232 *plparam = MapLS( cs );
2234 return 1;
2235 case WM_MDIGETACTIVE:
2236 return 1;
2237 case WM_MDISETMENU:
2238 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
2239 (HMENU16)LOWORD(*plparam) );
2240 *pwparam16 = (*plparam == 0);
2241 return 0;
2242 case WM_MENUSELECT:
2243 if(HIWORD(wParam32) & MF_POPUP)
2245 HMENU hmenu;
2246 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
2248 if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
2249 *pwparam16=HMENU_16(hmenu);
2252 /* fall through */
2253 case WM_MENUCHAR:
2254 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2255 return 0;
2256 case WM_MDIACTIVATE:
2257 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
2259 *pwparam16 = ((HWND)*plparam == hwnd);
2260 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
2261 (HWND16)LOWORD(wParam32) );
2263 else
2265 *pwparam16 = HWND_16( (HWND)wParam32 );
2266 *plparam = 0;
2268 return 0;
2269 case WM_NCCALCSIZE:
2271 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
2272 NCCALCSIZE_PARAMS16 *nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM));
2273 if (!nc) return -1;
2275 nc->rgrc[0].left = nc32->rgrc[0].left;
2276 nc->rgrc[0].top = nc32->rgrc[0].top;
2277 nc->rgrc[0].right = nc32->rgrc[0].right;
2278 nc->rgrc[0].bottom = nc32->rgrc[0].bottom;
2279 if (wParam32)
2281 WINDOWPOS16 *wp;
2282 nc->rgrc[1].left = nc32->rgrc[1].left;
2283 nc->rgrc[1].top = nc32->rgrc[1].top;
2284 nc->rgrc[1].right = nc32->rgrc[1].right;
2285 nc->rgrc[1].bottom = nc32->rgrc[1].bottom;
2286 nc->rgrc[2].left = nc32->rgrc[2].left;
2287 nc->rgrc[2].top = nc32->rgrc[2].top;
2288 nc->rgrc[2].right = nc32->rgrc[2].right;
2289 nc->rgrc[2].bottom = nc32->rgrc[2].bottom;
2290 if (!(wp = HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16) )))
2292 HeapFree( GetProcessHeap(), 0, nc );
2293 return -1;
2295 WINDOWPOS32to16( nc32->lppos, wp );
2296 nc->lppos = MapLS( wp );
2298 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
2299 *plparam = MapLS( nc );
2301 return 1;
2302 case WM_NCCREATE:
2303 case WM_CREATE:
2305 CREATESTRUCT16 *cs;
2306 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
2308 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2309 CREATESTRUCT32Ato16( cs32, cs );
2310 cs->lpszName = MapLS( cs32->lpszName );
2311 cs->lpszClass = MapLS( cs32->lpszClass );
2313 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2315 MDICREATESTRUCT16 *mdi_cs16;
2316 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
2317 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2318 if (!mdi_cs16)
2320 HeapFree(GetProcessHeap(), 0, cs);
2321 return -1;
2323 MDICREATESTRUCT32Ato16(mdi_cs, mdi_cs16);
2324 mdi_cs16->szTitle = MapLS( mdi_cs->szTitle );
2325 mdi_cs16->szClass = MapLS( mdi_cs->szClass );
2326 cs->lpCreateParams = MapLS( mdi_cs16 );
2328 *plparam = MapLS( cs );
2330 return 1;
2331 case WM_PARENTNOTIFY:
2332 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
2333 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
2334 /* else nothing to do */
2335 return 0;
2336 case WM_NOTIFY:
2337 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
2338 return 1;
2339 case WM_SETTEXT:
2340 case WM_WININICHANGE:
2341 case WM_DEVMODECHANGE:
2342 *plparam = MapLS( (LPSTR)*plparam );
2343 return 1;
2344 case WM_WINDOWPOSCHANGING:
2345 case WM_WINDOWPOSCHANGED:
2347 WINDOWPOS16 *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
2348 if (!wp) return -1;
2349 WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2350 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2351 *plparam = MapLS( wp );
2353 return 1;
2354 case WM_GETDLGCODE:
2355 if (*plparam) {
2356 LPMSG msg32 = (LPMSG) *plparam;
2357 LPMSG16 msg16 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16) );
2359 if (!msg16) return -1;
2360 msg16->hwnd = HWND_16( msg32->hwnd );
2361 msg16->lParam = msg32->lParam;
2362 msg16->time = msg32->time;
2363 msg16->pt.x = msg32->pt.x;
2364 msg16->pt.y = msg32->pt.y;
2365 /* this is right, right? */
2366 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2367 &msg16->message,&msg16->wParam, &msg16->lParam)<0)
2369 HeapFree( GetProcessHeap(), 0, msg16 );
2370 return -1;
2372 *plparam = MapLS( msg16 );
2373 return 1;
2375 return 0;
2377 case WM_ACTIVATEAPP:
2378 if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
2379 return 0;
2380 case WM_NEXTMENU:
2382 MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
2383 *plparam = (LPARAM)next->hmenuIn;
2384 return 1;
2386 case WM_PAINT:
2387 if (IsIconic( hwnd ) && GetClassLongW( hwnd, GCL_HICON ))
2389 *pmsg16 = WM_PAINTICON;
2390 *pwparam16 = 1;
2392 return 0;
2393 case WM_ERASEBKGND:
2394 if (IsIconic( hwnd ) && GetClassLongW( hwnd, GCL_HICON ))
2395 *pmsg16 = WM_ICONERASEBKGND;
2396 return 0;
2397 case WM_PAINTCLIPBOARD:
2398 case WM_SIZECLIPBOARD:
2399 FIXME_(msg)("message %04x needs translation\n", msg32 );
2400 return -1;
2401 /* following messages should not be sent to 16-bit apps */
2402 case WM_SIZING:
2403 case WM_MOVING:
2404 case WM_CAPTURECHANGED:
2405 case WM_STYLECHANGING:
2406 case WM_STYLECHANGED:
2407 return -1;
2408 case WM_DDE_INITIATE:
2409 case WM_DDE_TERMINATE:
2410 case WM_DDE_UNADVISE:
2411 case WM_DDE_REQUEST:
2412 *pwparam16 = HWND_16((HWND)wParam32);
2413 return 0;
2414 case WM_DDE_ADVISE:
2415 case WM_DDE_DATA:
2416 case WM_DDE_POKE:
2418 UINT lo32, hi;
2419 HANDLE16 lo16 = 0;
2421 *pwparam16 = HWND_16((HWND)wParam32);
2422 UnpackDDElParam(msg32, *plparam, &lo32, &hi);
2423 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE)))
2424 return -1;
2425 *plparam = MAKELPARAM(lo16, hi);
2427 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2428 case WM_DDE_ACK:
2430 UINT lo, hi;
2431 int flag = 0;
2432 char buf[2];
2434 *pwparam16 = HWND_16((HWND)wParam32);
2436 UnpackDDElParam(msg32, *plparam, &lo, &hi);
2438 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
2439 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
2440 switch (flag)
2442 case 0:
2443 if (hi)
2445 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2446 hi = 0;
2448 break;
2449 case 1:
2450 break; /* atom, nothing to do */
2451 case 3:
2452 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
2453 /* fall thru */
2454 case 2:
2455 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
2456 break;
2458 *plparam = MAKELPARAM(lo, hi);
2460 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2461 case WM_DDE_EXECUTE:
2462 *plparam = convert_handle_32_to_16(*plparam, GMEM_DDESHARE);
2463 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2464 default: /* No translation needed */
2465 return 0;
2470 /**********************************************************************
2471 * WINPROC_UnmapMsg32ATo16
2473 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2475 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2476 MSGPARAM16* p16 )
2478 switch(msg)
2480 case SBM_GETRANGE:
2481 *(LPINT)wParam = LOWORD(p16->lResult);
2482 *(LPINT)lParam = HIWORD(p16->lResult);
2483 break;
2485 case LB_ADDFILE:
2486 case LB_ADDSTRING:
2487 case LB_DIR:
2488 case LB_FINDSTRING:
2489 case LB_FINDSTRINGEXACT:
2490 case LB_INSERTSTRING:
2491 case LB_SELECTSTRING:
2492 case LB_GETTEXT:
2493 case CB_ADDSTRING:
2494 case CB_FINDSTRING:
2495 case CB_FINDSTRINGEXACT:
2496 case CB_INSERTSTRING:
2497 case CB_SELECTSTRING:
2498 case CB_DIR:
2499 case CB_GETLBTEXT:
2500 case WM_SETTEXT:
2501 case WM_WININICHANGE:
2502 case WM_DEVMODECHANGE:
2503 UnMapLS( (SEGPTR)p16->lParam );
2504 break;
2505 case LB_SETTABSTOPS:
2506 case WM_COMPAREITEM:
2507 case WM_DELETEITEM:
2508 case WM_DRAWITEM:
2510 void *ptr = MapSL( p16->lParam );
2511 UnMapLS( p16->lParam );
2512 HeapFree( GetProcessHeap(), 0, ptr );
2514 break;
2515 case CB_GETDROPPEDCONTROLRECT:
2516 case LB_GETITEMRECT:
2518 RECT *r32;
2519 RECT16 *rect = MapSL(p16->lParam);
2520 UnMapLS( p16->lParam );
2521 p16->lParam = *(LPARAM *)(rect + 1);
2522 r32 = (RECT *)p16->lParam;
2523 r32->left = rect->left;
2524 r32->top = rect->top;
2525 r32->right = rect->right;
2526 r32->bottom = rect->bottom;
2527 HeapFree( GetProcessHeap(), 0, rect );
2529 break;
2530 case LB_GETSELITEMS:
2532 INT i;
2533 LPINT16 items = MapSL(p16->lParam);
2534 UnMapLS( p16->lParam );
2535 p16->lParam = *((LPARAM *)items - 1);
2536 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2537 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
2539 break;
2541 case CB_GETEDITSEL:
2542 if( wParam )
2543 *((PUINT)(wParam)) = LOWORD(p16->lResult);
2544 if( lParam )
2545 *((PUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2546 break;
2548 case WM_MEASUREITEM:
2550 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2551 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2552 mis32->itemWidth = mis->itemWidth;
2553 mis32->itemHeight = mis->itemHeight;
2554 UnMapLS( p16->lParam );
2555 HeapFree( GetProcessHeap(), 0, mis );
2557 break;
2558 case WM_GETMINMAXINFO:
2560 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2561 UnMapLS( p16->lParam );
2562 p16->lParam = *(LPARAM *)(mmi + 1);
2563 MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2564 HeapFree( GetProcessHeap(), 0, mmi );
2566 break;
2567 case WM_GETTEXT:
2568 case WM_ASKCBFORMATNAME:
2570 LPSTR str = MapSL(p16->lParam);
2571 UnMapLS( p16->lParam );
2572 p16->lParam = *((LPARAM *)str - 1);
2573 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2574 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2576 break;
2577 case WM_MDICREATE:
2579 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2580 UnMapLS( cs->szTitle );
2581 UnMapLS( cs->szClass );
2582 UnMapLS( p16->lParam );
2583 HeapFree( GetProcessHeap(), 0, cs );
2585 break;
2586 case WM_MDIGETACTIVE:
2587 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2588 p16->lResult = (LRESULT)WIN_Handle32( LOWORD(p16->lResult) );
2589 break;
2590 case WM_NCCALCSIZE:
2592 NCCALCSIZE_PARAMS *nc32;
2593 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2594 UnMapLS( p16->lParam );
2595 p16->lParam = *(LPARAM *)(nc + 1);
2596 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2597 nc32->rgrc[0].left = nc->rgrc[0].left;
2598 nc32->rgrc[0].top = nc->rgrc[0].top;
2599 nc32->rgrc[0].right = nc->rgrc[0].right;
2600 nc32->rgrc[0].bottom = nc->rgrc[0].bottom;
2601 if (p16->wParam)
2603 WINDOWPOS16 *pos = MapSL(nc->lppos);
2604 UnMapLS( nc->lppos );
2605 nc32->rgrc[1].left = nc->rgrc[1].left;
2606 nc32->rgrc[1].top = nc->rgrc[1].top;
2607 nc32->rgrc[1].right = nc->rgrc[1].right;
2608 nc32->rgrc[1].bottom = nc->rgrc[1].bottom;
2609 nc32->rgrc[2].left = nc->rgrc[2].left;
2610 nc32->rgrc[2].top = nc->rgrc[2].top;
2611 nc32->rgrc[2].right = nc->rgrc[2].right;
2612 nc32->rgrc[2].bottom = nc->rgrc[2].bottom;
2613 WINDOWPOS16to32( pos, nc32->lppos );
2614 HeapFree( GetProcessHeap(), 0, pos );
2616 HeapFree( GetProcessHeap(), 0, nc );
2618 break;
2619 case WM_NCCREATE:
2620 case WM_CREATE:
2622 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2623 UnMapLS( p16->lParam );
2624 UnMapLS( cs->lpszName );
2625 UnMapLS( cs->lpszClass );
2626 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2628 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2629 UnMapLS( cs->lpCreateParams );
2630 UnMapLS( mdi_cs16->szTitle );
2631 UnMapLS( mdi_cs16->szClass );
2632 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2634 HeapFree( GetProcessHeap(), 0, cs );
2636 break;
2637 case WM_WINDOWPOSCHANGING:
2638 case WM_WINDOWPOSCHANGED:
2640 WINDOWPOS16 *wp = MapSL(p16->lParam);
2641 UnMapLS( p16->lParam );
2642 p16->lParam = *(LPARAM *)(wp + 1);
2643 WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2644 HeapFree( GetProcessHeap(), 0, wp );
2646 break;
2647 case WM_NOTIFY:
2648 UnMapLS(p16->lParam);
2649 break;
2650 case WM_GETDLGCODE:
2651 if (p16->lParam)
2653 LPMSG16 msg16 = MapSL(p16->lParam);
2654 MSGPARAM16 msgp16;
2655 UnMapLS( p16->lParam );
2656 msgp16.wParam=msg16->wParam;
2657 msgp16.lParam=msg16->lParam;
2658 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2659 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2660 &msgp16 );
2661 HeapFree( GetProcessHeap(), 0, msg16 );
2663 break;
2664 case WM_NEXTMENU:
2666 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2667 next->hmenuNext = HMENU_32( LOWORD(p16->lResult) );
2668 next->hwndNext = WIN_Handle32( HIWORD(p16->lResult) );
2669 p16->lResult = 0;
2671 break;
2676 /**********************************************************************
2677 * WINPROC_MapMsg32WTo16
2679 * Map a message from 32-bit Unicode to 16-bit.
2680 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2682 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2683 UINT16 *pmsg16, WPARAM16 *pwparam16,
2684 LPARAM *plparam )
2686 BYTE ch;
2687 WCHAR wch;
2689 *pmsg16 = LOWORD(msg32);
2690 *pwparam16 = LOWORD(wParam32);
2691 switch(msg32)
2693 case LB_ADDSTRING:
2694 case LB_FINDSTRING:
2695 case LB_FINDSTRINGEXACT:
2696 case LB_INSERTSTRING:
2697 case LB_SELECTSTRING:
2698 case LB_DIR:
2699 case LB_ADDFILE:
2700 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2701 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2702 return 1;
2704 case CB_ADDSTRING:
2705 case CB_FINDSTRING:
2706 case CB_FINDSTRINGEXACT:
2707 case CB_INSERTSTRING:
2708 case CB_SELECTSTRING:
2709 case CB_DIR:
2710 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2711 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2712 return 1;
2714 case WM_NCCREATE:
2715 case WM_CREATE:
2717 CREATESTRUCT16 *cs;
2718 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2720 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2721 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2722 cs->lpszName = map_str_32W_to_16( cs32->lpszName );
2723 cs->lpszClass = map_str_32W_to_16( cs32->lpszClass );
2725 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2727 MDICREATESTRUCT16 *mdi_cs16;
2728 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs32->lpCreateParams;
2729 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2730 if (!mdi_cs16)
2732 HeapFree(GetProcessHeap(), 0, cs);
2733 return -1;
2735 MDICREATESTRUCT32Ato16((MDICREATESTRUCTA *)mdi_cs, mdi_cs16);
2736 mdi_cs16->szTitle = map_str_32W_to_16(mdi_cs->szTitle);
2737 mdi_cs16->szClass = map_str_32W_to_16(mdi_cs->szClass);
2738 cs->lpCreateParams = MapLS(mdi_cs16);
2740 *plparam = MapLS(cs);
2742 return 1;
2743 case WM_MDICREATE:
2745 MDICREATESTRUCT16 *cs;
2746 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2748 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2749 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2750 cs->szTitle = map_str_32W_to_16( cs32->szTitle );
2751 cs->szClass = map_str_32W_to_16( cs32->szClass );
2752 *plparam = MapLS(cs);
2754 return 1;
2755 case WM_SETTEXT:
2756 case WM_WININICHANGE:
2757 case WM_DEVMODECHANGE:
2758 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2759 return 1;
2760 case LB_GETTEXT:
2761 if ( WINPROC_TestLBForStr( hwnd ))
2763 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2764 if (!str) return -1;
2765 *pmsg16 = LB_GETTEXT16;
2766 *plparam = (LPARAM)MapLS(str);
2768 return 1;
2769 case CB_GETLBTEXT:
2770 if ( WINPROC_TestCBForStr( hwnd ))
2772 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2773 if (!str) return -1;
2774 *pmsg16 = CB_GETLBTEXT16;
2775 *plparam = (LPARAM)MapLS(str);
2777 return 1;
2779 case WM_CHARTOITEM:
2780 wch = LOWORD(wParam32);
2781 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2782 *pwparam16 = ch;
2783 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2784 return 0;
2785 case WM_MENUCHAR:
2786 wch = LOWORD(wParam32);
2787 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2788 *pwparam16 = ch;
2789 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2790 return 0;
2791 case WM_CHAR:
2792 case WM_DEADCHAR:
2793 case WM_SYSCHAR:
2794 case WM_SYSDEADCHAR:
2795 wch = wParam32;
2796 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2797 *pwparam16 = ch;
2798 return 0;
2799 case WM_IME_CHAR:
2801 BYTE ch[2];
2803 wch = wParam32;
2804 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
2805 *pwparam16 = (ch[0] << 8) | ch[1];
2806 else
2807 *pwparam16 = ch[0];
2809 return 0;
2811 default: /* No Unicode translation needed (?) */
2812 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2813 pwparam16, plparam );
2818 /**********************************************************************
2819 * WINPROC_UnmapMsg32WTo16
2821 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2823 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2824 MSGPARAM16* p16 )
2826 switch(msg)
2828 case LB_ADDSTRING:
2829 case LB_FINDSTRING:
2830 case LB_FINDSTRINGEXACT:
2831 case LB_INSERTSTRING:
2832 case LB_SELECTSTRING:
2833 case LB_DIR:
2834 case LB_ADDFILE:
2835 case CB_ADDSTRING:
2836 case CB_FINDSTRING:
2837 case CB_FINDSTRINGEXACT:
2838 case CB_INSERTSTRING:
2839 case CB_SELECTSTRING:
2840 case CB_DIR:
2841 case WM_SETTEXT:
2842 case WM_WININICHANGE:
2843 case WM_DEVMODECHANGE:
2844 unmap_str_32W_to_16( p16->lParam );
2845 break;
2846 case WM_NCCREATE:
2847 case WM_CREATE:
2849 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2850 UnMapLS( p16->lParam );
2851 unmap_str_32W_to_16( cs->lpszName );
2852 unmap_str_32W_to_16( cs->lpszClass );
2854 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2856 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2857 UnMapLS( cs->lpCreateParams );
2858 unmap_str_32W_to_16(mdi_cs16->szTitle);
2859 unmap_str_32W_to_16(mdi_cs16->szClass);
2860 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2862 HeapFree( GetProcessHeap(), 0, cs );
2864 break;
2865 case WM_MDICREATE:
2867 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2868 UnMapLS( p16->lParam );
2869 unmap_str_32W_to_16( cs->szTitle );
2870 unmap_str_32W_to_16( cs->szClass );
2871 HeapFree( GetProcessHeap(), 0, cs );
2873 break;
2874 case WM_GETTEXT:
2875 case WM_ASKCBFORMATNAME:
2877 LPSTR str = MapSL(p16->lParam);
2878 UnMapLS( p16->lParam );
2879 p16->lParam = *((LPARAM *)str - 1);
2880 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2881 p16->lResult = strlenW( (LPWSTR)p16->lParam );
2882 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2884 break;
2885 case LB_GETTEXT:
2886 if ( WINPROC_TestLBForStr( hwnd ))
2888 LPSTR str = MapSL(p16->lParam);
2889 UnMapLS( p16->lParam );
2890 p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
2891 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2893 break;
2894 case CB_GETLBTEXT:
2895 if ( WINPROC_TestCBForStr( hwnd ))
2897 LPSTR str = MapSL(p16->lParam);
2898 UnMapLS( p16->lParam );
2899 p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
2900 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2902 break;
2903 default:
2904 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2905 break;
2910 /**********************************************************************
2911 * WINPROC_CallProc32ATo32W
2913 * Call a window procedure, translating args from Ansi to Unicode.
2915 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2916 UINT msg, WPARAM wParam,
2917 LPARAM lParam )
2919 LRESULT result;
2920 int unmap;
2922 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2923 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2925 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2926 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2927 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2928 return 0;
2930 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2931 if (unmap) result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
2932 return result;
2936 /**********************************************************************
2937 * WINPROC_CallProc32WTo32A_fast
2940 static BOOL WINPROC_CallProc32WTo32A_fast( WNDPROC func, HWND hwnd,
2941 UINT msg, WPARAM wParam,
2942 LPARAM lParam, LRESULT *result )
2944 switch(msg)
2946 case WM_NCCREATE:
2947 case WM_CREATE:
2948 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
2949 * at this point.
2951 char buffer[1024];
2952 char *cls = buffer, *name;
2953 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
2954 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
2955 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
2957 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
2958 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
2960 if (csW->lpszName)
2962 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
2963 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
2965 else
2966 name_lenW = name_lenA = 0;
2968 if (class_lenA + name_lenA + 2 > sizeof(buffer))
2970 cls = HeapAlloc(GetProcessHeap(), 0, class_lenA + name_lenA + 2);
2971 if (!cls) return FALSE;
2974 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
2975 cls[class_lenA] = 0;
2976 csA.lpszClass = cls;
2978 if (csW->lpszName)
2980 name = cls + class_lenA + 1;
2981 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
2982 name[name_lenA] = 0;
2983 csA.lpszName = name;
2986 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2988 MDICREATESTRUCTA mdi_cs;
2990 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
2991 mdi_cs.szTitle = csA.lpszName;
2992 mdi_cs.szClass = csA.lpszClass;
2993 csA.lpCreateParams = &mdi_cs;
2996 lParam = (LPARAM)&csA;
2997 *result = WINPROC_CallWndProc(func, hwnd, msg, wParam, lParam);
2999 if (cls != buffer) HeapFree(GetProcessHeap(), 0, cls);
3001 return TRUE;
3003 default:
3004 return FALSE;
3008 /**********************************************************************
3009 * WINPROC_CallProc32WTo32A
3011 * Call a window procedure, translating args from Unicode to Ansi.
3013 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
3014 UINT msg, WPARAM wParam,
3015 LPARAM lParam )
3017 LRESULT result;
3018 int unmap;
3020 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3021 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3023 if (WINPROC_CallProc32WTo32A_fast( func, hwnd, msg, wParam, lParam, &result ))
3024 return result;
3026 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
3027 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
3028 SPY_GetMsgName(msg, hwnd), wParam, lParam );
3029 return 0;
3031 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3032 if( unmap ) result = WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam, result );
3033 return result;
3037 /**********************************************************************
3038 * __wine_call_wndproc_32A (USER.1010)
3040 LRESULT WINAPI __wine_call_wndproc_32A( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
3041 WNDPROC func )
3043 LRESULT result;
3044 UINT msg32;
3045 WPARAM wParam32;
3046 HWND hwnd32 = WIN_Handle32( hwnd );
3048 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3049 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
3051 if (WINPROC_MapMsg16To32A( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
3052 return 0;
3053 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
3054 return WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, result );
3058 /**********************************************************************
3059 * __wine_call_wndproc_32W (USER.1011)
3061 LRESULT WINAPI __wine_call_wndproc_32W( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
3062 WNDPROC func )
3064 LRESULT result;
3065 UINT msg32;
3066 WPARAM wParam32;
3067 HWND hwnd32 = WIN_Handle32( hwnd );
3069 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3070 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
3072 if (WINPROC_MapMsg16To32W( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
3073 return 0;
3074 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
3075 return WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, result );
3079 /**********************************************************************
3080 * WINPROC_CallProc32ATo16
3082 * Call a 16-bit window procedure, translating the 32-bit args.
3084 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
3085 UINT msg, WPARAM wParam,
3086 LPARAM lParam )
3088 UINT16 msg16;
3089 MSGPARAM16 mp16;
3091 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3092 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3094 mp16.lParam = lParam;
3095 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
3096 return 0;
3097 mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
3098 mp16.wParam, mp16.lParam );
3099 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
3100 return mp16.lResult;
3104 /**********************************************************************
3105 * WINPROC_CallProc32WTo16
3107 * Call a 16-bit window procedure, translating the 32-bit args.
3109 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
3110 UINT msg, WPARAM wParam,
3111 LPARAM lParam )
3113 UINT16 msg16;
3114 MSGPARAM16 mp16;
3116 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3117 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3119 mp16.lParam = lParam;
3120 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
3121 &mp16.lParam ) == -1)
3122 return 0;
3123 mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
3124 mp16.wParam, mp16.lParam );
3125 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
3126 return mp16.lResult;
3130 /**********************************************************************
3131 * CallWindowProc (USER.122)
3133 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
3134 WPARAM16 wParam, LPARAM lParam )
3136 WINDOWPROC *proc;
3138 if (!func) return 0;
3140 if (!(proc = WINPROC_GetPtr( (WNDPROC)func )))
3141 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
3143 #if testing
3144 func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_16 );
3145 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
3146 #endif
3148 switch(proc->type)
3150 case WIN_PROC_16:
3151 if (!proc->thunk.t_from32.proc) return 0;
3152 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
3153 hwnd, msg, wParam, lParam );
3154 case WIN_PROC_32A:
3155 if (!proc->thunk.t_from16.proc) return 0;
3156 return __wine_call_wndproc_32A( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
3157 case WIN_PROC_32W:
3158 if (!proc->thunk.t_from16.proc) return 0;
3159 return __wine_call_wndproc_32W( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
3160 default:
3161 WARN_(relay)("Invalid proc %p\n", proc );
3162 return 0;
3167 /**********************************************************************
3168 * CallWindowProcA (USER32.@)
3170 * The CallWindowProc() function invokes the windows procedure _func_,
3171 * with _hwnd_ as the target window, the message specified by _msg_, and
3172 * the message parameters _wParam_ and _lParam_.
3174 * Some kinds of argument conversion may be done, I'm not sure what.
3176 * CallWindowProc() may be used for windows subclassing. Use
3177 * SetWindowLong() to set a new windows procedure for windows of the
3178 * subclass, and handle subclassed messages in the new windows
3179 * procedure. The new windows procedure may then use CallWindowProc()
3180 * with _func_ set to the parent class's windows procedure to dispatch
3181 * the message to the superclass.
3183 * RETURNS
3185 * The return value is message dependent.
3187 * CONFORMANCE
3189 * ECMA-234, Win32
3191 LRESULT WINAPI CallWindowProcA(
3192 WNDPROC func, /* [in] window procedure */
3193 HWND hwnd, /* [in] target window */
3194 UINT msg, /* [in] message */
3195 WPARAM wParam, /* [in] message dependent parameter */
3196 LPARAM lParam /* [in] message dependent parameter */
3198 WINDOWPROC *proc;
3200 if (!func) return 0;
3202 if (!(proc = WINPROC_GetPtr( func )))
3203 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3205 #if testing
3206 func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_32A );
3207 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3208 #endif
3210 switch(proc->type)
3212 case WIN_PROC_16:
3213 if (!proc->thunk.t_from32.proc) return 0;
3214 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
3215 hwnd, msg, wParam, lParam );
3216 case WIN_PROC_32A:
3217 if (!proc->thunk.t_from16.proc) return 0;
3218 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
3219 hwnd, msg, wParam, lParam );
3220 case WIN_PROC_32W:
3221 if (!proc->thunk.t_from16.proc) return 0;
3222 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
3223 hwnd, msg, wParam, lParam );
3224 default:
3225 WARN_(relay)("Invalid proc %p\n", proc );
3226 return 0;
3231 /**********************************************************************
3232 * CallWindowProcW (USER32.@)
3234 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
3235 WPARAM wParam, LPARAM lParam )
3237 WINDOWPROC *proc;
3239 if (!func) return 0;
3241 if (!(proc = WINPROC_GetPtr( (WNDPROC)func )))
3242 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3244 #if testing
3245 func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_32W );
3246 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3247 #endif
3249 switch(proc->type)
3251 case WIN_PROC_16:
3252 if (!proc->thunk.t_from32.proc) return 0;
3253 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
3254 hwnd, msg, wParam, lParam );
3255 case WIN_PROC_32A:
3256 if (!proc->thunk.t_from16.proc) return 0;
3257 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
3258 hwnd, msg, wParam, lParam );
3259 case WIN_PROC_32W:
3260 if (!proc->thunk.t_from16.proc) return 0;
3261 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
3262 hwnd, msg, wParam, lParam );
3263 default:
3264 WARN_(relay)("Invalid proc %p\n", proc );
3265 return 0;