2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
8 #include "wine/winbase16.h"
12 #include "selectors.h"
22 /* Window procedure 16-to-32-bit thunk,
23 * see BuildSpec16Files() in tools/build.c */
27 BYTE popl_eax
; /* popl %eax (return address) */
28 BYTE pushl_func
; /* pushl $proc */
29 WNDPROC proc WINE_PACKED
;
30 BYTE pushl_eax
; /* pushl %eax */
31 WORD pushw_bp WINE_PACKED
; /* pushw %bp */
32 BYTE pushl_thunk
; /* pushl $thunkfrom16 */
33 void (*thunk32
)() WINE_PACKED
;
34 BYTE lcall
; /* lcall cs:relay */
35 void (*relay
)() WINE_PACKED
; /* WINPROC_CallProc16To32A/W() */
37 } WINPROC_THUNK_FROM16
;
39 /* Window procedure 32-to-16-bit thunk,
40 * see BuildSpec32Files() in tools/build.c */
44 BYTE popl_eax
; /* popl %eax (return address) */
45 BYTE pushl_func
; /* pushl $proc */
46 WNDPROC16 proc WINE_PACKED
;
47 BYTE pushl_eax
; /* pushl %eax */
48 BYTE jmp
; /* jmp relay (relative jump)*/
49 void (*relay
)() WINE_PACKED
; /* WINPROC_CallProc32ATo16() */
50 } WINPROC_THUNK_FROM32
;
52 /* Simple jmp to call 32-bit procedure directly */
55 BYTE jmp
; /* jmp proc (relative jump) */
56 WNDPROC proc WINE_PACKED
;
61 WINPROC_THUNK_FROM16 t_from16
;
62 WINPROC_THUNK_FROM32 t_from32
;
65 typedef struct tagWINDOWPROC
67 WINPROC_THUNK thunk
; /* Thunk */
68 WINPROC_JUMP jmp
; /* Jump */
69 struct tagWINDOWPROC
*next
; /* Next window proc */
70 UINT magic
; /* Magic number */
71 WINDOWPROCTYPE type
; /* Function type */
72 WINDOWPROCUSER user
; /* Function user */
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 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
83 UINT msg
, WPARAM wParam
,
85 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
86 UINT msg
, WPARAM wParam
,
88 static LRESULT
WINPROC_CallProc16To32A( HWND16 hwnd
, UINT16 msg
,
89 WPARAM16 wParam
, LPARAM lParam
,
91 static LRESULT
WINPROC_CallProc16To32W( HWND16 hwnd
, UINT16 msg
,
92 WPARAM16 wParam
, LPARAM lParam
,
95 static HANDLE WinProcHeap
;
98 /**********************************************************************
101 BOOL
WINPROC_Init(void)
103 WinProcHeap
= HeapCreate( HEAP_WINE_SEGPTR
| HEAP_WINE_CODESEG
, 0, 0 );
106 WARN(relay
, "Unable to create winproc heap\n" );
113 /**********************************************************************
114 * WINPROC_CallWndProc32
116 * Call a 32-bit WndProc.
118 static LRESULT
WINPROC_CallWndProc( WNDPROC proc
, HWND hwnd
, UINT msg
,
119 WPARAM wParam
, LPARAM lParam
)
121 TRACE(relay
, "(wndproc=%p,hwnd=%08x,msg=%s,wp=%08x,lp=%08lx)\n",
122 proc
, hwnd
, SPY_GetMsgName(msg
), wParam
, lParam
);
123 return proc( hwnd
, msg
, wParam
, lParam
);
127 /**********************************************************************
130 * Return a pointer to the win proc.
132 static WINDOWPROC
*WINPROC_GetPtr( WNDPROC16 handle
)
137 /* Check for a linear pointer */
139 if (HEAP_IsInsideHeap( WinProcHeap
, 0, (LPVOID
)handle
))
141 ptr
= (BYTE
*)handle
;
142 /* First check if it is the jmp address */
143 if (*ptr
== 0xe9 /* jmp */) ptr
-= (int)&((WINDOWPROC
*)0)->jmp
-
144 (int)&((WINDOWPROC
*)0)->thunk
;
145 /* Now it must be the thunk address */
146 if (*ptr
== 0x58 /* popl eax */) ptr
-= (int)&((WINDOWPROC
*)0)->thunk
;
147 /* Now we have a pointer to the WINDOWPROC struct */
148 if (((WINDOWPROC
*)ptr
)->magic
== WINPROC_MAGIC
)
149 return (WINDOWPROC
*)ptr
;
152 /* Check for a segmented pointer */
154 if (!IsBadReadPtr16((SEGPTR
)handle
,sizeof(WINDOWPROC
)-sizeof(proc
->thunk
)))
156 ptr
= (BYTE
*)PTR_SEG_TO_LIN(handle
);
157 if (!HEAP_IsInsideHeap( WinProcHeap
, 0, ptr
)) return NULL
;
158 /* It must be the thunk address */
159 if (*ptr
== 0x58 /* popl eax */) ptr
-= (int)&((WINDOWPROC
*)0)->thunk
;
160 /* Now we have a pointer to the WINDOWPROC struct */
161 if (((WINDOWPROC
*)ptr
)->magic
== WINPROC_MAGIC
)
162 return (WINDOWPROC
*)ptr
;
169 /**********************************************************************
170 * WINPROC_AllocWinProc
172 * Allocate a new window procedure.
174 static WINDOWPROC
*WINPROC_AllocWinProc( WNDPROC16 func
, WINDOWPROCTYPE type
,
175 WINDOWPROCUSER user
)
177 WINDOWPROC
*proc
, *oldproc
;
179 /* Allocate a window procedure */
181 if (!(proc
= HeapAlloc( WinProcHeap
, 0, sizeof(WINDOWPROC
) ))) return 0;
183 /* Check if the function is already a win proc */
185 if ((oldproc
= WINPROC_GetPtr( func
)))
194 proc
->thunk
.t_from32
.popl_eax
= 0x58; /* popl %eax */
195 proc
->thunk
.t_from32
.pushl_func
= 0x68; /* pushl $proc */
196 proc
->thunk
.t_from32
.proc
= func
;
197 proc
->thunk
.t_from32
.pushl_eax
= 0x50; /* pushl %eax */
198 proc
->thunk
.t_from32
.jmp
= 0xe9; /* jmp relay*/
199 proc
->thunk
.t_from32
.relay
= /* relative jump */
200 (void(*)())((DWORD
)WINPROC_CallProc32ATo16
-
201 (DWORD
)(&proc
->thunk
.t_from32
.relay
+ 1));
205 proc
->thunk
.t_from16
.popl_eax
= 0x58; /* popl %eax */
206 proc
->thunk
.t_from16
.pushl_func
= 0x68; /* pushl $proc */
207 proc
->thunk
.t_from16
.proc
= (FARPROC
)func
;
208 proc
->thunk
.t_from16
.pushl_eax
= 0x50; /* pushl %eax */
209 proc
->thunk
.t_from16
.pushw_bp
= 0x5566; /* pushw %bp */
210 proc
->thunk
.t_from16
.pushl_thunk
= 0x68; /* pushl $thunkfrom16 */
211 proc
->thunk
.t_from16
.thunk32
= (type
== WIN_PROC_32A
) ?
212 (void(*)())WINPROC_CallProc16To32A
:
213 (void(*)())WINPROC_CallProc16To32W
;
214 proc
->thunk
.t_from16
.lcall
= 0x9a; /* lcall cs:relay */
215 proc
->thunk
.t_from16
.relay
= (void*)Callbacks
->CallFrom16WndProc
;
216 GET_CS(proc
->thunk
.t_from16
.cs
);
217 proc
->jmp
.jmp
= 0xe9;
218 /* Fixup relative jump */
219 proc
->jmp
.proc
= (WNDPROC
)((DWORD
)func
-
220 (DWORD
)(&proc
->jmp
.proc
+ 1));
223 /* Should not happen */
226 proc
->magic
= WINPROC_MAGIC
;
231 TRACE(win
, "(%08x,%d): returning %08x\n",
232 (UINT
)func
, type
, (UINT
)proc
);
237 /**********************************************************************
240 * Get a window procedure pointer that can be passed to the Windows program.
242 WNDPROC16
WINPROC_GetProc( HWINDOWPROC proc
, WINDOWPROCTYPE type
)
244 if (!proc
) return NULL
;
245 if (type
== WIN_PROC_16
) /* We want a 16:16 address */
247 if (((WINDOWPROC
*)proc
)->type
== WIN_PROC_16
)
248 return ((WINDOWPROC
*)proc
)->thunk
.t_from32
.proc
;
250 return (WNDPROC16
)HEAP_GetSegptr( WinProcHeap
, 0,
251 &((WINDOWPROC
*)proc
)->thunk
);
253 else /* We want a 32-bit address */
255 if (((WINDOWPROC
*)proc
)->type
== WIN_PROC_16
)
256 return (WNDPROC16
)&((WINDOWPROC
*)proc
)->thunk
;
257 else if (type
!= ((WINDOWPROC
*)proc
)->type
)
258 /* Have to return the jmp address if types don't match */
259 return (WNDPROC16
)&((WINDOWPROC
*)proc
)->jmp
;
261 /* Some Win16 programs want to get back the proc they set */
262 return (WNDPROC16
)((WINDOWPROC
*)proc
)->thunk
.t_from16
.proc
;
267 /**********************************************************************
270 * Set the window procedure for a window or class. There are
271 * three tree classes of winproc callbacks:
273 * 1) class -> wp - not subclassed
274 * class -> wp -> wp -> wp -> wp - SetClassLong()
276 * 2) window -' / - not subclassed
277 * window -> wp -> wp ' - SetWindowLong()
279 * 3) timer -> wp - SetTimer()
281 * Initially, winproc of the window points to the current winproc
282 * thunk of its class. Subclassing prepends a new thunk to the
283 * window winproc chain at the head of the list. Thus, window thunk
284 * list includes class thunks and the latter are preserved when the
285 * window is destroyed.
288 BOOL
WINPROC_SetProc( HWINDOWPROC
*pFirst
, WNDPROC16 func
,
289 WINDOWPROCTYPE type
, WINDOWPROCUSER user
)
291 BOOL bRecycle
= FALSE
;
292 WINDOWPROC
*proc
, **ppPrev
;
294 /* Check if function is already in the list */
296 ppPrev
= (WINDOWPROC
**)pFirst
;
297 proc
= WINPROC_GetPtr( func
);
304 if ((*ppPrev
)->user
!= user
)
306 /* terminal thunk is being restored */
308 WINPROC_FreeProc( *pFirst
, (*ppPrev
)->user
);
309 *(WINDOWPROC
**)pFirst
= *ppPrev
;
318 if (((*ppPrev
)->type
== type
) &&
319 (func
== WINPROC_THUNKPROC(*ppPrev
)))
326 /* WPF_CLASS thunk terminates window thunk list */
327 if ((*ppPrev
)->user
!= user
) break;
328 ppPrev
= &(*ppPrev
)->next
;
333 /* Extract this thunk from the list */
335 *ppPrev
= proc
->next
;
337 else /* Allocate a new one */
339 if (proc
) /* Was already a win proc */
342 func
= WINPROC_THUNKPROC(proc
);
344 proc
= WINPROC_AllocWinProc( func
, type
, user
);
345 if (!proc
) return FALSE
;
348 /* Add the win proc at the head of the list */
350 TRACE(win
, "(%08x,%08x,%d): res=%08x\n",
351 (UINT
)*pFirst
, (UINT
)func
, type
, (UINT
)proc
);
352 proc
->next
= *(WINDOWPROC
**)pFirst
;
353 *(WINDOWPROC
**)pFirst
= proc
;
358 /**********************************************************************
361 * Free a list of win procs.
363 void WINPROC_FreeProc( HWINDOWPROC proc
, WINDOWPROCUSER user
)
367 WINDOWPROC
*next
= ((WINDOWPROC
*)proc
)->next
;
368 if (((WINDOWPROC
*)proc
)->user
!= user
) break;
369 TRACE(win
, "freeing %08x\n", (UINT
)proc
);
370 HeapFree( WinProcHeap
, 0, proc
);
376 /**********************************************************************
377 * WINPROC_GetProcType
379 * Return the window procedure type.
381 WINDOWPROCTYPE
WINPROC_GetProcType( HWINDOWPROC proc
)
384 (((WINDOWPROC
*)proc
)->magic
!= WINPROC_MAGIC
))
385 return WIN_PROC_INVALID
;
386 return ((WINDOWPROC
*)proc
)->type
;
388 /**********************************************************************
389 * WINPROC_TestCBForStr
391 * Return TRUE if the lparam is a string
393 BOOL
WINPROC_TestCBForStr ( HWND hwnd
)
394 { WND
* wnd
= WIN_FindWndPtr(hwnd
);
395 return ( !(LOWORD(wnd
->dwStyle
) & (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) ||
396 (LOWORD(wnd
->dwStyle
) & CBS_HASSTRINGS
) );
398 /**********************************************************************
399 * WINPROC_TestLBForStr
401 * Return TRUE if the lparam is a string
403 BOOL
WINPROC_TestLBForStr ( HWND hwnd
)
404 { WND
* wnd
= WIN_FindWndPtr(hwnd
);
405 return ( !(LOWORD(wnd
->dwStyle
) & (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) ||
406 (LOWORD(wnd
->dwStyle
) & LBS_HASSTRINGS
) );
408 /**********************************************************************
409 * WINPROC_MapMsg32ATo32W
411 * Map a message from Ansi to Unicode.
412 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
415 * WM_CHAR, WM_CHARTOITEM, WM_DEADCHAR, WM_MENUCHAR, WM_SYSCHAR, WM_SYSDEADCHAR
418 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
419 * the first four bytes are the handle of the icon
420 * when the WM_SETTEXT message has been used to set the icon
422 INT
WINPROC_MapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM
*plparam
)
428 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
429 wParam
* sizeof(WCHAR
) + sizeof(LPARAM
) );
431 *ptr
++ = *plparam
; /* Store previous lParam */
432 *plparam
= (LPARAM
)ptr
;
435 /* lparam is string (0-terminated) */
437 case WM_WININICHANGE
:
440 case CB_FINDSTRINGEXACT
:
441 case CB_SELECTSTRING
:
445 case LB_SELECTSTRING
:
447 *plparam
= (LPARAM
)HEAP_strdupAtoW( SystemHeap
, 0, (LPCSTR
)*plparam
);
448 return (*plparam
? 1 : -1);
453 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)HeapAlloc( SystemHeap
, 0,
456 *cs
= *(CREATESTRUCTW
*)*plparam
;
457 if (HIWORD(cs
->lpszName
))
458 cs
->lpszName
= HEAP_strdupAtoW( SystemHeap
, 0,
459 (LPCSTR
)cs
->lpszName
);
460 if (HIWORD(cs
->lpszClass
))
461 cs
->lpszClass
= HEAP_strdupAtoW( SystemHeap
, 0,
462 (LPCSTR
)cs
->lpszClass
);
463 *plparam
= (LPARAM
)cs
;
468 MDICREATESTRUCTW
*cs
=
469 (MDICREATESTRUCTW
*)HeapAlloc( SystemHeap
, 0, sizeof(*cs
) );
471 *cs
= *(MDICREATESTRUCTW
*)*plparam
;
472 if (HIWORD(cs
->szClass
))
473 cs
->szClass
= HEAP_strdupAtoW( SystemHeap
, 0,
474 (LPCSTR
)cs
->szClass
);
475 if (HIWORD(cs
->szTitle
))
476 cs
->szTitle
= HEAP_strdupAtoW( SystemHeap
, 0,
477 (LPCSTR
)cs
->szTitle
);
478 *plparam
= (LPARAM
)cs
;
484 case LB_INSERTSTRING
:
485 if ( WINPROC_TestLBForStr( hwnd
))
486 *plparam
= (LPARAM
)HEAP_strdupAtoW( SystemHeap
, 0, (LPCSTR
)*plparam
);
487 return (*plparam
? 1 : -1);
489 case LB_GETTEXT
: /* fixme: fixed sized buffer */
490 { if ( WINPROC_TestLBForStr( hwnd
))
491 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
493 *ptr
++ = *plparam
; /* Store previous lParam */
494 *plparam
= (LPARAM
)ptr
;
501 case CB_INSERTSTRING
:
502 if ( WINPROC_TestCBForStr( hwnd
))
503 *plparam
= (LPARAM
)HEAP_strdupAtoW( SystemHeap
, 0, (LPCSTR
)*plparam
);
504 return (*plparam
? 1 : -1);
506 case CB_GETLBTEXT
: /* fixme: fixed sized buffer */
507 { if ( WINPROC_TestCBForStr( hwnd
))
508 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
510 *ptr
++ = *plparam
; /* Store previous lParam */
511 *plparam
= (LPARAM
)ptr
;
518 { WORD len
= (WORD
)*plparam
;
519 LPARAM
*ptr
= (LPARAM
*) HEAP_xalloc( SystemHeap
, 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(WCHAR
) );
521 *ptr
++ = *plparam
; /* Store previous lParam */
522 (WORD
)*ptr
= len
; /* Store the lenght */
523 *plparam
= (LPARAM
)ptr
;
527 case WM_ASKCBFORMATNAME
:
528 case WM_DEVMODECHANGE
:
529 case WM_PAINTCLIPBOARD
:
530 case WM_SIZECLIPBOARD
:
531 case EM_SETPASSWORDCHAR
:
532 FIXME(msg
, "message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg
), msg
);
534 default: /* No translation needed */
540 /**********************************************************************
541 * WINPROC_UnmapMsg32ATo32W
543 * Unmap a message that was mapped from Ansi to Unicode.
545 void WINPROC_UnmapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
551 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
552 lstrcpynWtoA( (LPSTR
)*ptr
, (LPWSTR
)lParam
, wParam
);
553 HeapFree( SystemHeap
, 0, ptr
);
560 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
561 if (HIWORD(cs
->lpszName
))
562 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszName
);
563 if (HIWORD(cs
->lpszClass
))
564 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszClass
);
565 HeapFree( SystemHeap
, 0, cs
);
571 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
572 if (HIWORD(cs
->szTitle
))
573 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szTitle
);
574 if (HIWORD(cs
->szClass
))
575 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szClass
);
576 HeapFree( SystemHeap
, 0, cs
);
581 case WM_WININICHANGE
:
584 case CB_FINDSTRINGEXACT
:
585 case CB_SELECTSTRING
:
589 case LB_SELECTSTRING
:
591 HeapFree( SystemHeap
, 0, (void *)lParam
);
596 case LB_INSERTSTRING
:
597 if ( WINPROC_TestLBForStr( hwnd
))
598 HeapFree( SystemHeap
, 0, (void *)lParam
);
602 { if ( WINPROC_TestLBForStr( hwnd
))
603 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
604 lstrcpyWtoA( (LPSTR
)*ptr
, (LPWSTR
)(lParam
) );
605 HeapFree( SystemHeap
, 0, ptr
);
612 case CB_INSERTSTRING
:
613 if ( WINPROC_TestCBForStr( hwnd
))
614 HeapFree( SystemHeap
, 0, (void *)lParam
);
618 { if ( WINPROC_TestCBForStr( hwnd
))
619 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
620 lstrcpyWtoA( (LPSTR
)*ptr
, (LPWSTR
)(lParam
) );
621 HeapFree( SystemHeap
, 0, ptr
);
628 { LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lParam */
629 WORD len
= *(WORD
*) lParam
;
630 lstrcpynWtoA( (LPSTR
)*ptr
, (LPWSTR
)lParam
, len
);
631 HeapFree( SystemHeap
, 0, ptr
);
638 /**********************************************************************
639 * WINPROC_MapMsg32WTo32A
641 * Map a message from Unicode to Ansi.
642 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
644 INT
WINPROC_MapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM
*plparam
)
649 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0,
650 wParam
+ sizeof(LPARAM
) );
652 *ptr
++ = *plparam
; /* Store previous lParam */
653 *plparam
= (LPARAM
)ptr
;
658 case WM_WININICHANGE
:
661 case CB_FINDSTRINGEXACT
:
662 case CB_SELECTSTRING
:
666 case LB_SELECTSTRING
:
668 *plparam
= (LPARAM
)HEAP_strdupWtoA( SystemHeap
, 0, (LPCWSTR
)*plparam
);
669 return (*plparam
? 1 : -1);
674 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0,
677 *cs
= *(CREATESTRUCTA
*)*plparam
;
678 if (HIWORD(cs
->lpszName
))
679 cs
->lpszName
= HEAP_strdupWtoA( SystemHeap
, 0,
680 (LPCWSTR
)cs
->lpszName
);
681 if (HIWORD(cs
->lpszClass
))
682 cs
->lpszClass
= HEAP_strdupWtoA( SystemHeap
, 0,
683 (LPCWSTR
)cs
->lpszClass
);
684 *plparam
= (LPARAM
)cs
;
689 MDICREATESTRUCTA
*cs
=
690 (MDICREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0, sizeof(*cs
) );
692 *cs
= *(MDICREATESTRUCTA
*)*plparam
;
693 if (HIWORD(cs
->szTitle
))
694 cs
->szTitle
= HEAP_strdupWtoA( SystemHeap
, 0,
695 (LPCWSTR
)cs
->szTitle
);
696 if (HIWORD(cs
->szClass
))
697 cs
->szClass
= HEAP_strdupWtoA( SystemHeap
, 0,
698 (LPCWSTR
)cs
->szClass
);
699 *plparam
= (LPARAM
)cs
;
705 case LB_INSERTSTRING
:
706 if ( WINPROC_TestLBForStr( hwnd
))
707 *plparam
= (LPARAM
)HEAP_strdupWtoA( SystemHeap
, 0, (LPCWSTR
)*plparam
);
708 return (*plparam
? 1 : -1);
710 case LB_GETTEXT
: /* fixme: fixed sized buffer */
711 { if ( WINPROC_TestLBForStr( hwnd
))
712 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 + sizeof(LPARAM
) );
714 *ptr
++ = *plparam
; /* Store previous lParam */
715 *plparam
= (LPARAM
)ptr
;
722 case CB_INSERTSTRING
:
723 if ( WINPROC_TestCBForStr( hwnd
))
724 *plparam
= (LPARAM
)HEAP_strdupWtoA( SystemHeap
, 0, (LPCWSTR
)*plparam
);
725 return (*plparam
? 1 : -1);
727 case CB_GETLBTEXT
: /* fixme: fixed sized buffer */
728 { if ( WINPROC_TestCBForStr( hwnd
))
729 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( SystemHeap
, 0, 256 + sizeof(LPARAM
) );
731 *ptr
++ = *plparam
; /* Store previous lParam */
732 *plparam
= (LPARAM
)ptr
;
739 { WORD len
= (WORD
)*plparam
;
740 LPARAM
*ptr
= (LPARAM
*) HEAP_xalloc( SystemHeap
, 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(CHAR
) );
742 *ptr
++ = *plparam
; /* Store previous lParam */
743 (WORD
)*ptr
= len
; /* Store the lenght */
744 *plparam
= (LPARAM
)ptr
;
748 case WM_ASKCBFORMATNAME
:
749 case WM_DEVMODECHANGE
:
750 case WM_PAINTCLIPBOARD
:
751 case WM_SIZECLIPBOARD
:
752 case EM_SETPASSWORDCHAR
:
753 FIXME(msg
, "message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg
),msg
);
755 default: /* No translation needed */
761 /**********************************************************************
762 * WINPROC_UnmapMsg32WTo32A
764 * Unmap a message that was mapped from Unicode to Ansi.
766 void WINPROC_UnmapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
772 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
773 lstrcpynAtoW( (LPWSTR
)*ptr
, (LPSTR
)lParam
, wParam
);
774 HeapFree( SystemHeap
, 0, ptr
);
779 case WM_WININICHANGE
:
782 case CB_FINDSTRINGEXACT
:
783 case CB_SELECTSTRING
:
787 case LB_SELECTSTRING
:
789 HeapFree( SystemHeap
, 0, (void *)lParam
);
795 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
796 if (HIWORD(cs
->lpszName
))
797 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszName
);
798 if (HIWORD(cs
->lpszClass
))
799 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszClass
);
800 HeapFree( SystemHeap
, 0, cs
);
806 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
807 if (HIWORD(cs
->szTitle
))
808 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szTitle
);
809 if (HIWORD(cs
->szClass
))
810 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szClass
);
811 HeapFree( SystemHeap
, 0, cs
);
817 case LB_INSERTSTRING
:
818 if ( WINPROC_TestLBForStr( hwnd
))
819 HeapFree( SystemHeap
, 0, (void *)lParam
);
823 { if ( WINPROC_TestLBForStr( hwnd
))
824 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
825 lstrcpyAtoW( (LPWSTR
)*ptr
, (LPSTR
)(lParam
) );
826 HeapFree( SystemHeap
, 0, ptr
);
833 case CB_INSERTSTRING
:
834 if ( WINPROC_TestCBForStr( hwnd
))
835 HeapFree( SystemHeap
, 0, (void *)lParam
);
839 { if ( WINPROC_TestCBForStr( hwnd
))
840 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
841 lstrcpyAtoW( (LPWSTR
)*ptr
, (LPSTR
)(lParam
) );
842 HeapFree( SystemHeap
, 0, ptr
);
849 { LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lparam */
850 WORD len
= *(WORD
*)ptr
;
851 lstrcpynAtoW( (LPWSTR
) *ptr
, (LPSTR
)lParam
, len
);
852 HeapFree( SystemHeap
, 0, ptr
);
859 /**********************************************************************
860 * WINPROC_MapMsg16To32A
862 * Map a message from 16- to 32-bit Ansi.
863 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
865 INT
WINPROC_MapMsg16To32A( UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
866 WPARAM
*pwparam32
, LPARAM
*plparam
)
868 *pmsg32
= (UINT
)msg16
;
869 *pwparam32
= (WPARAM
)wParam16
;
876 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
877 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
881 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
882 *plparam
= (LPARAM
)(HWND
)HIWORD(*plparam
);
885 if ( HIWORD(*plparam
) > CTLCOLOR_STATIC
) return -1;
886 *pmsg32
= WM_CTLCOLORMSGBOX
+ HIWORD(*plparam
);
887 *pwparam32
= (WPARAM
)(HDC
)wParam16
;
888 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
892 COMPAREITEMSTRUCT16
* cis16
= (COMPAREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
893 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)
894 HeapAlloc(SystemHeap
, 0, sizeof(*cis
));
896 cis
->CtlType
= cis16
->CtlType
;
897 cis
->CtlID
= cis16
->CtlID
;
898 cis
->hwndItem
= cis16
->hwndItem
;
899 cis
->itemID1
= cis16
->itemID1
;
900 cis
->itemData1
= cis16
->itemData1
;
901 cis
->itemID2
= cis16
->itemID2
;
902 cis
->itemData2
= cis16
->itemData2
;
903 cis
->dwLocaleId
= 0; /* FIXME */
904 *plparam
= (LPARAM
)cis
;
909 DELETEITEMSTRUCT16
* dis16
= (DELETEITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
910 DELETEITEMSTRUCT
*dis
= (DELETEITEMSTRUCT
*)
911 HeapAlloc(SystemHeap
, 0, sizeof(*dis
));
913 dis
->CtlType
= dis16
->CtlType
;
914 dis
->CtlID
= dis16
->CtlID
;
915 dis
->hwndItem
= dis16
->hwndItem
;
916 dis
->itemData
= dis16
->itemData
;
917 *plparam
= (LPARAM
)dis
;
922 MEASUREITEMSTRUCT16
* mis16
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
923 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)
924 HeapAlloc(SystemHeap
, 0,
925 sizeof(*mis
) + sizeof(LPARAM
));
927 mis
->CtlType
= mis16
->CtlType
;
928 mis
->CtlID
= mis16
->CtlID
;
929 mis
->itemID
= mis16
->itemID
;
930 mis
->itemWidth
= mis16
->itemWidth
;
931 mis
->itemHeight
= mis16
->itemHeight
;
932 mis
->itemData
= mis16
->itemData
;
933 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
934 *plparam
= (LPARAM
)mis
;
939 DRAWITEMSTRUCT16
* dis16
= (DRAWITEMSTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
940 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)HeapAlloc(SystemHeap
, 0,
943 dis
->CtlType
= dis16
->CtlType
;
944 dis
->CtlID
= dis16
->CtlID
;
945 dis
->itemID
= dis16
->itemID
;
946 dis
->itemAction
= dis16
->itemAction
;
947 dis
->itemState
= dis16
->itemState
;
948 dis
->hwndItem
= dis16
->hwndItem
;
949 dis
->hDC
= dis16
->hDC
;
950 dis
->itemData
= dis16
->itemData
;
951 CONV_RECT16TO32( &dis16
->rcItem
, &dis
->rcItem
);
952 *plparam
= (LPARAM
)dis
;
955 case WM_GETMINMAXINFO
:
957 MINMAXINFO
*mmi
= (MINMAXINFO
*)HeapAlloc( SystemHeap
, 0,
958 sizeof(*mmi
) + sizeof(LPARAM
));
960 STRUCT32_MINMAXINFO16to32( (MINMAXINFO16
*)PTR_SEG_TO_LIN(*plparam
),
962 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
963 *plparam
= (LPARAM
)mmi
;
968 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
972 MDICREATESTRUCT16
*cs16
=
973 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
974 MDICREATESTRUCTA
*cs
=
975 (MDICREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0,
976 sizeof(*cs
) + sizeof(LPARAM
) );
978 STRUCT32_MDICREATESTRUCT16to32A( cs16
, cs
);
979 cs
->szTitle
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->szTitle
);
980 cs
->szClass
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->szClass
);
981 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
982 *plparam
= (LPARAM
)cs
;
985 case WM_MDIGETACTIVE
:
986 *plparam
= (LPARAM
)HeapAlloc( SystemHeap
, 0, sizeof(BOOL
) );
987 *(BOOL
*)(*plparam
) = 0;
991 *pmsg32
=WM_MDIREFRESHMENU
;
992 *pwparam32
= (WPARAM
)(HMENU
)LOWORD(*plparam
);
993 *plparam
= (LPARAM
)(HMENU
)HIWORD(*plparam
);
997 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
998 *plparam
= (LPARAM
)(HMENU
)HIWORD(*plparam
);
1000 case WM_MDIACTIVATE
:
1003 *pwparam32
= (WPARAM
)(HWND
)HIWORD(*plparam
);
1004 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
1006 else /* message sent to MDI client */
1007 *pwparam32
= wParam16
;
1011 NCCALCSIZE_PARAMS16
*nc16
;
1012 NCCALCSIZE_PARAMS
*nc
;
1014 nc
= (NCCALCSIZE_PARAMS
*)HeapAlloc( SystemHeap
, 0,
1015 sizeof(*nc
) + sizeof(LPARAM
) );
1017 nc16
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(*plparam
);
1018 CONV_RECT16TO32( &nc16
->rgrc
[0], &nc
->rgrc
[0] );
1021 nc
->lppos
= (WINDOWPOS
*)HeapAlloc( SystemHeap
, 0,
1022 sizeof(*nc
->lppos
) );
1023 CONV_RECT16TO32( &nc16
->rgrc
[1], &nc
->rgrc
[1] );
1024 CONV_RECT16TO32( &nc16
->rgrc
[2], &nc
->rgrc
[2] );
1025 if (nc
->lppos
) STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc16
->lppos
), nc
->lppos
);
1027 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1028 *plparam
= (LPARAM
)nc
;
1034 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1035 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( SystemHeap
, 0,
1036 sizeof(*cs
) + sizeof(LPARAM
) );
1038 STRUCT32_CREATESTRUCT16to32A( cs16
, cs
);
1039 cs
->lpszName
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->lpszName
);
1040 cs
->lpszClass
= (LPCSTR
)PTR_SEG_TO_LIN(cs16
->lpszClass
);
1041 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1042 *plparam
= (LPARAM
)cs
;
1045 case WM_PARENTNOTIFY
:
1046 if ((wParam16
== WM_CREATE
) || (wParam16
== WM_DESTROY
))
1048 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
1049 *plparam
= (LPARAM
)(HWND
)LOWORD(*plparam
);
1052 case WM_WINDOWPOSCHANGING
:
1053 case WM_WINDOWPOSCHANGED
:
1055 WINDOWPOS
*wp
= (WINDOWPOS
*)HeapAlloc( SystemHeap
, 0,
1056 sizeof(*wp
) + sizeof(LPARAM
) );
1058 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(*plparam
),
1060 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1061 *plparam
= (LPARAM
)wp
;
1067 LPMSG16 msg16
= (LPMSG16
)PTR_SEG_TO_LIN(*plparam
);
1068 LPMSG msg32
= (LPMSG
)HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1070 if (!msg32
) return -1;
1071 msg32
->hwnd
= msg16
->hwnd
;
1072 msg32
->lParam
= msg16
->lParam
;
1073 msg32
->time
= msg16
->time
;
1074 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1075 /* this is right, right? */
1076 if (WINPROC_MapMsg16To32A(msg16
->message
,msg16
->wParam
,
1077 &msg32
->message
,&msg32
->wParam
,
1078 &msg32
->lParam
)<0) {
1079 HeapFree( SystemHeap
, 0, msg32
);
1082 *plparam
= (LPARAM
)msg32
;
1087 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
1089 case WM_ACTIVATEAPP
:
1091 { /* We need this when SetActiveWindow sends a Sendmessage16() to
1092 a 32bit window. Might be superflous with 32bit interprocess
1095 HTASK16 htask
= (HTASK16
) *plparam
;
1096 DWORD idThread
= (DWORD
)((TDB
*)GlobalLock16(htask
))->thdb
->server_tid
;
1097 *plparam
= (LPARAM
) idThread
;
1100 case WM_ASKCBFORMATNAME
:
1101 case WM_DEVMODECHANGE
:
1102 case WM_PAINTCLIPBOARD
:
1103 case WM_SIZECLIPBOARD
:
1104 case WM_WININICHANGE
:
1105 FIXME( msg
, "message %04x needs translation\n",msg16
);
1108 default: /* No translation needed */
1114 /**********************************************************************
1115 * WINPROC_UnmapMsg16To32A
1117 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1119 LRESULT
WINPROC_UnmapMsg16To32A( HWND16 hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1124 case WM_COMPAREITEM
:
1127 HeapFree( SystemHeap
, 0, (LPVOID
)lParam
);
1129 case WM_MEASUREITEM
:
1131 MEASUREITEMSTRUCT16
*mis16
;
1132 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lParam
;
1133 lParam
= *(LPARAM
*)(mis
+ 1);
1134 mis16
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(lParam
);
1135 mis16
->itemWidth
= (UINT16
)mis
->itemWidth
;
1136 mis16
->itemHeight
= (UINT16
)mis
->itemHeight
;
1137 HeapFree( SystemHeap
, 0, mis
);
1140 case WM_GETMINMAXINFO
:
1142 MINMAXINFO
*mmi
= (MINMAXINFO
*)lParam
;
1143 lParam
= *(LPARAM
*)(mmi
+ 1);
1144 STRUCT32_MINMAXINFO32to16( mmi
,
1145 (MINMAXINFO16
*)PTR_SEG_TO_LIN(lParam
));
1146 HeapFree( SystemHeap
, 0, mmi
);
1151 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
1152 lParam
= *(LPARAM
*)(cs
+ 1);
1153 STRUCT32_MDICREATESTRUCT32Ato16( cs
,
1154 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1155 HeapFree( SystemHeap
, 0, cs
);
1158 case WM_MDIGETACTIVE
:
1159 result
= MAKELONG( LOWORD(result
), (BOOL16
)(*(BOOL
*)lParam
) );
1160 HeapFree( SystemHeap
, 0, (BOOL
*)lParam
);
1164 NCCALCSIZE_PARAMS16
*nc16
;
1165 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lParam
;
1166 lParam
= *(LPARAM
*)(nc
+ 1);
1167 nc16
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(lParam
);
1168 CONV_RECT32TO16( &nc
->rgrc
[0], &nc16
->rgrc
[0] );
1171 CONV_RECT32TO16( &nc
->rgrc
[1], &nc16
->rgrc
[1] );
1172 CONV_RECT32TO16( &nc
->rgrc
[2], &nc16
->rgrc
[2] );
1175 STRUCT32_WINDOWPOS32to16( nc
->lppos
,
1176 (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc16
->lppos
));
1177 HeapFree( SystemHeap
, 0, nc
->lppos
);
1180 HeapFree( SystemHeap
, 0, nc
);
1186 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1187 lParam
= *(LPARAM
*)(cs
+ 1);
1188 STRUCT32_CREATESTRUCT32Ato16( cs
,
1189 (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1190 HeapFree( SystemHeap
, 0, cs
);
1193 case WM_WINDOWPOSCHANGING
:
1194 case WM_WINDOWPOSCHANGED
:
1196 WINDOWPOS
*wp
= (WINDOWPOS
*)lParam
;
1197 lParam
= *(LPARAM
*)(wp
+ 1);
1198 STRUCT32_WINDOWPOS32to16(wp
,(WINDOWPOS16
*)PTR_SEG_TO_LIN(lParam
));
1199 HeapFree( SystemHeap
, 0, wp
);
1205 LPMSG msg32
= (LPMSG
)lParam
;
1207 WINPROC_UnmapMsg16To32A( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1209 HeapFree( SystemHeap
, 0, msg32
);
1217 /**********************************************************************
1218 * WINPROC_MapMsg16To32W
1220 * Map a message from 16- to 32-bit Unicode.
1221 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1223 INT
WINPROC_MapMsg16To32W( HWND16 hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
1224 WPARAM
*pwparam32
, LPARAM
*plparam
)
1230 *plparam
= (LPARAM
)PTR_SEG_TO_LIN(*plparam
);
1231 return WINPROC_MapMsg32ATo32W( hwnd
, *pmsg32
, *pwparam32
, plparam
);
1235 CREATESTRUCT16
*cs16
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1236 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)HeapAlloc( SystemHeap
, 0,
1237 sizeof(*cs
) + sizeof(LPARAM
) );
1239 STRUCT32_CREATESTRUCT16to32A( cs16
, (CREATESTRUCTA
*)cs
);
1240 cs
->lpszName
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->lpszName
);
1241 cs
->lpszClass
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->lpszClass
);
1242 if (HIWORD(cs
->lpszName
))
1243 cs
->lpszName
= HEAP_strdupAtoW( SystemHeap
, 0,
1244 (LPCSTR
)cs
->lpszName
);
1245 if (HIWORD(cs
->lpszClass
))
1246 cs
->lpszClass
= HEAP_strdupAtoW( SystemHeap
, 0,
1247 (LPCSTR
)cs
->lpszClass
);
1248 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1249 *plparam
= (LPARAM
)cs
;
1254 MDICREATESTRUCT16
*cs16
=
1255 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(*plparam
);
1256 MDICREATESTRUCTW
*cs
=
1257 (MDICREATESTRUCTW
*)HeapAlloc( SystemHeap
, 0,
1258 sizeof(*cs
) + sizeof(LPARAM
) );
1260 STRUCT32_MDICREATESTRUCT16to32A( cs16
, (MDICREATESTRUCTA
*)cs
);
1261 cs
->szTitle
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->szTitle
);
1262 cs
->szClass
= (LPCWSTR
)PTR_SEG_TO_LIN(cs16
->szClass
);
1263 if (HIWORD(cs
->szTitle
))
1264 cs
->szTitle
= HEAP_strdupAtoW( SystemHeap
, 0,
1265 (LPCSTR
)cs
->szTitle
);
1266 if (HIWORD(cs
->szClass
))
1267 cs
->szClass
= HEAP_strdupAtoW( SystemHeap
, 0,
1268 (LPCSTR
)cs
->szClass
);
1269 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1270 *plparam
= (LPARAM
)cs
;
1276 LPMSG16 msg16
= (LPMSG16
)PTR_SEG_TO_LIN(*plparam
);
1277 LPMSG msg32
= (LPMSG
)HeapAlloc( SystemHeap
, 0, sizeof(MSG
) );
1279 if (!msg32
) return -1;
1280 msg32
->hwnd
= msg16
->hwnd
;
1281 msg32
->lParam
= msg16
->lParam
;
1282 msg32
->time
= msg16
->time
;
1283 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1284 /* this is right, right? */
1285 if (WINPROC_MapMsg16To32W(hwnd
, msg16
->message
,msg16
->wParam
,
1286 &msg32
->message
,&msg32
->wParam
,
1287 &msg32
->lParam
)<0) {
1288 HeapFree( SystemHeap
, 0, msg32
);
1291 *plparam
= (LPARAM
)msg32
;
1295 default: /* No Unicode translation needed */
1296 return WINPROC_MapMsg16To32A( msg16
, wParam16
, pmsg32
,
1297 pwparam32
, plparam
);
1302 /**********************************************************************
1303 * WINPROC_UnmapMsg16To32W
1305 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1307 LRESULT
WINPROC_UnmapMsg16To32W( HWND16 hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1314 WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
);
1319 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
1320 lParam
= *(LPARAM
*)(cs
+ 1);
1321 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs
,
1322 (CREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1323 if (HIWORD(cs
->lpszName
))
1324 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszName
);
1325 if (HIWORD(cs
->lpszClass
))
1326 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->lpszClass
);
1327 HeapFree( SystemHeap
, 0, cs
);
1332 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
1333 lParam
= *(LPARAM
*)(cs
+ 1);
1334 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs
,
1335 (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(lParam
) );
1336 if (HIWORD(cs
->szTitle
))
1337 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szTitle
);
1338 if (HIWORD(cs
->szClass
))
1339 HeapFree( SystemHeap
, 0, (LPVOID
)cs
->szClass
);
1340 HeapFree( SystemHeap
, 0, cs
);
1346 LPMSG msg32
= (LPMSG
)lParam
;
1348 WINPROC_UnmapMsg16To32W( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1350 HeapFree( SystemHeap
, 0, msg32
);
1354 return WINPROC_UnmapMsg16To32A( hwnd
, msg
, wParam
, lParam
, result
);
1360 /**********************************************************************
1361 * WINPROC_MapMsg32ATo16
1363 * Map a message from 32-bit Ansi to 16-bit.
1364 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1366 INT
WINPROC_MapMsg32ATo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
1367 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
1370 *pmsg16
= (UINT16
)msg32
;
1371 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1379 *pmsg16
= (UINT16
)msg32
+ (BM_GETCHECK16
- BM_GETCHECK
);
1388 case EM_SCROLLCARET
:
1391 case EM_GETLINECOUNT
:
1403 case EM_LINEFROMCHAR
:
1404 case EM_SETTABSTOPS
:
1405 case EM_SETPASSWORDCHAR
:
1406 case EM_EMPTYUNDOBUFFER
:
1407 case EM_GETFIRSTVISIBLELINE
:
1408 case EM_SETREADONLY
:
1409 case EM_SETWORDBREAKPROC
:
1410 case EM_GETWORDBREAKPROC
:
1411 case EM_GETPASSWORDCHAR
:
1412 *pmsg16
= (UINT16
)msg32
+ (EM_GETSEL16
- EM_GETSEL
);
1417 case LB_DELETESTRING
:
1418 case LB_GETANCHORINDEX
:
1419 case LB_GETCARETINDEX
:
1422 case LB_GETHORIZONTALEXTENT
:
1423 case LB_GETITEMDATA
:
1424 case LB_GETITEMHEIGHT
:
1426 case LB_GETSELCOUNT
:
1428 case LB_GETTOPINDEX
:
1429 case LB_RESETCONTENT
:
1430 case LB_SELITEMRANGE
:
1431 case LB_SELITEMRANGEEX
:
1432 case LB_SETANCHORINDEX
:
1433 case LB_SETCARETINDEX
:
1434 case LB_SETCOLUMNWIDTH
:
1436 case LB_SETHORIZONTALEXTENT
:
1437 case LB_SETITEMDATA
:
1438 case LB_SETITEMHEIGHT
:
1440 case LB_SETTOPINDEX
:
1441 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1443 case CB_DELETESTRING
:
1445 case CB_GETLBTEXTLEN
:
1447 case CB_RESETCONTENT
:
1451 case CB_SHOWDROPDOWN
:
1452 case CB_SETITEMDATA
:
1453 case CB_SETITEMHEIGHT
:
1454 case CB_GETITEMHEIGHT
:
1455 case CB_SETEXTENDEDUI
:
1456 case CB_GETEXTENDEDUI
:
1457 case CB_GETDROPPEDSTATE
:
1458 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1461 *pmsg16
= CB_GETEDITSEL16
;
1466 case LB_FINDSTRINGEXACT
:
1467 case LB_INSERTSTRING
:
1468 case LB_SELECTSTRING
:
1472 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1473 if (!str
) return -1;
1474 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1476 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1481 case CB_FINDSTRINGEXACT
:
1482 case CB_INSERTSTRING
:
1483 case CB_SELECTSTRING
:
1486 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1487 if (!str
) return -1;
1488 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1490 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1493 case LB_GETITEMRECT
:
1496 rect
= (RECT16
*)SEGPTR_ALLOC( sizeof(RECT16
) + sizeof(LPARAM
) );
1497 if (!rect
) return -1;
1498 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1499 *plparam
= (LPARAM
)SEGPTR_GET(rect
);
1501 *pmsg16
= LB_GETITEMRECT16
;
1503 case LB_GETSELITEMS
:
1506 *pwparam16
= (WPARAM16
)MIN( wParam32
, 0x7f80 ); /* Must be < 64K */
1507 if (!(items
= SEGPTR_ALLOC( *pwparam16
* sizeof(INT16
)
1508 + sizeof(LPARAM
)))) return -1;
1509 *((LPARAM
*)items
)++ = *plparam
; /* Store the previous lParam */
1510 *plparam
= (LPARAM
)SEGPTR_GET(items
);
1512 *pmsg16
= LB_GETSELITEMS16
;
1514 case LB_SETTABSTOPS
:
1519 *pwparam16
= (WPARAM16
)MIN( wParam32
, 0x7f80 ); /* Must be < 64K */
1520 if (!(stops
= SEGPTR_ALLOC( *pwparam16
* sizeof(INT16
)
1521 + sizeof(LPARAM
)))) return -1;
1522 for (i
= 0; i
< *pwparam16
; i
++) stops
[i
] = *((LPINT
)*plparam
+i
);
1523 *plparam
= (LPARAM
)SEGPTR_GET(stops
);
1526 *pmsg16
= LB_SETTABSTOPS16
;
1529 case CB_GETDROPPEDCONTROLRECT
:
1532 rect
= (RECT16
*)SEGPTR_ALLOC( sizeof(RECT16
) + sizeof(LPARAM
) );
1533 if (!rect
) return -1;
1534 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1535 *plparam
= (LPARAM
)SEGPTR_GET(rect
);
1537 *pmsg16
= CB_GETDROPPEDCONTROLRECT16
;
1541 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1542 *pmsg16
= LB_GETTEXT16
;
1546 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1547 *pmsg16
= CB_GETLBTEXT16
;
1552 *plparam
= MAKELONG( (INT16
)(INT
)wParam32
, (INT16
)*plparam
);
1553 *pmsg16
= EM_SETSEL16
;
1560 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
1564 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
1566 case WM_CTLCOLORMSGBOX
:
1567 case WM_CTLCOLOREDIT
:
1568 case WM_CTLCOLORLISTBOX
:
1569 case WM_CTLCOLORBTN
:
1570 case WM_CTLCOLORDLG
:
1571 case WM_CTLCOLORSCROLLBAR
:
1572 case WM_CTLCOLORSTATIC
:
1573 *pmsg16
= WM_CTLCOLOR
;
1574 *plparam
= MAKELPARAM( (HWND16
)*plparam
,
1575 (WORD
)msg32
- WM_CTLCOLORMSGBOX
);
1577 case WM_COMPAREITEM
:
1579 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)*plparam
;
1580 COMPAREITEMSTRUCT16
*cis
= SEGPTR_NEW(COMPAREITEMSTRUCT16
);
1581 if (!cis
) return -1;
1582 cis
->CtlType
= (UINT16
)cis32
->CtlType
;
1583 cis
->CtlID
= (UINT16
)cis32
->CtlID
;
1584 cis
->hwndItem
= (HWND16
)cis32
->hwndItem
;
1585 cis
->itemID1
= (UINT16
)cis32
->itemID1
;
1586 cis
->itemData1
= cis32
->itemData1
;
1587 cis
->itemID2
= (UINT16
)cis32
->itemID2
;
1588 cis
->itemData2
= cis32
->itemData2
;
1589 *plparam
= (LPARAM
)SEGPTR_GET(cis
);
1594 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)*plparam
;
1595 DELETEITEMSTRUCT16
*dis
= SEGPTR_NEW(DELETEITEMSTRUCT16
);
1596 if (!dis
) return -1;
1597 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1598 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1599 dis
->itemID
= (UINT16
)dis32
->itemID
;
1600 dis
->hwndItem
= (HWND16
)dis32
->hwndItem
;
1601 dis
->itemData
= dis32
->itemData
;
1602 *plparam
= (LPARAM
)SEGPTR_GET(dis
);
1607 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)*plparam
;
1608 DRAWITEMSTRUCT16
*dis
= SEGPTR_NEW(DRAWITEMSTRUCT16
);
1609 if (!dis
) return -1;
1610 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1611 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1612 dis
->itemID
= (UINT16
)dis32
->itemID
;
1613 dis
->itemAction
= (UINT16
)dis32
->itemAction
;
1614 dis
->itemState
= (UINT16
)dis32
->itemState
;
1615 dis
->hwndItem
= (HWND16
)dis32
->hwndItem
;
1616 dis
->hDC
= (HDC16
)dis32
->hDC
;
1617 dis
->itemData
= dis32
->itemData
;
1618 CONV_RECT32TO16( &dis32
->rcItem
, &dis
->rcItem
);
1619 *plparam
= (LPARAM
)SEGPTR_GET(dis
);
1622 case WM_MEASUREITEM
:
1624 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)*plparam
;
1625 MEASUREITEMSTRUCT16
*mis
= (MEASUREITEMSTRUCT16
*)
1626 SEGPTR_ALLOC(sizeof(*mis
)+sizeof(LPARAM
));
1627 if (!mis
) return -1;
1628 mis
->CtlType
= (UINT16
)mis32
->CtlType
;
1629 mis
->CtlID
= (UINT16
)mis32
->CtlID
;
1630 mis
->itemID
= (UINT16
)mis32
->itemID
;
1631 mis
->itemWidth
= (UINT16
)mis32
->itemWidth
;
1632 mis
->itemHeight
= (UINT16
)mis32
->itemHeight
;
1633 mis
->itemData
= mis32
->itemData
;
1634 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1635 *plparam
= (LPARAM
)SEGPTR_GET(mis
);
1638 case WM_GETMINMAXINFO
:
1640 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)SEGPTR_ALLOC( sizeof(*mmi
) +
1642 if (!mmi
) return -1;
1643 STRUCT32_MINMAXINFO32to16( (MINMAXINFO
*)*plparam
, mmi
);
1644 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1645 *plparam
= (LPARAM
)SEGPTR_GET(mmi
);
1651 *pwparam16
= (WPARAM16
)MIN( wParam32
, 0xff80 ); /* Must be < 64K */
1652 if (!(str
= SEGPTR_ALLOC(*pwparam16
+ sizeof(LPARAM
)))) return -1;
1653 *((LPARAM
*)str
)++ = *plparam
; /* Store the previous lParam */
1654 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1659 MDICREATESTRUCT16
*cs
;
1660 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)*plparam
;
1663 if (!(cs
= SEGPTR_NEW(MDICREATESTRUCT16
))) return -1;
1664 STRUCT32_MDICREATESTRUCT32Ato16( cs32
, cs
);
1665 name
= SEGPTR_STRDUP( cs32
->szTitle
);
1666 cls
= SEGPTR_STRDUP( cs32
->szClass
);
1667 cs
->szTitle
= SEGPTR_GET(name
);
1668 cs
->szClass
= SEGPTR_GET(cls
);
1669 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1672 case WM_MDIGETACTIVE
:
1675 *plparam
= MAKELPARAM( (HMENU16
)LOWORD(wParam32
),
1676 (HMENU16
)LOWORD(*plparam
) );
1677 *pwparam16
= (*plparam
== 0);
1681 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
1683 case WM_MDIACTIVATE
:
1684 if( WIDGETS_IsControl(WIN_FindWndPtr(hwnd
), BIC32_MDICLIENT
) )
1686 *pwparam16
= (HWND
)wParam32
;
1691 *pwparam16
= ((HWND
)*plparam
== hwnd
);
1692 *plparam
= MAKELPARAM( (HWND16
)LOWORD(*plparam
),
1693 (HWND16
)LOWORD(wParam32
) );
1698 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)*plparam
;
1699 NCCALCSIZE_PARAMS16
*nc
= (NCCALCSIZE_PARAMS16
*)SEGPTR_ALLOC( sizeof(*nc
) + sizeof(LPARAM
) );
1702 CONV_RECT32TO16( &nc32
->rgrc
[0], &nc
->rgrc
[0] );
1706 CONV_RECT32TO16( &nc32
->rgrc
[1], &nc
->rgrc
[1] );
1707 CONV_RECT32TO16( &nc32
->rgrc
[2], &nc
->rgrc
[2] );
1708 if (!(wp
= SEGPTR_NEW(WINDOWPOS16
)))
1713 STRUCT32_WINDOWPOS32to16( nc32
->lppos
, wp
);
1714 nc
->lppos
= SEGPTR_GET(wp
);
1716 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1717 *plparam
= (LPARAM
)SEGPTR_GET(nc
);
1724 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)*plparam
;
1727 if (!(cs
= SEGPTR_NEW(CREATESTRUCT16
))) return -1;
1728 STRUCT32_CREATESTRUCT32Ato16( cs32
, cs
);
1729 name
= SEGPTR_STRDUP( cs32
->lpszName
);
1730 cls
= SEGPTR_STRDUP( cs32
->lpszClass
);
1731 cs
->lpszName
= SEGPTR_GET(name
);
1732 cs
->lpszClass
= SEGPTR_GET(cls
);
1733 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
1736 case WM_PARENTNOTIFY
:
1737 if ((LOWORD(wParam32
)==WM_CREATE
) || (LOWORD(wParam32
)==WM_DESTROY
))
1738 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
));
1739 /* else nothing to do */
1742 *plparam
= MapLS( (NMHDR
*)*plparam
); /* NMHDR is already 32-bit */
1746 LPSTR str
= SEGPTR_STRDUP( (LPSTR
)*plparam
);
1747 if (!str
) return -1;
1748 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1751 case WM_WINDOWPOSCHANGING
:
1752 case WM_WINDOWPOSCHANGED
:
1754 WINDOWPOS16
*wp
= (WINDOWPOS16
*)SEGPTR_ALLOC( sizeof(*wp
) +
1757 STRUCT32_WINDOWPOS32to16( (WINDOWPOS
*)*plparam
, wp
);
1758 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1759 *plparam
= (LPARAM
)SEGPTR_GET(wp
);
1764 LPMSG msg32
= (LPMSG
) *plparam
;
1765 LPMSG16 msg16
= (LPMSG16
) SEGPTR_NEW( MSG16
);
1767 if (!msg16
) return -1;
1768 msg16
->hwnd
= msg32
->hwnd
;
1769 msg16
->lParam
= msg32
->lParam
;
1770 msg16
->time
= msg32
->time
;
1771 CONV_POINT32TO16(&msg32
->pt
,&msg16
->pt
);
1772 /* this is right, right? */
1773 if (WINPROC_MapMsg32ATo16(msg32
->hwnd
,msg32
->message
,msg32
->wParam
,
1774 &msg16
->message
,&msg16
->wParam
, &msg16
->lParam
)<0) {
1775 SEGPTR_FREE( msg16
);
1778 *plparam
= (LPARAM
)SEGPTR_GET(msg16
);
1783 case WM_ACTIVATEAPP
:
1785 *plparam
= (LPARAM
)THREAD_IdToTHDB((DWORD
) *plparam
)->teb
.htask16
;
1788 case WM_ASKCBFORMATNAME
:
1789 case WM_DEVMODECHANGE
:
1790 case WM_PAINTCLIPBOARD
:
1791 case WM_SIZECLIPBOARD
:
1792 case WM_WININICHANGE
:
1793 FIXME( msg
, "message %04x needs translation\n", msg32
);
1795 default: /* No translation needed */
1801 /**********************************************************************
1802 * WINPROC_UnmapMsg32ATo16
1804 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
1806 void WINPROC_UnmapMsg32ATo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1815 case LB_FINDSTRINGEXACT
:
1816 case LB_INSERTSTRING
:
1817 case LB_SELECTSTRING
:
1818 case LB_SETTABSTOPS
:
1821 case CB_FINDSTRINGEXACT
:
1822 case CB_INSERTSTRING
:
1823 case CB_SELECTSTRING
:
1825 case WM_COMPAREITEM
:
1829 SEGPTR_FREE( PTR_SEG_TO_LIN(p16
->lParam
) );
1832 case CB_GETDROPPEDCONTROLRECT
:
1833 case LB_GETITEMRECT
:
1835 RECT16
*rect
= (RECT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1836 p16
->lParam
= *(LPARAM
*)(rect
+ 1);
1837 CONV_RECT16TO32( rect
, (RECT
*)(p16
->lParam
));
1838 SEGPTR_FREE( rect
);
1841 case LB_GETSELITEMS
:
1844 LPINT16 items
= (LPINT16
)PTR_SEG_TO_LIN(lParam
);
1845 p16
->lParam
= *((LPARAM
*)items
- 1);
1846 for (i
= 0; i
< p16
->wParam
; i
++) *((LPINT
)(p16
->lParam
) + i
) = items
[i
];
1847 SEGPTR_FREE( (LPARAM
*)items
- 1 );
1853 *((LPUINT
)(wParam
)) = LOWORD(p16
->lResult
);
1855 *((LPUINT
)(lParam
)) = HIWORD(p16
->lResult
); /* FIXME: substract 1? */
1860 UnMapLS( (SEGPTR
)(p16
->lParam
) );
1863 case WM_MEASUREITEM
:
1865 MEASUREITEMSTRUCT16
*mis
= (MEASUREITEMSTRUCT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1866 MEASUREITEMSTRUCT
*mis32
= *(MEASUREITEMSTRUCT
**)(mis
+ 1);
1867 mis32
->itemWidth
= mis
->itemWidth
;
1868 mis32
->itemHeight
= mis
->itemHeight
;
1872 case WM_GETMINMAXINFO
:
1874 MINMAXINFO16
*mmi
= (MINMAXINFO16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1875 p16
->lParam
= *(LPARAM
*)(mmi
+ 1);
1876 STRUCT32_MINMAXINFO16to32( mmi
, (MINMAXINFO
*)(p16
->lParam
) );
1882 LPSTR str
= (LPSTR
)PTR_SEG_TO_LIN(p16
->lParam
);
1883 p16
->lParam
= *((LPARAM
*)str
- 1);
1884 lstrcpynA( (LPSTR
)(p16
->lParam
), str
, p16
->wParam
);
1885 SEGPTR_FREE( (LPARAM
*)str
- 1 );
1890 MDICREATESTRUCT16
*cs
= (MDICREATESTRUCT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1891 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->szTitle
) );
1892 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->szClass
) );
1896 case WM_MDIGETACTIVE
:
1897 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(p16
->lResult
);
1898 p16
->lResult
= (HWND
)LOWORD(p16
->lResult
);
1902 NCCALCSIZE_PARAMS
*nc32
;
1903 NCCALCSIZE_PARAMS16
*nc
= (NCCALCSIZE_PARAMS16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1904 p16
->lParam
= *(LPARAM
*)(nc
+ 1);
1905 nc32
= (NCCALCSIZE_PARAMS
*)(p16
->lParam
);
1906 CONV_RECT16TO32( &nc
->rgrc
[0], &nc32
->rgrc
[0] );
1909 CONV_RECT16TO32( &nc
->rgrc
[1], &nc32
->rgrc
[1] );
1910 CONV_RECT16TO32( &nc
->rgrc
[2], &nc32
->rgrc
[2] );
1911 STRUCT32_WINDOWPOS16to32( (WINDOWPOS16
*)PTR_SEG_TO_LIN(nc
->lppos
),
1913 SEGPTR_FREE( PTR_SEG_TO_LIN(nc
->lppos
) );
1921 CREATESTRUCT16
*cs
= (CREATESTRUCT16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1922 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->lpszName
) );
1923 SEGPTR_FREE( PTR_SEG_TO_LIN(cs
->lpszClass
) );
1927 case WM_WINDOWPOSCHANGING
:
1928 case WM_WINDOWPOSCHANGED
:
1930 WINDOWPOS16
*wp
= (WINDOWPOS16
*)PTR_SEG_TO_LIN(p16
->lParam
);
1931 p16
->lParam
= *(LPARAM
*)(wp
+ 1);
1932 STRUCT32_WINDOWPOS16to32( wp
, (WINDOWPOS
*)p16
->lParam
);
1937 UnMapLS(p16
->lParam
);
1942 LPMSG16 msg16
= (LPMSG16
)PTR_SEG_TO_LIN(p16
->lParam
);
1944 msgp16
.wParam
=msg16
->wParam
;
1945 msgp16
.lParam
=msg16
->lParam
;
1946 WINPROC_UnmapMsg32ATo16(((LPMSG
)lParam
)->hwnd
, ((LPMSG
)lParam
)->message
,
1947 ((LPMSG
)lParam
)->wParam
, ((LPMSG
)lParam
)->lParam
,
1956 /**********************************************************************
1957 * WINPROC_MapMsg32WTo16
1959 * Map a message from 32-bit Unicode to 16-bit.
1960 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1962 INT
WINPROC_MapMsg32WTo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
1963 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
1970 case LB_FINDSTRINGEXACT
:
1971 case LB_INSERTSTRING
:
1972 case LB_SELECTSTRING
:
1976 LPSTR str
= SEGPTR_STRDUP_WtoA( (LPWSTR
)*plparam
);
1977 if (!str
) return -1;
1978 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1979 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1981 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1986 case CB_FINDSTRINGEXACT
:
1987 case CB_INSERTSTRING
:
1988 case CB_SELECTSTRING
:
1991 LPSTR str
= SEGPTR_STRDUP_WtoA( (LPWSTR
)*plparam
);
1992 if (!str
) return -1;
1993 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1994 *plparam
= (LPARAM
)SEGPTR_GET(str
);
1996 *pmsg16
= (UINT16
)msg32
+ (CB_ADDSTRING16
- CB_ADDSTRING
);
2003 CREATESTRUCTW
*cs32
= (CREATESTRUCTW
*)*plparam
;
2006 if (!(cs
= SEGPTR_NEW(CREATESTRUCT16
))) return -1;
2007 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs32
, cs
);
2008 name
= SEGPTR_STRDUP_WtoA( cs32
->lpszName
);
2009 cls
= SEGPTR_STRDUP_WtoA( cs32
->lpszClass
);
2010 cs
->lpszName
= SEGPTR_GET(name
);
2011 cs
->lpszClass
= SEGPTR_GET(cls
);
2012 *pmsg16
= (UINT16
)msg32
;
2013 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2014 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
2019 MDICREATESTRUCT16
*cs
;
2020 MDICREATESTRUCTW
*cs32
= (MDICREATESTRUCTW
*)*plparam
;
2023 if (!(cs
= SEGPTR_NEW(MDICREATESTRUCT16
))) return -1;
2024 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs32
, cs
);
2025 name
= SEGPTR_STRDUP_WtoA( cs32
->szTitle
);
2026 cls
= SEGPTR_STRDUP_WtoA( cs32
->szClass
);
2027 cs
->szTitle
= SEGPTR_GET(name
);
2028 cs
->szClass
= SEGPTR_GET(cls
);
2029 *pmsg16
= (UINT16
)msg32
;
2030 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2031 *plparam
= (LPARAM
)SEGPTR_GET(cs
);
2036 LPSTR str
= SEGPTR_STRDUP_WtoA( (LPWSTR
)*plparam
);
2037 if (!str
) return -1;
2038 *pmsg16
= (UINT16
)msg32
;
2039 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
2040 *plparam
= (LPARAM
)SEGPTR_GET(str
);
2043 default: /* No Unicode translation needed */
2044 return WINPROC_MapMsg32ATo16( hwnd
, msg32
, wParam32
, pmsg16
,
2045 pwparam16
, plparam
);
2050 /**********************************************************************
2051 * WINPROC_UnmapMsg32WTo16
2053 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2055 void WINPROC_UnmapMsg32WTo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2062 LPSTR str
= (LPSTR
)PTR_SEG_TO_LIN(p16
->lParam
);
2063 p16
->lParam
= *((LPARAM
*)str
- 1);
2064 lstrcpyAtoW( (LPWSTR
)(p16
->lParam
), str
);
2065 SEGPTR_FREE( (LPARAM
*)str
- 1 );
2069 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, p16
);
2075 /**********************************************************************
2076 * WINPROC_CallProc32ATo32W
2078 * Call a window procedure, translating args from Ansi to Unicode.
2080 static LRESULT
WINPROC_CallProc32ATo32W( WNDPROC func
, HWND hwnd
,
2081 UINT msg
, WPARAM wParam
,
2086 if (WINPROC_MapMsg32ATo32W( hwnd
, msg
, wParam
, &lParam
) == -1) return 0;
2087 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2088 WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
);
2093 /**********************************************************************
2094 * WINPROC_CallProc32WTo32A
2096 * Call a window procedure, translating args from Unicode to Ansi.
2098 static LRESULT
WINPROC_CallProc32WTo32A( WNDPROC func
, HWND hwnd
,
2099 UINT msg
, WPARAM wParam
,
2104 if (WINPROC_MapMsg32WTo32A( hwnd
, msg
, wParam
, &lParam
) == -1) return 0;
2105 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2106 WINPROC_UnmapMsg32WTo32A( hwnd
, msg
, wParam
, lParam
);
2111 /**********************************************************************
2112 * WINPROC_CallProc16To32A
2114 * Call a 32-bit window procedure, translating the 16-bit args.
2116 LRESULT
WINPROC_CallProc16To32A( HWND16 hwnd
, UINT16 msg
,
2117 WPARAM16 wParam
, LPARAM lParam
,
2124 if (WINPROC_MapMsg16To32A( msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2126 result
= WINPROC_CallWndProc( func
, hwnd
, msg32
, wParam32
, lParam
);
2127 return WINPROC_UnmapMsg16To32A( hwnd
, msg32
, wParam32
, lParam
, result
);
2131 /**********************************************************************
2132 * WINPROC_CallProc16To32W
2134 * Call a 32-bit window procedure, translating the 16-bit args.
2136 LRESULT
WINPROC_CallProc16To32W( HWND16 hwnd
, UINT16 msg
,
2137 WPARAM16 wParam
, LPARAM lParam
,
2144 if (WINPROC_MapMsg16To32W( hwnd
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2146 result
= WINPROC_CallWndProc( func
, hwnd
, msg32
, wParam32
, lParam
);
2147 return WINPROC_UnmapMsg16To32W( hwnd
, msg32
, wParam32
, lParam
, result
);
2151 /**********************************************************************
2152 * WINPROC_CallProc32ATo16
2154 * Call a 16-bit window procedure, translating the 32-bit args.
2156 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
2157 UINT msg
, WPARAM wParam
,
2163 mp16
.lParam
= lParam
;
2164 if (WINPROC_MapMsg32ATo16( hwnd
, msg
, wParam
,
2165 &msg16
, &mp16
.wParam
, &mp16
.lParam
) == -1)
2167 mp16
.lResult
= Callbacks
->CallWndProc( func
, hwnd
, msg16
,
2168 mp16
.wParam
, mp16
.lParam
);
2169 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2170 return mp16
.lResult
;
2174 /**********************************************************************
2175 * WINPROC_CallProc32WTo16
2177 * Call a 16-bit window procedure, translating the 32-bit args.
2179 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
2180 UINT msg
, WPARAM wParam
,
2186 mp16
.lParam
= lParam
;
2187 if (WINPROC_MapMsg32WTo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
,
2188 &mp16
.lParam
) == -1)
2190 mp16
.lResult
= Callbacks
->CallWndProc( func
, hwnd
, msg16
,
2191 mp16
.wParam
, mp16
.lParam
);
2192 WINPROC_UnmapMsg32WTo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2193 return mp16
.lResult
;
2197 /**********************************************************************
2198 * CallWindowProc16 (USER.122)
2200 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2201 WPARAM16 wParam
, LPARAM lParam
)
2203 WINDOWPROC
*proc
= WINPROC_GetPtr( func
);
2206 return Callbacks
->CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2209 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_16
);
2210 return Callbacks
->CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2216 if (!proc
->thunk
.t_from32
.proc
) return 0;
2217 return Callbacks
->CallWndProc( proc
->thunk
.t_from32
.proc
,
2218 hwnd
, msg
, wParam
, lParam
);
2220 if (!proc
->thunk
.t_from16
.proc
) return 0;
2221 return WINPROC_CallProc16To32A( hwnd
, msg
, wParam
, lParam
,
2222 proc
->thunk
.t_from16
.proc
);
2224 if (!proc
->thunk
.t_from16
.proc
) return 0;
2225 return WINPROC_CallProc16To32W( hwnd
, msg
, wParam
, lParam
,
2226 proc
->thunk
.t_from16
.proc
);
2228 WARN( relay
, "Invalid proc %p\n", proc
);
2234 /**********************************************************************
2235 * CallWindowProc32A (USER32.18)
2237 * The CallWindowProc() function invokes the windows procedure _func_,
2238 * with _hwnd_ as the target window, the message specified by _msg_, and
2239 * the message parameters _wParam_ and _lParam_.
2241 * Some kinds of argument conversion may be done, I'm not sure what.
2243 * CallWindowProc() may be used for windows subclassing. Use
2244 * SetWindowLong() to set a new windows procedure for windows of the
2245 * subclass, and handle subclassed messages in the new windows
2246 * procedure. The new windows procedure may then use CallWindowProc()
2247 * with _func_ set to the parent class's windows procedure to dispatch
2248 * the message to the superclass.
2252 * The return value is message dependent.
2258 LRESULT WINAPI
CallWindowProcA(
2259 WNDPROC func
, /* window procedure */
2260 HWND hwnd
, /* target window */
2261 UINT msg
, /* message */
2262 WPARAM wParam
, /* message dependent parameter */
2263 LPARAM lParam
/* message dependent parameter */
2265 WINDOWPROC
*proc
= WINPROC_GetPtr( (WNDPROC16
)func
);
2267 if (!proc
) return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2270 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32A
);
2271 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2277 if (!proc
->thunk
.t_from32
.proc
) return 0;
2278 return WINPROC_CallProc32ATo16( proc
->thunk
.t_from32
.proc
,
2279 hwnd
, msg
, wParam
, lParam
);
2281 if (!proc
->thunk
.t_from16
.proc
) return 0;
2282 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
2283 hwnd
, msg
, wParam
, lParam
);
2285 if (!proc
->thunk
.t_from16
.proc
) return 0;
2286 return WINPROC_CallProc32ATo32W( proc
->thunk
.t_from16
.proc
,
2287 hwnd
, msg
, wParam
, lParam
);
2289 WARN( relay
, "Invalid proc %p\n", proc
);
2295 /**********************************************************************
2296 * CallWindowProc32W (USER32.19)
2298 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
2299 WPARAM wParam
, LPARAM lParam
)
2301 WINDOWPROC
*proc
= WINPROC_GetPtr( (WNDPROC16
)func
);
2303 if (!proc
) return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2306 func
= WINPROC_GetProc( (HWINDOWPROC
)proc
, WIN_PROC_32W
);
2307 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2313 if (!proc
->thunk
.t_from32
.proc
) return 0;
2314 return WINPROC_CallProc32WTo16( proc
->thunk
.t_from32
.proc
,
2315 hwnd
, msg
, wParam
, lParam
);
2317 if (!proc
->thunk
.t_from16
.proc
) return 0;
2318 return WINPROC_CallProc32WTo32A( proc
->thunk
.t_from16
.proc
,
2319 hwnd
, msg
, wParam
, lParam
);
2321 if (!proc
->thunk
.t_from16
.proc
) return 0;
2322 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
2323 hwnd
, msg
, wParam
, lParam
);
2325 WARN( relay
, "Invalid proc %p\n", proc
);