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"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "stackframe.h"
43 #include "wine/unicode.h"
44 #include "wine/debug.h"
46 WINE_DECLARE_DEBUG_CHANNEL(msg);
47 WINE_DECLARE_DEBUG_CHANNEL(relay);
48 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 */
62 } WINPROC_THUNK_FROM16;
64 /* Window procedure 32-to-16-bit thunk */
67 BYTE popl_eax; /* popl %eax (return address) */
68 BYTE pushl_func; /* pushl $proc */
70 BYTE pushl_eax; /* pushl %eax */
71 BYTE jmp; /* jmp relay (relative jump)*/
72 void (*relay)(); /* WINPROC_CallProc32ATo16() */
73 } WINPROC_THUNK_FROM32;
75 /* Simple jmp to call 32-bit procedure directly */
78 BYTE jmp; /* jmp proc (relative jump) */
85 WINPROC_THUNK_FROM16 t_from16;
86 WINPROC_THUNK_FROM32 t_from32;
89 typedef struct tagWINDOWPROC
91 WINPROC_THUNK thunk; /* Thunk */
92 WINPROC_JUMP jmp; /* Jump */
93 struct tagWINDOWPROC *next; /* Next window proc */
94 UINT magic; /* Magic number */
95 WINDOWPROCTYPE type; /* Function type */
96 WINDOWPROCUSER user; /* Function user */
99 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
101 #define WINPROC_THUNKPROC(pproc) \
102 (((pproc)->type == WIN_PROC_16) ? \
103 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
104 (WNDPROC16)((pproc)->thunk.t_from16.proc))
106 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
107 UINT msg, WPARAM wParam,
109 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
110 UINT msg, WPARAM wParam,
113 #define MAX_WINPROCS (0x10000 / sizeof(WINDOWPROC))
115 static WINDOWPROC winproc_array[MAX_WINPROCS];
116 static WINDOWPROC *winproc_first_free;
117 static UINT winproc_used;
119 static CRITICAL_SECTION winproc_cs;
120 static CRITICAL_SECTION_DEBUG critsect_debug =
123 { &critsect_debug.ProcessLocksList, &critsect_debug.ProcessLocksList },
124 0, 0, { 0, (DWORD)(__FILE__ ": winproc_cs") }
126 static CRITICAL_SECTION winproc_cs = { &critsect_debug, -1, 0, 0, 0, 0 };
128 /* allocate a window procedure from the global array */
129 static WINDOWPROC *alloc_winproc(void)
131 WINDOWPROC *ret = NULL;
133 EnterCriticalSection( &winproc_cs );
134 if ((ret = winproc_first_free))
135 winproc_first_free = ret->next;
136 else if (winproc_used < MAX_WINPROCS)
137 ret = &winproc_array[winproc_used++];
138 LeaveCriticalSection( &winproc_cs );
142 static void free_winproc( WINDOWPROC *proc )
144 EnterCriticalSection( &winproc_cs );
146 proc->next = winproc_first_free;
147 winproc_first_free = proc;
148 LeaveCriticalSection( &winproc_cs );
151 static BOOL is_valid_winproc( WINDOWPROC *proc )
153 if (proc < winproc_array || proc >= winproc_array + MAX_WINPROCS) return FALSE;
154 if (proc != winproc_array + (proc - winproc_array)) return FALSE;
155 return (proc->magic == WINPROC_MAGIC);
158 static WORD get_winproc_selector(void)
160 static LONG winproc_selector;
163 if (!(ret = winproc_selector))
166 WORD sel = wine_ldt_alloc_entries(1);
167 wine_ldt_set_base( &entry, winproc_array );
168 wine_ldt_set_limit( &entry, sizeof(winproc_array) - 1 );
169 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
170 wine_ldt_set_entry( sel, &entry );
171 if (!(ret = InterlockedCompareExchange( &winproc_selector, sel, 0 ))) ret = sel;
172 else wine_ldt_free_entries( sel, 1 ); /* somebody beat us to it */
179 /* Some window procedures modify register they shouldn't, or are not
180 * properly declared stdcall; so we need a small assembly wrapper to
182 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
183 WPARAM wParam, LPARAM lParam );
184 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
194 "movl 8(%ebp),%eax\n\t"
196 "leal -12(%ebp),%esp\n\t"
203 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
204 WPARAM wParam, LPARAM lParam )
206 return proc( hwnd, msg, wParam, lParam );
208 #endif /* __i386__ */
211 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
213 to->ptReserved.x = from->ptReserved.x;
214 to->ptReserved.y = from->ptReserved.y;
215 to->ptMaxSize.x = from->ptMaxSize.x;
216 to->ptMaxSize.y = from->ptMaxSize.y;
217 to->ptMaxPosition.x = from->ptMaxPosition.x;
218 to->ptMaxPosition.y = from->ptMaxPosition.y;
219 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
220 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
221 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
222 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
225 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
227 to->ptReserved.x = from->ptReserved.x;
228 to->ptReserved.y = from->ptReserved.y;
229 to->ptMaxSize.x = from->ptMaxSize.x;
230 to->ptMaxSize.y = from->ptMaxSize.y;
231 to->ptMaxPosition.x = from->ptMaxPosition.x;
232 to->ptMaxPosition.y = from->ptMaxPosition.y;
233 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
234 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
235 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
236 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
239 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
241 to->hwnd = HWND_16(from->hwnd);
242 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
247 to->flags = from->flags;
250 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
252 to->hwnd = WIN_Handle32(from->hwnd);
253 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
254 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
259 to->flags = from->flags;
262 /* The strings are not copied */
263 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
265 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
266 to->hInstance = HINSTANCE_16(from->hInstance);
267 to->hMenu = HMENU_16(from->hMenu);
268 to->hwndParent = HWND_16(from->hwndParent);
273 to->style = from->style;
274 to->dwExStyle = from->dwExStyle;
277 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
280 to->lpCreateParams = (LPVOID)from->lpCreateParams;
281 to->hInstance = HINSTANCE_32(from->hInstance);
282 to->hMenu = HMENU_32(from->hMenu);
283 to->hwndParent = WIN_Handle32(from->hwndParent);
288 to->style = from->style;
289 to->dwExStyle = from->dwExStyle;
292 /* The strings are not copied */
293 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
295 to->hOwner = HINSTANCE_16(from->hOwner);
300 to->style = from->style;
301 to->lParam = from->lParam;
304 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
306 to->hOwner = HINSTANCE_32(from->hOwner);
311 to->style = from->style;
312 to->lParam = from->lParam;
315 /**********************************************************************
316 * WINPROC_CallWndProc32
318 * Call a 32-bit WndProc.
320 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
321 WPARAM wParam, LPARAM lParam )
326 hwnd = WIN_GetFullHandle( hwnd );
328 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
329 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam );
330 /* To avoid any deadlocks, all the locks on the windows structures
331 must be suspended before the control is passed to the application */
332 iWndsLocks = WIN_SuspendWndsLock();
333 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
334 WIN_RestoreWndsLock(iWndsLocks);
337 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
338 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
342 /***********************************************************************
343 * WINPROC_CallWndProc16
345 * Call a 16-bit window procedure
347 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
348 UINT16 msg, WPARAM16 wParam,
355 TEB *teb = NtCurrentTeb();
358 /* Window procedures want ax = hInstance, ds = es = ss */
360 memset(&context, 0, sizeof(context));
361 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
362 context.SegFs = wine_get_fs();
363 context.SegGs = wine_get_gs();
364 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWL_HINSTANCE ))) context.Eax = context.SegDs;
365 context.SegCs = SELECTOROF(proc);
366 context.Eip = OFFSETOF(proc);
367 context.Ebp = OFFSETOF(teb->cur_stack)
368 + (WORD)&((STACK16FRAME*)0)->bp;
372 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
373 work if structures passed in lParam are placed in the stack/data
374 segment. Programmers easily make the mistake of converting lParam
375 to a near rather than a far pointer, since Windows apparently
376 allows this. We copy the structures to the 16 bit stack; this is
377 ugly but makes these programs work. */
382 offset = sizeof(CREATESTRUCT16); break;
384 offset = sizeof(DRAWITEMSTRUCT16); break;
386 offset = sizeof(COMPAREITEMSTRUCT16); break;
390 void *s = MapSL(lParam);
391 lParam = stack16_push( offset );
392 memcpy( MapSL(lParam), s, offset );
396 iWndsLocks = WIN_SuspendWndsLock();
401 args[1] = HIWORD(lParam);
402 args[0] = LOWORD(lParam);
403 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args), args, (DWORD *)&context );
404 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
406 if (offset) stack16_pop( offset );
408 WIN_RestoreWndsLock(iWndsLocks);
414 /**********************************************************************
417 * Return a pointer to the win proc.
419 static WINDOWPROC *WINPROC_GetPtr( WNDPROC handle )
424 /* ptr cannot be < 64K */
425 if (!HIWORD(handle)) return NULL;
427 /* Check for a linear pointer */
429 ptr = (BYTE *)handle;
430 /* First check if it is the jmp address */
431 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->jmp);
432 if (is_valid_winproc(proc)) return proc;
434 /* Now it must be the thunk address */
435 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
436 if (is_valid_winproc(proc)) return proc;
438 /* Check for a segmented pointer */
440 if (!IsBadReadPtr16( (SEGPTR)handle, sizeof(proc->thunk) ))
442 ptr = MapSL( (SEGPTR)handle );
443 /* It must be the thunk address */
444 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
445 if (is_valid_winproc(proc)) return proc;
452 /**********************************************************************
453 * WINPROC_AllocWinProc
455 * Allocate a new window procedure.
457 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC func, WINDOWPROCTYPE type,
458 WINDOWPROCUSER user )
460 static FARPROC16 relay_32A, relay_32W;
462 WINDOWPROC *proc, *oldproc;
464 /* Allocate a window procedure */
466 if (!(proc = alloc_winproc())) return 0;
468 /* Check if the function is already a win proc */
470 if ((oldproc = WINPROC_GetPtr( func )))
479 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
480 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
481 proc->thunk.t_from32.proc = (WNDPROC16)func;
482 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
483 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
484 proc->thunk.t_from32.relay = /* relative jump */
485 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
486 (DWORD)(&proc->thunk.t_from32.relay + 1));
489 if (!relay_32A) relay_32A = GetProcAddress16( GetModuleHandle16("user"),
490 "__wine_call_wndproc_32A" );
491 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
492 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
493 proc->thunk.t_from16.proc = func;
494 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
495 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
496 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32A);
497 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32A);
498 proc->jmp.jmp = 0xe9;
499 /* Fixup relative jump */
500 proc->jmp.proc = (WNDPROC)((DWORD)func - (DWORD)(&proc->jmp.proc + 1));
503 if (!relay_32W) relay_32W = GetProcAddress16( GetModuleHandle16("user"),
504 "__wine_call_wndproc_32W" );
505 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
506 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
507 proc->thunk.t_from16.proc = func;
508 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
509 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
510 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32W);
511 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32W);
512 proc->jmp.jmp = 0xe9;
513 /* Fixup relative jump */
514 proc->jmp.proc = (WNDPROC)((char *)func - (char *)(&proc->jmp.proc + 1));
517 /* Should not happen */
520 proc->magic = WINPROC_MAGIC;
525 TRACE("(%p,%d): returning %p\n", func, type, proc );
530 /**********************************************************************
533 * Get a window procedure pointer that can be passed to the Windows program.
535 WNDPROC16 WINPROC_GetProc( WNDPROC proc, WINDOWPROCTYPE type )
537 WINDOWPROC *ptr = (WINDOWPROC *)proc;
539 if (!proc) return NULL;
540 if (type == WIN_PROC_16) /* We want a 16:16 address */
542 if (ptr->type == WIN_PROC_16)
543 return ptr->thunk.t_from32.proc;
545 return (WNDPROC16)MAKESEGPTR( get_winproc_selector(),
546 (char *)&ptr->thunk - (char *)winproc_array );
548 else /* We want a 32-bit address */
550 if (ptr->type == WIN_PROC_16)
551 return (WNDPROC16)&ptr->thunk;
552 else if (type != ptr->type)
553 /* Have to return the jmp address if types don't match */
554 return (WNDPROC16)&ptr->jmp;
556 /* Some Win16 programs want to get back the proc they set */
557 return (WNDPROC16)ptr->thunk.t_from16.proc;
562 /**********************************************************************
565 * Set the window procedure for a window or class. There are
566 * three tree classes of winproc callbacks:
568 * 1) class -> wp - not subclassed
569 * class -> wp -> wp -> wp -> wp - SetClassLong()
571 * 2) window -' / - not subclassed
572 * window -> wp -> wp ' - SetWindowLong()
574 * 3) timer -> wp - SetTimer()
576 * Initially, winproc of the window points to the current winproc
577 * thunk of its class. Subclassing prepends a new thunk to the
578 * window winproc chain at the head of the list. Thus, window thunk
579 * list includes class thunks and the latter are preserved when the
580 * window is destroyed.
583 BOOL WINPROC_SetProc( WNDPROC *pFirst, WNDPROC func,
584 WINDOWPROCTYPE type, WINDOWPROCUSER user )
586 BOOL bRecycle = FALSE;
587 WINDOWPROC *proc, **ppPrev;
589 /* Check if function is already in the list */
591 ppPrev = (WINDOWPROC **)pFirst;
592 proc = WINPROC_GetPtr( func );
599 if ((*ppPrev)->user != user)
601 /* terminal thunk is being restored */
603 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
604 *(WINDOWPROC **)pFirst = *ppPrev;
613 if (((*ppPrev)->type == type) &&
614 (func == (WNDPROC)WINPROC_THUNKPROC(*ppPrev)))
616 if((*ppPrev)->user == user)
622 WINPROC_FreeProc( (WNDPROC)*ppPrev, user );
629 /* WPF_CLASS thunk terminates window thunk list */
630 if ((*ppPrev)->user != user) break;
631 ppPrev = &(*ppPrev)->next;
636 /* Extract this thunk from the list */
638 *ppPrev = proc->next;
640 else /* Allocate a new one */
642 if (proc) /* Was already a win proc */
645 func = (WNDPROC)WINPROC_THUNKPROC(proc);
647 proc = WINPROC_AllocWinProc( func, type, user );
648 if (!proc) return FALSE;
651 /* Add the win proc at the head of the list */
653 TRACE("(%p,%p,%d): res=%p\n", *pFirst, func, type, proc );
654 proc->next = *(WINDOWPROC **)pFirst;
655 *(WINDOWPROC **)pFirst = proc;
660 /**********************************************************************
663 * Free a list of win procs.
665 void WINPROC_FreeProc( WNDPROC proc, WINDOWPROCUSER user )
667 WINDOWPROC *ptr = (WINDOWPROC *)proc;
670 WINDOWPROC *next = ptr->next;
671 if (ptr->user != user) break;
672 TRACE("freeing %p (%d)\n", ptr, user);
679 /**********************************************************************
680 * WINPROC_GetProcType
682 * Return the window procedure type.
684 WINDOWPROCTYPE WINPROC_GetProcType( WNDPROC proc )
687 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
688 return WIN_PROC_INVALID;
689 return ((WINDOWPROC *)proc)->type;
691 /**********************************************************************
692 * WINPROC_TestCBForStr
694 * Return TRUE if the lparam is a string
696 inline static BOOL WINPROC_TestCBForStr( HWND hwnd )
698 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
699 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
701 /**********************************************************************
702 * WINPROC_TestLBForStr
704 * Return TRUE if the lparam is a string
706 inline static BOOL WINPROC_TestLBForStr( HWND hwnd )
708 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
709 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
712 /**********************************************************************
713 * WINPROC_MapMsg32ATo32W
715 * Map a message from Ansi to Unicode.
716 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
719 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
720 * the first four bytes are the handle of the icon
721 * when the WM_SETTEXT message has been used to set the icon
723 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
728 case WM_ASKCBFORMATNAME:
730 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
731 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
733 *ptr++ = *plparam; /* Store previous lParam */
734 *plparam = (LPARAM)ptr;
737 /* lparam is string (0-terminated) */
739 case WM_WININICHANGE:
740 case WM_DEVMODECHANGE:
746 DWORD len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, NULL, 0);
747 WCHAR *buf = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
748 len = MultiByteToWideChar(CP_ACP, 0, (LPCSTR)*plparam, -1, buf, len);
749 *plparam = (LPARAM)buf;
750 return (*plparam ? 1 : -1);
752 case WM_GETTEXTLENGTH:
753 case CB_GETLBTEXTLEN:
755 return 1; /* need to map result */
759 UNICODE_STRING usBuffer;
761 { CREATESTRUCTW cs; /* new structure */
762 LPCWSTR lpszName; /* allocated Name */
763 LPCWSTR lpszClass; /* allocated Class */
766 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
768 xs->cs = *(CREATESTRUCTW *)*plparam;
769 if (HIWORD(xs->cs.lpszName))
771 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszName);
772 xs->lpszName = xs->cs.lpszName = usBuffer.Buffer;
774 if (HIWORD(xs->cs.lpszClass))
776 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)xs->cs.lpszClass);
777 xs->lpszClass = xs->cs.lpszClass = usBuffer.Buffer;
780 if (GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
782 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)HeapAlloc(GetProcessHeap(), 0,
784 *mdi_cs = *(MDICREATESTRUCTW *)xs->cs.lpCreateParams;
785 if (HIWORD(mdi_cs->szTitle))
787 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szTitle);
788 mdi_cs->szTitle = usBuffer.Buffer;
790 if (HIWORD(mdi_cs->szClass))
792 RtlCreateUnicodeStringFromAsciiz(&usBuffer, (LPCSTR)mdi_cs->szClass);
793 mdi_cs->szClass = usBuffer.Buffer;
795 xs->cs.lpCreateParams = mdi_cs;
798 *plparam = (LPARAM)xs;
803 MDICREATESTRUCTW *cs =
804 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
806 *cs = *(MDICREATESTRUCTW *)*plparam;
807 if (HIWORD(cs->szClass))
809 UNICODE_STRING usBuffer;
810 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szClass);
811 cs->szClass = usBuffer.Buffer;
813 if (HIWORD(cs->szTitle))
815 UNICODE_STRING usBuffer;
816 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)cs->szTitle);
817 cs->szTitle = usBuffer.Buffer;
819 *plparam = (LPARAM)cs;
825 case LB_INSERTSTRING:
827 case LB_FINDSTRINGEXACT:
828 case LB_SELECTSTRING:
829 if(!*plparam) return 0;
830 if ( WINPROC_TestLBForStr( hwnd ))
832 UNICODE_STRING usBuffer;
833 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
834 *plparam = (LPARAM)usBuffer.Buffer;
836 return (*plparam ? 1 : -1);
838 case LB_GETTEXT: /* FIXME: fixed sized buffer */
839 { if ( WINPROC_TestLBForStr( hwnd ))
840 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
842 *ptr++ = *plparam; /* Store previous lParam */
843 *plparam = (LPARAM)ptr;
850 case CB_INSERTSTRING:
851 case CB_FINDSTRINGEXACT:
853 case CB_SELECTSTRING:
854 if(!*plparam) return 0;
855 if ( WINPROC_TestCBForStr( hwnd ))
857 UNICODE_STRING usBuffer;
858 RtlCreateUnicodeStringFromAsciiz(&usBuffer,(LPCSTR)*plparam);
859 *plparam = (LPARAM)usBuffer.Buffer;
861 return (*plparam ? 1 : -1);
863 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
864 { if ( WINPROC_TestCBForStr( hwnd ))
865 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
867 *ptr++ = *plparam; /* Store previous lParam */
868 *plparam = (LPARAM)ptr;
875 { WORD len = (WORD)*plparam;
876 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
878 *ptr++ = *plparam; /* Store previous lParam */
879 *((WORD *) ptr) = len; /* Store the length */
880 *plparam = (LPARAM)ptr;
890 case EM_SETPASSWORDCHAR:
892 BYTE ch = LOWORD(*pwparam);
894 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
895 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
903 ch[0] = (*pwparam >> 8);
904 ch[1] = *pwparam & 0xff;
906 MultiByteToWideChar(CP_ACP, 0, ch, 2, &wch, 1);
908 MultiByteToWideChar(CP_ACP, 0, &ch[1], 1, &wch, 1);
909 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
913 case WM_PAINTCLIPBOARD:
914 case WM_SIZECLIPBOARD:
915 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
917 default: /* No translation needed */
923 /**********************************************************************
924 * WINPROC_UnmapMsg32ATo32W
926 * Unmap a message that was mapped from Ansi to Unicode.
928 LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
934 case WM_ASKCBFORMATNAME:
936 LPARAM *ptr = (LPARAM *)lParam - 1;
937 if (!wParam) result = 0;
938 else if (!(result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
939 (LPSTR)*ptr, wParam, NULL, NULL )))
941 ((LPSTR)*ptr)[wParam-1] = 0;
944 else result--; /* do not count terminating null */
945 HeapFree( GetProcessHeap(), 0, ptr );
948 case WM_GETTEXTLENGTH:
949 case CB_GETLBTEXTLEN:
951 /* there may be one DBCS char for each Unicode char */
957 { CREATESTRUCTW cs; /* new structure */
958 LPWSTR lpszName; /* allocated Name */
959 LPWSTR lpszClass; /* allocated Class */
961 struct s *xs = (struct s *)lParam;
962 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
963 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
965 if (GetWindowLongA(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
967 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)xs->cs.lpCreateParams;
968 if (HIWORD(mdi_cs->szTitle))
969 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szTitle);
970 if (HIWORD(mdi_cs->szClass))
971 HeapFree(GetProcessHeap(), 0, (LPVOID)mdi_cs->szClass);
972 HeapFree(GetProcessHeap(), 0, mdi_cs);
974 HeapFree( GetProcessHeap(), 0, xs );
980 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
981 if (HIWORD(cs->szTitle))
982 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
983 if (HIWORD(cs->szClass))
984 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
985 HeapFree( GetProcessHeap(), 0, cs );
990 case WM_WININICHANGE:
991 case WM_DEVMODECHANGE:
996 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1001 case LB_INSERTSTRING:
1003 case LB_FINDSTRINGEXACT:
1004 case LB_SELECTSTRING:
1005 if ( WINPROC_TestLBForStr( hwnd ))
1006 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1010 if ( WINPROC_TestLBForStr( hwnd ))
1012 LPARAM *ptr = (LPARAM *)lParam - 1;
1013 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
1014 (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
1015 HeapFree( GetProcessHeap(), 0, ptr );
1021 case CB_INSERTSTRING:
1023 case CB_FINDSTRINGEXACT:
1024 case CB_SELECTSTRING:
1025 if ( WINPROC_TestCBForStr( hwnd ))
1026 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1030 if ( WINPROC_TestCBForStr( hwnd ))
1032 LPARAM *ptr = (LPARAM *)lParam - 1;
1033 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
1034 (LPSTR)*ptr, 0x7fffffff, NULL, NULL ) - 1;
1035 HeapFree( GetProcessHeap(), 0, ptr );
1039 /* Multiline edit */
1042 LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
1043 WORD len = *(WORD *) lParam;
1044 result = WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, result,
1045 (LPSTR)*ptr, len, NULL, NULL );
1046 if (result < len) ((LPSTR)*ptr)[result] = 0;
1047 HeapFree( GetProcessHeap(), 0, ptr );
1055 /**********************************************************************
1056 * WINPROC_MapMsg32WTo32A
1058 * Map a message from Unicode to Ansi.
1059 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1061 static INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
1066 case WM_ASKCBFORMATNAME:
1068 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
1069 *pwparam + sizeof(LPARAM) );
1070 if (!ptr) return -1;
1071 *ptr++ = *plparam; /* Store previous lParam */
1072 *plparam = (LPARAM)ptr;
1077 case WM_WININICHANGE:
1078 case WM_DEVMODECHANGE:
1083 if(!*plparam) return 0;
1084 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
1085 return (*plparam ? 1 : -1);
1089 MDICREATESTRUCTA *cs =
1090 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
1092 *cs = *(MDICREATESTRUCTA *)*plparam;
1093 if (HIWORD(cs->szTitle))
1094 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
1095 (LPCWSTR)cs->szTitle );
1096 if (HIWORD(cs->szClass))
1097 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
1098 (LPCWSTR)cs->szClass );
1099 *plparam = (LPARAM)cs;
1105 case LB_INSERTSTRING:
1107 case LB_FINDSTRINGEXACT:
1108 case LB_SELECTSTRING:
1109 if(!*plparam) return 0;
1110 if ( WINPROC_TestLBForStr( hwnd ))
1111 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
1112 return (*plparam ? 1 : -1);
1114 case LB_GETTEXT: /* FIXME: fixed sized buffer */
1115 { if ( WINPROC_TestLBForStr( hwnd ))
1116 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
1117 if (!ptr) return -1;
1118 *ptr++ = *plparam; /* Store previous lParam */
1119 *plparam = (LPARAM)ptr;
1126 case CB_INSERTSTRING:
1128 case CB_FINDSTRINGEXACT:
1129 case CB_SELECTSTRING:
1130 if(!*plparam) return 0;
1131 if ( WINPROC_TestCBForStr( hwnd ))
1132 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
1133 return (*plparam ? 1 : -1);
1135 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
1136 { if ( WINPROC_TestCBForStr( hwnd ))
1137 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
1138 if (!ptr) return -1;
1139 *ptr++ = *plparam; /* Store previous lParam */
1140 *plparam = (LPARAM)ptr;
1145 /* Multiline edit */
1147 { WORD len = (WORD)*plparam;
1148 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
1149 if (!ptr) return -1;
1150 *ptr++ = *plparam; /* Store previous lParam */
1151 *((WORD *) ptr) = len; /* Store the length */
1152 *plparam = (LPARAM)ptr;
1161 case WM_SYSDEADCHAR:
1162 case EM_SETPASSWORDCHAR:
1164 WCHAR wch = LOWORD(*pwparam);
1166 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
1167 *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
1173 WCHAR wch = LOWORD(*pwparam);
1176 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
1177 *pwparam = MAKEWPARAM( (ch[0] << 8) | ch[1], HIWORD(*pwparam) );
1179 *pwparam = MAKEWPARAM( ch[0], HIWORD(*pwparam) );
1183 case WM_PAINTCLIPBOARD:
1184 case WM_SIZECLIPBOARD:
1185 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg, hwnd),msg );
1187 default: /* No translation needed */
1193 /**********************************************************************
1194 * WINPROC_UnmapMsg32WTo32A
1196 * Unmap a message that was mapped from Unicode to Ansi.
1198 static LRESULT WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, LRESULT result )
1203 case WM_ASKCBFORMATNAME:
1205 LPARAM *ptr = (LPARAM *)lParam - 1;
1206 if (!wParam) result = 0;
1207 else if (!(result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1,
1208 (LPWSTR)*ptr, wParam )))
1210 ((LPWSTR)*ptr)[wParam-1] = 0;
1211 result = wParam - 1;
1213 else result--; /* do not count terminating null */
1214 HeapFree( GetProcessHeap(), 0, ptr );
1219 case WM_WININICHANGE:
1220 case WM_DEVMODECHANGE:
1225 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1230 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1231 if (HIWORD(cs->szTitle))
1232 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1233 if (HIWORD(cs->szClass))
1234 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1235 HeapFree( GetProcessHeap(), 0, cs );
1241 case LB_INSERTSTRING:
1243 case LB_FINDSTRINGEXACT:
1244 case LB_SELECTSTRING:
1245 if ( WINPROC_TestLBForStr( hwnd ))
1246 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1250 if ( WINPROC_TestLBForStr( hwnd ))
1252 LPARAM *ptr = (LPARAM *)lParam - 1;
1253 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
1254 HeapFree( GetProcessHeap(), 0, ptr );
1260 case CB_INSERTSTRING:
1262 case CB_FINDSTRINGEXACT:
1263 case CB_SELECTSTRING:
1264 if ( WINPROC_TestCBForStr( hwnd ))
1265 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1269 if ( WINPROC_TestCBForStr( hwnd ))
1271 LPARAM *ptr = (LPARAM *)lParam - 1;
1272 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff ) - 1;
1273 HeapFree( GetProcessHeap(), 0, ptr );
1277 /* Multiline edit */
1280 LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1281 WORD len = *(WORD *)ptr;
1284 result = MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, result, (LPWSTR)*ptr, len );
1285 if (result < len) ((LPWSTR)*ptr)[result] = 0;
1287 HeapFree( GetProcessHeap(), 0, ptr );
1294 static UINT convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
1297 UINT sz = GlobalSize16(src);
1300 if (!(dst = GlobalAlloc(flags, sz)))
1302 ptr16 = GlobalLock16(src);
1303 ptr32 = GlobalLock(dst);
1304 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
1305 GlobalUnlock16(src);
1311 /**********************************************************************
1312 * WINPROC_MapMsg16To32A
1314 * Map a message from 16- to 32-bit Ansi.
1315 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1317 INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1318 WPARAM *pwparam32, LPARAM *plparam )
1320 *pmsg32 = (UINT)msg16;
1321 *pwparam32 = (WPARAM)wParam16;
1328 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1329 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1333 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1334 *plparam = (LPARAM)WIN_Handle32( HIWORD(*plparam) );
1337 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1338 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1339 *pwparam32 = (WPARAM)HDC_32(wParam16);
1340 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1342 case WM_COMPAREITEM:
1344 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1345 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1346 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1347 if (!cis) return -1;
1348 cis->CtlType = cis16->CtlType;
1349 cis->CtlID = cis16->CtlID;
1350 cis->hwndItem = WIN_Handle32( cis16->hwndItem );
1351 cis->itemID1 = cis16->itemID1;
1352 cis->itemData1 = cis16->itemData1;
1353 cis->itemID2 = cis16->itemID2;
1354 cis->itemData2 = cis16->itemData2;
1355 cis->dwLocaleId = 0; /* FIXME */
1356 *plparam = (LPARAM)cis;
1361 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1362 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1363 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1364 if (!dis) return -1;
1365 dis->CtlType = dis16->CtlType;
1366 dis->CtlID = dis16->CtlID;
1367 dis->hwndItem = WIN_Handle32( dis16->hwndItem );
1368 dis->itemData = dis16->itemData;
1369 *plparam = (LPARAM)dis;
1372 case WM_MEASUREITEM:
1374 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1375 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1376 HeapAlloc(GetProcessHeap(), 0,
1377 sizeof(*mis) + sizeof(LPARAM));
1378 if (!mis) return -1;
1379 mis->CtlType = mis16->CtlType;
1380 mis->CtlID = mis16->CtlID;
1381 mis->itemID = mis16->itemID;
1382 mis->itemWidth = mis16->itemWidth;
1383 mis->itemHeight = mis16->itemHeight;
1384 mis->itemData = mis16->itemData;
1385 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1386 *plparam = (LPARAM)mis;
1391 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1392 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1394 if (!dis) return -1;
1395 dis->CtlType = dis16->CtlType;
1396 dis->CtlID = dis16->CtlID;
1397 dis->itemID = dis16->itemID;
1398 dis->itemAction = dis16->itemAction;
1399 dis->itemState = dis16->itemState;
1400 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
1401 : WIN_Handle32( dis16->hwndItem );
1402 dis->hDC = HDC_32(dis16->hDC);
1403 dis->itemData = dis16->itemData;
1404 dis->rcItem.left = dis16->rcItem.left;
1405 dis->rcItem.top = dis16->rcItem.top;
1406 dis->rcItem.right = dis16->rcItem.right;
1407 dis->rcItem.bottom = dis16->rcItem.bottom;
1408 *plparam = (LPARAM)dis;
1411 case WM_GETMINMAXINFO:
1413 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1414 sizeof(*mmi) + sizeof(LPARAM));
1415 if (!mmi) return -1;
1416 MINMAXINFO16to32( MapSL(*plparam), mmi );
1417 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1418 *plparam = (LPARAM)mmi;
1423 case WM_WININICHANGE:
1424 case WM_DEVMODECHANGE:
1425 case WM_ASKCBFORMATNAME:
1426 *plparam = (LPARAM)MapSL(*plparam);
1430 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1431 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1433 MDICREATESTRUCT16to32A( cs16, cs );
1434 cs->szTitle = MapSL(cs16->szTitle);
1435 cs->szClass = MapSL(cs16->szClass);
1436 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1437 *plparam = (LPARAM)cs;
1440 case WM_MDIGETACTIVE:
1441 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1442 *(BOOL*)(*plparam) = 0;
1446 *pmsg32=WM_MDIREFRESHMENU;
1447 *pwparam32 = (WPARAM)HMENU_32(LOWORD(*plparam));
1448 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1451 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1452 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1455 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1457 HMENU hmenu=HMENU_32(HIWORD(*plparam));
1458 UINT Pos=MENU_FindSubMenu( &hmenu, HMENU_32(wParam16));
1459 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1460 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1462 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1463 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1465 case WM_MDIACTIVATE:
1468 *pwparam32 = (WPARAM)WIN_Handle32( HIWORD(*plparam) );
1469 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1471 else /* message sent to MDI client */
1472 *pwparam32 = wParam16;
1476 NCCALCSIZE_PARAMS16 *nc16;
1477 NCCALCSIZE_PARAMS *nc;
1479 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1480 sizeof(*nc) + sizeof(LPARAM) );
1482 nc16 = MapSL(*plparam);
1483 nc->rgrc[0].left = nc16->rgrc[0].left;
1484 nc->rgrc[0].top = nc16->rgrc[0].top;
1485 nc->rgrc[0].right = nc16->rgrc[0].right;
1486 nc->rgrc[0].bottom = nc16->rgrc[0].bottom;
1489 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1490 sizeof(*nc->lppos) );
1491 nc->rgrc[1].left = nc16->rgrc[1].left;
1492 nc->rgrc[1].top = nc16->rgrc[1].top;
1493 nc->rgrc[1].right = nc16->rgrc[1].right;
1494 nc->rgrc[1].bottom = nc16->rgrc[1].bottom;
1495 nc->rgrc[2].left = nc16->rgrc[2].left;
1496 nc->rgrc[2].top = nc16->rgrc[2].top;
1497 nc->rgrc[2].right = nc16->rgrc[2].right;
1498 nc->rgrc[2].bottom = nc16->rgrc[2].bottom;
1499 if (nc->lppos) WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1501 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1502 *plparam = (LPARAM)nc;
1508 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1509 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1510 sizeof(*cs) + sizeof(LPARAM) );
1512 CREATESTRUCT16to32A( cs16, cs );
1513 cs->lpszName = MapSL(cs16->lpszName);
1514 cs->lpszClass = MapSL(cs16->lpszClass);
1516 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1518 MDICREATESTRUCT16 *mdi_cs16;
1519 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)HeapAlloc(GetProcessHeap(), 0,
1523 HeapFree(GetProcessHeap(), 0, cs);
1526 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1527 MDICREATESTRUCT16to32A(mdi_cs16, mdi_cs);
1528 mdi_cs->szTitle = MapSL(mdi_cs16->szTitle);
1529 mdi_cs->szClass = MapSL(mdi_cs16->szClass);
1531 cs->lpCreateParams = mdi_cs;
1533 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1534 *plparam = (LPARAM)cs;
1537 case WM_PARENTNOTIFY:
1538 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1540 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1541 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1544 case WM_WINDOWPOSCHANGING:
1545 case WM_WINDOWPOSCHANGED:
1547 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1548 sizeof(*wp) + sizeof(LPARAM) );
1550 WINDOWPOS16to32( MapSL(*plparam), wp );
1551 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1552 *plparam = (LPARAM)wp;
1558 LPMSG16 msg16 = MapSL(*plparam);
1559 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1561 if (!msg32) return -1;
1562 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1563 msg32->lParam = msg16->lParam;
1564 msg32->time = msg16->time;
1565 msg32->pt.x = msg16->pt.x;
1566 msg32->pt.y = msg16->pt.y;
1567 /* this is right, right? */
1568 if (WINPROC_MapMsg16To32A( msg32->hwnd, msg16->message,msg16->wParam,
1569 &msg32->message,&msg32->wParam,
1570 &msg32->lParam)<0) {
1571 HeapFree( GetProcessHeap(), 0, msg32 );
1574 *plparam = (LPARAM)msg32;
1579 *plparam = (LPARAM)MapSL(*plparam);
1581 case WM_ACTIVATEAPP:
1582 /* We need this when SetActiveWindow sends a Sendmessage16() to
1583 * a 32bit window. Might be superflous with 32bit interprocess
1584 * message queues. */
1585 if (*plparam) *plparam = HTASK_32( *plparam );
1589 MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
1590 if (!next) return -1;
1591 next->hmenuIn = (HMENU)*plparam;
1592 next->hmenuNext = 0;
1594 *plparam = (LPARAM)next;
1597 case WM_PAINTCLIPBOARD:
1598 case WM_SIZECLIPBOARD:
1599 FIXME_(msg)("message %04x needs translation\n",msg16 );
1601 case WM_DDE_INITIATE:
1602 case WM_DDE_TERMINATE:
1603 case WM_DDE_UNADVISE:
1604 case WM_DDE_REQUEST:
1605 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1615 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1616 lo16 = LOWORD(*plparam);
1617 hi = HIWORD(*plparam);
1618 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE)))
1620 *plparam = PackDDElParam(msg16, lo32, hi);
1622 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1629 *pwparam32 = (WPARAM)WIN_Handle32(wParam16);
1631 lo = LOWORD(*plparam);
1632 hi = HIWORD(*plparam);
1634 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
1635 if (GlobalSize16(hi) != 0) flag |= 2;
1641 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1646 break; /* atom, nothing to do */
1648 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
1651 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
1654 *plparam = PackDDElParam(WM_DDE_ACK, lo, hi);
1656 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1657 case WM_DDE_EXECUTE:
1658 *plparam = convert_handle_16_to_32(*plparam, GMEM_DDESHARE);
1659 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1660 default: /* No translation needed */
1666 /**********************************************************************
1667 * WINPROC_UnmapMsg16To32A
1669 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1671 LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1676 case WM_COMPAREITEM:
1679 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1681 case WM_MEASUREITEM:
1683 MEASUREITEMSTRUCT16 *mis16;
1684 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1685 lParam = *(LPARAM *)(mis + 1);
1686 mis16 = MapSL(lParam);
1687 mis16->itemWidth = (UINT16)mis->itemWidth;
1688 mis16->itemHeight = (UINT16)mis->itemHeight;
1689 HeapFree( GetProcessHeap(), 0, mis );
1692 case WM_GETMINMAXINFO:
1694 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1695 lParam = *(LPARAM *)(mmi + 1);
1696 MINMAXINFO32to16( mmi, MapSL(lParam));
1697 HeapFree( GetProcessHeap(), 0, mmi );
1702 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1703 lParam = *(LPARAM *)(cs + 1);
1704 MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1705 HeapFree( GetProcessHeap(), 0, cs );
1708 case WM_MDIGETACTIVE:
1709 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1710 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1714 NCCALCSIZE_PARAMS16 *nc16;
1715 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1716 lParam = *(LPARAM *)(nc + 1);
1717 nc16 = MapSL(lParam);
1718 nc16->rgrc[0].left = nc->rgrc[0].left;
1719 nc16->rgrc[0].top = nc->rgrc[0].top;
1720 nc16->rgrc[0].right = nc->rgrc[0].right;
1721 nc16->rgrc[0].bottom = nc->rgrc[0].bottom;
1724 nc16->rgrc[1].left = nc->rgrc[1].left;
1725 nc16->rgrc[1].top = nc->rgrc[1].top;
1726 nc16->rgrc[1].right = nc->rgrc[1].right;
1727 nc16->rgrc[1].bottom = nc->rgrc[1].bottom;
1728 nc16->rgrc[2].left = nc->rgrc[2].left;
1729 nc16->rgrc[2].top = nc->rgrc[2].top;
1730 nc16->rgrc[2].right = nc->rgrc[2].right;
1731 nc16->rgrc[2].bottom = nc->rgrc[2].bottom;
1734 WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1735 HeapFree( GetProcessHeap(), 0, nc->lppos );
1738 HeapFree( GetProcessHeap(), 0, nc );
1744 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1745 lParam = *(LPARAM *)(cs + 1);
1746 CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1748 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1749 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1751 HeapFree( GetProcessHeap(), 0, cs );
1754 case WM_WINDOWPOSCHANGING:
1755 case WM_WINDOWPOSCHANGED:
1757 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1758 lParam = *(LPARAM *)(wp + 1);
1759 WINDOWPOS32to16(wp, MapSL(lParam));
1760 HeapFree( GetProcessHeap(), 0, wp );
1766 LPMSG msg32 = (LPMSG)lParam;
1768 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1770 HeapFree( GetProcessHeap(), 0, msg32 );
1775 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1776 result = MAKELONG( HMENU_16(next->hmenuNext), HWND_16(next->hwndNext) );
1777 HeapFree( GetProcessHeap(), 0, next );
1785 /**********************************************************************
1786 * WINPROC_MapMsg16To32W
1788 * Map a message from 16- to 32-bit Unicode.
1789 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1791 INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1792 WPARAM *pwparam32, LPARAM *plparam )
1797 *pmsg32=(UINT)msg16;
1798 *pwparam32 = (WPARAM)wParam16;
1803 case WM_WININICHANGE:
1804 case WM_DEVMODECHANGE:
1805 case WM_ASKCBFORMATNAME:
1806 *plparam = (LPARAM)MapSL(*plparam);
1807 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1808 case WM_GETTEXTLENGTH:
1809 case CB_GETLBTEXTLEN:
1811 return 1; /* need to map result */
1815 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1816 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1817 sizeof(*cs) + sizeof(LPARAM) );
1819 CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1820 cs->lpszName = map_str_16_to_32W(cs16->lpszName);
1821 cs->lpszClass = map_str_16_to_32W(cs16->lpszClass);
1823 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1825 MDICREATESTRUCT16 *mdi_cs16;
1826 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)HeapAlloc(GetProcessHeap(), 0,
1830 HeapFree(GetProcessHeap(), 0, cs);
1833 mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs16->lpCreateParams);
1834 MDICREATESTRUCT16to32A(mdi_cs16, (MDICREATESTRUCTA *)mdi_cs);
1835 mdi_cs->szTitle = map_str_16_to_32W(mdi_cs16->szTitle);
1836 mdi_cs->szClass = map_str_16_to_32W(mdi_cs16->szClass);
1838 cs->lpCreateParams = mdi_cs;
1840 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1841 *plparam = (LPARAM)cs;
1846 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1847 MDICREATESTRUCTW *cs =
1848 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1849 sizeof(*cs) + sizeof(LPARAM) );
1851 MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1852 cs->szTitle = map_str_16_to_32W(cs16->szTitle);
1853 cs->szClass = map_str_16_to_32W(cs16->szClass);
1854 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1855 *plparam = (LPARAM)cs;
1861 LPMSG16 msg16 = MapSL(*plparam);
1862 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1864 if (!msg32) return -1;
1865 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1866 msg32->lParam = msg16->lParam;
1867 msg32->time = msg16->time;
1868 msg32->pt.x = msg16->pt.x;
1869 msg32->pt.y = msg16->pt.y;
1870 /* this is right, right? */
1871 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1872 &msg32->message,&msg32->wParam,
1873 &msg32->lParam)<0) {
1874 HeapFree( GetProcessHeap(), 0, msg32 );
1877 *plparam = (LPARAM)msg32;
1884 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1885 *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
1886 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1890 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1891 *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
1892 *plparam = (LPARAM)HMENU_32(HIWORD(*plparam));
1897 case WM_SYSDEADCHAR:
1899 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1903 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1905 default: /* No Unicode translation needed */
1906 return WINPROC_MapMsg16To32A( hwnd, msg16, wParam16, pmsg32,
1907 pwparam32, plparam );
1912 /**********************************************************************
1913 * WINPROC_UnmapMsg16To32W
1915 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1917 LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1924 case WM_GETTEXTLENGTH:
1925 case CB_GETLBTEXTLEN:
1927 case WM_ASKCBFORMATNAME:
1928 return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
1932 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1933 lParam = *(LPARAM *)(cs + 1);
1934 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1935 unmap_str_16_to_32W( cs->lpszName );
1936 unmap_str_16_to_32W( cs->lpszClass );
1938 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
1940 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs->lpCreateParams;
1941 unmap_str_16_to_32W( mdi_cs->szTitle );
1942 unmap_str_16_to_32W( mdi_cs->szClass );
1943 HeapFree(GetProcessHeap(), 0, cs->lpCreateParams);
1945 HeapFree( GetProcessHeap(), 0, cs );
1950 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1951 lParam = *(LPARAM *)(cs + 1);
1952 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1953 unmap_str_16_to_32W( cs->szTitle );
1954 unmap_str_16_to_32W( cs->szClass );
1955 HeapFree( GetProcessHeap(), 0, cs );
1961 LPMSG msg32 = (LPMSG)lParam;
1963 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1965 HeapFree( GetProcessHeap(), 0, msg32 );
1969 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1974 static HANDLE16 convert_handle_32_to_16(UINT src, unsigned int flags)
1977 UINT sz = GlobalSize((HANDLE)src);
1980 if (!(dst = GlobalAlloc16(flags, sz)))
1982 ptr32 = GlobalLock((HANDLE)src);
1983 ptr16 = GlobalLock16(dst);
1984 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
1985 GlobalUnlock((HANDLE)src);
1986 GlobalUnlock16(dst);
1992 /**********************************************************************
1993 * WINPROC_MapMsg32ATo16
1995 * Map a message from 32-bit Ansi to 16-bit.
1996 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1998 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1999 UINT16 *pmsg16, WPARAM16 *pwparam16,
2002 *pmsg16 = (UINT16)msg32;
2003 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2007 *pmsg16 = SBM_SETRANGE16;
2008 *plparam = MAKELPARAM(wParam32, *plparam);
2013 *pmsg16 = SBM_GETRANGE16;
2021 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
2030 case EM_SCROLLCARET:
2033 case EM_GETLINECOUNT:
2045 case EM_LINEFROMCHAR:
2046 case EM_SETTABSTOPS:
2047 case EM_SETPASSWORDCHAR:
2048 case EM_EMPTYUNDOBUFFER:
2049 case EM_GETFIRSTVISIBLELINE:
2050 case EM_SETREADONLY:
2051 case EM_SETWORDBREAKPROC:
2052 case EM_GETWORDBREAKPROC:
2053 case EM_GETPASSWORDCHAR:
2054 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
2059 case LB_DELETESTRING:
2060 case LB_GETANCHORINDEX:
2061 case LB_GETCARETINDEX:
2064 case LB_GETHORIZONTALEXTENT:
2065 case LB_GETITEMDATA:
2066 case LB_GETITEMHEIGHT:
2068 case LB_GETSELCOUNT:
2070 case LB_GETTOPINDEX:
2071 case LB_RESETCONTENT:
2072 case LB_SELITEMRANGE:
2073 case LB_SELITEMRANGEEX:
2074 case LB_SETANCHORINDEX:
2075 case LB_SETCARETINDEX:
2076 case LB_SETCOLUMNWIDTH:
2078 case LB_SETHORIZONTALEXTENT:
2079 case LB_SETITEMDATA:
2080 case LB_SETITEMHEIGHT:
2082 case LB_SETTOPINDEX:
2083 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2085 case CB_DELETESTRING:
2087 case CB_GETLBTEXTLEN:
2089 case CB_RESETCONTENT:
2093 case CB_SHOWDROPDOWN:
2094 case CB_SETITEMDATA:
2095 case CB_SETITEMHEIGHT:
2096 case CB_GETITEMHEIGHT:
2097 case CB_SETEXTENDEDUI:
2098 case CB_GETEXTENDEDUI:
2099 case CB_GETDROPPEDSTATE:
2100 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
2103 *pmsg16 = CB_GETEDITSEL16;
2108 case LB_FINDSTRINGEXACT:
2109 case LB_INSERTSTRING:
2110 case LB_SELECTSTRING:
2113 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
2114 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2119 case CB_FINDSTRINGEXACT:
2120 case CB_INSERTSTRING:
2121 case CB_SELECTSTRING:
2123 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
2124 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
2127 case LB_GETITEMRECT:
2129 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
2130 if (!rect) return -1;
2131 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
2132 *plparam = MapLS( rect );
2134 *pmsg16 = LB_GETITEMRECT16;
2136 case LB_GETSELITEMS:
2138 LPARAM *items; /* old LPARAM first, then *pwparam16 x INT16 entries */
2140 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
2141 if (!(items = HeapAlloc( GetProcessHeap(), 0,
2142 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
2143 *items++ = *plparam; /* Store the previous lParam */
2144 *plparam = MapLS( items );
2146 *pmsg16 = LB_GETSELITEMS16;
2148 case LB_SETTABSTOPS:
2153 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
2154 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
2155 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
2156 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
2157 *plparam = MapLS( stops );
2160 *pmsg16 = LB_SETTABSTOPS16;
2163 case CB_GETDROPPEDCONTROLRECT:
2165 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
2166 if (!rect) return -1;
2167 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
2168 *plparam = (LPARAM)MapLS(rect);
2170 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
2174 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
2175 *pmsg16 = LB_GETTEXT16;
2179 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
2180 *pmsg16 = CB_GETLBTEXT16;
2185 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
2186 *pmsg16 = EM_SETSEL16;
2193 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2197 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
2199 case WM_CTLCOLORMSGBOX:
2200 case WM_CTLCOLOREDIT:
2201 case WM_CTLCOLORLISTBOX:
2202 case WM_CTLCOLORBTN:
2203 case WM_CTLCOLORDLG:
2204 case WM_CTLCOLORSCROLLBAR:
2205 case WM_CTLCOLORSTATIC:
2206 *pmsg16 = WM_CTLCOLOR;
2207 *plparam = MAKELPARAM( (HWND16)*plparam,
2208 (WORD)msg32 - WM_CTLCOLORMSGBOX );
2210 case WM_COMPAREITEM:
2212 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
2213 COMPAREITEMSTRUCT16 *cis = HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16));
2214 if (!cis) return -1;
2215 cis->CtlType = (UINT16)cis32->CtlType;
2216 cis->CtlID = (UINT16)cis32->CtlID;
2217 cis->hwndItem = HWND_16( cis32->hwndItem );
2218 cis->itemID1 = (UINT16)cis32->itemID1;
2219 cis->itemData1 = cis32->itemData1;
2220 cis->itemID2 = (UINT16)cis32->itemID2;
2221 cis->itemData2 = cis32->itemData2;
2222 *plparam = MapLS( cis );
2227 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
2228 DELETEITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16) );
2229 if (!dis) return -1;
2230 dis->CtlType = (UINT16)dis32->CtlType;
2231 dis->CtlID = (UINT16)dis32->CtlID;
2232 dis->itemID = (UINT16)dis32->itemID;
2233 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
2234 : HWND_16( dis32->hwndItem );
2235 dis->itemData = dis32->itemData;
2236 *plparam = MapLS( dis );
2241 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
2242 DRAWITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16) );
2243 if (!dis) return -1;
2244 dis->CtlType = (UINT16)dis32->CtlType;
2245 dis->CtlID = (UINT16)dis32->CtlID;
2246 dis->itemID = (UINT16)dis32->itemID;
2247 dis->itemAction = (UINT16)dis32->itemAction;
2248 dis->itemState = (UINT16)dis32->itemState;
2249 dis->hwndItem = HWND_16( dis32->hwndItem );
2250 dis->hDC = HDC_16(dis32->hDC);
2251 dis->itemData = dis32->itemData;
2252 dis->rcItem.left = dis32->rcItem.left;
2253 dis->rcItem.top = dis32->rcItem.top;
2254 dis->rcItem.right = dis32->rcItem.right;
2255 dis->rcItem.bottom = dis32->rcItem.bottom;
2256 *plparam = MapLS( dis );
2259 case WM_MEASUREITEM:
2261 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
2262 MEASUREITEMSTRUCT16 *mis = HeapAlloc( GetProcessHeap(), 0, sizeof(*mis)+sizeof(LPARAM));
2263 if (!mis) return -1;
2264 mis->CtlType = (UINT16)mis32->CtlType;
2265 mis->CtlID = (UINT16)mis32->CtlID;
2266 mis->itemID = (UINT16)mis32->itemID;
2267 mis->itemWidth = (UINT16)mis32->itemWidth;
2268 mis->itemHeight = (UINT16)mis32->itemHeight;
2269 mis->itemData = mis32->itemData;
2270 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
2271 *plparam = MapLS( mis );
2274 case WM_GETMINMAXINFO:
2276 MINMAXINFO16 *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM) );
2277 if (!mmi) return -1;
2278 MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
2279 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
2280 *plparam = MapLS( mmi );
2284 case WM_ASKCBFORMATNAME:
2286 LPARAM *str; /* store LPARAM, then *pwparam16 char space */
2287 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
2288 if (!(str = HeapAlloc( GetProcessHeap(), 0, *pwparam16 + sizeof(LPARAM)))) return -1;
2289 *str++ = *plparam; /* Store the previous lParam */
2290 *plparam = MapLS( str );
2295 MDICREATESTRUCT16 *cs;
2296 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
2298 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2299 MDICREATESTRUCT32Ato16( cs32, cs );
2300 cs->szTitle = MapLS( cs32->szTitle );
2301 cs->szClass = MapLS( cs32->szClass );
2302 *plparam = MapLS( cs );
2305 case WM_MDIGETACTIVE:
2308 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
2309 (HMENU16)LOWORD(*plparam) );
2310 *pwparam16 = (*plparam == 0);
2313 if(HIWORD(wParam32) & MF_POPUP)
2316 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
2318 if((hmenu = GetSubMenu((HMENU)*plparam, *pwparam16)))
2319 *pwparam16=HMENU_16(hmenu);
2324 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2326 case WM_MDIACTIVATE:
2327 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
2329 *pwparam16 = ((HWND)*plparam == hwnd);
2330 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
2331 (HWND16)LOWORD(wParam32) );
2335 *pwparam16 = HWND_16( (HWND)wParam32 );
2341 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
2342 NCCALCSIZE_PARAMS16 *nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM));
2345 nc->rgrc[0].left = nc32->rgrc[0].left;
2346 nc->rgrc[0].top = nc32->rgrc[0].top;
2347 nc->rgrc[0].right = nc32->rgrc[0].right;
2348 nc->rgrc[0].bottom = nc32->rgrc[0].bottom;
2352 nc->rgrc[1].left = nc32->rgrc[1].left;
2353 nc->rgrc[1].top = nc32->rgrc[1].top;
2354 nc->rgrc[1].right = nc32->rgrc[1].right;
2355 nc->rgrc[1].bottom = nc32->rgrc[1].bottom;
2356 nc->rgrc[2].left = nc32->rgrc[2].left;
2357 nc->rgrc[2].top = nc32->rgrc[2].top;
2358 nc->rgrc[2].right = nc32->rgrc[2].right;
2359 nc->rgrc[2].bottom = nc32->rgrc[2].bottom;
2360 if (!(wp = HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16) )))
2362 HeapFree( GetProcessHeap(), 0, nc );
2365 WINDOWPOS32to16( nc32->lppos, wp );
2366 nc->lppos = MapLS( wp );
2368 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
2369 *plparam = MapLS( nc );
2376 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
2378 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2379 CREATESTRUCT32Ato16( cs32, cs );
2380 cs->lpszName = MapLS( cs32->lpszName );
2381 cs->lpszClass = MapLS( cs32->lpszClass );
2383 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2385 MDICREATESTRUCT16 *mdi_cs16;
2386 MDICREATESTRUCTA *mdi_cs = (MDICREATESTRUCTA *)cs32->lpCreateParams;
2387 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2390 HeapFree(GetProcessHeap(), 0, cs);
2393 MDICREATESTRUCT32Ato16(mdi_cs, mdi_cs16);
2394 mdi_cs16->szTitle = MapLS( mdi_cs->szTitle );
2395 mdi_cs16->szClass = MapLS( mdi_cs->szClass );
2396 cs->lpCreateParams = MapLS( mdi_cs16 );
2398 *plparam = MapLS( cs );
2401 case WM_PARENTNOTIFY:
2402 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
2403 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
2404 /* else nothing to do */
2407 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
2410 case WM_WININICHANGE:
2411 case WM_DEVMODECHANGE:
2412 *plparam = MapLS( (LPSTR)*plparam );
2414 case WM_WINDOWPOSCHANGING:
2415 case WM_WINDOWPOSCHANGED:
2417 WINDOWPOS16 *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
2419 WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2420 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2421 *plparam = MapLS( wp );
2426 LPMSG msg32 = (LPMSG) *plparam;
2427 LPMSG16 msg16 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16) );
2429 if (!msg16) return -1;
2430 msg16->hwnd = HWND_16( msg32->hwnd );
2431 msg16->lParam = msg32->lParam;
2432 msg16->time = msg32->time;
2433 msg16->pt.x = msg32->pt.x;
2434 msg16->pt.y = msg32->pt.y;
2435 /* this is right, right? */
2436 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2437 &msg16->message,&msg16->wParam, &msg16->lParam)<0)
2439 HeapFree( GetProcessHeap(), 0, msg16 );
2442 *plparam = MapLS( msg16 );
2447 case WM_ACTIVATEAPP:
2448 if (*plparam) *plparam = HTASK_16( (HANDLE)*plparam );
2452 MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
2453 *plparam = (LPARAM)next->hmenuIn;
2456 case WM_PAINTCLIPBOARD:
2457 case WM_SIZECLIPBOARD:
2458 FIXME_(msg)("message %04x needs translation\n", msg32 );
2460 /* following messages should not be sent to 16-bit apps */
2463 case WM_CAPTURECHANGED:
2464 case WM_STYLECHANGING:
2465 case WM_STYLECHANGED:
2467 case WM_DDE_INITIATE:
2468 case WM_DDE_TERMINATE:
2469 case WM_DDE_UNADVISE:
2470 case WM_DDE_REQUEST:
2471 *pwparam16 = HWND_16((HWND)wParam32);
2480 *pwparam16 = HWND_16((HWND)wParam32);
2481 UnpackDDElParam(msg32, *plparam, &lo32, &hi);
2482 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE)))
2484 *plparam = MAKELPARAM(lo16, hi);
2486 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2493 *pwparam16 = HWND_16((HWND)wParam32);
2495 UnpackDDElParam(msg32, *plparam, &lo, &hi);
2497 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
2498 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
2504 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2509 break; /* atom, nothing to do */
2511 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi);
2514 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
2517 *plparam = MAKELPARAM(lo, hi);
2519 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2520 case WM_DDE_EXECUTE:
2521 *plparam = convert_handle_32_to_16(*plparam, GMEM_DDESHARE);
2522 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2523 default: /* No translation needed */
2529 /**********************************************************************
2530 * WINPROC_UnmapMsg32ATo16
2532 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2534 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2540 *(LPINT)wParam = LOWORD(p16->lResult);
2541 *(LPINT)lParam = HIWORD(p16->lResult);
2548 case LB_FINDSTRINGEXACT:
2549 case LB_INSERTSTRING:
2550 case LB_SELECTSTRING:
2554 case CB_FINDSTRINGEXACT:
2555 case CB_INSERTSTRING:
2556 case CB_SELECTSTRING:
2560 case WM_WININICHANGE:
2561 case WM_DEVMODECHANGE:
2562 UnMapLS( (SEGPTR)p16->lParam );
2564 case LB_SETTABSTOPS:
2565 case WM_COMPAREITEM:
2569 void *ptr = MapSL( p16->lParam );
2570 UnMapLS( p16->lParam );
2571 HeapFree( GetProcessHeap(), 0, ptr );
2574 case CB_GETDROPPEDCONTROLRECT:
2575 case LB_GETITEMRECT:
2578 RECT16 *rect = MapSL(p16->lParam);
2579 UnMapLS( p16->lParam );
2580 p16->lParam = *(LPARAM *)(rect + 1);
2581 r32 = (RECT *)p16->lParam;
2582 r32->left = rect->left;
2583 r32->top = rect->top;
2584 r32->right = rect->right;
2585 r32->bottom = rect->bottom;
2586 HeapFree( GetProcessHeap(), 0, rect );
2589 case LB_GETSELITEMS:
2592 LPINT16 items = MapSL(p16->lParam);
2593 UnMapLS( p16->lParam );
2594 p16->lParam = *((LPARAM *)items - 1);
2595 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2596 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
2602 *((PUINT)(wParam)) = LOWORD(p16->lResult);
2604 *((PUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2607 case WM_MEASUREITEM:
2609 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2610 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2611 mis32->itemWidth = mis->itemWidth;
2612 mis32->itemHeight = mis->itemHeight;
2613 UnMapLS( p16->lParam );
2614 HeapFree( GetProcessHeap(), 0, mis );
2617 case WM_GETMINMAXINFO:
2619 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2620 UnMapLS( p16->lParam );
2621 p16->lParam = *(LPARAM *)(mmi + 1);
2622 MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2623 HeapFree( GetProcessHeap(), 0, mmi );
2627 case WM_ASKCBFORMATNAME:
2629 LPSTR str = MapSL(p16->lParam);
2630 UnMapLS( p16->lParam );
2631 p16->lParam = *((LPARAM *)str - 1);
2632 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2633 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2638 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2639 UnMapLS( cs->szTitle );
2640 UnMapLS( cs->szClass );
2641 UnMapLS( p16->lParam );
2642 HeapFree( GetProcessHeap(), 0, cs );
2645 case WM_MDIGETACTIVE:
2646 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2647 p16->lResult = (LRESULT)WIN_Handle32( LOWORD(p16->lResult) );
2651 NCCALCSIZE_PARAMS *nc32;
2652 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2653 UnMapLS( p16->lParam );
2654 p16->lParam = *(LPARAM *)(nc + 1);
2655 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2656 nc32->rgrc[0].left = nc->rgrc[0].left;
2657 nc32->rgrc[0].top = nc->rgrc[0].top;
2658 nc32->rgrc[0].right = nc->rgrc[0].right;
2659 nc32->rgrc[0].bottom = nc->rgrc[0].bottom;
2662 WINDOWPOS16 *pos = MapSL(nc->lppos);
2663 UnMapLS( nc->lppos );
2664 nc32->rgrc[1].left = nc->rgrc[1].left;
2665 nc32->rgrc[1].top = nc->rgrc[1].top;
2666 nc32->rgrc[1].right = nc->rgrc[1].right;
2667 nc32->rgrc[1].bottom = nc->rgrc[1].bottom;
2668 nc32->rgrc[2].left = nc->rgrc[2].left;
2669 nc32->rgrc[2].top = nc->rgrc[2].top;
2670 nc32->rgrc[2].right = nc->rgrc[2].right;
2671 nc32->rgrc[2].bottom = nc->rgrc[2].bottom;
2672 WINDOWPOS16to32( pos, nc32->lppos );
2673 HeapFree( GetProcessHeap(), 0, pos );
2675 HeapFree( GetProcessHeap(), 0, nc );
2681 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2682 UnMapLS( p16->lParam );
2683 UnMapLS( cs->lpszName );
2684 UnMapLS( cs->lpszClass );
2685 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2687 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2688 UnMapLS( cs->lpCreateParams );
2689 UnMapLS( mdi_cs16->szTitle );
2690 UnMapLS( mdi_cs16->szClass );
2691 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2693 HeapFree( GetProcessHeap(), 0, cs );
2696 case WM_WINDOWPOSCHANGING:
2697 case WM_WINDOWPOSCHANGED:
2699 WINDOWPOS16 *wp = MapSL(p16->lParam);
2700 UnMapLS( p16->lParam );
2701 p16->lParam = *(LPARAM *)(wp + 1);
2702 WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2703 HeapFree( GetProcessHeap(), 0, wp );
2707 UnMapLS(p16->lParam);
2712 LPMSG16 msg16 = MapSL(p16->lParam);
2714 UnMapLS( p16->lParam );
2715 msgp16.wParam=msg16->wParam;
2716 msgp16.lParam=msg16->lParam;
2717 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2718 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2720 HeapFree( GetProcessHeap(), 0, msg16 );
2725 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2726 next->hmenuNext = HMENU_32( LOWORD(p16->lResult) );
2727 next->hwndNext = WIN_Handle32( HIWORD(p16->lResult) );
2735 /**********************************************************************
2736 * WINPROC_MapMsg32WTo16
2738 * Map a message from 32-bit Unicode to 16-bit.
2739 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2741 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2742 UINT16 *pmsg16, WPARAM16 *pwparam16,
2748 *pmsg16 = LOWORD(msg32);
2749 *pwparam16 = LOWORD(wParam32);
2754 case LB_FINDSTRINGEXACT:
2755 case LB_INSERTSTRING:
2756 case LB_SELECTSTRING:
2759 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2760 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2765 case CB_FINDSTRINGEXACT:
2766 case CB_INSERTSTRING:
2767 case CB_SELECTSTRING:
2769 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2770 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2777 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2779 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2780 CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2781 cs->lpszName = map_str_32W_to_16( cs32->lpszName );
2782 cs->lpszClass = map_str_32W_to_16( cs32->lpszClass );
2784 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2786 MDICREATESTRUCT16 *mdi_cs16;
2787 MDICREATESTRUCTW *mdi_cs = (MDICREATESTRUCTW *)cs32->lpCreateParams;
2788 mdi_cs16 = HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16));
2791 HeapFree(GetProcessHeap(), 0, cs);
2794 MDICREATESTRUCT32Ato16((MDICREATESTRUCTA *)mdi_cs, mdi_cs16);
2795 mdi_cs16->szTitle = map_str_32W_to_16(mdi_cs->szTitle);
2796 mdi_cs16->szClass = map_str_32W_to_16(mdi_cs->szClass);
2797 cs->lpCreateParams = MapLS(mdi_cs16);
2799 *plparam = MapLS(cs);
2804 MDICREATESTRUCT16 *cs;
2805 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2807 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2808 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2809 cs->szTitle = map_str_32W_to_16( cs32->szTitle );
2810 cs->szClass = map_str_32W_to_16( cs32->szClass );
2811 *plparam = MapLS(cs);
2815 case WM_WININICHANGE:
2816 case WM_DEVMODECHANGE:
2817 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2820 if ( WINPROC_TestLBForStr( hwnd ))
2822 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2823 if (!str) return -1;
2824 *pmsg16 = LB_GETTEXT16;
2825 *plparam = (LPARAM)MapLS(str);
2829 if ( WINPROC_TestCBForStr( hwnd ))
2831 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2832 if (!str) return -1;
2833 *pmsg16 = CB_GETLBTEXT16;
2834 *plparam = (LPARAM)MapLS(str);
2839 wch = LOWORD(wParam32);
2840 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2842 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2845 wch = LOWORD(wParam32);
2846 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2848 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2853 case WM_SYSDEADCHAR:
2855 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2863 if (WideCharToMultiByte( CP_ACP, 0, &wch, 1, ch, 2, NULL, NULL ) == 2)
2864 *pwparam16 = (ch[0] << 8) | ch[1];
2870 default: /* No Unicode translation needed (?) */
2871 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2872 pwparam16, plparam );
2877 /**********************************************************************
2878 * WINPROC_UnmapMsg32WTo16
2880 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2882 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2889 case LB_FINDSTRINGEXACT:
2890 case LB_INSERTSTRING:
2891 case LB_SELECTSTRING:
2896 case CB_FINDSTRINGEXACT:
2897 case CB_INSERTSTRING:
2898 case CB_SELECTSTRING:
2901 case WM_WININICHANGE:
2902 case WM_DEVMODECHANGE:
2903 unmap_str_32W_to_16( p16->lParam );
2908 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2909 UnMapLS( p16->lParam );
2910 unmap_str_32W_to_16( cs->lpszName );
2911 unmap_str_32W_to_16( cs->lpszClass );
2913 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
2915 MDICREATESTRUCT16 *mdi_cs16 = (MDICREATESTRUCT16 *)MapSL(cs->lpCreateParams);
2916 UnMapLS( cs->lpCreateParams );
2917 unmap_str_32W_to_16(mdi_cs16->szTitle);
2918 unmap_str_32W_to_16(mdi_cs16->szClass);
2919 HeapFree(GetProcessHeap(), 0, mdi_cs16);
2921 HeapFree( GetProcessHeap(), 0, cs );
2926 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2927 UnMapLS( p16->lParam );
2928 unmap_str_32W_to_16( cs->szTitle );
2929 unmap_str_32W_to_16( cs->szClass );
2930 HeapFree( GetProcessHeap(), 0, cs );
2934 case WM_ASKCBFORMATNAME:
2936 LPSTR str = MapSL(p16->lParam);
2937 UnMapLS( p16->lParam );
2938 p16->lParam = *((LPARAM *)str - 1);
2939 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2940 p16->lResult = strlenW( (LPWSTR)p16->lParam );
2941 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2945 if ( WINPROC_TestLBForStr( hwnd ))
2947 LPSTR str = MapSL(p16->lParam);
2948 UnMapLS( p16->lParam );
2949 p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
2950 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2954 if ( WINPROC_TestCBForStr( hwnd ))
2956 LPSTR str = MapSL(p16->lParam);
2957 UnMapLS( p16->lParam );
2958 p16->lResult = MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff ) - 1;
2959 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2963 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2969 /**********************************************************************
2970 * WINPROC_CallProc32ATo32W
2972 * Call a window procedure, translating args from Ansi to Unicode.
2974 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2975 UINT msg, WPARAM wParam,
2981 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2982 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2984 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2985 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2986 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2989 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2990 if (unmap) result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
2995 /**********************************************************************
2996 * WINPROC_CallProc32WTo32A_fast
2999 static BOOL WINPROC_CallProc32WTo32A_fast( WNDPROC func, HWND hwnd,
3000 UINT msg, WPARAM wParam,
3001 LPARAM lParam, LRESULT *result )
3007 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
3011 char *cls = buffer, *name;
3012 CREATESTRUCTW *csW = (CREATESTRUCTW *)lParam;
3013 CREATESTRUCTA csA = *(CREATESTRUCTA *)csW;
3014 DWORD name_lenA, name_lenW, class_lenA, class_lenW;
3016 class_lenW = strlenW(csW->lpszClass) * sizeof(WCHAR);
3017 RtlUnicodeToMultiByteSize(&class_lenA, csW->lpszClass, class_lenW);
3021 name_lenW = strlenW(csW->lpszName) * sizeof(WCHAR);
3022 RtlUnicodeToMultiByteSize(&name_lenA, csW->lpszName, name_lenW);
3025 name_lenW = name_lenA = 0;
3027 if (class_lenA + name_lenA + 2 > sizeof(buffer))
3029 cls = HeapAlloc(GetProcessHeap(), 0, class_lenA + name_lenA + 2);
3030 if (!cls) return FALSE;
3033 RtlUnicodeToMultiByteN(cls, class_lenA, NULL, csW->lpszClass, class_lenW);
3034 cls[class_lenA] = 0;
3035 csA.lpszClass = cls;
3039 name = cls + class_lenA + 1;
3040 RtlUnicodeToMultiByteN(name, name_lenA, NULL, csW->lpszName, name_lenW);
3041 name[name_lenA] = 0;
3042 csA.lpszName = name;
3045 if (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD)
3047 MDICREATESTRUCTA mdi_cs;
3049 mdi_cs = *(MDICREATESTRUCTA *)csW->lpCreateParams;
3050 mdi_cs.szTitle = csA.lpszName;
3051 mdi_cs.szClass = csA.lpszClass;
3052 csA.lpCreateParams = &mdi_cs;
3055 lParam = (LPARAM)&csA;
3056 *result = WINPROC_CallWndProc(func, hwnd, msg, wParam, lParam);
3058 if (cls != buffer) HeapFree(GetProcessHeap(), 0, cls);
3067 /**********************************************************************
3068 * WINPROC_CallProc32WTo32A
3070 * Call a window procedure, translating args from Unicode to Ansi.
3072 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
3073 UINT msg, WPARAM wParam,
3079 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3080 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3082 if (WINPROC_CallProc32WTo32A_fast( func, hwnd, msg, wParam, lParam, &result ))
3085 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
3086 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
3087 SPY_GetMsgName(msg, hwnd), wParam, lParam );
3090 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3091 if( unmap ) result = WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam, result );
3096 /**********************************************************************
3097 * __wine_call_wndproc_32A (USER.1010)
3099 LRESULT WINAPI __wine_call_wndproc_32A( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
3105 HWND hwnd32 = WIN_Handle32( hwnd );
3107 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3108 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
3110 if (WINPROC_MapMsg16To32A( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
3112 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
3113 return WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, result );
3117 /**********************************************************************
3118 * __wine_call_wndproc_32W (USER.1011)
3120 LRESULT WINAPI __wine_call_wndproc_32W( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
3126 HWND hwnd32 = WIN_Handle32( hwnd );
3128 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3129 func, hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
3131 if (WINPROC_MapMsg16To32W( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
3133 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
3134 return WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, result );
3138 /**********************************************************************
3139 * WINPROC_CallProc32ATo16
3141 * Call a 16-bit window procedure, translating the 32-bit args.
3143 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
3144 UINT msg, WPARAM wParam,
3150 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3151 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3153 mp16.lParam = lParam;
3154 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
3156 mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
3157 mp16.wParam, mp16.lParam );
3158 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
3159 return mp16.lResult;
3163 /**********************************************************************
3164 * WINPROC_CallProc32WTo16
3166 * Call a 16-bit window procedure, translating the 32-bit args.
3168 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
3169 UINT msg, WPARAM wParam,
3175 TRACE_(msg)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
3176 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
3178 mp16.lParam = lParam;
3179 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
3180 &mp16.lParam ) == -1)
3182 mp16.lResult = WINPROC_CallWndProc16( func, HWND_16(hwnd), msg16,
3183 mp16.wParam, mp16.lParam );
3184 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
3185 return mp16.lResult;
3189 /**********************************************************************
3190 * CallWindowProc (USER.122)
3192 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
3193 WPARAM16 wParam, LPARAM lParam )
3197 if (!func) return 0;
3199 if (!(proc = WINPROC_GetPtr( (WNDPROC)func )))
3200 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
3203 func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_16 );
3204 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
3210 if (!proc->thunk.t_from32.proc) return 0;
3211 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
3212 hwnd, msg, wParam, lParam );
3214 if (!proc->thunk.t_from16.proc) return 0;
3215 return __wine_call_wndproc_32A( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
3217 if (!proc->thunk.t_from16.proc) return 0;
3218 return __wine_call_wndproc_32W( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
3220 WARN_(relay)("Invalid proc %p\n", proc );
3226 /**********************************************************************
3227 * CallWindowProcA (USER32.@)
3229 * The CallWindowProc() function invokes the windows procedure _func_,
3230 * with _hwnd_ as the target window, the message specified by _msg_, and
3231 * the message parameters _wParam_ and _lParam_.
3233 * Some kinds of argument conversion may be done, I'm not sure what.
3235 * CallWindowProc() may be used for windows subclassing. Use
3236 * SetWindowLong() to set a new windows procedure for windows of the
3237 * subclass, and handle subclassed messages in the new windows
3238 * procedure. The new windows procedure may then use CallWindowProc()
3239 * with _func_ set to the parent class's windows procedure to dispatch
3240 * the message to the superclass.
3244 * The return value is message dependent.
3250 LRESULT WINAPI CallWindowProcA(
3251 WNDPROC func, /* [in] window procedure */
3252 HWND hwnd, /* [in] target window */
3253 UINT msg, /* [in] message */
3254 WPARAM wParam, /* [in] message dependent parameter */
3255 LPARAM lParam /* [in] message dependent parameter */
3259 if (!func) return 0;
3261 if (!(proc = WINPROC_GetPtr( func )))
3262 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3265 func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_32A );
3266 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3272 if (!proc->thunk.t_from32.proc) return 0;
3273 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
3274 hwnd, msg, wParam, lParam );
3276 if (!proc->thunk.t_from16.proc) return 0;
3277 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
3278 hwnd, msg, wParam, lParam );
3280 if (!proc->thunk.t_from16.proc) return 0;
3281 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
3282 hwnd, msg, wParam, lParam );
3284 WARN_(relay)("Invalid proc %p\n", proc );
3290 /**********************************************************************
3291 * CallWindowProcW (USER32.@)
3293 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
3294 WPARAM wParam, LPARAM lParam )
3298 if (!func) return 0;
3300 if (!(proc = WINPROC_GetPtr( (WNDPROC)func )))
3301 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3304 func = WINPROC_GetProc( (WNDPROC)proc, WIN_PROC_32W );
3305 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
3311 if (!proc->thunk.t_from32.proc) return 0;
3312 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
3313 hwnd, msg, wParam, lParam );
3315 if (!proc->thunk.t_from16.proc) return 0;
3316 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
3317 hwnd, msg, wParam, lParam );
3319 if (!proc->thunk.t_from16.proc) return 0;
3320 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
3321 hwnd, msg, wParam, lParam );
3323 WARN_(relay)("Invalid proc %p\n", proc );