Added the DFCS_{HOT,TRANSPARENT} definitions.
[wine/gsoc_dplay.git] / windows / winproc.c
blob1d5b580a3ca8aa2270c809aa909e9dd2766c47d7
1 /*
2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "config.h"
24 #include <string.h>
26 #include "windef.h"
27 #include "winbase.h"
28 #include "wingdi.h"
29 #include "wine/winbase16.h"
30 #include "wine/winuser16.h"
31 #include "stackframe.h"
32 #include "selectors.h"
33 #include "controls.h"
34 #include "heap.h"
35 #include "struct32.h"
36 #include "win.h"
37 #include "winproc.h"
38 #include "wine/debug.h"
39 #include "spy.h"
40 #include "task.h"
41 #include "thread.h"
43 WINE_DECLARE_DEBUG_CHANNEL(msg);
44 WINE_DECLARE_DEBUG_CHANNEL(relay);
45 WINE_DECLARE_DEBUG_CHANNEL(win);
47 #include "pshpack1.h"
49 /* Window procedure 16-to-32-bit thunk */
50 typedef struct
52 BYTE popl_eax; /* popl %eax (return address) */
53 BYTE pushl_func; /* pushl $proc */
54 WNDPROC proc;
55 BYTE pushl_eax; /* pushl %eax */
56 BYTE ljmp; /* ljmp relay*/
57 DWORD relay_offset; /* __wine_call_wndproc_32A/W */
58 WORD relay_sel;
59 } WINPROC_THUNK_FROM16;
61 /* Window procedure 32-to-16-bit thunk */
62 typedef struct
64 BYTE popl_eax; /* popl %eax (return address) */
65 BYTE pushl_func; /* pushl $proc */
66 WNDPROC16 proc;
67 BYTE pushl_eax; /* pushl %eax */
68 BYTE jmp; /* jmp relay (relative jump)*/
69 void (*relay)(); /* WINPROC_CallProc32ATo16() */
70 } WINPROC_THUNK_FROM32;
72 /* Simple jmp to call 32-bit procedure directly */
73 typedef struct
75 BYTE jmp; /* jmp proc (relative jump) */
76 WNDPROC proc;
77 } WINPROC_JUMP;
78 #include "poppack.h"
80 typedef union
82 WINPROC_THUNK_FROM16 t_from16;
83 WINPROC_THUNK_FROM32 t_from32;
84 } WINPROC_THUNK;
86 typedef struct tagWINDOWPROC
88 WINPROC_THUNK thunk; /* Thunk */
89 WINPROC_JUMP jmp; /* Jump */
90 struct tagWINDOWPROC *next; /* Next window proc */
91 UINT magic; /* Magic number */
92 WINDOWPROCTYPE type; /* Function type */
93 WINDOWPROCUSER user; /* Function user */
94 } WINDOWPROC;
96 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
98 #define WINPROC_THUNKPROC(pproc) \
99 (((pproc)->type == WIN_PROC_16) ? \
100 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
101 (WNDPROC16)((pproc)->thunk.t_from16.proc))
103 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
104 UINT msg, WPARAM wParam,
105 LPARAM lParam );
106 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
107 UINT msg, WPARAM wParam,
108 LPARAM lParam );
110 static HANDLE WinProcHeap;
111 static WORD WinProcSel;
114 /**********************************************************************
115 * WINPROC_Init
117 BOOL WINPROC_Init(void)
119 WinProcHeap = HeapCreate( 0, 0x10000, 0x10000 );
120 WinProcSel = SELECTOR_AllocBlock( (void *)WinProcHeap, 0x10000,
121 WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
122 if (!WinProcHeap || !WinProcSel)
124 WARN_(relay)("Unable to create winproc heap\n" );
125 return FALSE;
127 return TRUE;
131 #ifdef __i386__
132 /* Some window procedures modify register they shouldn't, or are not
133 * properly declared stdcall; so we need a small assembly wrapper to
134 * call them. */
135 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
136 WPARAM wParam, LPARAM lParam );
137 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
138 "pushl %ebp\n\t"
139 "movl %esp,%ebp\n\t"
140 "pushl %edi\n\t"
141 "pushl %esi\n\t"
142 "pushl %ebx\n\t"
143 "pushl 24(%ebp)\n\t"
144 "pushl 20(%ebp)\n\t"
145 "pushl 16(%ebp)\n\t"
146 "pushl 12(%ebp)\n\t"
147 "movl 8(%ebp),%eax\n\t"
148 "call *%eax\n\t"
149 "leal -12(%ebp),%esp\n\t"
150 "popl %ebx\n\t"
151 "popl %esi\n\t"
152 "popl %edi\n\t"
153 "leave\n\t"
154 "ret" );
155 #else
156 static inline LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
157 WPARAM wParam, LPARAM lParam )
159 return proc( hwnd, msg, wParam, lParam );
161 #endif /* __i386__ */
163 /**********************************************************************
164 * WINPROC_CallWndProc32
166 * Call a 32-bit WndProc.
168 static LRESULT WINPROC_CallWndProc( WNDPROC proc, HWND hwnd, UINT msg,
169 WPARAM wParam, LPARAM lParam )
171 LRESULT retvalue;
172 int iWndsLocks;
174 hwnd = WIN_GetFullHandle( hwnd );
175 if (TRACE_ON(relay))
176 DPRINTF( "%08lx:Call window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
177 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam );
178 /* To avoid any deadlocks, all the locks on the windows structures
179 must be suspended before the control is passed to the application */
180 iWndsLocks = WIN_SuspendWndsLock();
181 retvalue = WINPROC_wrapper( proc, hwnd, msg, wParam, lParam );
182 WIN_RestoreWndsLock(iWndsLocks);
184 if (TRACE_ON(relay))
185 DPRINTF( "%08lx:Ret window proc %p (hwnd=%08x,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
186 GetCurrentThreadId(), proc, hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam, retvalue );
187 return retvalue;
190 /***********************************************************************
191 * WINPROC_CallWndProc16
193 * Call a 16-bit window procedure
195 static LRESULT WINAPI WINPROC_CallWndProc16( WNDPROC16 proc, HWND16 hwnd,
196 UINT16 msg, WPARAM16 wParam,
197 LPARAM lParam )
199 CONTEXT86 context;
200 LRESULT ret;
201 WORD *args;
202 DWORD offset = 0;
203 TEB *teb = NtCurrentTeb();
204 int iWndsLocks;
206 /* Window procedures want ax = hInstance, ds = es = ss */
208 memset(&context, '\0', sizeof(context));
209 context.SegDs = context.SegEs = SELECTOROF(teb->cur_stack);
210 if (!(context.Eax = GetWindowWord16( hwnd, GWL_HINSTANCE ))) context.Eax = context.SegDs;
211 context.SegCs = SELECTOROF(proc);
212 context.Eip = OFFSETOF(proc);
213 context.Ebp = OFFSETOF(teb->cur_stack)
214 + (WORD)&((STACK16FRAME*)0)->bp;
216 if (lParam)
218 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
219 work if structures passed in lParam are placed in the stack/data
220 segment. Programmers easily make the mistake of converting lParam
221 to a near rather than a far pointer, since Windows apparently
222 allows this. We copy the structures to the 16 bit stack; this is
223 ugly but makes these programs work. */
224 switch (msg)
226 case WM_CREATE:
227 case WM_NCCREATE:
228 offset = sizeof(CREATESTRUCT16); break;
229 case WM_DRAWITEM:
230 offset = sizeof(DRAWITEMSTRUCT16); break;
231 case WM_COMPAREITEM:
232 offset = sizeof(COMPAREITEMSTRUCT16); break;
234 if (offset)
236 void *s = MapSL(lParam);
237 lParam = stack16_push( offset );
238 memcpy( MapSL(lParam), s, offset );
242 iWndsLocks = WIN_SuspendWndsLock();
244 args = (WORD *)THREAD_STACK16(teb) - 5;
245 args[0] = LOWORD(lParam);
246 args[1] = HIWORD(lParam);
247 args[2] = wParam;
248 args[3] = msg;
249 args[4] = hwnd;
251 wine_call_to_16_regs_short( &context, 5 * sizeof(WORD) );
252 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
253 if (offset) stack16_pop( offset );
255 WIN_RestoreWndsLock(iWndsLocks);
257 return ret;
261 /**********************************************************************
262 * WINPROC_GetPtr
264 * Return a pointer to the win proc.
266 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
268 BYTE *ptr;
269 WINDOWPROC *proc;
271 /* ptr cannot be < 64K */
272 if (!HIWORD(handle)) return NULL;
274 /* Check for a linear pointer */
276 ptr = (BYTE *)handle;
277 /* First check if it is the jmp address */
278 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->jmp);
279 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
280 return proc;
281 /* Now it must be the thunk address */
282 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
283 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
284 return proc;
286 /* Check for a segmented pointer */
288 if (!IsBadReadPtr16( (SEGPTR)handle, sizeof(proc->thunk) ))
290 ptr = MapSL( (SEGPTR)handle );
291 /* It must be the thunk address */
292 proc = (WINDOWPROC *)(ptr - (int)&((WINDOWPROC *)0)->thunk);
293 if (HeapValidate( WinProcHeap, 0, proc ) && (proc->magic == WINPROC_MAGIC))
294 return proc;
297 return NULL;
301 /**********************************************************************
302 * WINPROC_AllocWinProc
304 * Allocate a new window procedure.
306 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type,
307 WINDOWPROCUSER user )
309 static FARPROC16 relay_32A, relay_32W;
311 WINDOWPROC *proc, *oldproc;
313 /* Allocate a window procedure */
315 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
317 /* Check if the function is already a win proc */
319 if ((oldproc = WINPROC_GetPtr( func )))
321 *proc = *oldproc;
323 else
325 switch(type)
327 case WIN_PROC_16:
328 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
329 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
330 proc->thunk.t_from32.proc = func;
331 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
332 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
333 proc->thunk.t_from32.relay = /* relative jump */
334 (void(*)())((DWORD)WINPROC_CallProc32ATo16 -
335 (DWORD)(&proc->thunk.t_from32.relay + 1));
336 break;
337 case WIN_PROC_32A:
338 if (!relay_32A) relay_32A = GetProcAddress16( GetModuleHandle16("user"),
339 "__wine_call_wndproc_32A" );
340 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
341 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
342 proc->thunk.t_from16.proc = (WNDPROC)func;
343 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
344 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
345 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32A);
346 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32A);
347 proc->jmp.jmp = 0xe9;
348 /* Fixup relative jump */
349 proc->jmp.proc = (WNDPROC)((DWORD)func - (DWORD)(&proc->jmp.proc + 1));
350 break;
351 case WIN_PROC_32W:
352 if (!relay_32W) relay_32W = GetProcAddress16( GetModuleHandle16("user"),
353 "__wine_call_wndproc_32W" );
354 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
355 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
356 proc->thunk.t_from16.proc = (WNDPROC)func;
357 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
358 proc->thunk.t_from16.ljmp = 0xea; /* ljmp relay*/
359 proc->thunk.t_from16.relay_offset = OFFSETOF(relay_32W);
360 proc->thunk.t_from16.relay_sel = SELECTOROF(relay_32W);
361 proc->jmp.jmp = 0xe9;
362 /* Fixup relative jump */
363 proc->jmp.proc = (WNDPROC)((DWORD)func - (DWORD)(&proc->jmp.proc + 1));
364 break;
365 default:
366 /* Should not happen */
367 break;
369 proc->magic = WINPROC_MAGIC;
370 proc->type = type;
371 proc->user = user;
373 proc->next = NULL;
374 TRACE_(win)("(%08x,%d): returning %08x\n",
375 (UINT)func, type, (UINT)proc );
376 return proc;
380 /**********************************************************************
381 * WINPROC_GetProc
383 * Get a window procedure pointer that can be passed to the Windows program.
385 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
387 WINDOWPROC *ptr = (WINDOWPROC *)proc;
389 if (!proc) return NULL;
390 if (type == WIN_PROC_16) /* We want a 16:16 address */
392 if (ptr->type == WIN_PROC_16)
393 return ptr->thunk.t_from32.proc;
394 else
395 return (WNDPROC16)MAKESEGPTR( WinProcSel, (char *)&ptr->thunk - (char *)WinProcHeap );
397 else /* We want a 32-bit address */
399 if (ptr->type == WIN_PROC_16)
400 return (WNDPROC16)&ptr->thunk;
401 else if (type != ptr->type)
402 /* Have to return the jmp address if types don't match */
403 return (WNDPROC16)&ptr->jmp;
404 else
405 /* Some Win16 programs want to get back the proc they set */
406 return (WNDPROC16)ptr->thunk.t_from16.proc;
411 /**********************************************************************
412 * WINPROC_SetProc
414 * Set the window procedure for a window or class. There are
415 * three tree classes of winproc callbacks:
417 * 1) class -> wp - not subclassed
418 * class -> wp -> wp -> wp -> wp - SetClassLong()
419 * / /
420 * 2) window -' / - not subclassed
421 * window -> wp -> wp ' - SetWindowLong()
423 * 3) timer -> wp - SetTimer()
425 * Initially, winproc of the window points to the current winproc
426 * thunk of its class. Subclassing prepends a new thunk to the
427 * window winproc chain at the head of the list. Thus, window thunk
428 * list includes class thunks and the latter are preserved when the
429 * window is destroyed.
432 BOOL WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
433 WINDOWPROCTYPE type, WINDOWPROCUSER user )
435 BOOL bRecycle = FALSE;
436 WINDOWPROC *proc, **ppPrev;
438 /* Check if function is already in the list */
440 ppPrev = (WINDOWPROC **)pFirst;
441 proc = WINPROC_GetPtr( func );
442 while (*ppPrev)
444 if (proc)
446 if (*ppPrev == proc)
448 if ((*ppPrev)->user != user)
450 /* terminal thunk is being restored */
452 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
453 *(WINDOWPROC **)pFirst = *ppPrev;
454 return TRUE;
456 bRecycle = TRUE;
457 break;
460 else
462 if (((*ppPrev)->type == type) &&
463 (func == WINPROC_THUNKPROC(*ppPrev)))
465 if((*ppPrev)->user == user)
467 bRecycle = TRUE;
469 else
471 WINPROC_FreeProc( *ppPrev, user );
472 *ppPrev = NULL;
474 break;
478 /* WPF_CLASS thunk terminates window thunk list */
479 if ((*ppPrev)->user != user) break;
480 ppPrev = &(*ppPrev)->next;
483 if (bRecycle)
485 /* Extract this thunk from the list */
486 proc = *ppPrev;
487 *ppPrev = proc->next;
489 else /* Allocate a new one */
491 if (proc) /* Was already a win proc */
493 type = proc->type;
494 func = WINPROC_THUNKPROC(proc);
496 proc = WINPROC_AllocWinProc( func, type, user );
497 if (!proc) return FALSE;
500 /* Add the win proc at the head of the list */
502 TRACE_(win)("(%08x,%08x,%d): res=%08x\n",
503 (UINT)*pFirst, (UINT)func, type, (UINT)proc );
504 proc->next = *(WINDOWPROC **)pFirst;
505 *(WINDOWPROC **)pFirst = proc;
506 return TRUE;
510 /**********************************************************************
511 * WINPROC_FreeProc
513 * Free a list of win procs.
515 void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
517 while (proc)
519 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
520 if (((WINDOWPROC *)proc)->user != user) break;
521 TRACE_(win)("freeing %08x\n", (UINT)proc);
522 HeapFree( WinProcHeap, 0, proc );
523 proc = next;
528 /**********************************************************************
529 * WINPROC_GetProcType
531 * Return the window procedure type.
533 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
535 if (!proc ||
536 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
537 return WIN_PROC_INVALID;
538 return ((WINDOWPROC *)proc)->type;
540 /**********************************************************************
541 * WINPROC_TestCBForStr
543 * Return TRUE if the lparam is a string
545 inline static BOOL WINPROC_TestCBForStr( HWND hwnd )
547 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
548 return (!(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)) || (style & CBS_HASSTRINGS));
550 /**********************************************************************
551 * WINPROC_TestLBForStr
553 * Return TRUE if the lparam is a string
555 inline static BOOL WINPROC_TestLBForStr( HWND hwnd )
557 DWORD style = GetWindowLongA( hwnd, GWL_STYLE );
558 return (!(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)) || (style & LBS_HASSTRINGS));
561 /**********************************************************************
562 * WINPROC_MapMsg32ATo32W
564 * Map a message from Ansi to Unicode.
565 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
567 * FIXME:
568 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
569 * the first four bytes are the handle of the icon
570 * when the WM_SETTEXT message has been used to set the icon
572 INT WINPROC_MapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
574 switch(msg)
576 case WM_GETTEXT:
577 case WM_ASKCBFORMATNAME:
579 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
580 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
581 if (!ptr) return -1;
582 *ptr++ = *plparam; /* Store previous lParam */
583 *plparam = (LPARAM)ptr;
585 return 1;
586 /* lparam is string (0-terminated) */
587 case WM_SETTEXT:
588 case WM_WININICHANGE:
589 case WM_DEVMODECHANGE:
590 case CB_DIR:
591 case LB_DIR:
592 case LB_ADDFILE:
593 case EM_REPLACESEL:
594 if(!*plparam) return 0;
595 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
596 return (*plparam ? 1 : -1);
597 case WM_GETTEXTLENGTH:
598 case CB_GETLBTEXTLEN:
599 case LB_GETTEXTLEN:
600 return 1; /* need to map result */
601 case WM_NCCREATE:
602 case WM_CREATE:
604 struct s
605 { CREATESTRUCTW cs; /* new structure */
606 LPCWSTR lpszName; /* allocated Name */
607 LPCWSTR lpszClass; /* allocated Class */
610 struct s *xs = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(struct s));
611 if (!xs) return -1;
612 xs->cs = *(CREATESTRUCTW *)*plparam;
613 if (HIWORD(xs->cs.lpszName))
614 xs->lpszName = xs->cs.lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
615 (LPCSTR)xs->cs.lpszName );
616 if (HIWORD(xs->cs.lpszClass))
617 xs->lpszClass = xs->cs.lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
618 (LPCSTR)xs->cs.lpszClass );
619 *plparam = (LPARAM)xs;
621 return 1;
622 case WM_MDICREATE:
624 MDICREATESTRUCTW *cs =
625 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
626 if (!cs) return -1;
627 *cs = *(MDICREATESTRUCTW *)*plparam;
628 if (HIWORD(cs->szClass))
629 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
630 (LPCSTR)cs->szClass );
631 if (HIWORD(cs->szTitle))
632 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
633 (LPCSTR)cs->szTitle );
634 *plparam = (LPARAM)cs;
636 return 1;
638 /* Listbox */
639 case LB_ADDSTRING:
640 case LB_INSERTSTRING:
641 case LB_FINDSTRING:
642 case LB_FINDSTRINGEXACT:
643 case LB_SELECTSTRING:
644 if(!*plparam) return 0;
645 if ( WINPROC_TestLBForStr( hwnd ))
646 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
647 return (*plparam ? 1 : -1);
649 case LB_GETTEXT: /* FIXME: fixed sized buffer */
650 { if ( WINPROC_TestLBForStr( hwnd ))
651 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
652 if (!ptr) return -1;
653 *ptr++ = *plparam; /* Store previous lParam */
654 *plparam = (LPARAM)ptr;
657 return 1;
659 /* Combobox */
660 case CB_ADDSTRING:
661 case CB_INSERTSTRING:
662 case CB_FINDSTRINGEXACT:
663 case CB_FINDSTRING:
664 case CB_SELECTSTRING:
665 if(!*plparam) return 0;
666 if ( WINPROC_TestCBForStr( hwnd ))
667 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
668 return (*plparam ? 1 : -1);
670 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
671 { if ( WINPROC_TestCBForStr( hwnd ))
672 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR) + sizeof(LPARAM) );
673 if (!ptr) return -1;
674 *ptr++ = *plparam; /* Store previous lParam */
675 *plparam = (LPARAM)ptr;
678 return 1;
680 /* Multiline edit */
681 case EM_GETLINE:
682 { WORD len = (WORD)*plparam;
683 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
684 if (!ptr) return -1;
685 *ptr++ = *plparam; /* Store previous lParam */
686 *((WORD *) ptr) = len; /* Store the length */
687 *plparam = (LPARAM)ptr;
689 return 1;
691 case WM_CHARTOITEM:
692 case WM_MENUCHAR:
693 case WM_CHAR:
694 case WM_DEADCHAR:
695 case WM_SYSCHAR:
696 case WM_SYSDEADCHAR:
697 case EM_SETPASSWORDCHAR:
699 char ch = LOWORD(*pwparam);
700 WCHAR wch;
701 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
702 *pwparam = MAKEWPARAM( wch, HIWORD(*pwparam) );
704 return 0;
706 case WM_PAINTCLIPBOARD:
707 case WM_SIZECLIPBOARD:
708 FIXME_(msg)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg, hwnd), msg );
709 return -1;
710 default: /* No translation needed */
711 return 0;
716 /**********************************************************************
717 * WINPROC_UnmapMsg32ATo32W
719 * Unmap a message that was mapped from Ansi to Unicode.
721 LRESULT WINPROC_UnmapMsg32ATo32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
722 LRESULT result )
724 switch(msg)
726 case WM_GETTEXT:
727 case WM_ASKCBFORMATNAME:
729 LPARAM *ptr = (LPARAM *)lParam - 1;
730 if (wParam > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
731 (LPSTR)*ptr, wParam, NULL, NULL ))
732 ((LPSTR)*ptr)[wParam-1] = 0;
733 HeapFree( GetProcessHeap(), 0, ptr );
735 break;
736 case WM_GETTEXTLENGTH:
737 case CB_GETLBTEXTLEN:
738 case LB_GETTEXTLEN:
739 /* there may be one DBCS char for each Unicode char */
740 return result * 2;
741 case WM_NCCREATE:
742 case WM_CREATE:
744 struct s
745 { CREATESTRUCTW cs; /* new structure */
746 LPWSTR lpszName; /* allocated Name */
747 LPWSTR lpszClass; /* allocated Class */
749 struct s *xs = (struct s *)lParam;
750 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
751 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
752 HeapFree( GetProcessHeap(), 0, xs );
754 break;
756 case WM_MDICREATE:
758 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
759 if (HIWORD(cs->szTitle))
760 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
761 if (HIWORD(cs->szClass))
762 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
763 HeapFree( GetProcessHeap(), 0, cs );
765 break;
767 case WM_SETTEXT:
768 case WM_WININICHANGE:
769 case WM_DEVMODECHANGE:
770 case CB_DIR:
771 case LB_DIR:
772 case LB_ADDFILE:
773 case EM_REPLACESEL:
774 HeapFree( GetProcessHeap(), 0, (void *)lParam );
775 break;
777 /* Listbox */
778 case LB_ADDSTRING:
779 case LB_INSERTSTRING:
780 case LB_FINDSTRING:
781 case LB_FINDSTRINGEXACT:
782 case LB_SELECTSTRING:
783 if ( WINPROC_TestLBForStr( hwnd ))
784 HeapFree( GetProcessHeap(), 0, (void *)lParam );
785 break;
787 case LB_GETTEXT:
788 { if ( WINPROC_TestLBForStr( hwnd ))
789 { LPARAM *ptr = (LPARAM *)lParam - 1;
790 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
791 HeapFree( GetProcessHeap(), 0, ptr );
794 break;
796 /* Combobox */
797 case CB_ADDSTRING:
798 case CB_INSERTSTRING:
799 case CB_FINDSTRING:
800 case CB_FINDSTRINGEXACT:
801 case CB_SELECTSTRING:
802 if ( WINPROC_TestCBForStr( hwnd ))
803 HeapFree( GetProcessHeap(), 0, (void *)lParam );
804 break;
806 case CB_GETLBTEXT:
807 { if ( WINPROC_TestCBForStr( hwnd ))
808 { LPARAM *ptr = (LPARAM *)lParam - 1;
809 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
810 HeapFree( GetProcessHeap(), 0, ptr );
813 break;
815 /* Multiline edit */
816 case EM_GETLINE:
817 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
818 WORD len = *(WORD *) lParam;
819 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
820 (LPSTR)*ptr, len, NULL, NULL ))
821 ((LPSTR)*ptr)[len-1] = 0;
822 HeapFree( GetProcessHeap(), 0, ptr );
824 break;
826 return result;
830 /**********************************************************************
831 * WINPROC_MapMsg32WTo32A
833 * Map a message from Unicode to Ansi.
834 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
836 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
838 switch(msg)
840 case WM_GETTEXT:
841 case WM_ASKCBFORMATNAME:
843 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
844 *pwparam + sizeof(LPARAM) );
845 if (!ptr) return -1;
846 *ptr++ = *plparam; /* Store previous lParam */
847 *plparam = (LPARAM)ptr;
849 return 1;
851 case WM_SETTEXT:
852 case WM_WININICHANGE:
853 case WM_DEVMODECHANGE:
854 case CB_DIR:
855 case LB_DIR:
856 case LB_ADDFILE:
857 case EM_REPLACESEL:
858 if(!*plparam) return 0;
859 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
860 return (*plparam ? 1 : -1);
862 case WM_NCCREATE:
863 case WM_CREATE:
865 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
866 sizeof(*cs) );
867 if (!cs) return -1;
868 *cs = *(CREATESTRUCTA *)*plparam;
869 if (HIWORD(cs->lpszName))
870 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
871 (LPCWSTR)cs->lpszName );
872 if (HIWORD(cs->lpszClass))
873 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
874 (LPCWSTR)cs->lpszClass);
875 *plparam = (LPARAM)cs;
877 return 1;
878 case WM_MDICREATE:
880 MDICREATESTRUCTA *cs =
881 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
882 if (!cs) return -1;
883 *cs = *(MDICREATESTRUCTA *)*plparam;
884 if (HIWORD(cs->szTitle))
885 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
886 (LPCWSTR)cs->szTitle );
887 if (HIWORD(cs->szClass))
888 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
889 (LPCWSTR)cs->szClass );
890 *plparam = (LPARAM)cs;
892 return 1;
894 /* Listbox */
895 case LB_ADDSTRING:
896 case LB_INSERTSTRING:
897 case LB_FINDSTRING:
898 case LB_FINDSTRINGEXACT:
899 case LB_SELECTSTRING:
900 if(!*plparam) return 0;
901 if ( WINPROC_TestLBForStr( hwnd ))
902 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
903 return (*plparam ? 1 : -1);
905 case LB_GETTEXT: /* FIXME: fixed sized buffer */
906 { if ( WINPROC_TestLBForStr( hwnd ))
907 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
908 if (!ptr) return -1;
909 *ptr++ = *plparam; /* Store previous lParam */
910 *plparam = (LPARAM)ptr;
913 return 1;
915 /* Combobox */
916 case CB_ADDSTRING:
917 case CB_INSERTSTRING:
918 case CB_FINDSTRING:
919 case CB_FINDSTRINGEXACT:
920 case CB_SELECTSTRING:
921 if(!*plparam) return 0;
922 if ( WINPROC_TestCBForStr( hwnd ))
923 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
924 return (*plparam ? 1 : -1);
926 case CB_GETLBTEXT: /* FIXME: fixed sized buffer */
927 { if ( WINPROC_TestCBForStr( hwnd ))
928 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
929 if (!ptr) return -1;
930 *ptr++ = *plparam; /* Store previous lParam */
931 *plparam = (LPARAM)ptr;
934 return 1;
936 /* Multiline edit */
937 case EM_GETLINE:
938 { WORD len = (WORD)*plparam;
939 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
940 if (!ptr) return -1;
941 *ptr++ = *plparam; /* Store previous lParam */
942 *((WORD *) ptr) = len; /* Store the length */
943 *plparam = (LPARAM)ptr;
945 return 1;
947 case WM_CHARTOITEM:
948 case WM_MENUCHAR:
949 case WM_CHAR:
950 case WM_DEADCHAR:
951 case WM_SYSCHAR:
952 case WM_SYSDEADCHAR:
953 case EM_SETPASSWORDCHAR:
955 WCHAR wch = LOWORD(*pwparam);
956 char ch;
957 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
958 *pwparam = MAKEWPARAM( ch, HIWORD(*pwparam) );
960 return 0;
962 case WM_PAINTCLIPBOARD:
963 case WM_SIZECLIPBOARD:
964 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg, hwnd),msg );
965 return -1;
966 default: /* No translation needed */
967 return 0;
972 /**********************************************************************
973 * WINPROC_UnmapMsg32WTo32A
975 * Unmap a message that was mapped from Unicode to Ansi.
977 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
979 switch(msg)
981 case WM_GETTEXT:
982 case WM_ASKCBFORMATNAME:
984 LPARAM *ptr = (LPARAM *)lParam - 1;
985 if (wParam)
987 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, wParam ))
988 ((LPWSTR)*ptr)[wParam-1] = 0;
990 HeapFree( GetProcessHeap(), 0, ptr );
992 break;
994 case WM_SETTEXT:
995 case WM_WININICHANGE:
996 case WM_DEVMODECHANGE:
997 case CB_DIR:
998 case LB_DIR:
999 case LB_ADDFILE:
1000 case EM_REPLACESEL:
1001 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1002 break;
1004 case WM_NCCREATE:
1005 case WM_CREATE:
1007 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1008 if (HIWORD(cs->lpszName))
1009 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1010 if (HIWORD(cs->lpszClass))
1011 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1012 HeapFree( GetProcessHeap(), 0, cs );
1014 break;
1016 case WM_MDICREATE:
1018 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1019 if (HIWORD(cs->szTitle))
1020 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1021 if (HIWORD(cs->szClass))
1022 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1023 HeapFree( GetProcessHeap(), 0, cs );
1025 break;
1027 /* Listbox */
1028 case LB_ADDSTRING:
1029 case LB_INSERTSTRING:
1030 case LB_FINDSTRING:
1031 case LB_FINDSTRINGEXACT:
1032 case LB_SELECTSTRING:
1033 if ( WINPROC_TestLBForStr( hwnd ))
1034 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1035 break;
1037 case LB_GETTEXT:
1038 if ( WINPROC_TestLBForStr( hwnd ))
1040 LPARAM *ptr = (LPARAM *)lParam - 1;
1041 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1042 HeapFree( GetProcessHeap(), 0, ptr );
1044 break;
1046 /* Combobox */
1047 case CB_ADDSTRING:
1048 case CB_INSERTSTRING:
1049 case CB_FINDSTRING:
1050 case CB_FINDSTRINGEXACT:
1051 case CB_SELECTSTRING:
1052 if ( WINPROC_TestCBForStr( hwnd ))
1053 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1054 break;
1056 case CB_GETLBTEXT:
1057 if ( WINPROC_TestCBForStr( hwnd ))
1059 LPARAM *ptr = (LPARAM *)lParam - 1;
1060 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1061 HeapFree( GetProcessHeap(), 0, ptr );
1063 break;
1065 /* Multiline edit */
1066 case EM_GETLINE:
1067 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1068 WORD len = *(WORD *)ptr;
1069 if (len)
1071 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, len ))
1072 ((LPWSTR)*ptr)[len-1] = 0;
1074 HeapFree( GetProcessHeap(), 0, ptr );
1076 break;
1081 /**********************************************************************
1082 * WINPROC_MapMsg16To32A
1084 * Map a message from 16- to 32-bit Ansi.
1085 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1087 INT WINPROC_MapMsg16To32A( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1088 WPARAM *pwparam32, LPARAM *plparam )
1090 *pmsg32 = (UINT)msg16;
1091 *pwparam32 = (WPARAM)wParam16;
1092 switch(msg16)
1094 case WM_ACTIVATE:
1095 case WM_CHARTOITEM:
1096 case WM_COMMAND:
1097 case WM_VKEYTOITEM:
1098 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1099 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1100 return 0;
1101 case WM_HSCROLL:
1102 case WM_VSCROLL:
1103 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1104 *plparam = (LPARAM)WIN_Handle32( HIWORD(*plparam) );
1105 return 0;
1106 case WM_CTLCOLOR:
1107 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1108 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1109 *pwparam32 = (WPARAM)(HDC)wParam16;
1110 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1111 return 0;
1112 case WM_COMPAREITEM:
1114 COMPAREITEMSTRUCT16* cis16 = MapSL(*plparam);
1115 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1116 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1117 if (!cis) return -1;
1118 cis->CtlType = cis16->CtlType;
1119 cis->CtlID = cis16->CtlID;
1120 cis->hwndItem = WIN_Handle32( cis16->hwndItem );
1121 cis->itemID1 = cis16->itemID1;
1122 cis->itemData1 = cis16->itemData1;
1123 cis->itemID2 = cis16->itemID2;
1124 cis->itemData2 = cis16->itemData2;
1125 cis->dwLocaleId = 0; /* FIXME */
1126 *plparam = (LPARAM)cis;
1128 return 1;
1129 case WM_DELETEITEM:
1131 DELETEITEMSTRUCT16* dis16 = MapSL(*plparam);
1132 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1133 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1134 if (!dis) return -1;
1135 dis->CtlType = dis16->CtlType;
1136 dis->CtlID = dis16->CtlID;
1137 dis->hwndItem = WIN_Handle32( dis16->hwndItem );
1138 dis->itemData = dis16->itemData;
1139 *plparam = (LPARAM)dis;
1141 return 1;
1142 case WM_MEASUREITEM:
1144 MEASUREITEMSTRUCT16* mis16 = MapSL(*plparam);
1145 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1146 HeapAlloc(GetProcessHeap(), 0,
1147 sizeof(*mis) + sizeof(LPARAM));
1148 if (!mis) return -1;
1149 mis->CtlType = mis16->CtlType;
1150 mis->CtlID = mis16->CtlID;
1151 mis->itemID = mis16->itemID;
1152 mis->itemWidth = mis16->itemWidth;
1153 mis->itemHeight = mis16->itemHeight;
1154 mis->itemData = mis16->itemData;
1155 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1156 *plparam = (LPARAM)mis;
1158 return 1;
1159 case WM_DRAWITEM:
1161 DRAWITEMSTRUCT16* dis16 = MapSL(*plparam);
1162 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1163 sizeof(*dis));
1164 if (!dis) return -1;
1165 dis->CtlType = dis16->CtlType;
1166 dis->CtlID = dis16->CtlID;
1167 dis->itemID = dis16->itemID;
1168 dis->itemAction = dis16->itemAction;
1169 dis->itemState = dis16->itemState;
1170 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND)(HMENU)dis16->hwndItem
1171 : WIN_Handle32( dis16->hwndItem );
1172 dis->hDC = dis16->hDC;
1173 dis->itemData = dis16->itemData;
1174 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1175 *plparam = (LPARAM)dis;
1177 return 1;
1178 case WM_GETMINMAXINFO:
1180 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1181 sizeof(*mmi) + sizeof(LPARAM));
1182 if (!mmi) return -1;
1183 STRUCT32_MINMAXINFO16to32( MapSL(*plparam), mmi );
1184 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1185 *plparam = (LPARAM)mmi;
1187 return 1;
1188 case WM_GETTEXT:
1189 case WM_SETTEXT:
1190 case WM_WININICHANGE:
1191 case WM_DEVMODECHANGE:
1192 case WM_ASKCBFORMATNAME:
1193 *plparam = (LPARAM)MapSL(*plparam);
1194 return 0;
1195 case WM_MDICREATE:
1197 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1198 MDICREATESTRUCTA *cs = HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) + sizeof(LPARAM) );
1199 if (!cs) return -1;
1200 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1201 cs->szTitle = MapSL(cs16->szTitle);
1202 cs->szClass = MapSL(cs16->szClass);
1203 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1204 *plparam = (LPARAM)cs;
1206 return 1;
1207 case WM_MDIGETACTIVE:
1208 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1209 *(BOOL*)(*plparam) = 0;
1210 return 1;
1211 case WM_MDISETMENU:
1212 if(wParam16==TRUE)
1213 *pmsg32=WM_MDIREFRESHMENU;
1214 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1215 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1216 return 0;
1217 case WM_MENUCHAR:
1218 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1219 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1220 return 0;
1221 case WM_MENUSELECT:
1222 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1224 HMENU hmenu=(HMENU)HIWORD(*plparam);
1225 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1226 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1227 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1229 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1230 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1231 return 0;
1232 case WM_MDIACTIVATE:
1233 if( *plparam )
1235 *pwparam32 = (WPARAM)WIN_Handle32( HIWORD(*plparam) );
1236 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1238 else /* message sent to MDI client */
1239 *pwparam32 = wParam16;
1240 return 0;
1241 case WM_NCCALCSIZE:
1243 NCCALCSIZE_PARAMS16 *nc16;
1244 NCCALCSIZE_PARAMS *nc;
1246 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1247 sizeof(*nc) + sizeof(LPARAM) );
1248 if (!nc) return -1;
1249 nc16 = MapSL(*plparam);
1250 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1251 if (wParam16)
1253 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1254 sizeof(*nc->lppos) );
1255 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1256 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1257 if (nc->lppos) STRUCT32_WINDOWPOS16to32( MapSL(nc16->lppos), nc->lppos );
1259 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1260 *plparam = (LPARAM)nc;
1262 return 1;
1263 case WM_NCCREATE:
1264 case WM_CREATE:
1266 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1267 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1268 sizeof(*cs) + sizeof(LPARAM) );
1269 if (!cs) return -1;
1270 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1271 cs->lpszName = MapSL(cs16->lpszName);
1272 cs->lpszClass = MapSL(cs16->lpszClass);
1273 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1274 *plparam = (LPARAM)cs;
1276 return 1;
1277 case WM_PARENTNOTIFY:
1278 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1280 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1281 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1283 return 0;
1284 case WM_WINDOWPOSCHANGING:
1285 case WM_WINDOWPOSCHANGED:
1287 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1288 sizeof(*wp) + sizeof(LPARAM) );
1289 if (!wp) return -1;
1290 STRUCT32_WINDOWPOS16to32( MapSL(*plparam), wp );
1291 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1292 *plparam = (LPARAM)wp;
1294 return 1;
1295 case WM_GETDLGCODE:
1296 if (*plparam)
1298 LPMSG16 msg16 = MapSL(*plparam);
1299 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1301 if (!msg32) return -1;
1302 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1303 msg32->lParam = msg16->lParam;
1304 msg32->time = msg16->time;
1305 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1306 /* this is right, right? */
1307 if (WINPROC_MapMsg16To32A( msg32->hwnd, msg16->message,msg16->wParam,
1308 &msg32->message,&msg32->wParam,
1309 &msg32->lParam)<0) {
1310 HeapFree( GetProcessHeap(), 0, msg32 );
1311 return -1;
1313 *plparam = (LPARAM)msg32;
1314 return 1;
1316 else return 0;
1317 case WM_NOTIFY:
1318 *plparam = (LPARAM)MapSL(*plparam);
1319 return 0;
1320 case WM_ACTIVATEAPP:
1321 if (*plparam)
1322 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1323 a 32bit window. Might be superflous with 32bit interprocess
1324 message queues.
1326 HTASK16 htask = (HTASK16) *plparam;
1327 DWORD idThread = (DWORD)TASK_GetPtr(htask)->teb->tid;
1328 *plparam = (LPARAM) idThread;
1330 return 0;
1331 case WM_NEXTMENU:
1333 MDINEXTMENU *next = HeapAlloc( GetProcessHeap(), 0, sizeof(*next) );
1334 if (!next) return -1;
1335 next->hmenuIn = *plparam;
1336 next->hmenuNext = 0;
1337 next->hwndNext = 0;
1338 *plparam = (LPARAM)next;
1339 return 1;
1341 case WM_PAINTCLIPBOARD:
1342 case WM_SIZECLIPBOARD:
1343 FIXME_(msg)("message %04x needs translation\n",msg16 );
1344 return -1;
1346 default: /* No translation needed */
1347 return 0;
1352 /**********************************************************************
1353 * WINPROC_UnmapMsg16To32A
1355 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1357 LRESULT WINPROC_UnmapMsg16To32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1358 LRESULT result )
1360 switch(msg)
1362 case WM_COMPAREITEM:
1363 case WM_DELETEITEM:
1364 case WM_DRAWITEM:
1365 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1366 break;
1367 case WM_MEASUREITEM:
1369 MEASUREITEMSTRUCT16 *mis16;
1370 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1371 lParam = *(LPARAM *)(mis + 1);
1372 mis16 = MapSL(lParam);
1373 mis16->itemWidth = (UINT16)mis->itemWidth;
1374 mis16->itemHeight = (UINT16)mis->itemHeight;
1375 HeapFree( GetProcessHeap(), 0, mis );
1377 break;
1378 case WM_GETMINMAXINFO:
1380 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1381 lParam = *(LPARAM *)(mmi + 1);
1382 STRUCT32_MINMAXINFO32to16( mmi, MapSL(lParam));
1383 HeapFree( GetProcessHeap(), 0, mmi );
1385 break;
1386 case WM_MDICREATE:
1388 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1389 lParam = *(LPARAM *)(cs + 1);
1390 STRUCT32_MDICREATESTRUCT32Ato16( cs, MapSL(lParam) );
1391 HeapFree( GetProcessHeap(), 0, cs );
1393 break;
1394 case WM_MDIGETACTIVE:
1395 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1396 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1397 break;
1398 case WM_NCCALCSIZE:
1400 NCCALCSIZE_PARAMS16 *nc16;
1401 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1402 lParam = *(LPARAM *)(nc + 1);
1403 nc16 = MapSL(lParam);
1404 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1405 if (wParam)
1407 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1408 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1409 if (nc->lppos)
1411 STRUCT32_WINDOWPOS32to16( nc->lppos, MapSL(nc16->lppos));
1412 HeapFree( GetProcessHeap(), 0, nc->lppos );
1415 HeapFree( GetProcessHeap(), 0, nc );
1417 break;
1418 case WM_NCCREATE:
1419 case WM_CREATE:
1421 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1422 lParam = *(LPARAM *)(cs + 1);
1423 STRUCT32_CREATESTRUCT32Ato16( cs, MapSL(lParam) );
1424 HeapFree( GetProcessHeap(), 0, cs );
1426 break;
1427 case WM_WINDOWPOSCHANGING:
1428 case WM_WINDOWPOSCHANGED:
1430 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1431 lParam = *(LPARAM *)(wp + 1);
1432 STRUCT32_WINDOWPOS32to16(wp, MapSL(lParam));
1433 HeapFree( GetProcessHeap(), 0, wp );
1435 break;
1436 case WM_GETDLGCODE:
1437 if (lParam)
1439 LPMSG msg32 = (LPMSG)lParam;
1441 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1442 result);
1443 HeapFree( GetProcessHeap(), 0, msg32 );
1445 break;
1446 case WM_NEXTMENU:
1448 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1449 result = MAKELONG( next->hmenuNext, WIN_Handle16(next->hwndNext) );
1450 HeapFree( GetProcessHeap(), 0, next );
1452 break;
1454 return result;
1458 /**********************************************************************
1459 * WINPROC_MapMsg16To32W
1461 * Map a message from 16- to 32-bit Unicode.
1462 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1464 INT WINPROC_MapMsg16To32W( HWND hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1465 WPARAM *pwparam32, LPARAM *plparam )
1467 char ch;
1468 WCHAR wch;
1470 *pmsg32=(UINT)msg16;
1471 *pwparam32 = (WPARAM)wParam16;
1472 switch(msg16)
1474 case WM_GETTEXT:
1475 case WM_SETTEXT:
1476 case WM_WININICHANGE:
1477 case WM_DEVMODECHANGE:
1478 case WM_ASKCBFORMATNAME:
1479 *plparam = (LPARAM)MapSL(*plparam);
1480 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1481 case WM_GETTEXTLENGTH:
1482 case CB_GETLBTEXTLEN:
1483 case LB_GETTEXTLEN:
1484 return 1; /* need to map result */
1485 case WM_NCCREATE:
1486 case WM_CREATE:
1488 CREATESTRUCT16 *cs16 = MapSL(*plparam);
1489 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1490 sizeof(*cs) + sizeof(LPARAM) );
1491 if (!cs) return -1;
1492 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1493 cs->lpszName = map_str_16_to_32W(cs16->lpszName);
1494 cs->lpszClass = map_str_16_to_32W(cs16->lpszClass);
1495 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1496 *plparam = (LPARAM)cs;
1498 return 1;
1499 case WM_MDICREATE:
1501 MDICREATESTRUCT16 *cs16 = MapSL(*plparam);
1502 MDICREATESTRUCTW *cs =
1503 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1504 sizeof(*cs) + sizeof(LPARAM) );
1505 if (!cs) return -1;
1506 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1507 cs->szTitle = map_str_16_to_32W(cs16->szTitle);
1508 cs->szClass = map_str_16_to_32W(cs16->szClass);
1509 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1510 *plparam = (LPARAM)cs;
1512 return 1;
1513 case WM_GETDLGCODE:
1514 if (*plparam)
1516 LPMSG16 msg16 = MapSL(*plparam);
1517 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1519 if (!msg32) return -1;
1520 msg32->hwnd = WIN_Handle32( msg16->hwnd );
1521 msg32->lParam = msg16->lParam;
1522 msg32->time = msg16->time;
1523 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1524 /* this is right, right? */
1525 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1526 &msg32->message,&msg32->wParam,
1527 &msg32->lParam)<0) {
1528 HeapFree( GetProcessHeap(), 0, msg32 );
1529 return -1;
1531 *plparam = (LPARAM)msg32;
1532 return 1;
1534 else return 0;
1536 case WM_CHARTOITEM:
1537 ch = wParam16;
1538 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1539 *pwparam32 = MAKEWPARAM( wch, HIWORD(*plparam) );
1540 *plparam = (LPARAM)WIN_Handle32( LOWORD(*plparam) );
1541 return 0;
1542 case WM_MENUCHAR:
1543 ch = wParam16;
1544 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1545 *pwparam32 = MAKEWPARAM( wch, LOWORD(*plparam) );
1546 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1547 return 0;
1548 case WM_CHAR:
1549 case WM_DEADCHAR:
1550 case WM_SYSCHAR:
1551 case WM_SYSDEADCHAR:
1552 ch = wParam16;
1553 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1554 *pwparam32 = wch;
1555 return 0;
1557 default: /* No Unicode translation needed */
1558 return WINPROC_MapMsg16To32A( hwnd, msg16, wParam16, pmsg32,
1559 pwparam32, plparam );
1564 /**********************************************************************
1565 * WINPROC_UnmapMsg16To32W
1567 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1569 LRESULT WINPROC_UnmapMsg16To32W( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1570 LRESULT result )
1572 switch(msg)
1574 case WM_GETTEXT:
1575 case WM_SETTEXT:
1576 case WM_GETTEXTLENGTH:
1577 case CB_GETLBTEXTLEN:
1578 case LB_GETTEXTLEN:
1579 case WM_ASKCBFORMATNAME:
1580 return WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
1581 case WM_NCCREATE:
1582 case WM_CREATE:
1584 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1585 lParam = *(LPARAM *)(cs + 1);
1586 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs, MapSL(lParam) );
1587 unmap_str_16_to_32W( cs->lpszName );
1588 unmap_str_16_to_32W( cs->lpszClass );
1589 HeapFree( GetProcessHeap(), 0, cs );
1591 break;
1592 case WM_MDICREATE:
1594 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1595 lParam = *(LPARAM *)(cs + 1);
1596 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs, MapSL(lParam) );
1597 unmap_str_16_to_32W( cs->szTitle );
1598 unmap_str_16_to_32W( cs->szClass );
1599 HeapFree( GetProcessHeap(), 0, cs );
1601 break;
1602 case WM_GETDLGCODE:
1603 if (lParam)
1605 LPMSG msg32 = (LPMSG)lParam;
1607 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1608 result);
1609 HeapFree( GetProcessHeap(), 0, msg32 );
1611 break;
1612 default:
1613 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1615 return result;
1619 /**********************************************************************
1620 * WINPROC_MapMsg32ATo16
1622 * Map a message from 32-bit Ansi to 16-bit.
1623 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1625 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1626 UINT16 *pmsg16, WPARAM16 *pwparam16,
1627 LPARAM *plparam )
1629 *pmsg16 = (UINT16)msg32;
1630 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1631 switch(msg32)
1633 case BM_GETCHECK:
1634 case BM_SETCHECK:
1635 case BM_GETSTATE:
1636 case BM_SETSTATE:
1637 case BM_SETSTYLE:
1638 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1639 return 0;
1641 case EM_GETSEL:
1642 case EM_GETRECT:
1643 case EM_SETRECT:
1644 case EM_SETRECTNP:
1645 case EM_SCROLL:
1646 case EM_LINESCROLL:
1647 case EM_SCROLLCARET:
1648 case EM_GETMODIFY:
1649 case EM_SETMODIFY:
1650 case EM_GETLINECOUNT:
1651 case EM_LINEINDEX:
1652 case EM_SETHANDLE:
1653 case EM_GETHANDLE:
1654 case EM_GETTHUMB:
1655 case EM_LINELENGTH:
1656 case EM_REPLACESEL:
1657 case EM_GETLINE:
1658 case EM_LIMITTEXT:
1659 case EM_CANUNDO:
1660 case EM_UNDO:
1661 case EM_FMTLINES:
1662 case EM_LINEFROMCHAR:
1663 case EM_SETTABSTOPS:
1664 case EM_SETPASSWORDCHAR:
1665 case EM_EMPTYUNDOBUFFER:
1666 case EM_GETFIRSTVISIBLELINE:
1667 case EM_SETREADONLY:
1668 case EM_SETWORDBREAKPROC:
1669 case EM_GETWORDBREAKPROC:
1670 case EM_GETPASSWORDCHAR:
1671 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1672 return 0;
1674 case LB_CARETOFF:
1675 case LB_CARETON:
1676 case LB_DELETESTRING:
1677 case LB_GETANCHORINDEX:
1678 case LB_GETCARETINDEX:
1679 case LB_GETCOUNT:
1680 case LB_GETCURSEL:
1681 case LB_GETHORIZONTALEXTENT:
1682 case LB_GETITEMDATA:
1683 case LB_GETITEMHEIGHT:
1684 case LB_GETSEL:
1685 case LB_GETSELCOUNT:
1686 case LB_GETTEXTLEN:
1687 case LB_GETTOPINDEX:
1688 case LB_RESETCONTENT:
1689 case LB_SELITEMRANGE:
1690 case LB_SELITEMRANGEEX:
1691 case LB_SETANCHORINDEX:
1692 case LB_SETCARETINDEX:
1693 case LB_SETCOLUMNWIDTH:
1694 case LB_SETCURSEL:
1695 case LB_SETHORIZONTALEXTENT:
1696 case LB_SETITEMDATA:
1697 case LB_SETITEMHEIGHT:
1698 case LB_SETSEL:
1699 case LB_SETTOPINDEX:
1700 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1701 return 0;
1702 case CB_DELETESTRING:
1703 case CB_GETCOUNT:
1704 case CB_GETLBTEXTLEN:
1705 case CB_LIMITTEXT:
1706 case CB_RESETCONTENT:
1707 case CB_SETEDITSEL:
1708 case CB_GETCURSEL:
1709 case CB_SETCURSEL:
1710 case CB_SHOWDROPDOWN:
1711 case CB_SETITEMDATA:
1712 case CB_SETITEMHEIGHT:
1713 case CB_GETITEMHEIGHT:
1714 case CB_SETEXTENDEDUI:
1715 case CB_GETEXTENDEDUI:
1716 case CB_GETDROPPEDSTATE:
1717 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1718 return 0;
1719 case CB_GETEDITSEL:
1720 *pmsg16 = CB_GETEDITSEL16;
1721 return 1;
1723 case LB_ADDSTRING:
1724 case LB_FINDSTRING:
1725 case LB_FINDSTRINGEXACT:
1726 case LB_INSERTSTRING:
1727 case LB_SELECTSTRING:
1728 case LB_DIR:
1729 case LB_ADDFILE:
1730 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
1731 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1732 return 1;
1734 case CB_ADDSTRING:
1735 case CB_FINDSTRING:
1736 case CB_FINDSTRINGEXACT:
1737 case CB_INSERTSTRING:
1738 case CB_SELECTSTRING:
1739 case CB_DIR:
1740 *plparam = (LPARAM)MapLS( (LPSTR)*plparam );
1741 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1742 return 1;
1744 case LB_GETITEMRECT:
1746 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
1747 if (!rect) return -1;
1748 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1749 *plparam = MapLS( rect );
1751 *pmsg16 = LB_GETITEMRECT16;
1752 return 1;
1753 case LB_GETSELITEMS:
1755 LPINT16 items;
1756 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1757 if (!(items = HeapAlloc( GetProcessHeap(), 0,
1758 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
1759 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1760 *plparam = MapLS( items );
1762 *pmsg16 = LB_GETSELITEMS16;
1763 return 1;
1764 case LB_SETTABSTOPS:
1765 if (wParam32)
1767 INT i;
1768 LPINT16 stops;
1769 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1770 if (!(stops = HeapAlloc( GetProcessHeap(), 0,
1771 *pwparam16 * sizeof(INT16) + sizeof(LPARAM)))) return -1;
1772 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1773 *plparam = MapLS( stops );
1774 return 1;
1776 *pmsg16 = LB_SETTABSTOPS16;
1777 return 0;
1779 case CB_GETDROPPEDCONTROLRECT:
1781 RECT16 *rect = HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16) + sizeof(LPARAM) );
1782 if (!rect) return -1;
1783 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1784 *plparam = (LPARAM)MapLS(rect);
1786 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1787 return 1;
1789 case LB_GETTEXT:
1790 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1791 *pmsg16 = LB_GETTEXT16;
1792 return 1;
1794 case CB_GETLBTEXT:
1795 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1796 *pmsg16 = CB_GETLBTEXT16;
1797 return 1;
1799 case EM_SETSEL:
1800 *pwparam16 = 0;
1801 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1802 *pmsg16 = EM_SETSEL16;
1803 return 0;
1805 case WM_ACTIVATE:
1806 case WM_CHARTOITEM:
1807 case WM_COMMAND:
1808 case WM_VKEYTOITEM:
1809 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1810 return 0;
1811 case WM_HSCROLL:
1812 case WM_VSCROLL:
1813 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1814 return 0;
1815 case WM_CTLCOLORMSGBOX:
1816 case WM_CTLCOLOREDIT:
1817 case WM_CTLCOLORLISTBOX:
1818 case WM_CTLCOLORBTN:
1819 case WM_CTLCOLORDLG:
1820 case WM_CTLCOLORSCROLLBAR:
1821 case WM_CTLCOLORSTATIC:
1822 *pmsg16 = WM_CTLCOLOR;
1823 *plparam = MAKELPARAM( (HWND16)*plparam,
1824 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1825 return 0;
1826 case WM_COMPAREITEM:
1828 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1829 COMPAREITEMSTRUCT16 *cis = HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16));
1830 if (!cis) return -1;
1831 cis->CtlType = (UINT16)cis32->CtlType;
1832 cis->CtlID = (UINT16)cis32->CtlID;
1833 cis->hwndItem = WIN_Handle16( cis32->hwndItem );
1834 cis->itemID1 = (UINT16)cis32->itemID1;
1835 cis->itemData1 = cis32->itemData1;
1836 cis->itemID2 = (UINT16)cis32->itemID2;
1837 cis->itemData2 = cis32->itemData2;
1838 *plparam = MapLS( cis );
1840 return 1;
1841 case WM_DELETEITEM:
1843 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1844 DELETEITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16) );
1845 if (!dis) return -1;
1846 dis->CtlType = (UINT16)dis32->CtlType;
1847 dis->CtlID = (UINT16)dis32->CtlID;
1848 dis->itemID = (UINT16)dis32->itemID;
1849 dis->hwndItem = (dis->CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1850 : WIN_Handle16( dis32->hwndItem );
1851 dis->itemData = dis32->itemData;
1852 *plparam = MapLS( dis );
1854 return 1;
1855 case WM_DRAWITEM:
1857 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1858 DRAWITEMSTRUCT16 *dis = HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16) );
1859 if (!dis) return -1;
1860 dis->CtlType = (UINT16)dis32->CtlType;
1861 dis->CtlID = (UINT16)dis32->CtlID;
1862 dis->itemID = (UINT16)dis32->itemID;
1863 dis->itemAction = (UINT16)dis32->itemAction;
1864 dis->itemState = (UINT16)dis32->itemState;
1865 dis->hwndItem = WIN_Handle16( dis32->hwndItem );
1866 dis->hDC = (HDC16)dis32->hDC;
1867 dis->itemData = dis32->itemData;
1868 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1869 *plparam = MapLS( dis );
1871 return 1;
1872 case WM_MEASUREITEM:
1874 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1875 MEASUREITEMSTRUCT16 *mis = HeapAlloc( GetProcessHeap(), 0, sizeof(*mis)+sizeof(LPARAM));
1876 if (!mis) return -1;
1877 mis->CtlType = (UINT16)mis32->CtlType;
1878 mis->CtlID = (UINT16)mis32->CtlID;
1879 mis->itemID = (UINT16)mis32->itemID;
1880 mis->itemWidth = (UINT16)mis32->itemWidth;
1881 mis->itemHeight = (UINT16)mis32->itemHeight;
1882 mis->itemData = mis32->itemData;
1883 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1884 *plparam = MapLS( mis );
1886 return 1;
1887 case WM_GETMINMAXINFO:
1889 MINMAXINFO16 *mmi = HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi) + sizeof(LPARAM) );
1890 if (!mmi) return -1;
1891 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1892 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1893 *plparam = MapLS( mmi );
1895 return 1;
1896 case WM_GETTEXT:
1897 case WM_ASKCBFORMATNAME:
1899 LPSTR str;
1900 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1901 if (!(str = HeapAlloc( GetProcessHeap(), 0, *pwparam16 + sizeof(LPARAM)))) return -1;
1902 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1903 *plparam = MapLS( str );
1905 return 1;
1906 case WM_MDICREATE:
1908 MDICREATESTRUCT16 *cs;
1909 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1911 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
1912 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1913 cs->szTitle = MapLS( cs32->szTitle );
1914 cs->szClass = MapLS( cs32->szClass );
1915 *plparam = MapLS( cs );
1917 return 1;
1918 case WM_MDIGETACTIVE:
1919 return 1;
1920 case WM_MDISETMENU:
1921 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1922 (HMENU16)LOWORD(*plparam) );
1923 *pwparam16 = (*plparam == 0);
1924 return 0;
1925 case WM_MENUSELECT:
1926 if(HIWORD(wParam32) & MF_POPUP)
1928 UINT16 hmenu;
1929 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1931 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1932 *pwparam16=hmenu;
1935 /* fall through */
1936 case WM_MENUCHAR:
1937 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1938 return 0;
1939 case WM_MDIACTIVATE:
1940 if (GetWindowLongA( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
1942 *pwparam16 = ((HWND)*plparam == hwnd);
1943 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1944 (HWND16)LOWORD(wParam32) );
1946 else
1948 *pwparam16 = WIN_Handle16( (HWND)wParam32 );
1949 *plparam = 0;
1951 return 0;
1952 case WM_NCCALCSIZE:
1954 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1955 NCCALCSIZE_PARAMS16 *nc = HeapAlloc( GetProcessHeap(), 0, sizeof(*nc) + sizeof(LPARAM));
1956 if (!nc) return -1;
1958 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1959 if (wParam32)
1961 WINDOWPOS16 *wp;
1962 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1963 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1964 if (!(wp = HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16) )))
1966 HeapFree( GetProcessHeap(), 0, nc );
1967 return -1;
1969 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1970 nc->lppos = MapLS( wp );
1972 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1973 *plparam = MapLS( nc );
1975 return 1;
1976 case WM_NCCREATE:
1977 case WM_CREATE:
1979 CREATESTRUCT16 *cs;
1980 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1982 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
1983 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1984 cs->lpszName = MapLS( cs32->lpszName );
1985 cs->lpszClass = MapLS( cs32->lpszClass );
1986 *plparam = MapLS( cs );
1988 return 1;
1989 case WM_PARENTNOTIFY:
1990 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1991 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1992 /* else nothing to do */
1993 return 0;
1994 case WM_NOTIFY:
1995 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1996 return 1;
1997 case WM_SETTEXT:
1998 case WM_WININICHANGE:
1999 case WM_DEVMODECHANGE:
2000 *plparam = MapLS( (LPSTR)*plparam );
2001 return 1;
2002 case WM_WINDOWPOSCHANGING:
2003 case WM_WINDOWPOSCHANGED:
2005 WINDOWPOS16 *wp = HeapAlloc( GetProcessHeap(), 0, sizeof(*wp) + sizeof(LPARAM) );
2006 if (!wp) return -1;
2007 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
2008 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
2009 *plparam = MapLS( wp );
2011 return 1;
2012 case WM_GETDLGCODE:
2013 if (*plparam) {
2014 LPMSG msg32 = (LPMSG) *plparam;
2015 LPMSG16 msg16 = HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16) );
2017 if (!msg16) return -1;
2018 msg16->hwnd = WIN_Handle16( msg32->hwnd );
2019 msg16->lParam = msg32->lParam;
2020 msg16->time = msg32->time;
2021 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
2022 /* this is right, right? */
2023 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
2024 &msg16->message,&msg16->wParam, &msg16->lParam)<0)
2026 HeapFree( GetProcessHeap(), 0, msg16 );
2027 return -1;
2029 *plparam = MapLS( msg16 );
2030 return 1;
2032 return 0;
2034 case WM_ACTIVATEAPP:
2035 if (*plparam) *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2036 return 0;
2037 case WM_NEXTMENU:
2039 MDINEXTMENU *next = (MDINEXTMENU *)*plparam;
2040 *plparam = next->hmenuIn;
2041 return 1;
2043 case WM_PAINTCLIPBOARD:
2044 case WM_SIZECLIPBOARD:
2045 FIXME_(msg)("message %04x needs translation\n", msg32 );
2046 return -1;
2047 /* following messages should not be sent to 16-bit apps */
2048 case WM_SIZING:
2049 case WM_MOVING:
2050 case WM_CAPTURECHANGED:
2051 case WM_STYLECHANGING:
2052 case WM_STYLECHANGED:
2053 return -1;
2054 default: /* No translation needed */
2055 return 0;
2060 /**********************************************************************
2061 * WINPROC_UnmapMsg32ATo16
2063 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2065 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2066 MSGPARAM16* p16 )
2068 switch(msg)
2070 case LB_ADDFILE:
2071 case LB_ADDSTRING:
2072 case LB_DIR:
2073 case LB_FINDSTRING:
2074 case LB_FINDSTRINGEXACT:
2075 case LB_INSERTSTRING:
2076 case LB_SELECTSTRING:
2077 case LB_GETTEXT:
2078 case CB_ADDSTRING:
2079 case CB_FINDSTRING:
2080 case CB_FINDSTRINGEXACT:
2081 case CB_INSERTSTRING:
2082 case CB_SELECTSTRING:
2083 case CB_DIR:
2084 case CB_GETLBTEXT:
2085 case WM_SETTEXT:
2086 case WM_WININICHANGE:
2087 case WM_DEVMODECHANGE:
2088 UnMapLS( (SEGPTR)p16->lParam );
2089 break;
2090 case LB_SETTABSTOPS:
2091 case WM_COMPAREITEM:
2092 case WM_DELETEITEM:
2093 case WM_DRAWITEM:
2095 void *ptr = MapSL( p16->lParam );
2096 UnMapLS( p16->lParam );
2097 HeapFree( GetProcessHeap(), 0, ptr );
2099 break;
2100 case CB_GETDROPPEDCONTROLRECT:
2101 case LB_GETITEMRECT:
2103 RECT16 *rect = MapSL(p16->lParam);
2104 UnMapLS( p16->lParam );
2105 p16->lParam = *(LPARAM *)(rect + 1);
2106 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2107 HeapFree( GetProcessHeap(), 0, rect );
2109 break;
2110 case LB_GETSELITEMS:
2112 INT i;
2113 LPINT16 items = MapSL(p16->lParam);
2114 UnMapLS( p16->lParam );
2115 p16->lParam = *((LPARAM *)items - 1);
2116 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2117 HeapFree( GetProcessHeap(), 0, (LPARAM *)items - 1 );
2119 break;
2121 case CB_GETEDITSEL:
2122 if( wParam )
2123 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2124 if( lParam )
2125 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2126 break;
2128 case WM_MEASUREITEM:
2130 MEASUREITEMSTRUCT16 *mis = MapSL(p16->lParam);
2131 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2132 mis32->itemWidth = mis->itemWidth;
2133 mis32->itemHeight = mis->itemHeight;
2134 UnMapLS( p16->lParam );
2135 HeapFree( GetProcessHeap(), 0, mis );
2137 break;
2138 case WM_GETMINMAXINFO:
2140 MINMAXINFO16 *mmi = MapSL(p16->lParam);
2141 UnMapLS( p16->lParam );
2142 p16->lParam = *(LPARAM *)(mmi + 1);
2143 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2144 HeapFree( GetProcessHeap(), 0, mmi );
2146 break;
2147 case WM_GETTEXT:
2148 case WM_ASKCBFORMATNAME:
2150 LPSTR str = MapSL(p16->lParam);
2151 UnMapLS( p16->lParam );
2152 p16->lParam = *((LPARAM *)str - 1);
2153 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2154 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2156 break;
2157 case WM_MDICREATE:
2159 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2160 UnMapLS( cs->szTitle );
2161 UnMapLS( cs->szClass );
2162 UnMapLS( p16->lParam );
2163 HeapFree( GetProcessHeap(), 0, cs );
2165 break;
2166 case WM_MDIGETACTIVE:
2167 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2168 p16->lResult = (LRESULT)WIN_Handle32( LOWORD(p16->lResult) );
2169 break;
2170 case WM_NCCALCSIZE:
2172 NCCALCSIZE_PARAMS *nc32;
2173 NCCALCSIZE_PARAMS16 *nc = MapSL(p16->lParam);
2174 UnMapLS( p16->lParam );
2175 p16->lParam = *(LPARAM *)(nc + 1);
2176 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2177 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2178 if (p16->wParam)
2180 WINDOWPOS16 *pos = MapSL(nc->lppos);
2181 UnMapLS( nc->lppos );
2182 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2183 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2184 STRUCT32_WINDOWPOS16to32( pos, nc32->lppos );
2185 HeapFree( GetProcessHeap(), 0, pos );
2187 HeapFree( GetProcessHeap(), 0, nc );
2189 break;
2190 case WM_NCCREATE:
2191 case WM_CREATE:
2193 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2194 UnMapLS( p16->lParam );
2195 UnMapLS( cs->lpszName );
2196 UnMapLS( cs->lpszClass );
2197 HeapFree( GetProcessHeap(), 0, cs );
2199 break;
2200 case WM_WINDOWPOSCHANGING:
2201 case WM_WINDOWPOSCHANGED:
2203 WINDOWPOS16 *wp = MapSL(p16->lParam);
2204 UnMapLS( p16->lParam );
2205 p16->lParam = *(LPARAM *)(wp + 1);
2206 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2207 HeapFree( GetProcessHeap(), 0, wp );
2209 break;
2210 case WM_NOTIFY:
2211 UnMapLS(p16->lParam);
2212 break;
2213 case WM_GETDLGCODE:
2214 if (p16->lParam)
2216 LPMSG16 msg16 = MapSL(p16->lParam);
2217 MSGPARAM16 msgp16;
2218 UnMapLS( p16->lParam );
2219 msgp16.wParam=msg16->wParam;
2220 msgp16.lParam=msg16->lParam;
2221 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2222 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2223 &msgp16 );
2224 HeapFree( GetProcessHeap(), 0, msg16 );
2226 break;
2227 case WM_NEXTMENU:
2229 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
2230 next->hmenuNext = LOWORD(p16->lResult);
2231 next->hwndNext = WIN_Handle32( HIWORD(p16->lResult) );
2232 p16->lResult = 0;
2234 break;
2239 /**********************************************************************
2240 * WINPROC_MapMsg32WTo16
2242 * Map a message from 32-bit Unicode to 16-bit.
2243 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2245 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2246 UINT16 *pmsg16, WPARAM16 *pwparam16,
2247 LPARAM *plparam )
2249 char ch;
2250 WCHAR wch;
2252 *pmsg16 = LOWORD(msg32);
2253 *pwparam16 = LOWORD(wParam32);
2254 switch(msg32)
2256 case LB_ADDSTRING:
2257 case LB_FINDSTRING:
2258 case LB_FINDSTRINGEXACT:
2259 case LB_INSERTSTRING:
2260 case LB_SELECTSTRING:
2261 case LB_DIR:
2262 case LB_ADDFILE:
2263 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2264 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2265 return 1;
2267 case CB_ADDSTRING:
2268 case CB_FINDSTRING:
2269 case CB_FINDSTRINGEXACT:
2270 case CB_INSERTSTRING:
2271 case CB_SELECTSTRING:
2272 case CB_DIR:
2273 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2274 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2275 return 1;
2277 case WM_NCCREATE:
2278 case WM_CREATE:
2280 CREATESTRUCT16 *cs;
2281 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2283 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16) ))) return -1;
2284 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2285 cs->lpszName = map_str_32W_to_16( cs32->lpszName );
2286 cs->lpszClass = map_str_32W_to_16( cs32->lpszClass );
2287 *plparam = MapLS(cs);
2289 return 1;
2290 case WM_MDICREATE:
2292 MDICREATESTRUCT16 *cs;
2293 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2295 if (!(cs = HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16) ))) return -1;
2296 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2297 cs->szTitle = map_str_32W_to_16( cs32->szTitle );
2298 cs->szClass = map_str_32W_to_16( cs32->szClass );
2299 *plparam = MapLS(cs);
2301 return 1;
2302 case WM_SETTEXT:
2303 case WM_WININICHANGE:
2304 case WM_DEVMODECHANGE:
2305 *plparam = map_str_32W_to_16( (LPWSTR)*plparam );
2306 return 1;
2307 case LB_GETTEXT:
2308 case CB_GETLBTEXT:
2309 if ( WINPROC_TestLBForStr( hwnd ))
2311 LPSTR str = HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2312 if (!str) return -1;
2313 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2314 *plparam = (LPARAM)MapLS(str);
2316 return 1;
2318 case WM_CHARTOITEM:
2319 wch = LOWORD(wParam32);
2320 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2321 *pwparam16 = ch;
2322 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
2323 return 0;
2324 case WM_MENUCHAR:
2325 wch = LOWORD(wParam32);
2326 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2327 *pwparam16 = ch;
2328 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
2329 return 0;
2330 case WM_CHAR:
2331 case WM_DEADCHAR:
2332 case WM_SYSCHAR:
2333 case WM_SYSDEADCHAR:
2334 wch = wParam32;
2335 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2336 *pwparam16 = ch;
2337 return 0;
2339 default: /* No Unicode translation needed (?) */
2340 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2341 pwparam16, plparam );
2346 /**********************************************************************
2347 * WINPROC_UnmapMsg32WTo16
2349 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2351 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2352 MSGPARAM16* p16 )
2354 switch(msg)
2356 case LB_ADDSTRING:
2357 case LB_FINDSTRING:
2358 case LB_FINDSTRINGEXACT:
2359 case LB_INSERTSTRING:
2360 case LB_SELECTSTRING:
2361 case LB_DIR:
2362 case LB_ADDFILE:
2363 case CB_ADDSTRING:
2364 case CB_FINDSTRING:
2365 case CB_FINDSTRINGEXACT:
2366 case CB_INSERTSTRING:
2367 case CB_SELECTSTRING:
2368 case CB_DIR:
2369 case WM_SETTEXT:
2370 case WM_WININICHANGE:
2371 case WM_DEVMODECHANGE:
2372 unmap_str_32W_to_16( p16->lParam );
2373 break;
2374 case WM_NCCREATE:
2375 case WM_CREATE:
2377 CREATESTRUCT16 *cs = MapSL(p16->lParam);
2378 UnMapLS( p16->lParam );
2379 unmap_str_32W_to_16( cs->lpszName );
2380 unmap_str_32W_to_16( cs->lpszClass );
2381 HeapFree( GetProcessHeap(), 0, cs );
2383 break;
2384 case WM_MDICREATE:
2386 MDICREATESTRUCT16 *cs = MapSL(p16->lParam);
2387 UnMapLS( p16->lParam );
2388 unmap_str_32W_to_16( cs->szTitle );
2389 unmap_str_32W_to_16( cs->szClass );
2390 HeapFree( GetProcessHeap(), 0, cs );
2392 break;
2393 case WM_GETTEXT:
2394 case WM_ASKCBFORMATNAME:
2396 LPSTR str = MapSL(p16->lParam);
2397 UnMapLS( p16->lParam );
2398 p16->lParam = *((LPARAM *)str - 1);
2399 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2400 HeapFree( GetProcessHeap(), 0, (LPARAM *)str - 1 );
2402 break;
2403 case LB_GETTEXT:
2404 case CB_GETLBTEXT:
2405 if ( WINPROC_TestLBForStr( hwnd ))
2407 LPSTR str = MapSL(p16->lParam);
2408 UnMapLS( p16->lParam );
2409 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2410 HeapFree( GetProcessHeap(), 0, (LPARAM *)str );
2412 break;
2413 default:
2414 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2415 break;
2420 /**********************************************************************
2421 * WINPROC_CallProc32ATo32W
2423 * Call a window procedure, translating args from Ansi to Unicode.
2425 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2426 UINT msg, WPARAM wParam,
2427 LPARAM lParam )
2429 LRESULT result;
2430 int unmap;
2432 if( (unmap = WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam )) == -1) {
2433 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2434 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2435 return 0;
2437 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2438 if (unmap) result = WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam, result );
2439 return result;
2443 /**********************************************************************
2444 * WINPROC_CallProc32WTo32A
2446 * Call a window procedure, translating args from Unicode to Ansi.
2448 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2449 UINT msg, WPARAM wParam,
2450 LPARAM lParam )
2452 LRESULT result;
2453 int unmap;
2455 if ((unmap = WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam )) == -1) {
2456 ERR_(msg)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2457 SPY_GetMsgName(msg, hwnd), wParam, lParam );
2458 return 0;
2460 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2461 if( unmap ) WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2462 return result;
2466 /**********************************************************************
2467 * __wine_call_wndproc_32A (USER.1010)
2469 LRESULT WINAPI __wine_call_wndproc_32A( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
2470 WNDPROC func )
2472 LRESULT result;
2473 UINT msg32;
2474 WPARAM wParam32;
2475 HWND hwnd32 = WIN_Handle32( hwnd );
2477 if (WINPROC_MapMsg16To32A( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2478 return 0;
2479 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
2480 return WINPROC_UnmapMsg16To32A( hwnd32, msg32, wParam32, lParam, result );
2484 /**********************************************************************
2485 * __wine_call_wndproc_32W (USER.1011)
2487 LRESULT WINAPI __wine_call_wndproc_32W( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
2488 WNDPROC func )
2490 LRESULT result;
2491 UINT msg32;
2492 WPARAM wParam32;
2493 HWND hwnd32 = WIN_Handle32( hwnd );
2495 if (WINPROC_MapMsg16To32W( hwnd32, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2496 return 0;
2497 result = WINPROC_CallWndProc( func, hwnd32, msg32, wParam32, lParam );
2498 return WINPROC_UnmapMsg16To32W( hwnd32, msg32, wParam32, lParam, result );
2502 /**********************************************************************
2503 * WINPROC_CallProc32ATo16
2505 * Call a 16-bit window procedure, translating the 32-bit args.
2507 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2508 UINT msg, WPARAM wParam,
2509 LPARAM lParam )
2511 UINT16 msg16;
2512 MSGPARAM16 mp16;
2514 mp16.lParam = lParam;
2515 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam, &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2516 return 0;
2517 mp16.lResult = WINPROC_CallWndProc16( func, WIN_Handle16(hwnd), msg16,
2518 mp16.wParam, mp16.lParam );
2519 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2520 return mp16.lResult;
2524 /**********************************************************************
2525 * WINPROC_CallProc32WTo16
2527 * Call a 16-bit window procedure, translating the 32-bit args.
2529 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2530 UINT msg, WPARAM wParam,
2531 LPARAM lParam )
2533 UINT16 msg16;
2534 MSGPARAM16 mp16;
2536 mp16.lParam = lParam;
2537 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2538 &mp16.lParam ) == -1)
2539 return 0;
2540 mp16.lResult = WINPROC_CallWndProc16( func, WIN_Handle16(hwnd), msg16,
2541 mp16.wParam, mp16.lParam );
2542 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2543 return mp16.lResult;
2547 /**********************************************************************
2548 * CallWindowProc (USER.122)
2549 * CallWindowProc16 (USER32.@)
2551 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2552 WPARAM16 wParam, LPARAM lParam )
2554 WINDOWPROC *proc = WINPROC_GetPtr( func );
2556 if (!proc)
2557 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2559 #if testing
2560 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2561 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2562 #endif
2564 switch(proc->type)
2566 case WIN_PROC_16:
2567 if (!proc->thunk.t_from32.proc) return 0;
2568 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2569 hwnd, msg, wParam, lParam );
2570 case WIN_PROC_32A:
2571 if (!proc->thunk.t_from16.proc) return 0;
2572 return __wine_call_wndproc_32A( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
2573 case WIN_PROC_32W:
2574 if (!proc->thunk.t_from16.proc) return 0;
2575 return __wine_call_wndproc_32W( hwnd, msg, wParam, lParam, proc->thunk.t_from16.proc );
2576 default:
2577 WARN_(relay)("Invalid proc %p\n", proc );
2578 return 0;
2583 /**********************************************************************
2584 * CallWindowProcA (USER32.@)
2586 * The CallWindowProc() function invokes the windows procedure _func_,
2587 * with _hwnd_ as the target window, the message specified by _msg_, and
2588 * the message parameters _wParam_ and _lParam_.
2590 * Some kinds of argument conversion may be done, I'm not sure what.
2592 * CallWindowProc() may be used for windows subclassing. Use
2593 * SetWindowLong() to set a new windows procedure for windows of the
2594 * subclass, and handle subclassed messages in the new windows
2595 * procedure. The new windows procedure may then use CallWindowProc()
2596 * with _func_ set to the parent class's windows procedure to dispatch
2597 * the message to the superclass.
2599 * RETURNS
2601 * The return value is message dependent.
2603 * CONFORMANCE
2605 * ECMA-234, Win32
2607 LRESULT WINAPI CallWindowProcA(
2608 WNDPROC func, /* [in] window procedure */
2609 HWND hwnd, /* [in] target window */
2610 UINT msg, /* [in] message */
2611 WPARAM wParam, /* [in] message dependent parameter */
2612 LPARAM lParam /* [in] message dependent parameter */
2614 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2616 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2618 #if testing
2619 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2620 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2621 #endif
2623 switch(proc->type)
2625 case WIN_PROC_16:
2626 if (!proc->thunk.t_from32.proc) return 0;
2627 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2628 hwnd, msg, wParam, lParam );
2629 case WIN_PROC_32A:
2630 if (!proc->thunk.t_from16.proc) return 0;
2631 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2632 hwnd, msg, wParam, lParam );
2633 case WIN_PROC_32W:
2634 if (!proc->thunk.t_from16.proc) return 0;
2635 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2636 hwnd, msg, wParam, lParam );
2637 default:
2638 WARN_(relay)("Invalid proc %p\n", proc );
2639 return 0;
2644 /**********************************************************************
2645 * CallWindowProcW (USER32.@)
2647 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2648 WPARAM wParam, LPARAM lParam )
2650 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2652 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2654 #if testing
2655 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2656 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2657 #endif
2659 switch(proc->type)
2661 case WIN_PROC_16:
2662 if (!proc->thunk.t_from32.proc) return 0;
2663 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2664 hwnd, msg, wParam, lParam );
2665 case WIN_PROC_32A:
2666 if (!proc->thunk.t_from16.proc) return 0;
2667 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2668 hwnd, msg, wParam, lParam );
2669 case WIN_PROC_32W:
2670 if (!proc->thunk.t_from16.proc) return 0;
2671 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2672 hwnd, msg, wParam, lParam );
2673 default:
2674 WARN_(relay)("Invalid proc %p\n", proc );
2675 return 0;