Release 970112
[wine.git] / windows / winproc.c
blobe8946ee1810bd501e577ddbae59b8288037dffd7
1 /*
2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
6 */
8 #include <stdio.h>
9 #include "windows.h"
10 #include "callback.h"
11 #include "heap.h"
12 #include "selectors.h"
13 #include "stackframe.h"
14 #include "struct32.h"
15 #include "win.h"
16 #include "winproc.h"
17 #include "stddebug.h"
18 #include "debug.h"
20 /* Window procedure 16-bit thunk; see BuildSpec16Files() in tools/build.c */
21 typedef struct
23 BYTE popl_eax; /* popl %eax (return address) */
24 BYTE pushl_func; /* pushl $proc */
25 WNDPROC32 proc WINE_PACKED;
26 BYTE pushl_eax; /* pushl %eax */
27 WORD pushw_bp WINE_PACKED; /* pushw %bp */
28 BYTE pushl_thunk; /* pushl $thunkfrom16 */
29 void (*thunk32)() WINE_PACKED;
30 BYTE lcall; /* lcall cs:relay */
31 void (*relay)() WINE_PACKED;
32 WORD cs WINE_PACKED;
33 } WINPROC_THUNK_FROM16;
35 /* Window procedure 32-bit thunk; see BuildSpec32Files() in tools/build.c */
36 typedef struct
38 BYTE popl_eax; /* popl %eax (return address) */
39 BYTE pushl_func; /* pushl $proc */
40 WNDPROC16 proc WINE_PACKED;
41 BYTE pushl_eax; /* pushl %eax */
42 BYTE pushl_ebp; /* pushl %ebp */
43 BYTE pushl_name; /* pushl $name */
44 LPCSTR name WINE_PACKED;
45 BYTE pushl_thunk; /* pushl $thunkfrom32 */
46 void (*thunk32)() WINE_PACKED;
47 BYTE jmp; /* jmp relay (relative jump)*/
48 void (*relay)() WINE_PACKED;
49 } WINPROC_THUNK_FROM32;
51 /* Simple jmp to call 32-bit procedure directly */
52 typedef struct
54 BYTE jmp; /* jmp proc (relative jump) */
55 WNDPROC32 proc WINE_PACKED;
56 } WINPROC_JUMP;
58 typedef union
60 WINPROC_THUNK_FROM16 t_from16;
61 WINPROC_THUNK_FROM32 t_from32;
62 } WINPROC_THUNK;
64 typedef struct tagWINDOWPROC
66 WINPROC_THUNK thunk; /* Thunk */
67 WINPROC_JUMP jmp; /* Jump */
68 struct tagWINDOWPROC *next; /* Next window proc */
69 UINT32 magic; /* Magic number */
70 WINDOWPROCTYPE type; /* Function type */
71 } WINDOWPROC;
73 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
75 #define WINPROC_THUNKPROC(pproc) \
76 (((pproc)->type == WIN_PROC_16) ? \
77 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
78 (WNDPROC16)((pproc)->thunk.t_from16.proc))
80 LRESULT WINPROC_CallProc16To32A( HWND16 hwnd, UINT16 msg,
81 WPARAM16 wParam, LPARAM lParam,
82 WNDPROC32 func );
83 LRESULT WINPROC_CallProc16To32W( HWND16 hwnd, UINT16 msg,
84 WPARAM16 wParam, LPARAM lParam,
85 WNDPROC32 func );
86 static LRESULT WINPROC_CallProc32ATo16( WNDPROC16 func, HWND32 hwnd,
87 UINT32 msg, WPARAM32 wParam,
88 LPARAM lParam );
89 static LRESULT WINPROC_CallProc32WTo16( WNDPROC16 func, HWND32 hwnd,
90 UINT32 msg, WPARAM32 wParam,
91 LPARAM lParam );
93 #ifndef WINELIB
94 extern void CallFrom16_long_wwwll(void);
95 extern void CallFrom32_stdcall_5(void);
96 #else
97 static void CallFrom16_long_wwwll(void) {}
98 static void CallFrom32_stdcall_5(void) {}
99 #endif /* WINELIB */
101 static HANDLE32 WinProcHeap;
103 /**********************************************************************
104 * WINPROC_Init
106 BOOL32 WINPROC_Init(void)
108 WinProcHeap = HeapCreate( HEAP_WINE_SEGPTR | HEAP_WINE_CODESEG, 0, 0 );
109 if (!WinProcHeap)
111 fprintf( stderr, "Unable to create winproc heap\n" );
112 return FALSE;
114 return TRUE;
118 /**********************************************************************
119 * WINPROC_GetPtr
121 * Return a pointer to the win proc.
123 static WINDOWPROC *WINPROC_GetPtr( WNDPROC16 handle )
125 BYTE *ptr;
126 WINDOWPROC *proc;
128 /* Check for a linear pointer */
130 if (HEAP_IsInsideHeap( WinProcHeap, 0, (LPVOID)handle ))
132 ptr = (BYTE *)handle;
133 /* First check if it is the jmp address */
134 if (*ptr == 0xe9 /* jmp */) ptr -= (int)&((WINDOWPROC *)0)->jmp -
135 (int)&((WINDOWPROC *)0)->thunk;
136 /* Now it must be the thunk address */
137 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
138 /* Now we have a pointer to the WINDOWPROC struct */
139 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
140 return (WINDOWPROC *)ptr;
143 /* Check for a segmented pointer */
145 if (!IsBadReadPtr16((SEGPTR)handle,sizeof(WINDOWPROC)-sizeof(proc->thunk)))
147 ptr = (BYTE *)PTR_SEG_TO_LIN(handle);
148 if (!HEAP_IsInsideHeap( WinProcHeap, 0, ptr )) return NULL;
149 /* It must be the thunk address */
150 if (*ptr == 0x58 /* popl eax */) ptr -= (int)&((WINDOWPROC *)0)->thunk;
151 /* Now we have a pointer to the WINDOWPROC struct */
152 if (((WINDOWPROC *)ptr)->magic == WINPROC_MAGIC)
153 return (WINDOWPROC *)ptr;
156 return NULL;
160 /**********************************************************************
161 * WINPROC_AllocWinProc
163 * Allocate a new window procedure.
165 static WINDOWPROC *WINPROC_AllocWinProc( WNDPROC16 func, WINDOWPROCTYPE type )
167 WINDOWPROC *proc, *oldproc;
169 /* Allocate a window procedure */
171 if (!(proc = HeapAlloc( WinProcHeap, 0, sizeof(WINDOWPROC) ))) return 0;
173 /* Check if the function is already a win proc */
175 if ((oldproc = WINPROC_GetPtr( func )))
177 *proc = *oldproc;
179 else
181 switch(type)
183 case WIN_PROC_16:
184 proc->thunk.t_from32.popl_eax = 0x58; /* popl %eax */
185 proc->thunk.t_from32.pushl_func = 0x68; /* pushl $proc */
186 proc->thunk.t_from32.proc = func;
187 proc->thunk.t_from32.pushl_eax = 0x50; /* pushl %eax */
188 proc->thunk.t_from32.pushl_ebp = 0x55; /* pushl %ebp */
189 proc->thunk.t_from32.pushl_name = 0x68; /* pushl $name */
190 proc->thunk.t_from32.name = "WINPROC_CallProc32ATo16";
191 proc->thunk.t_from32.pushl_thunk = 0x68; /* pushl $thunkfrom32 */
192 proc->thunk.t_from32.thunk32 = (void(*)())WINPROC_CallProc32ATo16;
193 proc->thunk.t_from32.jmp = 0xe9; /* jmp relay*/
194 proc->thunk.t_from32.relay = /* relative jump */
195 (void (*)())((DWORD)CallFrom32_stdcall_5 -
196 (DWORD)(&proc->thunk.t_from32.relay + 1));
197 break;
198 case WIN_PROC_32A:
199 case WIN_PROC_32W:
200 proc->thunk.t_from16.popl_eax = 0x58; /* popl %eax */
201 proc->thunk.t_from16.pushl_func = 0x68; /* pushl $proc */
202 proc->thunk.t_from16.proc = (FARPROC32)func;
203 proc->thunk.t_from16.pushl_eax = 0x50; /* pushl %eax */
204 proc->thunk.t_from16.pushw_bp = 0x5566; /* pushw %bp */
205 proc->thunk.t_from16.pushl_thunk = 0x68; /* pushl $thunkfrom16 */
206 proc->thunk.t_from16.thunk32 = (type == WIN_PROC_32A) ?
207 (void(*)())WINPROC_CallProc16To32A :
208 (void(*)())WINPROC_CallProc16To32W;
209 proc->thunk.t_from16.lcall = 0x9a; /* lcall cs:relay */
210 proc->thunk.t_from16.relay = CallFrom16_long_wwwll;
211 proc->thunk.t_from16.cs = WINE_CODE_SELECTOR;
212 proc->jmp.jmp = 0xe9;
213 /* Fixup relative jump */
214 proc->jmp.proc = (WNDPROC32)((DWORD)func -
215 (DWORD)(&proc->jmp.proc + 1));
216 break;
217 default:
218 /* Should not happen */
219 break;
221 proc->magic = WINPROC_MAGIC;
222 proc->type = type;
224 proc->next = NULL;
225 dprintf_win( stddeb, "WINPROC_AllocWinProc(%08x,%d): returning %08x\n",
226 (UINT32)func, type, (UINT32)proc );
227 return proc;
231 /**********************************************************************
232 * WINPROC_GetProc
234 * Get a window procedure pointer that can be passed to the Windows program.
236 WNDPROC16 WINPROC_GetProc( HWINDOWPROC proc, WINDOWPROCTYPE type )
238 if (type == WIN_PROC_16) /* We want a 16:16 address */
240 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
241 return ((WINDOWPROC *)proc)->thunk.t_from32.proc;
242 else
243 return (WNDPROC16)HEAP_GetSegptr( WinProcHeap, 0,
244 &((WINDOWPROC *)proc)->thunk );
246 else /* We want a 32-bit address */
248 if (((WINDOWPROC *)proc)->type == WIN_PROC_16)
249 return (WNDPROC16)&((WINDOWPROC *)proc)->thunk;
250 else
251 return (WNDPROC16)&((WINDOWPROC *)proc)->jmp;
256 /**********************************************************************
257 * WINPROC_SetProc
259 * Set the window procedure for a window or class.
261 BOOL32 WINPROC_SetProc( HWINDOWPROC *pFirst, WNDPROC16 func,
262 WINDOWPROCTYPE type )
264 WINDOWPROC *proc, **ppPrev;
266 /* Check if function is already in the list */
268 ppPrev = (WINDOWPROC **)pFirst;
269 proc = WINPROC_GetPtr( func );
270 while (*ppPrev)
272 if (proc)
274 if (*ppPrev == proc) break;
276 else
278 if (((*ppPrev)->type == type) &&
279 (func == WINPROC_THUNKPROC(*ppPrev))) break;
281 ppPrev = &(*ppPrev)->next;
284 if (*ppPrev) /* Remove it from the list */
286 proc = *ppPrev;
287 *ppPrev = proc->next;
289 else /* Allocate a new one */
291 if (proc) /* Was already a win proc */
293 type = proc->type;
294 func = WINPROC_THUNKPROC(proc);
296 proc = WINPROC_AllocWinProc( func, type );
297 if (!proc) return FALSE;
300 /* Add the win proc at the head of the list */
302 dprintf_win( stddeb, "WINPROC_SetProc(%08x,%08x,%d): res=%08x\n",
303 (UINT32)*pFirst, (UINT32)func, type, (UINT32)proc );
304 proc->next = *(WINDOWPROC **)pFirst;
305 *(WINDOWPROC **)pFirst = proc;
306 return TRUE;
310 /**********************************************************************
311 * WINPROC_FreeProc
313 * Free a list of win procs.
315 void WINPROC_FreeProc( HWINDOWPROC proc )
317 while (proc)
319 WINDOWPROC *next = ((WINDOWPROC *)proc)->next;
320 dprintf_win( stddeb, "WINPROC_FreeProc: freeing %08x\n", (UINT32)proc);
321 HeapFree( WinProcHeap, 0, proc );
322 proc = next;
327 /**********************************************************************
328 * WINPROC_GetProcType
330 * Return the window procedure type.
332 WINDOWPROCTYPE WINPROC_GetProcType( HWINDOWPROC proc )
334 if (!proc ||
335 (((WINDOWPROC *)proc)->magic != WINPROC_MAGIC))
336 return WIN_PROC_INVALID;
337 return ((WINDOWPROC *)proc)->type;
341 /**********************************************************************
342 * WINPROC_MapMsg32ATo32W
344 * Map a message from Ansi to Unicode.
345 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
347 INT32 WINPROC_MapMsg32ATo32W( UINT32 msg, WPARAM32 wParam, LPARAM *plparam )
349 switch(msg)
351 case WM_GETTEXT:
353 LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
354 wParam * sizeof(WCHAR) + sizeof(LPARAM) );
355 if (!ptr) return -1;
356 *ptr++ = *plparam; /* Store previous lParam */
357 *plparam = (LPARAM)ptr;
359 return 1;
360 case WM_SETTEXT:
361 *plparam = (LPARAM)HEAP_strdupAtoW( SystemHeap, 0, (LPCSTR)*plparam );
362 return (*plparam ? 1 : -1);
363 case WM_NCCREATE:
364 case WM_CREATE:
366 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)HeapAlloc( SystemHeap, 0,
367 sizeof(*cs) );
368 if (!cs) return -1;
369 *cs = *(CREATESTRUCT32W *)*plparam;
370 if (HIWORD(cs->lpszName))
371 cs->lpszName = HEAP_strdupAtoW( SystemHeap, 0,
372 (LPCSTR)cs->lpszName );
373 if (HIWORD(cs->lpszClass))
374 cs->lpszClass = HEAP_strdupAtoW( SystemHeap, 0,
375 (LPCSTR)cs->lpszClass );
376 *plparam = (LPARAM)cs;
378 return 1;
379 case WM_MDICREATE:
381 MDICREATESTRUCT32W *cs =
382 (MDICREATESTRUCT32W *)HeapAlloc( SystemHeap, 0, sizeof(*cs) );
383 if (!cs) return -1;
384 *cs = *(MDICREATESTRUCT32W *)*plparam;
385 if (HIWORD(cs->szClass))
386 cs->szClass = HEAP_strdupAtoW( SystemHeap, 0,
387 (LPCSTR)cs->szClass );
388 if (HIWORD(cs->szTitle))
389 cs->szTitle = HEAP_strdupAtoW( SystemHeap, 0,
390 (LPCSTR)cs->szTitle );
391 *plparam = (LPARAM)cs;
393 return 1;
394 case WM_ASKCBFORMATNAME:
395 case WM_DEVMODECHANGE:
396 case WM_MDIACTIVATE:
397 case WM_PAINTCLIPBOARD:
398 case WM_SIZECLIPBOARD:
399 case WM_WININICHANGE:
400 fprintf( stderr, "MapMsg32ATo32W: message %04x needs translation\n",
401 msg );
402 return -1;
403 default: /* No translation needed */
404 return 0;
409 /**********************************************************************
410 * WINPROC_UnmapMsg32ATo32W
412 * Unmap a message that was mapped from Ansi to Unicode.
414 void WINPROC_UnmapMsg32ATo32W( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
416 switch(msg)
418 case WM_GETTEXT:
420 LPARAM *ptr = (LPARAM *)lParam - 1;
421 lstrcpynWtoA( (LPSTR)*ptr, (LPWSTR)(ptr + 1), wParam );
422 HeapFree( SystemHeap, 0, ptr );
424 break;
425 case WM_SETTEXT:
426 HeapFree( SystemHeap, 0, (void *)lParam );
427 break;
428 case WM_NCCREATE:
429 case WM_CREATE:
431 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)lParam;
432 if (HIWORD(cs->lpszName))
433 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
434 if (HIWORD(cs->lpszClass))
435 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
436 HeapFree( SystemHeap, 0, cs );
438 break;
439 case WM_MDICREATE:
441 MDICREATESTRUCT32W *cs = (MDICREATESTRUCT32W *)lParam;
442 if (HIWORD(cs->szTitle))
443 HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
444 if (HIWORD(cs->szClass))
445 HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
446 HeapFree( SystemHeap, 0, cs );
448 break;
453 /**********************************************************************
454 * WINPROC_MapMsg32WTo32A
456 * Map a message from Unicode to Ansi.
457 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
459 INT32 WINPROC_MapMsg32WTo32A( UINT32 msg, WPARAM32 wParam, LPARAM *plparam )
461 switch(msg)
463 case WM_GETTEXT:
465 LPARAM *ptr = (LPARAM *)HeapAlloc( SystemHeap, 0,
466 wParam + sizeof(LPARAM) );
467 if (!ptr) return -1;
468 *ptr++ = *plparam; /* Store previous lParam */
469 *plparam = (LPARAM)ptr;
471 return 1;
472 case WM_SETTEXT:
473 *plparam = (LPARAM)HEAP_strdupWtoA( SystemHeap, 0, (LPCWSTR)*plparam );
474 return (*plparam ? 1 : -1);
475 case WM_NCCREATE:
476 case WM_CREATE:
478 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)HeapAlloc( SystemHeap, 0,
479 sizeof(*cs) );
480 if (!cs) return -1;
481 *cs = *(CREATESTRUCT32A *)*plparam;
482 if (HIWORD(cs->lpszName))
483 cs->lpszName = HEAP_strdupWtoA( SystemHeap, 0,
484 (LPCWSTR)cs->lpszName );
485 if (HIWORD(cs->lpszClass))
486 cs->lpszClass = HEAP_strdupWtoA( SystemHeap, 0,
487 (LPCWSTR)cs->lpszClass);
488 *plparam = (LPARAM)cs;
490 return 1;
491 case WM_MDICREATE:
493 MDICREATESTRUCT32A *cs =
494 (MDICREATESTRUCT32A *)HeapAlloc( SystemHeap, 0, sizeof(*cs) );
495 if (!cs) return -1;
496 *cs = *(MDICREATESTRUCT32A *)*plparam;
497 if (HIWORD(cs->szTitle))
498 cs->szTitle = HEAP_strdupWtoA( SystemHeap, 0,
499 (LPCWSTR)cs->szTitle );
500 if (HIWORD(cs->szClass))
501 cs->szClass = HEAP_strdupWtoA( SystemHeap, 0,
502 (LPCWSTR)cs->szClass );
503 *plparam = (LPARAM)cs;
505 return 1;
506 case WM_ASKCBFORMATNAME:
507 case WM_DEVMODECHANGE:
508 case WM_MDIACTIVATE:
509 case WM_PAINTCLIPBOARD:
510 case WM_SIZECLIPBOARD:
511 case WM_WININICHANGE:
512 fprintf( stderr, "MapMsg32WTo32A: message %04x needs translation\n",
513 msg );
514 return -1;
515 default: /* No translation needed */
516 return 0;
521 /**********************************************************************
522 * WINPROC_UnmapMsg32WTo32A
524 * Unmap a message that was mapped from Unicode to Ansi.
526 void WINPROC_UnmapMsg32WTo32A( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
528 switch(msg)
530 case WM_GETTEXT:
532 LPARAM *ptr = (LPARAM *)lParam - 1;
533 lstrcpynAtoW( (LPWSTR)*ptr, (LPSTR)(ptr + 1), wParam );
534 HeapFree( SystemHeap, 0, ptr );
536 break;
537 case WM_SETTEXT:
538 HeapFree( SystemHeap, 0, (void *)lParam );
539 break;
540 case WM_NCCREATE:
541 case WM_CREATE:
543 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
544 if (HIWORD(cs->lpszName))
545 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
546 if (HIWORD(cs->lpszClass))
547 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
548 HeapFree( SystemHeap, 0, cs );
550 break;
551 case WM_MDICREATE:
553 MDICREATESTRUCT32A *cs = (MDICREATESTRUCT32A *)lParam;
554 if (HIWORD(cs->szTitle))
555 HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
556 if (HIWORD(cs->szClass))
557 HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
558 HeapFree( SystemHeap, 0, cs );
560 break;
565 /**********************************************************************
566 * WINPROC_MapMsg16To32A
568 * Map a message from 16- to 32-bit Ansi.
569 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
571 INT32 WINPROC_MapMsg16To32A( UINT16 msg16, WPARAM16 wParam16, UINT32 *pmsg32,
572 WPARAM32 *pwparam32, LPARAM *plparam )
574 *pmsg32 = (UINT32)msg16;
575 *pwparam32 = (WPARAM32)wParam16;
576 switch(msg16)
578 case WM_ACTIVATE:
579 case WM_CHARTOITEM:
580 case WM_COMMAND:
581 case WM_VKEYTOITEM:
582 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
583 *plparam = (LPARAM)(HWND32)LOWORD(*plparam);
584 return 0;
585 case WM_HSCROLL:
586 case WM_VSCROLL:
587 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
588 *plparam = (LPARAM)(HWND32)HIWORD(*plparam);
589 return 0;
590 case WM_CTLCOLOR:
591 *pmsg32 = WM_CTLCOLORMSGBOX + HIWORD(*plparam);
592 *pwparam32 = (WPARAM32)(HDC32)wParam16;
593 *plparam = (LPARAM)(HWND32)LOWORD(*plparam);
594 return 0;
595 case WM_COMPAREITEM:
597 COMPAREITEMSTRUCT16* cis16 = (COMPAREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
598 COMPAREITEMSTRUCT32 *cis = (COMPAREITEMSTRUCT32 *)
599 HeapAlloc(SystemHeap, 0, sizeof(*cis));
600 if (!cis) return -1;
601 cis->CtlType = cis16->CtlType;
602 cis->CtlID = cis16->CtlID;
603 cis->hwndItem = cis16->hwndItem;
604 cis->itemID1 = cis16->itemID1;
605 cis->itemData1 = cis16->itemData1;
606 cis->itemID2 = cis16->itemID2;
607 cis->itemData2 = cis16->itemData2;
608 cis->dwLocaleId = 0; /* FIXME */
609 *plparam = (LPARAM)cis;
611 return 1;
612 case WM_DELETEITEM:
614 DELETEITEMSTRUCT16* dis16 = (DELETEITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
615 DELETEITEMSTRUCT32 *dis = (DELETEITEMSTRUCT32 *)
616 HeapAlloc(SystemHeap, 0, sizeof(*dis));
617 if (!dis) return -1;
618 dis->CtlType = dis16->CtlType;
619 dis->CtlID = dis16->CtlID;
620 dis->hwndItem = dis16->hwndItem;
621 dis->itemData = dis16->itemData;
622 *plparam = (LPARAM)dis;
624 return 1;
625 case WM_MEASUREITEM:
627 MEASUREITEMSTRUCT16* mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
628 MEASUREITEMSTRUCT32 *mis = (MEASUREITEMSTRUCT32 *)
629 HeapAlloc(SystemHeap, 0,
630 sizeof(*mis) + sizeof(LPARAM));
631 if (!mis) return -1;
632 mis->CtlType = mis16->CtlType;
633 mis->CtlID = mis16->CtlID;
634 mis->itemID = mis16->itemID;
635 mis->itemWidth = mis16->itemWidth;
636 mis->itemHeight = mis16->itemHeight;
637 mis->itemData = mis16->itemData;
638 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
639 *plparam = (LPARAM)mis;
641 return 1;
642 case WM_DRAWITEM:
644 DRAWITEMSTRUCT16* dis16 = (DRAWITEMSTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
645 DRAWITEMSTRUCT32 *dis = (DRAWITEMSTRUCT32*)HeapAlloc(SystemHeap, 0,
646 sizeof(*dis));
647 if (!dis) return -1;
648 dis->CtlType = dis16->CtlType;
649 dis->CtlID = dis16->CtlID;
650 dis->itemID = dis16->itemID;
651 dis->itemAction = dis16->itemAction;
652 dis->itemState = dis16->itemState;
653 dis->hwndItem = dis16->hwndItem;
654 dis->hDC = dis16->hDC;
655 dis->itemData = dis16->itemData;
656 CONV_RECT16TO32( &dis16->rcItem, &dis->rcItem );
657 *plparam = (LPARAM)dis;
659 return 1;
660 case WM_GETMINMAXINFO:
662 MINMAXINFO32 *mmi = (MINMAXINFO32 *)HeapAlloc( SystemHeap, 0,
663 sizeof(*mmi) + sizeof(LPARAM));
664 if (!mmi) return -1;
665 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16*)PTR_SEG_TO_LIN(*plparam),
666 mmi );
667 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
668 *plparam = (LPARAM)mmi;
670 return 1;
671 case WM_GETTEXT:
672 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
673 return 0;
674 case WM_MDICREATE:
676 MDICREATESTRUCT16 *cs16 =
677 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
678 MDICREATESTRUCT32A *cs =
679 (MDICREATESTRUCT32A *)HeapAlloc( SystemHeap, 0,
680 sizeof(*cs) + sizeof(LPARAM) );
681 if (!cs) return -1;
682 STRUCT32_MDICREATESTRUCT16to32A( cs16, cs );
683 cs->szTitle = (LPCSTR)PTR_SEG_TO_LIN(cs16->szTitle);
684 cs->szClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->szClass);
685 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
686 *plparam = (LPARAM)cs;
688 return 1;
689 case WM_MDISETMENU:
690 *pwparam32 = (WPARAM32)(HMENU32)LOWORD(*plparam);
691 *plparam = (LPARAM)(HMENU32)HIWORD(*plparam);
692 return 0;
693 case WM_MENUCHAR:
694 case WM_MENUSELECT:
695 *pwparam32 = MAKEWPARAM( wParam16, LOWORD(*plparam) );
696 *plparam = (LPARAM)(HMENU32)HIWORD(*plparam);
697 return 0;
698 case WM_NCCALCSIZE:
700 NCCALCSIZE_PARAMS16 *nc16;
701 NCCALCSIZE_PARAMS32 *nc;
703 nc = (NCCALCSIZE_PARAMS32 *)HeapAlloc( SystemHeap, 0,
704 sizeof(*nc) + sizeof(LPARAM) );
705 if (!nc) return -1;
706 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(*plparam);
707 CONV_RECT16TO32( &nc16->rgrc[0], &nc->rgrc[0] );
708 if (wParam16)
710 nc->lppos = (WINDOWPOS32 *)HeapAlloc( SystemHeap, 0,
711 sizeof(*nc->lppos) );
712 CONV_RECT16TO32( &nc16->rgrc[1], &nc->rgrc[1] );
713 CONV_RECT16TO32( &nc16->rgrc[2], &nc->rgrc[2] );
714 if (nc->lppos) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos), nc->lppos );
716 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
717 *plparam = (LPARAM)nc;
719 return 1;
720 case WM_NCCREATE:
721 case WM_CREATE:
723 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
724 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)HeapAlloc( SystemHeap, 0,
725 sizeof(*cs) + sizeof(LPARAM) );
726 if (!cs) return -1;
727 STRUCT32_CREATESTRUCT16to32A( cs16, cs );
728 cs->lpszName = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszName);
729 cs->lpszClass = (LPCSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
730 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
731 *plparam = (LPARAM)cs;
733 return 1;
734 case WM_PARENTNOTIFY:
735 if ((wParam16 == WM_CREATE) || (wParam16 == WM_DESTROY))
737 *pwparam32 = MAKEWPARAM( wParam16, HIWORD(*plparam) );
738 *plparam = (LPARAM)(HWND32)LOWORD(*plparam);
740 return 0;
741 case WM_SETTEXT:
742 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
743 return 0;
744 case WM_WINDOWPOSCHANGING:
745 case WM_WINDOWPOSCHANGED:
747 WINDOWPOS32 *wp = (WINDOWPOS32 *)HeapAlloc( SystemHeap, 0,
748 sizeof(*wp) + sizeof(LPARAM) );
749 if (!wp) return -1;
750 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(*plparam),
751 wp );
752 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
753 *plparam = (LPARAM)wp;
755 return 1;
756 case WM_ASKCBFORMATNAME:
757 case WM_DEVMODECHANGE:
758 case WM_MDIACTIVATE:
759 case WM_PAINTCLIPBOARD:
760 case WM_SIZECLIPBOARD:
761 case WM_WININICHANGE:
762 fprintf( stderr, "MapMsg16To32A: message %04x needs translation\n",
763 msg16 );
764 return -1;
766 default: /* No translation needed */
767 return 0;
772 /**********************************************************************
773 * WINPROC_UnmapMsg16To32A
775 * Unmap a message that was mapped from 16- to 32-bit Ansi.
777 void WINPROC_UnmapMsg16To32A( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
779 switch(msg)
781 case WM_COMPAREITEM:
782 case WM_DELETEITEM:
783 case WM_DRAWITEM:
784 HeapFree( SystemHeap, 0, (LPVOID)lParam );
785 break;
786 case WM_MEASUREITEM:
788 MEASUREITEMSTRUCT16 *mis16;
789 MEASUREITEMSTRUCT32 *mis = (MEASUREITEMSTRUCT32 *)lParam;
790 lParam = *(LPARAM *)(mis + 1);
791 mis16 = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
792 mis16->itemWidth = (UINT16)mis->itemWidth;
793 mis16->itemHeight = (UINT16)mis->itemHeight;
794 HeapFree( SystemHeap, 0, mis );
796 break;
797 case WM_GETMINMAXINFO:
799 MINMAXINFO32 *mmi = (MINMAXINFO32 *)lParam;
800 lParam = *(LPARAM *)(mmi + 1);
801 STRUCT32_MINMAXINFO32to16( mmi,
802 (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam));
803 HeapFree( SystemHeap, 0, mmi );
805 break;
806 case WM_MDICREATE:
808 MDICREATESTRUCT32A *cs = (MDICREATESTRUCT32A *)lParam;
809 lParam = *(LPARAM *)(cs + 1);
810 STRUCT32_MDICREATESTRUCT32Ato16( cs,
811 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
812 HeapFree( SystemHeap, 0, cs );
814 break;
815 case WM_NCCALCSIZE:
817 NCCALCSIZE_PARAMS16 *nc16;
818 NCCALCSIZE_PARAMS32 *nc = (NCCALCSIZE_PARAMS32 *)lParam;
819 lParam = *(LPARAM *)(nc + 1);
820 nc16 = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
821 CONV_RECT32TO16( &nc->rgrc[0], &nc16->rgrc[0] );
822 if (wParam)
824 CONV_RECT32TO16( &nc->rgrc[1], &nc16->rgrc[1] );
825 CONV_RECT32TO16( &nc->rgrc[2], &nc16->rgrc[2] );
826 if (nc->lppos)
828 STRUCT32_WINDOWPOS32to16( nc->lppos,
829 (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc16->lppos));
830 HeapFree( SystemHeap, 0, nc->lppos );
833 HeapFree( SystemHeap, 0, nc );
835 break;
836 case WM_NCCREATE:
837 case WM_CREATE:
839 CREATESTRUCT32A *cs = (CREATESTRUCT32A *)lParam;
840 lParam = *(LPARAM *)(cs + 1);
841 STRUCT32_CREATESTRUCT32Ato16( cs,
842 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
843 HeapFree( SystemHeap, 0, cs );
845 break;
846 case WM_WINDOWPOSCHANGING:
847 case WM_WINDOWPOSCHANGED:
849 WINDOWPOS32 *wp = (WINDOWPOS32 *)lParam;
850 lParam = *(LPARAM *)(wp + 1);
851 STRUCT32_WINDOWPOS32to16(wp,(WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam));
852 HeapFree( SystemHeap, 0, wp );
854 break;
859 /**********************************************************************
860 * WINPROC_MapMsg16To32W
862 * Map a message from 16- to 32-bit Unicode.
863 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
865 INT32 WINPROC_MapMsg16To32W( UINT16 msg16, WPARAM16 wParam16, UINT32 *pmsg32,
866 WPARAM32 *pwparam32, LPARAM *plparam )
868 switch(msg16)
870 case WM_GETTEXT:
871 case WM_SETTEXT:
872 *plparam = (LPARAM)PTR_SEG_TO_LIN(*plparam);
873 return WINPROC_MapMsg32ATo32W( *pmsg32, *pwparam32, plparam );
874 case WM_NCCREATE:
875 case WM_CREATE:
877 CREATESTRUCT16 *cs16 = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
878 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)HeapAlloc( SystemHeap, 0,
879 sizeof(*cs) + sizeof(LPARAM) );
880 if (!cs) return -1;
881 STRUCT32_CREATESTRUCT16to32A( cs16, (CREATESTRUCT32A *)cs );
882 cs->lpszName = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszName);
883 cs->lpszClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->lpszClass);
884 if (HIWORD(cs->lpszName))
885 cs->lpszName = HEAP_strdupAtoW( SystemHeap, 0,
886 (LPCSTR)cs->lpszName );
887 if (HIWORD(cs->lpszClass))
888 cs->lpszClass = HEAP_strdupAtoW( SystemHeap, 0,
889 (LPCSTR)cs->lpszClass );
890 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
891 *plparam = (LPARAM)cs;
893 return 1;
894 case WM_MDICREATE:
896 MDICREATESTRUCT16 *cs16 =
897 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(*plparam);
898 MDICREATESTRUCT32W *cs =
899 (MDICREATESTRUCT32W *)HeapAlloc( SystemHeap, 0,
900 sizeof(*cs) + sizeof(LPARAM) );
901 if (!cs) return -1;
902 STRUCT32_MDICREATESTRUCT16to32A( cs16, (MDICREATESTRUCT32A *)cs );
903 cs->szTitle = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szTitle);
904 cs->szClass = (LPCWSTR)PTR_SEG_TO_LIN(cs16->szClass);
905 if (HIWORD(cs->szTitle))
906 cs->szTitle = HEAP_strdupAtoW( SystemHeap, 0,
907 (LPCSTR)cs->szTitle );
908 if (HIWORD(cs->szClass))
909 cs->szClass = HEAP_strdupAtoW( SystemHeap, 0,
910 (LPCSTR)cs->szClass );
911 *(LPARAM *)(cs + 1) = *plparam; /* Store the previous lParam */
912 *plparam = (LPARAM)cs;
914 return 1;
915 default: /* No Unicode translation needed */
916 return WINPROC_MapMsg16To32A( msg16, wParam16, pmsg32,
917 pwparam32, plparam );
922 /**********************************************************************
923 * WINPROC_UnmapMsg16To32W
925 * Unmap a message that was mapped from 16- to 32-bit Unicode.
927 void WINPROC_UnmapMsg16To32W( UINT32 msg, WPARAM32 wParam, LPARAM lParam )
929 switch(msg)
931 case WM_GETTEXT:
932 case WM_SETTEXT:
933 WINPROC_UnmapMsg32ATo32W( msg, wParam, lParam );
934 break;
935 case WM_NCCREATE:
936 case WM_CREATE:
938 CREATESTRUCT32W *cs = (CREATESTRUCT32W *)lParam;
939 lParam = *(LPARAM *)(cs + 1);
940 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCT32A *)cs,
941 (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
942 if (HIWORD(cs->lpszName))
943 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszName );
944 if (HIWORD(cs->lpszClass))
945 HeapFree( SystemHeap, 0, (LPVOID)cs->lpszClass );
946 HeapFree( SystemHeap, 0, cs );
948 break;
949 case WM_MDICREATE:
951 MDICREATESTRUCT32W *cs = (MDICREATESTRUCT32W *)lParam;
952 lParam = *(LPARAM *)(cs + 1);
953 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCT32A *)cs,
954 (MDICREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam) );
955 if (HIWORD(cs->szTitle))
956 HeapFree( SystemHeap, 0, (LPVOID)cs->szTitle );
957 if (HIWORD(cs->szClass))
958 HeapFree( SystemHeap, 0, (LPVOID)cs->szClass );
959 HeapFree( SystemHeap, 0, cs );
961 break;
962 default:
963 WINPROC_UnmapMsg16To32A( msg, wParam, lParam );
964 break;
969 /**********************************************************************
970 * WINPROC_MapMsg32ATo16
972 * Map a message from 32-bit Ansi to 16-bit.
973 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
975 INT32 WINPROC_MapMsg32ATo16( UINT32 msg32, WPARAM32 wParam32, UINT16 *pmsg16,
976 WPARAM16 *pwparam16, LPARAM *plparam )
978 *pmsg16 = (UINT16)msg32;
979 *pwparam16 = (WPARAM16)LOWORD(wParam32);
980 switch(msg32)
982 case BM_GETCHECK32:
983 case BM_SETCHECK32:
984 case BM_GETSTATE32:
985 case BM_SETSTATE32:
986 case BM_SETSTYLE32:
987 *pmsg16 = (UINT16)msg32 + (BM_GETCHECK16 - BM_GETCHECK32);
988 return 0;
989 case LB_CARETOFF32:
990 case LB_CARETON32:
991 case LB_DELETESTRING32:
992 case LB_GETANCHORINDEX32:
993 case LB_GETCARETINDEX32:
994 case LB_GETCOUNT32:
995 case LB_GETCURSEL32:
996 case LB_GETHORIZONTALEXTENT32:
997 case LB_GETITEMDATA32:
998 case LB_GETITEMHEIGHT32:
999 case LB_GETSEL32:
1000 case LB_GETSELCOUNT32:
1001 case LB_GETTEXTLEN32:
1002 case LB_GETTOPINDEX32:
1003 case LB_RESETCONTENT32:
1004 case LB_SELITEMRANGE32:
1005 case LB_SELITEMRANGEEX32:
1006 case LB_SETANCHORINDEX32:
1007 case LB_SETCARETINDEX32:
1008 case LB_SETCOLUMNWIDTH32:
1009 case LB_SETCURSEL32:
1010 case LB_SETHORIZONTALEXTENT32:
1011 case LB_SETITEMDATA32:
1012 case LB_SETITEMHEIGHT32:
1013 case LB_SETSEL32:
1014 case LB_SETTOPINDEX32:
1015 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING32);
1016 return 0;
1017 case LB_ADDSTRING32:
1018 case LB_FINDSTRING32:
1019 case LB_FINDSTRINGEXACT32:
1020 case LB_INSERTSTRING32:
1021 case LB_SELECTSTRING32:
1022 case LB_DIR32:
1023 case LB_ADDFILE32:
1024 /* case LB_GETTEXT32: FIXME */
1026 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1027 if (!str) return -1;
1028 *plparam = (LPARAM)SEGPTR_GET(str);
1030 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING32);
1031 return 1;
1032 case LB_GETITEMRECT32:
1034 RECT16 *rect;
1035 rect = (RECT16 *)SEGPTR_ALLOC( sizeof(RECT16) + sizeof(LPARAM) );
1036 if (!rect) return -1;
1037 *(LPARAM *)(rect + 1) = *plparam; /* Store the previous lParam */
1038 *plparam = (LPARAM)SEGPTR_GET(rect);
1040 return 1;
1041 case LB_GETSELITEMS32:
1043 LPINT16 items;
1044 *pwparam16 = (WPARAM16)MIN( wParam32, 0x7f80 ); /* Must be < 64K */
1045 if (!(items = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1046 + sizeof(LPARAM)))) return -1;
1047 *((LPARAM *)items)++ = *plparam; /* Store the previous lParam */
1048 *plparam = (LPARAM)SEGPTR_GET(items);
1050 return 1;
1051 case LB_SETTABSTOPS32:
1052 if (wParam32)
1054 INT32 i;
1055 LPINT16 stops;
1056 *pwparam16 = (WPARAM16)MIN( wParam32, 0x7f80 ); /* Must be < 64K */
1057 if (!(stops = SEGPTR_ALLOC( *pwparam16 * sizeof(INT16)
1058 + sizeof(LPARAM)))) return -1;
1059 for (i = 0; i < *pwparam16; i++) stops[i] = *((LPINT32)*plparam+i);
1060 *plparam = (LPARAM)SEGPTR_GET(stops);
1061 return 1;
1063 *pmsg16 = LB_SETTABSTOPS16;
1064 return 0;
1065 case WM_ACTIVATE:
1066 case WM_CHARTOITEM:
1067 case WM_COMMAND:
1068 case WM_VKEYTOITEM:
1069 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32) );
1070 return 0;
1071 case WM_HSCROLL:
1072 case WM_VSCROLL:
1073 *plparam = MAKELPARAM( HIWORD(wParam32), (HWND16)*plparam );
1074 return 0;
1075 case WM_CTLCOLORMSGBOX:
1076 case WM_CTLCOLOREDIT:
1077 case WM_CTLCOLORLISTBOX:
1078 case WM_CTLCOLORBTN:
1079 case WM_CTLCOLORDLG:
1080 case WM_CTLCOLORSCROLLBAR:
1081 case WM_CTLCOLORSTATIC:
1082 *pmsg16 = WM_CTLCOLOR;
1083 *plparam = MAKELPARAM( (HWND16)*plparam,
1084 (WORD)msg32 - WM_CTLCOLORMSGBOX );
1085 return 0;
1086 case WM_COMPAREITEM:
1088 COMPAREITEMSTRUCT32 *cis32 = (COMPAREITEMSTRUCT32 *)*plparam;
1089 COMPAREITEMSTRUCT16 *cis = SEGPTR_NEW(COMPAREITEMSTRUCT16);
1090 if (!cis) return -1;
1091 cis->CtlType = (UINT16)cis32->CtlType;
1092 cis->CtlID = (UINT16)cis32->CtlID;
1093 cis->hwndItem = (HWND16)cis32->hwndItem;
1094 cis->itemID1 = (UINT16)cis32->itemID1;
1095 cis->itemData1 = cis32->itemData1;
1096 cis->itemID2 = (UINT16)cis32->itemID2;
1097 cis->itemData2 = cis32->itemData2;
1098 *plparam = (LPARAM)SEGPTR_GET(cis);
1100 return 1;
1101 case WM_DELETEITEM:
1103 DELETEITEMSTRUCT32 *dis32 = (DELETEITEMSTRUCT32 *)*plparam;
1104 DELETEITEMSTRUCT16 *dis = SEGPTR_NEW(DELETEITEMSTRUCT16);
1105 if (!dis) return -1;
1106 dis->CtlType = (UINT16)dis32->CtlType;
1107 dis->CtlID = (UINT16)dis32->CtlID;
1108 dis->itemID = (UINT16)dis32->itemID;
1109 dis->hwndItem = (HWND16)dis32->hwndItem;
1110 dis->itemData = dis32->itemData;
1111 *plparam = (LPARAM)SEGPTR_GET(dis);
1113 return 1;
1114 case WM_DRAWITEM:
1116 DRAWITEMSTRUCT32 *dis32 = (DRAWITEMSTRUCT32 *)*plparam;
1117 DRAWITEMSTRUCT16 *dis = SEGPTR_NEW(DRAWITEMSTRUCT16);
1118 if (!dis) return -1;
1119 dis->CtlType = (UINT16)dis32->CtlType;
1120 dis->CtlID = (UINT16)dis32->CtlID;
1121 dis->itemID = (UINT16)dis32->itemID;
1122 dis->itemAction = (UINT16)dis32->itemAction;
1123 dis->itemState = (UINT16)dis32->itemState;
1124 dis->hwndItem = (HWND16)dis32->hwndItem;
1125 dis->hDC = (HDC16)dis32->hDC;
1126 dis->itemData = dis32->itemData;
1127 CONV_RECT32TO16( &dis32->rcItem, &dis->rcItem );
1128 *plparam = (LPARAM)SEGPTR_GET(dis);
1130 return 1;
1131 case WM_MEASUREITEM:
1133 MEASUREITEMSTRUCT32 *mis32 = (MEASUREITEMSTRUCT32 *)*plparam;
1134 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)
1135 SEGPTR_ALLOC(sizeof(*mis)+sizeof(LPARAM));
1136 if (!mis) return -1;
1137 mis->CtlType = (UINT16)mis32->CtlType;
1138 mis->CtlID = (UINT16)mis32->CtlID;
1139 mis->itemID = (UINT16)mis32->itemID;
1140 mis->itemWidth = (UINT16)mis32->itemWidth;
1141 mis->itemHeight = (UINT16)mis32->itemHeight;
1142 mis->itemData = mis32->itemData;
1143 *(LPARAM *)(mis + 1) = *plparam; /* Store the previous lParam */
1144 *plparam = (LPARAM)SEGPTR_GET(mis);
1146 return 1;
1147 case WM_GETMINMAXINFO:
1149 MINMAXINFO16 *mmi = (MINMAXINFO16 *)SEGPTR_ALLOC( sizeof(*mmi) +
1150 sizeof(LPARAM) );
1151 if (!mmi) return -1;
1152 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32 *)*plparam, mmi );
1153 *(LPARAM *)(mmi + 1) = *plparam; /* Store the previous lParam */
1154 *plparam = (LPARAM)SEGPTR_GET(mmi);
1156 return 1;
1157 case WM_GETTEXT:
1159 LPSTR str;
1160 *pwparam16 = (WPARAM16)MIN( wParam32, 0xff80 ); /* Must be < 64K */
1161 if (!(str = SEGPTR_ALLOC(*pwparam16 + sizeof(LPARAM)))) return -1;
1162 *((LPARAM *)str)++ = *plparam; /* Store the previous lParam */
1163 *plparam = (LPARAM)SEGPTR_GET(str);
1165 return 1;
1166 case WM_MDICREATE:
1168 MDICREATESTRUCT16 *cs;
1169 MDICREATESTRUCT32A *cs32 = (MDICREATESTRUCT32A *)*plparam;
1170 LPSTR name, cls;
1172 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1173 STRUCT32_MDICREATESTRUCT32Ato16( cs32, cs );
1174 name = SEGPTR_STRDUP( cs32->szTitle );
1175 cls = SEGPTR_STRDUP( cs32->szClass );
1176 cs->szTitle = SEGPTR_GET(name);
1177 cs->szClass = SEGPTR_GET(cls);
1178 *plparam = (LPARAM)SEGPTR_GET(cs);
1180 return 1;
1181 case WM_MDISETMENU:
1182 *pwparam16 = TRUE; /* FIXME? */
1183 *plparam = MAKELPARAM( (HMENU16)LOWORD(wParam32),
1184 (HMENU16)LOWORD(*plparam) );
1185 return 0;
1186 case WM_MENUCHAR:
1187 case WM_MENUSELECT:
1188 *plparam = MAKELPARAM( HIWORD(wParam32), (HMENU16)*plparam );
1189 return 0;
1190 case WM_NCCALCSIZE:
1192 NCCALCSIZE_PARAMS32 *nc32 = (NCCALCSIZE_PARAMS32 *)*plparam;
1193 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)SEGPTR_ALLOC( sizeof(*nc) + sizeof(LPARAM) );
1194 if (!nc) return -1;
1196 CONV_RECT32TO16( &nc32->rgrc[0], &nc->rgrc[0] );
1197 if (wParam32)
1199 WINDOWPOS16 *wp;
1200 CONV_RECT32TO16( &nc32->rgrc[1], &nc->rgrc[1] );
1201 CONV_RECT32TO16( &nc32->rgrc[2], &nc->rgrc[2] );
1202 if (!(wp = SEGPTR_NEW(WINDOWPOS16)))
1204 SEGPTR_FREE(nc);
1205 return -1;
1207 STRUCT32_WINDOWPOS32to16( nc32->lppos, wp );
1208 nc->lppos = SEGPTR_GET(wp);
1210 *(LPARAM *)(nc + 1) = *plparam; /* Store the previous lParam */
1211 *plparam = (LPARAM)SEGPTR_GET(nc);
1213 return 1;
1214 case WM_NCCREATE:
1215 case WM_CREATE:
1217 CREATESTRUCT16 *cs;
1218 CREATESTRUCT32A *cs32 = (CREATESTRUCT32A *)*plparam;
1219 LPSTR name, cls;
1221 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1222 STRUCT32_CREATESTRUCT32Ato16( cs32, cs );
1223 name = SEGPTR_STRDUP( cs32->lpszName );
1224 cls = SEGPTR_STRDUP( cs32->lpszClass );
1225 cs->lpszName = SEGPTR_GET(name);
1226 cs->lpszClass = SEGPTR_GET(cls);
1227 *plparam = (LPARAM)SEGPTR_GET(cs);
1229 return 1;
1230 case WM_PARENTNOTIFY:
1231 if ((LOWORD(wParam32)==WM_CREATE) || (LOWORD(wParam32)==WM_DESTROY))
1232 *plparam = MAKELPARAM( (HWND16)*plparam, HIWORD(wParam32));
1233 /* else nothing to do */
1234 return 0;
1235 case WM_SETTEXT:
1237 LPSTR str = SEGPTR_STRDUP( (LPSTR)*plparam );
1238 if (!str) return -1;
1239 *plparam = (LPARAM)SEGPTR_GET(str);
1241 return 1;
1242 case WM_WINDOWPOSCHANGING:
1243 case WM_WINDOWPOSCHANGED:
1245 WINDOWPOS16 *wp = (WINDOWPOS16 *)SEGPTR_ALLOC( sizeof(*wp) +
1246 sizeof(LPARAM) );
1247 if (!wp) return -1;
1248 STRUCT32_WINDOWPOS32to16( (WINDOWPOS32 *)*plparam, wp );
1249 *(LPARAM *)(wp + 1) = *plparam; /* Store the previous lParam */
1250 *plparam = (LPARAM)SEGPTR_GET(wp);
1252 return 1;
1253 case WM_ASKCBFORMATNAME:
1254 case WM_DEVMODECHANGE:
1255 case WM_MDIACTIVATE:
1256 case WM_PAINTCLIPBOARD:
1257 case WM_SIZECLIPBOARD:
1258 case WM_WININICHANGE:
1259 fprintf( stderr, "MapMsg32ATo16: message %04x needs translation\n",
1260 msg32 );
1261 return -1;
1263 default: /* No translation needed */
1264 return 0;
1269 /**********************************************************************
1270 * WINPROC_UnmapMsg32ATo16
1272 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
1274 void WINPROC_UnmapMsg32ATo16( UINT32 msg, WPARAM16 wParam, LPARAM lParam )
1276 switch(msg)
1278 case LB_ADDFILE32:
1279 case LB_ADDSTRING32:
1280 case LB_DIR32:
1281 case LB_FINDSTRING32:
1282 case LB_FINDSTRINGEXACT32:
1283 case LB_INSERTSTRING32:
1284 case LB_SELECTSTRING32:
1285 case LB_SETTABSTOPS32:
1286 case WM_COMPAREITEM:
1287 case WM_DELETEITEM:
1288 case WM_DRAWITEM:
1289 case WM_SETTEXT:
1290 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam) );
1291 break;
1292 case LB_GETITEMRECT32:
1294 RECT16 *rect = (RECT16 *)PTR_SEG_TO_LIN(lParam);
1295 lParam = *(LPARAM *)(rect + 1);
1296 CONV_RECT16TO32( rect, (RECT32 *)lParam );
1297 SEGPTR_FREE( rect );
1299 break;
1300 case LB_GETSELITEMS32:
1302 INT32 i;
1303 LPINT16 items = (LPINT16)PTR_SEG_TO_LIN(lParam);
1304 lParam = *((LPARAM *)items - 1);
1305 for (i = 0; i < wParam; i++) *((LPINT32)lParam + i) = items[i];
1306 SEGPTR_FREE( (LPARAM *)items - 1 );
1308 break;
1309 case WM_MEASUREITEM:
1311 MEASUREITEMSTRUCT16 *mis = (MEASUREITEMSTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1312 MEASUREITEMSTRUCT32 *mis32 = *(MEASUREITEMSTRUCT32 **)(mis + 1);
1313 mis32->itemWidth = mis->itemWidth;
1314 mis32->itemHeight = mis->itemHeight;
1315 SEGPTR_FREE(mis);
1317 break;
1318 case WM_GETMINMAXINFO:
1320 MINMAXINFO16 *mmi = (MINMAXINFO16 *)PTR_SEG_TO_LIN(lParam);
1321 lParam = *(LPARAM *)(mmi + 1);
1322 STRUCT32_MINMAXINFO16to32( mmi, (MINMAXINFO32 *)lParam );
1323 SEGPTR_FREE(mmi);
1325 break;
1326 case WM_GETTEXT:
1328 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(lParam);
1329 lParam = *((LPARAM *)str - 1);
1330 lstrcpyn32A( (LPSTR)lParam, str, wParam );
1331 SEGPTR_FREE( (LPARAM *)str - 1 );
1333 break;
1334 case WM_MDICREATE:
1336 MDICREATESTRUCT16 *cs = (MDICREATESTRUCT16*)PTR_SEG_TO_LIN(lParam);
1337 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szTitle) );
1338 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->szClass) );
1339 SEGPTR_FREE( cs );
1341 break;
1342 case WM_NCCALCSIZE:
1344 NCCALCSIZE_PARAMS32 *nc32;
1345 NCCALCSIZE_PARAMS16 *nc = (NCCALCSIZE_PARAMS16 *)PTR_SEG_TO_LIN(lParam);
1346 lParam = *(LPARAM *)(nc + 1);
1347 nc32 = (NCCALCSIZE_PARAMS32 *)lParam;
1348 CONV_RECT16TO32( &nc->rgrc[0], &nc32->rgrc[0] );
1349 if (wParam)
1351 CONV_RECT16TO32( &nc->rgrc[1], &nc32->rgrc[1] );
1352 CONV_RECT16TO32( &nc->rgrc[2], &nc32->rgrc[2] );
1353 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16 *)PTR_SEG_TO_LIN(nc->lppos),
1354 nc32->lppos );
1355 SEGPTR_FREE( PTR_SEG_TO_LIN(nc->lppos) );
1357 SEGPTR_FREE(nc);
1359 break;
1360 case WM_NCCREATE:
1361 case WM_CREATE:
1363 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1364 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszName) );
1365 SEGPTR_FREE( PTR_SEG_TO_LIN(cs->lpszClass) );
1366 SEGPTR_FREE( cs );
1368 break;
1369 case WM_WINDOWPOSCHANGING:
1370 case WM_WINDOWPOSCHANGED:
1372 WINDOWPOS16 *wp = (WINDOWPOS16 *)PTR_SEG_TO_LIN(lParam);
1373 lParam = *(LPARAM *)(wp + 1);
1374 STRUCT32_WINDOWPOS16to32( wp, (WINDOWPOS32 *)lParam );
1375 SEGPTR_FREE(wp);
1377 break;
1382 /**********************************************************************
1383 * WINPROC_MapMsg32WTo16
1385 * Map a message from 32-bit Unicode to 16-bit.
1386 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1388 INT32 WINPROC_MapMsg32WTo16( UINT32 msg32, WPARAM32 wParam32, UINT16 *pmsg16,
1389 WPARAM16 *pwparam16, LPARAM *plparam )
1391 switch(msg32)
1393 case LB_ADDSTRING32:
1394 case LB_FINDSTRING32:
1395 case LB_FINDSTRINGEXACT32:
1396 case LB_INSERTSTRING32:
1397 case LB_SELECTSTRING32:
1398 case LB_DIR32:
1399 case LB_ADDFILE32:
1401 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
1402 if (!str) return -1;
1403 *pmsg16 = (UINT16)msg32 + (LB_ADDSTRING16 - LB_ADDSTRING32);
1404 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1405 *plparam = (LPARAM)SEGPTR_GET(str);
1407 return 1;
1408 case WM_NCCREATE:
1409 case WM_CREATE:
1411 CREATESTRUCT16 *cs;
1412 CREATESTRUCT32W *cs32 = (CREATESTRUCT32W *)*plparam;
1413 LPSTR name, cls;
1415 if (!(cs = SEGPTR_NEW(CREATESTRUCT16))) return -1;
1416 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCT32A *)cs32, cs );
1417 name = SEGPTR_STRDUP_WtoA( cs32->lpszName );
1418 cls = SEGPTR_STRDUP_WtoA( cs32->lpszClass );
1419 cs->lpszName = SEGPTR_GET(name);
1420 cs->lpszClass = SEGPTR_GET(cls);
1421 *pmsg16 = (UINT16)msg32;
1422 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1423 *plparam = (LPARAM)SEGPTR_GET(cs);
1425 return 1;
1426 case WM_MDICREATE:
1428 MDICREATESTRUCT16 *cs;
1429 MDICREATESTRUCT32W *cs32 = (MDICREATESTRUCT32W *)*plparam;
1430 LPSTR name, cls;
1432 if (!(cs = SEGPTR_NEW(MDICREATESTRUCT16))) return -1;
1433 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCT32A *)cs32, cs );
1434 name = SEGPTR_STRDUP_WtoA( cs32->szTitle );
1435 cls = SEGPTR_STRDUP_WtoA( cs32->szClass );
1436 cs->szTitle = SEGPTR_GET(name);
1437 cs->szClass = SEGPTR_GET(cls);
1438 *pmsg16 = (UINT16)msg32;
1439 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1440 *plparam = (LPARAM)SEGPTR_GET(cs);
1442 return 1;
1443 case WM_SETTEXT:
1445 LPSTR str = SEGPTR_STRDUP_WtoA( (LPWSTR)*plparam );
1446 if (!str) return -1;
1447 *pmsg16 = (UINT16)msg32;
1448 *pwparam16 = (WPARAM16)LOWORD(wParam32);
1449 *plparam = (LPARAM)SEGPTR_GET(str);
1451 return 1;
1452 default: /* No Unicode translation needed */
1453 return WINPROC_MapMsg32ATo16( msg32, wParam32, pmsg16,
1454 pwparam16, plparam );
1459 /**********************************************************************
1460 * WINPROC_UnmapMsg32WTo16
1462 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
1464 void WINPROC_UnmapMsg32WTo16( UINT32 msg, WPARAM16 wParam, LPARAM lParam )
1466 switch(msg)
1468 case WM_GETTEXT:
1470 LPSTR str = (LPSTR)PTR_SEG_TO_LIN(lParam);
1471 lParam = *((LPARAM *)str - 1);
1472 lstrcpyAtoW( (LPWSTR)lParam, str );
1473 SEGPTR_FREE( (LPARAM *)str - 1 );
1475 break;
1476 default:
1477 WINPROC_UnmapMsg32ATo16( msg, wParam, lParam );
1478 break;
1483 /**********************************************************************
1484 * WINPROC_CallProc32ATo32W
1486 * Call a window procedure, translating args from Ansi to Unicode.
1488 static LRESULT WINPROC_CallProc32ATo32W( WNDPROC32 func, HWND32 hwnd,
1489 UINT32 msg, WPARAM32 wParam,
1490 LPARAM lParam )
1492 LRESULT result;
1494 if (WINPROC_MapMsg32ATo32W( msg, wParam, &lParam ) == -1) return 0;
1495 result = CallWndProc32( func, hwnd, msg, wParam, lParam );
1496 WINPROC_UnmapMsg32ATo32W( msg, wParam, lParam );
1497 return result;
1501 /**********************************************************************
1502 * WINPROC_CallProc32WTo32A
1504 * Call a window procedure, translating args from Unicode to Ansi.
1506 static LRESULT WINPROC_CallProc32WTo32A( WNDPROC32 func, HWND32 hwnd,
1507 UINT32 msg, WPARAM32 wParam,
1508 LPARAM lParam )
1510 LRESULT result;
1512 if (WINPROC_MapMsg32WTo32A( msg, wParam, &lParam ) == -1) return 0;
1513 result = CallWndProc32( func, hwnd, msg, wParam, lParam );
1514 WINPROC_UnmapMsg32WTo32A( msg, wParam, lParam );
1515 return result;
1519 /**********************************************************************
1520 * WINPROC_CallProc16To32A
1522 * Call a 32-bit window procedure, translating the 16-bit args.
1524 LRESULT WINPROC_CallProc16To32A( HWND16 hwnd, UINT16 msg,
1525 WPARAM16 wParam, LPARAM lParam,
1526 WNDPROC32 func )
1528 LRESULT result;
1529 UINT32 msg32;
1530 WPARAM32 wParam32;
1532 if (WINPROC_MapMsg16To32A( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
1533 return 0;
1534 result = CallWndProc32( func, hwnd, msg32, wParam32, lParam );
1535 WINPROC_UnmapMsg16To32A( msg32, wParam32, lParam );
1536 return result;
1540 /**********************************************************************
1541 * WINPROC_CallProc16To32W
1543 * Call a 32-bit window procedure, translating the 16-bit args.
1545 LRESULT WINPROC_CallProc16To32W( HWND16 hwnd, UINT16 msg,
1546 WPARAM16 wParam, LPARAM lParam,
1547 WNDPROC32 func )
1549 LRESULT result;
1550 UINT32 msg32;
1551 WPARAM32 wParam32;
1553 if (WINPROC_MapMsg16To32W( msg, wParam, &msg32, &wParam32, &lParam ) == -1)
1554 return 0;
1555 result = CallWndProc32( func, hwnd, msg32, wParam32, lParam );
1556 WINPROC_UnmapMsg16To32W( msg32, wParam32, lParam );
1557 return result;
1561 /**********************************************************************
1562 * WINPROC_CallProc32ATo16
1564 * Call a 16-bit window procedure, translating the 32-bit args.
1566 static LRESULT WINPROC_CallProc32ATo16( WNDPROC16 func, HWND32 hwnd,
1567 UINT32 msg, WPARAM32 wParam,
1568 LPARAM lParam )
1570 LRESULT result;
1571 UINT16 msg16;
1572 WPARAM16 wParam16;
1573 WND *wndPtr = WIN_FindWndPtr( hwnd );
1574 WORD ds = CURRENT_DS;
1576 if (WINPROC_MapMsg32ATo16( msg, wParam, &msg16, &wParam16, &lParam ) == -1)
1577 return 0;
1578 if (wndPtr) CURRENT_DS = wndPtr->hInstance;
1579 result = CallWndProc16( func, hwnd, msg16, wParam16, lParam );
1580 CURRENT_DS = ds;
1581 WINPROC_UnmapMsg32ATo16( msg, wParam16, lParam );
1582 return result;
1586 /**********************************************************************
1587 * WINPROC_CallProc32WTo16
1589 * Call a 16-bit window procedure, translating the 32-bit args.
1591 static LRESULT WINPROC_CallProc32WTo16( WNDPROC16 func, HWND32 hwnd,
1592 UINT32 msg, WPARAM32 wParam,
1593 LPARAM lParam )
1595 LRESULT result;
1596 UINT16 msg16;
1597 WPARAM16 wParam16;
1598 WND *wndPtr = WIN_FindWndPtr( hwnd );
1599 WORD ds = CURRENT_DS;
1601 if (WINPROC_MapMsg32WTo16( msg, wParam, &msg16, &wParam16, &lParam ) == -1)
1602 return 0;
1603 if (wndPtr) CURRENT_DS = wndPtr->hInstance;
1604 result = CallWndProc16( func, hwnd, msg16, wParam16, lParam );
1605 CURRENT_DS = ds;
1606 WINPROC_UnmapMsg32WTo16( msg, wParam16, lParam );
1607 return result;
1611 /**********************************************************************
1612 * CallWindowProc16 (USER.122)
1614 LRESULT CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
1615 WPARAM16 wParam, LPARAM lParam )
1617 LRESULT result;
1618 WND *wndPtr;
1619 WINDOWPROC *proc = WINPROC_GetPtr( func );
1620 WORD ds = CURRENT_DS;
1622 if (!proc)
1624 wndPtr = WIN_FindWndPtr( hwnd );
1625 if (wndPtr) CURRENT_DS = wndPtr->hInstance;
1626 result = CallWndProc16( (FARPROC16)func, hwnd, msg, wParam, lParam );
1627 CURRENT_DS = ds;
1628 return result;
1630 #if testing
1631 wndPtr = WIN_FindWndPtr( hwnd );
1632 if (wndPtr) CURRENT_DS = wndPtr->hInstance;
1633 result = CallWndProc16( WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_16),
1634 hwnd, msg, wParam, lParam );
1635 CURRENT_DS = ds;
1636 return result;
1637 #endif
1639 switch(proc->type)
1641 case WIN_PROC_16:
1642 if (!proc->thunk.t_from32.proc) return 0;
1643 wndPtr = WIN_FindWndPtr( hwnd );
1644 if (wndPtr) CURRENT_DS = wndPtr->hInstance;
1645 #ifndef WINELIB
1646 if ((msg == WM_CREATE) || (msg == WM_NCCREATE))
1648 CREATESTRUCT16 *cs = (CREATESTRUCT16 *)PTR_SEG_TO_LIN(lParam);
1649 /* Build the CREATESTRUCT on the 16-bit stack. */
1650 /* This is really ugly, but some programs (notably the */
1651 /* "Undocumented Windows" examples) want it that way. */
1652 result = CallWndProcNCCREATE16( proc->thunk.t_from32.proc,
1653 cs->dwExStyle, cs->lpszClass, cs->lpszName, cs->style,
1654 cs->x, cs->y, cs->cx, cs->cy, cs->hwndParent, cs->hMenu,
1655 cs->hInstance, (LONG)cs->lpCreateParams, hwnd, msg, wParam,
1656 MAKELONG( IF1632_Saved16_sp-sizeof(CREATESTRUCT16),
1657 IF1632_Saved16_ss ) );
1658 CURRENT_DS = ds;
1659 return result;
1661 #endif
1662 result = CallWndProc16( proc->thunk.t_from32.proc,
1663 hwnd, msg, wParam, lParam );
1664 CURRENT_DS = ds;
1665 return result;
1667 case WIN_PROC_32A:
1668 if (!proc->thunk.t_from16.proc) return 0;
1669 return WINPROC_CallProc16To32A( hwnd, msg, wParam, lParam,
1670 proc->thunk.t_from16.proc );
1671 case WIN_PROC_32W:
1672 if (!proc->thunk.t_from16.proc) return 0;
1673 return WINPROC_CallProc16To32W( hwnd, msg, wParam, lParam,
1674 proc->thunk.t_from16.proc );
1675 default:
1676 fprintf( stderr, "CallWindowProc16: invalid proc %p\n", proc );
1677 return 0;
1682 /**********************************************************************
1683 * CallWindowProc32A (USER32.17)
1685 LRESULT CallWindowProc32A( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
1686 WPARAM32 wParam, LPARAM lParam )
1688 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
1690 if (!proc) return CallWndProc32( func, hwnd, msg, wParam, lParam );
1692 #if testing
1693 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32A );
1694 return CallWndProc32( func, hwnd, msg, wParam, lParam );
1695 #endif
1697 switch(proc->type)
1699 case WIN_PROC_16:
1700 if (!proc->thunk.t_from32.proc) return 0;
1701 return WINPROC_CallProc32ATo16( proc->thunk.t_from32.proc,
1702 hwnd, msg, wParam, lParam );
1703 case WIN_PROC_32A:
1704 if (!proc->thunk.t_from16.proc) return 0;
1705 return CallWndProc32( proc->thunk.t_from16.proc,
1706 hwnd, msg, wParam, lParam );
1707 case WIN_PROC_32W:
1708 if (!proc->thunk.t_from16.proc) return 0;
1709 return WINPROC_CallProc32ATo32W( proc->thunk.t_from16.proc,
1710 hwnd, msg, wParam, lParam );
1711 default:
1712 fprintf( stderr, "CallWindowProc32A: invalid proc %p\n", proc );
1713 return 0;
1718 /**********************************************************************
1719 * CallWindowProc32W (USER32.18)
1721 LRESULT CallWindowProc32W( WNDPROC32 func, HWND32 hwnd, UINT32 msg,
1722 WPARAM32 wParam, LPARAM lParam )
1724 WINDOWPROC *proc = WINPROC_GetPtr( (WNDPROC16)func );
1726 if (!proc) return CallWndProc32( func, hwnd, msg, wParam, lParam );
1728 #if testing
1729 func = WINPROC_GetProc( (HWINDOWPROC)proc, WIN_PROC_32W );
1730 return CallWndProc32( func, hwnd, msg, wParam, lParam );
1731 #endif
1733 switch(proc->type)
1735 case WIN_PROC_16:
1736 if (!proc->thunk.t_from32.proc) return 0;
1737 return WINPROC_CallProc32WTo16( proc->thunk.t_from32.proc,
1738 hwnd, msg, wParam, lParam );
1739 case WIN_PROC_32A:
1740 if (!proc->thunk.t_from16.proc) return 0;
1741 return WINPROC_CallProc32WTo32A( proc->thunk.t_from16.proc,
1742 hwnd, msg, wParam, lParam );
1743 case WIN_PROC_32W:
1744 if (!proc->thunk.t_from16.proc) return 0;
1745 return CallWndProc32( proc->thunk.t_from16.proc,
1746 hwnd, msg, wParam, lParam );
1747 default:
1748 fprintf( stderr, "CallWindowProc32W: invalid proc %p\n", proc );
1749 return 0;