Finished separation of advapi32.
[wine/multimedia.git] / windows / winproc.c
blob32ca4ac9cb28f3aa6b13bcc556f60292977383aa
1 /*
2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
6 */
8 #include <string.h>
9 #include "windef.h"
10 #include "winnls.h"
11 #include "wingdi.h"
12 #include "wine/winbase16.h"
13 #include "wine/winuser16.h"
14 #include "stackframe.h"
15 #include "builtin16.h"
16 #include "heap.h"
17 #include "selectors.h"
18 #include "struct32.h"
19 #include "win.h"
20 #include "winproc.h"
21 #include "debugtools.h"
22 #include "spy.h"
23 #include "commctrl.h"
24 #include "task.h"
25 #include "thread.h"
26 #include "menu.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 */
35 #include "pshpack1.h"
36 typedef struct
38 WORD pushw_bp; /* pushw %bp */
39 BYTE pushl_func; /* pushl $proc */
40 WNDPROC 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 */
48 WORD nArgs;
49 } WINPROC_THUNK_FROM16;
50 #include "poppack.h"
52 /* Window procedure 32-to-16-bit thunk,
53 * see BuildSpec32File() in tools/build.c */
55 typedef struct
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 */
66 typedef struct
68 BYTE jmp; /* jmp proc (relative jump) */
69 WNDPROC proc WINE_PACKED;
70 } WINPROC_JUMP;
72 typedef union
74 WINPROC_THUNK_FROM16 t_from16;
75 WINPROC_THUNK_FROM32 t_from32;
76 } WINPROC_THUNK;
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 */
86 } WINDOWPROC;
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,
97 LPARAM lParam );
98 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
99 UINT msg, WPARAM wParam,
100 LPARAM lParam );
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 /**********************************************************************
108 * WINPROC_Init
110 BOOL WINPROC_Init(void)
112 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
113 if (!WinProcHeap)
115 WARN_(relay)("Unable to create winproc heap\n" );
116 return FALSE;
118 return TRUE;
122 #ifdef __i386__
123 /* Some window procedures modify register they shouldn't, or are not
124 * properly declared stdcall; so we need a small assembly wrapper to
125 * call them. */
126 extern LRESULT WINPROC_wrapper( WNDPROC proc, HWND hwnd, UINT msg,
127 WPARAM wParam, LPARAM lParam );
128 __ASM_GLOBAL_FUNC( WINPROC_wrapper,
129 "pushl %ebp\n\t"
130 "movl %esp,%ebp\n\t"
131 "pushl %edi\n\t"
132 "pushl %esi\n\t"
133 "pushl %ebx\n\t"
134 "pushl 24(%ebp)\n\t"
135 "pushl 20(%ebp)\n\t"
136 "pushl 16(%ebp)\n\t"
137 "pushl 12(%ebp)\n\t"
138 "movl 8(%ebp),%eax\n\t"
139 "call *%eax\n\t"
140 "leal -12(%ebp),%esp\n\t"
141 "popl %ebx\n\t"
142 "popl %esi\n\t"
143 "popl %edi\n\t"
144 "leave\n\t"
145 "ret" );
146 #else
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 )
162 LRESULT retvalue;
163 int iWndsLocks;
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 );
174 return 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,
184 LPARAM lParam )
186 CONTEXT86 context;
187 LRESULT ret;
188 WORD *args;
189 WND *wndPtr = WIN_FindWndPtr( hwnd );
190 DWORD offset = 0;
191 TEB *teb = NtCurrentTeb();
192 int iWndsLocks;
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);
206 if (lParam)
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. */
214 switch (msg)
216 case WM_CREATE:
217 case WM_NCCREATE:
218 offset = sizeof(CREATESTRUCT16); break;
219 case WM_DRAWITEM:
220 offset = sizeof(DRAWITEMSTRUCT16); break;
221 case WM_COMPAREITEM:
222 offset = sizeof(COMPAREITEMSTRUCT16); break;
224 if (offset)
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);
237 args[2] = wParam;
238 args[3] = msg;
239 args[4] = hwnd;
241 wine_call_to_16_regs_short( &context, 5 * sizeof(WORD) );
242 ret = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
243 if (offset) stack16_pop( offset );
245 WIN_RestoreWndsLock(iWndsLocks);
247 return ret;
251 /**********************************************************************
252 * WINPROC_GetPtr
254 * Return a pointer to the win proc.
256 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
258 BYTE *ptr;
259 WINDOWPROC *proc;
261 /* Check for a linear pointer */
263 if (HeapValidate( 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 (!HeapValidate( 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;
289 return NULL;
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 )))
311 *proc = *oldproc;
313 else
315 switch(type)
317 case WIN_PROC_16:
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));
326 break;
327 case WIN_PROC_32A:
328 case WIN_PROC_32W:
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));
346 break;
347 default:
348 /* Should not happen */
349 break;
351 proc->magic = WINPROC_MAGIC;
352 proc->type = type;
353 proc->user = user;
355 proc->next = NULL;
356 TRACE_(win)("(%08x,%d): returning %08x\n",
357 (UINT)func, type, (UINT)proc );
358 return proc;
362 /**********************************************************************
363 * WINPROC_GetProc
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;
374 else
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;
385 else
386 /* Some Win16 programs want to get back the proc they set */
387 return (WNDPROC16)((WINDOWPROC *)proc)->thunk.t_from16.proc;
392 /**********************************************************************
393 * WINPROC_SetProc
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()
400 * / /
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 );
423 while (*ppPrev)
425 if (proc)
427 if (*ppPrev == proc)
429 if ((*ppPrev)->user != user)
431 /* terminal thunk is being restored */
433 WINPROC_FreeProc( *pFirst, (*ppPrev)->user );
434 *(WINDOWPROC **)pFirst = *ppPrev;
435 return TRUE;
437 bRecycle = TRUE;
438 break;
441 else
443 if (((*ppPrev)->type == type) &&
444 (func == WINPROC_THUNKPROC(*ppPrev)))
446 bRecycle = TRUE;
447 break;
451 /* WPF_CLASS thunk terminates window thunk list */
452 if ((*ppPrev)->user != user) break;
453 ppPrev = &(*ppPrev)->next;
456 if (bRecycle)
458 /* Extract this thunk from the list */
459 proc = *ppPrev;
460 *ppPrev = proc->next;
462 else /* Allocate a new one */
464 if (proc) /* Was already a win proc */
466 type = proc->type;
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;
479 return TRUE;
483 /**********************************************************************
484 * WINPROC_FreeProc
486 * Free a list of win procs.
488 void WINPROC_FreeProc( HWINDOWPROC proc, WINDOWPROCUSER user )
490 while (proc)
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 );
496 proc = next;
501 /**********************************************************************
502 * WINPROC_GetProcType
504 * Return the window procedure type.
506 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
508 if (!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 )
520 BOOL retvalue;
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);
525 return retvalue;
527 /**********************************************************************
528 * WINPROC_TestLBForStr
530 * Return TRUE if the lparam is a string
532 static BOOL WINPROC_TestLBForStr ( HWND hwnd )
534 BOOL retvalue;
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);
539 return retvalue;
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.
548 * FIXME:
549 * WM_CHARTOITEM, WM_MENUCHAR
551 * FIXME:
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 )
558 switch(msg)
560 case WM_GETTEXT:
562 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
563 *pwparam * sizeof(WCHAR) + sizeof(LPARAM) );
564 if (!ptr) return -1;
565 *ptr++ = *plparam; /* Store previous lParam */
566 *plparam = (LPARAM)ptr;
568 return 1;
569 /* lparam is string (0-terminated) */
570 case WM_SETTEXT:
571 case WM_WININICHANGE:
572 case CB_DIR:
573 case CB_FINDSTRING:
574 case CB_FINDSTRINGEXACT:
575 case CB_SELECTSTRING:
576 case LB_DIR:
577 case LB_ADDFILE:
578 case LB_FINDSTRING:
579 case LB_SELECTSTRING:
580 case EM_REPLACESEL:
581 *plparam = (LPARAM)HEAP_strdupAtoW( GetProcessHeap(), 0, (LPCSTR)*plparam );
582 return (*plparam ? 1 : -1);
584 case WM_NCCREATE:
585 case WM_CREATE:
587 struct s
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));
594 if (!xs) return -1;
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;
604 return 1;
605 case WM_MDICREATE:
607 MDICREATESTRUCTW *cs =
608 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
609 if (!cs) return -1;
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;
619 return 1;
621 /* Listbox */
622 case LB_ADDSTRING:
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) );
631 if (!ptr) return -1;
632 *ptr++ = *plparam; /* Store previous lParam */
633 *plparam = (LPARAM)ptr;
636 return 1;
638 /* Combobox */
639 case CB_ADDSTRING:
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) );
648 if (!ptr) return -1;
649 *ptr++ = *plparam; /* Store previous lParam */
650 *plparam = (LPARAM)ptr;
653 return 1;
655 /* Multiline edit */
656 case EM_GETLINE:
657 { WORD len = (WORD)*plparam;
658 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(WCHAR) );
659 if (!ptr) return -1;
660 *ptr++ = *plparam; /* Store previous lParam */
661 *((WORD *) ptr) = len; /* Store the length */
662 *plparam = (LPARAM)ptr;
664 return 1;
666 case WM_CHAR:
667 case WM_DEADCHAR:
668 case WM_SYSCHAR:
669 case WM_SYSDEADCHAR:
671 char ch = *pwparam;
672 WCHAR wch;
673 MultiByteToWideChar(CP_ACP, 0, &ch, 1, &wch, 1);
674 *pwparam = wch;
676 return 0;
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 );
684 return -1;
685 default: /* No translation needed */
686 return 0;
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 )
698 switch(msg)
700 case WM_GETTEXT:
702 LPARAM *ptr = (LPARAM *)lParam - 1;
703 if (wParam > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
704 (LPSTR)*ptr, wParam, NULL, NULL ))
705 ((LPSTR)*ptr)[wParam-1] = 0;
706 HeapFree( GetProcessHeap(), 0, ptr );
708 break;
710 case WM_NCCREATE:
711 case WM_CREATE:
713 struct s
714 { CREATESTRUCTW cs; /* new structure */
715 LPWSTR lpszName; /* allocated Name */
716 LPWSTR lpszClass; /* allocated Class */
718 struct s *xs = (struct s *)lParam;
719 if (xs->lpszName) HeapFree( GetProcessHeap(), 0, xs->lpszName );
720 if (xs->lpszClass) HeapFree( GetProcessHeap(), 0, xs->lpszClass );
721 HeapFree( GetProcessHeap(), 0, xs );
723 break;
725 case WM_MDICREATE:
727 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
728 if (HIWORD(cs->szTitle))
729 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
730 if (HIWORD(cs->szClass))
731 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
732 HeapFree( GetProcessHeap(), 0, cs );
734 break;
736 case WM_SETTEXT:
737 case WM_WININICHANGE:
738 case CB_DIR:
739 case CB_FINDSTRING:
740 case CB_FINDSTRINGEXACT:
741 case CB_SELECTSTRING:
742 case LB_DIR:
743 case LB_ADDFILE:
744 case LB_FINDSTRING:
745 case LB_SELECTSTRING:
746 case EM_REPLACESEL:
747 HeapFree( GetProcessHeap(), 0, (void *)lParam );
748 break;
750 /* Listbox */
751 case LB_ADDSTRING:
752 case LB_INSERTSTRING:
753 if ( WINPROC_TestLBForStr( hwnd ))
754 HeapFree( GetProcessHeap(), 0, (void *)lParam );
755 break;
757 case LB_GETTEXT:
758 { if ( WINPROC_TestLBForStr( hwnd ))
759 { LPARAM *ptr = (LPARAM *)lParam - 1;
760 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
761 HeapFree( GetProcessHeap(), 0, ptr );
764 break;
766 /* Combobox */
767 case CB_ADDSTRING:
768 case CB_INSERTSTRING:
769 if ( WINPROC_TestCBForStr( hwnd ))
770 HeapFree( GetProcessHeap(), 0, (void *)lParam );
771 break;
773 case CB_GETLBTEXT:
774 { if ( WINPROC_TestCBForStr( hwnd ))
775 { LPARAM *ptr = (LPARAM *)lParam - 1;
776 WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1, (LPSTR)*ptr, 0x7fffffff, NULL, NULL );
777 HeapFree( GetProcessHeap(), 0, ptr );
780 break;
782 /* Multiline edit */
783 case EM_GETLINE:
784 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lParam */
785 WORD len = *(WORD *) lParam;
786 if (len > 0 && !WideCharToMultiByte( CP_ACP, 0, (LPWSTR)lParam, -1,
787 (LPSTR)*ptr, len, NULL, NULL ))
788 ((LPSTR)*ptr)[len-1] = 0;
789 HeapFree( GetProcessHeap(), 0, ptr );
791 break;
796 /**********************************************************************
797 * WINPROC_MapMsg32WTo32A
799 * Map a message from Unicode to Ansi.
800 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
802 INT WINPROC_MapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM *pwparam, LPARAM *plparam )
804 switch(msg)
806 case WM_GETTEXT:
808 LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0,
809 *pwparam + sizeof(LPARAM) );
810 if (!ptr) return -1;
811 *ptr++ = *plparam; /* Store previous lParam */
812 *plparam = (LPARAM)ptr;
814 return 1;
816 case WM_SETTEXT:
817 case WM_WININICHANGE:
818 case CB_DIR:
819 case CB_FINDSTRING:
820 case CB_FINDSTRINGEXACT:
821 case CB_SELECTSTRING:
822 case LB_DIR:
823 case LB_ADDFILE:
824 case LB_FINDSTRING:
825 case LB_SELECTSTRING:
826 case EM_REPLACESEL:
827 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
828 return (*plparam ? 1 : -1);
830 case WM_NCCREATE:
831 case WM_CREATE:
833 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
834 sizeof(*cs) );
835 if (!cs) return -1;
836 *cs = *(CREATESTRUCTA *)*plparam;
837 if (HIWORD(cs->lpszName))
838 cs->lpszName = HEAP_strdupWtoA( GetProcessHeap(), 0,
839 (LPCWSTR)cs->lpszName );
840 if (HIWORD(cs->lpszClass))
841 cs->lpszClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
842 (LPCWSTR)cs->lpszClass);
843 *plparam = (LPARAM)cs;
845 return 1;
846 case WM_MDICREATE:
848 MDICREATESTRUCTA *cs =
849 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs) );
850 if (!cs) return -1;
851 *cs = *(MDICREATESTRUCTA *)*plparam;
852 if (HIWORD(cs->szTitle))
853 cs->szTitle = HEAP_strdupWtoA( GetProcessHeap(), 0,
854 (LPCWSTR)cs->szTitle );
855 if (HIWORD(cs->szClass))
856 cs->szClass = HEAP_strdupWtoA( GetProcessHeap(), 0,
857 (LPCWSTR)cs->szClass );
858 *plparam = (LPARAM)cs;
860 return 1;
862 /* Listbox */
863 case LB_ADDSTRING:
864 case LB_INSERTSTRING:
865 if ( WINPROC_TestLBForStr( hwnd ))
866 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
867 return (*plparam ? 1 : -1);
869 case LB_GETTEXT: /* fixme: fixed sized buffer */
870 { if ( WINPROC_TestLBForStr( hwnd ))
871 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
872 if (!ptr) return -1;
873 *ptr++ = *plparam; /* Store previous lParam */
874 *plparam = (LPARAM)ptr;
877 return 1;
879 /* Combobox */
880 case CB_ADDSTRING:
881 case CB_INSERTSTRING:
882 if ( WINPROC_TestCBForStr( hwnd ))
883 *plparam = (LPARAM)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR)*plparam );
884 return (*plparam ? 1 : -1);
886 case CB_GETLBTEXT: /* fixme: fixed sized buffer */
887 { if ( WINPROC_TestCBForStr( hwnd ))
888 { LPARAM *ptr = (LPARAM *)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM) );
889 if (!ptr) return -1;
890 *ptr++ = *plparam; /* Store previous lParam */
891 *plparam = (LPARAM)ptr;
894 return 1;
896 /* Multiline edit */
897 case EM_GETLINE:
898 { WORD len = (WORD)*plparam;
899 LPARAM *ptr = (LPARAM *) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM) + sizeof (WORD) + len*sizeof(CHAR) );
900 if (!ptr) return -1;
901 *ptr++ = *plparam; /* Store previous lParam */
902 *((WORD *) ptr) = len; /* Store the length */
903 *plparam = (LPARAM)ptr;
905 return 1;
907 case WM_CHAR:
908 case WM_DEADCHAR:
909 case WM_SYSCHAR:
910 case WM_SYSDEADCHAR:
912 WCHAR wch = *pwparam;
913 char ch;
914 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL );
915 *pwparam = ch;
917 return 0;
919 case WM_ASKCBFORMATNAME:
920 case WM_DEVMODECHANGE:
921 case WM_PAINTCLIPBOARD:
922 case WM_SIZECLIPBOARD:
923 case EM_SETPASSWORDCHAR:
924 FIXME_(msg)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg),msg );
925 return -1;
926 default: /* No translation needed */
927 return 0;
932 /**********************************************************************
933 * WINPROC_UnmapMsg32WTo32A
935 * Unmap a message that was mapped from Unicode to Ansi.
937 void WINPROC_UnmapMsg32WTo32A( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam )
939 switch(msg)
941 case WM_GETTEXT:
943 LPARAM *ptr = (LPARAM *)lParam - 1;
944 if (wParam)
946 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, wParam ))
947 ((LPWSTR)*ptr)[wParam-1] = 0;
949 HeapFree( GetProcessHeap(), 0, ptr );
951 break;
953 case WM_SETTEXT:
954 case WM_WININICHANGE:
955 case CB_DIR:
956 case CB_FINDSTRING:
957 case CB_FINDSTRINGEXACT:
958 case CB_SELECTSTRING:
959 case LB_DIR:
960 case LB_ADDFILE:
961 case LB_FINDSTRING:
962 case LB_SELECTSTRING:
963 case EM_REPLACESEL:
964 HeapFree( GetProcessHeap(), 0, (void *)lParam );
965 break;
967 case WM_NCCREATE:
968 case WM_CREATE:
970 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
971 if (HIWORD(cs->lpszName))
972 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
973 if (HIWORD(cs->lpszClass))
974 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
975 HeapFree( GetProcessHeap(), 0, cs );
977 break;
979 case WM_MDICREATE:
981 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
982 if (HIWORD(cs->szTitle))
983 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
984 if (HIWORD(cs->szClass))
985 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
986 HeapFree( GetProcessHeap(), 0, cs );
988 break;
990 /* Listbox */
991 case LB_ADDSTRING:
992 case LB_INSERTSTRING:
993 if ( WINPROC_TestLBForStr( hwnd ))
994 HeapFree( GetProcessHeap(), 0, (void *)lParam );
995 break;
997 case LB_GETTEXT:
998 if ( WINPROC_TestLBForStr( hwnd ))
1000 LPARAM *ptr = (LPARAM *)lParam - 1;
1001 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1002 HeapFree( GetProcessHeap(), 0, ptr );
1004 break;
1006 /* Combobox */
1007 case CB_ADDSTRING:
1008 case CB_INSERTSTRING:
1009 if ( WINPROC_TestCBForStr( hwnd ))
1010 HeapFree( GetProcessHeap(), 0, (void *)lParam );
1011 break;
1013 case CB_GETLBTEXT:
1014 if ( WINPROC_TestCBForStr( hwnd ))
1016 LPARAM *ptr = (LPARAM *)lParam - 1;
1017 MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, 0x7fffffff );
1018 HeapFree( GetProcessHeap(), 0, ptr );
1020 break;
1022 /* Multiline edit */
1023 case EM_GETLINE:
1024 { LPARAM * ptr = (LPARAM *)lParam - 1; /* get the old lparam */
1025 WORD len = *(WORD *)ptr;
1026 if (len)
1028 if (!MultiByteToWideChar( CP_ACP, 0, (LPSTR)lParam, -1, (LPWSTR)*ptr, len ))
1029 ((LPWSTR)*ptr)[len-1] = 0;
1031 HeapFree( GetProcessHeap(), 0, ptr );
1033 break;
1038 /**********************************************************************
1039 * WINPROC_MapMsg16To32A
1041 * Map a message from 16- to 32-bit Ansi.
1042 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1044 INT WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1045 WPARAM *pwparam32, LPARAM *plparam )
1047 *pmsg32 = (UINT)msg16;
1048 *pwparam32 = (WPARAM)wParam16;
1049 switch(msg16)
1051 case WM_ACTIVATE:
1052 case WM_CHARTOITEM:
1053 case WM_COMMAND:
1054 case WM_VKEYTOITEM:
1055 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1056 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1057 return 0;
1058 case WM_HSCROLL:
1059 case WM_VSCROLL:
1060 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1061 *plparam = (LPARAM)(HWND)HIWORD(*plparam);
1062 return 0;
1063 case WM_CTLCOLOR:
1064 if ( HIWORD(*plparam) > CTLCOLOR_STATIC ) return -1;
1065 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
1066 *pwparam32 = (WPARAM)(HDC)wParam16;
1067 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1068 return 0;
1069 case WM_COMPAREITEM:
1071 COMPAREITEMSTRUCT16* cis16 = (COMPAREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1072 COMPAREITEMSTRUCT *cis = (COMPAREITEMSTRUCT *)
1073 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis));
1074 if (!cis) return -1;
1075 cis->CtlType = cis16->CtlType;
1076 cis->CtlID = cis16->CtlID;
1077 cis->hwndItem = cis16->hwndItem;
1078 cis->itemID1 = cis16->itemID1;
1079 cis->itemData1 = cis16->itemData1;
1080 cis->itemID2 = cis16->itemID2;
1081 cis->itemData2 = cis16->itemData2;
1082 cis->dwLocaleId = 0; /* FIXME */
1083 *plparam = (LPARAM)cis;
1085 return 1;
1086 case WM_DELETEITEM:
1088 DELETEITEMSTRUCT16* dis16 = (DELETEITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1089 DELETEITEMSTRUCT *dis = (DELETEITEMSTRUCT *)
1090 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis));
1091 if (!dis) return -1;
1092 dis->CtlType = dis16->CtlType;
1093 dis->CtlID = dis16->CtlID;
1094 dis->hwndItem = dis16->hwndItem;
1095 dis->itemData = dis16->itemData;
1096 *plparam = (LPARAM)dis;
1098 return 1;
1099 case WM_MEASUREITEM:
1101 MEASUREITEMSTRUCT16* mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1102 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)
1103 HeapAlloc(GetProcessHeap(), 0,
1104 sizeof(*mis) + sizeof(LPARAM));
1105 if (!mis) return -1;
1106 mis->CtlType = mis16->CtlType;
1107 mis->CtlID = mis16->CtlID;
1108 mis->itemID = mis16->itemID;
1109 mis->itemWidth = mis16->itemWidth;
1110 mis->itemHeight = mis16->itemHeight;
1111 mis->itemData = mis16->itemData;
1112 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1113 *plparam = (LPARAM)mis;
1115 return 1;
1116 case WM_DRAWITEM:
1118 DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1119 DRAWITEMSTRUCT *dis = (DRAWITEMSTRUCT*)HeapAlloc(GetProcessHeap(), 0,
1120 sizeof(*dis));
1121 if (!dis) return -1;
1122 dis->CtlType = dis16->CtlType;
1123 dis->CtlID = dis16->CtlID;
1124 dis->itemID = dis16->itemID;
1125 dis->itemAction = dis16->itemAction;
1126 dis->itemState = dis16->itemState;
1127 dis->hwndItem = dis16->hwndItem;
1128 dis->hDC = dis16->hDC;
1129 dis->itemData = dis16->itemData;
1130 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
1131 *plparam = (LPARAM)dis;
1133 return 1;
1134 case WM_GETMINMAXINFO:
1136 MINMAXINFO *mmi = (MINMAXINFO *)HeapAlloc( GetProcessHeap(), 0,
1137 sizeof(*mmi) + sizeof(LPARAM));
1138 if (!mmi) return -1;
1139 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16*)PTR_SEG_TO_LIN(*plparam),
1140 mmi );
1141 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1142 *plparam = (LPARAM)mmi;
1144 return 1;
1145 case WM_GETTEXT:
1146 case WM_SETTEXT:
1147 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1148 return 0;
1149 case WM_MDICREATE:
1151 MDICREATESTRUCT16 *cs16 =
1152 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1153 MDICREATESTRUCTA *cs =
1154 (MDICREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1155 sizeof(*cs) + sizeof(LPARAM) );
1156 if (!cs) return -1;
1157 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
1158 cs->szTitle = (LPCSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1159 cs->szClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->szClass);
1160 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1161 *plparam = (LPARAM)cs;
1163 return 1;
1164 case WM_MDIGETACTIVE:
1165 *plparam = (LPARAM)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL) );
1166 *(BOOL*)(*plparam) = 0;
1167 return 1;
1168 case WM_MDISETMENU:
1169 if(wParam16==TRUE)
1170 *pmsg32=WM_MDIREFRESHMENU;
1171 *pwparam32 = (WPARAM)(HMENU)LOWORD(*plparam);
1172 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1173 return 0;
1174 case WM_MENUCHAR:
1175 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1176 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1177 return 0;
1178 case WM_MENUSELECT:
1179 if((LOWORD(*plparam) & MF_POPUP) && (LOWORD(*plparam) != 0xFFFF))
1181 HMENU hmenu=(HMENU)HIWORD(*plparam);
1182 UINT Pos=MENU_FindSubMenu( &hmenu, wParam16);
1183 if(Pos==0xFFFF) Pos=0; /* NO_SELECTED_ITEM */
1184 *pwparam32 = MAKEWPARAM( Pos, LOWORD(*plparam) );
1186 else *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
1187 *plparam = (LPARAM)(HMENU)HIWORD(*plparam);
1188 return 0;
1189 case WM_MDIACTIVATE:
1190 if( *plparam )
1192 *pwparam32 = (WPARAM)(HWND)HIWORD(*plparam);
1193 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1195 else /* message sent to MDI client */
1196 *pwparam32 = wParam16;
1197 return 0;
1198 case WM_NCCALCSIZE:
1200 NCCALCSIZE_PARAMS16 *nc16;
1201 NCCALCSIZE_PARAMS *nc;
1203 nc = (NCCALCSIZE_PARAMS *)HeapAlloc( GetProcessHeap(), 0,
1204 sizeof(*nc) + sizeof(LPARAM) );
1205 if (!nc) return -1;
1206 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(*plparam);
1207 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
1208 if (wParam16)
1210 nc->lppos = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1211 sizeof(*nc->lppos) );
1212 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
1213 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
1214 if (nc->lppos) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos), nc->lppos );
1216 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1217 *plparam = (LPARAM)nc;
1219 return 1;
1220 case WM_NCCREATE:
1221 case WM_CREATE:
1223 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1224 CREATESTRUCTA *cs = (CREATESTRUCTA *)HeapAlloc( GetProcessHeap(), 0,
1225 sizeof(*cs) + sizeof(LPARAM) );
1226 if (!cs) return -1;
1227 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
1228 cs->lpszName = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1229 cs->lpszClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1230 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1231 *plparam = (LPARAM)cs;
1233 return 1;
1234 case WM_PARENTNOTIFY:
1235 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
1237 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
1238 *plparam = (LPARAM)(HWND)LOWORD(*plparam);
1240 return 0;
1241 case WM_WINDOWPOSCHANGING:
1242 case WM_WINDOWPOSCHANGED:
1244 WINDOWPOS *wp = (WINDOWPOS *)HeapAlloc( GetProcessHeap(), 0,
1245 sizeof(*wp) + sizeof(LPARAM) );
1246 if (!wp) return -1;
1247 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(*plparam),
1248 wp );
1249 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1250 *plparam = (LPARAM)wp;
1252 return 1;
1253 case WM_GETDLGCODE:
1254 if (*plparam)
1256 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
1257 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1259 if (!msg32) return -1;
1260 msg32->hwnd = msg16->hwnd;
1261 msg32->lParam = msg16->lParam;
1262 msg32->time = msg16->time;
1263 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1264 /* this is right, right? */
1265 if (WINPROC_MapMsg16To32A(msg16->message,msg16->wParam,
1266 &msg32->message,&msg32->wParam,
1267 &msg32->lParam)<0) {
1268 HeapFree( GetProcessHeap(), 0, msg32 );
1269 return -1;
1271 *plparam = (LPARAM)msg32;
1272 return 1;
1274 else return 0;
1275 case WM_NOTIFY:
1276 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1277 return 1;
1278 case WM_ACTIVATEAPP:
1279 if (*plparam)
1280 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1281 a 32bit window. Might be superflous with 32bit interprocess
1282 message queues.
1284 HTASK16 htask = (HTASK16) *plparam;
1285 DWORD idThread = (DWORD)((TDB*)GlobalLock16(htask))->teb->tid;
1286 *plparam = (LPARAM) idThread;
1288 return 1;
1289 case WM_ASKCBFORMATNAME:
1290 case WM_DEVMODECHANGE:
1291 case WM_PAINTCLIPBOARD:
1292 case WM_SIZECLIPBOARD:
1293 case WM_WININICHANGE:
1294 FIXME_(msg)("message %04x needs translation\n",msg16 );
1295 return -1;
1297 default: /* No translation needed */
1298 return 0;
1303 /**********************************************************************
1304 * WINPROC_UnmapMsg16To32A
1306 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1308 LRESULT WINPROC_UnmapMsg16To32A( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1309 LRESULT result )
1311 switch(msg)
1313 case WM_COMPAREITEM:
1314 case WM_DELETEITEM:
1315 case WM_DRAWITEM:
1316 HeapFree( GetProcessHeap(), 0, (LPVOID)lParam );
1317 break;
1318 case WM_MEASUREITEM:
1320 MEASUREITEMSTRUCT16 *mis16;
1321 MEASUREITEMSTRUCT *mis = (MEASUREITEMSTRUCT *)lParam;
1322 lParam = *(LPARAM *)(mis + 1);
1323 mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1324 mis16->itemWidth = (UINT16)mis->itemWidth;
1325 mis16->itemHeight = (UINT16)mis->itemHeight;
1326 HeapFree( GetProcessHeap(), 0, mis );
1328 break;
1329 case WM_GETMINMAXINFO:
1331 MINMAXINFO *mmi = (MINMAXINFO *)lParam;
1332 lParam = *(LPARAM *)(mmi + 1);
1333 STRUCT32_MINMAXINFO32to16( mmi,
1334 (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
1335 HeapFree( GetProcessHeap(), 0, mmi );
1337 break;
1338 case WM_MDICREATE:
1340 MDICREATESTRUCTA *cs = (MDICREATESTRUCTA *)lParam;
1341 lParam = *(LPARAM *)(cs + 1);
1342 STRUCT32_MDICREATESTRUCT32Ato16( cs,
1343 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1344 HeapFree( GetProcessHeap(), 0, cs );
1346 break;
1347 case WM_MDIGETACTIVE:
1348 result = MAKELONG( LOWORD(result), (BOOL16)(*(BOOL *)lParam) );
1349 HeapFree( GetProcessHeap(), 0, (BOOL *)lParam );
1350 break;
1351 case WM_NCCALCSIZE:
1353 NCCALCSIZE_PARAMS16 *nc16;
1354 NCCALCSIZE_PARAMS *nc = (NCCALCSIZE_PARAMS *)lParam;
1355 lParam = *(LPARAM *)(nc + 1);
1356 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
1357 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
1358 if (wParam)
1360 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
1361 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
1362 if (nc->lppos)
1364 STRUCT32_WINDOWPOS32to16( nc->lppos,
1365 (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos));
1366 HeapFree( GetProcessHeap(), 0, nc->lppos );
1369 HeapFree( GetProcessHeap(), 0, nc );
1371 break;
1372 case WM_NCCREATE:
1373 case WM_CREATE:
1375 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
1376 lParam = *(LPARAM *)(cs + 1);
1377 STRUCT32_CREATESTRUCT32Ato16( cs,
1378 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1379 HeapFree( GetProcessHeap(), 0, cs );
1381 break;
1382 case WM_WINDOWPOSCHANGING:
1383 case WM_WINDOWPOSCHANGED:
1385 WINDOWPOS *wp = (WINDOWPOS *)lParam;
1386 lParam = *(LPARAM *)(wp + 1);
1387 STRUCT32_WINDOWPOS32to16(wp,(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam));
1388 HeapFree( GetProcessHeap(), 0, wp );
1390 break;
1391 case WM_GETDLGCODE:
1392 if (lParam)
1394 LPMSG msg32 = (LPMSG)lParam;
1396 WINPROC_UnmapMsg16To32A( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1397 result);
1398 HeapFree( GetProcessHeap(), 0, msg32 );
1400 break;
1402 return result;
1406 /**********************************************************************
1407 * WINPROC_MapMsg16To32W
1409 * Map a message from 16- to 32-bit Unicode.
1410 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1412 INT WINPROC_MapMsg16To32W( HWND16 hwnd, UINT16 msg16, WPARAM16 wParam16, UINT *pmsg32,
1413 WPARAM *pwparam32, LPARAM *plparam )
1415 switch(msg16)
1417 case WM_GETTEXT:
1418 case WM_SETTEXT:
1419 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
1420 return WINPROC_MapMsg32ATo32W( hwnd, *pmsg32, pwparam32, plparam );
1421 case WM_NCCREATE:
1422 case WM_CREATE:
1424 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1425 CREATESTRUCTW *cs = (CREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1426 sizeof(*cs) + sizeof(LPARAM) );
1427 if (!cs) return -1;
1428 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCTA *)cs );
1429 cs->lpszName = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
1430 cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
1431 if (HIWORD(cs->lpszName))
1432 cs->lpszName = HEAP_strdupAtoW( GetProcessHeap(), 0,
1433 (LPCSTR)cs->lpszName );
1434 if (HIWORD(cs->lpszClass))
1435 cs->lpszClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1436 (LPCSTR)cs->lpszClass );
1437 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1438 *plparam = (LPARAM)cs;
1440 return 1;
1441 case WM_MDICREATE:
1443 MDICREATESTRUCT16 *cs16 =
1444 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
1445 MDICREATESTRUCTW *cs =
1446 (MDICREATESTRUCTW *)HeapAlloc( GetProcessHeap(), 0,
1447 sizeof(*cs) + sizeof(LPARAM) );
1448 if (!cs) return -1;
1449 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCTA *)cs );
1450 cs->szTitle = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szTitle);
1451 cs->szClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szClass);
1452 if (HIWORD(cs->szTitle))
1453 cs->szTitle = HEAP_strdupAtoW( GetProcessHeap(), 0,
1454 (LPCSTR)cs->szTitle );
1455 if (HIWORD(cs->szClass))
1456 cs->szClass = HEAP_strdupAtoW( GetProcessHeap(), 0,
1457 (LPCSTR)cs->szClass );
1458 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
1459 *plparam = (LPARAM)cs;
1461 return 1;
1462 case WM_GETDLGCODE:
1463 if (*plparam)
1465 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(*plparam);
1466 LPMSG msg32 = (LPMSG)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG) );
1468 if (!msg32) return -1;
1469 msg32->hwnd = msg16->hwnd;
1470 msg32->lParam = msg16->lParam;
1471 msg32->time = msg16->time;
1472 CONV_POINT16TO32(&msg16->pt,&msg32->pt);
1473 /* this is right, right? */
1474 if (WINPROC_MapMsg16To32W(hwnd, msg16->message,msg16->wParam,
1475 &msg32->message,&msg32->wParam,
1476 &msg32->lParam)<0) {
1477 HeapFree( GetProcessHeap(), 0, msg32 );
1478 return -1;
1480 *plparam = (LPARAM)msg32;
1481 return 1;
1483 else return 0;
1485 case WM_CHAR:
1486 case WM_DEADCHAR:
1487 case WM_SYSCHAR:
1488 case WM_SYSDEADCHAR:
1490 char ch = wParam16;
1491 WCHAR wch;
1492 MultiByteToWideChar( CP_ACP, 0, &ch, 1, &wch, 1);
1493 *pwparam32 = wch;
1495 return 0;
1497 default: /* No Unicode translation needed */
1498 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
1499 pwparam32, plparam );
1504 /**********************************************************************
1505 * WINPROC_UnmapMsg16To32W
1507 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1509 LRESULT WINPROC_UnmapMsg16To32W( HWND16 hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
1510 LRESULT result )
1512 switch(msg)
1514 case WM_GETTEXT:
1515 case WM_SETTEXT:
1516 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
1517 break;
1518 case WM_NCCREATE:
1519 case WM_CREATE:
1521 CREATESTRUCTW *cs = (CREATESTRUCTW *)lParam;
1522 lParam = *(LPARAM *)(cs + 1);
1523 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs,
1524 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1525 if (HIWORD(cs->lpszName))
1526 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszName );
1527 if (HIWORD(cs->lpszClass))
1528 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->lpszClass );
1529 HeapFree( GetProcessHeap(), 0, cs );
1531 break;
1532 case WM_MDICREATE:
1534 MDICREATESTRUCTW *cs = (MDICREATESTRUCTW *)lParam;
1535 lParam = *(LPARAM *)(cs + 1);
1536 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs,
1537 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
1538 if (HIWORD(cs->szTitle))
1539 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szTitle );
1540 if (HIWORD(cs->szClass))
1541 HeapFree( GetProcessHeap(), 0, (LPVOID)cs->szClass );
1542 HeapFree( GetProcessHeap(), 0, cs );
1544 break;
1545 case WM_GETDLGCODE:
1546 if (lParam)
1548 LPMSG msg32 = (LPMSG)lParam;
1550 WINPROC_UnmapMsg16To32W( hwnd, msg32->message, msg32->wParam, msg32->lParam,
1551 result);
1552 HeapFree( GetProcessHeap(), 0, msg32 );
1554 break;
1555 default:
1556 return WINPROC_UnmapMsg16To32A( hwnd, msg, wParam, lParam, result );
1558 return result;
1562 /**********************************************************************
1563 * WINPROC_MapMsg32ATo16
1565 * Map a message from 32-bit Ansi to 16-bit.
1566 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1568 INT WINPROC_MapMsg32ATo16( HWND hwnd, UINT msg32, WPARAM wParam32,
1569 UINT16 *pmsg16, WPARAM16 *pwparam16,
1570 LPARAM *plparam )
1572 *pmsg16 = (UINT16)msg32;
1573 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1574 switch(msg32)
1576 case BM_GETCHECK:
1577 case BM_SETCHECK:
1578 case BM_GETSTATE:
1579 case BM_SETSTATE:
1580 case BM_SETSTYLE:
1581 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK);
1582 return 0;
1584 case EM_GETSEL:
1585 case EM_GETRECT:
1586 case EM_SETRECT:
1587 case EM_SETRECTNP:
1588 case EM_SCROLL:
1589 case EM_LINESCROLL:
1590 case EM_SCROLLCARET:
1591 case EM_GETMODIFY:
1592 case EM_SETMODIFY:
1593 case EM_GETLINECOUNT:
1594 case EM_LINEINDEX:
1595 case EM_SETHANDLE:
1596 case EM_GETHANDLE:
1597 case EM_GETTHUMB:
1598 case EM_LINELENGTH:
1599 case EM_REPLACESEL:
1600 case EM_GETLINE:
1601 case EM_LIMITTEXT:
1602 case EM_CANUNDO:
1603 case EM_UNDO:
1604 case EM_FMTLINES:
1605 case EM_LINEFROMCHAR:
1606 case EM_SETTABSTOPS:
1607 case EM_SETPASSWORDCHAR:
1608 case EM_EMPTYUNDOBUFFER:
1609 case EM_GETFIRSTVISIBLELINE:
1610 case EM_SETREADONLY:
1611 case EM_SETWORDBREAKPROC:
1612 case EM_GETWORDBREAKPROC:
1613 case EM_GETPASSWORDCHAR:
1614 *pmsg16 = (UINT16)msg32 + (EM_GETSEL16 - EM_GETSEL);
1615 return 0;
1617 case LB_CARETOFF:
1618 case LB_CARETON:
1619 case LB_DELETESTRING:
1620 case LB_GETANCHORINDEX:
1621 case LB_GETCARETINDEX:
1622 case LB_GETCOUNT:
1623 case LB_GETCURSEL:
1624 case LB_GETHORIZONTALEXTENT:
1625 case LB_GETITEMDATA:
1626 case LB_GETITEMHEIGHT:
1627 case LB_GETSEL:
1628 case LB_GETSELCOUNT:
1629 case LB_GETTEXTLEN:
1630 case LB_GETTOPINDEX:
1631 case LB_RESETCONTENT:
1632 case LB_SELITEMRANGE:
1633 case LB_SELITEMRANGEEX:
1634 case LB_SETANCHORINDEX:
1635 case LB_SETCARETINDEX:
1636 case LB_SETCOLUMNWIDTH:
1637 case LB_SETCURSEL:
1638 case LB_SETHORIZONTALEXTENT:
1639 case LB_SETITEMDATA:
1640 case LB_SETITEMHEIGHT:
1641 case LB_SETSEL:
1642 case LB_SETTOPINDEX:
1643 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1644 return 0;
1645 case CB_DELETESTRING:
1646 case CB_GETCOUNT:
1647 case CB_GETLBTEXTLEN:
1648 case CB_LIMITTEXT:
1649 case CB_RESETCONTENT:
1650 case CB_SETEDITSEL:
1651 case CB_GETCURSEL:
1652 case CB_SETCURSEL:
1653 case CB_SHOWDROPDOWN:
1654 case CB_SETITEMDATA:
1655 case CB_SETITEMHEIGHT:
1656 case CB_GETITEMHEIGHT:
1657 case CB_SETEXTENDEDUI:
1658 case CB_GETEXTENDEDUI:
1659 case CB_GETDROPPEDSTATE:
1660 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1661 return 0;
1662 case CB_GETEDITSEL:
1663 *pmsg16 = CB_GETEDITSEL16;
1664 return 1;
1666 case LB_ADDSTRING:
1667 case LB_FINDSTRING:
1668 case LB_FINDSTRINGEXACT:
1669 case LB_INSERTSTRING:
1670 case LB_SELECTSTRING:
1671 case LB_DIR:
1672 case LB_ADDFILE:
1674 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1675 if (!str) return -1;
1676 *plparam = (LPARAM)SEGPTR_GET(str);
1678 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
1679 return 1;
1681 case CB_ADDSTRING:
1682 case CB_FINDSTRING:
1683 case CB_FINDSTRINGEXACT:
1684 case CB_INSERTSTRING:
1685 case CB_SELECTSTRING:
1686 case CB_DIR:
1688 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1689 if (!str) return -1;
1690 *plparam = (LPARAM)SEGPTR_GET(str);
1692 *pmsg16 = (UINT16)msg32 + (CB_GETEDITSEL16 - CB_GETEDITSEL);
1693 return 1;
1695 case LB_GETITEMRECT:
1697 RECT16 *rect;
1698 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1699 if (!rect) return -1;
1700 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1701 *plparam = (LPARAM)SEGPTR_GET(rect);
1703 *pmsg16 = LB_GETITEMRECT16;
1704 return 1;
1705 case LB_GETSELITEMS:
1707 LPINT16 items;
1708 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1709 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1710 + sizeof(LPARAM)))) return -1;
1711 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1712 *plparam = (LPARAM)SEGPTR_GET(items);
1714 *pmsg16 = LB_GETSELITEMS16;
1715 return 1;
1716 case LB_SETTABSTOPS:
1717 if (wParam32)
1719 INT i;
1720 LPINT16 stops;
1721 *pwparam16 = (WPARAM16)min( wParam32, 0x7f80 ); /* Must be < 64K */
1722 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1723 + sizeof(LPARAM)))) return -1;
1724 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT)*plparam+i);
1725 *plparam = (LPARAM)SEGPTR_GET(stops);
1726 return 1;
1728 *pmsg16 = LB_SETTABSTOPS16;
1729 return 0;
1731 case CB_GETDROPPEDCONTROLRECT:
1733 RECT16 *rect;
1734 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1735 if (!rect) return -1;
1736 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1737 *plparam = (LPARAM)SEGPTR_GET(rect);
1739 *pmsg16 = CB_GETDROPPEDCONTROLRECT16;
1740 return 1;
1742 case LB_GETTEXT:
1743 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1744 *pmsg16 = LB_GETTEXT16;
1745 return 1;
1747 case CB_GETLBTEXT:
1748 *plparam = (LPARAM)MapLS( (LPVOID)(*plparam) );
1749 *pmsg16 = CB_GETLBTEXT16;
1750 return 1;
1752 case EM_SETSEL:
1753 *pwparam16 = 0;
1754 *plparam = MAKELONG( (INT16)(INT)wParam32, (INT16)*plparam );
1755 *pmsg16 = EM_SETSEL16;
1756 return 0;
1758 case WM_ACTIVATE:
1759 case WM_CHARTOITEM:
1760 case WM_COMMAND:
1761 case WM_VKEYTOITEM:
1762 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1763 return 0;
1764 case WM_HSCROLL:
1765 case WM_VSCROLL:
1766 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1767 return 0;
1768 case WM_CTLCOLORMSGBOX:
1769 case WM_CTLCOLOREDIT:
1770 case WM_CTLCOLORLISTBOX:
1771 case WM_CTLCOLORBTN:
1772 case WM_CTLCOLORDLG:
1773 case WM_CTLCOLORSCROLLBAR:
1774 case WM_CTLCOLORSTATIC:
1775 *pmsg16 = WM_CTLCOLOR;
1776 *plparam = MAKELPARAM( (HWND16)*plparam,
1777 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1778 return 0;
1779 case WM_COMPAREITEM:
1781 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)*plparam;
1782 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1783 if (!cis) return -1;
1784 cis->CtlType = (UINT16)cis32->CtlType;
1785 cis->CtlID = (UINT16)cis32->CtlID;
1786 cis->hwndItem = (HWND16)cis32->hwndItem;
1787 cis->itemID1 = (UINT16)cis32->itemID1;
1788 cis->itemData1 = cis32->itemData1;
1789 cis->itemID2 = (UINT16)cis32->itemID2;
1790 cis->itemData2 = cis32->itemData2;
1791 *plparam = (LPARAM)SEGPTR_GET(cis);
1793 return 1;
1794 case WM_DELETEITEM:
1796 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)*plparam;
1797 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1798 if (!dis) return -1;
1799 dis->CtlType = (UINT16)dis32->CtlType;
1800 dis->CtlID = (UINT16)dis32->CtlID;
1801 dis->itemID = (UINT16)dis32->itemID;
1802 dis->hwndItem = (HWND16)dis32->hwndItem;
1803 dis->itemData = dis32->itemData;
1804 *plparam = (LPARAM)SEGPTR_GET(dis);
1806 return 1;
1807 case WM_DRAWITEM:
1809 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)*plparam;
1810 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1811 if (!dis) return -1;
1812 dis->CtlType = (UINT16)dis32->CtlType;
1813 dis->CtlID = (UINT16)dis32->CtlID;
1814 dis->itemID = (UINT16)dis32->itemID;
1815 dis->itemAction = (UINT16)dis32->itemAction;
1816 dis->itemState = (UINT16)dis32->itemState;
1817 dis->hwndItem = (HWND16)dis32->hwndItem;
1818 dis->hDC = (HDC16)dis32->hDC;
1819 dis->itemData = dis32->itemData;
1820 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1821 *plparam = (LPARAM)SEGPTR_GET(dis);
1823 return 1;
1824 case WM_MEASUREITEM:
1826 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)*plparam;
1827 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1828 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1829 if (!mis) return -1;
1830 mis->CtlType = (UINT16)mis32->CtlType;
1831 mis->CtlID = (UINT16)mis32->CtlID;
1832 mis->itemID = (UINT16)mis32->itemID;
1833 mis->itemWidth = (UINT16)mis32->itemWidth;
1834 mis->itemHeight = (UINT16)mis32->itemHeight;
1835 mis->itemData = mis32->itemData;
1836 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1837 *plparam = (LPARAM)SEGPTR_GET(mis);
1839 return 1;
1840 case WM_GETMINMAXINFO:
1842 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1843 sizeof(LPARAM) );
1844 if (!mmi) return -1;
1845 STRUCT32_MINMAXINFO32to16( (MINMAXINFO *)*plparam, mmi );
1846 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1847 *plparam = (LPARAM)SEGPTR_GET(mmi);
1849 return 1;
1850 case WM_GETTEXT:
1852 LPSTR str;
1853 *pwparam16 = (WPARAM16)min( wParam32, 0xff80 ); /* Must be < 64K */
1854 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1855 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1856 *plparam = (LPARAM)SEGPTR_GET(str);
1858 return 1;
1859 case WM_MDICREATE:
1861 MDICREATESTRUCT16 *cs;
1862 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)*plparam;
1863 LPSTR name, cls;
1865 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1866 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1867 name = SEGPTR_STRDUP( cs32->szTitle );
1868 cls = SEGPTR_STRDUP( cs32->szClass );
1869 cs->szTitle = SEGPTR_GET(name);
1870 cs->szClass = SEGPTR_GET(cls);
1871 *plparam = (LPARAM)SEGPTR_GET(cs);
1873 return 1;
1874 case WM_MDIGETACTIVE:
1875 return 1;
1876 case WM_MDISETMENU:
1877 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1878 (HMENU16)LOWORD(*plparam) );
1879 *pwparam16 = (*plparam == 0);
1880 return 0;
1881 case WM_MENUSELECT:
1882 if(HIWORD(wParam32) & MF_POPUP)
1884 UINT16 hmenu;
1885 if (((UINT)HIWORD(wParam32) != 0xFFFF) || (*plparam))
1887 if((hmenu = GetSubMenu((HMENU16)*plparam, *pwparam16)))
1888 *pwparam16=hmenu;
1891 /* fall through */
1892 case WM_MENUCHAR:
1893 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1894 return 0;
1895 case WM_MDIACTIVATE:
1897 WND *tempWnd = WIN_FindWndPtr(hwnd);
1898 if( WIDGETS_IsControl(tempWnd, BIC32_MDICLIENT) )
1900 *pwparam16 = (HWND)wParam32;
1901 *plparam = 0;
1903 else
1905 *pwparam16 = ((HWND)*plparam == hwnd);
1906 *plparam = MAKELPARAM( (HWND16)LOWORD(*plparam),
1907 (HWND16)LOWORD(wParam32) );
1909 WIN_ReleaseWndPtr(tempWnd);
1911 return 0;
1912 case WM_NCCALCSIZE:
1914 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)*plparam;
1915 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1916 if (!nc) return -1;
1918 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1919 if (wParam32)
1921 WINDOWPOS16 *wp;
1922 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1923 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1924 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1926 SEGPTR_FREE(nc);
1927 return -1;
1929 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1930 nc->lppos = SEGPTR_GET(wp);
1932 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1933 *plparam = (LPARAM)SEGPTR_GET(nc);
1935 return 1;
1936 case WM_NCCREATE:
1937 case WM_CREATE:
1939 CREATESTRUCT16 *cs;
1940 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)*plparam;
1941 LPSTR name, cls;
1943 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1944 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1945 name = SEGPTR_STRDUP( cs32->lpszName );
1946 cls = SEGPTR_STRDUP( cs32->lpszClass );
1947 cs->lpszName = SEGPTR_GET(name);
1948 cs->lpszClass = SEGPTR_GET(cls);
1949 *plparam = (LPARAM)SEGPTR_GET(cs);
1951 return 1;
1952 case WM_PARENTNOTIFY:
1953 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1954 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1955 /* else nothing to do */
1956 return 0;
1957 case WM_NOTIFY:
1958 *plparam = MapLS( (NMHDR *)*plparam ); /* NMHDR is already 32-bit */
1959 return 1;
1960 case WM_SETTEXT:
1962 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1963 if (!str) return -1;
1964 *plparam = (LPARAM)SEGPTR_GET(str);
1966 return 1;
1967 case WM_WINDOWPOSCHANGING:
1968 case WM_WINDOWPOSCHANGED:
1970 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
1971 sizeof(LPARAM) );
1972 if (!wp) return -1;
1973 STRUCT32_WINDOWPOS32to16( (WINDOWPOS *)*plparam, wp );
1974 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1975 *plparam = (LPARAM)SEGPTR_GET(wp);
1977 return 1;
1978 case WM_GETDLGCODE:
1979 if (*plparam) {
1980 LPMSG msg32 = (LPMSG) *plparam;
1981 LPMSG16 msg16 = (LPMSG16) SEGPTR_NEW( MSG16 );
1983 if (!msg16) return -1;
1984 msg16->hwnd = msg32->hwnd;
1985 msg16->lParam = msg32->lParam;
1986 msg16->time = msg32->time;
1987 CONV_POINT32TO16(&msg32->pt,&msg16->pt);
1988 /* this is right, right? */
1989 if (WINPROC_MapMsg32ATo16(msg32->hwnd,msg32->message,msg32->wParam,
1990 &msg16->message,&msg16->wParam, &msg16->lParam)<0) {
1991 SEGPTR_FREE( msg16 );
1992 return -1;
1994 *plparam = (LPARAM)SEGPTR_GET(msg16);
1995 return 1;
1997 return 0;
1999 case WM_ACTIVATEAPP:
2000 if (*plparam) {
2001 *plparam = (LPARAM)THREAD_IdToTEB((DWORD) *plparam)->htask16;
2003 return 1;
2004 case WM_ASKCBFORMATNAME:
2005 case WM_DEVMODECHANGE:
2006 case WM_PAINTCLIPBOARD:
2007 case WM_SIZECLIPBOARD:
2008 case WM_WININICHANGE:
2009 FIXME_(msg)("message %04x needs translation\n", msg32 );
2010 return -1;
2011 case WM_SIZING: /* should not be send to 16-bit apps */
2012 return -1;
2013 default: /* No translation needed */
2014 return 0;
2019 /**********************************************************************
2020 * WINPROC_UnmapMsg32ATo16
2022 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2024 void WINPROC_UnmapMsg32ATo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2025 MSGPARAM16* p16 )
2027 switch(msg)
2029 case LB_ADDFILE:
2030 case LB_ADDSTRING:
2031 case LB_DIR:
2032 case LB_FINDSTRING:
2033 case LB_FINDSTRINGEXACT:
2034 case LB_INSERTSTRING:
2035 case LB_SELECTSTRING:
2036 case LB_SETTABSTOPS:
2037 case CB_ADDSTRING:
2038 case CB_FINDSTRING:
2039 case CB_FINDSTRINGEXACT:
2040 case CB_INSERTSTRING:
2041 case CB_SELECTSTRING:
2042 case CB_DIR:
2043 case WM_COMPAREITEM:
2044 case WM_DELETEITEM:
2045 case WM_DRAWITEM:
2046 case WM_SETTEXT:
2047 SEGPTR_FREE( PTR_SEG_TO_LIN(p16->lParam) );
2048 break;
2050 case CB_GETDROPPEDCONTROLRECT:
2051 case LB_GETITEMRECT:
2053 RECT16 *rect = (RECT16 *)PTR_SEG_TO_LIN(p16->lParam);
2054 p16->lParam = *(LPARAM *)(rect + 1);
2055 CONV_RECT16TO32( rect, (RECT *)(p16->lParam));
2056 SEGPTR_FREE( rect );
2058 break;
2059 case LB_GETSELITEMS:
2061 INT i;
2062 LPINT16 items = (LPINT16)PTR_SEG_TO_LIN(lParam);
2063 p16->lParam = *((LPARAM *)items - 1);
2064 for (i = 0; i < p16->wParam; i++) *((LPINT)(p16->lParam) + i) = items[i];
2065 SEGPTR_FREE( (LPARAM *)items - 1 );
2067 break;
2069 case CB_GETEDITSEL:
2070 if( wParam )
2071 *((LPUINT)(wParam)) = LOWORD(p16->lResult);
2072 if( lParam )
2073 *((LPUINT)(lParam)) = HIWORD(p16->lResult); /* FIXME: substract 1? */
2074 break;
2076 case LB_GETTEXT:
2077 case CB_GETLBTEXT:
2078 UnMapLS( (SEGPTR)(p16->lParam) );
2079 break;
2081 case WM_MEASUREITEM:
2083 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2084 MEASUREITEMSTRUCT *mis32 = *(MEASUREITEMSTRUCT **)(mis + 1);
2085 mis32->itemWidth = mis->itemWidth;
2086 mis32->itemHeight = mis->itemHeight;
2087 SEGPTR_FREE(mis);
2089 break;
2090 case WM_GETMINMAXINFO:
2092 MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(p16->lParam);
2093 p16->lParam = *(LPARAM *)(mmi + 1);
2094 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO *)(p16->lParam) );
2095 SEGPTR_FREE(mmi);
2097 break;
2098 case WM_GETTEXT:
2100 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2101 p16->lParam = *((LPARAM *)str - 1);
2102 lstrcpynA( (LPSTR)(p16->lParam), str, p16->wParam );
2103 SEGPTR_FREE( (LPARAM *)str - 1 );
2105 break;
2106 case WM_MDICREATE:
2108 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16*)PTR_SEG_TO_LIN(p16->lParam);
2109 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szTitle) );
2110 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szClass) );
2111 SEGPTR_FREE( cs );
2113 break;
2114 case WM_MDIGETACTIVE:
2115 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(p16->lResult);
2116 p16->lResult = (HWND)LOWORD(p16->lResult);
2117 break;
2118 case WM_NCCALCSIZE:
2120 NCCALCSIZE_PARAMS *nc32;
2121 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(p16->lParam);
2122 p16->lParam = *(LPARAM *)(nc + 1);
2123 nc32 = (NCCALCSIZE_PARAMS *)(p16->lParam);
2124 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
2125 if (p16->wParam)
2127 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
2128 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
2129 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
2130 nc32->lppos );
2131 SEGPTR_FREE( PTR_SEG_TO_LIN(nc->lppos) );
2133 SEGPTR_FREE(nc);
2135 break;
2136 case WM_NCCREATE:
2137 case WM_CREATE:
2139 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(p16->lParam);
2140 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszName) );
2141 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszClass) );
2142 SEGPTR_FREE( cs );
2144 break;
2145 case WM_WINDOWPOSCHANGING:
2146 case WM_WINDOWPOSCHANGED:
2148 WINDOWPOS16 *wp = (WINDOWPOS16 *)PTR_SEG_TO_LIN(p16->lParam);
2149 p16->lParam = *(LPARAM *)(wp + 1);
2150 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS *)p16->lParam );
2151 SEGPTR_FREE(wp);
2153 break;
2154 case WM_NOTIFY:
2155 UnMapLS(p16->lParam);
2156 break;
2157 case WM_GETDLGCODE:
2158 if (p16->lParam)
2160 LPMSG16 msg16 = (LPMSG16)PTR_SEG_TO_LIN(p16->lParam);
2161 MSGPARAM16 msgp16;
2162 msgp16.wParam=msg16->wParam;
2163 msgp16.lParam=msg16->lParam;
2164 WINPROC_UnmapMsg32ATo16(((LPMSG)lParam)->hwnd, ((LPMSG)lParam)->message,
2165 ((LPMSG)lParam)->wParam, ((LPMSG)lParam)->lParam,
2166 &msgp16 );
2167 SEGPTR_FREE(msg16);
2169 break;
2174 /**********************************************************************
2175 * WINPROC_MapMsg32WTo16
2177 * Map a message from 32-bit Unicode to 16-bit.
2178 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2180 INT WINPROC_MapMsg32WTo16( HWND hwnd, UINT msg32, WPARAM wParam32,
2181 UINT16 *pmsg16, WPARAM16 *pwparam16,
2182 LPARAM *plparam )
2184 *pmsg16 = LOWORD(msg32);
2185 *pwparam16 = LOWORD(wParam32);
2186 switch(msg32)
2188 case LB_ADDSTRING:
2189 case LB_FINDSTRING:
2190 case LB_FINDSTRINGEXACT:
2191 case LB_INSERTSTRING:
2192 case LB_SELECTSTRING:
2193 case LB_DIR:
2194 case LB_ADDFILE:
2196 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2197 if (!str) return -1;
2198 *plparam = (LPARAM)SEGPTR_GET(str);
2200 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING);
2201 return 1;
2203 case CB_ADDSTRING:
2204 case CB_FINDSTRING:
2205 case CB_FINDSTRINGEXACT:
2206 case CB_INSERTSTRING:
2207 case CB_SELECTSTRING:
2208 case CB_DIR:
2210 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2211 if (!str) return -1;
2212 *plparam = (LPARAM)SEGPTR_GET(str);
2214 *pmsg16 = (UINT16)msg32 + (CB_ADDSTRING16 - CB_ADDSTRING);
2215 return 1;
2217 case WM_NCCREATE:
2218 case WM_CREATE:
2220 CREATESTRUCT16 *cs;
2221 CREATESTRUCTW *cs32 = (CREATESTRUCTW *)*plparam;
2222 LPSTR name, cls;
2224 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
2225 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA *)cs32, cs );
2226 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
2227 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
2228 cs->lpszName = SEGPTR_GET(name);
2229 cs->lpszClass = SEGPTR_GET(cls);
2230 *plparam = (LPARAM)SEGPTR_GET(cs);
2232 return 1;
2233 case WM_MDICREATE:
2235 MDICREATESTRUCT16 *cs;
2236 MDICREATESTRUCTW *cs32 = (MDICREATESTRUCTW *)*plparam;
2237 LPSTR name, cls;
2239 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
2240 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA *)cs32, cs );
2241 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
2242 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
2243 cs->szTitle = SEGPTR_GET(name);
2244 cs->szClass = SEGPTR_GET(cls);
2245 *plparam = (LPARAM)SEGPTR_GET(cs);
2247 return 1;
2248 case WM_SETTEXT:
2250 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
2251 if (!str) return -1;
2252 *plparam = (LPARAM)SEGPTR_GET(str);
2254 return 1;
2255 case LB_GETTEXT:
2256 case CB_GETLBTEXT:
2257 if ( WINPROC_TestLBForStr( hwnd ))
2259 LPSTR str = (LPSTR) SEGPTR_ALLOC( 256 ); /* fixme: fixed sized buffer */
2260 if (!str) return -1;
2261 *pmsg16 = (msg32 == LB_GETTEXT)? LB_GETTEXT16 : CB_GETLBTEXT16;
2262 *plparam = (LPARAM)SEGPTR_GET(str);
2264 return 1;
2266 case WM_CHAR:
2267 case WM_DEADCHAR:
2268 case WM_SYSCHAR:
2269 case WM_SYSDEADCHAR:
2271 WCHAR wch = wParam32;
2272 char ch;
2273 WideCharToMultiByte( CP_ACP, 0, &wch, 1, &ch, 1, NULL, NULL);
2274 *pwparam16 = ch;
2276 return 0;
2278 default: /* No Unicode translation needed (?) */
2279 return WINPROC_MapMsg32ATo16( hwnd, msg32, wParam32, pmsg16,
2280 pwparam16, plparam );
2285 /**********************************************************************
2286 * WINPROC_UnmapMsg32WTo16
2288 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2290 void WINPROC_UnmapMsg32WTo16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam,
2291 MSGPARAM16* p16 )
2293 switch(msg)
2295 case WM_GETTEXT:
2297 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2298 p16->lParam = *((LPARAM *)str - 1);
2299 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)p16->lParam, 0x7fffffff );
2300 SEGPTR_FREE( (LPARAM *)str - 1 );
2302 break;
2303 case LB_GETTEXT:
2304 case CB_GETLBTEXT:
2305 if ( WINPROC_TestLBForStr( hwnd ))
2307 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(p16->lParam);
2308 MultiByteToWideChar( CP_ACP, 0, str, -1, (LPWSTR)lParam, 0x7fffffff );
2309 SEGPTR_FREE( (LPARAM *) str );
2311 break;
2312 default:
2313 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, p16 );
2314 break;
2319 /**********************************************************************
2320 * WINPROC_CallProc32ATo32W
2322 * Call a window procedure, translating args from Ansi to Unicode.
2324 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC func, HWND hwnd,
2325 UINT msg, WPARAM wParam,
2326 LPARAM lParam )
2328 LRESULT result;
2330 if (WINPROC_MapMsg32ATo32W( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2331 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2332 WINPROC_UnmapMsg32ATo32W( hwnd, msg, wParam, lParam );
2333 return result;
2337 /**********************************************************************
2338 * WINPROC_CallProc32WTo32A
2340 * Call a window procedure, translating args from Unicode to Ansi.
2342 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC func, HWND hwnd,
2343 UINT msg, WPARAM wParam,
2344 LPARAM lParam )
2346 LRESULT result;
2348 if (WINPROC_MapMsg32WTo32A( hwnd, msg, &wParam, &lParam ) == -1) return 0;
2349 result = WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2350 WINPROC_UnmapMsg32WTo32A( hwnd, msg, wParam, lParam );
2351 return result;
2355 /**********************************************************************
2356 * WINPROC_CallProc16To32A
2358 * Call a 32-bit window procedure, translating the 16-bit args.
2360 static LRESULT WINPROC_CallProc16To32A( WNDPROC func, HWND16 hwnd,
2361 UINT16 msg, WPARAM16 wParam,
2362 LPARAM lParam )
2364 LRESULT result;
2365 UINT msg32;
2366 WPARAM wParam32;
2368 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2369 return 0;
2370 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2371 return WINPROC_UnmapMsg16To32A( hwnd, msg32, wParam32, lParam, result );
2374 /**********************************************************************
2375 * WINPROC_Thunk16To32A
2377 static LRESULT WINAPI WINPROC_Thunk16To32A( WNDPROC func, LPBYTE args )
2379 HWND16 hwnd = *(HWND16 *)( args+8 );
2380 UINT16 msg = *(HWND16 *)( args+6 );
2381 WPARAM16 wParam = *(HWND16 *)( args+4 );
2382 LPARAM lParam = *(LPARAM *)( args+0 );
2384 return WINPROC_CallProc16To32A( func, hwnd, msg, wParam, lParam );
2388 /**********************************************************************
2389 * WINPROC_CallProc16To32W
2391 * Call a 32-bit window procedure, translating the 16-bit args.
2393 static LRESULT WINPROC_CallProc16To32W( WNDPROC func, HWND16 hwnd,
2394 UINT16 msg, WPARAM16 wParam,
2395 LPARAM lParam )
2397 LRESULT result;
2398 UINT msg32;
2399 WPARAM wParam32;
2401 if (WINPROC_MapMsg16To32W( hwnd, msg, wParam, &msg32, &wParam32, &lParam ) == -1)
2402 return 0;
2404 result = WINPROC_CallWndProc( func, hwnd, msg32, wParam32, lParam );
2406 return WINPROC_UnmapMsg16To32W( hwnd, msg32, wParam32, lParam, result );
2409 /**********************************************************************
2410 * WINPROC_Thunk16To32W
2412 static LRESULT WINAPI WINPROC_Thunk16To32W( WNDPROC func, LPBYTE args )
2414 HWND16 hwnd = *(HWND16 *)( args+8 );
2415 UINT16 msg = *(HWND16 *)( args+6 );
2416 WPARAM16 wParam = *(HWND16 *)( args+4 );
2417 LPARAM lParam = *(LPARAM *)( args+0 );
2419 return WINPROC_CallProc16To32W( func, hwnd, msg, wParam, lParam );
2422 /**********************************************************************
2423 * WINPROC_CallProc32ATo16
2425 * Call a 16-bit window procedure, translating the 32-bit args.
2427 static LRESULT WINAPI WINPROC_CallProc32ATo16( WNDPROC16 func, HWND hwnd,
2428 UINT msg, WPARAM wParam,
2429 LPARAM lParam )
2431 UINT16 msg16;
2432 MSGPARAM16 mp16;
2434 mp16.lParam = lParam;
2435 if (WINPROC_MapMsg32ATo16( hwnd, msg, wParam,
2436 &msg16, &mp16.wParam, &mp16.lParam ) == -1)
2437 return 0;
2438 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2439 mp16.wParam, mp16.lParam );
2440 WINPROC_UnmapMsg32ATo16( hwnd, msg, wParam, lParam, &mp16 );
2441 return mp16.lResult;
2445 /**********************************************************************
2446 * WINPROC_CallProc32WTo16
2448 * Call a 16-bit window procedure, translating the 32-bit args.
2450 static LRESULT WINAPI WINPROC_CallProc32WTo16( WNDPROC16 func, HWND hwnd,
2451 UINT msg, WPARAM wParam,
2452 LPARAM lParam )
2454 UINT16 msg16;
2455 MSGPARAM16 mp16;
2457 mp16.lParam = lParam;
2458 if (WINPROC_MapMsg32WTo16( hwnd, msg, wParam, &msg16, &mp16.wParam,
2459 &mp16.lParam ) == -1)
2460 return 0;
2461 mp16.lResult = WINPROC_CallWndProc16( func, hwnd, msg16,
2462 mp16.wParam, mp16.lParam );
2463 WINPROC_UnmapMsg32WTo16( hwnd, msg, wParam, lParam, &mp16 );
2464 return mp16.lResult;
2468 /**********************************************************************
2469 * CallWindowProc16 (USER.122)
2471 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
2472 WPARAM16 wParam, LPARAM lParam )
2474 WINDOWPROC *proc = WINPROC_GetPtr( func );
2476 if (!proc)
2477 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2479 #if testing
2480 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16 );
2481 return WINPROC_CallWndProc16( func, hwnd, msg, wParam, lParam );
2482 #endif
2484 switch(proc->type)
2486 case WIN_PROC_16:
2487 if (!proc->thunk.t_from32.proc) return 0;
2488 return WINPROC_CallWndProc16( proc->thunk.t_from32.proc,
2489 hwnd, msg, wParam, lParam );
2490 case WIN_PROC_32A:
2491 if (!proc->thunk.t_from16.proc) return 0;
2492 return WINPROC_CallProc16To32A( proc->thunk.t_from16.proc,
2493 hwnd, msg, wParam, lParam );
2494 case WIN_PROC_32W:
2495 if (!proc->thunk.t_from16.proc) return 0;
2496 return WINPROC_CallProc16To32W( proc->thunk.t_from16.proc,
2497 hwnd, msg, wParam, lParam );
2498 default:
2499 WARN_(relay)("Invalid proc %p\n", proc );
2500 return 0;
2505 /**********************************************************************
2506 * CallWindowProcA (USER32.18)
2508 * The CallWindowProc() function invokes the windows procedure _func_,
2509 * with _hwnd_ as the target window, the message specified by _msg_, and
2510 * the message parameters _wParam_ and _lParam_.
2512 * Some kinds of argument conversion may be done, I'm not sure what.
2514 * CallWindowProc() may be used for windows subclassing. Use
2515 * SetWindowLong() to set a new windows procedure for windows of the
2516 * subclass, and handle subclassed messages in the new windows
2517 * procedure. The new windows procedure may then use CallWindowProc()
2518 * with _func_ set to the parent class's windows procedure to dispatch
2519 * the message to the superclass.
2521 * RETURNS
2523 * The return value is message dependent.
2525 * CONFORMANCE
2527 * ECMA-234, Win32
2529 LRESULT WINAPI CallWindowProcA(
2530 WNDPROC func, /* window procedure */
2531 HWND hwnd, /* target window */
2532 UINT msg, /* message */
2533 WPARAM wParam, /* message dependent parameter */
2534 LPARAM lParam /* message dependent parameter */
2536 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2538 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2540 #if testing
2541 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
2542 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2543 #endif
2545 switch(proc->type)
2547 case WIN_PROC_16:
2548 if (!proc->thunk.t_from32.proc) return 0;
2549 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
2550 hwnd, msg, wParam, lParam );
2551 case WIN_PROC_32A:
2552 if (!proc->thunk.t_from16.proc) return 0;
2553 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2554 hwnd, msg, wParam, lParam );
2555 case WIN_PROC_32W:
2556 if (!proc->thunk.t_from16.proc) return 0;
2557 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
2558 hwnd, msg, wParam, lParam );
2559 default:
2560 WARN_(relay)("Invalid proc %p\n", proc );
2561 return 0;
2566 /**********************************************************************
2567 * CallWindowProcW (USER32.19)
2569 LRESULT WINAPI CallWindowProcW( WNDPROC func, HWND hwnd, UINT msg,
2570 WPARAM wParam, LPARAM lParam )
2572 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
2574 if (!proc) return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2576 #if testing
2577 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
2578 return WINPROC_CallWndProc( func, hwnd, msg, wParam, lParam );
2579 #endif
2581 switch(proc->type)
2583 case WIN_PROC_16:
2584 if (!proc->thunk.t_from32.proc) return 0;
2585 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
2586 hwnd, msg, wParam, lParam );
2587 case WIN_PROC_32A:
2588 if (!proc->thunk.t_from16.proc) return 0;
2589 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
2590 hwnd, msg, wParam, lParam );
2591 case WIN_PROC_32W:
2592 if (!proc->thunk.t_from16.proc) return 0;
2593 return WINPROC_CallWndProc( proc->thunk.t_from16.proc,
2594 hwnd, msg, wParam, lParam );
2595 default:
2596 WARN_(relay)("Invalid proc %p\n", proc );
2597 return 0;