2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
11 #include "wine/winbase16.h"
12 #include "wine/winuser16.h"
13 #include "stackframe.h"
14 #include "builtin16.h"
16 #include "selectors.h"
20 #include "debugtools.h"
27 DECLARE_DEBUG_CHANNEL(msg
)
28 DECLARE_DEBUG_CHANNEL(relay
)
29 DECLARE_DEBUG_CHANNEL(win
)
31 /* Window procedure 16-to-32-bit thunk,
32 * see BuildSpec16Files() in tools/build.c */
37 WORD pushw_bp
; /* pushw %bp */
38 BYTE pushl_func
; /* pushl $proc */
40 WORD pushw_ax
; /* pushw %ax */
41 BYTE pushl_relay
; /* pushl $relay */
42 void (*relay
)(); /* WINPROC_Thunk16To32A/W() */
43 BYTE lcall
; /* lcall cs:glue */
44 void (*glue
)(); /* CallFrom16Long */
45 WORD cs
; /* __FLATCS */
46 WORD lret
; /* lret $10 */
48 } WINPROC_THUNK_FROM16
;
51 /* Window procedure 32-to-16-bit thunk,
52 * see BuildSpec32Files() in tools/build.c */
56 BYTE popl_eax
; /* popl %eax (return address) */
57 BYTE pushl_func
; /* pushl $proc */
58 WNDPROC16 proc WINE_PACKED
;
59 BYTE pushl_eax
; /* pushl %eax */
60 BYTE jmp
; /* jmp relay (relative jump)*/
61 void (*relay
)() WINE_PACKED
; /* WINPROC_CallProc32ATo16() */
62 } WINPROC_THUNK_FROM32
;
64 /* Simple jmp to call 32-bit procedure directly */
67 BYTE jmp
; /* jmp proc (relative jump) */
68 WNDPROC proc WINE_PACKED
;
73 WINPROC_THUNK_FROM16 t_from16
;
74 WINPROC_THUNK_FROM32 t_from32
;
77 typedef struct tagWINDOWPROC
79 WINPROC_THUNK thunk
; /* Thunk */
80 WINPROC_JUMP jmp
; /* Jump */
81 struct tagWINDOWPROC
*next
; /* Next window proc */
82 UINT magic
; /* Magic number */
83 WINDOWPROCTYPE type
; /* Function type */
84 WINDOWPROCUSER user
; /* Function user */
87 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
89 #define WINPROC_THUNKPROC(pproc) \
90 (((pproc)->type == WIN_PROC_16) ? \
91 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
92 (WNDPROC16)((pproc)->thunk.t_from16.proc))
94 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
95 UINT msg
, WPARAM wParam
,
97 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
98 UINT msg
, WPARAM wParam
,
100 static LRESULT WINAPI
WINPROC_Thunk16To32A( WNDPROC func
, LPBYTE args
);
101 static LRESULT WINAPI
WINPROC_Thunk16To32W( WNDPROC func
, LPBYTE args
);
103 static HANDLE WinProcHeap
;
106 /**********************************************************************
109 BOOL
WINPROC_Init(void)
111 WinProcHeap
= HeapCreate( HEAP_WINE_SEGPTR
| HEAP_WINE_CODESEG
, 0, 0 );
114 WARN_(relay
)("Unable to create winproc heap\n" );
121 /**********************************************************************
122 * WINPROC_CallWndProc32
124 * Call a 32-bit WndProc.
126 static LRESULT
WINPROC_CallWndProc( WNDPROC proc
, HWND hwnd
, UINT msg
,
127 WPARAM wParam
, LPARAM lParam
)
132 TRACE_(relay
)("(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
133 proc
, hwnd
, SPY_GetMsgName(msg
), wParam
, lParam
);
134 /* To avoid any deadlocks, all the locks on the windows structures
135 must be suspended before the control is passed to the application */
136 iWndsLocks
= WIN_SuspendWndsLock();
137 retvalue
= proc( hwnd
, msg
, wParam
, lParam
);
138 WIN_RestoreWndsLock(iWndsLocks
);
142 /***********************************************************************
143 * WINPROC_CallWndProc16
145 * Call a 16-bit window procedure
147 static LRESULT WINAPI
WINPROC_CallWndProc16( WNDPROC16 proc
, HWND16 hwnd
,
148 UINT16 msg
, WPARAM16 wParam
,
154 WND
*wndPtr
= WIN_FindWndPtr( hwnd
);
156 TEB
*teb
= NtCurrentTeb();
159 /* Window procedures want ax = hInstance, ds = es = ss */
161 memset(&context
, '\0', sizeof(context
));
162 DS_reg(&context
) = SELECTOROF(teb
->cur_stack
);
163 ES_reg(&context
) = DS_reg(&context
);
164 EAX_reg(&context
) = wndPtr
? wndPtr
->hInstance
: DS_reg(&context
);
165 CS_reg(&context
) = SELECTOROF(proc
);
166 EIP_reg(&context
) = OFFSETOF(proc
);
167 EBP_reg(&context
) = OFFSETOF(teb
->cur_stack
)
168 + (WORD
)&((STACK16FRAME
*)0)->bp
;
170 WIN_ReleaseWndPtr(wndPtr
);
174 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
175 work if structures passed in lParam are placed in the stack/data
176 segment. Programmers easily make the mistake of converting lParam
177 to a near rather than a far pointer, since Windows apparently
178 allows this. We copy the structures to the 16 bit stack; this is
179 ugly but makes these programs work. */
184 offset
= sizeof(CREATESTRUCT16
); break;
186 offset
= sizeof(DRAWITEMSTRUCT16
); break;
188 offset
= sizeof(COMPAREITEMSTRUCT16
); break;
192 void *s
= PTR_SEG_TO_LIN(lParam
);
193 lParam
= stack16_push( offset
);
194 memcpy( PTR_SEG_TO_LIN(lParam
), s
, offset
);
198 iWndsLocks
= WIN_SuspendWndsLock();
200 args
= (WORD
*)THREAD_STACK16(teb
) - 5;
201 args
[0] = LOWORD(lParam
);
202 args
[1] = HIWORD(lParam
);
207 ret
= CallTo16RegisterShort( &context
, 5 * sizeof(WORD
) );
208 if (offset
) stack16_pop( offset
);
210 WIN_RestoreWndsLock(iWndsLocks
);
216 /**********************************************************************
219 * Return a pointer to the win proc.
221 static WINDOWPROC
*WINPROC_GetPtr( WNDPROC16 handle
)
226 /* Check for a linear pointer */
228 if (HEAP_IsInsideHeap( WinProcHeap
, 0, (LPVOID
)handle
))
230 ptr
= (BYTE
*)handle
;
231 /* First check if it is the jmp address */
232 if (*ptr
== 0xe9 /* jmp */) ptr
-= (int)&((WINDOWPROC
*)0)->jmp
-
233 (int)&((WINDOWPROC
*)0)->thunk
;
234 /* Now it must be the thunk address */
235 if (*ptr
== 0x58 /* popl eax */) ptr
-= (int)&((WINDOWPROC
*)0)->thunk
;
236 /* Now we have a pointer to the WINDOWPROC struct */
237 if (((WINDOWPROC
*)ptr
)->magic
== WINPROC_MAGIC
)
238 return (WINDOWPROC
*)ptr
;
241 /* Check for a segmented pointer */
243 if (!IsBadReadPtr16((SEGPTR
)handle
,sizeof(WINDOWPROC
)-sizeof(proc
->thunk
)))
245 ptr
= (BYTE
*)PTR_SEG_TO_LIN(handle
);
246 if (!HEAP_IsInsideHeap( WinProcHeap
, 0, ptr
)) return NULL
;
247 /* It must be the thunk address */
248 if (*ptr
== 0x58 /* popl eax */) ptr
-= (int)&((WINDOWPROC
*)0)->thunk
;
249 /* Now we have a pointer to the WINDOWPROC struct */
250 if (((WINDOWPROC
*)ptr
)->magic
== WINPROC_MAGIC
)
251 return (WINDOWPROC
*)ptr
;
258 /**********************************************************************
259 * WINPROC_AllocWinProc
261 * Allocate a new window procedure.
263 static WINDOWPROC
*WINPROC_AllocWinProc( WNDPROC16 func
, WINDOWPROCTYPE type
,
264 WINDOWPROCUSER user
)
266 WINDOWPROC
*proc
, *oldproc
;
268 /* Allocate a window procedure */
270 if (!(proc
= HeapAlloc( WinProcHeap
, 0, sizeof(WINDOWPROC
) ))) return 0;
272 /* Check if the function is already a win proc */
274 if ((oldproc
= WINPROC_GetPtr( func
)))
283 proc
->thunk
.t_from32
.popl_eax
= 0x58; /* popl %eax */
284 proc
->thunk
.t_from32
.pushl_func
= 0x68; /* pushl $proc */
285 proc
->thunk
.t_from32
.proc
= func
;
286 proc
->thunk
.t_from32
.pushl_eax
= 0x50; /* pushl %eax */
287 proc
->thunk
.t_from32
.jmp
= 0xe9; /* jmp relay*/
288 proc
->thunk
.t_from32
.relay
= /* relative jump */
289 (void(*)())((DWORD
)WINPROC_CallProc32ATo16
-
290 (DWORD
)(&proc
->thunk
.t_from32
.relay
+ 1));
294 proc
->thunk
.t_from16
.pushw_bp
= 0x5566; /* pushw %bp */
295 proc
->thunk
.t_from16
.pushl_func
= 0x68; /* pushl $proc */
296 proc
->thunk
.t_from16
.proc
= (FARPROC
)func
;
297 proc
->thunk
.t_from16
.pushw_ax
= 0x5066; /* pushw %ax */
298 proc
->thunk
.t_from16
.pushl_relay
= 0x68; /* pushl $relay */
299 proc
->thunk
.t_from16
.relay
= (type
== WIN_PROC_32A
) ?
300 (void(*)())WINPROC_Thunk16To32A
:
301 (void(*)())WINPROC_Thunk16To32W
;
302 proc
->thunk
.t_from16
.lcall
= 0x9a; /* lcall cs:glue */
303 proc
->thunk
.t_from16
.glue
= (void*)CallFrom16Long
;
304 GET_CS(proc
->thunk
.t_from16
.cs
);
305 proc
->thunk
.t_from16
.lret
= 0xca66;
306 proc
->thunk
.t_from16
.nArgs
= 10;
307 proc
->jmp
.jmp
= 0xe9;
308 /* Fixup relative jump */
309 proc
->jmp
.proc
= (WNDPROC
)((DWORD
)func
-
310 (DWORD
)(&proc
->jmp
.proc
+ 1));
313 /* Should not happen */
316 proc
->magic
= WINPROC_MAGIC
;
321 TRACE_(win
)("(%08x,%d): returning %08x\n",
322 (UINT
)func
, type
, (UINT
)proc
);
327 /**********************************************************************
330 * Get a window procedure pointer that can be passed to the Windows program.
332 WNDPROC16
WINPROC_GetProc( HWINDOWPROC proc
, WINDOWPROCTYPE type
)
334 if (!proc
) return NULL
;
335 if (type
== WIN_PROC_16
) /* We want a 16:16 address */
337 if (((WINDOWPROC
*)proc
)->type
== WIN_PROC_16
)
338 return ((WINDOWPROC
*)proc
)->thunk
.t_from32
.proc
;
340 return (WNDPROC16
)HEAP_GetSegptr( WinProcHeap
, 0,
341 &((WINDOWPROC
*)proc
)->thunk
);
343 else /* We want a 32-bit address */
345 if (((WINDOWPROC
*)proc
)->type
== WIN_PROC_16
)
346 return (WNDPROC16
)&((WINDOWPROC
*)proc
)->thunk
;
347 else if (type
!= ((WINDOWPROC
*)proc
)->type
)
348 /* Have to return the jmp address if types don't match */
349 return (WNDPROC16
)&((WINDOWPROC
*)proc
)->jmp
;
351 /* Some Win16 programs want to get back the proc they set */
352 return (WNDPROC16
)((WINDOWPROC
*)proc
)->thunk
.t_from16
.proc
;
357 /**********************************************************************
360 * Set the window procedure for a window or class. There are
361 * three tree classes of winproc callbacks:
363 * 1) class -> wp - not subclassed
364 * class -> wp -> wp -> wp -> wp - SetClassLong()
366 * 2) window -' / - not subclassed
367 * window -> wp -> wp ' - SetWindowLong()
369 * 3) timer -> wp - SetTimer()
371 * Initially, winproc of the window points to the current winproc
372 * thunk of its class. Subclassing prepends a new thunk to the
373 * window winproc chain at the head of the list. Thus, window thunk
374 * list includes class thunks and the latter are preserved when the
375 * window is destroyed.
378 BOOL
WINPROC_SetProc( HWINDOWPROC
*pFirst
, WNDPROC16 func
,
379 WINDOWPROCTYPE type
, WINDOWPROCUSER user
)
381 BOOL bRecycle
= FALSE
;
382 WINDOWPROC
*proc
, **ppPrev
;
384 /* Check if function is already in the list */
386 ppPrev
= (WINDOWPROC
**)pFirst
;
387 proc
= WINPROC_GetPtr( func
);
394 if ((*ppPrev
)->user
!= user
)
396 /* terminal thunk is being restored */
398 WINPROC_FreeProc( *pFirst
, (*ppPrev
)->user
);
399 *(WINDOWPROC
**)pFirst
= *ppPrev
;
408 if (((*ppPrev
)->type
== type
) &&
409 (func
== WINPROC_THUNKPROC(*ppPrev
)))
416 /* WPF_CLASS thunk terminates window thunk list */
417 if ((*ppPrev
)->user
!= user
) break;
418 ppPrev
= &(*ppPrev
)->next
;
423 /* Extract this thunk from the list */
425 *ppPrev
= proc
->next
;
427 else /* Allocate a new one */
429 if (proc
) /* Was already a win proc */
432 func
= WINPROC_THUNKPROC(proc
);
434 proc
= WINPROC_AllocWinProc( func
, type
, user
);
435 if (!proc
) return FALSE
;
438 /* Add the win proc at the head of the list */
440 TRACE_(win
)("(%08x,%08x,%d): res=%08x\n",
441 (UINT
)*pFirst
, (UINT
)func
, type
, (UINT
)proc
);
442 proc
->next
= *(WINDOWPROC
**)pFirst
;
443 *(WINDOWPROC
**)pFirst
= proc
;
448 /**********************************************************************
451 * Free a list of win procs.
453 void WINPROC_FreeProc( HWINDOWPROC proc
, WINDOWPROCUSER user
)
457 WINDOWPROC
*next
= ((WINDOWPROC
*)proc
)->next
;
458 if (((WINDOWPROC
*)proc
)->user
!= user
) break;
459 TRACE_(win
)("freeing %08x\n", (UINT
)proc
);
460 HeapFree( WinProcHeap
, 0, proc
);
466 /**********************************************************************
467 * WINPROC_GetProcType
469 * Return the window procedure type.
471 WINDOWPROCTYPE
WINPROC_GetProcType( HWINDOWPROC proc
)
474 (((WINDOWPROC
*)proc
)->magic
!= WINPROC_MAGIC
))
475 return WIN_PROC_INVALID
;
476 return ((WINDOWPROC
*)proc
)->type
;
478 /**********************************************************************
479 * WINPROC_TestCBForStr
481 * Return TRUE if the lparam is a string
483 static BOOL
WINPROC_TestCBForStr ( HWND hwnd
)
486 WND
* wnd
= WIN_FindWndPtr(hwnd
);
487 retvalue
= ( !(LOWORD(wnd
->dwStyle
) & (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) ||
488 (LOWORD(wnd
->dwStyle
) & CBS_HASSTRINGS
) );
489 WIN_ReleaseWndPtr(wnd
);
492 /**********************************************************************
493 * WINPROC_TestLBForStr
495 * Return TRUE if the lparam is a string
497 static BOOL
WINPROC_TestLBForStr ( HWND hwnd
)
500 WND
* wnd
= WIN_FindWndPtr(hwnd
);
501 retvalue
= ( !(LOWORD(wnd
->dwStyle
) & (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) ||
502 (LOWORD(wnd
->dwStyle
) & LBS_HASSTRINGS
) );
503 WIN_ReleaseWndPtr(wnd
);
507 /**********************************************************************
508 * WINPROC_MapMsg32ATo32W
510 * Map a message from Ansi to Unicode.
511 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
514 * WM_CHAR, WM_CHARTOITEM, WM_DEADCHAR, WM_MENUCHAR, WM_SYSCHAR, WM_SYSDEADCHAR
517 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
518 * the first four bytes are the handle of the icon
519 * when the WM_SETTEXT message has been used to set the icon
521 INT
WINPROC_MapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM
*plparam
)
527 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
528 wParam
* sizeof(WCHAR
) + sizeof(LPARAM
) );
530 *ptr
++ = *plparam
; /* Store previous lParam */
531 *plparam
= (LPARAM
)ptr
;
534 /* lparam is string (0-terminated) */
536 case WM_WININICHANGE
:
539 case CB_FINDSTRINGEXACT
:
540 case CB_SELECTSTRING
:
544 case LB_SELECTSTRING
:
546 *plparam
= (LPARAM
)HEAP_strdupAtoW( SystemHeap
, 0, (LPCSTR
)*plparam
);
547 return (*plparam
? 1 : -1);
553 { CREATESTRUCTW cs
; /* new structure */
554 LPCWSTR lpszName
; /* allocated Name */
555 LPCWSTR lpszClass
; /* allocated Class */
558 struct s
*xs
= HeapAlloc( SystemHeap
, HEAP_ZERO_MEMORY
, sizeof(struct s
));
560 xs
->cs
= *(CREATESTRUCTW
*)*plparam
;
561 if (HIWORD(xs
->cs
.lpszName
))
562 xs
->lpszName
= xs
->cs
.lpszName
= HEAP_strdupAtoW( SystemHeap
, 0,
563 (LPCSTR
)xs
->cs
.lpszName
);
564 if (HIWORD(xs
->cs
.lpszClass
))
565 xs
->lpszClass
= xs
->cs
.lpszClass
= HEAP_strdupAtoW( SystemHeap
, 0,
566 (LPCSTR
)xs
->cs
.lpszClass
);
567 *plparam
= (LPARAM
)xs
;
572 MDICREATESTRUCTW
*cs
=
573 (MDICREATESTRUCTW
*)HeapAlloc( SystemHeap
, 0, sizeof(*cs
) );
575 *cs
= *(MDICREATESTRUCTW
*)*plparam
;
576 if (HIWORD(cs
->szClass
))
577 cs
->szClass
= HEAP_strdupAtoW( SystemHeap
, 0,
578 (LPCSTR
)cs
->szClass
);
579 if (HIWORD(cs
->szTitle
))
580 cs
->szTitle
= HEAP_strdupAtoW( SystemHeap
, 0,
581 (LPCSTR
)cs
->szTitle
);
582 *plparam
= (LPARAM
)cs
;
588 case LB_INSERTSTRING
:
589 if ( WINPROC_TestLBForStr( hwnd
))
590 *plparam
= (LPARAM
)HEAP_strdupAtoW( SystemHeap
, 0, (LPCSTR
)*plparam
);
591 return (*plparam
? 1 : -1);
593 case LB_GETTEXT
: /* fixme: fixed sized buffer */
594 { if ( WINPROC_TestLBForStr( hwnd
))
595 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
597 *ptr
++ = *plparam
; /* Store previous lParam */
598 *plparam
= (LPARAM
)ptr
;
605 case CB_INSERTSTRING
:
606 if ( WINPROC_TestCBForStr( hwnd
))
607 *plparam
= (LPARAM
)HEAP_strdupAtoW( SystemHeap
, 0, (LPCSTR
)*plparam
);
608 return (*plparam
? 1 : -1);
610 case CB_GETLBTEXT
: /* fixme: fixed sized buffer */
611 { if ( WINPROC_TestCBForStr( hwnd
))
612 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
614 *ptr
++ = *plparam
; /* Store previous lParam */
615 *plparam
= (LPARAM
)ptr
;
622 { WORD len
= (WORD
)*plparam
;
623 LPARAM
*ptr
= (LPARAM
*) HEAP_xalloc( SystemHeap
, 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(WCHAR
) );
625 *ptr
++ = *plparam
; /* Store previous lParam */
626 *((WORD
*) ptr
) = len
; /* Store the length */
627 *plparam
= (LPARAM
)ptr
;
631 case WM_ASKCBFORMATNAME
:
632 case WM_DEVMODECHANGE
:
633 case WM_PAINTCLIPBOARD
:
634 case WM_SIZECLIPBOARD
:
635 case EM_SETPASSWORDCHAR
:
636 FIXME_(msg
)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg
), msg
);
638 default: /* No translation needed */
644 /**********************************************************************
645 * WINPROC_UnmapMsg32ATo32W
647 * Unmap a message that was mapped from Ansi to Unicode.
649 void WINPROC_UnmapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
655 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
656 lstrcpynWtoA( (LPSTR
)*ptr
, (LPWSTR
)lParam
, wParam
);
657 HeapFree( SystemHeap
, 0, ptr
);
665 { CREATESTRUCTW cs
; /* new structure */
666 LPWSTR lpszName
; /* allocated Name */
667 LPWSTR lpszClass
; /* allocated Class */
669 struct s
*xs
= (struct s
*)lParam
;
670 if (xs
->lpszName
) HeapFree( SystemHeap
, 0, xs
->lpszName
);
671 if (xs
->lpszClass
) HeapFree( SystemHeap
, 0, xs
->lpszClass
);
672 HeapFree( SystemHeap
, 0, xs
);
678 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
679 if (HIWORD(cs
->szTitle
))
680 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szTitle
);
681 if (HIWORD(cs
->szClass
))
682 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szClass
);
683 HeapFree( SystemHeap
, 0, cs
);
688 case WM_WININICHANGE
:
691 case CB_FINDSTRINGEXACT
:
692 case CB_SELECTSTRING
:
696 case LB_SELECTSTRING
:
698 HeapFree( SystemHeap
, 0, (void *)lParam
);
703 case LB_INSERTSTRING
:
704 if ( WINPROC_TestLBForStr( hwnd
))
705 HeapFree( SystemHeap
, 0, (void *)lParam
);
709 { if ( WINPROC_TestLBForStr( hwnd
))
710 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
711 lstrcpyWtoA( (LPSTR
)*ptr
, (LPWSTR
)(lParam
) );
712 HeapFree( SystemHeap
, 0, ptr
);
719 case CB_INSERTSTRING
:
720 if ( WINPROC_TestCBForStr( hwnd
))
721 HeapFree( SystemHeap
, 0, (void *)lParam
);
725 { if ( WINPROC_TestCBForStr( hwnd
))
726 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
727 lstrcpyWtoA( (LPSTR
)*ptr
, (LPWSTR
)(lParam
) );
728 HeapFree( SystemHeap
, 0, ptr
);
735 { LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lParam */
736 WORD len
= *(WORD
*) lParam
;
737 lstrcpynWtoA( (LPSTR
)*ptr
, (LPWSTR
)lParam
, len
);
738 HeapFree( SystemHeap
, 0, ptr
);
745 /**********************************************************************
746 * WINPROC_MapMsg32WTo32A
748 * Map a message from Unicode to Ansi.
749 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
751 INT
WINPROC_MapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM
*plparam
)
756 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
757 wParam
+ sizeof(LPARAM
) );
759 *ptr
++ = *plparam
; /* Store previous lParam */
760 *plparam
= (LPARAM
)ptr
;
765 case WM_WININICHANGE
:
768 case CB_FINDSTRINGEXACT
:
769 case CB_SELECTSTRING
:
773 case LB_SELECTSTRING
:
775 *plparam
= (LPARAM
)HEAP_strdupWtoA( SystemHeap
, 0, (LPCWSTR
)*plparam
);
776 return (*plparam
? 1 : -1);
781 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0,
784 *cs
= *(CREATESTRUCTA
*)*plparam
;
785 if (HIWORD(cs
->lpszName
))
786 cs
->lpszName
= HEAP_strdupWtoA( SystemHeap
, 0,
787 (LPCWSTR
)cs
->lpszName
);
788 if (HIWORD(cs
->lpszClass
))
789 cs
->lpszClass
= HEAP_strdupWtoA( SystemHeap
, 0,
790 (LPCWSTR
)cs
->lpszClass
);
791 *plparam
= (LPARAM
)cs
;
796 MDICREATESTRUCTA
*cs
=
797 (MDICREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0, sizeof(*cs
) );
799 *cs
= *(MDICREATESTRUCTA
*)*plparam
;
800 if (HIWORD(cs
->szTitle
))
801 cs
->szTitle
= HEAP_strdupWtoA( SystemHeap
, 0,
802 (LPCWSTR
)cs
->szTitle
);
803 if (HIWORD(cs
->szClass
))
804 cs
->szClass
= HEAP_strdupWtoA( SystemHeap
, 0,
805 (LPCWSTR
)cs
->szClass
);
806 *plparam
= (LPARAM
)cs
;
812 case LB_INSERTSTRING
:
813 if ( WINPROC_TestLBForStr( hwnd
))
814 *plparam
= (LPARAM
)HEAP_strdupWtoA( SystemHeap
, 0, (LPCWSTR
)*plparam
);
815 return (*plparam
? 1 : -1);
817 case LB_GETTEXT
: /* fixme: fixed sized buffer */
818 { if ( WINPROC_TestLBForStr( hwnd
))
819 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 + sizeof(LPARAM
) );
821 *ptr
++ = *plparam
; /* Store previous lParam */
822 *plparam
= (LPARAM
)ptr
;
829 case CB_INSERTSTRING
:
830 if ( WINPROC_TestCBForStr( hwnd
))
831 *plparam
= (LPARAM
)HEAP_strdupWtoA( SystemHeap
, 0, (LPCWSTR
)*plparam
);
832 return (*plparam
? 1 : -1);
834 case CB_GETLBTEXT
: /* fixme: fixed sized buffer */
835 { if ( WINPROC_TestCBForStr( hwnd
))
836 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 + sizeof(LPARAM
) );
838 *ptr
++ = *plparam
; /* Store previous lParam */
839 *plparam
= (LPARAM
)ptr
;
846 { WORD len
= (WORD
)*plparam
;
847 LPARAM
*ptr
= (LPARAM
*) HEAP_xalloc( SystemHeap
, 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(CHAR
) );
849 *ptr
++ = *plparam
; /* Store previous lParam */
850 *((WORD
*) ptr
) = len
; /* Store the length */
851 *plparam
= (LPARAM
)ptr
;
855 case WM_ASKCBFORMATNAME
:
856 case WM_DEVMODECHANGE
:
857 case WM_PAINTCLIPBOARD
:
858 case WM_SIZECLIPBOARD
:
859 case EM_SETPASSWORDCHAR
:
860 FIXME_(msg
)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg
),msg
);
862 default: /* No translation needed */
868 /**********************************************************************
869 * WINPROC_UnmapMsg32WTo32A
871 * Unmap a message that was mapped from Unicode to Ansi.
873 void WINPROC_UnmapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
879 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
880 lstrcpynAtoW( (LPWSTR
)*ptr
, (LPSTR
)lParam
, wParam
);
881 HeapFree( SystemHeap
, 0, ptr
);
886 case WM_WININICHANGE
:
889 case CB_FINDSTRINGEXACT
:
890 case CB_SELECTSTRING
:
894 case LB_SELECTSTRING
:
896 HeapFree( SystemHeap
, 0, (void *)lParam
);
902 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
903 if (HIWORD(cs
->lpszName
))
904 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszName
);
905 if (HIWORD(cs
->lpszClass
))
906 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszClass
);
907 HeapFree( SystemHeap
, 0, cs
);
913 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
914 if (HIWORD(cs
->szTitle
))
915 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szTitle
);
916 if (HIWORD(cs
->szClass
))
917 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szClass
);
918 HeapFree( SystemHeap
, 0, cs
);
924 case LB_INSERTSTRING
:
925 if ( WINPROC_TestLBForStr( hwnd
))
926 HeapFree( SystemHeap
, 0, (void *)lParam
);
930 { if ( WINPROC_TestLBForStr( hwnd
))
931 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
932 lstrcpyAtoW( (LPWSTR
)*ptr
, (LPSTR
)(lParam
) );
933 HeapFree( SystemHeap
, 0, ptr
);
940 case CB_INSERTSTRING
:
941 if ( WINPROC_TestCBForStr( hwnd
))
942 HeapFree( SystemHeap
, 0, (void *)lParam
);
946 { if ( WINPROC_TestCBForStr( hwnd
))
947 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
948 lstrcpyAtoW( (LPWSTR
)*ptr
, (LPSTR
)(lParam
) );
949 HeapFree( SystemHeap
, 0, ptr
);
956 { LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lparam */
957 WORD len
= *(WORD
*)ptr
;
958 lstrcpynAtoW( (LPWSTR
) *ptr
, (LPSTR
)lParam
, len
);
959 HeapFree( SystemHeap
, 0, ptr
);
966 /**********************************************************************
967 * WINPROC_MapMsg16To32A
969 * Map a message from 16- to 32-bit Ansi.
970 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
972 INT
WINPROC_MapMsg16To32A( UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
973 WPARAM
*pwparam32
, LPARAM
*plparam
)
975 *pmsg32
= (UINT
)msg16
;
976 *pwparam32
= (WPARAM
)wParam16
;
983 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
984 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
988 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
989 *plparam
= (LPARAM
)(HWND
)HIWORD(*plparam
);
992 if ( HIWORD(*plparam
) > CTLCOLOR_STATIC
) return -1;
993 *pmsg32
= WM_CTLCOLORMSGBOX
+ HIWORD(*plparam
);
994 *pwparam32
= (WPARAM
)(HDC
)wParam16
;
995 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
999 COMPAREITEMSTRUCT16
* cis16
= (COMPAREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1000 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)
1001 HeapAlloc(SystemHeap
, 0, sizeof(*cis
));
1002 if (!cis
) return -1;
1003 cis
->CtlType
= cis16
->CtlType
;
1004 cis
->CtlID
= cis16
->CtlID
;
1005 cis
->hwndItem
= cis16
->hwndItem
;
1006 cis
->itemID1
= cis16
->itemID1
;
1007 cis
->itemData1
= cis16
->itemData1
;
1008 cis
->itemID2
= cis16
->itemID2
;
1009 cis
->itemData2
= cis16
->itemData2
;
1010 cis
->dwLocaleId
= 0; /* FIXME */
1011 *plparam
= (LPARAM
)cis
;
1016 DELETEITEMSTRUCT16
* dis16
= (DELETEITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1017 DELETEITEMSTRUCT
*dis
= (DELETEITEMSTRUCT
*)
1018 HeapAlloc(SystemHeap
, 0, sizeof(*dis
));
1019 if (!dis
) return -1;
1020 dis
->CtlType
= dis16
->CtlType
;
1021 dis
->CtlID
= dis16
->CtlID
;
1022 dis
->hwndItem
= dis16
->hwndItem
;
1023 dis
->itemData
= dis16
->itemData
;
1024 *plparam
= (LPARAM
)dis
;
1027 case WM_MEASUREITEM
:
1029 MEASUREITEMSTRUCT16
* mis16
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1030 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)
1031 HeapAlloc(SystemHeap
, 0,
1032 sizeof(*mis
) + sizeof(LPARAM
));
1033 if (!mis
) return -1;
1034 mis
->CtlType
= mis16
->CtlType
;
1035 mis
->CtlID
= mis16
->CtlID
;
1036 mis
->itemID
= mis16
->itemID
;
1037 mis
->itemWidth
= mis16
->itemWidth
;
1038 mis
->itemHeight
= mis16
->itemHeight
;
1039 mis
->itemData
= mis16
->itemData
;
1040 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1041 *plparam
= (LPARAM
)mis
;
1046 DRAWITEMSTRUCT16
* dis16
= (DRAWITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1047 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)HeapAlloc(SystemHeap
, 0,
1049 if (!dis
) return -1;
1050 dis
->CtlType
= dis16
->CtlType
;
1051 dis
->CtlID
= dis16
->CtlID
;
1052 dis
->itemID
= dis16
->itemID
;
1053 dis
->itemAction
= dis16
->itemAction
;
1054 dis
->itemState
= dis16
->itemState
;
1055 dis
->hwndItem
= dis16
->hwndItem
;
1056 dis
->hDC
= dis16
->hDC
;
1057 dis
->itemData
= dis16
->itemData
;
1058 CONV_RECT16TO32( &dis16
->rcItem
, &dis
->rcItem
);
1059 *plparam
= (LPARAM
)dis
;
1062 case WM_GETMINMAXINFO
:
1064 MINMAXINFO
*mmi
= (MINMAXINFO
*)HeapAlloc( SystemHeap
, 0,
1065 sizeof(*mmi
) + sizeof(LPARAM
));
1066 if (!mmi
) return -1;
1067 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16
*)PTR_SEG_TO_LIN(*plparam
),
1069 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1070 *plparam
= (LPARAM
)mmi
;
1075 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
1079 MDICREATESTRUCT16
*cs16
=
1080 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1081 MDICREATESTRUCTA
*cs
=
1082 (MDICREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0,
1083 sizeof(*cs
) + sizeof(LPARAM
) );
1085 STRUCT32_MDICREATESTRUCT16to32A( cs16
, cs
);
1086 cs
->szTitle
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->szTitle
);
1087 cs
->szClass
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->szClass
);
1088 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1089 *plparam
= (LPARAM
)cs
;
1092 case WM_MDIGETACTIVE
:
1093 *plparam
= (LPARAM
)HeapAlloc( SystemHeap
, 0, sizeof(BOOL
) );
1094 *(BOOL
*)(*plparam
) = 0;
1098 *pmsg32
=WM_MDIREFRESHMENU
;
1099 *pwparam32
= (WPARAM
)(HMENU
)LOWORD(*plparam
);
1100 *plparam
= (LPARAM
)(HMENU
)HIWORD(*plparam
);
1103 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1104 *plparam
= (LPARAM
)(HMENU
)HIWORD(*plparam
);
1107 if((LOWORD(*plparam
) & MF_POPUP
) && (LOWORD(*plparam
) != 0xFFFF))
1109 HMENU hmenu
=(HMENU
)HIWORD(*plparam
);
1110 UINT Pos
=MENU_FindSubMenu( &hmenu
, wParam16
);
1111 if(Pos
==0xFFFF) Pos
=0; /* NO_SELECTED_ITEM */
1112 *pwparam32
= MAKEWPARAM( Pos
, LOWORD(*plparam
) );
1114 else *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1115 *plparam
= (LPARAM
)(HMENU
)HIWORD(*plparam
);
1117 case WM_MDIACTIVATE
:
1120 *pwparam32
= (WPARAM
)(HWND
)HIWORD(*plparam
);
1121 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
1123 else /* message sent to MDI client */
1124 *pwparam32
= wParam16
;
1128 NCCALCSIZE_PARAMS16
*nc16
;
1129 NCCALCSIZE_PARAMS
*nc
;
1131 nc
= (NCCALCSIZE_PARAMS
*)HeapAlloc( SystemHeap
, 0,
1132 sizeof(*nc
) + sizeof(LPARAM
) );
1134 nc16
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(*plparam
);
1135 CONV_RECT16TO32( &nc16
->rgrc
[0], &nc
->rgrc
[0] );
1138 nc
->lppos
= (WINDOWPOS
*)HeapAlloc( SystemHeap
, 0,
1139 sizeof(*nc
->lppos
) );
1140 CONV_RECT16TO32( &nc16
->rgrc
[1], &nc
->rgrc
[1] );
1141 CONV_RECT16TO32( &nc16
->rgrc
[2], &nc
->rgrc
[2] );
1142 if (nc
->lppos
) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc16
->lppos
), nc
->lppos
);
1144 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1145 *plparam
= (LPARAM
)nc
;
1151 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1152 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0,
1153 sizeof(*cs
) + sizeof(LPARAM
) );
1155 STRUCT32_CREATESTRUCT16to32A( cs16
, cs
);
1156 cs
->lpszName
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->lpszName
);
1157 cs
->lpszClass
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->lpszClass
);
1158 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1159 *plparam
= (LPARAM
)cs
;
1162 case WM_PARENTNOTIFY
:
1163 if ((wParam16
== WM_CREATE
) || (wParam16
== WM_DESTROY
))
1165 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
1166 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
1169 case WM_WINDOWPOSCHANGING
:
1170 case WM_WINDOWPOSCHANGED
:
1172 WINDOWPOS
*wp
= (WINDOWPOS
*)HeapAlloc( SystemHeap
, 0,
1173 sizeof(*wp
) + sizeof(LPARAM
) );
1175 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(*plparam
),
1177 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1178 *plparam
= (LPARAM
)wp
;
1184 LPMSG16 msg16
= (LPMSG16
)PTR_SEG_TO_LIN(*plparam
);
1185 LPMSG msg32
= (LPMSG
)HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1187 if (!msg32
) return -1;
1188 msg32
->hwnd
= msg16
->hwnd
;
1189 msg32
->lParam
= msg16
->lParam
;
1190 msg32
->time
= msg16
->time
;
1191 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1192 /* this is right, right? */
1193 if (WINPROC_MapMsg16To32A(msg16
->message
,msg16
->wParam
,
1194 &msg32
->message
,&msg32
->wParam
,
1195 &msg32
->lParam
)<0) {
1196 HeapFree( SystemHeap
, 0, msg32
);
1199 *plparam
= (LPARAM
)msg32
;
1204 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
1206 case WM_ACTIVATEAPP
:
1208 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1209 a 32bit window. Might be superflous with 32bit interprocess
1212 HTASK16 htask
= (HTASK16
) *plparam
;
1213 DWORD idThread
= (DWORD
)((TDB
*)GlobalLock16(htask
))->teb
->tid
;
1214 *plparam
= (LPARAM
) idThread
;
1217 case WM_ASKCBFORMATNAME
:
1218 case WM_DEVMODECHANGE
:
1219 case WM_PAINTCLIPBOARD
:
1220 case WM_SIZECLIPBOARD
:
1221 case WM_WININICHANGE
:
1222 FIXME_(msg
)("message %04x needs translation\n",msg16
);
1225 default: /* No translation needed */
1231 /**********************************************************************
1232 * WINPROC_UnmapMsg16To32A
1234 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1236 LRESULT
WINPROC_UnmapMsg16To32A( HWND16 hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1241 case WM_COMPAREITEM
:
1244 HeapFree( SystemHeap
, 0, (LPVOID
)lParam
);
1246 case WM_MEASUREITEM
:
1248 MEASUREITEMSTRUCT16
*mis16
;
1249 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lParam
;
1250 lParam
= *(LPARAM
*)(mis
+ 1);
1251 mis16
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
1252 mis16
->itemWidth
= (UINT16
)mis
->itemWidth
;
1253 mis16
->itemHeight
= (UINT16
)mis
->itemHeight
;
1254 HeapFree( SystemHeap
, 0, mis
);
1257 case WM_GETMINMAXINFO
:
1259 MINMAXINFO
*mmi
= (MINMAXINFO
*)lParam
;
1260 lParam
= *(LPARAM
*)(mmi
+ 1);
1261 STRUCT32_MINMAXINFO32to16( mmi
,
1262 (MINMAXINFO16
*)PTR_SEG_TO_LIN(lParam
));
1263 HeapFree( SystemHeap
, 0, mmi
);
1268 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
1269 lParam
= *(LPARAM
*)(cs
+ 1);
1270 STRUCT32_MDICREATESTRUCT32Ato16( cs
,
1271 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1272 HeapFree( SystemHeap
, 0, cs
);
1275 case WM_MDIGETACTIVE
:
1276 result
= MAKELONG( LOWORD(result
), (BOOL16
)(*(BOOL
*)lParam
) );
1277 HeapFree( SystemHeap
, 0, (BOOL
*)lParam
);
1281 NCCALCSIZE_PARAMS16
*nc16
;
1282 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lParam
;
1283 lParam
= *(LPARAM
*)(nc
+ 1);
1284 nc16
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(lParam
);
1285 CONV_RECT32TO16( &nc
->rgrc
[0], &nc16
->rgrc
[0] );
1288 CONV_RECT32TO16( &nc
->rgrc
[1], &nc16
->rgrc
[1] );
1289 CONV_RECT32TO16( &nc
->rgrc
[2], &nc16
->rgrc
[2] );
1292 STRUCT32_WINDOWPOS32to16( nc
->lppos
,
1293 (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc16
->lppos
));
1294 HeapFree( SystemHeap
, 0, nc
->lppos
);
1297 HeapFree( SystemHeap
, 0, nc
);
1303 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1304 lParam
= *(LPARAM
*)(cs
+ 1);
1305 STRUCT32_CREATESTRUCT32Ato16( cs
,
1306 (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1307 HeapFree( SystemHeap
, 0, cs
);
1310 case WM_WINDOWPOSCHANGING
:
1311 case WM_WINDOWPOSCHANGED
:
1313 WINDOWPOS
*wp
= (WINDOWPOS
*)lParam
;
1314 lParam
= *(LPARAM
*)(wp
+ 1);
1315 STRUCT32_WINDOWPOS32to16(wp
,(WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
));
1316 HeapFree( SystemHeap
, 0, wp
);
1322 LPMSG msg32
= (LPMSG
)lParam
;
1324 WINPROC_UnmapMsg16To32A( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1326 HeapFree( SystemHeap
, 0, msg32
);
1334 /**********************************************************************
1335 * WINPROC_MapMsg16To32W
1337 * Map a message from 16- to 32-bit Unicode.
1338 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1340 INT
WINPROC_MapMsg16To32W( HWND16 hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
1341 WPARAM
*pwparam32
, LPARAM
*plparam
)
1347 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
1348 return WINPROC_MapMsg32ATo32W( hwnd
, *pmsg32
, *pwparam32
, plparam
);
1352 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1353 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)HeapAlloc( SystemHeap
, 0,
1354 sizeof(*cs
) + sizeof(LPARAM
) );
1356 STRUCT32_CREATESTRUCT16to32A( cs16
, (CREATESTRUCTA
*)cs
);
1357 cs
->lpszName
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->lpszName
);
1358 cs
->lpszClass
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->lpszClass
);
1359 if (HIWORD(cs
->lpszName
))
1360 cs
->lpszName
= HEAP_strdupAtoW( SystemHeap
, 0,
1361 (LPCSTR
)cs
->lpszName
);
1362 if (HIWORD(cs
->lpszClass
))
1363 cs
->lpszClass
= HEAP_strdupAtoW( SystemHeap
, 0,
1364 (LPCSTR
)cs
->lpszClass
);
1365 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1366 *plparam
= (LPARAM
)cs
;
1371 MDICREATESTRUCT16
*cs16
=
1372 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1373 MDICREATESTRUCTW
*cs
=
1374 (MDICREATESTRUCTW
*)HeapAlloc( SystemHeap
, 0,
1375 sizeof(*cs
) + sizeof(LPARAM
) );
1377 STRUCT32_MDICREATESTRUCT16to32A( cs16
, (MDICREATESTRUCTA
*)cs
);
1378 cs
->szTitle
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->szTitle
);
1379 cs
->szClass
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->szClass
);
1380 if (HIWORD(cs
->szTitle
))
1381 cs
->szTitle
= HEAP_strdupAtoW( SystemHeap
, 0,
1382 (LPCSTR
)cs
->szTitle
);
1383 if (HIWORD(cs
->szClass
))
1384 cs
->szClass
= HEAP_strdupAtoW( SystemHeap
, 0,
1385 (LPCSTR
)cs
->szClass
);
1386 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1387 *plparam
= (LPARAM
)cs
;
1393 LPMSG16 msg16
= (LPMSG16
)PTR_SEG_TO_LIN(*plparam
);
1394 LPMSG msg32
= (LPMSG
)HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1396 if (!msg32
) return -1;
1397 msg32
->hwnd
= msg16
->hwnd
;
1398 msg32
->lParam
= msg16
->lParam
;
1399 msg32
->time
= msg16
->time
;
1400 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1401 /* this is right, right? */
1402 if (WINPROC_MapMsg16To32W(hwnd
, msg16
->message
,msg16
->wParam
,
1403 &msg32
->message
,&msg32
->wParam
,
1404 &msg32
->lParam
)<0) {
1405 HeapFree( SystemHeap
, 0, msg32
);
1408 *plparam
= (LPARAM
)msg32
;
1412 default: /* No Unicode translation needed */
1413 return WINPROC_MapMsg16To32A( msg16
, wParam16
, pmsg32
,
1414 pwparam32
, plparam
);
1419 /**********************************************************************
1420 * WINPROC_UnmapMsg16To32W
1422 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1424 LRESULT
WINPROC_UnmapMsg16To32W( HWND16 hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1431 WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
);
1436 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
1437 lParam
= *(LPARAM
*)(cs
+ 1);
1438 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs
,
1439 (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1440 if (HIWORD(cs
->lpszName
))
1441 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszName
);
1442 if (HIWORD(cs
->lpszClass
))
1443 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszClass
);
1444 HeapFree( SystemHeap
, 0, cs
);
1449 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
1450 lParam
= *(LPARAM
*)(cs
+ 1);
1451 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs
,
1452 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1453 if (HIWORD(cs
->szTitle
))
1454 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szTitle
);
1455 if (HIWORD(cs
->szClass
))
1456 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szClass
);
1457 HeapFree( SystemHeap
, 0, cs
);
1463 LPMSG msg32
= (LPMSG
)lParam
;
1465 WINPROC_UnmapMsg16To32W( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1467 HeapFree( SystemHeap
, 0, msg32
);
1471 return WINPROC_UnmapMsg16To32A( hwnd
, msg
, wParam
, lParam
, result
);
1477 /**********************************************************************
1478 * WINPROC_MapMsg32ATo16
1480 * Map a message from 32-bit Ansi to 16-bit.
1481 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1483 INT
WINPROC_MapMsg32ATo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
1484 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
1487 *pmsg16
= (UINT16
)msg32
;
1488 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1496 *pmsg16
= (UINT16
)msg32
+ (BM_GETCHECK16
- BM_GETCHECK
);
1505 case EM_SCROLLCARET
:
1508 case EM_GETLINECOUNT
:
1520 case EM_LINEFROMCHAR
:
1521 case EM_SETTABSTOPS
:
1522 case EM_SETPASSWORDCHAR
:
1523 case EM_EMPTYUNDOBUFFER
:
1524 case EM_GETFIRSTVISIBLELINE
:
1525 case EM_SETREADONLY
:
1526 case EM_SETWORDBREAKPROC
:
1527 case EM_GETWORDBREAKPROC
:
1528 case EM_GETPASSWORDCHAR
:
1529 *pmsg16
= (UINT16
)msg32
+ (EM_GETSEL16
- EM_GETSEL
);
1534 case LB_DELETESTRING
:
1535 case LB_GETANCHORINDEX
:
1536 case LB_GETCARETINDEX
:
1539 case LB_GETHORIZONTALEXTENT
:
1540 case LB_GETITEMDATA
:
1541 case LB_GETITEMHEIGHT
:
1543 case LB_GETSELCOUNT
:
1545 case LB_GETTOPINDEX
:
1546 case LB_RESETCONTENT
:
1547 case LB_SELITEMRANGE
:
1548 case LB_SELITEMRANGEEX
:
1549 case LB_SETANCHORINDEX
:
1550 case LB_SETCARETINDEX
:
1551 case LB_SETCOLUMNWIDTH
:
1553 case LB_SETHORIZONTALEXTENT
:
1554 case LB_SETITEMDATA
:
1555 case LB_SETITEMHEIGHT
:
1557 case LB_SETTOPINDEX
:
1558 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1560 case CB_DELETESTRING
:
1562 case CB_GETLBTEXTLEN
:
1564 case CB_RESETCONTENT
:
1568 case CB_SHOWDROPDOWN
:
1569 case CB_SETITEMDATA
:
1570 case CB_SETITEMHEIGHT
:
1571 case CB_GETITEMHEIGHT
:
1572 case CB_SETEXTENDEDUI
:
1573 case CB_GETEXTENDEDUI
:
1574 case CB_GETDROPPEDSTATE
:
1575 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1578 *pmsg16
= CB_GETEDITSEL16
;
1583 case LB_FINDSTRINGEXACT
:
1584 case LB_INSERTSTRING
:
1585 case LB_SELECTSTRING
:
1589 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1590 if (!str
) return -1;
1591 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1593 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1598 case CB_FINDSTRINGEXACT
:
1599 case CB_INSERTSTRING
:
1600 case CB_SELECTSTRING
:
1603 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1604 if (!str
) return -1;
1605 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1607 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1610 case LB_GETITEMRECT
:
1613 rect
= (RECT16
*)SEGPTR_ALLOC( sizeof(RECT16
) + sizeof(LPARAM
) );
1614 if (!rect
) return -1;
1615 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1616 *plparam
= (LPARAM
)SEGPTR_GET(rect
);
1618 *pmsg16
= LB_GETITEMRECT16
;
1620 case LB_GETSELITEMS
:
1623 *pwparam16
= (WPARAM16
)MIN( wParam32
, 0x7f80 ); /* Must be < 64K */
1624 if (!(items
= SEGPTR_ALLOC( *pwparam16
* sizeof(INT16
)
1625 + sizeof(LPARAM
)))) return -1;
1626 *((LPARAM
*)items
)++ = *plparam
; /* Store the previous lParam */
1627 *plparam
= (LPARAM
)SEGPTR_GET(items
);
1629 *pmsg16
= LB_GETSELITEMS16
;
1631 case LB_SETTABSTOPS
:
1636 *pwparam16
= (WPARAM16
)MIN( wParam32
, 0x7f80 ); /* Must be < 64K */
1637 if (!(stops
= SEGPTR_ALLOC( *pwparam16
* sizeof(INT16
)
1638 + sizeof(LPARAM
)))) return -1;
1639 for (i
= 0; i
< *pwparam16
; i
++) stops
[i
] = *((LPINT
)*plparam
+i
);
1640 *plparam
= (LPARAM
)SEGPTR_GET(stops
);
1643 *pmsg16
= LB_SETTABSTOPS16
;
1646 case CB_GETDROPPEDCONTROLRECT
:
1649 rect
= (RECT16
*)SEGPTR_ALLOC( sizeof(RECT16
) + sizeof(LPARAM
) );
1650 if (!rect
) return -1;
1651 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1652 *plparam
= (LPARAM
)SEGPTR_GET(rect
);
1654 *pmsg16
= CB_GETDROPPEDCONTROLRECT16
;
1658 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1659 *pmsg16
= LB_GETTEXT16
;
1663 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1664 *pmsg16
= CB_GETLBTEXT16
;
1669 *plparam
= MAKELONG( (INT16
)(INT
)wParam32
, (INT16
)*plparam
);
1670 *pmsg16
= EM_SETSEL16
;
1677 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
1681 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
1683 case WM_CTLCOLORMSGBOX
:
1684 case WM_CTLCOLOREDIT
:
1685 case WM_CTLCOLORLISTBOX
:
1686 case WM_CTLCOLORBTN
:
1687 case WM_CTLCOLORDLG
:
1688 case WM_CTLCOLORSCROLLBAR
:
1689 case WM_CTLCOLORSTATIC
:
1690 *pmsg16
= WM_CTLCOLOR
;
1691 *plparam
= MAKELPARAM( (HWND16
)*plparam
,
1692 (WORD
)msg32
- WM_CTLCOLORMSGBOX
);
1694 case WM_COMPAREITEM
:
1696 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)*plparam
;
1697 COMPAREITEMSTRUCT16
*cis
= SEGPTR_NEW(COMPAREITEMSTRUCT16
);
1698 if (!cis
) return -1;
1699 cis
->CtlType
= (UINT16
)cis32
->CtlType
;
1700 cis
->CtlID
= (UINT16
)cis32
->CtlID
;
1701 cis
->hwndItem
= (HWND16
)cis32
->hwndItem
;
1702 cis
->itemID1
= (UINT16
)cis32
->itemID1
;
1703 cis
->itemData1
= cis32
->itemData1
;
1704 cis
->itemID2
= (UINT16
)cis32
->itemID2
;
1705 cis
->itemData2
= cis32
->itemData2
;
1706 *plparam
= (LPARAM
)SEGPTR_GET(cis
);
1711 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)*plparam
;
1712 DELETEITEMSTRUCT16
*dis
= SEGPTR_NEW(DELETEITEMSTRUCT16
);
1713 if (!dis
) return -1;
1714 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1715 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1716 dis
->itemID
= (UINT16
)dis32
->itemID
;
1717 dis
->hwndItem
= (HWND16
)dis32
->hwndItem
;
1718 dis
->itemData
= dis32
->itemData
;
1719 *plparam
= (LPARAM
)SEGPTR_GET(dis
);
1724 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)*plparam
;
1725 DRAWITEMSTRUCT16
*dis
= SEGPTR_NEW(DRAWITEMSTRUCT16
);
1726 if (!dis
) return -1;
1727 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1728 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1729 dis
->itemID
= (UINT16
)dis32
->itemID
;
1730 dis
->itemAction
= (UINT16
)dis32
->itemAction
;
1731 dis
->itemState
= (UINT16
)dis32
->itemState
;
1732 dis
->hwndItem
= (HWND16
)dis32
->hwndItem
;
1733 dis
->hDC
= (HDC16
)dis32
->hDC
;
1734 dis
->itemData
= dis32
->itemData
;
1735 CONV_RECT32TO16( &dis32
->rcItem
, &dis
->rcItem
);
1736 *plparam
= (LPARAM
)SEGPTR_GET(dis
);
1739 case WM_MEASUREITEM
:
1741 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)*plparam
;
1742 MEASUREITEMSTRUCT16
*mis
= (MEASUREITEMSTRUCT16
*)
1743 SEGPTR_ALLOC(sizeof(*mis
)+sizeof(LPARAM
));
1744 if (!mis
) return -1;
1745 mis
->CtlType
= (UINT16
)mis32
->CtlType
;
1746 mis
->CtlID
= (UINT16
)mis32
->CtlID
;
1747 mis
->itemID
= (UINT16
)mis32
->itemID
;
1748 mis
->itemWidth
= (UINT16
)mis32
->itemWidth
;
1749 mis
->itemHeight
= (UINT16
)mis32
->itemHeight
;
1750 mis
->itemData
= mis32
->itemData
;
1751 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1752 *plparam
= (LPARAM
)SEGPTR_GET(mis
);
1755 case WM_GETMINMAXINFO
:
1757 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)SEGPTR_ALLOC( sizeof(*mmi
) +
1759 if (!mmi
) return -1;
1760 STRUCT32_MINMAXINFO32to16( (MINMAXINFO
*)*plparam
, mmi
);
1761 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1762 *plparam
= (LPARAM
)SEGPTR_GET(mmi
);
1768 *pwparam16
= (WPARAM16
)MIN( wParam32
, 0xff80 ); /* Must be < 64K */
1769 if (!(str
= SEGPTR_ALLOC(*pwparam16
+ sizeof(LPARAM
)))) return -1;
1770 *((LPARAM
*)str
)++ = *plparam
; /* Store the previous lParam */
1771 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1776 MDICREATESTRUCT16
*cs
;
1777 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)*plparam
;
1780 if (!(cs
= SEGPTR_NEW(MDICREATESTRUCT16
))) return -1;
1781 STRUCT32_MDICREATESTRUCT32Ato16( cs32
, cs
);
1782 name
= SEGPTR_STRDUP( cs32
->szTitle
);
1783 cls
= SEGPTR_STRDUP( cs32
->szClass
);
1784 cs
->szTitle
= SEGPTR_GET(name
);
1785 cs
->szClass
= SEGPTR_GET(cls
);
1786 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1789 case WM_MDIGETACTIVE
:
1792 *plparam
= MAKELPARAM( (HMENU16
)LOWORD(wParam32
),
1793 (HMENU16
)LOWORD(*plparam
) );
1794 *pwparam16
= (*plparam
== 0);
1797 if(HIWORD(wParam32
) & MF_POPUP
)
1800 if (((UINT
)HIWORD(wParam32
) != 0xFFFF) || (*plparam
))
1802 if((hmenu
= GetSubMenu((HMENU16
)*plparam
, *pwparam16
)))
1808 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
1810 case WM_MDIACTIVATE
:
1812 WND
*tempWnd
= WIN_FindWndPtr(hwnd
);
1813 if( WIDGETS_IsControl(tempWnd
, BIC32_MDICLIENT
) )
1815 *pwparam16
= (HWND
)wParam32
;
1820 *pwparam16
= ((HWND
)*plparam
== hwnd
);
1821 *plparam
= MAKELPARAM( (HWND16
)LOWORD(*plparam
),
1822 (HWND16
)LOWORD(wParam32
) );
1824 WIN_ReleaseWndPtr(tempWnd
);
1829 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)*plparam
;
1830 NCCALCSIZE_PARAMS16
*nc
= (NCCALCSIZE_PARAMS16
*)SEGPTR_ALLOC( sizeof(*nc
) + sizeof(LPARAM
) );
1833 CONV_RECT32TO16( &nc32
->rgrc
[0], &nc
->rgrc
[0] );
1837 CONV_RECT32TO16( &nc32
->rgrc
[1], &nc
->rgrc
[1] );
1838 CONV_RECT32TO16( &nc32
->rgrc
[2], &nc
->rgrc
[2] );
1839 if (!(wp
= SEGPTR_NEW(WINDOWPOS16
)))
1844 STRUCT32_WINDOWPOS32to16( nc32
->lppos
, wp
);
1845 nc
->lppos
= SEGPTR_GET(wp
);
1847 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1848 *plparam
= (LPARAM
)SEGPTR_GET(nc
);
1855 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)*plparam
;
1858 if (!(cs
= SEGPTR_NEW(CREATESTRUCT16
))) return -1;
1859 STRUCT32_CREATESTRUCT32Ato16( cs32
, cs
);
1860 name
= SEGPTR_STRDUP( cs32
->lpszName
);
1861 cls
= SEGPTR_STRDUP( cs32
->lpszClass
);
1862 cs
->lpszName
= SEGPTR_GET(name
);
1863 cs
->lpszClass
= SEGPTR_GET(cls
);
1864 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1867 case WM_PARENTNOTIFY
:
1868 if ((LOWORD(wParam32
)==WM_CREATE
) || (LOWORD(wParam32
)==WM_DESTROY
))
1869 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
));
1870 /* else nothing to do */
1873 *plparam
= MapLS( (NMHDR
*)*plparam
); /* NMHDR is already 32-bit */
1877 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1878 if (!str
) return -1;
1879 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1882 case WM_WINDOWPOSCHANGING
:
1883 case WM_WINDOWPOSCHANGED
:
1885 WINDOWPOS16
*wp
= (WINDOWPOS16
*)SEGPTR_ALLOC( sizeof(*wp
) +
1888 STRUCT32_WINDOWPOS32to16( (WINDOWPOS
*)*plparam
, wp
);
1889 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1890 *plparam
= (LPARAM
)SEGPTR_GET(wp
);
1895 LPMSG msg32
= (LPMSG
) *plparam
;
1896 LPMSG16 msg16
= (LPMSG16
) SEGPTR_NEW( MSG16
);
1898 if (!msg16
) return -1;
1899 msg16
->hwnd
= msg32
->hwnd
;
1900 msg16
->lParam
= msg32
->lParam
;
1901 msg16
->time
= msg32
->time
;
1902 CONV_POINT32TO16(&msg32
->pt
,&msg16
->pt
);
1903 /* this is right, right? */
1904 if (WINPROC_MapMsg32ATo16(msg32
->hwnd
,msg32
->message
,msg32
->wParam
,
1905 &msg16
->message
,&msg16
->wParam
, &msg16
->lParam
)<0) {
1906 SEGPTR_FREE( msg16
);
1909 *plparam
= (LPARAM
)SEGPTR_GET(msg16
);
1914 case WM_ACTIVATEAPP
:
1916 *plparam
= (LPARAM
)THREAD_IdToTEB((DWORD
) *plparam
)->htask16
;
1919 case WM_ASKCBFORMATNAME
:
1920 case WM_DEVMODECHANGE
:
1921 case WM_PAINTCLIPBOARD
:
1922 case WM_SIZECLIPBOARD
:
1923 case WM_WININICHANGE
:
1924 FIXME_(msg
)("message %04x needs translation\n", msg32
);
1926 default: /* No translation needed */
1932 /**********************************************************************
1933 * WINPROC_UnmapMsg32ATo16
1935 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
1937 void WINPROC_UnmapMsg32ATo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1946 case LB_FINDSTRINGEXACT
:
1947 case LB_INSERTSTRING
:
1948 case LB_SELECTSTRING
:
1949 case LB_SETTABSTOPS
:
1952 case CB_FINDSTRINGEXACT
:
1953 case CB_INSERTSTRING
:
1954 case CB_SELECTSTRING
:
1956 case WM_COMPAREITEM
:
1960 SEGPTR_FREE( PTR_SEG_TO_LIN(p16
->lParam
) );
1963 case CB_GETDROPPEDCONTROLRECT
:
1964 case LB_GETITEMRECT
:
1966 RECT16
*rect
= (RECT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1967 p16
->lParam
= *(LPARAM
*)(rect
+ 1);
1968 CONV_RECT16TO32( rect
, (RECT
*)(p16
->lParam
));
1969 SEGPTR_FREE( rect
);
1972 case LB_GETSELITEMS
:
1975 LPINT16 items
= (LPINT16
)PTR_SEG_TO_LIN(lParam
);
1976 p16
->lParam
= *((LPARAM
*)items
- 1);
1977 for (i
= 0; i
< p16
->wParam
; i
++) *((LPINT
)(p16
->lParam
) + i
) = items
[i
];
1978 SEGPTR_FREE( (LPARAM
*)items
- 1 );
1984 *((LPUINT
)(wParam
)) = LOWORD(p16
->lResult
);
1986 *((LPUINT
)(lParam
)) = HIWORD(p16
->lResult
); /* FIXME: substract 1? */
1991 UnMapLS( (SEGPTR
)(p16
->lParam
) );
1994 case WM_MEASUREITEM
:
1996 MEASUREITEMSTRUCT16
*mis
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1997 MEASUREITEMSTRUCT
*mis32
= *(MEASUREITEMSTRUCT
**)(mis
+ 1);
1998 mis32
->itemWidth
= mis
->itemWidth
;
1999 mis32
->itemHeight
= mis
->itemHeight
;
2003 case WM_GETMINMAXINFO
:
2005 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)PTR_SEG_TO_LIN(p16
->lParam
);
2006 p16
->lParam
= *(LPARAM
*)(mmi
+ 1);
2007 STRUCT32_MINMAXINFO16to32( mmi
, (MINMAXINFO
*)(p16
->lParam
) );
2013 LPSTR str
= (LPSTR
)PTR_SEG_TO_LIN(p16
->lParam
);
2014 p16
->lParam
= *((LPARAM
*)str
- 1);
2015 lstrcpynA( (LPSTR
)(p16
->lParam
), str
, p16
->wParam
);
2016 SEGPTR_FREE( (LPARAM
*)str
- 1 );
2021 MDICREATESTRUCT16
*cs
= (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
2022 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->szTitle
) );
2023 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->szClass
) );
2027 case WM_MDIGETACTIVE
:
2028 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(p16
->lResult
);
2029 p16
->lResult
= (HWND
)LOWORD(p16
->lResult
);
2033 NCCALCSIZE_PARAMS
*nc32
;
2034 NCCALCSIZE_PARAMS16
*nc
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(p16
->lParam
);
2035 p16
->lParam
= *(LPARAM
*)(nc
+ 1);
2036 nc32
= (NCCALCSIZE_PARAMS
*)(p16
->lParam
);
2037 CONV_RECT16TO32( &nc
->rgrc
[0], &nc32
->rgrc
[0] );
2040 CONV_RECT16TO32( &nc
->rgrc
[1], &nc32
->rgrc
[1] );
2041 CONV_RECT16TO32( &nc
->rgrc
[2], &nc32
->rgrc
[2] );
2042 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc
->lppos
),
2044 SEGPTR_FREE( PTR_SEG_TO_LIN(nc
->lppos
) );
2052 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
2053 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->lpszName
) );
2054 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->lpszClass
) );
2058 case WM_WINDOWPOSCHANGING
:
2059 case WM_WINDOWPOSCHANGED
:
2061 WINDOWPOS16
*wp
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(p16
->lParam
);
2062 p16
->lParam
= *(LPARAM
*)(wp
+ 1);
2063 STRUCT32_WINDOWPOS16to32( wp
, (WINDOWPOS
*)p16
->lParam
);
2068 UnMapLS(p16
->lParam
);
2073 LPMSG16 msg16
= (LPMSG16
)PTR_SEG_TO_LIN(p16
->lParam
);
2075 msgp16
.wParam
=msg16
->wParam
;
2076 msgp16
.lParam
=msg16
->lParam
;
2077 WINPROC_UnmapMsg32ATo16(((LPMSG
)lParam
)->hwnd
, ((LPMSG
)lParam
)->message
,
2078 ((LPMSG
)lParam
)->wParam
, ((LPMSG
)lParam
)->lParam
,
2087 /**********************************************************************
2088 * WINPROC_MapMsg32WTo16
2090 * Map a message from 32-bit Unicode to 16-bit.
2091 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2093 INT
WINPROC_MapMsg32WTo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
2094 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
2101 case LB_FINDSTRINGEXACT
:
2102 case LB_INSERTSTRING
:
2103 case LB_SELECTSTRING
:
2107 LPSTR str
= SEGPTR_STRDUP_WtoA( (LPWSTR
)*plparam
);
2108 if (!str
) return -1;
2109 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2110 *plparam
= (LPARAM
)SEGPTR_GET(str
);
2112 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
2117 case CB_FINDSTRINGEXACT
:
2118 case CB_INSERTSTRING
:
2119 case CB_SELECTSTRING
:
2122 LPSTR str
= SEGPTR_STRDUP_WtoA( (LPWSTR
)*plparam
);
2123 if (!str
) return -1;
2124 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2125 *plparam
= (LPARAM
)SEGPTR_GET(str
);
2127 *pmsg16
= (UINT16
)msg32
+ (CB_ADDSTRING16
- CB_ADDSTRING
);
2134 CREATESTRUCTW
*cs32
= (CREATESTRUCTW
*)*plparam
;
2137 if (!(cs
= SEGPTR_NEW(CREATESTRUCT16
))) return -1;
2138 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs32
, cs
);
2139 name
= SEGPTR_STRDUP_WtoA( cs32
->lpszName
);
2140 cls
= SEGPTR_STRDUP_WtoA( cs32
->lpszClass
);
2141 cs
->lpszName
= SEGPTR_GET(name
);
2142 cs
->lpszClass
= SEGPTR_GET(cls
);
2143 *pmsg16
= (UINT16
)msg32
;
2144 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2145 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
2150 MDICREATESTRUCT16
*cs
;
2151 MDICREATESTRUCTW
*cs32
= (MDICREATESTRUCTW
*)*plparam
;
2154 if (!(cs
= SEGPTR_NEW(MDICREATESTRUCT16
))) return -1;
2155 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs32
, cs
);
2156 name
= SEGPTR_STRDUP_WtoA( cs32
->szTitle
);
2157 cls
= SEGPTR_STRDUP_WtoA( cs32
->szClass
);
2158 cs
->szTitle
= SEGPTR_GET(name
);
2159 cs
->szClass
= SEGPTR_GET(cls
);
2160 *pmsg16
= (UINT16
)msg32
;
2161 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2162 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
2167 LPSTR str
= SEGPTR_STRDUP_WtoA( (LPWSTR
)*plparam
);
2168 if (!str
) return -1;
2169 *pmsg16
= (UINT16
)msg32
;
2170 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2171 *plparam
= (LPARAM
)SEGPTR_GET(str
);
2174 default: /* No Unicode translation needed */
2175 return WINPROC_MapMsg32ATo16( hwnd
, msg32
, wParam32
, pmsg16
,
2176 pwparam16
, plparam
);
2181 /**********************************************************************
2182 * WINPROC_UnmapMsg32WTo16
2184 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2186 void WINPROC_UnmapMsg32WTo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2193 LPSTR str
= (LPSTR
)PTR_SEG_TO_LIN(p16
->lParam
);
2194 p16
->lParam
= *((LPARAM
*)str
- 1);
2195 lstrcpyAtoW( (LPWSTR
)(p16
->lParam
), str
);
2196 SEGPTR_FREE( (LPARAM
*)str
- 1 );
2200 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, p16
);
2206 /**********************************************************************
2207 * WINPROC_CallProc32ATo32W
2209 * Call a window procedure, translating args from Ansi to Unicode.
2211 static LRESULT
WINPROC_CallProc32ATo32W( WNDPROC func
, HWND hwnd
,
2212 UINT msg
, WPARAM wParam
,
2217 if (WINPROC_MapMsg32ATo32W( hwnd
, msg
, wParam
, &lParam
) == -1) return 0;
2218 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2219 WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
);
2224 /**********************************************************************
2225 * WINPROC_CallProc32WTo32A
2227 * Call a window procedure, translating args from Unicode to Ansi.
2229 static LRESULT
WINPROC_CallProc32WTo32A( WNDPROC func
, HWND hwnd
,
2230 UINT msg
, WPARAM wParam
,
2235 if (WINPROC_MapMsg32WTo32A( hwnd
, msg
, wParam
, &lParam
) == -1) return 0;
2236 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2237 WINPROC_UnmapMsg32WTo32A( hwnd
, msg
, wParam
, lParam
);
2242 /**********************************************************************
2243 * WINPROC_CallProc16To32A
2245 * Call a 32-bit window procedure, translating the 16-bit args.
2247 static LRESULT
WINPROC_CallProc16To32A( WNDPROC func
, HWND16 hwnd
,
2248 UINT16 msg
, WPARAM16 wParam
,
2255 if (WINPROC_MapMsg16To32A( msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2257 result
= WINPROC_CallWndProc( func
, hwnd
, msg32
, wParam32
, lParam
);
2258 return WINPROC_UnmapMsg16To32A( hwnd
, msg32
, wParam32
, lParam
, result
);
2261 /**********************************************************************
2262 * WINPROC_Thunk16To32A
2264 static LRESULT WINAPI
WINPROC_Thunk16To32A( WNDPROC func
, LPBYTE args
)
2266 HWND16 hwnd
= *(HWND16
*)( args
+8 );
2267 UINT16 msg
= *(HWND16
*)( args
+6 );
2268 WPARAM16 wParam
= *(HWND16
*)( args
+4 );
2269 LPARAM lParam
= *(LPARAM
*)( args
+0 );
2271 return WINPROC_CallProc16To32A( func
, hwnd
, msg
, wParam
, lParam
);
2275 /**********************************************************************
2276 * WINPROC_CallProc16To32W
2278 * Call a 32-bit window procedure, translating the 16-bit args.
2280 static LRESULT
WINPROC_CallProc16To32W( WNDPROC func
, HWND16 hwnd
,
2281 UINT16 msg
, WPARAM16 wParam
,
2288 if (WINPROC_MapMsg16To32W( hwnd
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2291 result
= WINPROC_CallWndProc( func
, hwnd
, msg32
, wParam32
, lParam
);
2293 return WINPROC_UnmapMsg16To32W( hwnd
, msg32
, wParam32
, lParam
, result
);
2296 /**********************************************************************
2297 * WINPROC_Thunk16To32W
2299 static LRESULT WINAPI
WINPROC_Thunk16To32W( WNDPROC func
, LPBYTE args
)
2301 HWND16 hwnd
= *(HWND16
*)( args
+8 );
2302 UINT16 msg
= *(HWND16
*)( args
+6 );
2303 WPARAM16 wParam
= *(HWND16
*)( args
+4 );
2304 LPARAM lParam
= *(LPARAM
*)( args
+0 );
2306 return WINPROC_CallProc16To32W( func
, hwnd
, msg
, wParam
, lParam
);
2309 /**********************************************************************
2310 * WINPROC_CallProc32ATo16
2312 * Call a 16-bit window procedure, translating the 32-bit args.
2314 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
2315 UINT msg
, WPARAM wParam
,
2321 mp16
.lParam
= lParam
;
2322 if (WINPROC_MapMsg32ATo16( hwnd
, msg
, wParam
,
2323 &msg16
, &mp16
.wParam
, &mp16
.lParam
) == -1)
2325 mp16
.lResult
= WINPROC_CallWndProc16( func
, hwnd
, msg16
,
2326 mp16
.wParam
, mp16
.lParam
);
2327 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2328 return mp16
.lResult
;
2332 /**********************************************************************
2333 * WINPROC_CallProc32WTo16
2335 * Call a 16-bit window procedure, translating the 32-bit args.
2337 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
2338 UINT msg
, WPARAM wParam
,
2344 mp16
.lParam
= lParam
;
2345 if (WINPROC_MapMsg32WTo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
,
2346 &mp16
.lParam
) == -1)
2348 mp16
.lResult
= WINPROC_CallWndProc16( func
, hwnd
, msg16
,
2349 mp16
.wParam
, mp16
.lParam
);
2350 WINPROC_UnmapMsg32WTo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2351 return mp16
.lResult
;
2355 /**********************************************************************
2356 * CallWindowProc16 (USER.122)
2358 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2359 WPARAM16 wParam
, LPARAM lParam
)
2361 WINDOWPROC
*proc
= WINPROC_GetPtr( func
);
2364 return WINPROC_CallWndProc16( func
, hwnd
, msg
, wParam
, lParam
);
2367 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_16
);
2368 return WINPROC_CallWndProc16( func
, hwnd
, msg
, wParam
, lParam
);
2374 if (!proc
->thunk
.t_from32
.proc
) return 0;
2375 return WINPROC_CallWndProc16( proc
->thunk
.t_from32
.proc
,
2376 hwnd
, msg
, wParam
, lParam
);
2378 if (!proc
->thunk
.t_from16
.proc
) return 0;
2379 return WINPROC_CallProc16To32A( proc
->thunk
.t_from16
.proc
,
2380 hwnd
, msg
, wParam
, lParam
);
2382 if (!proc
->thunk
.t_from16
.proc
) return 0;
2383 return WINPROC_CallProc16To32W( proc
->thunk
.t_from16
.proc
,
2384 hwnd
, msg
, wParam
, lParam
);
2386 WARN_(relay
)("Invalid proc %p\n", proc
);
2392 /**********************************************************************
2393 * CallWindowProc32A (USER32.18)
2395 * The CallWindowProc() function invokes the windows procedure _func_,
2396 * with _hwnd_ as the target window, the message specified by _msg_, and
2397 * the message parameters _wParam_ and _lParam_.
2399 * Some kinds of argument conversion may be done, I'm not sure what.
2401 * CallWindowProc() may be used for windows subclassing. Use
2402 * SetWindowLong() to set a new windows procedure for windows of the
2403 * subclass, and handle subclassed messages in the new windows
2404 * procedure. The new windows procedure may then use CallWindowProc()
2405 * with _func_ set to the parent class's windows procedure to dispatch
2406 * the message to the superclass.
2410 * The return value is message dependent.
2416 LRESULT WINAPI
CallWindowProcA(
2417 WNDPROC func
, /* window procedure */
2418 HWND hwnd
, /* target window */
2419 UINT msg
, /* message */
2420 WPARAM wParam
, /* message dependent parameter */
2421 LPARAM lParam
/* message dependent parameter */
2423 WINDOWPROC
*proc
= WINPROC_GetPtr( (WNDPROC16
)func
);
2425 if (!proc
) return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2428 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32A
);
2429 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2435 if (!proc
->thunk
.t_from32
.proc
) return 0;
2436 return WINPROC_CallProc32ATo16( proc
->thunk
.t_from32
.proc
,
2437 hwnd
, msg
, wParam
, lParam
);
2439 if (!proc
->thunk
.t_from16
.proc
) return 0;
2440 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
2441 hwnd
, msg
, wParam
, lParam
);
2443 if (!proc
->thunk
.t_from16
.proc
) return 0;
2444 return WINPROC_CallProc32ATo32W( proc
->thunk
.t_from16
.proc
,
2445 hwnd
, msg
, wParam
, lParam
);
2447 WARN_(relay
)("Invalid proc %p\n", proc
);
2453 /**********************************************************************
2454 * CallWindowProc32W (USER32.19)
2456 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
2457 WPARAM wParam
, LPARAM lParam
)
2459 WINDOWPROC
*proc
= WINPROC_GetPtr( (WNDPROC16
)func
);
2461 if (!proc
) return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2464 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32W
);
2465 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2471 if (!proc
->thunk
.t_from32
.proc
) return 0;
2472 return WINPROC_CallProc32WTo16( proc
->thunk
.t_from32
.proc
,
2473 hwnd
, msg
, wParam
, lParam
);
2475 if (!proc
->thunk
.t_from16
.proc
) return 0;
2476 return WINPROC_CallProc32WTo32A( proc
->thunk
.t_from16
.proc
,
2477 hwnd
, msg
, wParam
, lParam
);
2479 if (!proc
->thunk
.t_from16
.proc
) return 0;
2480 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
2481 hwnd
, msg
, wParam
, lParam
);
2483 WARN_(relay
)("Invalid proc %p\n", proc
);