2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
13 #include "registers.h"
14 #include "stackframe.h"
22 /* Window procedure 16-bit thunk; see BuildSpec16Files() in tools/build.c */
25 BYTE popl_eax
; /* popl %eax (return address) */
26 BYTE pushl_func
; /* pushl $proc */
27 WNDPROC32 proc WINE_PACKED
;
28 BYTE pushl_eax
; /* pushl %eax */
29 WORD pushw_bp WINE_PACKED
; /* pushw %bp */
30 BYTE pushl_thunk
; /* pushl $thunkfrom16 */
31 void (*thunk32
)() WINE_PACKED
;
32 BYTE lcall
; /* lcall cs:relay */
33 void (*relay
)() WINE_PACKED
;
35 } WINPROC_THUNK_FROM16
;
37 /* Window procedure 32-bit thunk; see BuildSpec32Files() in tools/build.c */
40 BYTE popl_eax
; /* popl %eax (return address) */
41 BYTE pushl_func
; /* pushl $proc */
42 WNDPROC16 proc WINE_PACKED
;
43 BYTE pushl_eax
; /* pushl %eax */
44 BYTE pushl_ebp
; /* pushl %ebp */
45 BYTE pushl_name
; /* pushl $name */
46 LPCSTR name WINE_PACKED
;
47 BYTE pushl_thunk
; /* pushl $thunkfrom32 */
48 void (*thunk32
)() WINE_PACKED
;
49 BYTE jmp
; /* jmp relay (relative jump)*/
50 void (*relay
)() WINE_PACKED
;
51 } WINPROC_THUNK_FROM32
;
53 /* Simple jmp to call 32-bit procedure directly */
56 BYTE jmp
; /* jmp proc (relative jump) */
57 WNDPROC32 proc WINE_PACKED
;
62 WINPROC_THUNK_FROM16 t_from16
;
63 WINPROC_THUNK_FROM32 t_from32
;
66 typedef struct tagWINDOWPROC
68 WINPROC_THUNK thunk
; /* Thunk */
69 WINPROC_JUMP jmp
; /* Jump */
70 struct tagWINDOWPROC
*next
; /* Next window proc */
71 UINT32 magic
; /* Magic number */
72 WINDOWPROCTYPE type
; /* Function type */
75 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
77 #define WINPROC_THUNKPROC(pproc) \
78 (((pproc)->type == WIN_PROC_16) ? \
79 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
80 (WNDPROC16)((pproc)->thunk.t_from16.proc))
82 LRESULT
WINPROC_CallProc16To32A( HWND16 hwnd
, UINT16 msg
,
83 WPARAM16 wParam
, LPARAM lParam
,
85 LRESULT
WINPROC_CallProc16To32W( HWND16 hwnd
, UINT16 msg
,
86 WPARAM16 wParam
, LPARAM lParam
,
88 static LRESULT
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND32 hwnd
,
89 UINT32 msg
, WPARAM32 wParam
,
91 static LRESULT
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND32 hwnd
,
92 UINT32 msg
, WPARAM32 wParam
,
96 extern void CallFrom16_long_wwwll(void);
97 extern void CallFrom32_stdcall_5(void);
99 static void CallFrom16_long_wwwll(void) {}
100 static void CallFrom32_stdcall_5(void) {}
103 static HANDLE32 WinProcHeap
;
105 /**********************************************************************
108 BOOL32
WINPROC_Init(void)
110 WinProcHeap
= HeapCreate( HEAP_WINE_SEGPTR
| HEAP_WINE_CODESEG
, 0, 0 );
113 fprintf( stderr
, "Unable to create winproc heap\n" );
120 /**********************************************************************
123 * Return a pointer to the win proc.
125 static WINDOWPROC
*WINPROC_GetPtr( WNDPROC16 handle
)
130 /* Check for a linear pointer */
132 if (HEAP_IsInsideHeap( WinProcHeap
, 0, (LPVOID
)handle
))
134 ptr
= (BYTE
*)handle
;
135 /* First check if it is the jmp address */
136 if (*ptr
== 0xe9 /* jmp */) ptr
-= (int)&((WINDOWPROC
*)0)->jmp
-
137 (int)&((WINDOWPROC
*)0)->thunk
;
138 /* Now it must be the thunk address */
139 if (*ptr
== 0x58 /* popl eax */) ptr
-= (int)&((WINDOWPROC
*)0)->thunk
;
140 /* Now we have a pointer to the WINDOWPROC struct */
141 if (((WINDOWPROC
*)ptr
)->magic
== WINPROC_MAGIC
)
142 return (WINDOWPROC
*)ptr
;
145 /* Check for a segmented pointer */
147 if (!IsBadReadPtr16((SEGPTR
)handle
,sizeof(WINDOWPROC
)-sizeof(proc
->thunk
)))
149 ptr
= (BYTE
*)PTR_SEG_TO_LIN(handle
);
150 if (!HEAP_IsInsideHeap( WinProcHeap
, 0, ptr
)) return NULL
;
151 /* It must be the thunk address */
152 if (*ptr
== 0x58 /* popl eax */) ptr
-= (int)&((WINDOWPROC
*)0)->thunk
;
153 /* Now we have a pointer to the WINDOWPROC struct */
154 if (((WINDOWPROC
*)ptr
)->magic
== WINPROC_MAGIC
)
155 return (WINDOWPROC
*)ptr
;
162 /**********************************************************************
163 * WINPROC_AllocWinProc
165 * Allocate a new window procedure.
167 static WINDOWPROC
*WINPROC_AllocWinProc( WNDPROC16 func
, WINDOWPROCTYPE type
)
169 WINDOWPROC
*proc
, *oldproc
;
171 /* Allocate a window procedure */
173 if (!(proc
= HeapAlloc( WinProcHeap
, 0, sizeof(WINDOWPROC
) ))) return 0;
175 /* Check if the function is already a win proc */
177 if ((oldproc
= WINPROC_GetPtr( func
)))
186 proc
->thunk
.t_from32
.popl_eax
= 0x58; /* popl %eax */
187 proc
->thunk
.t_from32
.pushl_func
= 0x68; /* pushl $proc */
188 proc
->thunk
.t_from32
.proc
= func
;
189 proc
->thunk
.t_from32
.pushl_eax
= 0x50; /* pushl %eax */
190 proc
->thunk
.t_from32
.pushl_ebp
= 0x55; /* pushl %ebp */
191 proc
->thunk
.t_from32
.pushl_name
= 0x68; /* pushl $name */
192 proc
->thunk
.t_from32
.name
= "WINPROC_CallProc32ATo16";
193 proc
->thunk
.t_from32
.pushl_thunk
= 0x68; /* pushl $thunkfrom32 */
194 proc
->thunk
.t_from32
.thunk32
= (void(*)())WINPROC_CallProc32ATo16
;
195 proc
->thunk
.t_from32
.jmp
= 0xe9; /* jmp relay*/
196 proc
->thunk
.t_from32
.relay
= /* relative jump */
197 (void (*)())((DWORD
)CallFrom32_stdcall_5
-
198 (DWORD
)(&proc
->thunk
.t_from32
.relay
+ 1));
202 proc
->thunk
.t_from16
.popl_eax
= 0x58; /* popl %eax */
203 proc
->thunk
.t_from16
.pushl_func
= 0x68; /* pushl $proc */
204 proc
->thunk
.t_from16
.proc
= (FARPROC32
)func
;
205 proc
->thunk
.t_from16
.pushl_eax
= 0x50; /* pushl %eax */
206 proc
->thunk
.t_from16
.pushw_bp
= 0x5566; /* pushw %bp */
207 proc
->thunk
.t_from16
.pushl_thunk
= 0x68; /* pushl $thunkfrom16 */
208 proc
->thunk
.t_from16
.thunk32
= (type
== WIN_PROC_32A
) ?
209 (void(*)())WINPROC_CallProc16To32A
:
210 (void(*)())WINPROC_CallProc16To32W
;
211 proc
->thunk
.t_from16
.lcall
= 0x9a; /* lcall cs:relay */
212 proc
->thunk
.t_from16
.relay
= CallFrom16_long_wwwll
;
213 proc
->thunk
.t_from16
.cs
= WINE_CODE_SELECTOR
;
214 proc
->jmp
.jmp
= 0xe9;
215 /* Fixup relative jump */
216 proc
->jmp
.proc
= (WNDPROC32
)((DWORD
)func
-
217 (DWORD
)(&proc
->jmp
.proc
+ 1));
220 /* Should not happen */
223 proc
->magic
= WINPROC_MAGIC
;
227 dprintf_win( stddeb
, "WINPROC_AllocWinProc(%08x,%d): returning %08x\n",
228 (UINT32
)func
, type
, (UINT32
)proc
);
233 /**********************************************************************
236 * Get a window procedure pointer that can be passed to the Windows program.
238 WNDPROC16
WINPROC_GetProc( HWINDOWPROC proc
, WINDOWPROCTYPE type
)
240 if (type
== WIN_PROC_16
) /* We want a 16:16 address */
242 if (((WINDOWPROC
*)proc
)->type
== WIN_PROC_16
)
243 return ((WINDOWPROC
*)proc
)->thunk
.t_from32
.proc
;
245 return (WNDPROC16
)HEAP_GetSegptr( WinProcHeap
, 0,
246 &((WINDOWPROC
*)proc
)->thunk
);
248 else /* We want a 32-bit address */
250 if (((WINDOWPROC
*)proc
)->type
== WIN_PROC_16
)
251 return (WNDPROC16
)&((WINDOWPROC
*)proc
)->thunk
;
253 return (WNDPROC16
)&((WINDOWPROC
*)proc
)->jmp
;
258 /**********************************************************************
261 * Set the window procedure for a window or class.
263 BOOL32
WINPROC_SetProc( HWINDOWPROC
*pFirst
, WNDPROC16 func
,
264 WINDOWPROCTYPE type
)
266 WINDOWPROC
*proc
, **ppPrev
;
268 /* Check if function is already in the list */
270 ppPrev
= (WINDOWPROC
**)pFirst
;
271 proc
= WINPROC_GetPtr( func
);
276 if (*ppPrev
== proc
) break;
280 if (((*ppPrev
)->type
== type
) &&
281 (func
== WINPROC_THUNKPROC(*ppPrev
))) break;
283 ppPrev
= &(*ppPrev
)->next
;
286 if (*ppPrev
) /* Remove it from the list */
289 *ppPrev
= proc
->next
;
291 else /* Allocate a new one */
293 if (proc
) /* Was already a win proc */
296 func
= WINPROC_THUNKPROC(proc
);
298 proc
= WINPROC_AllocWinProc( func
, type
);
299 if (!proc
) return FALSE
;
302 /* Add the win proc at the head of the list */
304 dprintf_win( stddeb
, "WINPROC_SetProc(%08x,%08x,%d): res=%08x\n",
305 (UINT32
)*pFirst
, (UINT32
)func
, type
, (UINT32
)proc
);
306 proc
->next
= *(WINDOWPROC
**)pFirst
;
307 *(WINDOWPROC
**)pFirst
= proc
;
312 /**********************************************************************
315 * Free a list of win procs.
317 void WINPROC_FreeProc( HWINDOWPROC proc
)
321 WINDOWPROC
*next
= ((WINDOWPROC
*)proc
)->next
;
322 dprintf_win( stddeb
, "WINPROC_FreeProc: freeing %08x\n", (UINT32
)proc
);
323 HeapFree( WinProcHeap
, 0, proc
);
329 /**********************************************************************
330 * WINPROC_GetProcType
332 * Return the window procedure type.
334 WINDOWPROCTYPE
WINPROC_GetProcType( HWINDOWPROC proc
)
337 (((WINDOWPROC
*)proc
)->magic
!= WINPROC_MAGIC
))
338 return WIN_PROC_INVALID
;
339 return ((WINDOWPROC
*)proc
)->type
;
343 /**********************************************************************
344 * WINPROC_MapMsg32ATo32W
346 * Map a message from Ansi to Unicode.
347 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
349 INT32
WINPROC_MapMsg32ATo32W( UINT32 msg
, WPARAM32 wParam
, LPARAM
*plparam
)
355 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
356 wParam
* sizeof(WCHAR
) + sizeof(LPARAM
) );
358 *ptr
++ = *plparam
; /* Store previous lParam */
359 *plparam
= (LPARAM
)ptr
;
363 *plparam
= (LPARAM
)STRING32_DupAnsiToUni( (LPCSTR
)*plparam
);
364 return (*plparam
? 1 : -1);
368 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)HeapAlloc( SystemHeap
, 0,
371 *cs
= *(CREATESTRUCT32W
*)*plparam
;
372 if (HIWORD(cs
->lpszName
))
373 cs
->lpszName
= STRING32_DupAnsiToUni( (LPCSTR
)cs
->lpszName
);
374 if (HIWORD(cs
->lpszClass
))
375 cs
->lpszClass
= STRING32_DupAnsiToUni( (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
= STRING32_DupAnsiToUni( (LPCSTR
)cs
->szClass
);
387 if (HIWORD(cs
->szTitle
))
388 cs
->szTitle
= STRING32_DupAnsiToUni( (LPCSTR
)cs
->szTitle
);
389 *plparam
= (LPARAM
)cs
;
392 case WM_ASKCBFORMATNAME
:
393 case WM_DEVMODECHANGE
:
395 case WM_PAINTCLIPBOARD
:
396 case WM_SIZECLIPBOARD
:
397 case WM_WININICHANGE
:
398 fprintf( stderr
, "MapMsg32ATo32W: message %04x needs translation\n",
401 default: /* No translation needed */
407 /**********************************************************************
408 * WINPROC_UnmapMsg32ATo32W
410 * Unmap a message that was mapped from Ansi to Unicode.
412 void WINPROC_UnmapMsg32ATo32W( UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
418 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
419 lstrcpynWtoA( (LPSTR
)*ptr
, (LPWSTR
)(ptr
+ 1), wParam
);
420 HeapFree( SystemHeap
, 0, ptr
);
424 free( (void *)lParam
);
429 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
430 if (HIWORD(cs
->lpszName
)) free( (LPVOID
)cs
->lpszName
);
431 if (HIWORD(cs
->lpszClass
)) free( (LPVOID
)cs
->lpszClass
);
432 HeapFree( SystemHeap
, 0, cs
);
437 MDICREATESTRUCT32W
*cs
= (MDICREATESTRUCT32W
*)lParam
;
438 if (HIWORD(cs
->szTitle
)) free( (LPVOID
)cs
->szTitle
);
439 if (HIWORD(cs
->szClass
)) free( (LPVOID
)cs
->szClass
);
440 HeapFree( SystemHeap
, 0, cs
);
447 /**********************************************************************
448 * WINPROC_MapMsg32WTo32A
450 * Map a message from Unicode to Ansi.
451 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
453 INT32
WINPROC_MapMsg32WTo32A( UINT32 msg
, WPARAM32 wParam
, LPARAM
*plparam
)
459 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
460 wParam
+ sizeof(LPARAM
) );
462 *ptr
++ = *plparam
; /* Store previous lParam */
463 *plparam
= (LPARAM
)ptr
;
467 *plparam
= (LPARAM
)STRING32_DupUniToAnsi( (LPCWSTR
)*plparam
);
468 return (*plparam
? 1 : -1);
472 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0,
475 *cs
= *(CREATESTRUCT32A
*)*plparam
;
476 if (HIWORD(cs
->lpszName
))
477 cs
->lpszName
= STRING32_DupUniToAnsi( (LPCWSTR
)cs
->lpszName
);
478 if (HIWORD(cs
->lpszClass
))
479 cs
->lpszClass
= STRING32_DupUniToAnsi( (LPCWSTR
)cs
->lpszClass
);
480 *plparam
= (LPARAM
)cs
;
485 MDICREATESTRUCT32A
*cs
=
486 (MDICREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0, sizeof(*cs
) );
488 *cs
= *(MDICREATESTRUCT32A
*)*plparam
;
489 if (HIWORD(cs
->szTitle
))
490 cs
->szTitle
= STRING32_DupUniToAnsi( (LPCWSTR
)cs
->szTitle
);
491 if (HIWORD(cs
->szClass
))
492 cs
->szClass
= STRING32_DupUniToAnsi( (LPCWSTR
)cs
->szClass
);
493 *plparam
= (LPARAM
)cs
;
496 case WM_ASKCBFORMATNAME
:
497 case WM_DEVMODECHANGE
:
499 case WM_PAINTCLIPBOARD
:
500 case WM_SIZECLIPBOARD
:
501 case WM_WININICHANGE
:
502 fprintf( stderr
, "MapMsg32WTo32A: message %04x needs translation\n",
505 default: /* No translation needed */
511 /**********************************************************************
512 * WINPROC_UnmapMsg32WTo32A
514 * Unmap a message that was mapped from Unicode to Ansi.
516 void WINPROC_UnmapMsg32WTo32A( UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
522 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
523 lstrcpynAtoW( (LPWSTR
)*ptr
, (LPSTR
)(ptr
+ 1), wParam
);
524 HeapFree( SystemHeap
, 0, ptr
);
528 free( (void *)lParam
);
533 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
534 if (HIWORD(cs
->lpszName
)) free( (LPVOID
)cs
->lpszName
);
535 if (HIWORD(cs
->lpszClass
)) free( (LPVOID
)cs
->lpszClass
);
536 HeapFree( SystemHeap
, 0, cs
);
541 MDICREATESTRUCT32A
*cs
= (MDICREATESTRUCT32A
*)lParam
;
542 if (HIWORD(cs
->szTitle
)) free( (LPVOID
)cs
->szTitle
);
543 if (HIWORD(cs
->szClass
)) free( (LPVOID
)cs
->szClass
);
544 HeapFree( SystemHeap
, 0, cs
);
551 /**********************************************************************
552 * WINPROC_MapMsg16To32A
554 * Map a message from 16- to 32-bit Ansi.
555 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
557 INT32
WINPROC_MapMsg16To32A( UINT16 msg16
, WPARAM16 wParam16
, UINT32
*pmsg32
,
558 WPARAM32
*pwparam32
, LPARAM
*plparam
)
560 *pmsg32
= (UINT32
)msg16
;
561 *pwparam32
= (WPARAM32
)wParam16
;
568 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
569 *plparam
= (LPARAM
)(HWND32
)LOWORD(*plparam
);
573 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
574 *plparam
= (LPARAM
)(HWND32
)HIWORD(*plparam
);
577 *pmsg32
= WM_CTLCOLORMSGBOX
+ HIWORD(*plparam
);
578 *pwparam32
= (WPARAM32
)(HDC32
)wParam16
;
579 *plparam
= (LPARAM
)(HWND32
)LOWORD(*plparam
);
583 COMPAREITEMSTRUCT16
* cis16
= (COMPAREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
584 COMPAREITEMSTRUCT32
*cis
= (COMPAREITEMSTRUCT32
*)
585 HeapAlloc(SystemHeap
, 0, sizeof(*cis
));
587 cis
->CtlType
= cis16
->CtlType
;
588 cis
->CtlID
= cis16
->CtlID
;
589 cis
->hwndItem
= cis16
->hwndItem
;
590 cis
->itemID1
= cis16
->itemID1
;
591 cis
->itemData1
= cis16
->itemData1
;
592 cis
->itemID2
= cis16
->itemID2
;
593 cis
->itemData2
= cis16
->itemData2
;
594 cis
->dwLocaleId
= 0; /* FIXME */
595 *plparam
= (LPARAM
)cis
;
600 DELETEITEMSTRUCT16
* dis16
= (DELETEITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
601 DELETEITEMSTRUCT32
*dis
= (DELETEITEMSTRUCT32
*)
602 HeapAlloc(SystemHeap
, 0, sizeof(*dis
));
604 dis
->CtlType
= dis16
->CtlType
;
605 dis
->CtlID
= dis16
->CtlID
;
606 dis
->hwndItem
= dis16
->hwndItem
;
607 dis
->itemData
= dis16
->itemData
;
608 *plparam
= (LPARAM
)dis
;
613 MEASUREITEMSTRUCT16
* mis16
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
614 MEASUREITEMSTRUCT32
*mis
= (MEASUREITEMSTRUCT32
*)
615 HeapAlloc(SystemHeap
, 0,
616 sizeof(*mis
) + sizeof(LPARAM
));
618 mis
->CtlType
= mis16
->CtlType
;
619 mis
->CtlID
= mis16
->CtlID
;
620 mis
->itemID
= mis16
->itemID
;
621 mis
->itemWidth
= mis16
->itemWidth
;
622 mis
->itemHeight
= mis16
->itemHeight
;
623 mis
->itemData
= mis16
->itemData
;
624 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
625 *plparam
= (LPARAM
)mis
;
630 DRAWITEMSTRUCT16
* dis16
= (DRAWITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
631 DRAWITEMSTRUCT32
*dis
= (DRAWITEMSTRUCT32
*)HeapAlloc(SystemHeap
, 0,
634 dis
->CtlType
= dis16
->CtlType
;
635 dis
->CtlID
= dis16
->CtlID
;
636 dis
->itemID
= dis16
->itemID
;
637 dis
->itemAction
= dis16
->itemAction
;
638 dis
->itemState
= dis16
->itemState
;
639 dis
->hwndItem
= dis16
->hwndItem
;
640 dis
->hDC
= dis16
->hDC
;
641 dis
->itemData
= dis16
->itemData
;
642 CONV_RECT16TO32( &dis16
->rcItem
, &dis
->rcItem
);
643 *plparam
= (LPARAM
)dis
;
646 case WM_GETMINMAXINFO
:
648 MINMAXINFO32
*mmi
= (MINMAXINFO32
*)HeapAlloc( SystemHeap
, 0,
649 sizeof(*mmi
) + sizeof(LPARAM
));
651 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16
*)PTR_SEG_TO_LIN(*plparam
),
653 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
654 *plparam
= (LPARAM
)mmi
;
658 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
662 MDICREATESTRUCT16
*cs16
=
663 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
664 MDICREATESTRUCT32A
*cs
=
665 (MDICREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0,
666 sizeof(*cs
) + sizeof(LPARAM
) );
668 STRUCT32_MDICREATESTRUCT16to32A( cs16
, cs
);
669 cs
->szTitle
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->szTitle
);
670 cs
->szClass
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->szClass
);
671 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
672 *plparam
= (LPARAM
)cs
;
676 *pwparam32
= (WPARAM32
)(HMENU32
)LOWORD(*plparam
);
677 *plparam
= (LPARAM
)(HMENU32
)HIWORD(*plparam
);
681 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
682 *plparam
= (LPARAM
)(HMENU32
)HIWORD(*plparam
);
686 NCCALCSIZE_PARAMS16
*nc16
;
687 NCCALCSIZE_PARAMS32
*nc
;
689 nc
= (NCCALCSIZE_PARAMS32
*)HeapAlloc( SystemHeap
, 0,
690 sizeof(*nc
) + sizeof(LPARAM
) );
692 nc16
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(*plparam
);
693 CONV_RECT16TO32( &nc16
->rgrc
[0], &nc
->rgrc
[0] );
696 nc
->lppos
= (WINDOWPOS32
*)HeapAlloc( SystemHeap
, 0,
697 sizeof(*nc
->lppos
) );
698 CONV_RECT16TO32( &nc16
->rgrc
[1], &nc
->rgrc
[1] );
699 CONV_RECT16TO32( &nc16
->rgrc
[2], &nc
->rgrc
[2] );
700 if (nc
->lppos
) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc16
->lppos
), nc
->lppos
);
702 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
703 *plparam
= (LPARAM
)nc
;
709 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
710 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)HeapAlloc( SystemHeap
, 0,
711 sizeof(*cs
) + sizeof(LPARAM
) );
713 STRUCT32_CREATESTRUCT16to32A( cs16
, cs
);
714 cs
->lpszName
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->lpszName
);
715 cs
->lpszClass
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->lpszClass
);
716 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
717 *plparam
= (LPARAM
)cs
;
720 case WM_PARENTNOTIFY
:
721 if ((wParam16
== WM_CREATE
) || (wParam16
== WM_DESTROY
))
723 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
724 *plparam
= (LPARAM
)(HWND32
)LOWORD(*plparam
);
728 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
730 case WM_WINDOWPOSCHANGING
:
731 case WM_WINDOWPOSCHANGED
:
733 WINDOWPOS32
*wp
= (WINDOWPOS32
*)HeapAlloc( SystemHeap
, 0,
734 sizeof(*wp
) + sizeof(LPARAM
) );
736 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(*plparam
),
738 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
739 *plparam
= (LPARAM
)wp
;
742 case WM_ASKCBFORMATNAME
:
743 case WM_DEVMODECHANGE
:
745 case WM_PAINTCLIPBOARD
:
746 case WM_SIZECLIPBOARD
:
747 case WM_WININICHANGE
:
748 fprintf( stderr
, "MapMsg16To32A: message %04x needs translation\n",
752 default: /* No translation needed */
758 /**********************************************************************
759 * WINPROC_UnmapMsg16To32A
761 * Unmap a message that was mapped from 16- to 32-bit Ansi.
763 void WINPROC_UnmapMsg16To32A( UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
770 HeapFree( SystemHeap
, 0, (LPVOID
)lParam
);
774 MEASUREITEMSTRUCT16
*mis16
;
775 MEASUREITEMSTRUCT32
*mis
= (MEASUREITEMSTRUCT32
*)lParam
;
776 lParam
= *(LPARAM
*)(mis
+ 1);
777 mis16
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
778 mis16
->itemWidth
= (UINT16
)mis
->itemWidth
;
779 mis16
->itemHeight
= (UINT16
)mis
->itemHeight
;
780 HeapFree( SystemHeap
, 0, mis
);
783 case WM_GETMINMAXINFO
:
785 MINMAXINFO32
*mmi
= (MINMAXINFO32
*)lParam
;
786 lParam
= *(LPARAM
*)(mmi
+ 1);
787 STRUCT32_MINMAXINFO32to16( mmi
,
788 (MINMAXINFO16
*)PTR_SEG_TO_LIN(lParam
));
789 HeapFree( SystemHeap
, 0, mmi
);
794 MDICREATESTRUCT32A
*cs
= (MDICREATESTRUCT32A
*)lParam
;
795 lParam
= *(LPARAM
*)(cs
+ 1);
796 STRUCT32_MDICREATESTRUCT32Ato16( cs
,
797 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
798 HeapFree( SystemHeap
, 0, cs
);
803 NCCALCSIZE_PARAMS16
*nc16
;
804 NCCALCSIZE_PARAMS32
*nc
= (NCCALCSIZE_PARAMS32
*)lParam
;
805 lParam
= *(LPARAM
*)(nc
+ 1);
806 nc16
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(lParam
);
807 CONV_RECT32TO16( &nc
->rgrc
[0], &nc16
->rgrc
[0] );
810 CONV_RECT32TO16( &nc
->rgrc
[1], &nc16
->rgrc
[1] );
811 CONV_RECT32TO16( &nc
->rgrc
[2], &nc16
->rgrc
[2] );
814 STRUCT32_WINDOWPOS32to16( nc
->lppos
,
815 (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc16
->lppos
));
816 HeapFree( SystemHeap
, 0, nc
->lppos
);
819 HeapFree( SystemHeap
, 0, nc
);
825 CREATESTRUCT32A
*cs
= (CREATESTRUCT32A
*)lParam
;
826 lParam
= *(LPARAM
*)(cs
+ 1);
827 STRUCT32_CREATESTRUCT32Ato16( cs
,
828 (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
829 HeapFree( SystemHeap
, 0, cs
);
832 case WM_WINDOWPOSCHANGING
:
833 case WM_WINDOWPOSCHANGED
:
835 WINDOWPOS32
*wp
= (WINDOWPOS32
*)lParam
;
836 lParam
= *(LPARAM
*)(wp
+ 1);
837 STRUCT32_WINDOWPOS32to16(wp
,(WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
));
838 HeapFree( SystemHeap
, 0, wp
);
845 /**********************************************************************
846 * WINPROC_MapMsg16To32W
848 * Map a message from 16- to 32-bit Unicode.
849 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
851 INT32
WINPROC_MapMsg16To32W( UINT16 msg16
, WPARAM16 wParam16
, UINT32
*pmsg32
,
852 WPARAM32
*pwparam32
, LPARAM
*plparam
)
858 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
859 return WINPROC_MapMsg32ATo32W( *pmsg32
, *pwparam32
, plparam
);
863 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
864 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)HeapAlloc( SystemHeap
, 0,
865 sizeof(*cs
) + sizeof(LPARAM
) );
867 STRUCT32_CREATESTRUCT16to32A( cs16
, (CREATESTRUCT32A
*)cs
);
868 cs
->lpszName
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->lpszName
);
869 cs
->lpszClass
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->lpszClass
);
870 if (HIWORD(cs
->lpszName
))
871 cs
->lpszName
= STRING32_DupAnsiToUni( (LPCSTR
)cs
->lpszName
);
872 if (HIWORD(cs
->lpszClass
))
873 cs
->lpszClass
= STRING32_DupAnsiToUni( (LPCSTR
)cs
->lpszClass
);
874 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
875 *plparam
= (LPARAM
)cs
;
880 MDICREATESTRUCT16
*cs16
=
881 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
882 MDICREATESTRUCT32W
*cs
=
883 (MDICREATESTRUCT32W
*)HeapAlloc( SystemHeap
, 0,
884 sizeof(*cs
) + sizeof(LPARAM
) );
886 STRUCT32_MDICREATESTRUCT16to32A( cs16
, (MDICREATESTRUCT32A
*)cs
);
887 cs
->szTitle
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->szTitle
);
888 cs
->szClass
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->szClass
);
889 if (HIWORD(cs
->szTitle
))
890 cs
->szTitle
= STRING32_DupAnsiToUni( (LPCSTR
)cs
->szTitle
);
891 if (HIWORD(cs
->szClass
))
892 cs
->szClass
= STRING32_DupAnsiToUni( (LPCSTR
)cs
->szClass
);
893 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
894 *plparam
= (LPARAM
)cs
;
897 default: /* No Unicode translation needed */
898 return WINPROC_MapMsg16To32A( msg16
, wParam16
, pmsg32
,
899 pwparam32
, plparam
);
904 /**********************************************************************
905 * WINPROC_UnmapMsg16To32W
907 * Unmap a message that was mapped from 16- to 32-bit Unicode.
909 void WINPROC_UnmapMsg16To32W( UINT32 msg
, WPARAM32 wParam
, LPARAM lParam
)
915 WINPROC_UnmapMsg32ATo32W( msg
, wParam
, lParam
);
920 CREATESTRUCT32W
*cs
= (CREATESTRUCT32W
*)lParam
;
921 lParam
= *(LPARAM
*)(cs
+ 1);
922 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCT32A
*)cs
,
923 (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
924 if (HIWORD(cs
->lpszName
)) free( (LPVOID
)cs
->lpszName
);
925 if (HIWORD(cs
->lpszClass
)) free( (LPVOID
)cs
->lpszClass
);
926 HeapFree( SystemHeap
, 0, cs
);
931 MDICREATESTRUCT32W
*cs
= (MDICREATESTRUCT32W
*)lParam
;
932 lParam
= *(LPARAM
*)(cs
+ 1);
933 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCT32A
*)cs
,
934 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
935 if (HIWORD(cs
->szTitle
)) free( (LPVOID
)cs
->szTitle
);
936 if (HIWORD(cs
->szClass
)) free( (LPVOID
)cs
->szClass
);
937 HeapFree( SystemHeap
, 0, cs
);
941 WINPROC_UnmapMsg16To32A( msg
, wParam
, lParam
);
947 /**********************************************************************
948 * WINPROC_MapMsg32ATo16
950 * Map a message from 32-bit Ansi to 16-bit.
951 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
953 INT32
WINPROC_MapMsg32ATo16( UINT32 msg32
, WPARAM32 wParam32
, UINT16
*pmsg16
,
954 WPARAM16
*pwparam16
, LPARAM
*plparam
)
956 *pmsg16
= (UINT16
)msg32
;
957 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
965 *pmsg16
= (UINT16
)msg32
+ (BM_GETCHECK16
- BM_GETCHECK32
);
971 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
975 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
977 case WM_CTLCOLORMSGBOX
:
978 case WM_CTLCOLOREDIT
:
979 case WM_CTLCOLORLISTBOX
:
982 case WM_CTLCOLORSCROLLBAR
:
983 case WM_CTLCOLORSTATIC
:
984 *pmsg16
= WM_CTLCOLOR
;
985 *plparam
= MAKELPARAM( (HWND16
)*plparam
,
986 (WORD
)msg32
- WM_CTLCOLORMSGBOX
);
990 COMPAREITEMSTRUCT32
*cis32
= (COMPAREITEMSTRUCT32
*)*plparam
;
991 COMPAREITEMSTRUCT16
*cis
= SEGPTR_NEW(COMPAREITEMSTRUCT16
);
993 cis
->CtlType
= (UINT16
)cis32
->CtlType
;
994 cis
->CtlID
= (UINT16
)cis32
->CtlID
;
995 cis
->hwndItem
= (HWND16
)cis32
->hwndItem
;
996 cis
->itemID1
= (UINT16
)cis32
->itemID1
;
997 cis
->itemData1
= cis32
->itemData1
;
998 cis
->itemID2
= (UINT16
)cis32
->itemID2
;
999 cis
->itemData2
= cis32
->itemData2
;
1000 *plparam
= (LPARAM
)SEGPTR_GET(cis
);
1005 DELETEITEMSTRUCT32
*dis32
= (DELETEITEMSTRUCT32
*)*plparam
;
1006 DELETEITEMSTRUCT16
*dis
= SEGPTR_NEW(DELETEITEMSTRUCT16
);
1007 if (!dis
) return -1;
1008 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1009 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1010 dis
->itemID
= (UINT16
)dis32
->itemID
;
1011 dis
->hwndItem
= (HWND16
)dis32
->hwndItem
;
1012 dis
->itemData
= dis32
->itemData
;
1013 *plparam
= (LPARAM
)SEGPTR_GET(dis
);
1018 DRAWITEMSTRUCT32
*dis32
= (DRAWITEMSTRUCT32
*)*plparam
;
1019 DRAWITEMSTRUCT16
*dis
= SEGPTR_NEW(DRAWITEMSTRUCT16
);
1020 if (!dis
) return -1;
1021 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1022 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1023 dis
->itemID
= (UINT16
)dis32
->itemID
;
1024 dis
->itemAction
= (UINT16
)dis32
->itemAction
;
1025 dis
->itemState
= (UINT16
)dis32
->itemState
;
1026 dis
->hwndItem
= (HWND16
)dis32
->hwndItem
;
1027 dis
->hDC
= (HDC16
)dis32
->hDC
;
1028 dis
->itemData
= dis32
->itemData
;
1029 CONV_RECT32TO16( &dis32
->rcItem
, &dis
->rcItem
);
1030 *plparam
= (LPARAM
)SEGPTR_GET(dis
);
1033 case WM_MEASUREITEM
:
1035 MEASUREITEMSTRUCT32
*mis32
= (MEASUREITEMSTRUCT32
*)*plparam
;
1036 MEASUREITEMSTRUCT16
*mis
= (MEASUREITEMSTRUCT16
*)
1037 SEGPTR_ALLOC(sizeof(*mis
)+sizeof(LPARAM
));
1038 if (!mis
) return -1;
1039 mis
->CtlType
= (UINT16
)mis32
->CtlType
;
1040 mis
->CtlID
= (UINT16
)mis32
->CtlID
;
1041 mis
->itemID
= (UINT16
)mis32
->itemID
;
1042 mis
->itemWidth
= (UINT16
)mis32
->itemWidth
;
1043 mis
->itemHeight
= (UINT16
)mis32
->itemHeight
;
1044 mis
->itemData
= mis32
->itemData
;
1045 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1046 *plparam
= (LPARAM
)SEGPTR_GET(mis
);
1049 case WM_GETMINMAXINFO
:
1051 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)SEGPTR_ALLOC( sizeof(*mmi
) +
1053 if (!mmi
) return -1;
1054 STRUCT32_MINMAXINFO32to16( (MINMAXINFO32
*)*plparam
, mmi
);
1055 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1056 *plparam
= (LPARAM
)SEGPTR_GET(mmi
);
1062 *pwparam16
= (WPARAM16
)MIN( wParam32
, 0xff80 ); /* Must be < 64K */
1063 if (!(str
= SEGPTR_ALLOC(*pwparam16
+ sizeof(LPARAM
)))) return -1;
1064 *((LPARAM
*)str
)++ = *plparam
; /* Store the previous lParam */
1065 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1070 MDICREATESTRUCT16
*cs
;
1071 MDICREATESTRUCT32A
*cs32
= (MDICREATESTRUCT32A
*)*plparam
;
1074 if (!(cs
= SEGPTR_NEW(MDICREATESTRUCT16
))) return -1;
1075 STRUCT32_MDICREATESTRUCT32Ato16( cs32
, cs
);
1076 name
= SEGPTR_STRDUP( cs32
->szTitle
);
1077 cls
= SEGPTR_STRDUP( cs32
->szClass
);
1078 cs
->szTitle
= SEGPTR_GET(name
);
1079 cs
->szClass
= SEGPTR_GET(cls
);
1080 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1084 *pwparam16
= TRUE
; /* FIXME? */
1085 *plparam
= MAKELPARAM( (HMENU16
)LOWORD(wParam32
),
1086 (HMENU16
)LOWORD(*plparam
) );
1090 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
1094 NCCALCSIZE_PARAMS32
*nc32
= (NCCALCSIZE_PARAMS32
*)*plparam
;
1095 NCCALCSIZE_PARAMS16
*nc
= (NCCALCSIZE_PARAMS16
*)SEGPTR_ALLOC( sizeof(*nc
) + sizeof(LPARAM
) );
1098 CONV_RECT32TO16( &nc32
->rgrc
[0], &nc
->rgrc
[0] );
1102 CONV_RECT32TO16( &nc32
->rgrc
[1], &nc
->rgrc
[1] );
1103 CONV_RECT32TO16( &nc32
->rgrc
[2], &nc
->rgrc
[2] );
1104 if (!(wp
= SEGPTR_NEW(WINDOWPOS16
)))
1109 STRUCT32_WINDOWPOS32to16( nc32
->lppos
, wp
);
1110 nc
->lppos
= SEGPTR_GET(wp
);
1112 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1113 *plparam
= (LPARAM
)SEGPTR_GET(nc
);
1120 CREATESTRUCT32A
*cs32
= (CREATESTRUCT32A
*)*plparam
;
1123 if (!(cs
= SEGPTR_NEW(CREATESTRUCT16
))) return -1;
1124 STRUCT32_CREATESTRUCT32Ato16( cs32
, cs
);
1125 name
= SEGPTR_STRDUP( cs32
->lpszName
);
1126 cls
= SEGPTR_STRDUP( cs32
->lpszClass
);
1127 cs
->lpszName
= SEGPTR_GET(name
);
1128 cs
->lpszClass
= SEGPTR_GET(cls
);
1129 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1132 case WM_PARENTNOTIFY
:
1133 if ((LOWORD(wParam32
)==WM_CREATE
) || (LOWORD(wParam32
)==WM_DESTROY
))
1134 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
));
1135 /* else nothing to do */
1139 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1140 if (!str
) return -1;
1141 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1144 case WM_WINDOWPOSCHANGING
:
1145 case WM_WINDOWPOSCHANGED
:
1147 WINDOWPOS16
*wp
= (WINDOWPOS16
*)SEGPTR_ALLOC( sizeof(*wp
) +
1150 STRUCT32_WINDOWPOS32to16( (WINDOWPOS32
*)*plparam
, wp
);
1151 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1152 *plparam
= (LPARAM
)SEGPTR_GET(wp
);
1155 case WM_ASKCBFORMATNAME
:
1156 case WM_DEVMODECHANGE
:
1157 case WM_MDIACTIVATE
:
1158 case WM_PAINTCLIPBOARD
:
1159 case WM_SIZECLIPBOARD
:
1160 case WM_WININICHANGE
:
1161 fprintf( stderr
, "MapMsg32ATo16: message %04x needs translation\n",
1165 default: /* No translation needed */
1171 /**********************************************************************
1172 * WINPROC_UnmapMsg32ATo16
1174 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
1176 void WINPROC_UnmapMsg32ATo16( UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
1180 case WM_COMPAREITEM
:
1183 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam
) );
1185 case WM_MEASUREITEM
:
1187 MEASUREITEMSTRUCT16
*mis
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
1188 MEASUREITEMSTRUCT32
*mis32
= *(MEASUREITEMSTRUCT32
**)(mis
+ 1);
1189 mis32
->itemWidth
= mis
->itemWidth
;
1190 mis32
->itemHeight
= mis
->itemHeight
;
1194 case WM_GETMINMAXINFO
:
1196 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)PTR_SEG_TO_LIN(lParam
);
1197 lParam
= *(LPARAM
*)(mmi
+ 1);
1198 STRUCT32_MINMAXINFO16to32( mmi
, (MINMAXINFO32
*)lParam
);
1204 LPSTR str
= (LPSTR
)PTR_SEG_TO_LIN(lParam
);
1205 lParam
= *((LPARAM
*)str
- 1);
1206 strcpy( (LPSTR
)lParam
, str
);
1207 SEGPTR_FREE( (LPARAM
*)str
- 1 );
1212 MDICREATESTRUCT16
*cs
= (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
1213 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->szTitle
) );
1214 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->szClass
) );
1220 NCCALCSIZE_PARAMS32
*nc32
;
1221 NCCALCSIZE_PARAMS16
*nc
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(lParam
);
1222 lParam
= *(LPARAM
*)(nc
+ 1);
1223 nc32
= (NCCALCSIZE_PARAMS32
*)lParam
;
1224 CONV_RECT16TO32( &nc
->rgrc
[0], &nc32
->rgrc
[0] );
1227 CONV_RECT16TO32( &nc
->rgrc
[1], &nc32
->rgrc
[1] );
1228 CONV_RECT16TO32( &nc
->rgrc
[2], &nc32
->rgrc
[2] );
1229 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc
->lppos
),
1231 SEGPTR_FREE( PTR_SEG_TO_LIN(nc
->lppos
) );
1239 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
1240 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->lpszName
) );
1241 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->lpszClass
) );
1246 SEGPTR_FREE( PTR_SEG_TO_LIN(lParam
) );
1248 case WM_WINDOWPOSCHANGING
:
1249 case WM_WINDOWPOSCHANGED
:
1251 WINDOWPOS16
*wp
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
);
1252 lParam
= *(LPARAM
*)(wp
+ 1);
1253 STRUCT32_WINDOWPOS16to32( wp
, (WINDOWPOS32
*)lParam
);
1261 /**********************************************************************
1262 * WINPROC_MapMsg32WTo16
1264 * Map a message from 32-bit Unicode to 16-bit.
1265 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1267 INT32
WINPROC_MapMsg32WTo16( UINT32 msg32
, WPARAM32 wParam32
, UINT16
*pmsg16
,
1268 WPARAM16
*pwparam16
, LPARAM
*plparam
)
1276 CREATESTRUCT32W
*cs32
= (CREATESTRUCT32W
*)*plparam
;
1278 if (!(cs
= SEGPTR_NEW(CREATESTRUCT16
))) return -1;
1279 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCT32A
*)cs32
, cs
);
1280 if (HIWORD(cs32
->lpszName
))
1282 LPSTR name
= SEGPTR_ALLOC( lstrlen32W(cs32
->lpszName
) + 1 );
1283 STRING32_UniToAnsi( name
, cs32
->lpszName
);
1284 cs
->lpszName
= SEGPTR_GET(name
);
1286 else cs
->lpszName
= (SEGPTR
)cs32
->lpszName
;
1287 if (HIWORD(cs32
->lpszClass
))
1289 LPSTR name
= SEGPTR_ALLOC( lstrlen32W(cs32
->lpszClass
) + 1 );
1290 STRING32_UniToAnsi( name
, cs32
->lpszClass
);
1291 cs
->lpszClass
= SEGPTR_GET(name
);
1293 else cs
->lpszClass
= (SEGPTR
)cs32
->lpszClass
;
1294 *pmsg16
= (UINT16
)msg32
;
1295 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1296 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1301 MDICREATESTRUCT16
*cs
;
1302 MDICREATESTRUCT32W
*cs32
= (MDICREATESTRUCT32W
*)*plparam
;
1304 if (!(cs
= SEGPTR_NEW(MDICREATESTRUCT16
))) return -1;
1305 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCT32A
*)cs32
, cs
);
1306 if (HIWORD(cs32
->szTitle
))
1308 LPSTR name
= SEGPTR_ALLOC( lstrlen32W(cs32
->szTitle
) + 1 );
1309 STRING32_UniToAnsi( name
, cs32
->szTitle
);
1310 cs
->szTitle
= SEGPTR_GET(name
);
1312 else cs
->szTitle
= (SEGPTR
)cs32
->szTitle
;
1313 if (HIWORD(cs32
->szClass
))
1315 LPSTR name
= SEGPTR_ALLOC( lstrlen32W(cs32
->szClass
) + 1 );
1316 STRING32_UniToAnsi( name
, cs32
->szClass
);
1317 cs
->szClass
= SEGPTR_GET(name
);
1319 else cs
->szClass
= (SEGPTR
)cs32
->szClass
;
1320 *pmsg16
= (UINT16
)msg32
;
1321 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1322 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1327 LPSTR str
= SEGPTR_ALLOC( lstrlen32W((LPWSTR
)*plparam
) + 1 );
1328 if (!str
) return -1;
1329 STRING32_UniToAnsi( str
, (LPWSTR
)*plparam
);
1330 *pmsg16
= (UINT16
)msg32
;
1331 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1332 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1335 default: /* No Unicode translation needed */
1336 return WINPROC_MapMsg32ATo16( msg32
, wParam32
, pmsg16
,
1337 pwparam16
, plparam
);
1342 /**********************************************************************
1343 * WINPROC_UnmapMsg32WTo16
1345 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
1347 void WINPROC_UnmapMsg32WTo16( UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
1353 LPSTR str
= (LPSTR
)PTR_SEG_TO_LIN(lParam
);
1354 lParam
= *((LPARAM
*)str
- 1);
1355 STRING32_AnsiToUni( (LPWSTR
)lParam
, str
);
1356 SEGPTR_FREE( (LPARAM
*)str
- 1 );
1360 WINPROC_UnmapMsg32ATo16( msg
, wParam
, lParam
);
1366 /**********************************************************************
1367 * WINPROC_CallProc32ATo32W
1369 * Call a window procedure, translating args from Ansi to Unicode.
1371 static LRESULT
WINPROC_CallProc32ATo32W( WNDPROC32 func
, HWND32 hwnd
,
1372 UINT32 msg
, WPARAM32 wParam
,
1377 if (WINPROC_MapMsg32ATo32W( msg
, wParam
, &lParam
) == -1) return 0;
1378 result
= CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1379 WINPROC_UnmapMsg32ATo32W( msg
, wParam
, lParam
);
1384 /**********************************************************************
1385 * WINPROC_CallProc32WTo32A
1387 * Call a window procedure, translating args from Unicode to Ansi.
1389 static LRESULT
WINPROC_CallProc32WTo32A( WNDPROC32 func
, HWND32 hwnd
,
1390 UINT32 msg
, WPARAM32 wParam
,
1395 if (WINPROC_MapMsg32WTo32A( msg
, wParam
, &lParam
) == -1) return 0;
1396 result
= CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1397 WINPROC_UnmapMsg32WTo32A( msg
, wParam
, lParam
);
1402 /**********************************************************************
1403 * WINPROC_CallProc16To32A
1405 * Call a 32-bit window procedure, translating the 16-bit args.
1407 LRESULT
WINPROC_CallProc16To32A( HWND16 hwnd
, UINT16 msg
,
1408 WPARAM16 wParam
, LPARAM lParam
,
1415 if (WINPROC_MapMsg16To32A( msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
1417 result
= CallWndProc32( func
, hwnd
, msg32
, wParam32
, lParam
);
1418 WINPROC_UnmapMsg16To32A( msg32
, wParam32
, lParam
);
1423 /**********************************************************************
1424 * WINPROC_CallProc16To32W
1426 * Call a 32-bit window procedure, translating the 16-bit args.
1428 LRESULT
WINPROC_CallProc16To32W( HWND16 hwnd
, UINT16 msg
,
1429 WPARAM16 wParam
, LPARAM lParam
,
1436 if (WINPROC_MapMsg16To32W( msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
1438 result
= CallWndProc32( func
, hwnd
, msg32
, wParam32
, lParam
);
1439 WINPROC_UnmapMsg16To32W( msg32
, wParam32
, lParam
);
1444 /**********************************************************************
1445 * WINPROC_CallProc32ATo16
1447 * Call a 16-bit window procedure, translating the 32-bit args.
1449 static LRESULT
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND32 hwnd
,
1450 UINT32 msg
, WPARAM32 wParam
,
1456 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1457 WORD ds
= CURRENT_DS
;
1459 if (WINPROC_MapMsg32ATo16( msg
, wParam
, &msg16
, &wParam16
, &lParam
) == -1)
1461 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1462 result
= CallWndProc16( func
, hwnd
, msg16
, wParam16
, lParam
);
1464 WINPROC_UnmapMsg32ATo16( msg16
, wParam16
, lParam
);
1469 /**********************************************************************
1470 * WINPROC_CallProc32WTo16
1472 * Call a 16-bit window procedure, translating the 32-bit args.
1474 static LRESULT
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND32 hwnd
,
1475 UINT32 msg
, WPARAM32 wParam
,
1481 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
1482 WORD ds
= CURRENT_DS
;
1484 if (WINPROC_MapMsg32WTo16( msg
, wParam
, &msg16
, &wParam16
, &lParam
) == -1)
1486 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1487 result
= CallWndProc16( func
, hwnd
, msg16
, wParam16
, lParam
);
1489 WINPROC_UnmapMsg32WTo16( msg16
, wParam16
, lParam
);
1494 /**********************************************************************
1495 * CallWindowProc16 (USER.122)
1497 LRESULT
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
1498 WPARAM16 wParam
, LPARAM lParam
)
1502 WINDOWPROC
*proc
= WINPROC_GetPtr( func
);
1503 WORD ds
= CURRENT_DS
;
1507 wndPtr
= WIN_FindWndPtr( hwnd
);
1508 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1509 result
= CallWndProc16( (FARPROC16
)func
, hwnd
, msg
, wParam
, lParam
);
1514 wndPtr
= WIN_FindWndPtr( hwnd
);
1515 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1516 result
= CallWndProc16( WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_16
),
1517 hwnd
, msg
, wParam
, lParam
);
1525 if (!proc
->thunk
.t_from32
.proc
) return 0;
1526 wndPtr
= WIN_FindWndPtr( hwnd
);
1527 if (wndPtr
) CURRENT_DS
= wndPtr
->hInstance
;
1529 if ((msg
== WM_CREATE
) || (msg
== WM_NCCREATE
))
1531 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
1532 /* Build the CREATESTRUCT on the 16-bit stack. */
1533 /* This is really ugly, but some programs (notably the */
1534 /* "Undocumented Windows" examples) want it that way. */
1535 result
= CallWndProcNCCREATE16( proc
->thunk
.t_from32
.proc
,
1536 cs
->dwExStyle
, cs
->lpszClass
, cs
->lpszName
, cs
->style
,
1537 cs
->x
, cs
->y
, cs
->cx
, cs
->cy
, cs
->hwndParent
, cs
->hMenu
,
1538 cs
->hInstance
, (LONG
)cs
->lpCreateParams
, hwnd
, msg
, wParam
,
1539 MAKELONG( IF1632_Saved16_sp
-sizeof(CREATESTRUCT16
),
1540 IF1632_Saved16_ss
) );
1545 result
= CallWndProc16( proc
->thunk
.t_from32
.proc
,
1546 hwnd
, msg
, wParam
, lParam
);
1551 if (!proc
->thunk
.t_from16
.proc
) return 0;
1552 return WINPROC_CallProc16To32A( hwnd
, msg
, wParam
, lParam
,
1553 proc
->thunk
.t_from16
.proc
);
1555 if (!proc
->thunk
.t_from16
.proc
) return 0;
1556 return WINPROC_CallProc16To32W( hwnd
, msg
, wParam
, lParam
,
1557 proc
->thunk
.t_from16
.proc
);
1559 fprintf( stderr
, "CallWindowProc16: invalid proc %p\n", proc
);
1565 /**********************************************************************
1566 * CallWindowProc32A (USER32.17)
1568 LRESULT
CallWindowProc32A( WNDPROC32 func
, HWND32 hwnd
, UINT32 msg
,
1569 WPARAM32 wParam
, LPARAM lParam
)
1571 WINDOWPROC
*proc
= WINPROC_GetPtr( (WNDPROC16
)func
);
1573 if (!proc
) return CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1576 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32A
);
1577 return CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1583 if (!proc
->thunk
.t_from32
.proc
) return 0;
1584 return WINPROC_CallProc32ATo16( proc
->thunk
.t_from32
.proc
,
1585 hwnd
, msg
, wParam
, lParam
);
1587 if (!proc
->thunk
.t_from16
.proc
) return 0;
1588 return CallWndProc32( proc
->thunk
.t_from16
.proc
,
1589 hwnd
, msg
, wParam
, lParam
);
1591 if (!proc
->thunk
.t_from16
.proc
) return 0;
1592 return WINPROC_CallProc32ATo32W( proc
->thunk
.t_from16
.proc
,
1593 hwnd
, msg
, wParam
, lParam
);
1595 fprintf( stderr
, "CallWindowProc32A: invalid proc %p\n", proc
);
1601 /**********************************************************************
1602 * CallWindowProc32W (USER32.18)
1604 LRESULT
CallWindowProc32W( WNDPROC32 func
, HWND32 hwnd
, UINT32 msg
,
1605 WPARAM32 wParam
, LPARAM lParam
)
1607 WINDOWPROC
*proc
= WINPROC_GetPtr( (WNDPROC16
)func
);
1609 if (!proc
) return CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1612 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32W
);
1613 return CallWndProc32( func
, hwnd
, msg
, wParam
, lParam
);
1619 if (!proc
->thunk
.t_from32
.proc
) return 0;
1620 return WINPROC_CallProc32WTo16( proc
->thunk
.t_from32
.proc
,
1621 hwnd
, msg
, wParam
, lParam
);
1623 if (!proc
->thunk
.t_from16
.proc
) return 0;
1624 return WINPROC_CallProc32WTo32A( proc
->thunk
.t_from16
.proc
,
1625 hwnd
, msg
, wParam
, lParam
);
1627 if (!proc
->thunk
.t_from16
.proc
) return 0;
1628 return CallWndProc32( proc
->thunk
.t_from16
.proc
,
1629 hwnd
, msg
, wParam
, lParam
);
1631 fprintf( stderr
, "CallWindowProc32W: invalid proc %p\n", proc
);