2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
14 #include "wine/winbase16.h"
15 #include "wine/winuser16.h"
16 #include "stackframe.h"
17 #include "builtin16.h"
23 #include "debugtools.h"
28 DECLARE_DEBUG_CHANNEL(msg);
29 DECLARE_DEBUG_CHANNEL(relay);
30 DECLARE_DEBUG_CHANNEL(win);
32 /* Window procedure 16-to-32-bit thunk,
33 * see BuildSpec16File() in tools/build.c */
38 WORD pushw_bp; /* pushw %bp */
39 BYTE pushl_func; /* pushl $proc */
41 WORD pushw_ax; /* pushw %ax */
42 BYTE pushl_relay; /* pushl $relay */
43 void (*relay)(); /* WINPROC_Thunk16To32A/W() */
44 BYTE lcall; /* lcall cs:glue */
45 void (*glue)(); /* __wine_call_from_16_long */
46 WORD cs; /* __FLATCS */
47 WORD lret; /* lret $10 */
49 } WINPROC_THUNK_FROM16;
52 /* Window procedure 32-to-16-bit thunk,
53 * see BuildSpec32File() in tools/build.c */
57 BYTE popl_eax; /* popl %eax (return address) */
58 BYTE pushl_func; /* pushl $proc */
59 WNDPROC16 proc WINE_PACKED;
60 BYTE pushl_eax; /* pushl %eax */
61 BYTE jmp; /* jmp relay (relative jump)*/
62 void (*relay)() WINE_PACKED; /* WINPROC_CallProc32ATo16() */
63 } WINPROC_THUNK_FROM32;
65 /* Simple jmp to call 32-bit procedure directly */
68 BYTE jmp; /* jmp proc (relative jump) */
69 WNDPROC proc WINE_PACKED;
74 WINPROC_THUNK_FROM16 t_from16;
75 WINPROC_THUNK_FROM32 t_from32;
78 typedef struct tagWINDOWPROC
80 WINPROC_THUNK thunk; /* Thunk */
81 WINPROC_JUMP jmp; /* Jump */
82 struct tagWINDOWPROC *next; /* Next window proc */
83 UINT magic; /* Magic number */
84 WINDOWPROCTYPE type; /* Function type */
85 WINDOWPROCUSER user; /* Function user */
88 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
90 #define WINPROC_THUNKPROC(pproc) \
91 (((pproc)->type == WIN_PROC_16) ? \
92 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
93 (WNDPROC16)((pproc)->thunk.t_from16.proc))
95 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
96 UINT msg, WPARAM wParam,
98 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
99 UINT msg, WPARAM wParam,
101 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args );
102 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args );
104 static HANDLE WinProcHeap;
107 /**********************************************************************
110 BOOL WINPROC_Init(void)
112 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
115 WARN_(relay)("Unable to create winproc heap\n" );
123 /* Some window procedures modify register they shouldn't, or are not
124 * properly declared stdcall; so we need a small assembly wrapper to
126 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
127 WPARAM wParam, LPARAM lParam );
128 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
138 "movl 8(%ebp),%eax\n\t"
140 "leal -12(%ebp),%esp\n\t"
147 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
148 WPARAM wParam, LPARAM lParam )
150 return proc( hwnd, msg, wParam, lParam );
152 #endif /* __i386__ */
154 /**********************************************************************
155 * WINPROC_CallWndProc32
157 * Call a 32-bit WndProc.
159 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
160 WPARAM wParam, LPARAM lParam )
166 DPRINTF( "%08lx:Call window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
167 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg), wParam, lParam );
168 /* To avoid any deadlocks, all the locks on the windows structures
169 must be suspended before the control is passed to the application */
170 iWndsLocks = WIN_SuspendWndsLock();
171 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
172 WIN_RestoreWndsLock(iWndsLocks);
175 DPRINTF( "%08lx:Ret window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
176 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg), wParam, lParam, retvalue );
180 /***********************************************************************
181 * WINPROC_CallWndProc16
183 * Call a 16-bit window procedure
185 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
186 UINT16 msg, WPARAM16 wParam,
192 WND *wndPtr = WIN_FindWndPtr( hwnd );
194 TEB *teb = NtCurrentTeb();
197 /* Window procedures want ax = hInstance, ds = es = ss */
199 memset(&context, '\0', sizeof(context));
200 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
201 context.Eax = wndPtr ? wndPtr->hInstance : context.SegDs;
202 context.SegCs = SELECTOROF(proc);
203 context.Eip = OFFSETOF(proc);
204 context.Ebp = OFFSETOF(teb->cur_stack)
205 + (WORD)&((STACK16FRAME*)0)->bp;
207 WIN_ReleaseWndPtr(wndPtr);
211 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
212 work if structures passed in lParam are placed in the stack/data
213 segment. Programmers easily make the mistake of converting lParam
214 to a near rather than a far pointer, since Windows apparently
215 allows this. We copy the structures to the 16 bit stack; this is
216 ugly but makes these programs work. */
221 offset = sizeof(CREATESTRUCT16); break;
223 offset = sizeof(DRAWITEMSTRUCT16); break;
225 offset = sizeof(COMPAREITEMSTRUCT16); break;
229 void *s = MapSL(lParam);
230 lParam = stack16_push( offset );
231 memcpy( MapSL(lParam), s, offset );
235 iWndsLocks = WIN_SuspendWndsLock();
237 args = (WORD *)THREAD_STACK16(teb) - 5;
238 args[0] = LOWORD(lParam);
239 args[1] = HIWORD(lParam);
244 wine_call_to_16_regs_short( &context, 5 * sizeof(WORD) );
245 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
246 if (offset) stack16_pop( offset );
248 WIN_RestoreWndsLock(iWndsLocks);
254 /**********************************************************************
257 * Return a pointer to the win proc.
259 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
264 /* ptr cannot be < 64K */
265 if (!HIWORD(handle)) return NULL;
267 /* Check for a linear pointer */
269 ptr = (BYTE *)handle;
270 /* First check if it is the jmp address */
271 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->jmp);
272 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
274 /* Now it must be the thunk address */
275 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
276 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
279 /* Check for a segmented pointer */
281 if (!IsBadReadPtr16( (SEGPTR)handle, sizeof(proc->thunk) ))
283 ptr = MapSL( (SEGPTR)handle );
284 /* It must be the thunk address */
285 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
286 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
294 /**********************************************************************
295 * WINPROC_AllocWinProc
297 * Allocate a new window procedure.
299 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
300 WINDOWPROCUSER user )
302 WINDOWPROC *proc, *oldproc;
304 /* Allocate a window procedure */
306 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
308 /* Check if the function is already a win proc */
310 if ((oldproc = WINPROC_GetPtr( func )))
319 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
320 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
321 proc->thunk.t_from32.proc = func;
322 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
323 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
324 proc->thunk.t_from32.relay = /* relative jump */
325 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
326 (DWORD)(&proc->thunk.t_from32.relay + 1));
330 proc->thunk.t_from16.pushw_bp = 0x5566; /* pushw %bp */
331 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
332 proc->thunk.t_from16.proc = (WNDPROC)func;
333 proc->thunk.t_from16.pushw_ax = 0x5066; /* pushw %ax */
334 proc->thunk.t_from16.pushl_relay = 0x68; /* pushl $relay */
335 proc->thunk.t_from16.relay = (type == WIN_PROC_32A) ?
336 (void(*)())WINPROC_Thunk16To32A :
337 (void(*)())WINPROC_Thunk16To32W;
338 proc->thunk.t_from16.lcall = 0x9a; /* lcall cs:glue */
339 proc->thunk.t_from16.glue = (void*)__wine_call_from_16_long;
340 proc->thunk.t_from16.cs = __get_cs();
341 proc->thunk.t_from16.lret = 0xca66;
342 proc->thunk.t_from16.nArgs = 10;
343 proc->jmp.jmp = 0xe9;
344 /* Fixup relative jump */
345 proc->jmp.proc = (WNDPROC)((DWORD)func -
346 (DWORD)(&proc->jmp.proc + 1));
349 /* Should not happen */
352 proc->magic = WINPROC_MAGIC;
357 TRACE_(win)("(%08x,%d): returning %08x\n",
358 (UINT)func, type, (UINT)proc );
363 /**********************************************************************
366 * Get a window procedure pointer that can be passed to the Windows program.
368 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
370 if (!proc) return NULL;
371 if (type == WIN_PROC_16) /* We want a 16:16 address */
373 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
374 return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
376 return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
377 &((WINDOWPROC *)proc)->thunk );
379 else /* We want a 32-bit address */
381 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
382 return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
383 else if (type != ((WINDOWPROC *)proc)->type)
384 /* Have to return the jmp address if types don't match */
385 return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
387 /* Some Win16 programs want to get back the proc they set */
388 return (WNDPROC16)((WINDOWPROC *)proc)->thunk.t_from16.proc;
393 /**********************************************************************
396 * Set the window procedure for a window or class. There are
397 * three tree classes of winproc callbacks:
399 * 1) class -> wp - not subclassed
400 * class -> wp -> wp -> wp -> wp - SetClassLong()
402 * 2) window -' / - not subclassed
403 * window -> wp -> wp ' - SetWindowLong()
405 * 3) timer -> wp - SetTimer()
407 * Initially, winproc of the window points to the current winproc
408 * thunk of its class. Subclassing prepends a new thunk to the
409 * window winproc chain at the head of the list. Thus, window thunk
410 * list includes class thunks and the latter are preserved when the
411 * window is destroyed.
414 BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
415 WINDOWPROCTYPE type, WINDOWPROCUSER user )
417 BOOL bRecycle = FALSE;
418 WINDOWPROC *proc, **ppPrev;
420 /* Check if function is already in the list */
422 ppPrev = (WINDOWPROC **)pFirst;
423 proc = WINPROC_GetPtr( func );
430 if ((*ppPrev)->user != user)
432 /* terminal thunk is being restored */
434 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
435 *(WINDOWPROC **)pFirst = *ppPrev;
444 if (((*ppPrev)->type == type) &&
445 (func == WINPROC_THUNKPROC(*ppPrev)))
452 /* WPF_CLASS thunk terminates window thunk list */
453 if ((*ppPrev)->user != user) break;
454 ppPrev = &(*ppPrev)->next;
459 /* Extract this thunk from the list */
461 *ppPrev = proc->next;
463 else /* Allocate a new one */
465 if (proc) /* Was already a win proc */
468 func = WINPROC_THUNKPROC(proc);
470 proc = WINPROC_AllocWinProc( func, type, user );
471 if (!proc) return FALSE;
474 /* Add the win proc at the head of the list */
476 TRACE_(win)("(%08x,%08x,%d): res=%08x\n",
477 (UINT)*pFirst, (UINT)func, type, (UINT)proc );
478 proc->next = *(WINDOWPROC **)pFirst;
479 *(WINDOWPROC **)pFirst = proc;
484 /**********************************************************************
487 * Free a list of win procs.
489 void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
493 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
494 if (((WINDOWPROC *)proc)->user != user) break;
495 TRACE_(win)("freeing %08x\n", (UINT)proc);
496 HeapFree( WinProcHeap, 0, proc );
502 /**********************************************************************
503 * WINPROC_GetProcType
505 * Return the window procedure type.
507 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
510 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
511 return WIN_PROC_INVALID;
512 return ((WINDOWPROC *)proc)->type;
514 /**********************************************************************
515 * WINPROC_TestCBForStr
517 * Return TRUE if the lparam is a string
519 static BOOL WINPROC_TestCBForStr ( HWND hwnd )
522 WND * wnd = WIN_FindWndPtr(hwnd);
523 retvalue = ( !(LOWORD(wnd->dwStyle) & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) ||
524 (LOWORD(wnd->dwStyle) & CBS_HASSTRINGS) );
525 WIN_ReleaseWndPtr(wnd);
528 /**********************************************************************
529 * WINPROC_TestLBForStr
531 * Return TRUE if the lparam is a string
533 static BOOL WINPROC_TestLBForStr ( HWND hwnd )
536 WND * wnd = WIN_FindWndPtr(hwnd);
537 retvalue = ( !(LOWORD(wnd->dwStyle) & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) ||
538 (LOWORD(wnd->dwStyle) & LBS_HASSTRINGS) );
539 WIN_ReleaseWndPtr(wnd);
543 /**********************************************************************
544 * WINPROC_MapMsg32ATo32W
546 * Map a message from Ansi to Unicode.
547 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
550 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
551 * the first four bytes are the handle of the icon
552 * when the WM_SETTEXT message has been used to set the icon
554 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
560 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
561 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
563 *ptr++ = *plparam; /* Store previous lParam */
564 *plparam = (LPARAM)ptr;
567 /* lparam is string (0-terminated) */
569 case WM_WININICHANGE:
572 case CB_FINDSTRINGEXACT:
573 case CB_SELECTSTRING:
577 case LB_FINDSTRINGEXACT:
578 case LB_SELECTSTRING:
580 if(!*plparam) return 0;
581 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
582 return (*plparam ? 1 : -1);
588 { CREATESTRUCTW cs; /* new structure */
589 LPCWSTR lpszName; /* allocated Name */
590 LPCWSTR lpszClass; /* allocated Class */
593 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
595 xs->cs = *(CREATESTRUCTW *)*plparam;
596 if (HIWORD(xs->cs.lpszName))
597 xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
598 (LPCSTR)xs->cs.lpszName );
599 if (HIWORD(xs->cs.lpszClass))
600 xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
601 (LPCSTR)xs->cs.lpszClass );
602 *plparam = (LPARAM)xs;
607 MDICREATESTRUCTW *cs =
608 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
610 *cs = *(MDICREATESTRUCTW *)*plparam;
611 if (HIWORD(cs->szClass))
612 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
613 (LPCSTR)cs->szClass );
614 if (HIWORD(cs->szTitle))
615 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
616 (LPCSTR)cs->szTitle );
617 *plparam = (LPARAM)cs;
623 case LB_INSERTSTRING:
624 if(!*plparam) return 0;
625 if ( WINPROC_TestLBForStr( hwnd ))
626 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
627 return (*plparam ? 1 : -1);
629 case LB_GETTEXT: /* fixme: fixed sized buffer */
630 { if ( WINPROC_TestLBForStr( hwnd ))
631 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
633 *ptr++ = *plparam; /* Store previous lParam */
634 *plparam = (LPARAM)ptr;
641 case CB_INSERTSTRING:
642 if(!*plparam) return 0;
643 if ( WINPROC_TestCBForStr( hwnd ))
644 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
645 return (*plparam ? 1 : -1);
647 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
648 { if ( WINPROC_TestCBForStr( hwnd ))
649 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
651 *ptr++ = *plparam; /* Store previous lParam */
652 *plparam = (LPARAM)ptr;
659 { WORD len = (WORD)*plparam;
660 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
662 *ptr++ = *plparam; /* Store previous lParam */
663 *((WORD *) ptr) = len; /* Store the length */
664 *plparam = (LPARAM)ptr;
674 case EM_SETPASSWORDCHAR:
676 char ch = LOWORD(*pwparam);
678 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
679 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
683 case WM_ASKCBFORMATNAME:
684 case WM_DEVMODECHANGE:
685 case WM_PAINTCLIPBOARD:
686 case WM_SIZECLIPBOARD:
687 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg), msg );
689 default: /* No translation needed */
695 /**********************************************************************
696 * WINPROC_UnmapMsg32ATo32W
698 * Unmap a message that was mapped from Ansi to Unicode.
700 void WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
706 LPARAM *ptr = (LPARAM *)lParam - 1;
707 if (wParam > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
708 (LPSTR)*ptr, wParam, NULL, NULL ))
709 ((LPSTR)*ptr)[wParam-1] = 0;
710 HeapFree( GetProcessHeap(), 0, ptr );
718 { CREATESTRUCTW cs; /* new structure */
719 LPWSTR lpszName; /* allocated Name */
720 LPWSTR lpszClass; /* allocated Class */
722 struct s *xs = (struct s *)lParam;
723 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
724 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
725 HeapFree( GetProcessHeap(), 0, xs );
731 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
732 if (HIWORD(cs->szTitle))
733 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
734 if (HIWORD(cs->szClass))
735 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
736 HeapFree( GetProcessHeap(), 0, cs );
741 case WM_WININICHANGE:
744 case CB_FINDSTRINGEXACT:
745 case CB_SELECTSTRING:
749 case LB_FINDSTRINGEXACT:
750 case LB_SELECTSTRING:
752 HeapFree( GetProcessHeap(), 0, (void *)lParam );
757 case LB_INSERTSTRING:
758 if ( WINPROC_TestLBForStr( hwnd ))
759 HeapFree( GetProcessHeap(), 0, (void *)lParam );
763 { if ( WINPROC_TestLBForStr( hwnd ))
764 { LPARAM *ptr = (LPARAM *)lParam - 1;
765 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
766 HeapFree( GetProcessHeap(), 0, ptr );
773 case CB_INSERTSTRING:
774 if ( WINPROC_TestCBForStr( hwnd ))
775 HeapFree( GetProcessHeap(), 0, (void *)lParam );
779 { if ( WINPROC_TestCBForStr( hwnd ))
780 { LPARAM *ptr = (LPARAM *)lParam - 1;
781 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
782 HeapFree( GetProcessHeap(), 0, ptr );
789 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
790 WORD len = *(WORD *) lParam;
791 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
792 (LPSTR)*ptr, len, NULL, NULL ))
793 ((LPSTR)*ptr)[len-1] = 0;
794 HeapFree( GetProcessHeap(), 0, ptr );
801 /**********************************************************************
802 * WINPROC_MapMsg32WTo32A
804 * Map a message from Unicode to Ansi.
805 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
807 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
813 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
814 *pwparam + sizeof(LPARAM) );
816 *ptr++ = *plparam; /* Store previous lParam */
817 *plparam = (LPARAM)ptr;
822 case WM_WININICHANGE:
825 case CB_FINDSTRINGEXACT:
826 case CB_SELECTSTRING:
830 case LB_FINDSTRINGEXACT:
831 case LB_SELECTSTRING:
833 if(!*plparam) return 0;
834 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
835 return (*plparam ? 1 : -1);
840 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
843 *cs = *(CREATESTRUCTA *)*plparam;
844 if (HIWORD(cs->lpszName))
845 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
846 (LPCWSTR)cs->lpszName );
847 if (HIWORD(cs->lpszClass))
848 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
849 (LPCWSTR)cs->lpszClass);
850 *plparam = (LPARAM)cs;
855 MDICREATESTRUCTA *cs =
856 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
858 *cs = *(MDICREATESTRUCTA *)*plparam;
859 if (HIWORD(cs->szTitle))
860 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
861 (LPCWSTR)cs->szTitle );
862 if (HIWORD(cs->szClass))
863 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
864 (LPCWSTR)cs->szClass );
865 *plparam = (LPARAM)cs;
871 case LB_INSERTSTRING:
872 if(!*plparam) return 0;
873 if ( WINPROC_TestLBForStr( hwnd ))
874 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
875 return (*plparam ? 1 : -1);
877 case LB_GETTEXT: /* fixme: fixed sized buffer */
878 { if ( WINPROC_TestLBForStr( hwnd ))
879 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
881 *ptr++ = *plparam; /* Store previous lParam */
882 *plparam = (LPARAM)ptr;
889 case CB_INSERTSTRING:
890 if(!*plparam) return 0;
891 if ( WINPROC_TestCBForStr( hwnd ))
892 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
893 return (*plparam ? 1 : -1);
895 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
896 { if ( WINPROC_TestCBForStr( hwnd ))
897 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
899 *ptr++ = *plparam; /* Store previous lParam */
900 *plparam = (LPARAM)ptr;
907 { WORD len = (WORD)*plparam;
908 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
910 *ptr++ = *plparam; /* Store previous lParam */
911 *((WORD *) ptr) = len; /* Store the length */
912 *plparam = (LPARAM)ptr;
922 case EM_SETPASSWORDCHAR:
924 WCHAR wch = LOWORD(*pwparam);
926 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
927 *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
931 case WM_ASKCBFORMATNAME:
932 case WM_DEVMODECHANGE:
933 case WM_PAINTCLIPBOARD:
934 case WM_SIZECLIPBOARD:
935 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
937 default: /* No translation needed */
943 /**********************************************************************
944 * WINPROC_UnmapMsg32WTo32A
946 * Unmap a message that was mapped from Unicode to Ansi.
948 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
954 LPARAM *ptr = (LPARAM *)lParam - 1;
957 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, wParam ))
958 ((LPWSTR)*ptr)[wParam-1] = 0;
960 HeapFree( GetProcessHeap(), 0, ptr );
965 case WM_WININICHANGE:
968 case CB_FINDSTRINGEXACT:
969 case CB_SELECTSTRING:
973 case LB_FINDSTRINGEXACT:
974 case LB_SELECTSTRING:
976 HeapFree( GetProcessHeap(), 0, (void *)lParam );
982 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
983 if (HIWORD(cs->lpszName))
984 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
985 if (HIWORD(cs->lpszClass))
986 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
987 HeapFree( GetProcessHeap(), 0, cs );
993 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
994 if (HIWORD(cs->szTitle))
995 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
996 if (HIWORD(cs->szClass))
997 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
998 HeapFree( GetProcessHeap(), 0, cs );
1004 case LB_INSERTSTRING:
1005 if ( WINPROC_TestLBForStr( hwnd ))
1006 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1010 if ( WINPROC_TestLBForStr( hwnd ))
1012 LPARAM *ptr = (LPARAM *)lParam - 1;
1013 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1014 HeapFree( GetProcessHeap(), 0, ptr );
1020 case CB_INSERTSTRING:
1021 if ( WINPROC_TestCBForStr( hwnd ))
1022 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1026 if ( WINPROC_TestCBForStr( hwnd ))
1028 LPARAM *ptr = (LPARAM *)lParam - 1;
1029 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1030 HeapFree( GetProcessHeap(), 0, ptr );
1034 /* Multiline edit */
1036 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1037 WORD len = *(WORD *)ptr;
1040 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, len ))
1041 ((LPWSTR)*ptr)[len-1] = 0;
1043 HeapFree( GetProcessHeap(), 0, ptr );
1050 /**********************************************************************
1051 * WINPROC_MapMsg16To32A
1053 * Map a message from 16- to 32-bit Ansi.
1054 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1056 INT WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1057 WPARAM *pwparam32, LPARAM *plparam )
1059 *pmsg32 = (UINT)msg16;
1060 *pwparam32 = (WPARAM)wParam16;
1067 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1068 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1072 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1073 *plparam = (LPARAM)(HWND)HIWORD(*plparam);
1076 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1077 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1078 *pwparam32 = (WPARAM)(HDC)wParam16;
1079 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1081 case WM_COMPAREITEM:
1083 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1084 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1085 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1086 if (!cis) return -1;
1087 cis->CtlType = cis16->CtlType;
1088 cis->CtlID = cis16->CtlID;
1089 cis->hwndItem = cis16->hwndItem;
1090 cis->itemID1 = cis16->itemID1;
1091 cis->itemData1 = cis16->itemData1;
1092 cis->itemID2 = cis16->itemID2;
1093 cis->itemData2 = cis16->itemData2;
1094 cis->dwLocaleId = 0; /* FIXME */
1095 *plparam = (LPARAM)cis;
1100 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1101 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1102 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1103 if (!dis) return -1;
1104 dis->CtlType = dis16->CtlType;
1105 dis->CtlID = dis16->CtlID;
1106 dis->hwndItem = dis16->hwndItem;
1107 dis->itemData = dis16->itemData;
1108 *plparam = (LPARAM)dis;
1111 case WM_MEASUREITEM:
1113 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1114 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1115 HeapAlloc(GetProcessHeap(), 0,
1116 sizeof(*mis) + sizeof(LPARAM));
1117 if (!mis) return -1;
1118 mis->CtlType = mis16->CtlType;
1119 mis->CtlID = mis16->CtlID;
1120 mis->itemID = mis16->itemID;
1121 mis->itemWidth = mis16->itemWidth;
1122 mis->itemHeight = mis16->itemHeight;
1123 mis->itemData = mis16->itemData;
1124 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1125 *plparam = (LPARAM)mis;
1130 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1131 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1133 if (!dis) return -1;
1134 dis->CtlType = dis16->CtlType;
1135 dis->CtlID = dis16->CtlID;
1136 dis->itemID = dis16->itemID;
1137 dis->itemAction = dis16->itemAction;
1138 dis->itemState = dis16->itemState;
1139 dis->hwndItem = dis16->hwndItem;
1140 dis->hDC = dis16->hDC;
1141 dis->itemData = dis16->itemData;
1142 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1143 *plparam = (LPARAM)dis;
1146 case WM_GETMINMAXINFO:
1148 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1149 sizeof(*mmi) + sizeof(LPARAM));
1150 if (!mmi) return -1;
1151 STRUCT32_MINMAXINFO16to32( MapSL(*plparam), mmi );
1152 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1153 *plparam = (LPARAM)mmi;
1158 *plparam = (LPARAM)MapSL(*plparam);
1162 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1163 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1165 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1166 cs->szTitle = MapSL(cs16->szTitle);
1167 cs->szClass = MapSL(cs16->szClass);
1168 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1169 *plparam = (LPARAM)cs;
1172 case WM_MDIGETACTIVE:
1173 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1174 *(BOOL*)(*plparam) = 0;
1178 *pmsg32=WM_MDIREFRESHMENU;
1179 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1180 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1183 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1184 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1187 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1189 HMENU hmenu=(HMENU)HIWORD(*plparam);
1190 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1191 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1192 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1194 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1195 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1197 case WM_MDIACTIVATE:
1200 *pwparam32 = (WPARAM)(HWND)HIWORD(*plparam);
1201 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1203 else /* message sent to MDI client */
1204 *pwparam32 = wParam16;
1208 NCCALCSIZE_PARAMS16 *nc16;
1209 NCCALCSIZE_PARAMS *nc;
1211 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1212 sizeof(*nc) + sizeof(LPARAM) );
1214 nc16 = MapSL(*plparam);
1215 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1218 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1219 sizeof(*nc->lppos) );
1220 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1221 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1222 if (nc->lppos) STRUCT32_WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1224 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1225 *plparam = (LPARAM)nc;
1231 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1232 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1233 sizeof(*cs) + sizeof(LPARAM) );
1235 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1236 cs->lpszName = MapSL(cs16->lpszName);
1237 cs->lpszClass = MapSL(cs16->lpszClass);
1238 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1239 *plparam = (LPARAM)cs;
1242 case WM_PARENTNOTIFY:
1243 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1245 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1246 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1249 case WM_WINDOWPOSCHANGING:
1250 case WM_WINDOWPOSCHANGED:
1252 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1253 sizeof(*wp) + sizeof(LPARAM) );
1255 STRUCT32_WINDOWPOS16to32( MapSL(*plparam), wp );
1256 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1257 *plparam = (LPARAM)wp;
1263 LPMSG16 msg16 = MapSL(*plparam);
1264 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1266 if (!msg32) return -1;
1267 msg32->hwnd = msg16->hwnd;
1268 msg32->lParam = msg16->lParam;
1269 msg32->time = msg16->time;
1270 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1271 /* this is right, right? */
1272 if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
1273 &msg32->message,&msg32->wParam,
1274 &msg32->lParam)<0) {
1275 HeapFree( GetProcessHeap(), 0, msg32 );
1278 *plparam = (LPARAM)msg32;
1283 *plparam = (LPARAM)MapSL(*plparam);
1285 case WM_ACTIVATEAPP:
1287 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1288 a 32bit window. Might be superflous with 32bit interprocess
1291 HTASK16 htask = (HTASK16) *plparam;
1292 DWORD idThread = (DWORD)TASK_GetPtr(htask)->teb->tid;
1293 *plparam = (LPARAM) idThread;
1296 case WM_ASKCBFORMATNAME:
1297 case WM_DEVMODECHANGE:
1298 case WM_PAINTCLIPBOARD:
1299 case WM_SIZECLIPBOARD:
1300 case WM_WININICHANGE:
1301 FIXME_(msg)("message %04x needs translation\n",msg16 );
1304 default: /* No translation needed */
1310 /**********************************************************************
1311 * WINPROC_UnmapMsg16To32A
1313 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1315 LRESULT WINPROC_UnmapMsg16To32A( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1320 case WM_COMPAREITEM:
1323 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1325 case WM_MEASUREITEM:
1327 MEASUREITEMSTRUCT16 *mis16;
1328 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1329 lParam = *(LPARAM *)(mis + 1);
1330 mis16 = MapSL(lParam);
1331 mis16->itemWidth = (UINT16)mis->itemWidth;
1332 mis16->itemHeight = (UINT16)mis->itemHeight;
1333 HeapFree( GetProcessHeap(), 0, mis );
1336 case WM_GETMINMAXINFO:
1338 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1339 lParam = *(LPARAM *)(mmi + 1);
1340 STRUCT32_MINMAXINFO32to16( mmi, MapSL(lParam));
1341 HeapFree( GetProcessHeap(), 0, mmi );
1346 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1347 lParam = *(LPARAM *)(cs + 1);
1348 STRUCT32_MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1349 HeapFree( GetProcessHeap(), 0, cs );
1352 case WM_MDIGETACTIVE:
1353 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1354 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1358 NCCALCSIZE_PARAMS16 *nc16;
1359 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1360 lParam = *(LPARAM *)(nc + 1);
1361 nc16 = MapSL(lParam);
1362 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1365 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1366 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1369 STRUCT32_WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1370 HeapFree( GetProcessHeap(), 0, nc->lppos );
1373 HeapFree( GetProcessHeap(), 0, nc );
1379 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1380 lParam = *(LPARAM *)(cs + 1);
1381 STRUCT32_CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1382 HeapFree( GetProcessHeap(), 0, cs );
1385 case WM_WINDOWPOSCHANGING:
1386 case WM_WINDOWPOSCHANGED:
1388 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1389 lParam = *(LPARAM *)(wp + 1);
1390 STRUCT32_WINDOWPOS32to16(wp, MapSL(lParam));
1391 HeapFree( GetProcessHeap(), 0, wp );
1397 LPMSG msg32 = (LPMSG)lParam;
1399 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1401 HeapFree( GetProcessHeap(), 0, msg32 );
1409 /**********************************************************************
1410 * WINPROC_MapMsg16To32W
1412 * Map a message from 16- to 32-bit Unicode.
1413 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1415 INT WINPROC_MapMsg16To32W( HWND16 hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1416 WPARAM *pwparam32, LPARAM *plparam )
1421 *pmsg32=(UINT)msg16;
1422 *pwparam32 = (WPARAM)wParam16;
1427 *plparam = (LPARAM)MapSL(*plparam);
1428 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1432 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1433 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1434 sizeof(*cs) + sizeof(LPARAM) );
1436 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1437 cs->lpszName = MapSL(cs16->lpszName);
1438 cs->lpszClass = MapSL(cs16->lpszClass);
1439 if (HIWORD(cs->lpszName))
1440 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
1441 (LPCSTR)cs->lpszName );
1442 if (HIWORD(cs->lpszClass))
1443 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1444 (LPCSTR)cs->lpszClass );
1445 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1446 *plparam = (LPARAM)cs;
1451 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1452 MDICREATESTRUCTW *cs =
1453 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1454 sizeof(*cs) + sizeof(LPARAM) );
1456 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1457 cs->szTitle = MapSL(cs16->szTitle);
1458 cs->szClass = MapSL(cs16->szClass);
1459 if (HIWORD(cs->szTitle))
1460 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
1461 (LPCSTR)cs->szTitle );
1462 if (HIWORD(cs->szClass))
1463 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1464 (LPCSTR)cs->szClass );
1465 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1466 *plparam = (LPARAM)cs;
1472 LPMSG16 msg16 = MapSL(*plparam);
1473 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1475 if (!msg32) return -1;
1476 msg32->hwnd = msg16->hwnd;
1477 msg32->lParam = msg16->lParam;
1478 msg32->time = msg16->time;
1479 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1480 /* this is right, right? */
1481 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1482 &msg32->message,&msg32->wParam,
1483 &msg32->lParam)<0) {
1484 HeapFree( GetProcessHeap(), 0, msg32 );
1487 *plparam = (LPARAM)msg32;
1494 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1495 *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
1496 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1500 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1501 *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
1502 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1507 case WM_SYSDEADCHAR:
1509 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1513 default: /* No Unicode translation needed */
1514 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1515 pwparam32, plparam );
1520 /**********************************************************************
1521 * WINPROC_UnmapMsg16To32W
1523 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1525 LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1532 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
1537 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1538 lParam = *(LPARAM *)(cs + 1);
1539 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1540 if (HIWORD(cs->lpszName))
1541 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1542 if (HIWORD(cs->lpszClass))
1543 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1544 HeapFree( GetProcessHeap(), 0, cs );
1549 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1550 lParam = *(LPARAM *)(cs + 1);
1551 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1552 if (HIWORD(cs->szTitle))
1553 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1554 if (HIWORD(cs->szClass))
1555 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1556 HeapFree( GetProcessHeap(), 0, cs );
1562 LPMSG msg32 = (LPMSG)lParam;
1564 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1566 HeapFree( GetProcessHeap(), 0, msg32 );
1570 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1576 /**********************************************************************
1577 * WINPROC_MapMsg32ATo16
1579 * Map a message from 32-bit Ansi to 16-bit.
1580 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1582 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1583 UINT16 *pmsg16, WPARAM16 *pwparam16,
1586 *pmsg16 = (UINT16)msg32;
1587 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1595 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1604 case EM_SCROLLCARET:
1607 case EM_GETLINECOUNT:
1619 case EM_LINEFROMCHAR:
1620 case EM_SETTABSTOPS:
1621 case EM_SETPASSWORDCHAR:
1622 case EM_EMPTYUNDOBUFFER:
1623 case EM_GETFIRSTVISIBLELINE:
1624 case EM_SETREADONLY:
1625 case EM_SETWORDBREAKPROC:
1626 case EM_GETWORDBREAKPROC:
1627 case EM_GETPASSWORDCHAR:
1628 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1633 case LB_DELETESTRING:
1634 case LB_GETANCHORINDEX:
1635 case LB_GETCARETINDEX:
1638 case LB_GETHORIZONTALEXTENT:
1639 case LB_GETITEMDATA:
1640 case LB_GETITEMHEIGHT:
1642 case LB_GETSELCOUNT:
1644 case LB_GETTOPINDEX:
1645 case LB_RESETCONTENT:
1646 case LB_SELITEMRANGE:
1647 case LB_SELITEMRANGEEX:
1648 case LB_SETANCHORINDEX:
1649 case LB_SETCARETINDEX:
1650 case LB_SETCOLUMNWIDTH:
1652 case LB_SETHORIZONTALEXTENT:
1653 case LB_SETITEMDATA:
1654 case LB_SETITEMHEIGHT:
1656 case LB_SETTOPINDEX:
1657 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1659 case CB_DELETESTRING:
1661 case CB_GETLBTEXTLEN:
1663 case CB_RESETCONTENT:
1667 case CB_SHOWDROPDOWN:
1668 case CB_SETITEMDATA:
1669 case CB_SETITEMHEIGHT:
1670 case CB_GETITEMHEIGHT:
1671 case CB_SETEXTENDEDUI:
1672 case CB_GETEXTENDEDUI:
1673 case CB_GETDROPPEDSTATE:
1674 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1677 *pmsg16 = CB_GETEDITSEL16;
1682 case LB_FINDSTRINGEXACT:
1683 case LB_INSERTSTRING:
1684 case LB_SELECTSTRING:
1688 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1689 if (!str) return -1;
1690 *plparam = (LPARAM)SEGPTR_GET(str);
1692 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1697 case CB_FINDSTRINGEXACT:
1698 case CB_INSERTSTRING:
1699 case CB_SELECTSTRING:
1702 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1703 if (!str) return -1;
1704 *plparam = (LPARAM)SEGPTR_GET(str);
1706 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1709 case LB_GETITEMRECT:
1712 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1713 if (!rect) return -1;
1714 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1715 *plparam = (LPARAM)SEGPTR_GET(rect);
1717 *pmsg16 = LB_GETITEMRECT16;
1719 case LB_GETSELITEMS:
1722 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1723 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1724 + sizeof(LPARAM)))) return -1;
1725 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1726 *plparam = (LPARAM)SEGPTR_GET(items);
1728 *pmsg16 = LB_GETSELITEMS16;
1730 case LB_SETTABSTOPS:
1735 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1736 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1737 + sizeof(LPARAM)))) return -1;
1738 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1739 *plparam = (LPARAM)SEGPTR_GET(stops);
1742 *pmsg16 = LB_SETTABSTOPS16;
1745 case CB_GETDROPPEDCONTROLRECT:
1748 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1749 if (!rect) return -1;
1750 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1751 *plparam = (LPARAM)SEGPTR_GET(rect);
1753 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1757 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1758 *pmsg16 = LB_GETTEXT16;
1762 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1763 *pmsg16 = CB_GETLBTEXT16;
1768 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1769 *pmsg16 = EM_SETSEL16;
1776 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1780 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1782 case WM_CTLCOLORMSGBOX:
1783 case WM_CTLCOLOREDIT:
1784 case WM_CTLCOLORLISTBOX:
1785 case WM_CTLCOLORBTN:
1786 case WM_CTLCOLORDLG:
1787 case WM_CTLCOLORSCROLLBAR:
1788 case WM_CTLCOLORSTATIC:
1789 *pmsg16 = WM_CTLCOLOR;
1790 *plparam = MAKELPARAM( (HWND16)*plparam,
1791 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1793 case WM_COMPAREITEM:
1795 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1796 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1797 if (!cis) return -1;
1798 cis->CtlType = (UINT16)cis32->CtlType;
1799 cis->CtlID = (UINT16)cis32->CtlID;
1800 cis->hwndItem = (HWND16)cis32->hwndItem;
1801 cis->itemID1 = (UINT16)cis32->itemID1;
1802 cis->itemData1 = cis32->itemData1;
1803 cis->itemID2 = (UINT16)cis32->itemID2;
1804 cis->itemData2 = cis32->itemData2;
1805 *plparam = (LPARAM)SEGPTR_GET(cis);
1810 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1811 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1812 if (!dis) return -1;
1813 dis->CtlType = (UINT16)dis32->CtlType;
1814 dis->CtlID = (UINT16)dis32->CtlID;
1815 dis->itemID = (UINT16)dis32->itemID;
1816 dis->hwndItem = (HWND16)dis32->hwndItem;
1817 dis->itemData = dis32->itemData;
1818 *plparam = (LPARAM)SEGPTR_GET(dis);
1823 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1824 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1825 if (!dis) return -1;
1826 dis->CtlType = (UINT16)dis32->CtlType;
1827 dis->CtlID = (UINT16)dis32->CtlID;
1828 dis->itemID = (UINT16)dis32->itemID;
1829 dis->itemAction = (UINT16)dis32->itemAction;
1830 dis->itemState = (UINT16)dis32->itemState;
1831 dis->hwndItem = (HWND16)dis32->hwndItem;
1832 dis->hDC = (HDC16)dis32->hDC;
1833 dis->itemData = dis32->itemData;
1834 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1835 *plparam = (LPARAM)SEGPTR_GET(dis);
1838 case WM_MEASUREITEM:
1840 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1841 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1842 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1843 if (!mis) return -1;
1844 mis->CtlType = (UINT16)mis32->CtlType;
1845 mis->CtlID = (UINT16)mis32->CtlID;
1846 mis->itemID = (UINT16)mis32->itemID;
1847 mis->itemWidth = (UINT16)mis32->itemWidth;
1848 mis->itemHeight = (UINT16)mis32->itemHeight;
1849 mis->itemData = mis32->itemData;
1850 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1851 *plparam = (LPARAM)SEGPTR_GET(mis);
1854 case WM_GETMINMAXINFO:
1856 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1858 if (!mmi) return -1;
1859 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1860 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1861 *plparam = (LPARAM)SEGPTR_GET(mmi);
1867 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1868 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1869 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1870 *plparam = (LPARAM)SEGPTR_GET(str);
1875 MDICREATESTRUCT16 *cs;
1876 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1879 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1880 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1881 name = SEGPTR_STRDUP( cs32->szTitle );
1882 cls = SEGPTR_STRDUP( cs32->szClass );
1883 cs->szTitle = SEGPTR_GET(name);
1884 cs->szClass = SEGPTR_GET(cls);
1885 *plparam = (LPARAM)SEGPTR_GET(cs);
1888 case WM_MDIGETACTIVE:
1891 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1892 (HMENU16)LOWORD(*plparam) );
1893 *pwparam16 = (*plparam == 0);
1896 if(HIWORD(wParam32) & MF_POPUP)
1899 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1901 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1907 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1909 case WM_MDIACTIVATE:
1910 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1912 *pwparam16 = ((HWND)*plparam == hwnd);
1913 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1914 (HWND16)LOWORD(wParam32) );
1918 *pwparam16 = (HWND)wParam32;
1924 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1925 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1928 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1932 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1933 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1934 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1939 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1940 nc->lppos = SEGPTR_GET(wp);
1942 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1943 *plparam = (LPARAM)SEGPTR_GET(nc);
1950 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1953 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1954 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1955 name = SEGPTR_STRDUP( cs32->lpszName );
1956 cls = SEGPTR_STRDUP( cs32->lpszClass );
1957 cs->lpszName = SEGPTR_GET(name);
1958 cs->lpszClass = SEGPTR_GET(cls);
1959 *plparam = (LPARAM)SEGPTR_GET(cs);
1962 case WM_PARENTNOTIFY:
1963 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1964 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1965 /* else nothing to do */
1968 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1972 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1973 if (!str) return -1;
1974 *plparam = (LPARAM)SEGPTR_GET(str);
1977 case WM_WINDOWPOSCHANGING:
1978 case WM_WINDOWPOSCHANGED:
1980 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
1983 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
1984 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1985 *plparam = (LPARAM)SEGPTR_GET(wp);
1990 LPMSG msg32 = (LPMSG) *plparam;
1991 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
1993 if (!msg16) return -1;
1994 msg16->hwnd = msg32->hwnd;
1995 msg16->lParam = msg32->lParam;
1996 msg16->time = msg32->time;
1997 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
1998 /* this is right, right? */
1999 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2000 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
2001 SEGPTR_FREE( msg16 );
2004 *plparam = (LPARAM)SEGPTR_GET(msg16);
2009 case WM_ACTIVATEAPP:
2011 *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2014 case WM_ASKCBFORMATNAME:
2015 case WM_DEVMODECHANGE:
2016 case WM_PAINTCLIPBOARD:
2017 case WM_SIZECLIPBOARD:
2018 case WM_WININICHANGE:
2019 FIXME_(msg)("message %04x needs translation\n", msg32 );
2021 case WM_SIZING: /* should not be send to 16-bit apps */
2023 default: /* No translation needed */
2029 /**********************************************************************
2030 * WINPROC_UnmapMsg32ATo16
2032 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2034 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2043 case LB_FINDSTRINGEXACT:
2044 case LB_INSERTSTRING:
2045 case LB_SELECTSTRING:
2046 case LB_SETTABSTOPS:
2049 case CB_FINDSTRINGEXACT:
2050 case CB_INSERTSTRING:
2051 case CB_SELECTSTRING:
2053 case WM_COMPAREITEM:
2057 SEGPTR_FREE( MapSL(p16->lParam) );
2060 case CB_GETDROPPEDCONTROLRECT:
2061 case LB_GETITEMRECT:
2063 RECT16 *rect = MapSL(p16->lParam);
2064 p16->lParam = *(LPARAM *)(rect + 1);
2065 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2066 SEGPTR_FREE( rect );
2069 case LB_GETSELITEMS:
2072 LPINT16 items = MapSL(lParam);
2073 p16->lParam = *((LPARAM *)items - 1);
2074 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2075 SEGPTR_FREE( (LPARAM *)items - 1 );
2081 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2083 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2088 UnMapLS( (SEGPTR)(p16->lParam) );
2091 case WM_MEASUREITEM:
2093 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2094 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2095 mis32->itemWidth = mis->itemWidth;
2096 mis32->itemHeight = mis->itemHeight;
2100 case WM_GETMINMAXINFO:
2102 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2103 p16->lParam = *(LPARAM *)(mmi + 1);
2104 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2110 LPSTR str = MapSL(p16->lParam);
2111 p16->lParam = *((LPARAM *)str - 1);
2112 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2113 SEGPTR_FREE( (LPARAM *)str - 1 );
2118 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2119 SEGPTR_FREE( MapSL(cs->szTitle) );
2120 SEGPTR_FREE( MapSL(cs->szClass) );
2124 case WM_MDIGETACTIVE:
2125 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2126 p16->lResult = (HWND)LOWORD(p16->lResult);
2130 NCCALCSIZE_PARAMS *nc32;
2131 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2132 p16->lParam = *(LPARAM *)(nc + 1);
2133 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2134 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2137 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2138 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2139 STRUCT32_WINDOWPOS16to32( MapSL(nc->lppos), nc32->lppos );
2140 SEGPTR_FREE( MapSL(nc->lppos) );
2148 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2149 SEGPTR_FREE( MapSL(cs->lpszName) );
2150 SEGPTR_FREE( MapSL(cs->lpszClass) );
2154 case WM_WINDOWPOSCHANGING:
2155 case WM_WINDOWPOSCHANGED:
2157 WINDOWPOS16 *wp = MapSL(p16->lParam);
2158 p16->lParam = *(LPARAM *)(wp + 1);
2159 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2164 UnMapLS(p16->lParam);
2169 LPMSG16 msg16 = MapSL(p16->lParam);
2171 msgp16.wParam=msg16->wParam;
2172 msgp16.lParam=msg16->lParam;
2173 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2174 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2183 /**********************************************************************
2184 * WINPROC_MapMsg32WTo16
2186 * Map a message from 32-bit Unicode to 16-bit.
2187 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2189 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2190 UINT16 *pmsg16, WPARAM16 *pwparam16,
2196 *pmsg16 = LOWORD(msg32);
2197 *pwparam16 = LOWORD(wParam32);
2202 case LB_FINDSTRINGEXACT:
2203 case LB_INSERTSTRING:
2204 case LB_SELECTSTRING:
2208 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2209 if (!str) return -1;
2210 *plparam = (LPARAM)SEGPTR_GET(str);
2212 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2217 case CB_FINDSTRINGEXACT:
2218 case CB_INSERTSTRING:
2219 case CB_SELECTSTRING:
2222 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2223 if (!str) return -1;
2224 *plparam = (LPARAM)SEGPTR_GET(str);
2226 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2233 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2236 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
2237 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2238 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2239 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2240 cs->lpszName = SEGPTR_GET(name);
2241 cs->lpszClass = SEGPTR_GET(cls);
2242 *plparam = (LPARAM)SEGPTR_GET(cs);
2247 MDICREATESTRUCT16 *cs;
2248 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2251 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
2252 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2253 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2254 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2255 cs->szTitle = SEGPTR_GET(name);
2256 cs->szClass = SEGPTR_GET(cls);
2257 *plparam = (LPARAM)SEGPTR_GET(cs);
2262 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2263 if (!str) return -1;
2264 *plparam = (LPARAM)SEGPTR_GET(str);
2269 if ( WINPROC_TestLBForStr( hwnd ))
2271 LPSTR str = (LPSTR) SEGPTR_ALLOC( 256 ); /* fixme: fixed sized buffer */
2272 if (!str) return -1;
2273 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2274 *plparam = (LPARAM)SEGPTR_GET(str);
2279 wch = LOWORD(wParam32);
2280 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2282 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2285 wch = LOWORD(wParam32);
2286 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2288 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2293 case WM_SYSDEADCHAR:
2295 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2299 default: /* No Unicode translation needed (?) */
2300 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2301 pwparam16, plparam );
2306 /**********************************************************************
2307 * WINPROC_UnmapMsg32WTo16
2309 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2311 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2318 LPSTR str = MapSL(p16->lParam);
2319 p16->lParam = *((LPARAM *)str - 1);
2320 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2321 SEGPTR_FREE( (LPARAM *)str - 1 );
2326 if ( WINPROC_TestLBForStr( hwnd ))
2328 LPSTR str = MapSL(p16->lParam);
2329 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2330 SEGPTR_FREE( (LPARAM *) str );
2334 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2340 /**********************************************************************
2341 * WINPROC_CallProc32ATo32W
2343 * Call a window procedure, translating args from Ansi to Unicode.
2345 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2346 UINT msg, WPARAM wParam,
2352 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2353 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2354 SPY_GetMsgName(msg), wParam, lParam );
2357 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2358 if( unmap ) WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
2363 /**********************************************************************
2364 * WINPROC_CallProc32WTo32A
2366 * Call a window procedure, translating args from Unicode to Ansi.
2368 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2369 UINT msg, WPARAM wParam,
2375 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
2376 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2377 SPY_GetMsgName(msg), wParam, lParam );
2380 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2381 if( unmap ) WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2386 /**********************************************************************
2387 * WINPROC_CallProc16To32A
2389 * Call a 32-bit window procedure, translating the 16-bit args.
2391 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd,
2392 UINT16 msg, WPARAM16 wParam,
2399 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2401 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2402 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
2405 /**********************************************************************
2406 * WINPROC_Thunk16To32A
2408 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args )
2410 HWND16 hwnd = *(HWND16 *)( args+8 );
2411 UINT16 msg = *(HWND16 *)( args+6 );
2412 WPARAM16 wParam = *(HWND16 *)( args+4 );
2413 LPARAM lParam = *(LPARAM *)( args+0 );
2415 return WINPROC_CallProc16To32A( func, hwnd, msg, wParam, lParam );
2419 /**********************************************************************
2420 * WINPROC_CallProc16To32W
2422 * Call a 32-bit window procedure, translating the 16-bit args.
2424 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd,
2425 UINT16 msg, WPARAM16 wParam,
2432 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2435 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2437 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
2440 /**********************************************************************
2441 * WINPROC_Thunk16To32W
2443 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args )
2445 HWND16 hwnd = *(HWND16 *)( args+8 );
2446 UINT16 msg = *(HWND16 *)( args+6 );
2447 WPARAM16 wParam = *(HWND16 *)( args+4 );
2448 LPARAM lParam = *(LPARAM *)( args+0 );
2450 return WINPROC_CallProc16To32W( func, hwnd, msg, wParam, lParam );
2453 /**********************************************************************
2454 * WINPROC_CallProc32ATo16
2456 * Call a 16-bit window procedure, translating the 32-bit args.
2458 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2459 UINT msg, WPARAM wParam,
2465 mp16.lParam = lParam;
2466 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2467 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2469 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2470 mp16.wParam, mp16.lParam );
2471 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2472 return mp16.lResult;
2476 /**********************************************************************
2477 * WINPROC_CallProc32WTo16
2479 * Call a 16-bit window procedure, translating the 32-bit args.
2481 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2482 UINT msg, WPARAM wParam,
2488 mp16.lParam = lParam;
2489 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2490 &mp16.lParam ) == -1)
2492 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2493 mp16.wParam, mp16.lParam );
2494 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2495 return mp16.lResult;
2499 /**********************************************************************
2500 * CallWindowProc (USER.122)
2501 * CallWindowProc16 (USER32.@)
2503 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2504 WPARAM16 wParam, LPARAM lParam )
2506 WINDOWPROC *proc = WINPROC_GetPtr( func );
2509 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2512 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2513 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2519 if (!proc->thunk.t_from32.proc) return 0;
2520 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2521 hwnd, msg, wParam, lParam );
2523 if (!proc->thunk.t_from16.proc) return 0;
2524 return WINPROC_CallProc16To32A( proc->thunk.t_from16.proc,
2525 hwnd, msg, wParam, lParam );
2527 if (!proc->thunk.t_from16.proc) return 0;
2528 return WINPROC_CallProc16To32W( proc->thunk.t_from16.proc,
2529 hwnd, msg, wParam, lParam );
2531 WARN_(relay)("Invalid proc %p\n", proc );
2537 /**********************************************************************
2538 * CallWindowProcA (USER32.@)
2540 * The CallWindowProc() function invokes the windows procedure _func_,
2541 * with _hwnd_ as the target window, the message specified by _msg_, and
2542 * the message parameters _wParam_ and _lParam_.
2544 * Some kinds of argument conversion may be done, I'm not sure what.
2546 * CallWindowProc() may be used for windows subclassing. Use
2547 * SetWindowLong() to set a new windows procedure for windows of the
2548 * subclass, and handle subclassed messages in the new windows
2549 * procedure. The new windows procedure may then use CallWindowProc()
2550 * with _func_ set to the parent class's windows procedure to dispatch
2551 * the message to the superclass.
2555 * The return value is message dependent.
2561 LRESULT WINAPI CallWindowProcA(
2562 WNDPROC func, /* [in] window procedure */
2563 HWND hwnd, /* [in] target window */
2564 UINT msg, /* [in] message */
2565 WPARAM wParam, /* [in] message dependent parameter */
2566 LPARAM lParam /* [in] message dependent parameter */
2568 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2570 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2573 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2574 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2580 if (!proc->thunk.t_from32.proc) return 0;
2581 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2582 hwnd, msg, wParam, lParam );
2584 if (!proc->thunk.t_from16.proc) return 0;
2585 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2586 hwnd, msg, wParam, lParam );
2588 if (!proc->thunk.t_from16.proc) return 0;
2589 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2590 hwnd, msg, wParam, lParam );
2592 WARN_(relay)("Invalid proc %p\n", proc );
2598 /**********************************************************************
2599 * CallWindowProcW (USER32.@)
2601 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2602 WPARAM wParam, LPARAM lParam )
2604 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2606 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2609 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2610 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2616 if (!proc->thunk.t_from32.proc) return 0;
2617 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2618 hwnd, msg, wParam, lParam );
2620 if (!proc->thunk.t_from16.proc) return 0;
2621 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2622 hwnd, msg, wParam, lParam );
2624 if (!proc->thunk.t_from16.proc) return 0;
2625 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2626 hwnd, msg, wParam, lParam );
2628 WARN_(relay)("Invalid proc %p\n", proc );