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
23 #include "wine/port.h"
33 #include "wine/winbase16.h"
34 #include "wine/winuser16.h"
38 #include "user_private.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DECLARE_DEBUG_CHANNEL(msg);
45 WINE_DECLARE_DEBUG_CHANNEL(relay);
46 WINE_DEFAULT_DEBUG_CHANNEL(win);
52 /* Window procedure 16-to-32-bit thunk */
55 BYTE popl_eax; /* popl %eax (return address) */
56 BYTE pushl_func; /* pushl $proc */
58 BYTE pushl_eax; /* pushl %eax */
59 BYTE ljmp; /* ljmp relay*/
60 DWORD relay_offset; /* __wine_call_wndproc_32A/W */
75 typedef struct tagWINDOWPROC
77 WINPROC_THUNK thunk; /* Thunk */
78 BYTE type; /* Function type */
79 WNDPROC16 proc16; /* 16-bit window proc */
82 #define WINPROC_HANDLE (~0UL >> 16)
83 #define MAX_WINPROCS (0x10000 / sizeof(WINDOWPROC))
85 static WINDOWPROC winproc_array[MAX_WINPROCS];
86 static UINT winproc_used;
88 static CRITICAL_SECTION winproc_cs;
89 static CRITICAL_SECTION_DEBUG critsect_debug =
92 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
93 0, 0, { (DWORD_PTR)(__FILE__ ": winproc_cs") }
95 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
97 static BOOL is_valid_winproc( WINDOWPROC *proc )
100 if (((BYTE *)proc - (BYTE *)winproc_array) % sizeof(*proc)) return FALSE;
101 /* check array limits */
102 if (proc < winproc_array || proc >= winproc_array + winproc_used) return FALSE;
103 return (proc->type != WIN_PROC_INVALID);
106 /* find an existing winproc for a given 16-bit function and type */
107 /* FIXME: probably should do something more clever than a linear search */
108 static inline WINDOWPROC *find_winproc16( WNDPROC16 func )
112 for (i = 0; i < winproc_used; i++)
114 if (winproc_array[i].type == WIN_PROC_16 && winproc_array[i].proc16 == func)
115 return &winproc_array[i];
120 /* find an existing winproc for a given function and type */
121 /* FIXME: probably should do something more clever than a linear search */
122 static inline WINDOWPROC *find_winproc( WNDPROC func, BOOL unicode )
126 for (i = 0; i < winproc_used; i++)
128 if (winproc_array[i].thunk.proc == func &&
129 winproc_array[i].type == (unicode ? WIN_PROC_32W : WIN_PROC_32A))
130 return &winproc_array[i];
135 /* initialize a new 16-bit winproc */
136 static inline void set_winproc16( WINDOWPROC *proc, WNDPROC16 func )
139 proc->type = WIN_PROC_16;
142 /* initialize a new winproc */
143 static inline void set_winproc( WINDOWPROC *proc, WNDPROC func, BOOL unicode )
146 static FARPROC16 relay_32A, relay_32W;
148 proc->thunk.popl_eax = 0x58; /* popl %eax */
149 proc->thunk.pushl_func = 0x68; /* pushl $proc */
150 proc->thunk.pushl_eax = 0x50; /* pushl %eax */
151 proc->thunk.ljmp = 0xea; /* ljmp relay*/
154 if (!relay_32A) relay_32A = GetProcAddress16( GetModuleHandle16("user"),
155 "__wine_call_wndproc_32A" );
156 proc->thunk.relay_offset = OFFSETOF(relay_32A);
157 proc->thunk.relay_sel = SELECTOROF(relay_32A);
161 if (!relay_32W) relay_32W = GetProcAddress16( GetModuleHandle16("user"),
162 "__wine_call_wndproc_32W" );
163 proc->thunk.relay_offset = OFFSETOF(relay_32W);
164 proc->thunk.relay_sel = SELECTOROF(relay_32W);
166 #endif /* __i386__ */
167 proc->thunk.proc = func;
169 proc->type = unicode ? WIN_PROC_32W : WIN_PROC_32A;
172 static WORD get_winproc_selector(void)
174 static LONG winproc_selector;
177 if (!(ret = winproc_selector))
180 WORD sel = wine_ldt_alloc_entries(1);
181 wine_ldt_set_base( &entry, winproc_array );
182 wine_ldt_set_limit( &entry, sizeof(winproc_array) - 1 );
183 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
184 wine_ldt_set_entry( sel, &entry );
185 if (!(ret = InterlockedCompareExchange( &winproc_selector, sel, 0 ))) ret = sel;
186 else wine_ldt_free_entries( sel, 1 ); /* somebody beat us to it */
191 /* return the window proc for a given handle, or NULL for an invalid handle */
192 static inline WINDOWPROC *handle_to_proc( WNDPROC handle )
194 UINT index = LOWORD(handle);
195 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return NULL;
196 if (index >= winproc_used) return NULL;
197 return &winproc_array[index];
200 /* return the window proc for a given handle, or NULL for an invalid handle */
201 static inline WINDOWPROC *handle16_to_proc( WNDPROC16 handle )
203 if (HIWORD(handle) == get_winproc_selector())
205 BYTE *ptr = (BYTE *)winproc_array + LOWORD(handle);
206 /* It must be the thunk address */
207 WINDOWPROC *proc = (WINDOWPROC *)(ptr - FIELD_OFFSET(WINDOWPROC,thunk));
208 if (is_valid_winproc(proc)) return proc;
211 return handle_to_proc( (WNDPROC)handle );
214 /* create a handle for a given window proc */
215 static inline WNDPROC proc_to_handle( WINDOWPROC *proc )
217 return (WNDPROC)(ULONG_PTR)((proc - winproc_array) | (WINPROC_HANDLE << 16));
222 /* Some window procedures modify register they shouldn't, or are not
223 * properly declared stdcall; so we need a small assembly wrapper to
225 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
226 WPARAM wParam, LPARAM lParam );
227 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
238 "movl 8(%ebp),%eax\n\t"
240 "leal -12(%ebp),%esp\n\t"
247 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
248 WPARAM wParam, LPARAM lParam )
250 return proc( hwnd, msg, wParam, lParam );
252 #endif /* __i386__ */
255 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
257 to->ptReserved.x = from->ptReserved.x;
258 to->ptReserved.y = from->ptReserved.y;
259 to->ptMaxSize.x = from->ptMaxSize.x;
260 to->ptMaxSize.y = from->ptMaxSize.y;
261 to->ptMaxPosition.x = from->ptMaxPosition.x;
262 to->ptMaxPosition.y = from->ptMaxPosition.y;
263 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
264 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
265 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
266 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
269 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
271 to->ptReserved.x = from->ptReserved.x;
272 to->ptReserved.y = from->ptReserved.y;
273 to->ptMaxSize.x = from->ptMaxSize.x;
274 to->ptMaxSize.y = from->ptMaxSize.y;
275 to->ptMaxPosition.x = from->ptMaxPosition.x;
276 to->ptMaxPosition.y = from->ptMaxPosition.y;
277 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
278 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
279 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
280 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
283 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
285 to->hwnd = HWND_16(from->hwnd);
286 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
291 to->flags = from->flags;
294 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
296 to->hwnd = WIN_Handle32(from->hwnd);
297 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
298 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
303 to->flags = from->flags;
306 /* The strings are not copied */
307 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
309 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
310 to->hInstance = HINSTANCE_16(from->hInstance);
311 to->hMenu = HMENU_16(from->hMenu);
312 to->hwndParent = HWND_16(from->hwndParent);
317 to->style = from->style;
318 to->dwExStyle = from->dwExStyle;
321 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
324 to->lpCreateParams = (LPVOID)from->lpCreateParams;
325 to->hInstance = HINSTANCE_32(from->hInstance);
326 to->hMenu = HMENU_32(from->hMenu);
327 to->hwndParent = WIN_Handle32(from->hwndParent);
332 to->style = from->style;
333 to->dwExStyle = from->dwExStyle;
336 /* The strings are not copied */
337 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
339 to->hOwner = HINSTANCE_16(from->hOwner);
344 to->style = from->style;
345 to->lParam = from->lParam;
348 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
350 to->hOwner = HINSTANCE_32(from->hOwner);
355 to->style = from->style;
356 to->lParam = from->lParam;
359 /**********************************************************************
360 * WINPROC_CallWndProc32
362 * Call a 32-bit WndProc.
364 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
365 WPARAM wParam, LPARAM lParam )
371 hwnd = WIN_GetFullHandle( hwnd );
373 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
374 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam );
376 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
379 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
380 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
384 /***********************************************************************
385 * WINPROC_CallWndProc16
387 * Call a 16-bit window procedure
389 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
390 UINT16 msg, WPARAM16 wParam,
401 DRAWITEMSTRUCT16 dis16;
402 COMPAREITEMSTRUCT16 cis16;
408 /* Window procedures want ax = hInstance, ds = es = ss */
410 memset(&context, 0, sizeof(context));
411 context.SegDs = context.SegEs = SELECTOROF(NtCurrentTeb()->WOW32Reserved);
412 context.SegFs = wine_get_fs();
413 context.SegGs = wine_get_gs();
414 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
415 context.SegCs = SELECTOROF(proc);
416 context.Eip = OFFSETOF(proc);
417 context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + (WORD)&((STACK16FRAME*)0)->bp;
421 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
422 work if structures passed in lParam are placed in the stack/data
423 segment. Programmers easily make the mistake of converting lParam
424 to a near rather than a far pointer, since Windows apparently
425 allows this. We copy the structures to the 16 bit stack; this is
426 ugly but makes these programs work. */
431 size = sizeof(CREATESTRUCT16); break;
433 size = sizeof(DRAWITEMSTRUCT16); break;
435 size = sizeof(COMPAREITEMSTRUCT16); break;
439 memcpy( &args.u, MapSL(lParam), size );
440 lParam = (SEGPTR)NtCurrentTeb()->WOW32Reserved - size;
444 args.params[4] = hwnd;
445 args.params[3] = msg;
446 args.params[2] = wParam;
447 args.params[1] = HIWORD(lParam);
448 args.params[0] = LOWORD(lParam);
449 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
450 return MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
454 /**********************************************************************
457 * Get a window procedure pointer that can be passed to the Windows program.
459 WNDPROC16 WINPROC_GetProc16( WNDPROC proc )
461 WINDOWPROC *ptr = handle_to_proc( proc );
465 if (ptr->type == WIN_PROC_16)
468 return (WNDPROC16)MAKESEGPTR( get_winproc_selector(),
469 (char *)&ptr->thunk - (char *)winproc_array );
473 /**********************************************************************
476 * Get a window procedure pointer that can be passed to the Windows program.
478 WNDPROC WINPROC_GetProc( WNDPROC proc, BOOL unicode )
480 WINDOWPROC *ptr = handle_to_proc( proc );
482 if (!ptr || ptr->type != (unicode ? WIN_PROC_32W : WIN_PROC_32A)) return proc;
483 return ptr->thunk.proc; /* we can return the original proc in that case */
487 /**********************************************************************
488 * WINPROC_AllocProc16
490 * Allocate a window procedure for a window or class.
492 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
493 * lot of windows, it will usually only have a limited number of window procedures, so the
494 * array won't grow too large, and this way we avoid the need to track allocations per window.
496 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
500 if (!func) return NULL;
502 EnterCriticalSection( &winproc_cs );
504 /* check if the function is already a win proc */
505 if (!(proc = handle16_to_proc( func )))
507 /* then check if we already have a winproc for that function */
508 if (!(proc = find_winproc16( func )))
510 if (winproc_used >= MAX_WINPROCS)
511 FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
514 proc = &winproc_array[winproc_used++];
515 set_winproc16( proc, func );
516 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
517 proc_to_handle(proc), func, winproc_used, MAX_WINPROCS );
520 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc), func );
523 LeaveCriticalSection( &winproc_cs );
524 return proc_to_handle( proc );
528 /**********************************************************************
531 * Allocate a window procedure for a window or class.
533 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
534 * lot of windows, it will usually only have a limited number of window procedures, so the
535 * array won't grow too large, and this way we avoid the need to track allocations per window.
537 WNDPROC WINPROC_AllocProc( WNDPROC func, BOOL unicode )
541 if (!func) return NULL;
543 /* check if the function is already a win proc */
544 if (!(proc = handle_to_proc( func )))
546 EnterCriticalSection( &winproc_cs );
548 /* then check if we already have a winproc for that function */
549 if (!(proc = find_winproc( func, unicode )))
551 if (winproc_used >= MAX_WINPROCS)
552 FIXME( "too many winprocs, cannot allocate one for %p %c\n", func, unicode ? 'W' : 'A' );
555 proc = &winproc_array[winproc_used++];
556 set_winproc( proc, func, unicode );
557 TRACE( "allocated %p for %p %c (%d/%d used)\n",
558 proc_to_handle(proc), func, unicode ? 'W' : 'A', winproc_used, MAX_WINPROCS );
561 else TRACE( "reusing %p for %p %c\n", proc_to_handle(proc), func, unicode ? 'W' : 'A' );
563 LeaveCriticalSection( &winproc_cs );
566 return proc_to_handle( proc );
570 /**********************************************************************
573 * Return the window procedure type, or the default value if not a winproc handle.
575 BOOL WINPROC_IsUnicode( WNDPROC proc, BOOL def_val )
577 WINDOWPROC *ptr = handle_to_proc( proc );
579 if (!ptr) return def_val;
580 return (ptr->type == WIN_PROC_32W);
584 /**********************************************************************
585 * WINPROC_TestCBForStr
587 * Return TRUE if the lparam is a string
589 inline static BOOL WINPROC_TestCBForStr( HWND hwnd )
591 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
592 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
594 /**********************************************************************
595 * WINPROC_TestLBForStr
597 * Return TRUE if the lparam is a string
599 inline static BOOL WINPROC_TestLBForStr( HWND hwnd )
601 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
602 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
605 /**********************************************************************
606 * WINPROC_MapMsg32ATo32W
608 * Map a message from Ansi to Unicode.
609 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
612 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
613 * the first four bytes are the handle of the icon
614 * when the WM_SETTEXT message has been used to set the icon
616 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
621 case WM_ASKCBFORMATNAME:
623 LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0,
624 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
626 *ptr++ = *plparam; /* Store previous lParam */
627 *plparam = (LPARAM)ptr;
630 /* lparam is string (0-terminated) */
632 case WM_WININICHANGE:
633 case WM_DEVMODECHANGE:
638 if (!*plparam) return 0;
641 DWORD len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, NULL, 0);
642 WCHAR *buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
643 MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, buf, len);
644 *plparam = (LPARAM)buf;
645 return (*plparam ? 1 : -1);
647 case WM_GETTEXTLENGTH:
648 case CB_GETLBTEXTLEN:
650 return 1; /* need to map result */
654 UNICODE_STRING usBuffer;
656 { CREATESTRUCTW cs; /* new structure */
657 LPCWSTR lpszName; /* allocated Name */
658 LPCWSTR lpszClass; /* allocated Class */
661 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
663 xs->cs = *(CREATESTRUCTW *)*plparam;
664 if (HIWORD(xs->cs.lpszName))
666 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszName);
667 xs->lpszName = xs->cs.lpszName = usBuffer.Buffer;
669 if (HIWORD(xs->cs.lpszClass))
671 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszClass);
672 xs->lpszClass = xs->cs.lpszClass = usBuffer.Buffer;
675 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
677 MDICREATESTRUCTW *mdi_cs = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs));
678 *mdi_cs = *(MDICREATESTRUCTW *)xs->cs.lpCreateParams;
679 if (HIWORD(mdi_cs->szTitle))
681 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szTitle);
682 mdi_cs->szTitle = usBuffer.Buffer;
684 if (HIWORD(mdi_cs->szClass))
686 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szClass);
687 mdi_cs->szClass = usBuffer.Buffer;
689 xs->cs.lpCreateParams = mdi_cs;
692 *plparam = (LPARAM)xs;
697 MDICREATESTRUCTW *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
699 *cs = *(MDICREATESTRUCTW *)*plparam;
700 if (HIWORD(cs->szClass))
702 UNICODE_STRING usBuffer;
703 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szClass);
704 cs->szClass = usBuffer.Buffer;
706 if (HIWORD(cs->szTitle))
708 UNICODE_STRING usBuffer;
709 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szTitle);
710 cs->szTitle = usBuffer.Buffer;
712 *plparam = (LPARAM)cs;
718 case LB_INSERTSTRING:
720 case LB_FINDSTRINGEXACT:
721 case LB_SELECTSTRING:
722 if(!*plparam) return 0;
723 if ( WINPROC_TestLBForStr( hwnd ))
725 UNICODE_STRING usBuffer;
726 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
727 *plparam = (LPARAM)usBuffer.Buffer;
729 return (*plparam ? 1 : -1);
731 case LB_GETTEXT: /* FIXME: fixed sized buffer */
732 { if ( WINPROC_TestLBForStr( hwnd ))
733 { LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, 512 * sizeof(WCHAR) + sizeof(LPARAM) );
735 *ptr++ = *plparam; /* Store previous lParam */
736 *plparam = (LPARAM)ptr;
743 case CB_INSERTSTRING:
744 case CB_FINDSTRINGEXACT:
746 case CB_SELECTSTRING:
747 if(!*plparam) return 0;
748 if ( WINPROC_TestCBForStr( hwnd ))
750 UNICODE_STRING usBuffer;
751 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
752 *plparam = (LPARAM)usBuffer.Buffer;
754 return (*plparam ? 1 : -1);
756 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
757 { if ( WINPROC_TestCBForStr( hwnd ))
758 { LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, 512 * sizeof(WCHAR) + sizeof(LPARAM) );
760 *ptr++ = *plparam; /* Store previous lParam */
761 *plparam = (LPARAM)ptr;
768 { WORD len = (WORD)*plparam;
769 LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
771 *ptr++ = *plparam; /* Store previous lParam */
772 *((WORD *) ptr) = len; /* Store the length */
773 *plparam = (LPARAM)ptr;
783 case EM_SETPASSWORDCHAR:
785 CHAR ch = LOWORD(*pwparam);
787 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
788 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
796 ch[0] = (*pwparam >> 8);
797 ch[1] = *pwparam & 0xff;
799 MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
801 MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
802 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
806 case WM_PAINTCLIPBOARD:
807 case WM_SIZECLIPBOARD:
808 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
810 default: /* No translation needed */
816 /**********************************************************************
817 * WINPROC_UnmapMsg32ATo32W
819 * Unmap a message that was mapped from Ansi to Unicode.
821 LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
822 LRESULT result, WNDPROC dispatch )
827 case WM_ASKCBFORMATNAME:
829 LPARAM *ptr = (LPARAM *)lParam - 1;
830 if (!wParam) result = 0;
831 else if (!(result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
832 (LPSTR)*ptr, wParam, NULL, NULL )))
834 ((LPSTR)*ptr)[wParam-1] = 0;
837 else result--; /* do not count terminating null */
838 HeapFree( GetProcessHeap(), 0, ptr );
841 case WM_GETTEXTLENGTH:
842 case CB_GETLBTEXTLEN:
846 /* Determine respective GETTEXT message */
848 (msg == WM_GETTEXTLENGTH) ? WM_GETTEXT :
849 ((msg == CB_GETLBTEXTLEN) ? CB_GETLBTEXT : LB_GETTEXT);
850 /* wParam differs between the messages */
851 WPARAM wp = (msg == WM_GETTEXTLENGTH) ? (WPARAM)(result + 1) : wParam;
853 WCHAR* p = HeapAlloc (GetProcessHeap(), 0, (result + 1) * sizeof(WCHAR));
860 n = WINPROC_CallWndProc(dispatch, hwnd, msgGetText, wp, (LPARAM)p);
862 n = SendMessageW (hwnd, msgGetText, wp, (LPARAM)p);
864 result = WideCharToMultiByte( CP_ACP, 0, p, n, NULL, 0, 0, NULL );
865 HeapFree (GetProcessHeap(), 0, p);
873 { CREATESTRUCTW cs; /* new structure */
874 LPWSTR lpszName; /* allocated Name */
875 LPWSTR lpszClass; /* allocated Class */
877 struct s *xs = (struct s *)lParam;
878 HeapFree( GetProcessHeap(), 0, xs->lpszName );
879 HeapFree( GetProcessHeap(), 0, xs->lpszClass );
881 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
883 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)xs->cs.lpCreateParams;
884 if (HIWORD(mdi_cs->szTitle))
885 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szTitle);
886 if (HIWORD(mdi_cs->szClass))
887 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szClass);
888 HeapFree(GetProcessHeap(), 0, mdi_cs);
890 HeapFree( GetProcessHeap(), 0, xs );
896 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
897 if (HIWORD(cs->szTitle))
898 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
899 if (HIWORD(cs->szClass))
900 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
901 HeapFree( GetProcessHeap(), 0, cs );
906 case WM_WININICHANGE:
907 case WM_DEVMODECHANGE:
912 HeapFree( GetProcessHeap(), 0, (void *)lParam );
917 case LB_INSERTSTRING:
919 case LB_FINDSTRINGEXACT:
920 case LB_SELECTSTRING:
921 if ( WINPROC_TestLBForStr( hwnd ))
922 HeapFree( GetProcessHeap(), 0, (void *)lParam );
926 if ( WINPROC_TestLBForStr( hwnd ))
928 LPARAM *ptr = (LPARAM *)lParam - 1;
930 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
931 (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
932 HeapFree( GetProcessHeap(), 0, ptr );
938 case CB_INSERTSTRING:
940 case CB_FINDSTRINGEXACT:
941 case CB_SELECTSTRING:
942 if ( WINPROC_TestCBForStr( hwnd ))
943 HeapFree( GetProcessHeap(), 0, (void *)lParam );
947 if ( result < 0) /* CB_ERR and CB_ERRSPACE */
949 LPARAM *ptr = (LPARAM *)lParam - 1;
950 HeapFree( GetProcessHeap(), 0, ptr );
952 else if ( WINPROC_TestCBForStr( hwnd ))
954 LPARAM *ptr = (LPARAM *)lParam - 1;
955 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
956 (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
957 HeapFree( GetProcessHeap(), 0, ptr );
964 LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
965 WORD len = *(WORD *) lParam;
966 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, result,
967 (LPSTR)*ptr, len, NULL, NULL );
968 if (result < len) ((LPSTR)*ptr)[result] = 0;
969 HeapFree( GetProcessHeap(), 0, ptr );
977 /**********************************************************************
978 * WINPROC_MapMsg32WTo32A
980 * Map a message from Unicode to Ansi.
981 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
983 static INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
988 case WM_ASKCBFORMATNAME:
990 LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, *pwparam + sizeof(LPARAM) );
992 *ptr++ = *plparam; /* Store previous lParam */
993 *plparam = (LPARAM)ptr;
998 case WM_WININICHANGE:
999 case WM_DEVMODECHANGE:
1006 LPCWSTR str = (LPCWSTR)*plparam;
1007 int len = WideCharToMultiByte(CP_ACP, 0, str, -1, NULL, 0, 0, 0);
1008 *plparam = (LPARAM)HeapAlloc(GetProcessHeap(), 0, len);
1009 if (!*plparam) return -1;
1010 WideCharToMultiByte(CP_ACP, 0, str, -1, (LPSTR)*plparam, len, 0, 0);
1017 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
1019 *cs = *(MDICREATESTRUCTA *)*plparam;
1020 if (HIWORD(cs->szTitle))
1022 int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szTitle, -1, NULL, 0, 0, 0);
1023 LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
1024 if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szTitle, -1, buf, len, 0, 0);
1027 if (HIWORD(cs->szClass))
1029 int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szClass, -1, NULL, 0, 0, 0);
1030 LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
1031 if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)cs->szClass, -1, buf, len, 0, 0);
1034 *plparam = (LPARAM)cs;
1040 case LB_INSERTSTRING:
1042 case LB_FINDSTRINGEXACT:
1043 case LB_SELECTSTRING:
1044 if(!*plparam) return 0;
1045 if ( WINPROC_TestLBForStr( hwnd ))
1047 int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, NULL, 0, 0, 0);
1048 LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
1049 if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, buf, len, 0, 0);
1050 *plparam = (LPARAM)buf;
1052 return (*plparam ? 1 : -1);
1054 case LB_GETTEXT: /* FIXME: fixed sized buffer */
1055 { if ( WINPROC_TestLBForStr( hwnd ))
1056 { LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, 512 + sizeof(LPARAM) );
1057 if (!ptr) return -1;
1058 *ptr++ = *plparam; /* Store previous lParam */
1059 *plparam = (LPARAM)ptr;
1066 case CB_INSERTSTRING:
1068 case CB_FINDSTRINGEXACT:
1069 case CB_SELECTSTRING:
1070 if(!*plparam) return 0;
1071 if ( WINPROC_TestCBForStr( hwnd ))
1073 int len = WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, NULL, 0, 0, 0);
1074 LPSTR buf = HeapAlloc(GetProcessHeap(), 0, len);
1075 if (buf) WideCharToMultiByte(CP_ACP, 0, (LPCWSTR)*plparam, -1, buf, len, 0, 0);
1076 *plparam = (LPARAM)buf;
1078 return (*plparam ? 1 : -1);
1080 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
1081 { if ( WINPROC_TestCBForStr( hwnd ))
1082 { LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, 512 + sizeof(LPARAM) );
1083 if (!ptr) return -1;
1084 *ptr++ = *plparam; /* Store previous lParam */
1085 *plparam = (LPARAM)ptr;
1090 /* Multiline edit */
1092 { WORD len = (WORD)*plparam;
1093 LPARAM *ptr = HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
1094 if (!ptr) return -1;
1095 *ptr++ = *plparam; /* Store previous lParam */
1096 *((WORD *) ptr) = len; /* Store the length */
1097 *plparam = (LPARAM)ptr;
1106 case WM_SYSDEADCHAR:
1107 case EM_SETPASSWORDCHAR:
1109 WCHAR wch = LOWORD(*pwparam);
1111 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL );
1112 *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
1118 WCHAR wch = LOWORD(*pwparam);
1121 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)ch, 2, NULL, NULL ) == 2)
1122 *pwparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(*pwparam) );
1124 *pwparam = MAKEWPARAM( ch[0], HIWORD(*pwparam) );
1128 case WM_PAINTCLIPBOARD:
1129 case WM_SIZECLIPBOARD:
1130 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg, hwnd),msg );
1132 default: /* No translation needed */
1138 /**********************************************************************
1139 * WINPROC_UnmapMsg32WTo32A
1141 * Unmap a message that was mapped from Unicode to Ansi.
1143 static LRESULT WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result )
1148 case WM_ASKCBFORMATNAME:
1150 LPARAM *ptr = (LPARAM *)lParam - 1;
1151 if (!wParam) result = 0;
1152 else if (!(result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1,
1153 (LPWSTR)*ptr, wParam )))
1155 ((LPWSTR)*ptr)[wParam-1] = 0;
1156 result = wParam - 1;
1158 else result--; /* do not count terminating null */
1159 HeapFree( GetProcessHeap(), 0, ptr );
1164 case WM_WININICHANGE:
1165 case WM_DEVMODECHANGE:
1170 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1175 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1176 if (HIWORD(cs->szTitle))
1177 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1178 if (HIWORD(cs->szClass))
1179 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1180 HeapFree( GetProcessHeap(), 0, cs );
1186 case LB_INSERTSTRING:
1188 case LB_FINDSTRINGEXACT:
1189 case LB_SELECTSTRING:
1190 if ( WINPROC_TestLBForStr( hwnd ))
1191 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1195 if ( WINPROC_TestLBForStr( hwnd ))
1197 LPARAM *ptr = (LPARAM *)lParam - 1;
1199 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
1200 HeapFree( GetProcessHeap(), 0, ptr );
1206 case CB_INSERTSTRING:
1208 case CB_FINDSTRINGEXACT:
1209 case CB_SELECTSTRING:
1210 if ( WINPROC_TestCBForStr( hwnd ))
1211 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1215 if ( result < 0) /* CB_ERR and CB_ERRSPACE */
1217 LPARAM *ptr = (LPARAM *)lParam - 1;
1218 HeapFree( GetProcessHeap(), 0, ptr );
1220 else if ( WINPROC_TestCBForStr( hwnd ))
1222 LPARAM *ptr = (LPARAM *)lParam - 1;
1223 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
1224 HeapFree( GetProcessHeap(), 0, ptr );
1228 /* Multiline edit */
1231 LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1232 WORD len = *(WORD *)ptr;
1235 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, result, (LPWSTR)*ptr, len );
1236 if (result < len) ((LPWSTR)*ptr)[result] = 0;
1238 HeapFree( GetProcessHeap(), 0, ptr );
1245 static UINT convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
1248 UINT sz = GlobalSize16(src);
1251 if (!(dst = GlobalAlloc(flags, sz)))
1253 ptr16 = GlobalLock16(src);
1254 ptr32 = GlobalLock(dst);
1255 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
1256 GlobalUnlock16(src);
1262 /**********************************************************************
1263 * WINPROC_MapMsg16To32A
1265 * Map a message from 16- to 32-bit Ansi.
1266 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1268 INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1269 WPARAM *pwparam32, LPARAM *plparam )
1271 *pmsg32 = (UINT)msg16;
1272 *pwparam32 = (WPARAM)wParam16;
1279 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1280 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1284 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1285 *plparam = (LPARAM)WIN_Handle32( HIWORD(*plparam) );
1288 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1289 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1290 *pwparam32 = (WPARAM)HDC_32(wParam16);
1291 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1293 case WM_COMPAREITEM:
1295 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1296 COMPAREITEMSTRUCT *cis = HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1297 if (!cis) return -1;
1298 cis->CtlType = cis16->CtlType;
1299 cis->CtlID = cis16->CtlID;
1300 cis->hwndItem = WIN_Handle32( cis16->hwndItem );
1301 cis->itemID1 = cis16->itemID1;
1302 cis->itemData1 = cis16->itemData1;
1303 cis->itemID2 = cis16->itemID2;
1304 cis->itemData2 = cis16->itemData2;
1305 cis->dwLocaleId = 0; /* FIXME */
1306 *plparam = (LPARAM)cis;
1311 PCOPYDATASTRUCT16 pcds16 = MapSL(*plparam);
1312 PCOPYDATASTRUCT pcds = HeapAlloc ( GetProcessHeap(), 0, sizeof(*pcds));
1313 pcds->dwData = pcds16->dwData;
1314 pcds->cbData = pcds16->cbData;
1315 pcds->lpData = MapSL( pcds16->lpData);
1316 *plparam = (LPARAM)pcds;
1321 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1322 DELETEITEMSTRUCT *dis = HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1323 if (!dis) return -1;
1324 dis->CtlType = dis16->CtlType;
1325 dis->CtlID = dis16->CtlID;
1326 dis->hwndItem = WIN_Handle32( dis16->hwndItem );
1327 dis->itemData = dis16->itemData;
1328 *plparam = (LPARAM)dis;
1331 case WM_MEASUREITEM:
1333 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1334 MEASUREITEMSTRUCT *mis = HeapAlloc(GetProcessHeap(), 0,
1335 sizeof(*mis) + sizeof(LPARAM));
1336 if (!mis) return -1;
1337 mis->CtlType = mis16->CtlType;
1338 mis->CtlID = mis16->CtlID;
1339 mis->itemID = mis16->itemID;
1340 mis->itemWidth = mis16->itemWidth;
1341 mis->itemHeight = mis16->itemHeight;
1342 mis->itemData = mis16->itemData;
1343 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1344 *plparam = (LPARAM)mis;
1349 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1350 DRAWITEMSTRUCT *dis = HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1351 if (!dis) return -1;
1352 dis->CtlType = dis16->CtlType;
1353 dis->CtlID = dis16->CtlID;
1354 dis->itemID = dis16->itemID;
1355 dis->itemAction = dis16->itemAction;
1356 dis->itemState = dis16->itemState;
1357 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1358 : WIN_Handle32( dis16->hwndItem );
1359 dis->hDC = HDC_32(dis16->hDC);
1360 dis->itemData = dis16->itemData;
1361 dis->rcItem.left = dis16->rcItem.left;
1362 dis->rcItem.top = dis16->rcItem.top;
1363 dis->rcItem.right = dis16->rcItem.right;
1364 dis->rcItem.bottom = dis16->rcItem.bottom;
1365 *plparam = (LPARAM)dis;
1368 case WM_GETMINMAXINFO:
1370 MINMAXINFO *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM));
1371 if (!mmi) return -1;
1372 MINMAXINFO16to32( MapSL(*plparam), mmi );
1373 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1374 *plparam = (LPARAM)mmi;
1379 case WM_WININICHANGE:
1380 case WM_DEVMODECHANGE:
1381 case WM_ASKCBFORMATNAME:
1382 *plparam = (LPARAM)MapSL(*plparam);
1386 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1387 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1389 MDICREATESTRUCT16to32A( cs16, cs );
1390 cs->szTitle = MapSL(cs16->szTitle);
1391 cs->szClass = MapSL(cs16->szClass);
1392 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1393 *plparam = (LPARAM)cs;
1396 case WM_MDIGETACTIVE:
1397 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1398 *(BOOL*)(*plparam) = 0;
1401 if(wParam16) *pmsg32=WM_MDIREFRESHMENU;
1402 *pwparam32 = (WPARAM)HMENU_32(LOWORD(*plparam));
1403 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1406 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1407 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1410 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1412 HMENU hmenu=HMENU_32(HIWORD(*plparam));
1413 UINT Pos=MENU_FindSubMenu( &hmenu, HMENU_32(wParam16));
1414 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1415 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1417 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1418 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1420 case WM_MDIACTIVATE:
1423 *pwparam32 = (WPARAM)WIN_Handle32( HIWORD(*plparam) );
1424 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1426 else /* message sent to MDI client */
1427 *pwparam32 = wParam16;
1431 NCCALCSIZE_PARAMS16 *nc16;
1432 NCCALCSIZE_PARAMS *nc;
1434 nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM) );
1436 nc16 = MapSL(*plparam);
1437 nc->rgrc[0].left = nc16->rgrc[0].left;
1438 nc->rgrc[0].top = nc16->rgrc[0].top;
1439 nc->rgrc[0].right = nc16->rgrc[0].right;
1440 nc->rgrc[0].bottom = nc16->rgrc[0].bottom;
1443 nc->lppos = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc->lppos) );
1444 nc->rgrc[1].left = nc16->rgrc[1].left;
1445 nc->rgrc[1].top = nc16->rgrc[1].top;
1446 nc->rgrc[1].right = nc16->rgrc[1].right;
1447 nc->rgrc[1].bottom = nc16->rgrc[1].bottom;
1448 nc->rgrc[2].left = nc16->rgrc[2].left;
1449 nc->rgrc[2].top = nc16->rgrc[2].top;
1450 nc->rgrc[2].right = nc16->rgrc[2].right;
1451 nc->rgrc[2].bottom = nc16->rgrc[2].bottom;
1452 if (nc->lppos) WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1454 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1455 *plparam = (LPARAM)nc;
1461 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1462 CREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1464 CREATESTRUCT16to32A( cs16, cs );
1465 cs->lpszName = MapSL(cs16->lpszName);
1466 cs->lpszClass = MapSL(cs16->lpszClass);
1468 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1470 MDICREATESTRUCT16 *mdi_cs16;
1471 MDICREATESTRUCTA *mdi_cs = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs));
1474 HeapFree(GetProcessHeap(), 0, cs);
1477 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1478 MDICREATESTRUCT16to32A(mdi_cs16, mdi_cs);
1479 mdi_cs->szTitle = MapSL(mdi_cs16->szTitle);
1480 mdi_cs->szClass = MapSL(mdi_cs16->szClass);
1482 cs->lpCreateParams = mdi_cs;
1484 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1485 *plparam = (LPARAM)cs;
1488 case WM_PARENTNOTIFY:
1489 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1491 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1492 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1495 case WM_WINDOWPOSCHANGING:
1496 case WM_WINDOWPOSCHANGED:
1498 WINDOWPOS *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
1500 WINDOWPOS16to32( MapSL(*plparam), wp );
1501 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1502 *plparam = (LPARAM)wp;
1508 LPMSG16 msg16 = MapSL(*plparam);
1509 LPMSG msg32 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1511 if (!msg32) return -1;
1512 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1513 msg32->lParam = msg16->lParam;
1514 msg32->time = msg16->time;
1515 msg32->pt.x = msg16->pt.x;
1516 msg32->pt.y = msg16->pt.y;
1517 /* this is right, right? */
1518 if (WINPROC_MapMsg16To32A( msg32->hwnd, msg16->message,msg16->wParam,
1519 &msg32->message,&msg32->wParam,
1520 &msg32->lParam)<0) {
1521 HeapFree( GetProcessHeap(), 0, msg32 );
1524 *plparam = (LPARAM)msg32;
1529 *plparam = (LPARAM)MapSL(*plparam);
1531 case WM_ACTIVATEAPP:
1532 /* We need this when SetActiveWindow sends a Sendmessage16() to
1533 * a 32bit window. Might be superflous with 32bit interprocess
1534 * message queues. */
1535 if (*plparam) *plparam = HTASK_32( *plparam );
1539 MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
1540 if (!next) return -1;
1541 next->hmenuIn = (HMENU)*plparam;
1542 next->hmenuNext = 0;
1544 *plparam = (LPARAM)next;
1547 case WM_PAINTCLIPBOARD:
1548 case WM_SIZECLIPBOARD:
1549 FIXME_(msg)("message %04x needs translation\n",msg16 );
1551 case WM_DDE_INITIATE:
1552 case WM_DDE_TERMINATE:
1553 case WM_DDE_UNADVISE:
1554 case WM_DDE_REQUEST:
1555 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1565 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1566 lo16 = LOWORD(*plparam);
1567 hi = HIWORD(*plparam);
1568 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE)))
1570 *plparam = PackDDElParam(msg16, lo32, hi);
1572 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1579 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1581 lo = LOWORD(*plparam);
1582 hi = HIWORD(*plparam);
1584 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1585 if (GlobalSize16(hi) != 0) flag |= 2;
1591 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1596 break; /* atom, nothing to do */
1598 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1601 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1604 *plparam = PackDDElParam(WM_DDE_ACK, lo, hi);
1606 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1607 case WM_DDE_EXECUTE:
1608 *plparam = convert_handle_16_to_32(*plparam, GMEM_DDESHARE);
1609 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1610 default: /* No translation needed */
1616 /**********************************************************************
1617 * WINPROC_UnmapMsg16To32A
1619 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1621 LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1626 case WM_COMPAREITEM:
1630 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1632 case WM_MEASUREITEM:
1634 MEASUREITEMSTRUCT16 *mis16;
1635 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1636 lParam = *(LPARAM *)(mis + 1);
1637 mis16 = MapSL(lParam);
1638 mis16->itemWidth = (UINT16)mis->itemWidth;
1639 mis16->itemHeight = (UINT16)mis->itemHeight;
1640 HeapFree( GetProcessHeap(), 0, mis );
1643 case WM_GETMINMAXINFO:
1645 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1646 lParam = *(LPARAM *)(mmi + 1);
1647 MINMAXINFO32to16( mmi, MapSL(lParam));
1648 HeapFree( GetProcessHeap(), 0, mmi );
1653 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1654 lParam = *(LPARAM *)(cs + 1);
1655 MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1656 HeapFree( GetProcessHeap(), 0, cs );
1659 case WM_MDIGETACTIVE:
1660 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1661 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1665 NCCALCSIZE_PARAMS16 *nc16;
1666 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1667 lParam = *(LPARAM *)(nc + 1);
1668 nc16 = MapSL(lParam);
1669 nc16->rgrc[0].left = nc->rgrc[0].left;
1670 nc16->rgrc[0].top = nc->rgrc[0].top;
1671 nc16->rgrc[0].right = nc->rgrc[0].right;
1672 nc16->rgrc[0].bottom = nc->rgrc[0].bottom;
1675 nc16->rgrc[1].left = nc->rgrc[1].left;
1676 nc16->rgrc[1].top = nc->rgrc[1].top;
1677 nc16->rgrc[1].right = nc->rgrc[1].right;
1678 nc16->rgrc[1].bottom = nc->rgrc[1].bottom;
1679 nc16->rgrc[2].left = nc->rgrc[2].left;
1680 nc16->rgrc[2].top = nc->rgrc[2].top;
1681 nc16->rgrc[2].right = nc->rgrc[2].right;
1682 nc16->rgrc[2].bottom = nc->rgrc[2].bottom;
1685 WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1686 HeapFree( GetProcessHeap(), 0, nc->lppos );
1689 HeapFree( GetProcessHeap(), 0, nc );
1695 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1696 lParam = *(LPARAM *)(cs + 1);
1697 CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1699 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1700 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1702 HeapFree( GetProcessHeap(), 0, cs );
1705 case WM_WINDOWPOSCHANGING:
1706 case WM_WINDOWPOSCHANGED:
1708 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1709 lParam = *(LPARAM *)(wp + 1);
1710 WINDOWPOS32to16(wp, MapSL(lParam));
1711 HeapFree( GetProcessHeap(), 0, wp );
1717 LPMSG msg32 = (LPMSG)lParam;
1719 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1721 HeapFree( GetProcessHeap(), 0, msg32 );
1726 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1727 result = MAKELONG( HMENU_16(next->hmenuNext), HWND_16(next->hwndNext) );
1728 HeapFree( GetProcessHeap(), 0, next );
1736 /**********************************************************************
1737 * WINPROC_MapMsg16To32W
1739 * Map a message from 16- to 32-bit Unicode.
1740 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1742 INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1743 WPARAM *pwparam32, LPARAM *plparam )
1748 *pmsg32=(UINT)msg16;
1749 *pwparam32 = (WPARAM)wParam16;
1754 case WM_WININICHANGE:
1755 case WM_DEVMODECHANGE:
1756 case WM_ASKCBFORMATNAME:
1757 *plparam = (LPARAM)MapSL(*plparam);
1758 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1759 case WM_GETTEXTLENGTH:
1760 case CB_GETLBTEXTLEN:
1762 return 1; /* need to map result */
1766 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1767 CREATESTRUCTW *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1769 CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1770 cs->lpszName = map_str_16_to_32W(cs16->lpszName);
1771 cs->lpszClass = map_str_16_to_32W(cs16->lpszClass);
1773 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1775 MDICREATESTRUCT16 *mdi_cs16;
1776 MDICREATESTRUCTW *mdi_cs = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs));
1779 HeapFree(GetProcessHeap(), 0, cs);
1782 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1783 MDICREATESTRUCT16to32A(mdi_cs16, (MDICREATESTRUCTA *)mdi_cs);
1784 mdi_cs->szTitle = map_str_16_to_32W(mdi_cs16->szTitle);
1785 mdi_cs->szClass = map_str_16_to_32W(mdi_cs16->szClass);
1787 cs->lpCreateParams = mdi_cs;
1789 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1790 *plparam = (LPARAM)cs;
1795 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1796 MDICREATESTRUCTW *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1798 MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1799 cs->szTitle = map_str_16_to_32W(cs16->szTitle);
1800 cs->szClass = map_str_16_to_32W(cs16->szClass);
1801 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1802 *plparam = (LPARAM)cs;
1808 LPMSG16 msg16 = MapSL(*plparam);
1809 LPMSG msg32 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1811 if (!msg32) return -1;
1812 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1813 msg32->lParam = msg16->lParam;
1814 msg32->time = msg16->time;
1815 msg32->pt.x = msg16->pt.x;
1816 msg32->pt.y = msg16->pt.y;
1817 /* this is right, right? */
1818 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1819 &msg32->message,&msg32->wParam,
1820 &msg32->lParam)<0) {
1821 HeapFree( GetProcessHeap(), 0, msg32 );
1824 *plparam = (LPARAM)msg32;
1831 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1832 *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
1833 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1837 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1838 *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
1839 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1844 case WM_SYSDEADCHAR:
1846 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1850 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1852 default: /* No Unicode translation needed */
1853 return WINPROC_MapMsg16To32A( hwnd, msg16, wParam16, pmsg32,
1854 pwparam32, plparam );
1859 /**********************************************************************
1860 * WINPROC_UnmapMsg16To32W
1862 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1864 LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1865 LRESULT result, WNDPROC dispatch )
1871 case WM_GETTEXTLENGTH:
1872 case CB_GETLBTEXTLEN:
1874 case WM_ASKCBFORMATNAME:
1875 return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result, dispatch );
1879 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1880 lParam = *(LPARAM *)(cs + 1);
1881 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1882 unmap_str_16_to_32W( cs->lpszName );
1883 unmap_str_16_to_32W( cs->lpszClass );
1885 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1887 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs->lpCreateParams;
1888 unmap_str_16_to_32W( mdi_cs->szTitle );
1889 unmap_str_16_to_32W( mdi_cs->szClass );
1890 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1892 HeapFree( GetProcessHeap(), 0, cs );
1897 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1898 lParam = *(LPARAM *)(cs + 1);
1899 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1900 unmap_str_16_to_32W( cs->szTitle );
1901 unmap_str_16_to_32W( cs->szClass );
1902 HeapFree( GetProcessHeap(), 0, cs );
1908 LPMSG msg32 = (LPMSG)lParam;
1910 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1912 HeapFree( GetProcessHeap(), 0, msg32 );
1916 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1921 static HANDLE16 convert_handle_32_to_16(UINT src, unsigned int flags)
1924 UINT sz = GlobalSize((HANDLE)src);
1927 if (!(dst = GlobalAlloc16(flags, sz)))
1929 ptr32 = GlobalLock((HANDLE)src);
1930 ptr16 = GlobalLock16(dst);
1931 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
1932 GlobalUnlock((HANDLE)src);
1933 GlobalUnlock16(dst);
1939 /**********************************************************************
1940 * WINPROC_MapMsg32ATo16
1942 * Map a message from 32-bit Ansi to 16-bit.
1943 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1945 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1946 UINT16 *pmsg16, WPARAM16 *pwparam16,
1949 *pmsg16 = (UINT16)msg32;
1950 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1954 *pmsg16 = SBM_SETRANGE16;
1955 *plparam = MAKELPARAM(wParam32, *plparam);
1960 *pmsg16 = SBM_GETRANGE16;
1968 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1977 case EM_SCROLLCARET:
1980 case EM_GETLINECOUNT:
1992 case EM_LINEFROMCHAR:
1993 case EM_SETTABSTOPS:
1994 case EM_SETPASSWORDCHAR:
1995 case EM_EMPTYUNDOBUFFER:
1996 case EM_GETFIRSTVISIBLELINE:
1997 case EM_SETREADONLY:
1998 case EM_SETWORDBREAKPROC:
1999 case EM_GETWORDBREAKPROC:
2000 case EM_GETPASSWORDCHAR:
2001 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
2006 case LB_DELETESTRING:
2007 case LB_GETANCHORINDEX:
2008 case LB_GETCARETINDEX:
2011 case LB_GETHORIZONTALEXTENT:
2012 case LB_GETITEMDATA:
2013 case LB_GETITEMHEIGHT:
2015 case LB_GETSELCOUNT:
2017 case LB_GETTOPINDEX:
2018 case LB_RESETCONTENT:
2019 case LB_SELITEMRANGE:
2020 case LB_SELITEMRANGEEX:
2021 case LB_SETANCHORINDEX:
2022 case LB_SETCARETINDEX:
2023 case LB_SETCOLUMNWIDTH:
2025 case LB_SETHORIZONTALEXTENT:
2026 case LB_SETITEMDATA:
2027 case LB_SETITEMHEIGHT:
2029 case LB_SETTOPINDEX:
2030 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2032 case CB_DELETESTRING:
2034 case CB_GETLBTEXTLEN:
2036 case CB_RESETCONTENT:
2040 case CB_SHOWDROPDOWN:
2041 case CB_SETITEMDATA:
2042 case CB_SETITEMHEIGHT:
2043 case CB_GETITEMHEIGHT:
2044 case CB_SETEXTENDEDUI:
2045 case CB_GETEXTENDEDUI:
2046 case CB_GETDROPPEDSTATE:
2047 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
2050 *pmsg16 = CB_GETEDITSEL16;
2055 case LB_FINDSTRINGEXACT:
2056 case LB_INSERTSTRING:
2057 case LB_SELECTSTRING:
2060 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
2061 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2066 case CB_FINDSTRINGEXACT:
2067 case CB_INSERTSTRING:
2068 case CB_SELECTSTRING:
2070 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
2071 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
2074 case LB_GETITEMRECT:
2076 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
2077 if (!rect) return -1;
2078 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
2079 *plparam = MapLS( rect );
2081 *pmsg16 = LB_GETITEMRECT16;
2083 case LB_GETSELITEMS:
2085 LPARAM *items; /* old LPARAM first, then *pwparam16 x INT16 entries */
2087 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
2088 if (!(items = HeapAlloc( GetProcessHeap(), 0,
2089 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
2090 *items++ = *plparam; /* Store the previous lParam */
2091 *plparam = MapLS( items );
2093 *pmsg16 = LB_GETSELITEMS16;
2095 case LB_SETTABSTOPS:
2100 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
2101 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
2102 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
2103 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
2104 *plparam = MapLS( stops );
2107 *pmsg16 = LB_SETTABSTOPS16;
2110 case CB_GETDROPPEDCONTROLRECT:
2112 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
2113 if (!rect) return -1;
2114 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
2115 *plparam = (LPARAM)MapLS(rect);
2117 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
2121 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
2122 *pmsg16 = LB_GETTEXT16;
2126 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
2127 *pmsg16 = CB_GETLBTEXT16;
2132 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
2133 *pmsg16 = EM_SETSEL16;
2140 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2144 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
2148 PCOPYDATASTRUCT pcds32 = (PCOPYDATASTRUCT) *plparam;
2149 PCOPYDATASTRUCT16 pcds = HeapAlloc( GetProcessHeap(), 0, sizeof( *pcds));
2150 pcds->dwData = pcds32->dwData;
2151 pcds->cbData = pcds32->cbData;
2152 pcds->lpData = MapLS( pcds32->lpData);
2153 *plparam = MapLS( pcds );
2156 case WM_CTLCOLORMSGBOX:
2157 case WM_CTLCOLOREDIT:
2158 case WM_CTLCOLORLISTBOX:
2159 case WM_CTLCOLORBTN:
2160 case WM_CTLCOLORDLG:
2161 case WM_CTLCOLORSCROLLBAR:
2162 case WM_CTLCOLORSTATIC:
2163 *pmsg16 = WM_CTLCOLOR;
2164 *plparam = MAKELPARAM( (HWND16)*plparam,
2165 (WORD)msg32 - WM_CTLCOLORMSGBOX );
2167 case WM_COMPAREITEM:
2169 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
2170 COMPAREITEMSTRUCT16 *cis = HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16));
2171 if (!cis) return -1;
2172 cis->CtlType = (UINT16)cis32->CtlType;
2173 cis->CtlID = (UINT16)cis32->CtlID;
2174 cis->hwndItem = HWND_16( cis32->hwndItem );
2175 cis->itemID1 = (UINT16)cis32->itemID1;
2176 cis->itemData1 = cis32->itemData1;
2177 cis->itemID2 = (UINT16)cis32->itemID2;
2178 cis->itemData2 = cis32->itemData2;
2179 *plparam = MapLS( cis );
2184 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
2185 DELETEITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16) );
2186 if (!dis) return -1;
2187 dis->CtlType = (UINT16)dis32->CtlType;
2188 dis->CtlID = (UINT16)dis32->CtlID;
2189 dis->itemID = (UINT16)dis32->itemID;
2190 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
2191 : HWND_16( dis32->hwndItem );
2192 dis->itemData = dis32->itemData;
2193 *plparam = MapLS( dis );
2198 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
2199 DRAWITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16) );
2200 if (!dis) return -1;
2201 dis->CtlType = (UINT16)dis32->CtlType;
2202 dis->CtlID = (UINT16)dis32->CtlID;
2203 dis->itemID = (UINT16)dis32->itemID;
2204 dis->itemAction = (UINT16)dis32->itemAction;
2205 dis->itemState = (UINT16)dis32->itemState;
2206 dis->hwndItem = HWND_16( dis32->hwndItem );
2207 dis->hDC = HDC_16(dis32->hDC);
2208 dis->itemData = dis32->itemData;
2209 dis->rcItem.left = dis32->rcItem.left;
2210 dis->rcItem.top = dis32->rcItem.top;
2211 dis->rcItem.right = dis32->rcItem.right;
2212 dis->rcItem.bottom = dis32->rcItem.bottom;
2213 *plparam = MapLS( dis );
2216 case WM_MEASUREITEM:
2218 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
2219 MEASUREITEMSTRUCT16 *mis = HeapAlloc( GetProcessHeap(), 0, sizeof(*mis)+sizeof(LPARAM));
2220 if (!mis) return -1;
2221 mis->CtlType = (UINT16)mis32->CtlType;
2222 mis->CtlID = (UINT16)mis32->CtlID;
2223 mis->itemID = (UINT16)mis32->itemID;
2224 mis->itemWidth = (UINT16)mis32->itemWidth;
2225 mis->itemHeight = (UINT16)mis32->itemHeight;
2226 mis->itemData = mis32->itemData;
2227 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
2228 *plparam = MapLS( mis );
2231 case WM_GETMINMAXINFO:
2233 MINMAXINFO16 *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM) );
2234 if (!mmi) return -1;
2235 MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
2236 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
2237 *plparam = MapLS( mmi );
2241 case WM_ASKCBFORMATNAME:
2243 LPARAM *str; /* store LPARAM, then *pwparam16 char space */
2244 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
2245 if (!(str = HeapAlloc( GetProcessHeap(), 0, *pwparam16 + sizeof(LPARAM)))) return -1;
2246 *str++ = *plparam; /* Store the previous lParam */
2247 *plparam = MapLS( str );
2252 MDICREATESTRUCT16 *cs;
2253 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
2255 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2256 MDICREATESTRUCT32Ato16( cs32, cs );
2257 cs->szTitle = MapLS( cs32->szTitle );
2258 cs->szClass = MapLS( cs32->szClass );
2259 *plparam = MapLS( cs );
2262 case WM_MDIGETACTIVE:
2265 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
2266 (HMENU16)LOWORD(*plparam) );
2267 *pwparam16 = (*plparam == 0);
2270 if(HIWORD(wParam32) & MF_POPUP)
2273 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
2275 if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
2276 *pwparam16=HMENU_16(hmenu);
2281 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2283 case WM_MDIACTIVATE:
2284 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
2286 *pwparam16 = ((HWND)*plparam == hwnd);
2287 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
2288 (HWND16)LOWORD(wParam32) );
2292 *pwparam16 = HWND_16( (HWND)wParam32 );
2298 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
2299 NCCALCSIZE_PARAMS16 *nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM));
2302 nc->rgrc[0].left = nc32->rgrc[0].left;
2303 nc->rgrc[0].top = nc32->rgrc[0].top;
2304 nc->rgrc[0].right = nc32->rgrc[0].right;
2305 nc->rgrc[0].bottom = nc32->rgrc[0].bottom;
2309 nc->rgrc[1].left = nc32->rgrc[1].left;
2310 nc->rgrc[1].top = nc32->rgrc[1].top;
2311 nc->rgrc[1].right = nc32->rgrc[1].right;
2312 nc->rgrc[1].bottom = nc32->rgrc[1].bottom;
2313 nc->rgrc[2].left = nc32->rgrc[2].left;
2314 nc->rgrc[2].top = nc32->rgrc[2].top;
2315 nc->rgrc[2].right = nc32->rgrc[2].right;
2316 nc->rgrc[2].bottom = nc32->rgrc[2].bottom;
2317 if (!(wp = HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16) )))
2319 HeapFree( GetProcessHeap(), 0, nc );
2322 WINDOWPOS32to16( nc32->lppos, wp );
2323 nc->lppos = MapLS( wp );
2325 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
2326 *plparam = MapLS( nc );
2333 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
2335 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2336 CREATESTRUCT32Ato16( cs32, cs );
2337 cs->lpszName = MapLS( cs32->lpszName );
2338 cs->lpszClass = MapLS( cs32->lpszClass );
2340 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2342 MDICREATESTRUCT16 *mdi_cs16;
2343 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
2344 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2347 HeapFree(GetProcessHeap(), 0, cs);
2350 MDICREATESTRUCT32Ato16(mdi_cs, mdi_cs16);
2351 mdi_cs16->szTitle = MapLS( mdi_cs->szTitle );
2352 mdi_cs16->szClass = MapLS( mdi_cs->szClass );
2353 cs->lpCreateParams = MapLS( mdi_cs16 );
2355 *plparam = MapLS( cs );
2358 case WM_PARENTNOTIFY:
2359 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
2360 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
2361 /* else nothing to do */
2364 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
2367 case WM_WININICHANGE:
2368 case WM_DEVMODECHANGE:
2369 *plparam = MapLS( (LPSTR)*plparam );
2371 case WM_WINDOWPOSCHANGING:
2372 case WM_WINDOWPOSCHANGED:
2374 WINDOWPOS16 *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
2376 WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2377 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2378 *plparam = MapLS( wp );
2383 LPMSG msg32 = (LPMSG) *plparam;
2384 LPMSG16 msg16 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16) );
2386 if (!msg16) return -1;
2387 msg16->hwnd = HWND_16( msg32->hwnd );
2388 msg16->lParam = msg32->lParam;
2389 msg16->time = msg32->time;
2390 msg16->pt.x = msg32->pt.x;
2391 msg16->pt.y = msg32->pt.y;
2392 /* this is right, right? */
2393 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2394 &msg16->message,&msg16->wParam, &msg16->lParam)<0)
2396 HeapFree( GetProcessHeap(), 0, msg16 );
2399 *plparam = MapLS( msg16 );
2404 case WM_ACTIVATEAPP:
2405 if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
2409 MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
2410 *plparam = (LPARAM)next->hmenuIn;
2414 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
2416 *pmsg16 = WM_PAINTICON;
2421 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
2422 *pmsg16 = WM_ICONERASEBKGND;
2424 case WM_PAINTCLIPBOARD:
2425 case WM_SIZECLIPBOARD:
2426 FIXME_(msg)("message %04x needs translation\n", msg32 );
2428 /* following messages should not be sent to 16-bit apps */
2431 case WM_CAPTURECHANGED:
2432 case WM_STYLECHANGING:
2433 case WM_STYLECHANGED:
2435 case WM_DDE_INITIATE:
2436 case WM_DDE_TERMINATE:
2437 case WM_DDE_UNADVISE:
2438 case WM_DDE_REQUEST:
2439 *pwparam16 = HWND_16((HWND)wParam32);
2448 *pwparam16 = HWND_16((HWND)wParam32);
2449 UnpackDDElParam(msg32, *plparam, &lo32, &hi);
2450 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE)))
2452 *plparam = MAKELPARAM(lo16, hi);
2454 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2461 *pwparam16 = HWND_16((HWND)wParam32);
2463 UnpackDDElParam(msg32, *plparam, &lo, &hi);
2465 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
2466 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
2472 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2477 break; /* atom, nothing to do */
2479 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
2482 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
2485 *plparam = MAKELPARAM(lo, hi);
2487 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2488 case WM_DDE_EXECUTE:
2489 *plparam = convert_handle_32_to_16(*plparam, GMEM_DDESHARE);
2490 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2491 default: /* No translation needed */
2497 /**********************************************************************
2498 * WINPROC_UnmapMsg32ATo16
2500 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2502 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2508 *(LPINT)wParam = LOWORD(p16->lResult);
2509 *(LPINT)lParam = HIWORD(p16->lResult);
2516 case LB_FINDSTRINGEXACT:
2517 case LB_INSERTSTRING:
2518 case LB_SELECTSTRING:
2522 case CB_FINDSTRINGEXACT:
2523 case CB_INSERTSTRING:
2524 case CB_SELECTSTRING:
2528 case WM_WININICHANGE:
2529 case WM_DEVMODECHANGE:
2530 UnMapLS( (SEGPTR)p16->lParam );
2532 case LB_SETTABSTOPS:
2533 case WM_COMPAREITEM:
2537 void *ptr = MapSL( p16->lParam );
2538 UnMapLS( p16->lParam );
2539 HeapFree( GetProcessHeap(), 0, ptr );
2544 PCOPYDATASTRUCT16 pcds = MapSL( p16->lParam );
2545 UnMapLS( p16->lParam );
2546 UnMapLS( pcds->lpData );
2547 HeapFree( GetProcessHeap(), 0, pcds );
2550 case CB_GETDROPPEDCONTROLRECT:
2551 case LB_GETITEMRECT:
2554 RECT16 *rect = MapSL(p16->lParam);
2555 UnMapLS( p16->lParam );
2556 p16->lParam = *(LPARAM *)(rect + 1);
2557 r32 = (RECT *)p16->lParam;
2558 r32->left = rect->left;
2559 r32->top = rect->top;
2560 r32->right = rect->right;
2561 r32->bottom = rect->bottom;
2562 HeapFree( GetProcessHeap(), 0, rect );
2565 case LB_GETSELITEMS:
2568 LPINT16 items = MapSL(p16->lParam);
2569 UnMapLS( p16->lParam );
2570 p16->lParam = *((LPARAM *)items - 1);
2571 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2572 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
2578 *((PUINT)(wParam)) = LOWORD(p16->lResult);
2580 *((PUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2583 case WM_MEASUREITEM:
2585 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2586 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2587 mis32->itemWidth = mis->itemWidth;
2588 mis32->itemHeight = mis->itemHeight;
2589 UnMapLS( p16->lParam );
2590 HeapFree( GetProcessHeap(), 0, mis );
2593 case WM_GETMINMAXINFO:
2595 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2596 UnMapLS( p16->lParam );
2597 p16->lParam = *(LPARAM *)(mmi + 1);
2598 MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2599 HeapFree( GetProcessHeap(), 0, mmi );
2603 case WM_ASKCBFORMATNAME:
2605 LPSTR str = MapSL(p16->lParam);
2606 UnMapLS( p16->lParam );
2607 p16->lParam = *((LPARAM *)str - 1);
2608 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2609 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2614 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2615 UnMapLS( cs->szTitle );
2616 UnMapLS( cs->szClass );
2617 UnMapLS( p16->lParam );
2618 HeapFree( GetProcessHeap(), 0, cs );
2621 case WM_MDIGETACTIVE:
2622 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2623 p16->lResult = (LRESULT)WIN_Handle32( LOWORD(p16->lResult) );
2627 NCCALCSIZE_PARAMS *nc32;
2628 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2629 UnMapLS( p16->lParam );
2630 p16->lParam = *(LPARAM *)(nc + 1);
2631 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2632 nc32->rgrc[0].left = nc->rgrc[0].left;
2633 nc32->rgrc[0].top = nc->rgrc[0].top;
2634 nc32->rgrc[0].right = nc->rgrc[0].right;
2635 nc32->rgrc[0].bottom = nc->rgrc[0].bottom;
2638 WINDOWPOS16 *pos = MapSL(nc->lppos);
2639 UnMapLS( nc->lppos );
2640 nc32->rgrc[1].left = nc->rgrc[1].left;
2641 nc32->rgrc[1].top = nc->rgrc[1].top;
2642 nc32->rgrc[1].right = nc->rgrc[1].right;
2643 nc32->rgrc[1].bottom = nc->rgrc[1].bottom;
2644 nc32->rgrc[2].left = nc->rgrc[2].left;
2645 nc32->rgrc[2].top = nc->rgrc[2].top;
2646 nc32->rgrc[2].right = nc->rgrc[2].right;
2647 nc32->rgrc[2].bottom = nc->rgrc[2].bottom;
2648 WINDOWPOS16to32( pos, nc32->lppos );
2649 HeapFree( GetProcessHeap(), 0, pos );
2651 HeapFree( GetProcessHeap(), 0, nc );
2657 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2658 UnMapLS( p16->lParam );
2659 UnMapLS( cs->lpszName );
2660 UnMapLS( cs->lpszClass );
2661 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2663 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2664 UnMapLS( cs->lpCreateParams );
2665 UnMapLS( mdi_cs16->szTitle );
2666 UnMapLS( mdi_cs16->szClass );
2667 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2669 HeapFree( GetProcessHeap(), 0, cs );
2672 case WM_WINDOWPOSCHANGING:
2673 case WM_WINDOWPOSCHANGED:
2675 WINDOWPOS16 *wp = MapSL(p16->lParam);
2676 UnMapLS( p16->lParam );
2677 p16->lParam = *(LPARAM *)(wp + 1);
2678 WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2679 HeapFree( GetProcessHeap(), 0, wp );
2683 UnMapLS(p16->lParam);
2688 LPMSG16 msg16 = MapSL(p16->lParam);
2690 UnMapLS( p16->lParam );
2691 msgp16.wParam=msg16->wParam;
2692 msgp16.lParam=msg16->lParam;
2693 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2694 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2696 HeapFree( GetProcessHeap(), 0, msg16 );
2701 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2702 next->hmenuNext = HMENU_32( LOWORD(p16->lResult) );
2703 next->hwndNext = WIN_Handle32( HIWORD(p16->lResult) );
2711 /**********************************************************************
2712 * WINPROC_MapMsg32WTo16
2714 * Map a message from 32-bit Unicode to 16-bit.
2715 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2717 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2718 UINT16 *pmsg16, WPARAM16 *pwparam16,
2724 *pmsg16 = LOWORD(msg32);
2725 *pwparam16 = LOWORD(wParam32);
2730 case LB_FINDSTRINGEXACT:
2731 case LB_INSERTSTRING:
2732 case LB_SELECTSTRING:
2735 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2736 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2741 case CB_FINDSTRINGEXACT:
2742 case CB_INSERTSTRING:
2743 case CB_SELECTSTRING:
2745 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2746 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2753 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2755 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2756 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2757 cs->lpszName = map_str_32W_to_16( cs32->lpszName );
2758 cs->lpszClass = map_str_32W_to_16( cs32->lpszClass );
2760 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2762 MDICREATESTRUCT16 *mdi_cs16;
2763 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs32->lpCreateParams;
2764 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2767 HeapFree(GetProcessHeap(), 0, cs);
2770 MDICREATESTRUCT32Ato16((MDICREATESTRUCTA *)mdi_cs, mdi_cs16);
2771 mdi_cs16->szTitle = map_str_32W_to_16(mdi_cs->szTitle);
2772 mdi_cs16->szClass = map_str_32W_to_16(mdi_cs->szClass);
2773 cs->lpCreateParams = MapLS(mdi_cs16);
2775 *plparam = MapLS(cs);
2780 MDICREATESTRUCT16 *cs;
2781 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2783 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2784 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2785 cs->szTitle = map_str_32W_to_16( cs32->szTitle );
2786 cs->szClass = map_str_32W_to_16( cs32->szClass );
2787 *plparam = MapLS(cs);
2791 case WM_WININICHANGE:
2792 case WM_DEVMODECHANGE:
2793 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2796 if ( WINPROC_TestLBForStr( hwnd ))
2798 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 512 ); /* FIXME: fixed sized buffer */
2799 if (!str) return -1;
2800 *pmsg16 = LB_GETTEXT16;
2801 *plparam = (LPARAM)MapLS(str);
2805 if ( WINPROC_TestCBForStr( hwnd ))
2807 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 512 ); /* FIXME: fixed sized buffer */
2808 if (!str) return -1;
2809 *pmsg16 = CB_GETLBTEXT16;
2810 *plparam = (LPARAM)MapLS(str);
2815 wch = LOWORD(wParam32);
2816 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL);
2818 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2821 wch = LOWORD(wParam32);
2822 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL);
2824 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2829 case WM_SYSDEADCHAR:
2831 WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)&ch, 1, NULL, NULL);
2839 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, (LPSTR)ch, 2, NULL, NULL ) == 2)
2840 *pwparam16 = (ch[0] << 8) | ch[1];
2846 default: /* No Unicode translation needed (?) */
2847 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2848 pwparam16, plparam );
2853 /**********************************************************************
2854 * WINPROC_UnmapMsg32WTo16
2856 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2858 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2865 case LB_FINDSTRINGEXACT:
2866 case LB_INSERTSTRING:
2867 case LB_SELECTSTRING:
2872 case CB_FINDSTRINGEXACT:
2873 case CB_INSERTSTRING:
2874 case CB_SELECTSTRING:
2877 case WM_WININICHANGE:
2878 case WM_DEVMODECHANGE:
2879 unmap_str_32W_to_16( p16->lParam );
2884 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2885 UnMapLS( p16->lParam );
2886 unmap_str_32W_to_16( cs->lpszName );
2887 unmap_str_32W_to_16( cs->lpszClass );
2889 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2891 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2892 UnMapLS( cs->lpCreateParams );
2893 unmap_str_32W_to_16(mdi_cs16->szTitle);
2894 unmap_str_32W_to_16(mdi_cs16->szClass);
2895 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2897 HeapFree( GetProcessHeap(), 0, cs );
2902 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2903 UnMapLS( p16->lParam );
2904 unmap_str_32W_to_16( cs->szTitle );
2905 unmap_str_32W_to_16( cs->szClass );
2906 HeapFree( GetProcessHeap(), 0, cs );
2910 case WM_ASKCBFORMATNAME:
2912 LPSTR str = MapSL(p16->lParam);
2913 UnMapLS( p16->lParam );
2914 p16->lParam = *((LPARAM *)str - 1);
2915 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2916 p16->lResult = strlenW( (LPWSTR)p16->lParam );
2917 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2921 if ( WINPROC_TestLBForStr( hwnd ))
2923 LPSTR str = MapSL(p16->lParam);
2924 UnMapLS( p16->lParam );
2925 p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
2926 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2930 if ( WINPROC_TestCBForStr( hwnd ))
2932 LPSTR str = MapSL(p16->lParam);
2933 UnMapLS( p16->lParam );
2934 p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
2935 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2939 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2945 /**********************************************************************
2946 * WINPROC_CallProc32ATo32W
2948 * Call a window procedure, translating args from Ansi to Unicode.
2950 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2951 UINT msg, WPARAM wParam,
2957 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2958 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2960 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2961 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2962 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2965 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2966 if (unmap) result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result, func );
2971 /**********************************************************************
2972 * WINPROC_CallProc32WTo32A_fast
2975 static BOOL WINPROC_CallProc32WTo32A_fast( WNDPROC func, HWND hwnd,
2976 UINT msg, WPARAM wParam,
2977 LPARAM lParam, LRESULT *result )
2983 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
2987 char *cls = buffer, *name;
2988 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
2989 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
2990 MDICREATESTRUCTA mdi_cs;
2991 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
2993 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
2994 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
2998 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
2999 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
3002 name_lenW = name_lenA = 0;
3004 if (class_lenA + name_lenA + 2 > sizeof(buffer))
3006 cls = HeapAlloc(GetProcessHeap(), 0, class_lenA + name_lenA + 2);
3007 if (!cls) return FALSE;
3010 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
3011 cls[class_lenA] = 0;
3012 csA.lpszClass = cls;
3016 name = cls + class_lenA + 1;
3017 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
3018 name[name_lenA] = 0;
3019 csA.lpszName = name;
3022 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
3024 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
3025 mdi_cs.szTitle = csA.lpszName;
3026 mdi_cs.szClass = csA.lpszClass;
3027 csA.lpCreateParams = &mdi_cs;
3030 lParam = (LPARAM)&csA;
3031 *result = WINPROC_CallWndProc(func, hwnd, msg, wParam, lParam);
3033 if (cls != buffer) HeapFree(GetProcessHeap(), 0, cls);
3042 /**********************************************************************
3043 * WINPROC_CallProc32WTo32A
3045 * Call a window procedure, translating args from Unicode to Ansi.
3047 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
3048 UINT msg, WPARAM wParam,
3054 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3055 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3057 if (WINPROC_CallProc32WTo32A_fast( func, hwnd, msg, wParam, lParam, &result ))
3060 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
3061 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
3062 SPY_GetMsgName(msg, hwnd), wParam, lParam );
3065 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3066 if( unmap ) result = WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam, result );
3071 /**********************************************************************
3072 * __wine_call_wndproc_32A (USER.1010)
3074 LRESULT WINAPI __wine_call_wndproc_32A( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
3080 HWND hwnd32 = WIN_Handle32( hwnd );
3082 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3083 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
3085 if (WINPROC_MapMsg16To32A( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
3087 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
3088 return WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, result );
3092 /**********************************************************************
3093 * __wine_call_wndproc_32W (USER.1011)
3095 LRESULT WINAPI __wine_call_wndproc_32W( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
3101 HWND hwnd32 = WIN_Handle32( hwnd );
3103 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3104 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
3106 if (WINPROC_MapMsg16To32W( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
3108 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
3109 return WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, result,
3114 /**********************************************************************
3115 * WINPROC_CallProc32ATo16
3117 * Call a 16-bit window procedure, translating the 32-bit args.
3119 static LRESULT WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
3120 UINT msg, WPARAM wParam, LPARAM lParam )
3125 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3126 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3128 mp16.lParam = lParam;
3129 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
3131 mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
3132 mp16.wParam, mp16.lParam );
3133 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
3134 return mp16.lResult;
3138 /**********************************************************************
3139 * WINPROC_CallProc32WTo16
3141 * Call a 16-bit window procedure, translating the 32-bit args.
3143 static LRESULT WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
3144 UINT msg, WPARAM wParam, LPARAM lParam )
3149 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3150 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3152 mp16.lParam = lParam;
3153 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
3154 &mp16.lParam ) == -1)
3156 mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
3157 mp16.wParam, mp16.lParam );
3158 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
3159 return mp16.lResult;
3163 /**********************************************************************
3164 * CallWindowProc (USER.122)
3166 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
3167 WPARAM16 wParam, LPARAM lParam )
3171 if (!func) return 0;
3173 if (!(proc = handle16_to_proc( func )))
3174 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
3179 return WINPROC_CallWndProc16( proc->proc16, hwnd, msg, wParam, lParam );
3181 return __wine_call_wndproc_32A( hwnd, msg, wParam, lParam, proc->thunk.proc );
3183 return __wine_call_wndproc_32W( hwnd, msg, wParam, lParam, proc->thunk.proc );
3185 WARN_(relay)("Invalid proc %p\n", proc );
3191 /**********************************************************************
3192 * CallWindowProcA (USER32.@)
3194 * The CallWindowProc() function invokes the windows procedure _func_,
3195 * with _hwnd_ as the target window, the message specified by _msg_, and
3196 * the message parameters _wParam_ and _lParam_.
3198 * Some kinds of argument conversion may be done, I'm not sure what.
3200 * CallWindowProc() may be used for windows subclassing. Use
3201 * SetWindowLong() to set a new windows procedure for windows of the
3202 * subclass, and handle subclassed messages in the new windows
3203 * procedure. The new windows procedure may then use CallWindowProc()
3204 * with _func_ set to the parent class's windows procedure to dispatch
3205 * the message to the superclass.
3209 * The return value is message dependent.
3215 LRESULT WINAPI CallWindowProcA(
3216 WNDPROC func, /* [in] window procedure */
3217 HWND hwnd, /* [in] target window */
3218 UINT msg, /* [in] message */
3219 WPARAM wParam, /* [in] message dependent parameter */
3220 LPARAM lParam /* [in] message dependent parameter */
3224 if (!func) return 0;
3226 if (!(proc = handle_to_proc( func )))
3227 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3232 return WINPROC_CallProc32ATo16( proc->proc16, hwnd, msg, wParam, lParam );
3234 return WINPROC_CallWndProc( proc->thunk.proc, hwnd, msg, wParam, lParam );
3236 return WINPROC_CallProc32ATo32W( proc->thunk.proc, hwnd, msg, wParam, lParam );
3238 WARN_(relay)("Invalid proc %p\n", proc );
3244 /**********************************************************************
3245 * CallWindowProcW (USER32.@)
3247 * See CallWindowProcA.
3249 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
3250 WPARAM wParam, LPARAM lParam )
3254 if (!func) return 0;
3256 if (!(proc = handle_to_proc( func )))
3257 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3262 return WINPROC_CallProc32WTo16( proc->proc16, hwnd, msg, wParam, lParam );
3264 return WINPROC_CallProc32WTo32A( proc->thunk.proc, hwnd, msg, wParam, lParam );
3266 return WINPROC_CallWndProc( proc->thunk.proc, hwnd, msg, wParam, lParam );
3268 WARN_(relay)("Invalid proc %p\n", proc );
3274 /**********************************************************************
3275 * WINPROC_CallDlgProc16
3277 INT_PTR WINPROC_CallDlgProc16( DLGPROC16 func, HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
3281 if (!func) return 0;
3283 if (!(proc = handle16_to_proc( (WNDPROC16)func )))
3284 return LOWORD( WINPROC_CallWndProc16( (WNDPROC16)func, hwnd, msg, wParam, lParam ) );
3289 return LOWORD( WINPROC_CallWndProc16( proc->proc16, hwnd, msg, wParam, lParam ) );
3291 return __wine_call_wndproc_32A( hwnd, msg, wParam, lParam, proc->thunk.proc );
3293 return __wine_call_wndproc_32W( hwnd, msg, wParam, lParam, proc->thunk.proc );
3295 WARN_(relay)("Invalid proc %p\n", proc );
3301 /**********************************************************************
3302 * WINPROC_CallDlgProcA
3304 INT_PTR WINPROC_CallDlgProcA( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
3308 if (!func) return 0;
3310 if (!(proc = handle_to_proc( (WNDPROC)func )))
3311 return WINPROC_CallWndProc( (WNDPROC)func, hwnd, msg, wParam, lParam );
3316 return LOWORD( WINPROC_CallProc32ATo16( proc->proc16, hwnd, msg, wParam, lParam ) );
3318 return WINPROC_CallWndProc( proc->thunk.proc, hwnd, msg, wParam, lParam );
3320 return WINPROC_CallProc32ATo32W( proc->thunk.proc, hwnd, msg, wParam, lParam );
3322 WARN_(relay)("Invalid proc %p\n", proc );
3328 /**********************************************************************
3329 * WINPROC_CallDlgProcW
3331 INT_PTR WINPROC_CallDlgProcW( DLGPROC func, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
3335 if (!func) return 0;
3337 if (!(proc = handle_to_proc( (WNDPROC)func )))
3338 return WINPROC_CallWndProc( (WNDPROC)func, hwnd, msg, wParam, lParam );
3343 return LOWORD( WINPROC_CallProc32WTo16( proc->proc16, hwnd, msg, wParam, lParam ));
3345 return WINPROC_CallProc32WTo32A( proc->thunk.proc, hwnd, msg, wParam, lParam );
3347 return WINPROC_CallWndProc( proc->thunk.proc, hwnd, msg, wParam, lParam );
3349 WARN_(relay)("Invalid proc %p\n", proc );