2 * Window procedure callbacks
4 * Copyright 1995 Martin von Loewis
5 * Copyright 1996 Alexandre Julliard
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 #include "wine/port.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
34 #include "stackframe.h"
40 #include "wine/debug.h"
46 WINE_DECLARE_DEBUG_CHANNEL(msg
);
47 WINE_DECLARE_DEBUG_CHANNEL(relay
);
48 WINE_DEFAULT_DEBUG_CHANNEL(win
);
52 /* Window procedure 16-to-32-bit thunk */
55 BYTE popl_eax
; /* popl %eax (return address) */
56 BYTE pushl_func
; /* pushl $proc */
58 BYTE pushl_eax
; /* pushl %eax */
59 BYTE ljmp
; /* ljmp relay*/
60 DWORD relay_offset
; /* __wine_call_wndproc_32A/W */
62 } WINPROC_THUNK_FROM16
;
64 /* Window procedure 32-to-16-bit thunk */
67 BYTE popl_eax
; /* popl %eax (return address) */
68 BYTE pushl_func
; /* pushl $proc */
70 BYTE pushl_eax
; /* pushl %eax */
71 BYTE jmp
; /* jmp relay (relative jump)*/
72 void (*relay
)(); /* WINPROC_CallProc32ATo16() */
73 } WINPROC_THUNK_FROM32
;
75 /* Simple jmp to call 32-bit procedure directly */
78 BYTE jmp
; /* jmp proc (relative jump) */
85 WINPROC_THUNK_FROM16 t_from16
;
86 WINPROC_THUNK_FROM32 t_from32
;
89 typedef struct tagWINDOWPROC
91 WINPROC_THUNK thunk
; /* Thunk */
92 WINPROC_JUMP jmp
; /* Jump */
93 struct tagWINDOWPROC
*next
; /* Next window proc */
94 UINT magic
; /* Magic number */
95 WINDOWPROCTYPE type
; /* Function type */
96 WINDOWPROCUSER user
; /* Function user */
99 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
101 #define WINPROC_THUNKPROC(pproc) \
102 (((pproc)->type == WIN_PROC_16) ? \
103 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
104 (WNDPROC16)((pproc)->thunk.t_from16.proc))
106 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
107 UINT msg
, WPARAM wParam
,
109 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
110 UINT msg
, WPARAM wParam
,
113 #define MAX_WINPROCS (0x10000 / sizeof(WINDOWPROC))
115 static WINDOWPROC winproc_array
[MAX_WINPROCS
];
116 static WINDOWPROC
*winproc_first_free
;
117 static UINT winproc_used
;
119 static CRITICAL_SECTION winproc_cs
;
120 static CRITICAL_SECTION_DEBUG critsect_debug
=
123 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
124 0, 0, { 0, (DWORD
)(__FILE__
": winproc_cs") }
126 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
128 /* allocate a window procedure from the global array */
129 static WINDOWPROC
*alloc_winproc(void)
131 WINDOWPROC
*ret
= NULL
;
133 EnterCriticalSection( &winproc_cs
);
134 if ((ret
= winproc_first_free
))
135 winproc_first_free
= ret
->next
;
136 else if (winproc_used
< MAX_WINPROCS
)
137 ret
= &winproc_array
[winproc_used
++];
138 LeaveCriticalSection( &winproc_cs
);
142 static void free_winproc( WINDOWPROC
*proc
)
144 EnterCriticalSection( &winproc_cs
);
146 proc
->next
= winproc_first_free
;
147 winproc_first_free
= proc
;
148 LeaveCriticalSection( &winproc_cs
);
151 static BOOL
is_valid_winproc( WINDOWPROC
*proc
)
153 if (proc
< winproc_array
|| proc
>= winproc_array
+ MAX_WINPROCS
) return FALSE
;
154 if (proc
!= winproc_array
+ (proc
- winproc_array
)) return FALSE
;
155 return (proc
->magic
== WINPROC_MAGIC
);
158 static WORD
get_winproc_selector(void)
160 static LONG winproc_selector
;
163 if (!(ret
= winproc_selector
))
166 WORD sel
= wine_ldt_alloc_entries(1);
167 wine_ldt_set_base( &entry
, winproc_array
);
168 wine_ldt_set_limit( &entry
, sizeof(winproc_array
) - 1 );
169 wine_ldt_set_flags( &entry
, WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
170 wine_ldt_set_entry( sel
, &entry
);
171 if (!(ret
= InterlockedCompareExchange( &winproc_selector
, sel
, 0 ))) ret
= sel
;
172 else wine_ldt_free_entries( sel
, 1 ); /* somebody beat us to it */
179 /* Some window procedures modify register they shouldn't, or are not
180 * properly declared stdcall; so we need a small assembly wrapper to
182 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
183 WPARAM wParam
, LPARAM lParam
);
184 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
194 "movl 8(%ebp),%eax\n\t"
196 "leal -12(%ebp),%esp\n\t"
203 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
204 WPARAM wParam
, LPARAM lParam
)
206 return proc( hwnd
, msg
, wParam
, lParam
);
208 #endif /* __i386__ */
210 /**********************************************************************
211 * WINPROC_CallWndProc32
213 * Call a 32-bit WndProc.
215 static LRESULT
WINPROC_CallWndProc( WNDPROC proc
, HWND hwnd
, UINT msg
,
216 WPARAM wParam
, LPARAM lParam
)
221 hwnd
= WIN_GetFullHandle( hwnd
);
223 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
224 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
225 /* To avoid any deadlocks, all the locks on the windows structures
226 must be suspended before the control is passed to the application */
227 iWndsLocks
= WIN_SuspendWndsLock();
228 retvalue
= WINPROC_wrapper( proc
, hwnd
, msg
, wParam
, lParam
);
229 WIN_RestoreWndsLock(iWndsLocks
);
232 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
233 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
, retvalue
);
237 /***********************************************************************
238 * WINPROC_CallWndProc16
240 * Call a 16-bit window procedure
242 static LRESULT WINAPI
WINPROC_CallWndProc16( WNDPROC16 proc
, HWND16 hwnd
,
243 UINT16 msg
, WPARAM16 wParam
,
250 TEB
*teb
= NtCurrentTeb();
253 /* Window procedures want ax = hInstance, ds = es = ss */
255 memset(&context
, 0, sizeof(context
));
256 context
.SegDs
= context
.SegEs
= SELECTOROF(teb
->cur_stack
);
257 context
.SegFs
= wine_get_fs();
258 context
.SegGs
= wine_get_gs();
259 if (!(context
.Eax
= GetWindowWord( HWND_32(hwnd
), GWL_HINSTANCE
))) context
.Eax
= context
.SegDs
;
260 context
.SegCs
= SELECTOROF(proc
);
261 context
.Eip
= OFFSETOF(proc
);
262 context
.Ebp
= OFFSETOF(teb
->cur_stack
)
263 + (WORD
)&((STACK16FRAME
*)0)->bp
;
267 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
268 work if structures passed in lParam are placed in the stack/data
269 segment. Programmers easily make the mistake of converting lParam
270 to a near rather than a far pointer, since Windows apparently
271 allows this. We copy the structures to the 16 bit stack; this is
272 ugly but makes these programs work. */
277 offset
= sizeof(CREATESTRUCT16
); break;
279 offset
= sizeof(DRAWITEMSTRUCT16
); break;
281 offset
= sizeof(COMPAREITEMSTRUCT16
); break;
285 void *s
= MapSL(lParam
);
286 lParam
= stack16_push( offset
);
287 memcpy( MapSL(lParam
), s
, offset
);
291 iWndsLocks
= WIN_SuspendWndsLock();
296 args
[1] = HIWORD(lParam
);
297 args
[0] = LOWORD(lParam
);
298 WOWCallback16Ex( 0, WCB16_REGS
, sizeof(args
), args
, (DWORD
*)&context
);
299 ret
= MAKELONG( LOWORD(context
.Eax
), LOWORD(context
.Edx
) );
301 if (offset
) stack16_pop( offset
);
303 WIN_RestoreWndsLock(iWndsLocks
);
309 /**********************************************************************
312 * Return a pointer to the win proc.
314 static WINDOWPROC
*WINPROC_GetPtr( WNDPROC handle
)
319 /* ptr cannot be < 64K */
320 if (!HIWORD(handle
)) return NULL
;
322 /* Check for a linear pointer */
324 ptr
= (BYTE
*)handle
;
325 /* First check if it is the jmp address */
326 proc
= (WINDOWPROC
*)(ptr
- (int)&((WINDOWPROC
*)0)->jmp
);
327 if (is_valid_winproc(proc
)) return proc
;
329 /* Now it must be the thunk address */
330 proc
= (WINDOWPROC
*)(ptr
- (int)&((WINDOWPROC
*)0)->thunk
);
331 if (is_valid_winproc(proc
)) return proc
;
333 /* Check for a segmented pointer */
335 if (!IsBadReadPtr16( (SEGPTR
)handle
, sizeof(proc
->thunk
) ))
337 ptr
= MapSL( (SEGPTR
)handle
);
338 /* It must be the thunk address */
339 proc
= (WINDOWPROC
*)(ptr
- (int)&((WINDOWPROC
*)0)->thunk
);
340 if (is_valid_winproc(proc
)) return proc
;
347 /**********************************************************************
348 * WINPROC_AllocWinProc
350 * Allocate a new window procedure.
352 static WINDOWPROC
*WINPROC_AllocWinProc( WNDPROC func
, WINDOWPROCTYPE type
,
353 WINDOWPROCUSER user
)
355 static FARPROC16 relay_32A
, relay_32W
;
357 WINDOWPROC
*proc
, *oldproc
;
359 /* Allocate a window procedure */
361 if (!(proc
= alloc_winproc())) return 0;
363 /* Check if the function is already a win proc */
365 if ((oldproc
= WINPROC_GetPtr( func
)))
374 proc
->thunk
.t_from32
.popl_eax
= 0x58; /* popl %eax */
375 proc
->thunk
.t_from32
.pushl_func
= 0x68; /* pushl $proc */
376 proc
->thunk
.t_from32
.proc
= (WNDPROC16
)func
;
377 proc
->thunk
.t_from32
.pushl_eax
= 0x50; /* pushl %eax */
378 proc
->thunk
.t_from32
.jmp
= 0xe9; /* jmp relay*/
379 proc
->thunk
.t_from32
.relay
= /* relative jump */
380 (void(*)())((DWORD
)WINPROC_CallProc32ATo16
-
381 (DWORD
)(&proc
->thunk
.t_from32
.relay
+ 1));
384 if (!relay_32A
) relay_32A
= GetProcAddress16( GetModuleHandle16("user"),
385 "__wine_call_wndproc_32A" );
386 proc
->thunk
.t_from16
.popl_eax
= 0x58; /* popl %eax */
387 proc
->thunk
.t_from16
.pushl_func
= 0x68; /* pushl $proc */
388 proc
->thunk
.t_from16
.proc
= func
;
389 proc
->thunk
.t_from16
.pushl_eax
= 0x50; /* pushl %eax */
390 proc
->thunk
.t_from16
.ljmp
= 0xea; /* ljmp relay*/
391 proc
->thunk
.t_from16
.relay_offset
= OFFSETOF(relay_32A
);
392 proc
->thunk
.t_from16
.relay_sel
= SELECTOROF(relay_32A
);
393 proc
->jmp
.jmp
= 0xe9;
394 /* Fixup relative jump */
395 proc
->jmp
.proc
= (WNDPROC
)((DWORD
)func
- (DWORD
)(&proc
->jmp
.proc
+ 1));
398 if (!relay_32W
) relay_32W
= GetProcAddress16( GetModuleHandle16("user"),
399 "__wine_call_wndproc_32W" );
400 proc
->thunk
.t_from16
.popl_eax
= 0x58; /* popl %eax */
401 proc
->thunk
.t_from16
.pushl_func
= 0x68; /* pushl $proc */
402 proc
->thunk
.t_from16
.proc
= func
;
403 proc
->thunk
.t_from16
.pushl_eax
= 0x50; /* pushl %eax */
404 proc
->thunk
.t_from16
.ljmp
= 0xea; /* ljmp relay*/
405 proc
->thunk
.t_from16
.relay_offset
= OFFSETOF(relay_32W
);
406 proc
->thunk
.t_from16
.relay_sel
= SELECTOROF(relay_32W
);
407 proc
->jmp
.jmp
= 0xe9;
408 /* Fixup relative jump */
409 proc
->jmp
.proc
= (WNDPROC
)((char *)func
- (char *)(&proc
->jmp
.proc
+ 1));
412 /* Should not happen */
415 proc
->magic
= WINPROC_MAGIC
;
420 TRACE("(%p,%d): returning %p\n", func
, type
, proc
);
425 /**********************************************************************
428 * Get a window procedure pointer that can be passed to the Windows program.
430 WNDPROC16
WINPROC_GetProc( WNDPROC proc
, WINDOWPROCTYPE type
)
432 WINDOWPROC
*ptr
= (WINDOWPROC
*)proc
;
434 if (!proc
) return NULL
;
435 if (type
== WIN_PROC_16
) /* We want a 16:16 address */
437 if (ptr
->type
== WIN_PROC_16
)
438 return ptr
->thunk
.t_from32
.proc
;
440 return (WNDPROC16
)MAKESEGPTR( get_winproc_selector(),
441 (char *)&ptr
->thunk
- (char *)winproc_array
);
443 else /* We want a 32-bit address */
445 if (ptr
->type
== WIN_PROC_16
)
446 return (WNDPROC16
)&ptr
->thunk
;
447 else if (type
!= ptr
->type
)
448 /* Have to return the jmp address if types don't match */
449 return (WNDPROC16
)&ptr
->jmp
;
451 /* Some Win16 programs want to get back the proc they set */
452 return (WNDPROC16
)ptr
->thunk
.t_from16
.proc
;
457 /**********************************************************************
460 * Set the window procedure for a window or class. There are
461 * three tree classes of winproc callbacks:
463 * 1) class -> wp - not subclassed
464 * class -> wp -> wp -> wp -> wp - SetClassLong()
466 * 2) window -' / - not subclassed
467 * window -> wp -> wp ' - SetWindowLong()
469 * 3) timer -> wp - SetTimer()
471 * Initially, winproc of the window points to the current winproc
472 * thunk of its class. Subclassing prepends a new thunk to the
473 * window winproc chain at the head of the list. Thus, window thunk
474 * list includes class thunks and the latter are preserved when the
475 * window is destroyed.
478 BOOL
WINPROC_SetProc( WNDPROC
*pFirst
, WNDPROC func
,
479 WINDOWPROCTYPE type
, WINDOWPROCUSER user
)
481 BOOL bRecycle
= FALSE
;
482 WINDOWPROC
*proc
, **ppPrev
;
484 /* Check if function is already in the list */
486 ppPrev
= (WINDOWPROC
**)pFirst
;
487 proc
= WINPROC_GetPtr( func
);
494 if ((*ppPrev
)->user
!= user
)
496 /* terminal thunk is being restored */
498 WINPROC_FreeProc( *pFirst
, (*ppPrev
)->user
);
499 *(WINDOWPROC
**)pFirst
= *ppPrev
;
508 if (((*ppPrev
)->type
== type
) &&
509 (func
== (WNDPROC
)WINPROC_THUNKPROC(*ppPrev
)))
511 if((*ppPrev
)->user
== user
)
517 WINPROC_FreeProc( (WNDPROC
)*ppPrev
, user
);
524 /* WPF_CLASS thunk terminates window thunk list */
525 if ((*ppPrev
)->user
!= user
) break;
526 ppPrev
= &(*ppPrev
)->next
;
531 /* Extract this thunk from the list */
533 *ppPrev
= proc
->next
;
535 else /* Allocate a new one */
537 if (proc
) /* Was already a win proc */
540 func
= (WNDPROC
)WINPROC_THUNKPROC(proc
);
542 proc
= WINPROC_AllocWinProc( func
, type
, user
);
543 if (!proc
) return FALSE
;
546 /* Add the win proc at the head of the list */
548 TRACE("(%p,%p,%d): res=%p\n", *pFirst
, func
, type
, proc
);
549 proc
->next
= *(WINDOWPROC
**)pFirst
;
550 *(WINDOWPROC
**)pFirst
= proc
;
555 /**********************************************************************
558 * Free a list of win procs.
560 void WINPROC_FreeProc( WNDPROC proc
, WINDOWPROCUSER user
)
562 WINDOWPROC
*ptr
= (WINDOWPROC
*)proc
;
565 WINDOWPROC
*next
= ptr
->next
;
566 if (ptr
->user
!= user
) break;
567 TRACE("freeing %p (%d)\n", ptr
, user
);
574 /**********************************************************************
575 * WINPROC_GetProcType
577 * Return the window procedure type.
579 WINDOWPROCTYPE
WINPROC_GetProcType( WNDPROC proc
)
582 (((WINDOWPROC
*)proc
)->magic
!= WINPROC_MAGIC
))
583 return WIN_PROC_INVALID
;
584 return ((WINDOWPROC
*)proc
)->type
;
586 /**********************************************************************
587 * WINPROC_TestCBForStr
589 * Return TRUE if the lparam is a string
591 inline static BOOL
WINPROC_TestCBForStr( HWND hwnd
)
593 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
594 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
596 /**********************************************************************
597 * WINPROC_TestLBForStr
599 * Return TRUE if the lparam is a string
601 inline static BOOL
WINPROC_TestLBForStr( HWND hwnd
)
603 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
604 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
607 /**********************************************************************
608 * WINPROC_MapMsg32ATo32W
610 * Map a message from Ansi to Unicode.
611 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
614 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
615 * the first four bytes are the handle of the icon
616 * when the WM_SETTEXT message has been used to set the icon
618 INT
WINPROC_MapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM
*pwparam
, LPARAM
*plparam
)
623 case WM_ASKCBFORMATNAME
:
625 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0,
626 *pwparam
* sizeof(WCHAR
) + sizeof(LPARAM
) );
628 *ptr
++ = *plparam
; /* Store previous lParam */
629 *plparam
= (LPARAM
)ptr
;
632 /* lparam is string (0-terminated) */
634 case WM_WININICHANGE
:
635 case WM_DEVMODECHANGE
:
641 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*plparam
, -1, NULL
, 0);
642 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
643 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*plparam
, -1, buf
, len
);
644 *plparam
= (LPARAM
)buf
;
645 return (*plparam
? 1 : -1);
647 case WM_GETTEXTLENGTH
:
648 case CB_GETLBTEXTLEN
:
650 return 1; /* need to map result */
654 UNICODE_STRING usBuffer
;
656 { CREATESTRUCTW cs
; /* new structure */
657 LPCWSTR lpszName
; /* allocated Name */
658 LPCWSTR lpszClass
; /* allocated Class */
661 struct s
*xs
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct s
));
663 xs
->cs
= *(CREATESTRUCTW
*)*plparam
;
664 if (HIWORD(xs
->cs
.lpszName
))
666 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)xs
->cs
.lpszName
);
667 xs
->lpszName
= xs
->cs
.lpszName
= usBuffer
.Buffer
;
669 if (HIWORD(xs
->cs
.lpszClass
))
671 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)xs
->cs
.lpszClass
);
672 xs
->lpszClass
= xs
->cs
.lpszClass
= usBuffer
.Buffer
;
674 *plparam
= (LPARAM
)xs
;
679 MDICREATESTRUCTW
*cs
=
680 (MDICREATESTRUCTW
*)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) );
682 *cs
= *(MDICREATESTRUCTW
*)*plparam
;
683 if (HIWORD(cs
->szClass
))
685 UNICODE_STRING usBuffer
;
686 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)cs
->szClass
);
687 cs
->szClass
= usBuffer
.Buffer
;
689 if (HIWORD(cs
->szTitle
))
691 UNICODE_STRING usBuffer
;
692 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)cs
->szTitle
);
693 cs
->szTitle
= usBuffer
.Buffer
;
695 *plparam
= (LPARAM
)cs
;
701 case LB_INSERTSTRING
:
703 case LB_FINDSTRINGEXACT
:
704 case LB_SELECTSTRING
:
705 if(!*plparam
) return 0;
706 if ( WINPROC_TestLBForStr( hwnd
))
708 UNICODE_STRING usBuffer
;
709 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)*plparam
);
710 *plparam
= (LPARAM
)usBuffer
.Buffer
;
712 return (*plparam
? 1 : -1);
714 case LB_GETTEXT
: /* FIXME: fixed sized buffer */
715 { if ( WINPROC_TestLBForStr( hwnd
))
716 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
718 *ptr
++ = *plparam
; /* Store previous lParam */
719 *plparam
= (LPARAM
)ptr
;
726 case CB_INSERTSTRING
:
727 case CB_FINDSTRINGEXACT
:
729 case CB_SELECTSTRING
:
730 if(!*plparam
) return 0;
731 if ( WINPROC_TestCBForStr( hwnd
))
733 UNICODE_STRING usBuffer
;
734 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)*plparam
);
735 *plparam
= (LPARAM
)usBuffer
.Buffer
;
737 return (*plparam
? 1 : -1);
739 case CB_GETLBTEXT
: /* FIXME: fixed sized buffer */
740 { if ( WINPROC_TestCBForStr( hwnd
))
741 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
743 *ptr
++ = *plparam
; /* Store previous lParam */
744 *plparam
= (LPARAM
)ptr
;
751 { WORD len
= (WORD
)*plparam
;
752 LPARAM
*ptr
= (LPARAM
*) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(WCHAR
) );
754 *ptr
++ = *plparam
; /* Store previous lParam */
755 *((WORD
*) ptr
) = len
; /* Store the length */
756 *plparam
= (LPARAM
)ptr
;
766 case EM_SETPASSWORDCHAR
:
768 BYTE ch
= LOWORD(*pwparam
);
770 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
771 *pwparam
= MAKEWPARAM( wch
, HIWORD(*pwparam
) );
779 ch
[0] = (*pwparam
>> 8);
780 ch
[1] = *pwparam
& 0xff;
781 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
782 *pwparam
= MAKEWPARAM( wch
, HIWORD(*pwparam
) );
786 case WM_PAINTCLIPBOARD
:
787 case WM_SIZECLIPBOARD
:
788 FIXME_(msg
)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg
, hwnd
), msg
);
790 default: /* No translation needed */
796 /**********************************************************************
797 * WINPROC_UnmapMsg32ATo32W
799 * Unmap a message that was mapped from Ansi to Unicode.
801 LRESULT
WINPROC_UnmapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
807 case WM_ASKCBFORMATNAME
:
809 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
810 if (wParam
> 0 && !WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1,
811 (LPSTR
)*ptr
, wParam
, NULL
, NULL
))
812 ((LPSTR
)*ptr
)[wParam
-1] = 0;
813 HeapFree( GetProcessHeap(), 0, ptr
);
816 case WM_GETTEXTLENGTH
:
817 case CB_GETLBTEXTLEN
:
819 /* there may be one DBCS char for each Unicode char */
825 { CREATESTRUCTW cs
; /* new structure */
826 LPWSTR lpszName
; /* allocated Name */
827 LPWSTR lpszClass
; /* allocated Class */
829 struct s
*xs
= (struct s
*)lParam
;
830 if (xs
->lpszName
) HeapFree( GetProcessHeap(), 0, xs
->lpszName
);
831 if (xs
->lpszClass
) HeapFree( GetProcessHeap(), 0, xs
->lpszClass
);
832 HeapFree( GetProcessHeap(), 0, xs
);
838 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
839 if (HIWORD(cs
->szTitle
))
840 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szTitle
);
841 if (HIWORD(cs
->szClass
))
842 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szClass
);
843 HeapFree( GetProcessHeap(), 0, cs
);
848 case WM_WININICHANGE
:
849 case WM_DEVMODECHANGE
:
854 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
859 case LB_INSERTSTRING
:
861 case LB_FINDSTRINGEXACT
:
862 case LB_SELECTSTRING
:
863 if ( WINPROC_TestLBForStr( hwnd
))
864 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
868 { if ( WINPROC_TestLBForStr( hwnd
))
869 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
870 WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, (LPSTR
)*ptr
, 0x7fffffff, NULL
, NULL
);
871 HeapFree( GetProcessHeap(), 0, ptr
);
878 case CB_INSERTSTRING
:
880 case CB_FINDSTRINGEXACT
:
881 case CB_SELECTSTRING
:
882 if ( WINPROC_TestCBForStr( hwnd
))
883 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
887 { if ( WINPROC_TestCBForStr( hwnd
))
888 { LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
889 WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1, (LPSTR
)*ptr
, 0x7fffffff, NULL
, NULL
);
890 HeapFree( GetProcessHeap(), 0, ptr
);
897 { LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lParam */
898 WORD len
= *(WORD
*) lParam
;
899 if (len
> 0 && !WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1,
900 (LPSTR
)*ptr
, len
, NULL
, NULL
))
901 ((LPSTR
)*ptr
)[len
-1] = 0;
902 HeapFree( GetProcessHeap(), 0, ptr
);
910 /**********************************************************************
911 * WINPROC_MapMsg32WTo32A
913 * Map a message from Unicode to Ansi.
914 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
916 INT
WINPROC_MapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM
*pwparam
, LPARAM
*plparam
)
921 case WM_ASKCBFORMATNAME
:
923 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0,
924 *pwparam
+ sizeof(LPARAM
) );
926 *ptr
++ = *plparam
; /* Store previous lParam */
927 *plparam
= (LPARAM
)ptr
;
932 case WM_WININICHANGE
:
933 case WM_DEVMODECHANGE
:
938 if(!*plparam
) return 0;
939 *plparam
= (LPARAM
)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)*plparam
);
940 return (*plparam
? 1 : -1);
945 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( GetProcessHeap(), 0,
948 *cs
= *(CREATESTRUCTA
*)*plparam
;
949 if (HIWORD(cs
->lpszName
))
950 cs
->lpszName
= HEAP_strdupWtoA( GetProcessHeap(), 0,
951 (LPCWSTR
)cs
->lpszName
);
952 if (HIWORD(cs
->lpszClass
))
953 cs
->lpszClass
= HEAP_strdupWtoA( GetProcessHeap(), 0,
954 (LPCWSTR
)cs
->lpszClass
);
955 *plparam
= (LPARAM
)cs
;
960 MDICREATESTRUCTA
*cs
=
961 (MDICREATESTRUCTA
*)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) );
963 *cs
= *(MDICREATESTRUCTA
*)*plparam
;
964 if (HIWORD(cs
->szTitle
))
965 cs
->szTitle
= HEAP_strdupWtoA( GetProcessHeap(), 0,
966 (LPCWSTR
)cs
->szTitle
);
967 if (HIWORD(cs
->szClass
))
968 cs
->szClass
= HEAP_strdupWtoA( GetProcessHeap(), 0,
969 (LPCWSTR
)cs
->szClass
);
970 *plparam
= (LPARAM
)cs
;
976 case LB_INSERTSTRING
:
978 case LB_FINDSTRINGEXACT
:
979 case LB_SELECTSTRING
:
980 if(!*plparam
) return 0;
981 if ( WINPROC_TestLBForStr( hwnd
))
982 *plparam
= (LPARAM
)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)*plparam
);
983 return (*plparam
? 1 : -1);
985 case LB_GETTEXT
: /* FIXME: fixed sized buffer */
986 { if ( WINPROC_TestLBForStr( hwnd
))
987 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM
) );
989 *ptr
++ = *plparam
; /* Store previous lParam */
990 *plparam
= (LPARAM
)ptr
;
997 case CB_INSERTSTRING
:
999 case CB_FINDSTRINGEXACT
:
1000 case CB_SELECTSTRING
:
1001 if(!*plparam
) return 0;
1002 if ( WINPROC_TestCBForStr( hwnd
))
1003 *plparam
= (LPARAM
)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)*plparam
);
1004 return (*plparam
? 1 : -1);
1006 case CB_GETLBTEXT
: /* FIXME: fixed sized buffer */
1007 { if ( WINPROC_TestCBForStr( hwnd
))
1008 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM
) );
1009 if (!ptr
) return -1;
1010 *ptr
++ = *plparam
; /* Store previous lParam */
1011 *plparam
= (LPARAM
)ptr
;
1016 /* Multiline edit */
1018 { WORD len
= (WORD
)*plparam
;
1019 LPARAM
*ptr
= (LPARAM
*) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(CHAR
) );
1020 if (!ptr
) return -1;
1021 *ptr
++ = *plparam
; /* Store previous lParam */
1022 *((WORD
*) ptr
) = len
; /* Store the length */
1023 *plparam
= (LPARAM
)ptr
;
1032 case WM_SYSDEADCHAR
:
1033 case EM_SETPASSWORDCHAR
:
1035 WCHAR wch
= LOWORD(*pwparam
);
1037 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
1038 *pwparam
= MAKEWPARAM( ch
, HIWORD(*pwparam
) );
1044 WCHAR wch
= LOWORD(*pwparam
);
1048 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
1049 *pwparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(*pwparam
) );
1053 case WM_PAINTCLIPBOARD
:
1054 case WM_SIZECLIPBOARD
:
1055 FIXME_(msg
)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg
, hwnd
),msg
);
1057 default: /* No translation needed */
1063 /**********************************************************************
1064 * WINPROC_UnmapMsg32WTo32A
1066 * Unmap a message that was mapped from Unicode to Ansi.
1068 void WINPROC_UnmapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1073 case WM_ASKCBFORMATNAME
:
1075 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
1078 if (!MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, (LPWSTR
)*ptr
, wParam
))
1079 ((LPWSTR
)*ptr
)[wParam
-1] = 0;
1081 HeapFree( GetProcessHeap(), 0, ptr
);
1086 case WM_WININICHANGE
:
1087 case WM_DEVMODECHANGE
:
1092 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
1098 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1099 if (HIWORD(cs
->lpszName
))
1100 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->lpszName
);
1101 if (HIWORD(cs
->lpszClass
))
1102 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->lpszClass
);
1103 HeapFree( GetProcessHeap(), 0, cs
);
1109 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
1110 if (HIWORD(cs
->szTitle
))
1111 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szTitle
);
1112 if (HIWORD(cs
->szClass
))
1113 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szClass
);
1114 HeapFree( GetProcessHeap(), 0, cs
);
1120 case LB_INSERTSTRING
:
1122 case LB_FINDSTRINGEXACT
:
1123 case LB_SELECTSTRING
:
1124 if ( WINPROC_TestLBForStr( hwnd
))
1125 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
1129 if ( WINPROC_TestLBForStr( hwnd
))
1131 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
1132 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, (LPWSTR
)*ptr
, 0x7fffffff );
1133 HeapFree( GetProcessHeap(), 0, ptr
);
1139 case CB_INSERTSTRING
:
1141 case CB_FINDSTRINGEXACT
:
1142 case CB_SELECTSTRING
:
1143 if ( WINPROC_TestCBForStr( hwnd
))
1144 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
1148 if ( WINPROC_TestCBForStr( hwnd
))
1150 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
1151 MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, (LPWSTR
)*ptr
, 0x7fffffff );
1152 HeapFree( GetProcessHeap(), 0, ptr
);
1156 /* Multiline edit */
1158 { LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lparam */
1159 WORD len
= *(WORD
*)ptr
;
1162 if (!MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, (LPWSTR
)*ptr
, len
))
1163 ((LPWSTR
)*ptr
)[len
-1] = 0;
1165 HeapFree( GetProcessHeap(), 0, ptr
);
1171 static UINT
convert_handle_16_to_32(HANDLE16 src
, unsigned int flags
)
1174 UINT sz
= GlobalSize16(src
);
1177 if (!(dst
= GlobalAlloc(flags
, sz
)))
1179 ptr16
= GlobalLock16(src
);
1180 ptr32
= GlobalLock(dst
);
1181 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr32
, ptr16
, sz
);
1182 GlobalUnlock16(src
);
1188 /**********************************************************************
1189 * WINPROC_MapMsg16To32A
1191 * Map a message from 16- to 32-bit Ansi.
1192 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1194 INT
WINPROC_MapMsg16To32A( HWND hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
1195 WPARAM
*pwparam32
, LPARAM
*plparam
)
1197 *pmsg32
= (UINT
)msg16
;
1198 *pwparam32
= (WPARAM
)wParam16
;
1205 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
1206 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1210 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1211 *plparam
= (LPARAM
)WIN_Handle32( HIWORD(*plparam
) );
1214 if ( HIWORD(*plparam
) > CTLCOLOR_STATIC
) return -1;
1215 *pmsg32
= WM_CTLCOLORMSGBOX
+ HIWORD(*plparam
);
1216 *pwparam32
= (WPARAM
)HDC_32(wParam16
);
1217 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1219 case WM_COMPAREITEM
:
1221 COMPAREITEMSTRUCT16
* cis16
= MapSL(*plparam
);
1222 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)
1223 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis
));
1224 if (!cis
) return -1;
1225 cis
->CtlType
= cis16
->CtlType
;
1226 cis
->CtlID
= cis16
->CtlID
;
1227 cis
->hwndItem
= WIN_Handle32( cis16
->hwndItem
);
1228 cis
->itemID1
= cis16
->itemID1
;
1229 cis
->itemData1
= cis16
->itemData1
;
1230 cis
->itemID2
= cis16
->itemID2
;
1231 cis
->itemData2
= cis16
->itemData2
;
1232 cis
->dwLocaleId
= 0; /* FIXME */
1233 *plparam
= (LPARAM
)cis
;
1238 DELETEITEMSTRUCT16
* dis16
= MapSL(*plparam
);
1239 DELETEITEMSTRUCT
*dis
= (DELETEITEMSTRUCT
*)
1240 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis
));
1241 if (!dis
) return -1;
1242 dis
->CtlType
= dis16
->CtlType
;
1243 dis
->CtlID
= dis16
->CtlID
;
1244 dis
->hwndItem
= WIN_Handle32( dis16
->hwndItem
);
1245 dis
->itemData
= dis16
->itemData
;
1246 *plparam
= (LPARAM
)dis
;
1249 case WM_MEASUREITEM
:
1251 MEASUREITEMSTRUCT16
* mis16
= MapSL(*plparam
);
1252 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)
1253 HeapAlloc(GetProcessHeap(), 0,
1254 sizeof(*mis
) + sizeof(LPARAM
));
1255 if (!mis
) return -1;
1256 mis
->CtlType
= mis16
->CtlType
;
1257 mis
->CtlID
= mis16
->CtlID
;
1258 mis
->itemID
= mis16
->itemID
;
1259 mis
->itemWidth
= mis16
->itemWidth
;
1260 mis
->itemHeight
= mis16
->itemHeight
;
1261 mis
->itemData
= mis16
->itemData
;
1262 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1263 *plparam
= (LPARAM
)mis
;
1268 DRAWITEMSTRUCT16
* dis16
= MapSL(*plparam
);
1269 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)HeapAlloc(GetProcessHeap(), 0,
1271 if (!dis
) return -1;
1272 dis
->CtlType
= dis16
->CtlType
;
1273 dis
->CtlID
= dis16
->CtlID
;
1274 dis
->itemID
= dis16
->itemID
;
1275 dis
->itemAction
= dis16
->itemAction
;
1276 dis
->itemState
= dis16
->itemState
;
1277 dis
->hwndItem
= (dis
->CtlType
== ODT_MENU
) ? (HWND
)HMENU_32(dis16
->hwndItem
)
1278 : WIN_Handle32( dis16
->hwndItem
);
1279 dis
->hDC
= HDC_32(dis16
->hDC
);
1280 dis
->itemData
= dis16
->itemData
;
1281 CONV_RECT16TO32( &dis16
->rcItem
, &dis
->rcItem
);
1282 *plparam
= (LPARAM
)dis
;
1285 case WM_GETMINMAXINFO
:
1287 MINMAXINFO
*mmi
= (MINMAXINFO
*)HeapAlloc( GetProcessHeap(), 0,
1288 sizeof(*mmi
) + sizeof(LPARAM
));
1289 if (!mmi
) return -1;
1290 STRUCT32_MINMAXINFO16to32( MapSL(*plparam
), mmi
);
1291 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1292 *plparam
= (LPARAM
)mmi
;
1297 case WM_WININICHANGE
:
1298 case WM_DEVMODECHANGE
:
1299 case WM_ASKCBFORMATNAME
:
1300 *plparam
= (LPARAM
)MapSL(*plparam
);
1304 MDICREATESTRUCT16
*cs16
= MapSL(*plparam
);
1305 MDICREATESTRUCTA
*cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) + sizeof(LPARAM
) );
1307 STRUCT32_MDICREATESTRUCT16to32A( cs16
, cs
);
1308 cs
->szTitle
= MapSL(cs16
->szTitle
);
1309 cs
->szClass
= MapSL(cs16
->szClass
);
1310 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1311 *plparam
= (LPARAM
)cs
;
1314 case WM_MDIGETACTIVE
:
1315 *plparam
= (LPARAM
)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL
) );
1316 *(BOOL
*)(*plparam
) = 0;
1320 *pmsg32
=WM_MDIREFRESHMENU
;
1321 *pwparam32
= (WPARAM
)HMENU_32(LOWORD(*plparam
));
1322 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1325 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1326 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1329 if((LOWORD(*plparam
) & MF_POPUP
) && (LOWORD(*plparam
) != 0xFFFF))
1331 HMENU hmenu
=HMENU_32(HIWORD(*plparam
));
1332 UINT Pos
=MENU_FindSubMenu( &hmenu
, HMENU_32(wParam16
));
1333 if(Pos
==0xFFFF) Pos
=0; /* NO_SELECTED_ITEM */
1334 *pwparam32
= MAKEWPARAM( Pos
, LOWORD(*plparam
) );
1336 else *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1337 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1339 case WM_MDIACTIVATE
:
1342 *pwparam32
= (WPARAM
)WIN_Handle32( HIWORD(*plparam
) );
1343 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1345 else /* message sent to MDI client */
1346 *pwparam32
= wParam16
;
1350 NCCALCSIZE_PARAMS16
*nc16
;
1351 NCCALCSIZE_PARAMS
*nc
;
1353 nc
= (NCCALCSIZE_PARAMS
*)HeapAlloc( GetProcessHeap(), 0,
1354 sizeof(*nc
) + sizeof(LPARAM
) );
1356 nc16
= MapSL(*plparam
);
1357 CONV_RECT16TO32( &nc16
->rgrc
[0], &nc
->rgrc
[0] );
1360 nc
->lppos
= (WINDOWPOS
*)HeapAlloc( GetProcessHeap(), 0,
1361 sizeof(*nc
->lppos
) );
1362 CONV_RECT16TO32( &nc16
->rgrc
[1], &nc
->rgrc
[1] );
1363 CONV_RECT16TO32( &nc16
->rgrc
[2], &nc
->rgrc
[2] );
1364 if (nc
->lppos
) STRUCT32_WINDOWPOS16to32( MapSL(nc16
->lppos
), nc
->lppos
);
1366 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1367 *plparam
= (LPARAM
)nc
;
1373 CREATESTRUCT16
*cs16
= MapSL(*plparam
);
1374 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( GetProcessHeap(), 0,
1375 sizeof(*cs
) + sizeof(LPARAM
) );
1377 STRUCT32_CREATESTRUCT16to32A( cs16
, cs
);
1378 cs
->lpszName
= MapSL(cs16
->lpszName
);
1379 cs
->lpszClass
= MapSL(cs16
->lpszClass
);
1380 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1381 *plparam
= (LPARAM
)cs
;
1384 case WM_PARENTNOTIFY
:
1385 if ((wParam16
== WM_CREATE
) || (wParam16
== WM_DESTROY
))
1387 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
1388 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1391 case WM_WINDOWPOSCHANGING
:
1392 case WM_WINDOWPOSCHANGED
:
1394 WINDOWPOS
*wp
= (WINDOWPOS
*)HeapAlloc( GetProcessHeap(), 0,
1395 sizeof(*wp
) + sizeof(LPARAM
) );
1397 STRUCT32_WINDOWPOS16to32( MapSL(*plparam
), wp
);
1398 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1399 *plparam
= (LPARAM
)wp
;
1405 LPMSG16 msg16
= MapSL(*plparam
);
1406 LPMSG msg32
= (LPMSG
)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG
) );
1408 if (!msg32
) return -1;
1409 msg32
->hwnd
= WIN_Handle32( msg16
->hwnd
);
1410 msg32
->lParam
= msg16
->lParam
;
1411 msg32
->time
= msg16
->time
;
1412 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1413 /* this is right, right? */
1414 if (WINPROC_MapMsg16To32A( msg32
->hwnd
, msg16
->message
,msg16
->wParam
,
1415 &msg32
->message
,&msg32
->wParam
,
1416 &msg32
->lParam
)<0) {
1417 HeapFree( GetProcessHeap(), 0, msg32
);
1420 *plparam
= (LPARAM
)msg32
;
1425 *plparam
= (LPARAM
)MapSL(*plparam
);
1427 case WM_ACTIVATEAPP
:
1428 /* We need this when SetActiveWindow sends a Sendmessage16() to
1429 * a 32bit window. Might be superflous with 32bit interprocess
1430 * message queues. */
1431 if (*plparam
) *plparam
= HTASK_32( *plparam
);
1435 MDINEXTMENU
*next
= HeapAlloc( GetProcessHeap(), 0, sizeof(*next
) );
1436 if (!next
) return -1;
1437 next
->hmenuIn
= (HMENU
)*plparam
;
1438 next
->hmenuNext
= 0;
1440 *plparam
= (LPARAM
)next
;
1443 case WM_PAINTCLIPBOARD
:
1444 case WM_SIZECLIPBOARD
:
1445 FIXME_(msg
)("message %04x needs translation\n",msg16
);
1447 case WM_DDE_INITIATE
:
1448 case WM_DDE_TERMINATE
:
1449 case WM_DDE_UNADVISE
:
1450 case WM_DDE_REQUEST
:
1451 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1461 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1462 lo16
= LOWORD(*plparam
);
1463 hi
= HIWORD(*plparam
);
1464 if (lo16
&& !(lo32
= convert_handle_16_to_32(lo16
, GMEM_DDESHARE
)))
1466 *plparam
= PackDDElParam(msg16
, lo32
, hi
);
1468 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1475 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1477 lo
= LOWORD(*plparam
);
1478 hi
= HIWORD(*plparam
);
1480 if (GlobalGetAtomNameA(hi
, buf
, 2) > 0) flag
|= 1;
1481 if (GlobalSize16(hi
) != 0) flag
|= 2;
1487 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1492 break; /* atom, nothing to do */
1494 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
1497 hi
= convert_handle_16_to_32(hi
, GMEM_DDESHARE
);
1500 *plparam
= PackDDElParam(WM_DDE_ACK
, lo
, hi
);
1502 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1503 case WM_DDE_EXECUTE
:
1504 *plparam
= convert_handle_16_to_32(*plparam
, GMEM_DDESHARE
);
1505 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1506 default: /* No translation needed */
1512 /**********************************************************************
1513 * WINPROC_UnmapMsg16To32A
1515 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1517 LRESULT
WINPROC_UnmapMsg16To32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1522 case WM_COMPAREITEM
:
1525 HeapFree( GetProcessHeap(), 0, (LPVOID
)lParam
);
1527 case WM_MEASUREITEM
:
1529 MEASUREITEMSTRUCT16
*mis16
;
1530 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lParam
;
1531 lParam
= *(LPARAM
*)(mis
+ 1);
1532 mis16
= MapSL(lParam
);
1533 mis16
->itemWidth
= (UINT16
)mis
->itemWidth
;
1534 mis16
->itemHeight
= (UINT16
)mis
->itemHeight
;
1535 HeapFree( GetProcessHeap(), 0, mis
);
1538 case WM_GETMINMAXINFO
:
1540 MINMAXINFO
*mmi
= (MINMAXINFO
*)lParam
;
1541 lParam
= *(LPARAM
*)(mmi
+ 1);
1542 STRUCT32_MINMAXINFO32to16( mmi
, MapSL(lParam
));
1543 HeapFree( GetProcessHeap(), 0, mmi
);
1548 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
1549 lParam
= *(LPARAM
*)(cs
+ 1);
1550 STRUCT32_MDICREATESTRUCT32Ato16( cs
, MapSL(lParam
) );
1551 HeapFree( GetProcessHeap(), 0, cs
);
1554 case WM_MDIGETACTIVE
:
1555 result
= MAKELONG( LOWORD(result
), (BOOL16
)(*(BOOL
*)lParam
) );
1556 HeapFree( GetProcessHeap(), 0, (BOOL
*)lParam
);
1560 NCCALCSIZE_PARAMS16
*nc16
;
1561 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lParam
;
1562 lParam
= *(LPARAM
*)(nc
+ 1);
1563 nc16
= MapSL(lParam
);
1564 CONV_RECT32TO16( &nc
->rgrc
[0], &nc16
->rgrc
[0] );
1567 CONV_RECT32TO16( &nc
->rgrc
[1], &nc16
->rgrc
[1] );
1568 CONV_RECT32TO16( &nc
->rgrc
[2], &nc16
->rgrc
[2] );
1571 STRUCT32_WINDOWPOS32to16( nc
->lppos
, MapSL(nc16
->lppos
));
1572 HeapFree( GetProcessHeap(), 0, nc
->lppos
);
1575 HeapFree( GetProcessHeap(), 0, nc
);
1581 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1582 lParam
= *(LPARAM
*)(cs
+ 1);
1583 STRUCT32_CREATESTRUCT32Ato16( cs
, MapSL(lParam
) );
1584 HeapFree( GetProcessHeap(), 0, cs
);
1587 case WM_WINDOWPOSCHANGING
:
1588 case WM_WINDOWPOSCHANGED
:
1590 WINDOWPOS
*wp
= (WINDOWPOS
*)lParam
;
1591 lParam
= *(LPARAM
*)(wp
+ 1);
1592 STRUCT32_WINDOWPOS32to16(wp
, MapSL(lParam
));
1593 HeapFree( GetProcessHeap(), 0, wp
);
1599 LPMSG msg32
= (LPMSG
)lParam
;
1601 WINPROC_UnmapMsg16To32A( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1603 HeapFree( GetProcessHeap(), 0, msg32
);
1608 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
1609 result
= MAKELONG( HMENU_16(next
->hmenuNext
), HWND_16(next
->hwndNext
) );
1610 HeapFree( GetProcessHeap(), 0, next
);
1618 /**********************************************************************
1619 * WINPROC_MapMsg16To32W
1621 * Map a message from 16- to 32-bit Unicode.
1622 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1624 INT
WINPROC_MapMsg16To32W( HWND hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
1625 WPARAM
*pwparam32
, LPARAM
*plparam
)
1630 *pmsg32
=(UINT
)msg16
;
1631 *pwparam32
= (WPARAM
)wParam16
;
1636 case WM_WININICHANGE
:
1637 case WM_DEVMODECHANGE
:
1638 case WM_ASKCBFORMATNAME
:
1639 *plparam
= (LPARAM
)MapSL(*plparam
);
1640 return WINPROC_MapMsg32ATo32W( hwnd
, *pmsg32
, pwparam32
, plparam
);
1641 case WM_GETTEXTLENGTH
:
1642 case CB_GETLBTEXTLEN
:
1644 return 1; /* need to map result */
1648 CREATESTRUCT16
*cs16
= MapSL(*plparam
);
1649 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)HeapAlloc( GetProcessHeap(), 0,
1650 sizeof(*cs
) + sizeof(LPARAM
) );
1652 STRUCT32_CREATESTRUCT16to32A( cs16
, (CREATESTRUCTA
*)cs
);
1653 cs
->lpszName
= map_str_16_to_32W(cs16
->lpszName
);
1654 cs
->lpszClass
= map_str_16_to_32W(cs16
->lpszClass
);
1655 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1656 *plparam
= (LPARAM
)cs
;
1661 MDICREATESTRUCT16
*cs16
= MapSL(*plparam
);
1662 MDICREATESTRUCTW
*cs
=
1663 (MDICREATESTRUCTW
*)HeapAlloc( GetProcessHeap(), 0,
1664 sizeof(*cs
) + sizeof(LPARAM
) );
1666 STRUCT32_MDICREATESTRUCT16to32A( cs16
, (MDICREATESTRUCTA
*)cs
);
1667 cs
->szTitle
= map_str_16_to_32W(cs16
->szTitle
);
1668 cs
->szClass
= map_str_16_to_32W(cs16
->szClass
);
1669 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1670 *plparam
= (LPARAM
)cs
;
1676 LPMSG16 msg16
= MapSL(*plparam
);
1677 LPMSG msg32
= (LPMSG
)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG
) );
1679 if (!msg32
) return -1;
1680 msg32
->hwnd
= WIN_Handle32( msg16
->hwnd
);
1681 msg32
->lParam
= msg16
->lParam
;
1682 msg32
->time
= msg16
->time
;
1683 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1684 /* this is right, right? */
1685 if (WINPROC_MapMsg16To32W(hwnd
, msg16
->message
,msg16
->wParam
,
1686 &msg32
->message
,&msg32
->wParam
,
1687 &msg32
->lParam
)<0) {
1688 HeapFree( GetProcessHeap(), 0, msg32
);
1691 *plparam
= (LPARAM
)msg32
;
1698 MultiByteToWideChar( CP_ACP
, 0, &ch
, 1, &wch
, 1);
1699 *pwparam32
= MAKEWPARAM( wch
, HIWORD(*plparam
) );
1700 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1704 MultiByteToWideChar( CP_ACP
, 0, &ch
, 1, &wch
, 1);
1705 *pwparam32
= MAKEWPARAM( wch
, LOWORD(*plparam
) );
1706 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1711 case WM_SYSDEADCHAR
:
1713 MultiByteToWideChar( CP_ACP
, 0, &ch
, 1, &wch
, 1);
1719 ch
[0] = (wParam16
>> 8);
1720 ch
[1] = wParam16
& 0xff;
1721 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
1726 default: /* No Unicode translation needed */
1727 return WINPROC_MapMsg16To32A( hwnd
, msg16
, wParam16
, pmsg32
,
1728 pwparam32
, plparam
);
1733 /**********************************************************************
1734 * WINPROC_UnmapMsg16To32W
1736 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1738 LRESULT
WINPROC_UnmapMsg16To32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1745 case WM_GETTEXTLENGTH
:
1746 case CB_GETLBTEXTLEN
:
1748 case WM_ASKCBFORMATNAME
:
1749 return WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
, result
);
1753 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
1754 lParam
= *(LPARAM
*)(cs
+ 1);
1755 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs
, MapSL(lParam
) );
1756 unmap_str_16_to_32W( cs
->lpszName
);
1757 unmap_str_16_to_32W( cs
->lpszClass
);
1758 HeapFree( GetProcessHeap(), 0, cs
);
1763 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
1764 lParam
= *(LPARAM
*)(cs
+ 1);
1765 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs
, MapSL(lParam
) );
1766 unmap_str_16_to_32W( cs
->szTitle
);
1767 unmap_str_16_to_32W( cs
->szClass
);
1768 HeapFree( GetProcessHeap(), 0, cs
);
1774 LPMSG msg32
= (LPMSG
)lParam
;
1776 WINPROC_UnmapMsg16To32W( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1778 HeapFree( GetProcessHeap(), 0, msg32
);
1782 return WINPROC_UnmapMsg16To32A( hwnd
, msg
, wParam
, lParam
, result
);
1787 static HANDLE16
convert_handle_32_to_16(UINT src
, unsigned int flags
)
1790 UINT sz
= GlobalSize((HANDLE
)src
);
1793 if (!(dst
= GlobalAlloc16(flags
, sz
)))
1795 ptr32
= GlobalLock((HANDLE
)src
);
1796 ptr16
= GlobalLock16(dst
);
1797 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr16
, ptr32
, sz
);
1798 GlobalUnlock((HANDLE
)src
);
1799 GlobalUnlock16(dst
);
1805 /**********************************************************************
1806 * WINPROC_MapMsg32ATo16
1808 * Map a message from 32-bit Ansi to 16-bit.
1809 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1811 INT
WINPROC_MapMsg32ATo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
1812 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
1815 *pmsg16
= (UINT16
)msg32
;
1816 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1824 *pmsg16
= (UINT16
)msg32
+ (BM_GETCHECK16
- BM_GETCHECK
);
1833 case EM_SCROLLCARET
:
1836 case EM_GETLINECOUNT
:
1848 case EM_LINEFROMCHAR
:
1849 case EM_SETTABSTOPS
:
1850 case EM_SETPASSWORDCHAR
:
1851 case EM_EMPTYUNDOBUFFER
:
1852 case EM_GETFIRSTVISIBLELINE
:
1853 case EM_SETREADONLY
:
1854 case EM_SETWORDBREAKPROC
:
1855 case EM_GETWORDBREAKPROC
:
1856 case EM_GETPASSWORDCHAR
:
1857 *pmsg16
= (UINT16
)msg32
+ (EM_GETSEL16
- EM_GETSEL
);
1862 case LB_DELETESTRING
:
1863 case LB_GETANCHORINDEX
:
1864 case LB_GETCARETINDEX
:
1867 case LB_GETHORIZONTALEXTENT
:
1868 case LB_GETITEMDATA
:
1869 case LB_GETITEMHEIGHT
:
1871 case LB_GETSELCOUNT
:
1873 case LB_GETTOPINDEX
:
1874 case LB_RESETCONTENT
:
1875 case LB_SELITEMRANGE
:
1876 case LB_SELITEMRANGEEX
:
1877 case LB_SETANCHORINDEX
:
1878 case LB_SETCARETINDEX
:
1879 case LB_SETCOLUMNWIDTH
:
1881 case LB_SETHORIZONTALEXTENT
:
1882 case LB_SETITEMDATA
:
1883 case LB_SETITEMHEIGHT
:
1885 case LB_SETTOPINDEX
:
1886 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1888 case CB_DELETESTRING
:
1890 case CB_GETLBTEXTLEN
:
1892 case CB_RESETCONTENT
:
1896 case CB_SHOWDROPDOWN
:
1897 case CB_SETITEMDATA
:
1898 case CB_SETITEMHEIGHT
:
1899 case CB_GETITEMHEIGHT
:
1900 case CB_SETEXTENDEDUI
:
1901 case CB_GETEXTENDEDUI
:
1902 case CB_GETDROPPEDSTATE
:
1903 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1906 *pmsg16
= CB_GETEDITSEL16
;
1911 case LB_FINDSTRINGEXACT
:
1912 case LB_INSERTSTRING
:
1913 case LB_SELECTSTRING
:
1916 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
1917 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1922 case CB_FINDSTRINGEXACT
:
1923 case CB_INSERTSTRING
:
1924 case CB_SELECTSTRING
:
1926 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
1927 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1930 case LB_GETITEMRECT
:
1932 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
1933 if (!rect
) return -1;
1934 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1935 *plparam
= MapLS( rect
);
1937 *pmsg16
= LB_GETITEMRECT16
;
1939 case LB_GETSELITEMS
:
1942 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
1943 if (!(items
= HeapAlloc( GetProcessHeap(), 0,
1944 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
1945 *((LPARAM
*)items
)++ = *plparam
; /* Store the previous lParam */
1946 *plparam
= MapLS( items
);
1948 *pmsg16
= LB_GETSELITEMS16
;
1950 case LB_SETTABSTOPS
:
1955 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
1956 if (!(stops
= HeapAlloc( GetProcessHeap(), 0,
1957 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
1958 for (i
= 0; i
< *pwparam16
; i
++) stops
[i
] = *((LPINT
)*plparam
+i
);
1959 *plparam
= MapLS( stops
);
1962 *pmsg16
= LB_SETTABSTOPS16
;
1965 case CB_GETDROPPEDCONTROLRECT
:
1967 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
1968 if (!rect
) return -1;
1969 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1970 *plparam
= (LPARAM
)MapLS(rect
);
1972 *pmsg16
= CB_GETDROPPEDCONTROLRECT16
;
1976 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1977 *pmsg16
= LB_GETTEXT16
;
1981 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1982 *pmsg16
= CB_GETLBTEXT16
;
1987 *plparam
= MAKELONG( (INT16
)(INT
)wParam32
, (INT16
)*plparam
);
1988 *pmsg16
= EM_SETSEL16
;
1995 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
1999 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
2001 case WM_CTLCOLORMSGBOX
:
2002 case WM_CTLCOLOREDIT
:
2003 case WM_CTLCOLORLISTBOX
:
2004 case WM_CTLCOLORBTN
:
2005 case WM_CTLCOLORDLG
:
2006 case WM_CTLCOLORSCROLLBAR
:
2007 case WM_CTLCOLORSTATIC
:
2008 *pmsg16
= WM_CTLCOLOR
;
2009 *plparam
= MAKELPARAM( (HWND16
)*plparam
,
2010 (WORD
)msg32
- WM_CTLCOLORMSGBOX
);
2012 case WM_COMPAREITEM
:
2014 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)*plparam
;
2015 COMPAREITEMSTRUCT16
*cis
= HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16
));
2016 if (!cis
) return -1;
2017 cis
->CtlType
= (UINT16
)cis32
->CtlType
;
2018 cis
->CtlID
= (UINT16
)cis32
->CtlID
;
2019 cis
->hwndItem
= HWND_16( cis32
->hwndItem
);
2020 cis
->itemID1
= (UINT16
)cis32
->itemID1
;
2021 cis
->itemData1
= cis32
->itemData1
;
2022 cis
->itemID2
= (UINT16
)cis32
->itemID2
;
2023 cis
->itemData2
= cis32
->itemData2
;
2024 *plparam
= MapLS( cis
);
2029 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)*plparam
;
2030 DELETEITEMSTRUCT16
*dis
= HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16
) );
2031 if (!dis
) return -1;
2032 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
2033 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
2034 dis
->itemID
= (UINT16
)dis32
->itemID
;
2035 dis
->hwndItem
= (dis
->CtlType
== ODT_MENU
) ? (HWND16
)LOWORD(dis32
->hwndItem
)
2036 : HWND_16( dis32
->hwndItem
);
2037 dis
->itemData
= dis32
->itemData
;
2038 *plparam
= MapLS( dis
);
2043 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)*plparam
;
2044 DRAWITEMSTRUCT16
*dis
= HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16
) );
2045 if (!dis
) return -1;
2046 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
2047 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
2048 dis
->itemID
= (UINT16
)dis32
->itemID
;
2049 dis
->itemAction
= (UINT16
)dis32
->itemAction
;
2050 dis
->itemState
= (UINT16
)dis32
->itemState
;
2051 dis
->hwndItem
= HWND_16( dis32
->hwndItem
);
2052 dis
->hDC
= HDC_16(dis32
->hDC
);
2053 dis
->itemData
= dis32
->itemData
;
2054 CONV_RECT32TO16( &dis32
->rcItem
, &dis
->rcItem
);
2055 *plparam
= MapLS( dis
);
2058 case WM_MEASUREITEM
:
2060 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)*plparam
;
2061 MEASUREITEMSTRUCT16
*mis
= HeapAlloc( GetProcessHeap(), 0, sizeof(*mis
)+sizeof(LPARAM
));
2062 if (!mis
) return -1;
2063 mis
->CtlType
= (UINT16
)mis32
->CtlType
;
2064 mis
->CtlID
= (UINT16
)mis32
->CtlID
;
2065 mis
->itemID
= (UINT16
)mis32
->itemID
;
2066 mis
->itemWidth
= (UINT16
)mis32
->itemWidth
;
2067 mis
->itemHeight
= (UINT16
)mis32
->itemHeight
;
2068 mis
->itemData
= mis32
->itemData
;
2069 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
2070 *plparam
= MapLS( mis
);
2073 case WM_GETMINMAXINFO
:
2075 MINMAXINFO16
*mmi
= HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi
) + sizeof(LPARAM
) );
2076 if (!mmi
) return -1;
2077 STRUCT32_MINMAXINFO32to16( (MINMAXINFO
*)*plparam
, mmi
);
2078 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
2079 *plparam
= MapLS( mmi
);
2083 case WM_ASKCBFORMATNAME
:
2086 *pwparam16
= (WPARAM16
)min( wParam32
, 0xff80 ); /* Must be < 64K */
2087 if (!(str
= HeapAlloc( GetProcessHeap(), 0, *pwparam16
+ sizeof(LPARAM
)))) return -1;
2088 *((LPARAM
*)str
)++ = *plparam
; /* Store the previous lParam */
2089 *plparam
= MapLS( str
);
2094 MDICREATESTRUCT16
*cs
;
2095 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)*plparam
;
2097 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16
) ))) return -1;
2098 STRUCT32_MDICREATESTRUCT32Ato16( cs32
, cs
);
2099 cs
->szTitle
= MapLS( cs32
->szTitle
);
2100 cs
->szClass
= MapLS( cs32
->szClass
);
2101 *plparam
= MapLS( cs
);
2104 case WM_MDIGETACTIVE
:
2107 *plparam
= MAKELPARAM( (HMENU16
)LOWORD(wParam32
),
2108 (HMENU16
)LOWORD(*plparam
) );
2109 *pwparam16
= (*plparam
== 0);
2112 if(HIWORD(wParam32
) & MF_POPUP
)
2115 if (((UINT
)HIWORD(wParam32
) != 0xFFFF) || (*plparam
))
2117 if((hmenu
= GetSubMenu((HMENU
)*plparam
, *pwparam16
)))
2118 *pwparam16
=HMENU_16(hmenu
);
2123 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
2125 case WM_MDIACTIVATE
:
2126 if (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
2128 *pwparam16
= ((HWND
)*plparam
== hwnd
);
2129 *plparam
= MAKELPARAM( (HWND16
)LOWORD(*plparam
),
2130 (HWND16
)LOWORD(wParam32
) );
2134 *pwparam16
= HWND_16( (HWND
)wParam32
);
2140 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)*plparam
;
2141 NCCALCSIZE_PARAMS16
*nc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*nc
) + sizeof(LPARAM
));
2144 CONV_RECT32TO16( &nc32
->rgrc
[0], &nc
->rgrc
[0] );
2148 CONV_RECT32TO16( &nc32
->rgrc
[1], &nc
->rgrc
[1] );
2149 CONV_RECT32TO16( &nc32
->rgrc
[2], &nc
->rgrc
[2] );
2150 if (!(wp
= HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16
) )))
2152 HeapFree( GetProcessHeap(), 0, nc
);
2155 STRUCT32_WINDOWPOS32to16( nc32
->lppos
, wp
);
2156 nc
->lppos
= MapLS( wp
);
2158 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
2159 *plparam
= MapLS( nc
);
2166 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)*plparam
;
2168 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16
) ))) return -1;
2169 STRUCT32_CREATESTRUCT32Ato16( cs32
, cs
);
2170 cs
->lpszName
= MapLS( cs32
->lpszName
);
2171 cs
->lpszClass
= MapLS( cs32
->lpszClass
);
2172 *plparam
= MapLS( cs
);
2175 case WM_PARENTNOTIFY
:
2176 if ((LOWORD(wParam32
)==WM_CREATE
) || (LOWORD(wParam32
)==WM_DESTROY
))
2177 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
));
2178 /* else nothing to do */
2181 *plparam
= MapLS( (NMHDR
*)*plparam
); /* NMHDR is already 32-bit */
2184 case WM_WININICHANGE
:
2185 case WM_DEVMODECHANGE
:
2186 *plparam
= MapLS( (LPSTR
)*plparam
);
2188 case WM_WINDOWPOSCHANGING
:
2189 case WM_WINDOWPOSCHANGED
:
2191 WINDOWPOS16
*wp
= HeapAlloc( GetProcessHeap(), 0, sizeof(*wp
) + sizeof(LPARAM
) );
2193 STRUCT32_WINDOWPOS32to16( (WINDOWPOS
*)*plparam
, wp
);
2194 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
2195 *plparam
= MapLS( wp
);
2200 LPMSG msg32
= (LPMSG
) *plparam
;
2201 LPMSG16 msg16
= HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16
) );
2203 if (!msg16
) return -1;
2204 msg16
->hwnd
= HWND_16( msg32
->hwnd
);
2205 msg16
->lParam
= msg32
->lParam
;
2206 msg16
->time
= msg32
->time
;
2207 CONV_POINT32TO16(&msg32
->pt
,&msg16
->pt
);
2208 /* this is right, right? */
2209 if (WINPROC_MapMsg32ATo16(msg32
->hwnd
,msg32
->message
,msg32
->wParam
,
2210 &msg16
->message
,&msg16
->wParam
, &msg16
->lParam
)<0)
2212 HeapFree( GetProcessHeap(), 0, msg16
);
2215 *plparam
= MapLS( msg16
);
2220 case WM_ACTIVATEAPP
:
2221 if (*plparam
) *plparam
= HTASK_16( (HANDLE
)*plparam
);
2225 MDINEXTMENU
*next
= (MDINEXTMENU
*)*plparam
;
2226 *plparam
= (LPARAM
)next
->hmenuIn
;
2229 case WM_PAINTCLIPBOARD
:
2230 case WM_SIZECLIPBOARD
:
2231 FIXME_(msg
)("message %04x needs translation\n", msg32
);
2233 /* following messages should not be sent to 16-bit apps */
2236 case WM_CAPTURECHANGED
:
2237 case WM_STYLECHANGING
:
2238 case WM_STYLECHANGED
:
2240 case WM_DDE_INITIATE
:
2241 case WM_DDE_TERMINATE
:
2242 case WM_DDE_UNADVISE
:
2243 case WM_DDE_REQUEST
:
2244 *pwparam16
= HWND_16((HWND
)wParam32
);
2253 *pwparam16
= HWND_16((HWND
)wParam32
);
2254 UnpackDDElParam(msg32
, *plparam
, &lo32
, &hi
);
2255 if (lo32
&& !(lo16
= convert_handle_32_to_16(lo32
, GMEM_DDESHARE
)))
2257 *plparam
= MAKELPARAM(lo16
, hi
);
2259 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2266 *pwparam16
= HWND_16((HWND
)wParam32
);
2268 UnpackDDElParam(msg32
, *plparam
, &lo
, &hi
);
2270 if (GlobalGetAtomNameA((ATOM
)hi
, buf
, sizeof(buf
)) > 0) flag
|= 1;
2271 if (GlobalSize((HANDLE
)hi
) != 0) flag
|= 2;
2277 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2282 break; /* atom, nothing to do */
2284 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
2287 hi
= convert_handle_32_to_16(hi
, GMEM_DDESHARE
);
2290 *plparam
= MAKELPARAM(lo
, hi
);
2292 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2293 case WM_DDE_EXECUTE
:
2294 *plparam
= convert_handle_32_to_16(*plparam
, GMEM_DDESHARE
);
2295 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2296 default: /* No translation needed */
2302 /**********************************************************************
2303 * WINPROC_UnmapMsg32ATo16
2305 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2307 void WINPROC_UnmapMsg32ATo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2316 case LB_FINDSTRINGEXACT
:
2317 case LB_INSERTSTRING
:
2318 case LB_SELECTSTRING
:
2322 case CB_FINDSTRINGEXACT
:
2323 case CB_INSERTSTRING
:
2324 case CB_SELECTSTRING
:
2328 case WM_WININICHANGE
:
2329 case WM_DEVMODECHANGE
:
2330 UnMapLS( (SEGPTR
)p16
->lParam
);
2332 case LB_SETTABSTOPS
:
2333 case WM_COMPAREITEM
:
2337 void *ptr
= MapSL( p16
->lParam
);
2338 UnMapLS( p16
->lParam
);
2339 HeapFree( GetProcessHeap(), 0, ptr
);
2342 case CB_GETDROPPEDCONTROLRECT
:
2343 case LB_GETITEMRECT
:
2345 RECT16
*rect
= MapSL(p16
->lParam
);
2346 UnMapLS( p16
->lParam
);
2347 p16
->lParam
= *(LPARAM
*)(rect
+ 1);
2348 CONV_RECT16TO32( rect
, (RECT
*)(p16
->lParam
));
2349 HeapFree( GetProcessHeap(), 0, rect
);
2352 case LB_GETSELITEMS
:
2355 LPINT16 items
= MapSL(p16
->lParam
);
2356 UnMapLS( p16
->lParam
);
2357 p16
->lParam
= *((LPARAM
*)items
- 1);
2358 for (i
= 0; i
< p16
->wParam
; i
++) *((LPINT
)(p16
->lParam
) + i
) = items
[i
];
2359 HeapFree( GetProcessHeap(), 0, (LPARAM
*)items
- 1 );
2365 *((PUINT
)(wParam
)) = LOWORD(p16
->lResult
);
2367 *((PUINT
)(lParam
)) = HIWORD(p16
->lResult
); /* FIXME: substract 1? */
2370 case WM_MEASUREITEM
:
2372 MEASUREITEMSTRUCT16
*mis
= MapSL(p16
->lParam
);
2373 MEASUREITEMSTRUCT
*mis32
= *(MEASUREITEMSTRUCT
**)(mis
+ 1);
2374 mis32
->itemWidth
= mis
->itemWidth
;
2375 mis32
->itemHeight
= mis
->itemHeight
;
2376 UnMapLS( p16
->lParam
);
2377 HeapFree( GetProcessHeap(), 0, mis
);
2380 case WM_GETMINMAXINFO
:
2382 MINMAXINFO16
*mmi
= MapSL(p16
->lParam
);
2383 UnMapLS( p16
->lParam
);
2384 p16
->lParam
= *(LPARAM
*)(mmi
+ 1);
2385 STRUCT32_MINMAXINFO16to32( mmi
, (MINMAXINFO
*)(p16
->lParam
) );
2386 HeapFree( GetProcessHeap(), 0, mmi
);
2390 case WM_ASKCBFORMATNAME
:
2392 LPSTR str
= MapSL(p16
->lParam
);
2393 UnMapLS( p16
->lParam
);
2394 p16
->lParam
= *((LPARAM
*)str
- 1);
2395 lstrcpynA( (LPSTR
)(p16
->lParam
), str
, p16
->wParam
);
2396 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
- 1 );
2401 MDICREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2402 UnMapLS( cs
->szTitle
);
2403 UnMapLS( cs
->szClass
);
2404 UnMapLS( p16
->lParam
);
2405 HeapFree( GetProcessHeap(), 0, cs
);
2408 case WM_MDIGETACTIVE
:
2409 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(p16
->lResult
);
2410 p16
->lResult
= (LRESULT
)WIN_Handle32( LOWORD(p16
->lResult
) );
2414 NCCALCSIZE_PARAMS
*nc32
;
2415 NCCALCSIZE_PARAMS16
*nc
= MapSL(p16
->lParam
);
2416 UnMapLS( p16
->lParam
);
2417 p16
->lParam
= *(LPARAM
*)(nc
+ 1);
2418 nc32
= (NCCALCSIZE_PARAMS
*)(p16
->lParam
);
2419 CONV_RECT16TO32( &nc
->rgrc
[0], &nc32
->rgrc
[0] );
2422 WINDOWPOS16
*pos
= MapSL(nc
->lppos
);
2423 UnMapLS( nc
->lppos
);
2424 CONV_RECT16TO32( &nc
->rgrc
[1], &nc32
->rgrc
[1] );
2425 CONV_RECT16TO32( &nc
->rgrc
[2], &nc32
->rgrc
[2] );
2426 STRUCT32_WINDOWPOS16to32( pos
, nc32
->lppos
);
2427 HeapFree( GetProcessHeap(), 0, pos
);
2429 HeapFree( GetProcessHeap(), 0, nc
);
2435 CREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2436 UnMapLS( p16
->lParam
);
2437 UnMapLS( cs
->lpszName
);
2438 UnMapLS( cs
->lpszClass
);
2439 HeapFree( GetProcessHeap(), 0, cs
);
2442 case WM_WINDOWPOSCHANGING
:
2443 case WM_WINDOWPOSCHANGED
:
2445 WINDOWPOS16
*wp
= MapSL(p16
->lParam
);
2446 UnMapLS( p16
->lParam
);
2447 p16
->lParam
= *(LPARAM
*)(wp
+ 1);
2448 STRUCT32_WINDOWPOS16to32( wp
, (WINDOWPOS
*)p16
->lParam
);
2449 HeapFree( GetProcessHeap(), 0, wp
);
2453 UnMapLS(p16
->lParam
);
2458 LPMSG16 msg16
= MapSL(p16
->lParam
);
2460 UnMapLS( p16
->lParam
);
2461 msgp16
.wParam
=msg16
->wParam
;
2462 msgp16
.lParam
=msg16
->lParam
;
2463 WINPROC_UnmapMsg32ATo16(((LPMSG
)lParam
)->hwnd
, ((LPMSG
)lParam
)->message
,
2464 ((LPMSG
)lParam
)->wParam
, ((LPMSG
)lParam
)->lParam
,
2466 HeapFree( GetProcessHeap(), 0, msg16
);
2471 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
2472 next
->hmenuNext
= HMENU_32( LOWORD(p16
->lResult
) );
2473 next
->hwndNext
= WIN_Handle32( HIWORD(p16
->lResult
) );
2481 /**********************************************************************
2482 * WINPROC_MapMsg32WTo16
2484 * Map a message from 32-bit Unicode to 16-bit.
2485 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2487 INT
WINPROC_MapMsg32WTo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
2488 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
2494 *pmsg16
= LOWORD(msg32
);
2495 *pwparam16
= LOWORD(wParam32
);
2500 case LB_FINDSTRINGEXACT
:
2501 case LB_INSERTSTRING
:
2502 case LB_SELECTSTRING
:
2505 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2506 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
2511 case CB_FINDSTRINGEXACT
:
2512 case CB_INSERTSTRING
:
2513 case CB_SELECTSTRING
:
2515 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2516 *pmsg16
= (UINT16
)msg32
+ (CB_ADDSTRING16
- CB_ADDSTRING
);
2523 CREATESTRUCTW
*cs32
= (CREATESTRUCTW
*)*plparam
;
2525 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16
) ))) return -1;
2526 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs32
, cs
);
2527 cs
->lpszName
= map_str_32W_to_16( cs32
->lpszName
);
2528 cs
->lpszClass
= map_str_32W_to_16( cs32
->lpszClass
);
2529 *plparam
= MapLS(cs
);
2534 MDICREATESTRUCT16
*cs
;
2535 MDICREATESTRUCTW
*cs32
= (MDICREATESTRUCTW
*)*plparam
;
2537 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16
) ))) return -1;
2538 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs32
, cs
);
2539 cs
->szTitle
= map_str_32W_to_16( cs32
->szTitle
);
2540 cs
->szClass
= map_str_32W_to_16( cs32
->szClass
);
2541 *plparam
= MapLS(cs
);
2545 case WM_WININICHANGE
:
2546 case WM_DEVMODECHANGE
:
2547 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2551 if ( WINPROC_TestLBForStr( hwnd
))
2553 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2554 if (!str
) return -1;
2555 *pmsg16
= (msg32
== LB_GETTEXT
)? LB_GETTEXT16
: CB_GETLBTEXT16
;
2556 *plparam
= (LPARAM
)MapLS(str
);
2561 wch
= LOWORD(wParam32
);
2562 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
2564 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
2567 wch
= LOWORD(wParam32
);
2568 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
2570 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
2575 case WM_SYSDEADCHAR
:
2577 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
2587 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
);
2588 *pwparam16
= (ch
[0] << 8) | ch
[1];
2592 default: /* No Unicode translation needed (?) */
2593 return WINPROC_MapMsg32ATo16( hwnd
, msg32
, wParam32
, pmsg16
,
2594 pwparam16
, plparam
);
2599 /**********************************************************************
2600 * WINPROC_UnmapMsg32WTo16
2602 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2604 void WINPROC_UnmapMsg32WTo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2611 case LB_FINDSTRINGEXACT
:
2612 case LB_INSERTSTRING
:
2613 case LB_SELECTSTRING
:
2618 case CB_FINDSTRINGEXACT
:
2619 case CB_INSERTSTRING
:
2620 case CB_SELECTSTRING
:
2623 case WM_WININICHANGE
:
2624 case WM_DEVMODECHANGE
:
2625 unmap_str_32W_to_16( p16
->lParam
);
2630 CREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2631 UnMapLS( p16
->lParam
);
2632 unmap_str_32W_to_16( cs
->lpszName
);
2633 unmap_str_32W_to_16( cs
->lpszClass
);
2634 HeapFree( GetProcessHeap(), 0, cs
);
2639 MDICREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2640 UnMapLS( p16
->lParam
);
2641 unmap_str_32W_to_16( cs
->szTitle
);
2642 unmap_str_32W_to_16( cs
->szClass
);
2643 HeapFree( GetProcessHeap(), 0, cs
);
2647 case WM_ASKCBFORMATNAME
:
2649 LPSTR str
= MapSL(p16
->lParam
);
2650 UnMapLS( p16
->lParam
);
2651 p16
->lParam
= *((LPARAM
*)str
- 1);
2652 MultiByteToWideChar( CP_ACP
, 0, str
, -1, (LPWSTR
)p16
->lParam
, 0x7fffffff );
2653 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
- 1 );
2658 if ( WINPROC_TestLBForStr( hwnd
))
2660 LPSTR str
= MapSL(p16
->lParam
);
2661 UnMapLS( p16
->lParam
);
2662 MultiByteToWideChar( CP_ACP
, 0, str
, -1, (LPWSTR
)lParam
, 0x7fffffff );
2663 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
);
2667 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, p16
);
2673 /**********************************************************************
2674 * WINPROC_CallProc32ATo32W
2676 * Call a window procedure, translating args from Ansi to Unicode.
2678 static LRESULT
WINPROC_CallProc32ATo32W( WNDPROC func
, HWND hwnd
,
2679 UINT msg
, WPARAM wParam
,
2685 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2686 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2688 if( (unmap
= WINPROC_MapMsg32ATo32W( hwnd
, msg
, &wParam
, &lParam
)) == -1) {
2689 ERR_(msg
)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2690 SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2693 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2694 if (unmap
) result
= WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
, result
);
2699 /**********************************************************************
2700 * WINPROC_CallProc32WTo32A
2702 * Call a window procedure, translating args from Unicode to Ansi.
2704 static LRESULT
WINPROC_CallProc32WTo32A( WNDPROC func
, HWND hwnd
,
2705 UINT msg
, WPARAM wParam
,
2711 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2712 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2714 if ((unmap
= WINPROC_MapMsg32WTo32A( hwnd
, msg
, &wParam
, &lParam
)) == -1) {
2715 ERR_(msg
)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2716 SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2719 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2720 if( unmap
) WINPROC_UnmapMsg32WTo32A( hwnd
, msg
, wParam
, lParam
);
2725 /**********************************************************************
2726 * __wine_call_wndproc_32A (USER.1010)
2728 LRESULT WINAPI
__wine_call_wndproc_32A( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
2734 HWND hwnd32
= WIN_Handle32( hwnd
);
2736 if (WINPROC_MapMsg16To32A( hwnd32
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2738 result
= WINPROC_CallWndProc( func
, hwnd32
, msg32
, wParam32
, lParam
);
2739 return WINPROC_UnmapMsg16To32A( hwnd32
, msg32
, wParam32
, lParam
, result
);
2743 /**********************************************************************
2744 * __wine_call_wndproc_32W (USER.1011)
2746 LRESULT WINAPI
__wine_call_wndproc_32W( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
2752 HWND hwnd32
= WIN_Handle32( hwnd
);
2754 if (WINPROC_MapMsg16To32W( hwnd32
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2756 result
= WINPROC_CallWndProc( func
, hwnd32
, msg32
, wParam32
, lParam
);
2757 return WINPROC_UnmapMsg16To32W( hwnd32
, msg32
, wParam32
, lParam
, result
);
2761 /**********************************************************************
2762 * WINPROC_CallProc32ATo16
2764 * Call a 16-bit window procedure, translating the 32-bit args.
2766 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
2767 UINT msg
, WPARAM wParam
,
2773 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2774 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2776 mp16
.lParam
= lParam
;
2777 if (WINPROC_MapMsg32ATo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
, &mp16
.lParam
) == -1)
2779 mp16
.lResult
= WINPROC_CallWndProc16( func
, HWND_16(hwnd
), msg16
,
2780 mp16
.wParam
, mp16
.lParam
);
2781 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2782 return mp16
.lResult
;
2786 /**********************************************************************
2787 * WINPROC_CallProc32WTo16
2789 * Call a 16-bit window procedure, translating the 32-bit args.
2791 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
2792 UINT msg
, WPARAM wParam
,
2798 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2799 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2801 mp16
.lParam
= lParam
;
2802 if (WINPROC_MapMsg32WTo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
,
2803 &mp16
.lParam
) == -1)
2805 mp16
.lResult
= WINPROC_CallWndProc16( func
, HWND_16(hwnd
), msg16
,
2806 mp16
.wParam
, mp16
.lParam
);
2807 WINPROC_UnmapMsg32WTo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2808 return mp16
.lResult
;
2812 /**********************************************************************
2813 * CallWindowProc (USER.122)
2815 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2816 WPARAM16 wParam
, LPARAM lParam
)
2820 if (!func
) return 0;
2822 if (!(proc
= WINPROC_GetPtr( (WNDPROC
)func
)))
2823 return WINPROC_CallWndProc16( func
, hwnd
, msg
, wParam
, lParam
);
2826 func
= WINPROC_GetProc( (WNDPROC
)proc
, WIN_PROC_16
);
2827 return WINPROC_CallWndProc16( func
, hwnd
, msg
, wParam
, lParam
);
2833 if (!proc
->thunk
.t_from32
.proc
) return 0;
2834 return WINPROC_CallWndProc16( proc
->thunk
.t_from32
.proc
,
2835 hwnd
, msg
, wParam
, lParam
);
2837 if (!proc
->thunk
.t_from16
.proc
) return 0;
2838 return __wine_call_wndproc_32A( hwnd
, msg
, wParam
, lParam
, proc
->thunk
.t_from16
.proc
);
2840 if (!proc
->thunk
.t_from16
.proc
) return 0;
2841 return __wine_call_wndproc_32W( hwnd
, msg
, wParam
, lParam
, proc
->thunk
.t_from16
.proc
);
2843 WARN_(relay
)("Invalid proc %p\n", proc
);
2849 /**********************************************************************
2850 * CallWindowProcA (USER32.@)
2852 * The CallWindowProc() function invokes the windows procedure _func_,
2853 * with _hwnd_ as the target window, the message specified by _msg_, and
2854 * the message parameters _wParam_ and _lParam_.
2856 * Some kinds of argument conversion may be done, I'm not sure what.
2858 * CallWindowProc() may be used for windows subclassing. Use
2859 * SetWindowLong() to set a new windows procedure for windows of the
2860 * subclass, and handle subclassed messages in the new windows
2861 * procedure. The new windows procedure may then use CallWindowProc()
2862 * with _func_ set to the parent class's windows procedure to dispatch
2863 * the message to the superclass.
2867 * The return value is message dependent.
2873 LRESULT WINAPI
CallWindowProcA(
2874 WNDPROC func
, /* [in] window procedure */
2875 HWND hwnd
, /* [in] target window */
2876 UINT msg
, /* [in] message */
2877 WPARAM wParam
, /* [in] message dependent parameter */
2878 LPARAM lParam
/* [in] message dependent parameter */
2882 if (!func
) return 0;
2884 if (!(proc
= WINPROC_GetPtr( func
)))
2885 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2888 func
= WINPROC_GetProc( (WNDPROC
)proc
, WIN_PROC_32A
);
2889 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2895 if (!proc
->thunk
.t_from32
.proc
) return 0;
2896 return WINPROC_CallProc32ATo16( proc
->thunk
.t_from32
.proc
,
2897 hwnd
, msg
, wParam
, lParam
);
2899 if (!proc
->thunk
.t_from16
.proc
) return 0;
2900 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
2901 hwnd
, msg
, wParam
, lParam
);
2903 if (!proc
->thunk
.t_from16
.proc
) return 0;
2904 return WINPROC_CallProc32ATo32W( proc
->thunk
.t_from16
.proc
,
2905 hwnd
, msg
, wParam
, lParam
);
2907 WARN_(relay
)("Invalid proc %p\n", proc
);
2913 /**********************************************************************
2914 * CallWindowProcW (USER32.@)
2916 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
2917 WPARAM wParam
, LPARAM lParam
)
2921 if (!func
) return 0;
2923 if (!(proc
= WINPROC_GetPtr( (WNDPROC
)func
)))
2924 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2927 func
= WINPROC_GetProc( (WNDPROC
)proc
, WIN_PROC_32W
);
2928 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2934 if (!proc
->thunk
.t_from32
.proc
) return 0;
2935 return WINPROC_CallProc32WTo16( proc
->thunk
.t_from32
.proc
,
2936 hwnd
, msg
, wParam
, lParam
);
2938 if (!proc
->thunk
.t_from16
.proc
) return 0;
2939 return WINPROC_CallProc32WTo32A( proc
->thunk
.t_from16
.proc
,
2940 hwnd
, msg
, wParam
, lParam
);
2942 if (!proc
->thunk
.t_from16
.proc
) return 0;
2943 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
2944 hwnd
, msg
, wParam
, lParam
);
2946 WARN_(relay
)("Invalid proc %p\n", proc
);