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
29 #include "wine/winbase16.h"
30 #include "wine/winuser16.h"
31 #include "stackframe.h"
32 #include "selectors.h"
38 #include "wine/debug.h"
43 WINE_DECLARE_DEBUG_CHANNEL(msg);
44 WINE_DECLARE_DEBUG_CHANNEL(relay);
45 WINE_DECLARE_DEBUG_CHANNEL(win);
49 /* Window procedure 16-to-32-bit thunk */
52 BYTE popl_eax; /* popl %eax (return address) */
53 BYTE pushl_func; /* pushl $proc */
55 BYTE pushl_eax; /* pushl %eax */
56 BYTE ljmp; /* ljmp relay*/
57 DWORD relay_offset; /* __wine_call_wndproc_32A/W */
59 } WINPROC_THUNK_FROM16;
61 /* Window procedure 32-to-16-bit thunk */
64 BYTE popl_eax; /* popl %eax (return address) */
65 BYTE pushl_func; /* pushl $proc */
67 BYTE pushl_eax; /* pushl %eax */
68 BYTE jmp; /* jmp relay (relative jump)*/
69 void (*relay)(); /* WINPROC_CallProc32ATo16() */
70 } WINPROC_THUNK_FROM32;
72 /* Simple jmp to call 32-bit procedure directly */
75 BYTE jmp; /* jmp proc (relative jump) */
82 WINPROC_THUNK_FROM16 t_from16;
83 WINPROC_THUNK_FROM32 t_from32;
86 typedef struct tagWINDOWPROC
88 WINPROC_THUNK thunk; /* Thunk */
89 WINPROC_JUMP jmp; /* Jump */
90 struct tagWINDOWPROC *next; /* Next window proc */
91 UINT magic; /* Magic number */
92 WINDOWPROCTYPE type; /* Function type */
93 WINDOWPROCUSER user; /* Function user */
96 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
98 #define WINPROC_THUNKPROC(pproc) \
99 (((pproc)->type == WIN_PROC_16) ? \
100 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
101 (WNDPROC16)((pproc)->thunk.t_from16.proc))
103 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
104 UINT msg, WPARAM wParam,
106 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
107 UINT msg, WPARAM wParam,
110 static HANDLE WinProcHeap;
111 static WORD WinProcSel;
114 /**********************************************************************
117 BOOL WINPROC_Init(void)
119 WinProcHeap = HeapCreate( 0, 0x10000, 0x10000 );
120 WinProcSel = SELECTOR_AllocBlock( (void *)WinProcHeap, 0x10000,
121 WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
122 if (!WinProcHeap || !WinProcSel)
124 WARN_(relay)("Unable to create winproc heap\n" );
132 /* Some window procedures modify register they shouldn't, or are not
133 * properly declared stdcall; so we need a small assembly wrapper to
135 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
136 WPARAM wParam, LPARAM lParam );
137 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
147 "movl 8(%ebp),%eax\n\t"
149 "leal -12(%ebp),%esp\n\t"
156 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
157 WPARAM wParam, LPARAM lParam )
159 return proc( hwnd, msg, wParam, lParam );
161 #endif /* __i386__ */
163 /**********************************************************************
164 * WINPROC_CallWndProc32
166 * Call a 32-bit WndProc.
168 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
169 WPARAM wParam, LPARAM lParam )
174 hwnd = WIN_GetFullHandle( hwnd );
176 DPRINTF( "%08lx:Call window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
177 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam );
178 /* To avoid any deadlocks, all the locks on the windows structures
179 must be suspended before the control is passed to the application */
180 iWndsLocks = WIN_SuspendWndsLock();
181 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
182 WIN_RestoreWndsLock(iWndsLocks);
185 DPRINTF( "%08lx:Ret window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
186 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
190 /***********************************************************************
191 * WINPROC_CallWndProc16
193 * Call a 16-bit window procedure
195 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
196 UINT16 msg, WPARAM16 wParam,
203 TEB *teb = NtCurrentTeb();
206 /* Window procedures want ax = hInstance, ds = es = ss */
208 memset(&context, '\0', sizeof(context));
209 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
210 if (!(context.Eax = GetWindowWord16( hwnd, GWL_HINSTANCE ))) context.Eax = context.SegDs;
211 context.SegCs = SELECTOROF(proc);
212 context.Eip = OFFSETOF(proc);
213 context.Ebp = OFFSETOF(teb->cur_stack)
214 + (WORD)&((STACK16FRAME*)0)->bp;
218 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
219 work if structures passed in lParam are placed in the stack/data
220 segment. Programmers easily make the mistake of converting lParam
221 to a near rather than a far pointer, since Windows apparently
222 allows this. We copy the structures to the 16 bit stack; this is
223 ugly but makes these programs work. */
228 offset = sizeof(CREATESTRUCT16); break;
230 offset = sizeof(DRAWITEMSTRUCT16); break;
232 offset = sizeof(COMPAREITEMSTRUCT16); break;
236 void *s = MapSL(lParam);
237 lParam = stack16_push( offset );
238 memcpy( MapSL(lParam), s, offset );
242 iWndsLocks = WIN_SuspendWndsLock();
244 args = (WORD *)THREAD_STACK16(teb) - 5;
245 args[0] = LOWORD(lParam);
246 args[1] = HIWORD(lParam);
251 wine_call_to_16_regs_short( &context, 5 * sizeof(WORD) );
252 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
253 if (offset) stack16_pop( offset );
255 WIN_RestoreWndsLock(iWndsLocks);
261 /**********************************************************************
264 * Return a pointer to the win proc.
266 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
271 /* ptr cannot be < 64K */
272 if (!HIWORD(handle)) return NULL;
274 /* Check for a linear pointer */
276 ptr = (BYTE *)handle;
277 /* First check if it is the jmp address */
278 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->jmp);
279 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
281 /* Now it must be the thunk address */
282 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
283 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
286 /* Check for a segmented pointer */
288 if (!IsBadReadPtr16( (SEGPTR)handle, sizeof(proc->thunk) ))
290 ptr = MapSL( (SEGPTR)handle );
291 /* It must be the thunk address */
292 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
293 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
301 /**********************************************************************
302 * WINPROC_AllocWinProc
304 * Allocate a new window procedure.
306 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
307 WINDOWPROCUSER user )
309 static FARPROC16 relay_32A, relay_32W;
311 WINDOWPROC *proc, *oldproc;
313 /* Allocate a window procedure */
315 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
317 /* Check if the function is already a win proc */
319 if ((oldproc = WINPROC_GetPtr( func )))
328 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
329 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
330 proc->thunk.t_from32.proc = func;
331 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
332 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
333 proc->thunk.t_from32.relay = /* relative jump */
334 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
335 (DWORD)(&proc->thunk.t_from32.relay + 1));
338 if (!relay_32A) relay_32A = GetProcAddress16( GetModuleHandle16("user"),
339 "__wine_call_wndproc_32A" );
340 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
341 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
342 proc->thunk.t_from16.proc = (WNDPROC)func;
343 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
344 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
345 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32A);
346 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32A);
347 proc->jmp.jmp = 0xe9;
348 /* Fixup relative jump */
349 proc->jmp.proc = (WNDPROC)((DWORD)func - (DWORD)(&proc->jmp.proc + 1));
352 if (!relay_32W) relay_32W = GetProcAddress16( GetModuleHandle16("user"),
353 "__wine_call_wndproc_32W" );
354 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
355 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
356 proc->thunk.t_from16.proc = (WNDPROC)func;
357 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
358 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
359 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32W);
360 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32W);
361 proc->jmp.jmp = 0xe9;
362 /* Fixup relative jump */
363 proc->jmp.proc = (WNDPROC)((DWORD)func - (DWORD)(&proc->jmp.proc + 1));
366 /* Should not happen */
369 proc->magic = WINPROC_MAGIC;
374 TRACE_(win)("(%08x,%d): returning %08x\n",
375 (UINT)func, type, (UINT)proc );
380 /**********************************************************************
383 * Get a window procedure pointer that can be passed to the Windows program.
385 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
387 WINDOWPROC *ptr = (WINDOWPROC *)proc;
389 if (!proc) return NULL;
390 if (type == WIN_PROC_16) /* We want a 16:16 address */
392 if (ptr->type == WIN_PROC_16)
393 return ptr->thunk.t_from32.proc;
395 return (WNDPROC16)MAKESEGPTR( WinProcSel, (char *)&ptr->thunk - (char *)WinProcHeap );
397 else /* We want a 32-bit address */
399 if (ptr->type == WIN_PROC_16)
400 return (WNDPROC16)&ptr->thunk;
401 else if (type != ptr->type)
402 /* Have to return the jmp address if types don't match */
403 return (WNDPROC16)&ptr->jmp;
405 /* Some Win16 programs want to get back the proc they set */
406 return (WNDPROC16)ptr->thunk.t_from16.proc;
411 /**********************************************************************
414 * Set the window procedure for a window or class. There are
415 * three tree classes of winproc callbacks:
417 * 1) class -> wp - not subclassed
418 * class -> wp -> wp -> wp -> wp - SetClassLong()
420 * 2) window -' / - not subclassed
421 * window -> wp -> wp ' - SetWindowLong()
423 * 3) timer -> wp - SetTimer()
425 * Initially, winproc of the window points to the current winproc
426 * thunk of its class. Subclassing prepends a new thunk to the
427 * window winproc chain at the head of the list. Thus, window thunk
428 * list includes class thunks and the latter are preserved when the
429 * window is destroyed.
432 BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
433 WINDOWPROCTYPE type, WINDOWPROCUSER user )
435 BOOL bRecycle = FALSE;
436 WINDOWPROC *proc, **ppPrev;
438 /* Check if function is already in the list */
440 ppPrev = (WINDOWPROC **)pFirst;
441 proc = WINPROC_GetPtr( func );
448 if ((*ppPrev)->user != user)
450 /* terminal thunk is being restored */
452 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
453 *(WINDOWPROC **)pFirst = *ppPrev;
462 if (((*ppPrev)->type == type) &&
463 (func == WINPROC_THUNKPROC(*ppPrev)))
465 if((*ppPrev)->user == user)
471 WINPROC_FreeProc( *ppPrev, user );
478 /* WPF_CLASS thunk terminates window thunk list */
479 if ((*ppPrev)->user != user) break;
480 ppPrev = &(*ppPrev)->next;
485 /* Extract this thunk from the list */
487 *ppPrev = proc->next;
489 else /* Allocate a new one */
491 if (proc) /* Was already a win proc */
494 func = WINPROC_THUNKPROC(proc);
496 proc = WINPROC_AllocWinProc( func, type, user );
497 if (!proc) return FALSE;
500 /* Add the win proc at the head of the list */
502 TRACE_(win)("(%08x,%08x,%d): res=%08x\n",
503 (UINT)*pFirst, (UINT)func, type, (UINT)proc );
504 proc->next = *(WINDOWPROC **)pFirst;
505 *(WINDOWPROC **)pFirst = proc;
510 /**********************************************************************
513 * Free a list of win procs.
515 void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
519 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
520 if (((WINDOWPROC *)proc)->user != user) break;
521 TRACE_(win)("freeing %08x\n", (UINT)proc);
522 HeapFree( WinProcHeap, 0, proc );
528 /**********************************************************************
529 * WINPROC_GetProcType
531 * Return the window procedure type.
533 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
536 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
537 return WIN_PROC_INVALID;
538 return ((WINDOWPROC *)proc)->type;
540 /**********************************************************************
541 * WINPROC_TestCBForStr
543 * Return TRUE if the lparam is a string
545 inline static BOOL WINPROC_TestCBForStr( HWND hwnd )
547 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
548 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
550 /**********************************************************************
551 * WINPROC_TestLBForStr
553 * Return TRUE if the lparam is a string
555 inline static BOOL WINPROC_TestLBForStr( HWND hwnd )
557 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
558 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
561 /**********************************************************************
562 * WINPROC_MapMsg32ATo32W
564 * Map a message from Ansi to Unicode.
565 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
568 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
569 * the first four bytes are the handle of the icon
570 * when the WM_SETTEXT message has been used to set the icon
572 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
577 case WM_ASKCBFORMATNAME:
579 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
580 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
582 *ptr++ = *plparam; /* Store previous lParam */
583 *plparam = (LPARAM)ptr;
586 /* lparam is string (0-terminated) */
588 case WM_WININICHANGE:
589 case WM_DEVMODECHANGE:
594 if(!*plparam) return 0;
595 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
596 return (*plparam ? 1 : -1);
597 case WM_GETTEXTLENGTH:
598 case CB_GETLBTEXTLEN:
600 return 1; /* need to map result */
605 { CREATESTRUCTW cs; /* new structure */
606 LPCWSTR lpszName; /* allocated Name */
607 LPCWSTR lpszClass; /* allocated Class */
610 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
612 xs->cs = *(CREATESTRUCTW *)*plparam;
613 if (HIWORD(xs->cs.lpszName))
614 xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
615 (LPCSTR)xs->cs.lpszName );
616 if (HIWORD(xs->cs.lpszClass))
617 xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
618 (LPCSTR)xs->cs.lpszClass );
619 *plparam = (LPARAM)xs;
624 MDICREATESTRUCTW *cs =
625 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
627 *cs = *(MDICREATESTRUCTW *)*plparam;
628 if (HIWORD(cs->szClass))
629 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
630 (LPCSTR)cs->szClass );
631 if (HIWORD(cs->szTitle))
632 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
633 (LPCSTR)cs->szTitle );
634 *plparam = (LPARAM)cs;
640 case LB_INSERTSTRING:
642 case LB_FINDSTRINGEXACT:
643 case LB_SELECTSTRING:
644 if(!*plparam) return 0;
645 if ( WINPROC_TestLBForStr( hwnd ))
646 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
647 return (*plparam ? 1 : -1);
649 case LB_GETTEXT: /* FIXME: fixed sized buffer */
650 { if ( WINPROC_TestLBForStr( hwnd ))
651 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
653 *ptr++ = *plparam; /* Store previous lParam */
654 *plparam = (LPARAM)ptr;
661 case CB_INSERTSTRING:
662 case CB_FINDSTRINGEXACT:
664 case CB_SELECTSTRING:
665 if(!*plparam) return 0;
666 if ( WINPROC_TestCBForStr( hwnd ))
667 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
668 return (*plparam ? 1 : -1);
670 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
671 { if ( WINPROC_TestCBForStr( hwnd ))
672 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
674 *ptr++ = *plparam; /* Store previous lParam */
675 *plparam = (LPARAM)ptr;
682 { WORD len = (WORD)*plparam;
683 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
685 *ptr++ = *plparam; /* Store previous lParam */
686 *((WORD *) ptr) = len; /* Store the length */
687 *plparam = (LPARAM)ptr;
697 case EM_SETPASSWORDCHAR:
699 BYTE ch = LOWORD(*pwparam);
701 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
702 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
706 case WM_PAINTCLIPBOARD:
707 case WM_SIZECLIPBOARD:
708 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
710 default: /* No translation needed */
716 /**********************************************************************
717 * WINPROC_UnmapMsg32ATo32W
719 * Unmap a message that was mapped from Ansi to Unicode.
721 LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
727 case WM_ASKCBFORMATNAME:
729 LPARAM *ptr = (LPARAM *)lParam - 1;
730 if (wParam > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
731 (LPSTR)*ptr, wParam, NULL, NULL ))
732 ((LPSTR)*ptr)[wParam-1] = 0;
733 HeapFree( GetProcessHeap(), 0, ptr );
736 case WM_GETTEXTLENGTH:
737 case CB_GETLBTEXTLEN:
739 /* there may be one DBCS char for each Unicode char */
745 { CREATESTRUCTW cs; /* new structure */
746 LPWSTR lpszName; /* allocated Name */
747 LPWSTR lpszClass; /* allocated Class */
749 struct s *xs = (struct s *)lParam;
750 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
751 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
752 HeapFree( GetProcessHeap(), 0, xs );
758 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
759 if (HIWORD(cs->szTitle))
760 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
761 if (HIWORD(cs->szClass))
762 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
763 HeapFree( GetProcessHeap(), 0, cs );
768 case WM_WININICHANGE:
769 case WM_DEVMODECHANGE:
774 HeapFree( GetProcessHeap(), 0, (void *)lParam );
779 case LB_INSERTSTRING:
781 case LB_FINDSTRINGEXACT:
782 case LB_SELECTSTRING:
783 if ( WINPROC_TestLBForStr( hwnd ))
784 HeapFree( GetProcessHeap(), 0, (void *)lParam );
788 { if ( WINPROC_TestLBForStr( hwnd ))
789 { LPARAM *ptr = (LPARAM *)lParam - 1;
790 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
791 HeapFree( GetProcessHeap(), 0, ptr );
798 case CB_INSERTSTRING:
800 case CB_FINDSTRINGEXACT:
801 case CB_SELECTSTRING:
802 if ( WINPROC_TestCBForStr( hwnd ))
803 HeapFree( GetProcessHeap(), 0, (void *)lParam );
807 { if ( WINPROC_TestCBForStr( hwnd ))
808 { LPARAM *ptr = (LPARAM *)lParam - 1;
809 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
810 HeapFree( GetProcessHeap(), 0, ptr );
817 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
818 WORD len = *(WORD *) lParam;
819 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
820 (LPSTR)*ptr, len, NULL, NULL ))
821 ((LPSTR)*ptr)[len-1] = 0;
822 HeapFree( GetProcessHeap(), 0, ptr );
830 /**********************************************************************
831 * WINPROC_MapMsg32WTo32A
833 * Map a message from Unicode to Ansi.
834 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
836 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
841 case WM_ASKCBFORMATNAME:
843 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
844 *pwparam + sizeof(LPARAM) );
846 *ptr++ = *plparam; /* Store previous lParam */
847 *plparam = (LPARAM)ptr;
852 case WM_WININICHANGE:
853 case WM_DEVMODECHANGE:
858 if(!*plparam) return 0;
859 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
860 return (*plparam ? 1 : -1);
865 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
868 *cs = *(CREATESTRUCTA *)*plparam;
869 if (HIWORD(cs->lpszName))
870 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
871 (LPCWSTR)cs->lpszName );
872 if (HIWORD(cs->lpszClass))
873 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
874 (LPCWSTR)cs->lpszClass);
875 *plparam = (LPARAM)cs;
880 MDICREATESTRUCTA *cs =
881 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
883 *cs = *(MDICREATESTRUCTA *)*plparam;
884 if (HIWORD(cs->szTitle))
885 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
886 (LPCWSTR)cs->szTitle );
887 if (HIWORD(cs->szClass))
888 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
889 (LPCWSTR)cs->szClass );
890 *plparam = (LPARAM)cs;
896 case LB_INSERTSTRING:
898 case LB_FINDSTRINGEXACT:
899 case LB_SELECTSTRING:
900 if(!*plparam) return 0;
901 if ( WINPROC_TestLBForStr( hwnd ))
902 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
903 return (*plparam ? 1 : -1);
905 case LB_GETTEXT: /* FIXME: fixed sized buffer */
906 { if ( WINPROC_TestLBForStr( hwnd ))
907 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
909 *ptr++ = *plparam; /* Store previous lParam */
910 *plparam = (LPARAM)ptr;
917 case CB_INSERTSTRING:
919 case CB_FINDSTRINGEXACT:
920 case CB_SELECTSTRING:
921 if(!*plparam) return 0;
922 if ( WINPROC_TestCBForStr( hwnd ))
923 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
924 return (*plparam ? 1 : -1);
926 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
927 { if ( WINPROC_TestCBForStr( hwnd ))
928 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
930 *ptr++ = *plparam; /* Store previous lParam */
931 *plparam = (LPARAM)ptr;
938 { WORD len = (WORD)*plparam;
939 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
941 *ptr++ = *plparam; /* Store previous lParam */
942 *((WORD *) ptr) = len; /* Store the length */
943 *plparam = (LPARAM)ptr;
953 case EM_SETPASSWORDCHAR:
955 WCHAR wch = LOWORD(*pwparam);
957 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
958 *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
962 case WM_PAINTCLIPBOARD:
963 case WM_SIZECLIPBOARD:
964 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg, hwnd),msg );
966 default: /* No translation needed */
972 /**********************************************************************
973 * WINPROC_UnmapMsg32WTo32A
975 * Unmap a message that was mapped from Unicode to Ansi.
977 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
982 case WM_ASKCBFORMATNAME:
984 LPARAM *ptr = (LPARAM *)lParam - 1;
987 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, wParam ))
988 ((LPWSTR)*ptr)[wParam-1] = 0;
990 HeapFree( GetProcessHeap(), 0, ptr );
995 case WM_WININICHANGE:
996 case WM_DEVMODECHANGE:
1001 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1007 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1008 if (HIWORD(cs->lpszName))
1009 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1010 if (HIWORD(cs->lpszClass))
1011 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1012 HeapFree( GetProcessHeap(), 0, cs );
1018 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1019 if (HIWORD(cs->szTitle))
1020 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1021 if (HIWORD(cs->szClass))
1022 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1023 HeapFree( GetProcessHeap(), 0, cs );
1029 case LB_INSERTSTRING:
1031 case LB_FINDSTRINGEXACT:
1032 case LB_SELECTSTRING:
1033 if ( WINPROC_TestLBForStr( hwnd ))
1034 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1038 if ( WINPROC_TestLBForStr( hwnd ))
1040 LPARAM *ptr = (LPARAM *)lParam - 1;
1041 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1042 HeapFree( GetProcessHeap(), 0, ptr );
1048 case CB_INSERTSTRING:
1050 case CB_FINDSTRINGEXACT:
1051 case CB_SELECTSTRING:
1052 if ( WINPROC_TestCBForStr( hwnd ))
1053 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1057 if ( WINPROC_TestCBForStr( hwnd ))
1059 LPARAM *ptr = (LPARAM *)lParam - 1;
1060 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1061 HeapFree( GetProcessHeap(), 0, ptr );
1065 /* Multiline edit */
1067 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1068 WORD len = *(WORD *)ptr;
1071 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, len ))
1072 ((LPWSTR)*ptr)[len-1] = 0;
1074 HeapFree( GetProcessHeap(), 0, ptr );
1081 /**********************************************************************
1082 * WINPROC_MapMsg16To32A
1084 * Map a message from 16- to 32-bit Ansi.
1085 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1087 INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1088 WPARAM *pwparam32, LPARAM *plparam )
1090 *pmsg32 = (UINT)msg16;
1091 *pwparam32 = (WPARAM)wParam16;
1098 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1099 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1103 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1104 *plparam = (LPARAM)WIN_Handle32( HIWORD(*plparam) );
1107 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1108 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1109 *pwparam32 = (WPARAM)(HDC)wParam16;
1110 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1112 case WM_COMPAREITEM:
1114 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1115 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1116 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1117 if (!cis) return -1;
1118 cis->CtlType = cis16->CtlType;
1119 cis->CtlID = cis16->CtlID;
1120 cis->hwndItem = WIN_Handle32( cis16->hwndItem );
1121 cis->itemID1 = cis16->itemID1;
1122 cis->itemData1 = cis16->itemData1;
1123 cis->itemID2 = cis16->itemID2;
1124 cis->itemData2 = cis16->itemData2;
1125 cis->dwLocaleId = 0; /* FIXME */
1126 *plparam = (LPARAM)cis;
1131 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1132 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1133 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1134 if (!dis) return -1;
1135 dis->CtlType = dis16->CtlType;
1136 dis->CtlID = dis16->CtlID;
1137 dis->hwndItem = WIN_Handle32( dis16->hwndItem );
1138 dis->itemData = dis16->itemData;
1139 *plparam = (LPARAM)dis;
1142 case WM_MEASUREITEM:
1144 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1145 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1146 HeapAlloc(GetProcessHeap(), 0,
1147 sizeof(*mis) + sizeof(LPARAM));
1148 if (!mis) return -1;
1149 mis->CtlType = mis16->CtlType;
1150 mis->CtlID = mis16->CtlID;
1151 mis->itemID = mis16->itemID;
1152 mis->itemWidth = mis16->itemWidth;
1153 mis->itemHeight = mis16->itemHeight;
1154 mis->itemData = mis16->itemData;
1155 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1156 *plparam = (LPARAM)mis;
1161 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1162 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1164 if (!dis) return -1;
1165 dis->CtlType = dis16->CtlType;
1166 dis->CtlID = dis16->CtlID;
1167 dis->itemID = dis16->itemID;
1168 dis->itemAction = dis16->itemAction;
1169 dis->itemState = dis16->itemState;
1170 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND)(HMENU)dis16->hwndItem
1171 : WIN_Handle32( dis16->hwndItem );
1172 dis->hDC = dis16->hDC;
1173 dis->itemData = dis16->itemData;
1174 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1175 *plparam = (LPARAM)dis;
1178 case WM_GETMINMAXINFO:
1180 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1181 sizeof(*mmi) + sizeof(LPARAM));
1182 if (!mmi) return -1;
1183 STRUCT32_MINMAXINFO16to32( MapSL(*plparam), mmi );
1184 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1185 *plparam = (LPARAM)mmi;
1190 case WM_WININICHANGE:
1191 case WM_DEVMODECHANGE:
1192 case WM_ASKCBFORMATNAME:
1193 *plparam = (LPARAM)MapSL(*plparam);
1197 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1198 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1200 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1201 cs->szTitle = MapSL(cs16->szTitle);
1202 cs->szClass = MapSL(cs16->szClass);
1203 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1204 *plparam = (LPARAM)cs;
1207 case WM_MDIGETACTIVE:
1208 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1209 *(BOOL*)(*plparam) = 0;
1213 *pmsg32=WM_MDIREFRESHMENU;
1214 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1215 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1218 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1219 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1222 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1224 HMENU hmenu=(HMENU)HIWORD(*plparam);
1225 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1226 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1227 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1229 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1230 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1232 case WM_MDIACTIVATE:
1235 *pwparam32 = (WPARAM)WIN_Handle32( HIWORD(*plparam) );
1236 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1238 else /* message sent to MDI client */
1239 *pwparam32 = wParam16;
1243 NCCALCSIZE_PARAMS16 *nc16;
1244 NCCALCSIZE_PARAMS *nc;
1246 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1247 sizeof(*nc) + sizeof(LPARAM) );
1249 nc16 = MapSL(*plparam);
1250 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1253 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1254 sizeof(*nc->lppos) );
1255 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1256 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1257 if (nc->lppos) STRUCT32_WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1259 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1260 *plparam = (LPARAM)nc;
1266 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1267 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1268 sizeof(*cs) + sizeof(LPARAM) );
1270 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1271 cs->lpszName = MapSL(cs16->lpszName);
1272 cs->lpszClass = MapSL(cs16->lpszClass);
1273 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1274 *plparam = (LPARAM)cs;
1277 case WM_PARENTNOTIFY:
1278 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1280 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1281 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1284 case WM_WINDOWPOSCHANGING:
1285 case WM_WINDOWPOSCHANGED:
1287 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1288 sizeof(*wp) + sizeof(LPARAM) );
1290 STRUCT32_WINDOWPOS16to32( MapSL(*plparam), wp );
1291 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1292 *plparam = (LPARAM)wp;
1298 LPMSG16 msg16 = MapSL(*plparam);
1299 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1301 if (!msg32) return -1;
1302 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1303 msg32->lParam = msg16->lParam;
1304 msg32->time = msg16->time;
1305 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1306 /* this is right, right? */
1307 if (WINPROC_MapMsg16To32A( msg32->hwnd, msg16->message,msg16->wParam,
1308 &msg32->message,&msg32->wParam,
1309 &msg32->lParam)<0) {
1310 HeapFree( GetProcessHeap(), 0, msg32 );
1313 *plparam = (LPARAM)msg32;
1318 *plparam = (LPARAM)MapSL(*plparam);
1320 case WM_ACTIVATEAPP:
1322 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1323 a 32bit window. Might be superflous with 32bit interprocess
1326 HTASK16 htask = (HTASK16) *plparam;
1327 DWORD idThread = (DWORD)TASK_GetPtr(htask)->teb->tid;
1328 *plparam = (LPARAM) idThread;
1333 MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
1334 if (!next) return -1;
1335 next->hmenuIn = *plparam;
1336 next->hmenuNext = 0;
1338 *plparam = (LPARAM)next;
1341 case WM_PAINTCLIPBOARD:
1342 case WM_SIZECLIPBOARD:
1343 FIXME_(msg)("message %04x needs translation\n",msg16 );
1346 default: /* No translation needed */
1352 /**********************************************************************
1353 * WINPROC_UnmapMsg16To32A
1355 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1357 LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1362 case WM_COMPAREITEM:
1365 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1367 case WM_MEASUREITEM:
1369 MEASUREITEMSTRUCT16 *mis16;
1370 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1371 lParam = *(LPARAM *)(mis + 1);
1372 mis16 = MapSL(lParam);
1373 mis16->itemWidth = (UINT16)mis->itemWidth;
1374 mis16->itemHeight = (UINT16)mis->itemHeight;
1375 HeapFree( GetProcessHeap(), 0, mis );
1378 case WM_GETMINMAXINFO:
1380 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1381 lParam = *(LPARAM *)(mmi + 1);
1382 STRUCT32_MINMAXINFO32to16( mmi, MapSL(lParam));
1383 HeapFree( GetProcessHeap(), 0, mmi );
1388 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1389 lParam = *(LPARAM *)(cs + 1);
1390 STRUCT32_MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1391 HeapFree( GetProcessHeap(), 0, cs );
1394 case WM_MDIGETACTIVE:
1395 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1396 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1400 NCCALCSIZE_PARAMS16 *nc16;
1401 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1402 lParam = *(LPARAM *)(nc + 1);
1403 nc16 = MapSL(lParam);
1404 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1407 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1408 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1411 STRUCT32_WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1412 HeapFree( GetProcessHeap(), 0, nc->lppos );
1415 HeapFree( GetProcessHeap(), 0, nc );
1421 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1422 lParam = *(LPARAM *)(cs + 1);
1423 STRUCT32_CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1424 HeapFree( GetProcessHeap(), 0, cs );
1427 case WM_WINDOWPOSCHANGING:
1428 case WM_WINDOWPOSCHANGED:
1430 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1431 lParam = *(LPARAM *)(wp + 1);
1432 STRUCT32_WINDOWPOS32to16(wp, MapSL(lParam));
1433 HeapFree( GetProcessHeap(), 0, wp );
1439 LPMSG msg32 = (LPMSG)lParam;
1441 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1443 HeapFree( GetProcessHeap(), 0, msg32 );
1448 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1449 result = MAKELONG( next->hmenuNext, WIN_Handle16(next->hwndNext) );
1450 HeapFree( GetProcessHeap(), 0, next );
1458 /**********************************************************************
1459 * WINPROC_MapMsg16To32W
1461 * Map a message from 16- to 32-bit Unicode.
1462 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1464 INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1465 WPARAM *pwparam32, LPARAM *plparam )
1470 *pmsg32=(UINT)msg16;
1471 *pwparam32 = (WPARAM)wParam16;
1476 case WM_WININICHANGE:
1477 case WM_DEVMODECHANGE:
1478 case WM_ASKCBFORMATNAME:
1479 *plparam = (LPARAM)MapSL(*plparam);
1480 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1481 case WM_GETTEXTLENGTH:
1482 case CB_GETLBTEXTLEN:
1484 return 1; /* need to map result */
1488 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1489 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1490 sizeof(*cs) + sizeof(LPARAM) );
1492 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1493 cs->lpszName = map_str_16_to_32W(cs16->lpszName);
1494 cs->lpszClass = map_str_16_to_32W(cs16->lpszClass);
1495 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1496 *plparam = (LPARAM)cs;
1501 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1502 MDICREATESTRUCTW *cs =
1503 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1504 sizeof(*cs) + sizeof(LPARAM) );
1506 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1507 cs->szTitle = map_str_16_to_32W(cs16->szTitle);
1508 cs->szClass = map_str_16_to_32W(cs16->szClass);
1509 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1510 *plparam = (LPARAM)cs;
1516 LPMSG16 msg16 = MapSL(*plparam);
1517 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1519 if (!msg32) return -1;
1520 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1521 msg32->lParam = msg16->lParam;
1522 msg32->time = msg16->time;
1523 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1524 /* this is right, right? */
1525 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1526 &msg32->message,&msg32->wParam,
1527 &msg32->lParam)<0) {
1528 HeapFree( GetProcessHeap(), 0, msg32 );
1531 *plparam = (LPARAM)msg32;
1538 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1539 *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
1540 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1544 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1545 *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
1546 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1551 case WM_SYSDEADCHAR:
1553 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1557 default: /* No Unicode translation needed */
1558 return WINPROC_MapMsg16To32A( hwnd, msg16, wParam16, pmsg32,
1559 pwparam32, plparam );
1564 /**********************************************************************
1565 * WINPROC_UnmapMsg16To32W
1567 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1569 LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1576 case WM_GETTEXTLENGTH:
1577 case CB_GETLBTEXTLEN:
1579 case WM_ASKCBFORMATNAME:
1580 return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
1584 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1585 lParam = *(LPARAM *)(cs + 1);
1586 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1587 unmap_str_16_to_32W( cs->lpszName );
1588 unmap_str_16_to_32W( cs->lpszClass );
1589 HeapFree( GetProcessHeap(), 0, cs );
1594 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1595 lParam = *(LPARAM *)(cs + 1);
1596 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1597 unmap_str_16_to_32W( cs->szTitle );
1598 unmap_str_16_to_32W( cs->szClass );
1599 HeapFree( GetProcessHeap(), 0, cs );
1605 LPMSG msg32 = (LPMSG)lParam;
1607 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1609 HeapFree( GetProcessHeap(), 0, msg32 );
1613 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1619 /**********************************************************************
1620 * WINPROC_MapMsg32ATo16
1622 * Map a message from 32-bit Ansi to 16-bit.
1623 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1625 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1626 UINT16 *pmsg16, WPARAM16 *pwparam16,
1629 *pmsg16 = (UINT16)msg32;
1630 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1638 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1647 case EM_SCROLLCARET:
1650 case EM_GETLINECOUNT:
1662 case EM_LINEFROMCHAR:
1663 case EM_SETTABSTOPS:
1664 case EM_SETPASSWORDCHAR:
1665 case EM_EMPTYUNDOBUFFER:
1666 case EM_GETFIRSTVISIBLELINE:
1667 case EM_SETREADONLY:
1668 case EM_SETWORDBREAKPROC:
1669 case EM_GETWORDBREAKPROC:
1670 case EM_GETPASSWORDCHAR:
1671 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1676 case LB_DELETESTRING:
1677 case LB_GETANCHORINDEX:
1678 case LB_GETCARETINDEX:
1681 case LB_GETHORIZONTALEXTENT:
1682 case LB_GETITEMDATA:
1683 case LB_GETITEMHEIGHT:
1685 case LB_GETSELCOUNT:
1687 case LB_GETTOPINDEX:
1688 case LB_RESETCONTENT:
1689 case LB_SELITEMRANGE:
1690 case LB_SELITEMRANGEEX:
1691 case LB_SETANCHORINDEX:
1692 case LB_SETCARETINDEX:
1693 case LB_SETCOLUMNWIDTH:
1695 case LB_SETHORIZONTALEXTENT:
1696 case LB_SETITEMDATA:
1697 case LB_SETITEMHEIGHT:
1699 case LB_SETTOPINDEX:
1700 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1702 case CB_DELETESTRING:
1704 case CB_GETLBTEXTLEN:
1706 case CB_RESETCONTENT:
1710 case CB_SHOWDROPDOWN:
1711 case CB_SETITEMDATA:
1712 case CB_SETITEMHEIGHT:
1713 case CB_GETITEMHEIGHT:
1714 case CB_SETEXTENDEDUI:
1715 case CB_GETEXTENDEDUI:
1716 case CB_GETDROPPEDSTATE:
1717 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1720 *pmsg16 = CB_GETEDITSEL16;
1725 case LB_FINDSTRINGEXACT:
1726 case LB_INSERTSTRING:
1727 case LB_SELECTSTRING:
1730 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
1731 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1736 case CB_FINDSTRINGEXACT:
1737 case CB_INSERTSTRING:
1738 case CB_SELECTSTRING:
1740 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
1741 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1744 case LB_GETITEMRECT:
1746 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
1747 if (!rect) return -1;
1748 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1749 *plparam = MapLS( rect );
1751 *pmsg16 = LB_GETITEMRECT16;
1753 case LB_GETSELITEMS:
1756 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1757 if (!(items = HeapAlloc( GetProcessHeap(), 0,
1758 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
1759 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1760 *plparam = MapLS( items );
1762 *pmsg16 = LB_GETSELITEMS16;
1764 case LB_SETTABSTOPS:
1769 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1770 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
1771 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
1772 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1773 *plparam = MapLS( stops );
1776 *pmsg16 = LB_SETTABSTOPS16;
1779 case CB_GETDROPPEDCONTROLRECT:
1781 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
1782 if (!rect) return -1;
1783 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1784 *plparam = (LPARAM)MapLS(rect);
1786 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1790 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1791 *pmsg16 = LB_GETTEXT16;
1795 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1796 *pmsg16 = CB_GETLBTEXT16;
1801 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1802 *pmsg16 = EM_SETSEL16;
1809 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1813 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1815 case WM_CTLCOLORMSGBOX:
1816 case WM_CTLCOLOREDIT:
1817 case WM_CTLCOLORLISTBOX:
1818 case WM_CTLCOLORBTN:
1819 case WM_CTLCOLORDLG:
1820 case WM_CTLCOLORSCROLLBAR:
1821 case WM_CTLCOLORSTATIC:
1822 *pmsg16 = WM_CTLCOLOR;
1823 *plparam = MAKELPARAM( (HWND16)*plparam,
1824 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1826 case WM_COMPAREITEM:
1828 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1829 COMPAREITEMSTRUCT16 *cis = HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16));
1830 if (!cis) return -1;
1831 cis->CtlType = (UINT16)cis32->CtlType;
1832 cis->CtlID = (UINT16)cis32->CtlID;
1833 cis->hwndItem = WIN_Handle16( cis32->hwndItem );
1834 cis->itemID1 = (UINT16)cis32->itemID1;
1835 cis->itemData1 = cis32->itemData1;
1836 cis->itemID2 = (UINT16)cis32->itemID2;
1837 cis->itemData2 = cis32->itemData2;
1838 *plparam = MapLS( cis );
1843 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1844 DELETEITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16) );
1845 if (!dis) return -1;
1846 dis->CtlType = (UINT16)dis32->CtlType;
1847 dis->CtlID = (UINT16)dis32->CtlID;
1848 dis->itemID = (UINT16)dis32->itemID;
1849 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1850 : WIN_Handle16( dis32->hwndItem );
1851 dis->itemData = dis32->itemData;
1852 *plparam = MapLS( dis );
1857 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1858 DRAWITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16) );
1859 if (!dis) return -1;
1860 dis->CtlType = (UINT16)dis32->CtlType;
1861 dis->CtlID = (UINT16)dis32->CtlID;
1862 dis->itemID = (UINT16)dis32->itemID;
1863 dis->itemAction = (UINT16)dis32->itemAction;
1864 dis->itemState = (UINT16)dis32->itemState;
1865 dis->hwndItem = WIN_Handle16( dis32->hwndItem );
1866 dis->hDC = (HDC16)dis32->hDC;
1867 dis->itemData = dis32->itemData;
1868 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1869 *plparam = MapLS( dis );
1872 case WM_MEASUREITEM:
1874 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1875 MEASUREITEMSTRUCT16 *mis = HeapAlloc( GetProcessHeap(), 0, sizeof(*mis)+sizeof(LPARAM));
1876 if (!mis) return -1;
1877 mis->CtlType = (UINT16)mis32->CtlType;
1878 mis->CtlID = (UINT16)mis32->CtlID;
1879 mis->itemID = (UINT16)mis32->itemID;
1880 mis->itemWidth = (UINT16)mis32->itemWidth;
1881 mis->itemHeight = (UINT16)mis32->itemHeight;
1882 mis->itemData = mis32->itemData;
1883 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1884 *plparam = MapLS( mis );
1887 case WM_GETMINMAXINFO:
1889 MINMAXINFO16 *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM) );
1890 if (!mmi) return -1;
1891 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1892 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1893 *plparam = MapLS( mmi );
1897 case WM_ASKCBFORMATNAME:
1900 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1901 if (!(str = HeapAlloc( GetProcessHeap(), 0, *pwparam16 + sizeof(LPARAM)))) return -1;
1902 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1903 *plparam = MapLS( str );
1908 MDICREATESTRUCT16 *cs;
1909 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1911 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
1912 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1913 cs->szTitle = MapLS( cs32->szTitle );
1914 cs->szClass = MapLS( cs32->szClass );
1915 *plparam = MapLS( cs );
1918 case WM_MDIGETACTIVE:
1921 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1922 (HMENU16)LOWORD(*plparam) );
1923 *pwparam16 = (*plparam == 0);
1926 if(HIWORD(wParam32) & MF_POPUP)
1929 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1931 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1937 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1939 case WM_MDIACTIVATE:
1940 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1942 *pwparam16 = ((HWND)*plparam == hwnd);
1943 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1944 (HWND16)LOWORD(wParam32) );
1948 *pwparam16 = WIN_Handle16( (HWND)wParam32 );
1954 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1955 NCCALCSIZE_PARAMS16 *nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM));
1958 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1962 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1963 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1964 if (!(wp = HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16) )))
1966 HeapFree( GetProcessHeap(), 0, nc );
1969 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1970 nc->lppos = MapLS( wp );
1972 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1973 *plparam = MapLS( nc );
1980 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1982 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
1983 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1984 cs->lpszName = MapLS( cs32->lpszName );
1985 cs->lpszClass = MapLS( cs32->lpszClass );
1986 *plparam = MapLS( cs );
1989 case WM_PARENTNOTIFY:
1990 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1991 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1992 /* else nothing to do */
1995 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1998 case WM_WININICHANGE:
1999 case WM_DEVMODECHANGE:
2000 *plparam = MapLS( (LPSTR)*plparam );
2002 case WM_WINDOWPOSCHANGING:
2003 case WM_WINDOWPOSCHANGED:
2005 WINDOWPOS16 *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
2007 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2008 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2009 *plparam = MapLS( wp );
2014 LPMSG msg32 = (LPMSG) *plparam;
2015 LPMSG16 msg16 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16) );
2017 if (!msg16) return -1;
2018 msg16->hwnd = WIN_Handle16( msg32->hwnd );
2019 msg16->lParam = msg32->lParam;
2020 msg16->time = msg32->time;
2021 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
2022 /* this is right, right? */
2023 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2024 &msg16->message,&msg16->wParam, &msg16->lParam)<0)
2026 HeapFree( GetProcessHeap(), 0, msg16 );
2029 *plparam = MapLS( msg16 );
2034 case WM_ACTIVATEAPP:
2035 if (*plparam) *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2039 MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
2040 *plparam = next->hmenuIn;
2043 case WM_PAINTCLIPBOARD:
2044 case WM_SIZECLIPBOARD:
2045 FIXME_(msg)("message %04x needs translation\n", msg32 );
2047 /* following messages should not be sent to 16-bit apps */
2050 case WM_CAPTURECHANGED:
2051 case WM_STYLECHANGING:
2052 case WM_STYLECHANGED:
2054 default: /* No translation needed */
2060 /**********************************************************************
2061 * WINPROC_UnmapMsg32ATo16
2063 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2065 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2074 case LB_FINDSTRINGEXACT:
2075 case LB_INSERTSTRING:
2076 case LB_SELECTSTRING:
2080 case CB_FINDSTRINGEXACT:
2081 case CB_INSERTSTRING:
2082 case CB_SELECTSTRING:
2086 case WM_WININICHANGE:
2087 case WM_DEVMODECHANGE:
2088 UnMapLS( (SEGPTR)p16->lParam );
2090 case LB_SETTABSTOPS:
2091 case WM_COMPAREITEM:
2095 void *ptr = MapSL( p16->lParam );
2096 UnMapLS( p16->lParam );
2097 HeapFree( GetProcessHeap(), 0, ptr );
2100 case CB_GETDROPPEDCONTROLRECT:
2101 case LB_GETITEMRECT:
2103 RECT16 *rect = MapSL(p16->lParam);
2104 UnMapLS( p16->lParam );
2105 p16->lParam = *(LPARAM *)(rect + 1);
2106 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2107 HeapFree( GetProcessHeap(), 0, rect );
2110 case LB_GETSELITEMS:
2113 LPINT16 items = MapSL(p16->lParam);
2114 UnMapLS( p16->lParam );
2115 p16->lParam = *((LPARAM *)items - 1);
2116 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2117 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
2123 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2125 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2128 case WM_MEASUREITEM:
2130 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2131 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2132 mis32->itemWidth = mis->itemWidth;
2133 mis32->itemHeight = mis->itemHeight;
2134 UnMapLS( p16->lParam );
2135 HeapFree( GetProcessHeap(), 0, mis );
2138 case WM_GETMINMAXINFO:
2140 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2141 UnMapLS( p16->lParam );
2142 p16->lParam = *(LPARAM *)(mmi + 1);
2143 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2144 HeapFree( GetProcessHeap(), 0, mmi );
2148 case WM_ASKCBFORMATNAME:
2150 LPSTR str = MapSL(p16->lParam);
2151 UnMapLS( p16->lParam );
2152 p16->lParam = *((LPARAM *)str - 1);
2153 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2154 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2159 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2160 UnMapLS( cs->szTitle );
2161 UnMapLS( cs->szClass );
2162 UnMapLS( p16->lParam );
2163 HeapFree( GetProcessHeap(), 0, cs );
2166 case WM_MDIGETACTIVE:
2167 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2168 p16->lResult = (LRESULT)WIN_Handle32( LOWORD(p16->lResult) );
2172 NCCALCSIZE_PARAMS *nc32;
2173 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2174 UnMapLS( p16->lParam );
2175 p16->lParam = *(LPARAM *)(nc + 1);
2176 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2177 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2180 WINDOWPOS16 *pos = MapSL(nc->lppos);
2181 UnMapLS( nc->lppos );
2182 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2183 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2184 STRUCT32_WINDOWPOS16to32( pos, nc32->lppos );
2185 HeapFree( GetProcessHeap(), 0, pos );
2187 HeapFree( GetProcessHeap(), 0, nc );
2193 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2194 UnMapLS( p16->lParam );
2195 UnMapLS( cs->lpszName );
2196 UnMapLS( cs->lpszClass );
2197 HeapFree( GetProcessHeap(), 0, cs );
2200 case WM_WINDOWPOSCHANGING:
2201 case WM_WINDOWPOSCHANGED:
2203 WINDOWPOS16 *wp = MapSL(p16->lParam);
2204 UnMapLS( p16->lParam );
2205 p16->lParam = *(LPARAM *)(wp + 1);
2206 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2207 HeapFree( GetProcessHeap(), 0, wp );
2211 UnMapLS(p16->lParam);
2216 LPMSG16 msg16 = MapSL(p16->lParam);
2218 UnMapLS( p16->lParam );
2219 msgp16.wParam=msg16->wParam;
2220 msgp16.lParam=msg16->lParam;
2221 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2222 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2224 HeapFree( GetProcessHeap(), 0, msg16 );
2229 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2230 next->hmenuNext = LOWORD(p16->lResult);
2231 next->hwndNext = WIN_Handle32( HIWORD(p16->lResult) );
2239 /**********************************************************************
2240 * WINPROC_MapMsg32WTo16
2242 * Map a message from 32-bit Unicode to 16-bit.
2243 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2245 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2246 UINT16 *pmsg16, WPARAM16 *pwparam16,
2252 *pmsg16 = LOWORD(msg32);
2253 *pwparam16 = LOWORD(wParam32);
2258 case LB_FINDSTRINGEXACT:
2259 case LB_INSERTSTRING:
2260 case LB_SELECTSTRING:
2263 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2264 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2269 case CB_FINDSTRINGEXACT:
2270 case CB_INSERTSTRING:
2271 case CB_SELECTSTRING:
2273 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2274 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2281 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2283 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2284 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2285 cs->lpszName = map_str_32W_to_16( cs32->lpszName );
2286 cs->lpszClass = map_str_32W_to_16( cs32->lpszClass );
2287 *plparam = MapLS(cs);
2292 MDICREATESTRUCT16 *cs;
2293 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2295 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2296 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2297 cs->szTitle = map_str_32W_to_16( cs32->szTitle );
2298 cs->szClass = map_str_32W_to_16( cs32->szClass );
2299 *plparam = MapLS(cs);
2303 case WM_WININICHANGE:
2304 case WM_DEVMODECHANGE:
2305 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2309 if ( WINPROC_TestLBForStr( hwnd ))
2311 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2312 if (!str) return -1;
2313 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2314 *plparam = (LPARAM)MapLS(str);
2319 wch = LOWORD(wParam32);
2320 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2322 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2325 wch = LOWORD(wParam32);
2326 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2328 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2333 case WM_SYSDEADCHAR:
2335 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2339 default: /* No Unicode translation needed (?) */
2340 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2341 pwparam16, plparam );
2346 /**********************************************************************
2347 * WINPROC_UnmapMsg32WTo16
2349 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2351 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2358 case LB_FINDSTRINGEXACT:
2359 case LB_INSERTSTRING:
2360 case LB_SELECTSTRING:
2365 case CB_FINDSTRINGEXACT:
2366 case CB_INSERTSTRING:
2367 case CB_SELECTSTRING:
2370 case WM_WININICHANGE:
2371 case WM_DEVMODECHANGE:
2372 unmap_str_32W_to_16( p16->lParam );
2377 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2378 UnMapLS( p16->lParam );
2379 unmap_str_32W_to_16( cs->lpszName );
2380 unmap_str_32W_to_16( cs->lpszClass );
2381 HeapFree( GetProcessHeap(), 0, cs );
2386 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2387 UnMapLS( p16->lParam );
2388 unmap_str_32W_to_16( cs->szTitle );
2389 unmap_str_32W_to_16( cs->szClass );
2390 HeapFree( GetProcessHeap(), 0, cs );
2394 case WM_ASKCBFORMATNAME:
2396 LPSTR str = MapSL(p16->lParam);
2397 UnMapLS( p16->lParam );
2398 p16->lParam = *((LPARAM *)str - 1);
2399 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2400 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2405 if ( WINPROC_TestLBForStr( hwnd ))
2407 LPSTR str = MapSL(p16->lParam);
2408 UnMapLS( p16->lParam );
2409 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2410 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2414 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2420 /**********************************************************************
2421 * WINPROC_CallProc32ATo32W
2423 * Call a window procedure, translating args from Ansi to Unicode.
2425 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2426 UINT msg, WPARAM wParam,
2432 TRACE_(msg)("func %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
2433 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2435 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2436 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2437 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2440 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2441 if (unmap) result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
2446 /**********************************************************************
2447 * WINPROC_CallProc32WTo32A
2449 * Call a window procedure, translating args from Unicode to Ansi.
2451 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2452 UINT msg, WPARAM wParam,
2458 TRACE_(msg)("func %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
2459 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2461 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
2462 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2463 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2466 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2467 if( unmap ) WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2472 /**********************************************************************
2473 * __wine_call_wndproc_32A (USER.1010)
2475 LRESULT WINAPI __wine_call_wndproc_32A( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
2481 HWND hwnd32 = WIN_Handle32( hwnd );
2483 if (WINPROC_MapMsg16To32A( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2485 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
2486 return WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, result );
2490 /**********************************************************************
2491 * __wine_call_wndproc_32W (USER.1011)
2493 LRESULT WINAPI __wine_call_wndproc_32W( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
2499 HWND hwnd32 = WIN_Handle32( hwnd );
2501 if (WINPROC_MapMsg16To32W( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2503 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
2504 return WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, result );
2508 /**********************************************************************
2509 * WINPROC_CallProc32ATo16
2511 * Call a 16-bit window procedure, translating the 32-bit args.
2513 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2514 UINT msg, WPARAM wParam,
2520 TRACE_(msg)("func %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
2521 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2523 mp16.lParam = lParam;
2524 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2526 mp16.lResult = WINPROC_CallWndProc16( func, WIN_Handle16(hwnd), msg16,
2527 mp16.wParam, mp16.lParam );
2528 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2529 return mp16.lResult;
2533 /**********************************************************************
2534 * WINPROC_CallProc32WTo16
2536 * Call a 16-bit window procedure, translating the 32-bit args.
2538 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2539 UINT msg, WPARAM wParam,
2545 TRACE_(msg)("func %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
2546 func, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
2548 mp16.lParam = lParam;
2549 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2550 &mp16.lParam ) == -1)
2552 mp16.lResult = WINPROC_CallWndProc16( func, WIN_Handle16(hwnd), msg16,
2553 mp16.wParam, mp16.lParam );
2554 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2555 return mp16.lResult;
2559 /**********************************************************************
2560 * CallWindowProc (USER.122)
2561 * CallWindowProc16 (USER32.@)
2563 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2564 WPARAM16 wParam, LPARAM lParam )
2566 WINDOWPROC *proc = WINPROC_GetPtr( func );
2569 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2572 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2573 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2579 if (!proc->thunk.t_from32.proc) return 0;
2580 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2581 hwnd, msg, wParam, lParam );
2583 if (!proc->thunk.t_from16.proc) return 0;
2584 return __wine_call_wndproc_32A( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
2586 if (!proc->thunk.t_from16.proc) return 0;
2587 return __wine_call_wndproc_32W( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
2589 WARN_(relay)("Invalid proc %p\n", proc );
2595 /**********************************************************************
2596 * CallWindowProcA (USER32.@)
2598 * The CallWindowProc() function invokes the windows procedure _func_,
2599 * with _hwnd_ as the target window, the message specified by _msg_, and
2600 * the message parameters _wParam_ and _lParam_.
2602 * Some kinds of argument conversion may be done, I'm not sure what.
2604 * CallWindowProc() may be used for windows subclassing. Use
2605 * SetWindowLong() to set a new windows procedure for windows of the
2606 * subclass, and handle subclassed messages in the new windows
2607 * procedure. The new windows procedure may then use CallWindowProc()
2608 * with _func_ set to the parent class's windows procedure to dispatch
2609 * the message to the superclass.
2613 * The return value is message dependent.
2619 LRESULT WINAPI CallWindowProcA(
2620 WNDPROC func, /* [in] window procedure */
2621 HWND hwnd, /* [in] target window */
2622 UINT msg, /* [in] message */
2623 WPARAM wParam, /* [in] message dependent parameter */
2624 LPARAM lParam /* [in] message dependent parameter */
2626 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2628 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2631 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2632 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2638 if (!proc->thunk.t_from32.proc) return 0;
2639 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2640 hwnd, msg, wParam, lParam );
2642 if (!proc->thunk.t_from16.proc) return 0;
2643 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2644 hwnd, msg, wParam, lParam );
2646 if (!proc->thunk.t_from16.proc) return 0;
2647 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2648 hwnd, msg, wParam, lParam );
2650 WARN_(relay)("Invalid proc %p\n", proc );
2656 /**********************************************************************
2657 * CallWindowProcW (USER32.@)
2659 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2660 WPARAM wParam, LPARAM lParam )
2662 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2664 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2667 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2668 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2674 if (!proc->thunk.t_from32.proc) return 0;
2675 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2676 hwnd, msg, wParam, lParam );
2678 if (!proc->thunk.t_from16.proc) return 0;
2679 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2680 hwnd, msg, wParam, lParam );
2682 if (!proc->thunk.t_from16.proc) return 0;
2683 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2684 hwnd, msg, wParam, lParam );
2686 WARN_(relay)("Invalid proc %p\n", proc );