2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
12 #include "selectors.h"
13 #include "stackframe.h"
20 /* Window procedure 16-bit thunk; see BuildSpec16Files() in tools/build.c */
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
;
33 } WINPROC_THUNK_FROM16
;
35 /* Window procedure 32-bit thunk; see BuildSpec32Files() in tools/build.c */
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 */
54 BYTE jmp
; /* jmp proc (relative jump) */
55 WNDPROC32 proc WINE_PACKED
;
60 WINPROC_THUNK_FROM16 t_from16
;
61 WINPROC_THUNK_FROM32 t_from32
;
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 */
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
,
83 LRESULT
WINPROC_CallProc16To32W( HWND16 hwnd
, UINT16 msg
,
84 WPARAM16 wParam
, LPARAM lParam
,
86 static LRESULT
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND32 hwnd
,
87 UINT32 msg
, WPARAM32 wParam
,
89 static LRESULT
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND32 hwnd
,
90 UINT32 msg
, WPARAM32 wParam
,
94 extern void CallFrom16_long_wwwll(void);
95 extern void CallFrom32_stdcall_5(void);
97 static void CallFrom16_long_wwwll(void) {}
98 static void CallFrom32_stdcall_5(void) {}
101 static HANDLE32 WinProcHeap
;
103 /**********************************************************************
106 BOOL32
WINPROC_Init(void)
108 WinProcHeap
= HeapCreate( HEAP_WINE_SEGPTR
| HEAP_WINE_CODESEG
, 0, 0 );
111 fprintf( stderr
, "Unable to create winproc heap\n" );
118 /**********************************************************************
121 * Return a pointer to the win proc.
123 static WINDOWPROC
*WINPROC_GetPtr( WNDPROC16 handle
)
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
;
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
)))
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));
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));
218 /* Should not happen */
221 proc
->magic
= WINPROC_MAGIC
;
225 dprintf_win( stddeb
, "WINPROC_AllocWinProc(%08x,%d): returning %08x\n",
226 (UINT32
)func
, type
, (UINT32
)proc
);
231 /**********************************************************************
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
;
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
;
251 return (WNDPROC16
)&((WINDOWPROC
*)proc
)->jmp
;
256 /**********************************************************************
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
);
274 if (*ppPrev
== proc
) break;
278 if (((*ppPrev
)->type
== type
) &&
279 (func
== WINPROC_THUNKPROC(*ppPrev
))) break;
281 ppPrev
= &(*ppPrev
)->next
;
284 if (*ppPrev
) /* Remove it from the list */
287 *ppPrev
= proc
->next
;
289 else /* Allocate a new one */
291 if (proc
) /* Was already a win proc */
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
;
310 /**********************************************************************
313 * Free a list of win procs.
315 void WINPROC_FreeProc( HWINDOWPROC proc
)
319 WINDOWPROC
*next
= ((WINDOWPROC
*)proc
)->next
;
320 dprintf_win( stddeb
, "WINPROC_FreeProc: freeing %08x\n", (UINT32
)proc
);
321 HeapFree( WinProcHeap
, 0, proc
);
327 /**********************************************************************
328 * WINPROC_GetProcType
330 * Return the window procedure type.
332 WINDOWPROCTYPE
WINPROC_GetProcType( HWINDOWPROC 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
)
353 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
354 wParam
* sizeof(WCHAR
) + sizeof(LPARAM
) );
356 *ptr
++ = *plparam
; /* Store previous lParam */
357 *plparam
= (LPARAM
)ptr
;
361 *plparam
= (LPARAM
)HEAP_strdupAtoW( SystemHeap
, 0, (LPCSTR
)*plparam
);
362 return (*plparam
? 1 : -1);
366 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)HeapAlloc( SystemHeap
, 0,
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
;
381 MDICREATESTRUCT32W
*cs
=
382 (MDICREATESTRUCT32W
*)HeapAlloc( SystemHeap
, 0, sizeof(*cs
) );
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
;
394 case WM_ASKCBFORMATNAME
:
395 case WM_DEVMODECHANGE
:
397 case WM_PAINTCLIPBOARD
:
398 case WM_SIZECLIPBOARD
:
399 case WM_WININICHANGE
:
400 fprintf( stderr
, "MapMsg32ATo32W: message %04x needs translation\n",
403 default: /* No translation needed */
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
)
420 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
421 lstrcpynWtoA( (LPSTR
)*ptr
, (LPWSTR
)(ptr
+ 1), wParam
);
422 HeapFree( SystemHeap
, 0, ptr
);
426 HeapFree( SystemHeap
, 0, (void *)lParam
);
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
);
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
);
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
)
465 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
466 wParam
+ sizeof(LPARAM
) );
468 *ptr
++ = *plparam
; /* Store previous lParam */
469 *plparam
= (LPARAM
)ptr
;
473 *plparam
= (LPARAM
)HEAP_strdupWtoA( SystemHeap
, 0, (LPCWSTR
)*plparam
);
474 return (*plparam
? 1 : -1);
478 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0,
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
;
493 MDICREATESTRUCT32A
*cs
=
494 (MDICREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0, sizeof(*cs
) );
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
;
506 case WM_ASKCBFORMATNAME
:
507 case WM_DEVMODECHANGE
:
509 case WM_PAINTCLIPBOARD
:
510 case WM_SIZECLIPBOARD
:
511 case WM_WININICHANGE
:
512 fprintf( stderr
, "MapMsg32WTo32A: message %04x needs translation\n",
515 default: /* No translation needed */
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
)
532 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
533 lstrcpynAtoW( (LPWSTR
)*ptr
, (LPSTR
)(ptr
+ 1), wParam
);
534 HeapFree( SystemHeap
, 0, ptr
);
538 HeapFree( SystemHeap
, 0, (void *)lParam
);
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
);
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
);
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
;
582 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
583 *plparam
= (LPARAM
)(HWND32
)LOWORD(*plparam
);
587 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
588 *plparam
= (LPARAM
)(HWND32
)HIWORD(*plparam
);
591 *pmsg32
= WM_CTLCOLORMSGBOX
+ HIWORD(*plparam
);
592 *pwparam32
= (WPARAM32
)(HDC32
)wParam16
;
593 *plparam
= (LPARAM
)(HWND32
)LOWORD(*plparam
);
597 COMPAREITEMSTRUCT16
* cis16
= (COMPAREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
598 COMPAREITEMSTRUCT32
*cis
= (COMPAREITEMSTRUCT32
*)
599 HeapAlloc(SystemHeap
, 0, sizeof(*cis
));
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
;
614 DELETEITEMSTRUCT16
* dis16
= (DELETEITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
615 DELETEITEMSTRUCT32
*dis
= (DELETEITEMSTRUCT32
*)
616 HeapAlloc(SystemHeap
, 0, sizeof(*dis
));
618 dis
->CtlType
= dis16
->CtlType
;
619 dis
->CtlID
= dis16
->CtlID
;
620 dis
->hwndItem
= dis16
->hwndItem
;
621 dis
->itemData
= dis16
->itemData
;
622 *plparam
= (LPARAM
)dis
;
627 MEASUREITEMSTRUCT16
* mis16
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
628 MEASUREITEMSTRUCT32
*mis
= (MEASUREITEMSTRUCT32
*)
629 HeapAlloc(SystemHeap
, 0,
630 sizeof(*mis
) + sizeof(LPARAM
));
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
;
644 DRAWITEMSTRUCT16
* dis16
= (DRAWITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
645 DRAWITEMSTRUCT32
*dis
= (DRAWITEMSTRUCT32
*)HeapAlloc(SystemHeap
, 0,
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
;
660 case WM_GETMINMAXINFO
:
662 MINMAXINFO32
*mmi
= (MINMAXINFO32
*)HeapAlloc( SystemHeap
, 0,
663 sizeof(*mmi
) + sizeof(LPARAM
));
665 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16
*)PTR_SEG_TO_LIN(*plparam
),
667 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
668 *plparam
= (LPARAM
)mmi
;
672 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
676 MDICREATESTRUCT16
*cs16
=
677 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
678 MDICREATESTRUCT32A
*cs
=
679 (MDICREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0,
680 sizeof(*cs
) + sizeof(LPARAM
) );
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
;
690 *pwparam32
= (WPARAM32
)(HMENU32
)LOWORD(*plparam
);
691 *plparam
= (LPARAM
)(HMENU32
)HIWORD(*plparam
);
695 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
696 *plparam
= (LPARAM
)(HMENU32
)HIWORD(*plparam
);
700 NCCALCSIZE_PARAMS16
*nc16
;
701 NCCALCSIZE_PARAMS32
*nc
;
703 nc
= (NCCALCSIZE_PARAMS32
*)HeapAlloc( SystemHeap
, 0,
704 sizeof(*nc
) + sizeof(LPARAM
) );
706 nc16
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(*plparam
);
707 CONV_RECT16TO32( &nc16
->rgrc
[0], &nc
->rgrc
[0] );
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
;
723 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
724 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0,
725 sizeof(*cs
) + sizeof(LPARAM
) );
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
;
734 case WM_PARENTNOTIFY
:
735 if ((wParam16
== WM_CREATE
) || (wParam16
== WM_DESTROY
))
737 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
738 *plparam
= (LPARAM
)(HWND32
)LOWORD(*plparam
);
742 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
744 case WM_WINDOWPOSCHANGING
:
745 case WM_WINDOWPOSCHANGED
:
747 WINDOWPOS32
*wp
= (WINDOWPOS32
*)HeapAlloc( SystemHeap
, 0,
748 sizeof(*wp
) + sizeof(LPARAM
) );
750 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(*plparam
),
752 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
753 *plparam
= (LPARAM
)wp
;
756 case WM_ASKCBFORMATNAME
:
757 case WM_DEVMODECHANGE
:
759 case WM_PAINTCLIPBOARD
:
760 case WM_SIZECLIPBOARD
:
761 case WM_WININICHANGE
:
762 fprintf( stderr
, "MapMsg16To32A: message %04x needs translation\n",
766 default: /* No translation needed */
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
)
784 HeapFree( SystemHeap
, 0, (LPVOID
)lParam
);
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
);
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
);
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
);
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] );
824 CONV_RECT32TO16( &nc
->rgrc
[1], &nc16
->rgrc
[1] );
825 CONV_RECT32TO16( &nc
->rgrc
[2], &nc16
->rgrc
[2] );
828 STRUCT32_WINDOWPOS32to16( nc
->lppos
,
829 (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc16
->lppos
));
830 HeapFree( SystemHeap
, 0, nc
->lppos
);
833 HeapFree( SystemHeap
, 0, nc
);
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
);
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
);
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
)
872 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
873 return WINPROC_MapMsg32ATo32W( *pmsg32
, *pwparam32
, plparam
);
877 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
878 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)HeapAlloc( SystemHeap
, 0,
879 sizeof(*cs
) + sizeof(LPARAM
) );
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
;
896 MDICREATESTRUCT16
*cs16
=
897 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
898 MDICREATESTRUCT32W
*cs
=
899 (MDICREATESTRUCT32W
*)HeapAlloc( SystemHeap
, 0,
900 sizeof(*cs
) + sizeof(LPARAM
) );
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
;
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
)
933 WINPROC_UnmapMsg32ATo32W( msg
, wParam
, lParam
);
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
);
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
);
963 WINPROC_UnmapMsg16To32A( msg
, wParam
, lParam
);
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
);
987 *pmsg16
= (UINT16
)msg32
+ (BM_GETCHECK16
- BM_GETCHECK32
);
991 case LB_DELETESTRING32
:
992 case LB_GETANCHORINDEX32
:
993 case LB_GETCARETINDEX32
:
996 case LB_GETHORIZONTALEXTENT32
:
997 case LB_GETITEMDATA32
:
998 case LB_GETITEMHEIGHT32
:
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
:
1014 case LB_SETTOPINDEX32
:
1015 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING32
);
1017 case LB_ADDSTRING32
:
1018 case LB_FINDSTRING32
:
1019 case LB_FINDSTRINGEXACT32
:
1020 case LB_INSERTSTRING32
:
1021 case LB_SELECTSTRING32
:
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
);
1032 case LB_GETITEMRECT32
:
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
);
1041 case LB_GETSELITEMS32
:
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
);
1051 case LB_SETTABSTOPS32
:
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
);
1063 *pmsg16
= LB_SETTABSTOPS16
;
1069 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
1073 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
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
);
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
);
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
);
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
);
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
);
1147 case WM_GETMINMAXINFO
:
1149 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)SEGPTR_ALLOC( sizeof(*mmi
) +
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
);
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
);
1168 MDICREATESTRUCT16
*cs
;
1169 MDICREATESTRUCT32A
*cs32
= (MDICREATESTRUCT32A
*)*plparam
;
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
);
1182 *pwparam16
= TRUE
; /* FIXME? */
1183 *plparam
= MAKELPARAM( (HMENU16
)LOWORD(wParam32
),
1184 (HMENU16
)LOWORD(*plparam
) );
1188 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
1192 NCCALCSIZE_PARAMS32
*nc32
= (NCCALCSIZE_PARAMS32
*)*plparam
;
1193 NCCALCSIZE_PARAMS16
*nc
= (NCCALCSIZE_PARAMS16
*)SEGPTR_ALLOC( sizeof(*nc
) + sizeof(LPARAM
) );
1196 CONV_RECT32TO16( &nc32
->rgrc
[0], &nc
->rgrc
[0] );
1200 CONV_RECT32TO16( &nc32
->rgrc
[1], &nc
->rgrc
[1] );
1201 CONV_RECT32TO16( &nc32
->rgrc
[2], &nc
->rgrc
[2] );
1202 if (!(wp
= SEGPTR_NEW(WINDOWPOS16
)))
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
);
1218 CREATESTRUCT32A
*cs32
= (CREATESTRUCT32A
*)*plparam
;
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
);
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 */
1237 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1238 if (!str
) return -1;
1239 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1242 case WM_WINDOWPOSCHANGING
:
1243 case WM_WINDOWPOSCHANGED
:
1245 WINDOWPOS16
*wp
= (WINDOWPOS16
*)SEGPTR_ALLOC( sizeof(*wp
) +
1248 STRUCT32_WINDOWPOS32to16( (WINDOWPOS32
*)*plparam
, wp
);
1249 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1250 *plparam
= (LPARAM
)SEGPTR_GET(wp
);
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",
1263 default: /* No translation needed */
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
)
1279 case LB_ADDSTRING32
:
1281 case LB_FINDSTRING32
:
1282 case LB_FINDSTRINGEXACT32
:
1283 case LB_INSERTSTRING32
:
1284 case LB_SELECTSTRING32
:
1285 case LB_SETTABSTOPS32
:
1286 case WM_COMPAREITEM
:
1290 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam
) );
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
);
1300 case LB_GETSELITEMS32
:
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 );
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
;
1318 case WM_GETMINMAXINFO
:
1320 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)PTR_SEG_TO_LIN(lParam
);
1321 lParam
= *(LPARAM
*)(mmi
+ 1);
1322 STRUCT32_MINMAXINFO16to32( mmi
, (MINMAXINFO32
*)lParam
);
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 );
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
) );
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] );
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
),
1355 SEGPTR_FREE( PTR_SEG_TO_LIN(nc
->lppos
) );
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
) );
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
);
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
)
1393 case LB_ADDSTRING32
:
1394 case LB_FINDSTRING32
:
1395 case LB_FINDSTRINGEXACT32
:
1396 case LB_INSERTSTRING32
:
1397 case LB_SELECTSTRING32
:
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
);
1412 CREATESTRUCT32W
*cs32
= (CREATESTRUCT32W
*)*plparam
;
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
);
1428 MDICREATESTRUCT16
*cs
;
1429 MDICREATESTRUCT32W
*cs32
= (MDICREATESTRUCT32W
*)*plparam
;
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
);
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
);
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
)
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 );
1477 WINPROC_UnmapMsg32ATo16( msg
, wParam
, lParam
);
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
,
1494 if (WINPROC_MapMsg32ATo32W( msg
, wParam
, &lParam
) == -1) return 0;
1495 result
= CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1496 WINPROC_UnmapMsg32ATo32W( msg
, wParam
, lParam
);
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
,
1512 if (WINPROC_MapMsg32WTo32A( msg
, wParam
, &lParam
) == -1) return 0;
1513 result
= CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1514 WINPROC_UnmapMsg32WTo32A( msg
, wParam
, lParam
);
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
,
1532 if (WINPROC_MapMsg16To32A( msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
1534 result
= CallWndProc32( func
, hwnd
, msg32
, wParam32
, lParam
);
1535 WINPROC_UnmapMsg16To32A( msg32
, wParam32
, lParam
);
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
,
1553 if (WINPROC_MapMsg16To32W( msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
1555 result
= CallWndProc32( func
, hwnd
, msg32
, wParam32
, lParam
);
1556 WINPROC_UnmapMsg16To32W( msg32
, wParam32
, lParam
);
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
,
1573 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1574 WORD ds
= CURRENT_DS
;
1576 if (WINPROC_MapMsg32ATo16( msg
, wParam
, &msg16
, &wParam16
, &lParam
) == -1)
1578 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1579 result
= CallWndProc16( func
, hwnd
, msg16
, wParam16
, lParam
);
1581 WINPROC_UnmapMsg32ATo16( msg
, wParam16
, lParam
);
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
,
1598 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1599 WORD ds
= CURRENT_DS
;
1601 if (WINPROC_MapMsg32WTo16( msg
, wParam
, &msg16
, &wParam16
, &lParam
) == -1)
1603 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1604 result
= CallWndProc16( func
, hwnd
, msg16
, wParam16
, lParam
);
1606 WINPROC_UnmapMsg32WTo16( msg
, wParam16
, lParam
);
1611 /**********************************************************************
1612 * CallWindowProc16 (USER.122)
1614 LRESULT
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
1615 WPARAM16 wParam
, LPARAM lParam
)
1619 WINDOWPROC
*proc
= WINPROC_GetPtr( func
);
1620 WORD ds
= CURRENT_DS
;
1624 wndPtr
= WIN_FindWndPtr( hwnd
);
1625 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1626 result
= CallWndProc16( (FARPROC16
)func
, hwnd
, msg
, wParam
, lParam
);
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
);
1642 if (!proc
->thunk
.t_from32
.proc
) return 0;
1643 wndPtr
= WIN_FindWndPtr( hwnd
);
1644 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
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
) );
1662 result
= CallWndProc16( proc
->thunk
.t_from32
.proc
,
1663 hwnd
, msg
, wParam
, lParam
);
1668 if (!proc
->thunk
.t_from16
.proc
) return 0;
1669 return WINPROC_CallProc16To32A( hwnd
, msg
, wParam
, lParam
,
1670 proc
->thunk
.t_from16
.proc
);
1672 if (!proc
->thunk
.t_from16
.proc
) return 0;
1673 return WINPROC_CallProc16To32W( hwnd
, msg
, wParam
, lParam
,
1674 proc
->thunk
.t_from16
.proc
);
1676 fprintf( stderr
, "CallWindowProc16: invalid proc %p\n", proc
);
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
);
1693 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32A
);
1694 return CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1700 if (!proc
->thunk
.t_from32
.proc
) return 0;
1701 return WINPROC_CallProc32ATo16( proc
->thunk
.t_from32
.proc
,
1702 hwnd
, msg
, wParam
, lParam
);
1704 if (!proc
->thunk
.t_from16
.proc
) return 0;
1705 return CallWndProc32( proc
->thunk
.t_from16
.proc
,
1706 hwnd
, msg
, wParam
, lParam
);
1708 if (!proc
->thunk
.t_from16
.proc
) return 0;
1709 return WINPROC_CallProc32ATo32W( proc
->thunk
.t_from16
.proc
,
1710 hwnd
, msg
, wParam
, lParam
);
1712 fprintf( stderr
, "CallWindowProc32A: invalid proc %p\n", proc
);
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
);
1729 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32W
);
1730 return CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1736 if (!proc
->thunk
.t_from32
.proc
) return 0;
1737 return WINPROC_CallProc32WTo16( proc
->thunk
.t_from32
.proc
,
1738 hwnd
, msg
, wParam
, lParam
);
1740 if (!proc
->thunk
.t_from16
.proc
) return 0;
1741 return WINPROC_CallProc32WTo32A( proc
->thunk
.t_from16
.proc
,
1742 hwnd
, msg
, wParam
, lParam
);
1744 if (!proc
->thunk
.t_from16
.proc
) return 0;
1745 return CallWndProc32( proc
->thunk
.t_from16
.proc
,
1746 hwnd
, msg
, wParam
, lParam
);
1748 fprintf( stderr
, "CallWindowProc32W: invalid proc %p\n", proc
);