2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
13 #include "wine/winestring.h"
14 #include "stackframe.h"
15 #include "builtin16.h"
17 #include "selectors.h"
21 #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 )
165 TRACE_(relay)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
166 proc, hwnd, SPY_GetMsgName(msg), wParam, lParam );
167 /* To avoid any deadlocks, all the locks on the windows structures
168 must be suspended before the control is passed to the application */
169 iWndsLocks = WIN_SuspendWndsLock();
170 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
171 WIN_RestoreWndsLock(iWndsLocks);
172 TRACE_(relay)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx) ret=%08lx\n",
173 proc, hwnd, SPY_GetMsgName(msg), wParam, lParam, retvalue );
177 /***********************************************************************
178 * WINPROC_CallWndProc16
180 * Call a 16-bit window procedure
182 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
183 UINT16 msg, WPARAM16 wParam,
189 WND *wndPtr = WIN_FindWndPtr( hwnd );
191 TEB *teb = NtCurrentTeb();
194 /* Window procedures want ax = hInstance, ds = es = ss */
196 memset(&context, '\0', sizeof(context));
197 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
198 context.Eax = wndPtr ? wndPtr->hInstance : context.SegDs;
199 context.SegCs = SELECTOROF(proc);
200 context.Eip = OFFSETOF(proc);
201 context.Ebp = OFFSETOF(teb->cur_stack)
202 + (WORD)&((STACK16FRAME*)0)->bp;
204 WIN_ReleaseWndPtr(wndPtr);
208 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
209 work if structures passed in lParam are placed in the stack/data
210 segment. Programmers easily make the mistake of converting lParam
211 to a near rather than a far pointer, since Windows apparently
212 allows this. We copy the structures to the 16 bit stack; this is
213 ugly but makes these programs work. */
218 offset = sizeof(CREATESTRUCT16); break;
220 offset = sizeof(DRAWITEMSTRUCT16); break;
222 offset = sizeof(COMPAREITEMSTRUCT16); break;
226 void *s = PTR_SEG_TO_LIN(lParam);
227 lParam = stack16_push( offset );
228 memcpy( PTR_SEG_TO_LIN(lParam), s, offset );
232 iWndsLocks = WIN_SuspendWndsLock();
234 args = (WORD *)THREAD_STACK16(teb) - 5;
235 args[0] = LOWORD(lParam);
236 args[1] = HIWORD(lParam);
241 CallTo16RegisterShort( &context, 5 * sizeof(WORD) );
242 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
243 if (offset) stack16_pop( offset );
245 WIN_RestoreWndsLock(iWndsLocks);
251 /**********************************************************************
254 * Return a pointer to the win proc.
256 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
261 /* Check for a linear pointer */
263 if (HEAP_IsInsideHeap( WinProcHeap, 0, (LPVOID)handle ))
265 ptr = (BYTE *)handle;
266 /* First check if it is the jmp address */
267 if (*ptr == 0xe9 /* jmp */) ptr -= (int)&((WINDOWPROC *)0)->jmp -
268 (int)&((WINDOWPROC *)0)->thunk;
269 /* Now it must be the thunk address */
270 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
271 /* Now we have a pointer to the WINDOWPROC struct */
272 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
273 return (WINDOWPROC *)ptr;
276 /* Check for a segmented pointer */
278 if (!IsBadReadPtr16((SEGPTR)handle,sizeof(WINDOWPROC)-sizeof(proc->thunk)))
280 ptr = (BYTE *)PTR_SEG_TO_LIN(handle);
281 if (!HEAP_IsInsideHeap( WinProcHeap, 0, ptr )) return NULL;
282 /* It must be the thunk address */
283 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
284 /* Now we have a pointer to the WINDOWPROC struct */
285 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
286 return (WINDOWPROC *)ptr;
293 /**********************************************************************
294 * WINPROC_AllocWinProc
296 * Allocate a new window procedure.
298 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
299 WINDOWPROCUSER user )
301 WINDOWPROC *proc, *oldproc;
303 /* Allocate a window procedure */
305 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
307 /* Check if the function is already a win proc */
309 if ((oldproc = WINPROC_GetPtr( func )))
318 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
319 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
320 proc->thunk.t_from32.proc = func;
321 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
322 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
323 proc->thunk.t_from32.relay = /* relative jump */
324 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
325 (DWORD)(&proc->thunk.t_from32.relay + 1));
329 proc->thunk.t_from16.pushw_bp = 0x5566; /* pushw %bp */
330 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
331 proc->thunk.t_from16.proc = (FARPROC)func;
332 proc->thunk.t_from16.pushw_ax = 0x5066; /* pushw %ax */
333 proc->thunk.t_from16.pushl_relay = 0x68; /* pushl $relay */
334 proc->thunk.t_from16.relay = (type == WIN_PROC_32A) ?
335 (void(*)())WINPROC_Thunk16To32A :
336 (void(*)())WINPROC_Thunk16To32W;
337 proc->thunk.t_from16.lcall = 0x9a; /* lcall cs:glue */
338 proc->thunk.t_from16.glue = (void*)__wine_call_from_16_long;
339 proc->thunk.t_from16.cs = __get_cs();
340 proc->thunk.t_from16.lret = 0xca66;
341 proc->thunk.t_from16.nArgs = 10;
342 proc->jmp.jmp = 0xe9;
343 /* Fixup relative jump */
344 proc->jmp.proc = (WNDPROC)((DWORD)func -
345 (DWORD)(&proc->jmp.proc + 1));
348 /* Should not happen */
351 proc->magic = WINPROC_MAGIC;
356 TRACE_(win)("(%08x,%d): returning %08x\n",
357 (UINT)func, type, (UINT)proc );
362 /**********************************************************************
365 * Get a window procedure pointer that can be passed to the Windows program.
367 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
369 if (!proc) return NULL;
370 if (type == WIN_PROC_16) /* We want a 16:16 address */
372 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
373 return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
375 return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
376 &((WINDOWPROC *)proc)->thunk );
378 else /* We want a 32-bit address */
380 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
381 return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
382 else if (type != ((WINDOWPROC *)proc)->type)
383 /* Have to return the jmp address if types don't match */
384 return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
386 /* Some Win16 programs want to get back the proc they set */
387 return (WNDPROC16)((WINDOWPROC *)proc)->thunk.t_from16.proc;
392 /**********************************************************************
395 * Set the window procedure for a window or class. There are
396 * three tree classes of winproc callbacks:
398 * 1) class -> wp - not subclassed
399 * class -> wp -> wp -> wp -> wp - SetClassLong()
401 * 2) window -' / - not subclassed
402 * window -> wp -> wp ' - SetWindowLong()
404 * 3) timer -> wp - SetTimer()
406 * Initially, winproc of the window points to the current winproc
407 * thunk of its class. Subclassing prepends a new thunk to the
408 * window winproc chain at the head of the list. Thus, window thunk
409 * list includes class thunks and the latter are preserved when the
410 * window is destroyed.
413 BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
414 WINDOWPROCTYPE type, WINDOWPROCUSER user )
416 BOOL bRecycle = FALSE;
417 WINDOWPROC *proc, **ppPrev;
419 /* Check if function is already in the list */
421 ppPrev = (WINDOWPROC **)pFirst;
422 proc = WINPROC_GetPtr( func );
429 if ((*ppPrev)->user != user)
431 /* terminal thunk is being restored */
433 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
434 *(WINDOWPROC **)pFirst = *ppPrev;
443 if (((*ppPrev)->type == type) &&
444 (func == WINPROC_THUNKPROC(*ppPrev)))
451 /* WPF_CLASS thunk terminates window thunk list */
452 if ((*ppPrev)->user != user) break;
453 ppPrev = &(*ppPrev)->next;
458 /* Extract this thunk from the list */
460 *ppPrev = proc->next;
462 else /* Allocate a new one */
464 if (proc) /* Was already a win proc */
467 func = WINPROC_THUNKPROC(proc);
469 proc = WINPROC_AllocWinProc( func, type, user );
470 if (!proc) return FALSE;
473 /* Add the win proc at the head of the list */
475 TRACE_(win)("(%08x,%08x,%d): res=%08x\n",
476 (UINT)*pFirst, (UINT)func, type, (UINT)proc );
477 proc->next = *(WINDOWPROC **)pFirst;
478 *(WINDOWPROC **)pFirst = proc;
483 /**********************************************************************
486 * Free a list of win procs.
488 void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
492 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
493 if (((WINDOWPROC *)proc)->user != user) break;
494 TRACE_(win)("freeing %08x\n", (UINT)proc);
495 HeapFree( WinProcHeap, 0, proc );
501 /**********************************************************************
502 * WINPROC_GetProcType
504 * Return the window procedure type.
506 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
509 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
510 return WIN_PROC_INVALID;
511 return ((WINDOWPROC *)proc)->type;
513 /**********************************************************************
514 * WINPROC_TestCBForStr
516 * Return TRUE if the lparam is a string
518 static BOOL WINPROC_TestCBForStr ( HWND hwnd )
521 WND * wnd = WIN_FindWndPtr(hwnd);
522 retvalue = ( !(LOWORD(wnd->dwStyle) & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) ||
523 (LOWORD(wnd->dwStyle) & CBS_HASSTRINGS) );
524 WIN_ReleaseWndPtr(wnd);
527 /**********************************************************************
528 * WINPROC_TestLBForStr
530 * Return TRUE if the lparam is a string
532 static BOOL WINPROC_TestLBForStr ( HWND hwnd )
535 WND * wnd = WIN_FindWndPtr(hwnd);
536 retvalue = ( !(LOWORD(wnd->dwStyle) & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) ||
537 (LOWORD(wnd->dwStyle) & LBS_HASSTRINGS) );
538 WIN_ReleaseWndPtr(wnd);
542 /**********************************************************************
543 * WINPROC_MapMsg32ATo32W
545 * Map a message from Ansi to Unicode.
546 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
549 * WM_CHARTOITEM, WM_MENUCHAR
552 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
553 * the first four bytes are the handle of the icon
554 * when the WM_SETTEXT message has been used to set the icon
556 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
562 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
563 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
565 *ptr++ = *plparam; /* Store previous lParam */
566 *plparam = (LPARAM)ptr;
569 /* lparam is string (0-terminated) */
571 case WM_WININICHANGE:
574 case CB_FINDSTRINGEXACT:
575 case CB_SELECTSTRING:
579 case LB_SELECTSTRING:
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 ( WINPROC_TestLBForStr( hwnd ))
625 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
626 return (*plparam ? 1 : -1);
628 case LB_GETTEXT: /* fixme: fixed sized buffer */
629 { if ( WINPROC_TestLBForStr( hwnd ))
630 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
632 *ptr++ = *plparam; /* Store previous lParam */
633 *plparam = (LPARAM)ptr;
640 case CB_INSERTSTRING:
641 if ( WINPROC_TestCBForStr( hwnd ))
642 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
643 return (*plparam ? 1 : -1);
645 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
646 { if ( WINPROC_TestCBForStr( hwnd ))
647 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
649 *ptr++ = *plparam; /* Store previous lParam */
650 *plparam = (LPARAM)ptr;
657 { WORD len = (WORD)*plparam;
658 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
660 *ptr++ = *plparam; /* Store previous lParam */
661 *((WORD *) ptr) = len; /* Store the length */
662 *plparam = (LPARAM)ptr;
673 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
678 case WM_ASKCBFORMATNAME:
679 case WM_DEVMODECHANGE:
680 case WM_PAINTCLIPBOARD:
681 case WM_SIZECLIPBOARD:
682 case EM_SETPASSWORDCHAR:
683 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg), msg );
685 default: /* No translation needed */
691 /**********************************************************************
692 * WINPROC_UnmapMsg32ATo32W
694 * Unmap a message that was mapped from Ansi to Unicode.
696 void WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
702 LPARAM *ptr = (LPARAM *)lParam - 1;
703 lstrcpynWtoA( (LPSTR)*ptr, (LPWSTR)lParam, wParam );
704 HeapFree( GetProcessHeap(), 0, ptr );
712 { CREATESTRUCTW cs; /* new structure */
713 LPWSTR lpszName; /* allocated Name */
714 LPWSTR lpszClass; /* allocated Class */
716 struct s *xs = (struct s *)lParam;
717 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
718 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
719 HeapFree( GetProcessHeap(), 0, xs );
725 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
726 if (HIWORD(cs->szTitle))
727 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
728 if (HIWORD(cs->szClass))
729 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
730 HeapFree( GetProcessHeap(), 0, cs );
735 case WM_WININICHANGE:
738 case CB_FINDSTRINGEXACT:
739 case CB_SELECTSTRING:
743 case LB_SELECTSTRING:
745 HeapFree( GetProcessHeap(), 0, (void *)lParam );
750 case LB_INSERTSTRING:
751 if ( WINPROC_TestLBForStr( hwnd ))
752 HeapFree( GetProcessHeap(), 0, (void *)lParam );
756 { if ( WINPROC_TestLBForStr( hwnd ))
757 { LPARAM *ptr = (LPARAM *)lParam - 1;
758 lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
759 HeapFree( GetProcessHeap(), 0, ptr );
766 case CB_INSERTSTRING:
767 if ( WINPROC_TestCBForStr( hwnd ))
768 HeapFree( GetProcessHeap(), 0, (void *)lParam );
772 { if ( WINPROC_TestCBForStr( hwnd ))
773 { LPARAM *ptr = (LPARAM *)lParam - 1;
774 lstrcpyWtoA( (LPSTR)*ptr, (LPWSTR)(lParam) );
775 HeapFree( GetProcessHeap(), 0, ptr );
782 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
783 WORD len = *(WORD *) lParam;
784 lstrcpynWtoA( (LPSTR)*ptr , (LPWSTR)lParam, len );
785 HeapFree( GetProcessHeap(), 0, ptr );
792 /**********************************************************************
793 * WINPROC_MapMsg32WTo32A
795 * Map a message from Unicode to Ansi.
796 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
798 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
804 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
805 *pwparam + sizeof(LPARAM) );
807 *ptr++ = *plparam; /* Store previous lParam */
808 *plparam = (LPARAM)ptr;
813 case WM_WININICHANGE:
816 case CB_FINDSTRINGEXACT:
817 case CB_SELECTSTRING:
821 case LB_SELECTSTRING:
823 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
824 return (*plparam ? 1 : -1);
829 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
832 *cs = *(CREATESTRUCTA *)*plparam;
833 if (HIWORD(cs->lpszName))
834 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
835 (LPCWSTR)cs->lpszName );
836 if (HIWORD(cs->lpszClass))
837 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
838 (LPCWSTR)cs->lpszClass);
839 *plparam = (LPARAM)cs;
844 MDICREATESTRUCTA *cs =
845 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
847 *cs = *(MDICREATESTRUCTA *)*plparam;
848 if (HIWORD(cs->szTitle))
849 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
850 (LPCWSTR)cs->szTitle );
851 if (HIWORD(cs->szClass))
852 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
853 (LPCWSTR)cs->szClass );
854 *plparam = (LPARAM)cs;
860 case LB_INSERTSTRING:
861 if ( WINPROC_TestLBForStr( hwnd ))
862 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
863 return (*plparam ? 1 : -1);
865 case LB_GETTEXT: /* fixme: fixed sized buffer */
866 { if ( WINPROC_TestLBForStr( hwnd ))
867 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
869 *ptr++ = *plparam; /* Store previous lParam */
870 *plparam = (LPARAM)ptr;
877 case CB_INSERTSTRING:
878 if ( WINPROC_TestCBForStr( hwnd ))
879 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
880 return (*plparam ? 1 : -1);
882 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
883 { if ( WINPROC_TestCBForStr( hwnd ))
884 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
886 *ptr++ = *plparam; /* Store previous lParam */
887 *plparam = (LPARAM)ptr;
894 { WORD len = (WORD)*plparam;
895 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
897 *ptr++ = *plparam; /* Store previous lParam */
898 *((WORD *) ptr) = len; /* Store the length */
899 *plparam = (LPARAM)ptr;
908 WCHAR wch = *pwparam;
910 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
915 case WM_ASKCBFORMATNAME:
916 case WM_DEVMODECHANGE:
917 case WM_PAINTCLIPBOARD:
918 case WM_SIZECLIPBOARD:
919 case EM_SETPASSWORDCHAR:
920 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
922 default: /* No translation needed */
928 /**********************************************************************
929 * WINPROC_UnmapMsg32WTo32A
931 * Unmap a message that was mapped from Unicode to Ansi.
933 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
939 LPARAM *ptr = (LPARAM *)lParam - 1;
940 lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)lParam, wParam );
941 HeapFree( GetProcessHeap(), 0, ptr );
946 case WM_WININICHANGE:
949 case CB_FINDSTRINGEXACT:
950 case CB_SELECTSTRING:
954 case LB_SELECTSTRING:
956 HeapFree( GetProcessHeap(), 0, (void *)lParam );
962 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
963 if (HIWORD(cs->lpszName))
964 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
965 if (HIWORD(cs->lpszClass))
966 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
967 HeapFree( GetProcessHeap(), 0, cs );
973 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
974 if (HIWORD(cs->szTitle))
975 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
976 if (HIWORD(cs->szClass))
977 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
978 HeapFree( GetProcessHeap(), 0, cs );
984 case LB_INSERTSTRING:
985 if ( WINPROC_TestLBForStr( hwnd ))
986 HeapFree( GetProcessHeap(), 0, (void *)lParam );
990 { if ( WINPROC_TestLBForStr( hwnd ))
991 { LPARAM *ptr = (LPARAM *)lParam - 1;
992 lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
993 HeapFree( GetProcessHeap(), 0, ptr );
1000 case CB_INSERTSTRING:
1001 if ( WINPROC_TestCBForStr( hwnd ))
1002 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1006 { if ( WINPROC_TestCBForStr( hwnd ))
1007 { LPARAM *ptr = (LPARAM *)lParam - 1;
1008 lstrcpyAtoW( (LPWSTR)*ptr, (LPSTR)(lParam) );
1009 HeapFree( GetProcessHeap(), 0, ptr );
1014 /* Multiline edit */
1016 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1017 WORD len = *(WORD *)ptr;
1018 lstrcpynAtoW( (LPWSTR) *ptr, (LPSTR)lParam, len );
1019 HeapFree( GetProcessHeap(), 0, ptr );
1026 /**********************************************************************
1027 * WINPROC_MapMsg16To32A
1029 * Map a message from 16- to 32-bit Ansi.
1030 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1032 INT WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1033 WPARAM *pwparam32, LPARAM *plparam )
1035 *pmsg32 = (UINT)msg16;
1036 *pwparam32 = (WPARAM)wParam16;
1043 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1044 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1048 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1049 *plparam = (LPARAM)(HWND)HIWORD(*plparam);
1052 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1053 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1054 *pwparam32 = (WPARAM)(HDC)wParam16;
1055 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1057 case WM_COMPAREITEM:
1059 COMPAREITEMSTRUCT16* cis16 = (COMPAREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1060 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1061 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1062 if (!cis) return -1;
1063 cis->CtlType = cis16->CtlType;
1064 cis->CtlID = cis16->CtlID;
1065 cis->hwndItem = cis16->hwndItem;
1066 cis->itemID1 = cis16->itemID1;
1067 cis->itemData1 = cis16->itemData1;
1068 cis->itemID2 = cis16->itemID2;
1069 cis->itemData2 = cis16->itemData2;
1070 cis->dwLocaleId = 0; /* FIXME */
1071 *plparam = (LPARAM)cis;
1076 DELETEITEMSTRUCT16* dis16 = (DELETEITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1077 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1078 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1079 if (!dis) return -1;
1080 dis->CtlType = dis16->CtlType;
1081 dis->CtlID = dis16->CtlID;
1082 dis->hwndItem = dis16->hwndItem;
1083 dis->itemData = dis16->itemData;
1084 *plparam = (LPARAM)dis;
1087 case WM_MEASUREITEM:
1089 MEASUREITEMSTRUCT16* mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1090 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1091 HeapAlloc(GetProcessHeap(), 0,
1092 sizeof(*mis) + sizeof(LPARAM));
1093 if (!mis) return -1;
1094 mis->CtlType = mis16->CtlType;
1095 mis->CtlID = mis16->CtlID;
1096 mis->itemID = mis16->itemID;
1097 mis->itemWidth = mis16->itemWidth;
1098 mis->itemHeight = mis16->itemHeight;
1099 mis->itemData = mis16->itemData;
1100 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1101 *plparam = (LPARAM)mis;
1106 DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1107 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1109 if (!dis) return -1;
1110 dis->CtlType = dis16->CtlType;
1111 dis->CtlID = dis16->CtlID;
1112 dis->itemID = dis16->itemID;
1113 dis->itemAction = dis16->itemAction;
1114 dis->itemState = dis16->itemState;
1115 dis->hwndItem = dis16->hwndItem;
1116 dis->hDC = dis16->hDC;
1117 dis->itemData = dis16->itemData;
1118 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1119 *plparam = (LPARAM)dis;
1122 case WM_GETMINMAXINFO:
1124 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1125 sizeof(*mmi) + sizeof(LPARAM));
1126 if (!mmi) return -1;
1127 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16*)PTR_SEG_TO_LIN(*plparam),
1129 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1130 *plparam = (LPARAM)mmi;
1135 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1139 MDICREATESTRUCT16 *cs16 =
1140 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1141 MDICREATESTRUCTA *cs =
1142 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1143 sizeof(*cs) + sizeof(LPARAM) );
1145 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1146 cs->szTitle = (LPCSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1147 cs->szClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->szClass);
1148 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1149 *plparam = (LPARAM)cs;
1152 case WM_MDIGETACTIVE:
1153 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1154 *(BOOL*)(*plparam) = 0;
1158 *pmsg32=WM_MDIREFRESHMENU;
1159 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1160 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1163 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1164 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1167 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1169 HMENU hmenu=(HMENU)HIWORD(*plparam);
1170 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1171 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1172 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1174 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1175 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1177 case WM_MDIACTIVATE:
1180 *pwparam32 = (WPARAM)(HWND)HIWORD(*plparam);
1181 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1183 else /* message sent to MDI client */
1184 *pwparam32 = wParam16;
1188 NCCALCSIZE_PARAMS16 *nc16;
1189 NCCALCSIZE_PARAMS *nc;
1191 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1192 sizeof(*nc) + sizeof(LPARAM) );
1194 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(*plparam);
1195 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1198 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1199 sizeof(*nc->lppos) );
1200 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1201 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1202 if (nc->lppos) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos), nc->lppos );
1204 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1205 *plparam = (LPARAM)nc;
1211 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1212 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1213 sizeof(*cs) + sizeof(LPARAM) );
1215 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1216 cs->lpszName = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1217 cs->lpszClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1218 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1219 *plparam = (LPARAM)cs;
1222 case WM_PARENTNOTIFY:
1223 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1225 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1226 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1229 case WM_WINDOWPOSCHANGING:
1230 case WM_WINDOWPOSCHANGED:
1232 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1233 sizeof(*wp) + sizeof(LPARAM) );
1235 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(*plparam),
1237 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1238 *plparam = (LPARAM)wp;
1244 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
1245 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1247 if (!msg32) return -1;
1248 msg32->hwnd = msg16->hwnd;
1249 msg32->lParam = msg16->lParam;
1250 msg32->time = msg16->time;
1251 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1252 /* this is right, right? */
1253 if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
1254 &msg32->message,&msg32->wParam,
1255 &msg32->lParam)<0) {
1256 HeapFree( GetProcessHeap(), 0, msg32 );
1259 *plparam = (LPARAM)msg32;
1264 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1266 case WM_ACTIVATEAPP:
1268 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1269 a 32bit window. Might be superflous with 32bit interprocess
1272 HTASK16 htask = (HTASK16) *plparam;
1273 DWORD idThread = (DWORD)((TDB*)GlobalLock16(htask))->teb->tid;
1274 *plparam = (LPARAM) idThread;
1277 case WM_ASKCBFORMATNAME:
1278 case WM_DEVMODECHANGE:
1279 case WM_PAINTCLIPBOARD:
1280 case WM_SIZECLIPBOARD:
1281 case WM_WININICHANGE:
1282 FIXME_(msg)("message %04x needs translation\n",msg16 );
1285 default: /* No translation needed */
1291 /**********************************************************************
1292 * WINPROC_UnmapMsg16To32A
1294 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1296 LRESULT WINPROC_UnmapMsg16To32A( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1301 case WM_COMPAREITEM:
1304 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1306 case WM_MEASUREITEM:
1308 MEASUREITEMSTRUCT16 *mis16;
1309 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1310 lParam = *(LPARAM *)(mis + 1);
1311 mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1312 mis16->itemWidth = (UINT16)mis->itemWidth;
1313 mis16->itemHeight = (UINT16)mis->itemHeight;
1314 HeapFree( GetProcessHeap(), 0, mis );
1317 case WM_GETMINMAXINFO:
1319 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1320 lParam = *(LPARAM *)(mmi + 1);
1321 STRUCT32_MINMAXINFO32to16( mmi,
1322 (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
1323 HeapFree( GetProcessHeap(), 0, mmi );
1328 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1329 lParam = *(LPARAM *)(cs + 1);
1330 STRUCT32_MDICREATESTRUCT32Ato16( cs,
1331 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1332 HeapFree( GetProcessHeap(), 0, cs );
1335 case WM_MDIGETACTIVE:
1336 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1337 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1341 NCCALCSIZE_PARAMS16 *nc16;
1342 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1343 lParam = *(LPARAM *)(nc + 1);
1344 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
1345 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1348 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1349 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1352 STRUCT32_WINDOWPOS32to16( nc->lppos,
1353 (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos));
1354 HeapFree( GetProcessHeap(), 0, nc->lppos );
1357 HeapFree( GetProcessHeap(), 0, nc );
1363 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1364 lParam = *(LPARAM *)(cs + 1);
1365 STRUCT32_CREATESTRUCT32Ato16( cs,
1366 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1367 HeapFree( GetProcessHeap(), 0, cs );
1370 case WM_WINDOWPOSCHANGING:
1371 case WM_WINDOWPOSCHANGED:
1373 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1374 lParam = *(LPARAM *)(wp + 1);
1375 STRUCT32_WINDOWPOS32to16(wp,(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam));
1376 HeapFree( GetProcessHeap(), 0, wp );
1382 LPMSG msg32 = (LPMSG)lParam;
1384 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1386 HeapFree( GetProcessHeap(), 0, msg32 );
1394 /**********************************************************************
1395 * WINPROC_MapMsg16To32W
1397 * Map a message from 16- to 32-bit Unicode.
1398 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1400 INT WINPROC_MapMsg16To32W( HWND16 hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1401 WPARAM *pwparam32, LPARAM *plparam )
1407 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1408 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1412 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1413 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1414 sizeof(*cs) + sizeof(LPARAM) );
1416 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1417 cs->lpszName = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1418 cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1419 if (HIWORD(cs->lpszName))
1420 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
1421 (LPCSTR)cs->lpszName );
1422 if (HIWORD(cs->lpszClass))
1423 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1424 (LPCSTR)cs->lpszClass );
1425 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1426 *plparam = (LPARAM)cs;
1431 MDICREATESTRUCT16 *cs16 =
1432 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1433 MDICREATESTRUCTW *cs =
1434 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1435 sizeof(*cs) + sizeof(LPARAM) );
1437 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1438 cs->szTitle = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1439 cs->szClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szClass);
1440 if (HIWORD(cs->szTitle))
1441 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
1442 (LPCSTR)cs->szTitle );
1443 if (HIWORD(cs->szClass))
1444 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1445 (LPCSTR)cs->szClass );
1446 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1447 *plparam = (LPARAM)cs;
1453 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
1454 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1456 if (!msg32) return -1;
1457 msg32->hwnd = msg16->hwnd;
1458 msg32->lParam = msg16->lParam;
1459 msg32->time = msg16->time;
1460 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1461 /* this is right, right? */
1462 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1463 &msg32->message,&msg32->wParam,
1464 &msg32->lParam)<0) {
1465 HeapFree( GetProcessHeap(), 0, msg32 );
1468 *plparam = (LPARAM)msg32;
1476 case WM_SYSDEADCHAR:
1480 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1485 default: /* No Unicode translation needed */
1486 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1487 pwparam32, plparam );
1492 /**********************************************************************
1493 * WINPROC_UnmapMsg16To32W
1495 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1497 LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1504 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
1509 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1510 lParam = *(LPARAM *)(cs + 1);
1511 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs,
1512 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1513 if (HIWORD(cs->lpszName))
1514 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1515 if (HIWORD(cs->lpszClass))
1516 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1517 HeapFree( GetProcessHeap(), 0, cs );
1522 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1523 lParam = *(LPARAM *)(cs + 1);
1524 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs,
1525 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1526 if (HIWORD(cs->szTitle))
1527 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1528 if (HIWORD(cs->szClass))
1529 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1530 HeapFree( GetProcessHeap(), 0, cs );
1536 LPMSG msg32 = (LPMSG)lParam;
1538 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1540 HeapFree( GetProcessHeap(), 0, msg32 );
1544 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1550 /**********************************************************************
1551 * WINPROC_MapMsg32ATo16
1553 * Map a message from 32-bit Ansi to 16-bit.
1554 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1556 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1557 UINT16 *pmsg16, WPARAM16 *pwparam16,
1560 *pmsg16 = (UINT16)msg32;
1561 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1569 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1578 case EM_SCROLLCARET:
1581 case EM_GETLINECOUNT:
1593 case EM_LINEFROMCHAR:
1594 case EM_SETTABSTOPS:
1595 case EM_SETPASSWORDCHAR:
1596 case EM_EMPTYUNDOBUFFER:
1597 case EM_GETFIRSTVISIBLELINE:
1598 case EM_SETREADONLY:
1599 case EM_SETWORDBREAKPROC:
1600 case EM_GETWORDBREAKPROC:
1601 case EM_GETPASSWORDCHAR:
1602 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1607 case LB_DELETESTRING:
1608 case LB_GETANCHORINDEX:
1609 case LB_GETCARETINDEX:
1612 case LB_GETHORIZONTALEXTENT:
1613 case LB_GETITEMDATA:
1614 case LB_GETITEMHEIGHT:
1616 case LB_GETSELCOUNT:
1618 case LB_GETTOPINDEX:
1619 case LB_RESETCONTENT:
1620 case LB_SELITEMRANGE:
1621 case LB_SELITEMRANGEEX:
1622 case LB_SETANCHORINDEX:
1623 case LB_SETCARETINDEX:
1624 case LB_SETCOLUMNWIDTH:
1626 case LB_SETHORIZONTALEXTENT:
1627 case LB_SETITEMDATA:
1628 case LB_SETITEMHEIGHT:
1630 case LB_SETTOPINDEX:
1631 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1633 case CB_DELETESTRING:
1635 case CB_GETLBTEXTLEN:
1637 case CB_RESETCONTENT:
1641 case CB_SHOWDROPDOWN:
1642 case CB_SETITEMDATA:
1643 case CB_SETITEMHEIGHT:
1644 case CB_GETITEMHEIGHT:
1645 case CB_SETEXTENDEDUI:
1646 case CB_GETEXTENDEDUI:
1647 case CB_GETDROPPEDSTATE:
1648 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1651 *pmsg16 = CB_GETEDITSEL16;
1656 case LB_FINDSTRINGEXACT:
1657 case LB_INSERTSTRING:
1658 case LB_SELECTSTRING:
1662 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1663 if (!str) return -1;
1664 *plparam = (LPARAM)SEGPTR_GET(str);
1666 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1671 case CB_FINDSTRINGEXACT:
1672 case CB_INSERTSTRING:
1673 case CB_SELECTSTRING:
1676 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1677 if (!str) return -1;
1678 *plparam = (LPARAM)SEGPTR_GET(str);
1680 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1683 case LB_GETITEMRECT:
1686 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1687 if (!rect) return -1;
1688 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1689 *plparam = (LPARAM)SEGPTR_GET(rect);
1691 *pmsg16 = LB_GETITEMRECT16;
1693 case LB_GETSELITEMS:
1696 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1697 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1698 + sizeof(LPARAM)))) return -1;
1699 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1700 *plparam = (LPARAM)SEGPTR_GET(items);
1702 *pmsg16 = LB_GETSELITEMS16;
1704 case LB_SETTABSTOPS:
1709 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1710 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1711 + sizeof(LPARAM)))) return -1;
1712 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1713 *plparam = (LPARAM)SEGPTR_GET(stops);
1716 *pmsg16 = LB_SETTABSTOPS16;
1719 case CB_GETDROPPEDCONTROLRECT:
1722 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1723 if (!rect) return -1;
1724 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1725 *plparam = (LPARAM)SEGPTR_GET(rect);
1727 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1731 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1732 *pmsg16 = LB_GETTEXT16;
1736 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1737 *pmsg16 = CB_GETLBTEXT16;
1742 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1743 *pmsg16 = EM_SETSEL16;
1750 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1754 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1756 case WM_CTLCOLORMSGBOX:
1757 case WM_CTLCOLOREDIT:
1758 case WM_CTLCOLORLISTBOX:
1759 case WM_CTLCOLORBTN:
1760 case WM_CTLCOLORDLG:
1761 case WM_CTLCOLORSCROLLBAR:
1762 case WM_CTLCOLORSTATIC:
1763 *pmsg16 = WM_CTLCOLOR;
1764 *plparam = MAKELPARAM( (HWND16)*plparam,
1765 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1767 case WM_COMPAREITEM:
1769 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1770 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1771 if (!cis) return -1;
1772 cis->CtlType = (UINT16)cis32->CtlType;
1773 cis->CtlID = (UINT16)cis32->CtlID;
1774 cis->hwndItem = (HWND16)cis32->hwndItem;
1775 cis->itemID1 = (UINT16)cis32->itemID1;
1776 cis->itemData1 = cis32->itemData1;
1777 cis->itemID2 = (UINT16)cis32->itemID2;
1778 cis->itemData2 = cis32->itemData2;
1779 *plparam = (LPARAM)SEGPTR_GET(cis);
1784 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1785 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1786 if (!dis) return -1;
1787 dis->CtlType = (UINT16)dis32->CtlType;
1788 dis->CtlID = (UINT16)dis32->CtlID;
1789 dis->itemID = (UINT16)dis32->itemID;
1790 dis->hwndItem = (HWND16)dis32->hwndItem;
1791 dis->itemData = dis32->itemData;
1792 *plparam = (LPARAM)SEGPTR_GET(dis);
1797 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1798 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1799 if (!dis) return -1;
1800 dis->CtlType = (UINT16)dis32->CtlType;
1801 dis->CtlID = (UINT16)dis32->CtlID;
1802 dis->itemID = (UINT16)dis32->itemID;
1803 dis->itemAction = (UINT16)dis32->itemAction;
1804 dis->itemState = (UINT16)dis32->itemState;
1805 dis->hwndItem = (HWND16)dis32->hwndItem;
1806 dis->hDC = (HDC16)dis32->hDC;
1807 dis->itemData = dis32->itemData;
1808 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1809 *plparam = (LPARAM)SEGPTR_GET(dis);
1812 case WM_MEASUREITEM:
1814 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1815 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1816 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1817 if (!mis) return -1;
1818 mis->CtlType = (UINT16)mis32->CtlType;
1819 mis->CtlID = (UINT16)mis32->CtlID;
1820 mis->itemID = (UINT16)mis32->itemID;
1821 mis->itemWidth = (UINT16)mis32->itemWidth;
1822 mis->itemHeight = (UINT16)mis32->itemHeight;
1823 mis->itemData = mis32->itemData;
1824 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1825 *plparam = (LPARAM)SEGPTR_GET(mis);
1828 case WM_GETMINMAXINFO:
1830 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1832 if (!mmi) return -1;
1833 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1834 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1835 *plparam = (LPARAM)SEGPTR_GET(mmi);
1841 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1842 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1843 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1844 *plparam = (LPARAM)SEGPTR_GET(str);
1849 MDICREATESTRUCT16 *cs;
1850 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1853 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1854 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1855 name = SEGPTR_STRDUP( cs32->szTitle );
1856 cls = SEGPTR_STRDUP( cs32->szClass );
1857 cs->szTitle = SEGPTR_GET(name);
1858 cs->szClass = SEGPTR_GET(cls);
1859 *plparam = (LPARAM)SEGPTR_GET(cs);
1862 case WM_MDIGETACTIVE:
1865 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1866 (HMENU16)LOWORD(*plparam) );
1867 *pwparam16 = (*plparam == 0);
1870 if(HIWORD(wParam32) & MF_POPUP)
1873 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1875 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1881 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1883 case WM_MDIACTIVATE:
1885 WND *tempWnd = WIN_FindWndPtr(hwnd);
1886 if( WIDGETS_IsControl(tempWnd, BIC32_MDICLIENT) )
1888 *pwparam16 = (HWND)wParam32;
1893 *pwparam16 = ((HWND)*plparam == hwnd);
1894 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1895 (HWND16)LOWORD(wParam32) );
1897 WIN_ReleaseWndPtr(tempWnd);
1902 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1903 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1906 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1910 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1911 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1912 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1917 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1918 nc->lppos = SEGPTR_GET(wp);
1920 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1921 *plparam = (LPARAM)SEGPTR_GET(nc);
1928 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1931 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1932 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1933 name = SEGPTR_STRDUP( cs32->lpszName );
1934 cls = SEGPTR_STRDUP( cs32->lpszClass );
1935 cs->lpszName = SEGPTR_GET(name);
1936 cs->lpszClass = SEGPTR_GET(cls);
1937 *plparam = (LPARAM)SEGPTR_GET(cs);
1940 case WM_PARENTNOTIFY:
1941 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1942 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1943 /* else nothing to do */
1946 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1950 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1951 if (!str) return -1;
1952 *plparam = (LPARAM)SEGPTR_GET(str);
1955 case WM_WINDOWPOSCHANGING:
1956 case WM_WINDOWPOSCHANGED:
1958 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
1961 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
1962 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1963 *plparam = (LPARAM)SEGPTR_GET(wp);
1968 LPMSG msg32 = (LPMSG) *plparam;
1969 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
1971 if (!msg16) return -1;
1972 msg16->hwnd = msg32->hwnd;
1973 msg16->lParam = msg32->lParam;
1974 msg16->time = msg32->time;
1975 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
1976 /* this is right, right? */
1977 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
1978 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
1979 SEGPTR_FREE( msg16 );
1982 *plparam = (LPARAM)SEGPTR_GET(msg16);
1987 case WM_ACTIVATEAPP:
1989 *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
1992 case WM_ASKCBFORMATNAME:
1993 case WM_DEVMODECHANGE:
1994 case WM_PAINTCLIPBOARD:
1995 case WM_SIZECLIPBOARD:
1996 case WM_WININICHANGE:
1997 FIXME_(msg)("message %04x needs translation\n", msg32 );
1999 case WM_SIZING: /* should not be send to 16-bit apps */
2001 default: /* No translation needed */
2007 /**********************************************************************
2008 * WINPROC_UnmapMsg32ATo16
2010 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2012 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2021 case LB_FINDSTRINGEXACT:
2022 case LB_INSERTSTRING:
2023 case LB_SELECTSTRING:
2024 case LB_SETTABSTOPS:
2027 case CB_FINDSTRINGEXACT:
2028 case CB_INSERTSTRING:
2029 case CB_SELECTSTRING:
2031 case WM_COMPAREITEM:
2035 SEGPTR_FREE( PTR_SEG_TO_LIN(p16->lParam) );
2038 case CB_GETDROPPEDCONTROLRECT:
2039 case LB_GETITEMRECT:
2041 RECT16 *rect = (RECT16 *)PTR_SEG_TO_LIN(p16->lParam);
2042 p16->lParam = *(LPARAM *)(rect + 1);
2043 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2044 SEGPTR_FREE( rect );
2047 case LB_GETSELITEMS:
2050 LPINT16 items = (LPINT16)PTR_SEG_TO_LIN(lParam);
2051 p16->lParam = *((LPARAM *)items - 1);
2052 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2053 SEGPTR_FREE( (LPARAM *)items - 1 );
2059 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2061 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2066 UnMapLS( (SEGPTR)(p16->lParam) );
2069 case WM_MEASUREITEM:
2071 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2072 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2073 mis32->itemWidth = mis->itemWidth;
2074 mis32->itemHeight = mis->itemHeight;
2078 case WM_GETMINMAXINFO:
2080 MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(p16->lParam);
2081 p16->lParam = *(LPARAM *)(mmi + 1);
2082 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2088 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2089 p16->lParam = *((LPARAM *)str - 1);
2090 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2091 SEGPTR_FREE( (LPARAM *)str - 1 );
2096 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16*)PTR_SEG_TO_LIN(p16->lParam);
2097 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szTitle) );
2098 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szClass) );
2102 case WM_MDIGETACTIVE:
2103 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2104 p16->lResult = (HWND)LOWORD(p16->lResult);
2108 NCCALCSIZE_PARAMS *nc32;
2109 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(p16->lParam);
2110 p16->lParam = *(LPARAM *)(nc + 1);
2111 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2112 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2115 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2116 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2117 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
2119 SEGPTR_FREE( PTR_SEG_TO_LIN(nc->lppos) );
2127 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2128 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszName) );
2129 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszClass) );
2133 case WM_WINDOWPOSCHANGING:
2134 case WM_WINDOWPOSCHANGED:
2136 WINDOWPOS16 *wp = (WINDOWPOS16 *)PTR_SEG_TO_LIN(p16->lParam);
2137 p16->lParam = *(LPARAM *)(wp + 1);
2138 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2143 UnMapLS(p16->lParam);
2148 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(p16->lParam);
2150 msgp16.wParam=msg16->wParam;
2151 msgp16.lParam=msg16->lParam;
2152 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2153 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2162 /**********************************************************************
2163 * WINPROC_MapMsg32WTo16
2165 * Map a message from 32-bit Unicode to 16-bit.
2166 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2168 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2169 UINT16 *pmsg16, WPARAM16 *pwparam16,
2176 case LB_FINDSTRINGEXACT:
2177 case LB_INSERTSTRING:
2178 case LB_SELECTSTRING:
2182 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2183 if (!str) return -1;
2184 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2185 *plparam = (LPARAM)SEGPTR_GET(str);
2187 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2192 case CB_FINDSTRINGEXACT:
2193 case CB_INSERTSTRING:
2194 case CB_SELECTSTRING:
2197 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2198 if (!str) return -1;
2199 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2200 *plparam = (LPARAM)SEGPTR_GET(str);
2202 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2209 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2212 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
2213 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2214 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2215 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2216 cs->lpszName = SEGPTR_GET(name);
2217 cs->lpszClass = SEGPTR_GET(cls);
2218 *pmsg16 = (UINT16)msg32;
2219 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2220 *plparam = (LPARAM)SEGPTR_GET(cs);
2225 MDICREATESTRUCT16 *cs;
2226 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2229 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
2230 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2231 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2232 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2233 cs->szTitle = SEGPTR_GET(name);
2234 cs->szClass = SEGPTR_GET(cls);
2235 *pmsg16 = (UINT16)msg32;
2236 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2237 *plparam = (LPARAM)SEGPTR_GET(cs);
2242 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2243 if (!str) return -1;
2244 *pmsg16 = (UINT16)msg32;
2245 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2246 *plparam = (LPARAM)SEGPTR_GET(str);
2251 if ( WINPROC_TestLBForStr( hwnd ))
2253 LPSTR str = (LPSTR) SEGPTR_ALLOC( 256 ); /* fixme: fixed sized buffer */
2254 if (!str) return -1;
2255 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2256 *pwparam16 = (WPARAM16)LOWORD(wParam32);
2257 *plparam = (LPARAM)SEGPTR_GET(str);
2264 case WM_SYSDEADCHAR:
2266 WCHAR wch = wParam32;
2268 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2273 default: /* No Unicode translation needed (?) */
2274 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2275 pwparam16, plparam );
2280 /**********************************************************************
2281 * WINPROC_UnmapMsg32WTo16
2283 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2285 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2292 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2293 p16->lParam = *((LPARAM *)str - 1);
2294 lstrcpyAtoW( (LPWSTR)(p16->lParam), str );
2295 SEGPTR_FREE( (LPARAM *)str - 1 );
2300 if ( WINPROC_TestLBForStr( hwnd ))
2302 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2303 lstrcpyAtoW( (LPWSTR)lParam, str );
2304 SEGPTR_FREE( (LPARAM *) str );
2308 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2314 /**********************************************************************
2315 * WINPROC_CallProc32ATo32W
2317 * Call a window procedure, translating args from Ansi to Unicode.
2319 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2320 UINT msg, WPARAM wParam,
2325 if (WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2326 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2327 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
2332 /**********************************************************************
2333 * WINPROC_CallProc32WTo32A
2335 * Call a window procedure, translating args from Unicode to Ansi.
2337 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2338 UINT msg, WPARAM wParam,
2343 if (WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2344 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2345 WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2350 /**********************************************************************
2351 * WINPROC_CallProc16To32A
2353 * Call a 32-bit window procedure, translating the 16-bit args.
2355 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd,
2356 UINT16 msg, WPARAM16 wParam,
2363 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2365 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2366 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
2369 /**********************************************************************
2370 * WINPROC_Thunk16To32A
2372 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args )
2374 HWND16 hwnd = *(HWND16 *)( args+8 );
2375 UINT16 msg = *(HWND16 *)( args+6 );
2376 WPARAM16 wParam = *(HWND16 *)( args+4 );
2377 LPARAM lParam = *(LPARAM *)( args+0 );
2379 return WINPROC_CallProc16To32A( func, hwnd, msg, wParam, lParam );
2383 /**********************************************************************
2384 * WINPROC_CallProc16To32W
2386 * Call a 32-bit window procedure, translating the 16-bit args.
2388 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd,
2389 UINT16 msg, WPARAM16 wParam,
2396 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2399 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2401 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
2404 /**********************************************************************
2405 * WINPROC_Thunk16To32W
2407 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args )
2409 HWND16 hwnd = *(HWND16 *)( args+8 );
2410 UINT16 msg = *(HWND16 *)( args+6 );
2411 WPARAM16 wParam = *(HWND16 *)( args+4 );
2412 LPARAM lParam = *(LPARAM *)( args+0 );
2414 return WINPROC_CallProc16To32W( func, hwnd, msg, wParam, lParam );
2417 /**********************************************************************
2418 * WINPROC_CallProc32ATo16
2420 * Call a 16-bit window procedure, translating the 32-bit args.
2422 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2423 UINT msg, WPARAM wParam,
2429 mp16.lParam = lParam;
2430 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2431 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2433 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2434 mp16.wParam, mp16.lParam );
2435 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2436 return mp16.lResult;
2440 /**********************************************************************
2441 * WINPROC_CallProc32WTo16
2443 * Call a 16-bit window procedure, translating the 32-bit args.
2445 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2446 UINT msg, WPARAM wParam,
2452 mp16.lParam = lParam;
2453 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2454 &mp16.lParam ) == -1)
2456 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2457 mp16.wParam, mp16.lParam );
2458 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2459 return mp16.lResult;
2463 /**********************************************************************
2464 * CallWindowProc16 (USER.122)
2466 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2467 WPARAM16 wParam, LPARAM lParam )
2469 WINDOWPROC *proc = WINPROC_GetPtr( func );
2472 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2475 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2476 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2482 if (!proc->thunk.t_from32.proc) return 0;
2483 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2484 hwnd, msg, wParam, lParam );
2486 if (!proc->thunk.t_from16.proc) return 0;
2487 return WINPROC_CallProc16To32A( proc->thunk.t_from16.proc,
2488 hwnd, msg, wParam, lParam );
2490 if (!proc->thunk.t_from16.proc) return 0;
2491 return WINPROC_CallProc16To32W( proc->thunk.t_from16.proc,
2492 hwnd, msg, wParam, lParam );
2494 WARN_(relay)("Invalid proc %p\n", proc );
2500 /**********************************************************************
2501 * CallWindowProcA (USER32.18)
2503 * The CallWindowProc() function invokes the windows procedure _func_,
2504 * with _hwnd_ as the target window, the message specified by _msg_, and
2505 * the message parameters _wParam_ and _lParam_.
2507 * Some kinds of argument conversion may be done, I'm not sure what.
2509 * CallWindowProc() may be used for windows subclassing. Use
2510 * SetWindowLong() to set a new windows procedure for windows of the
2511 * subclass, and handle subclassed messages in the new windows
2512 * procedure. The new windows procedure may then use CallWindowProc()
2513 * with _func_ set to the parent class's windows procedure to dispatch
2514 * the message to the superclass.
2518 * The return value is message dependent.
2524 LRESULT WINAPI CallWindowProcA(
2525 WNDPROC func, /* window procedure */
2526 HWND hwnd, /* target window */
2527 UINT msg, /* message */
2528 WPARAM wParam, /* message dependent parameter */
2529 LPARAM lParam /* message dependent parameter */
2531 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2533 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2536 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2537 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2543 if (!proc->thunk.t_from32.proc) return 0;
2544 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2545 hwnd, msg, wParam, lParam );
2547 if (!proc->thunk.t_from16.proc) return 0;
2548 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2549 hwnd, msg, wParam, lParam );
2551 if (!proc->thunk.t_from16.proc) return 0;
2552 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2553 hwnd, msg, wParam, lParam );
2555 WARN_(relay)("Invalid proc %p\n", proc );
2561 /**********************************************************************
2562 * CallWindowProcW (USER32.19)
2564 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2565 WPARAM wParam, LPARAM lParam )
2567 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2569 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2572 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2573 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2579 if (!proc->thunk.t_from32.proc) return 0;
2580 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2581 hwnd, msg, wParam, lParam );
2583 if (!proc->thunk.t_from16.proc) return 0;
2584 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2585 hwnd, msg, wParam, lParam );
2587 if (!proc->thunk.t_from16.proc) return 0;
2588 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2589 hwnd, msg, wParam, lParam );
2591 WARN_(relay)("Invalid proc %p\n", proc );