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"
44 #include "wine/unicode.h"
45 #include "wine/debug.h"
47 WINE_DECLARE_DEBUG_CHANNEL(msg
);
48 WINE_DECLARE_DEBUG_CHANNEL(relay
);
49 WINE_DEFAULT_DEBUG_CHANNEL(win
);
53 /* Window procedure 16-to-32-bit thunk */
56 BYTE popl_eax
; /* popl %eax (return address) */
57 BYTE pushl_func
; /* pushl $proc */
59 BYTE pushl_eax
; /* pushl %eax */
60 BYTE ljmp
; /* ljmp relay*/
61 DWORD relay_offset
; /* __wine_call_wndproc_32A/W */
63 } WINPROC_THUNK_FROM16
;
65 /* Window procedure 32-to-16-bit thunk */
68 BYTE popl_eax
; /* popl %eax (return address) */
69 BYTE pushl_func
; /* pushl $proc */
71 BYTE pushl_eax
; /* pushl %eax */
72 BYTE jmp
; /* jmp relay (relative jump)*/
73 void (*relay
)(); /* WINPROC_CallProc32ATo16() */
74 } WINPROC_THUNK_FROM32
;
76 /* Simple jmp to call 32-bit procedure directly */
79 BYTE jmp
; /* jmp proc (relative jump) */
86 WINPROC_THUNK_FROM16 t_from16
;
87 WINPROC_THUNK_FROM32 t_from32
;
90 typedef struct tagWINDOWPROC
92 WINPROC_THUNK thunk
; /* Thunk */
93 WINPROC_JUMP jmp
; /* Jump */
94 struct tagWINDOWPROC
*next
; /* Next window proc */
95 UINT magic
; /* Magic number */
96 WINDOWPROCTYPE type
; /* Function type */
97 WINDOWPROCUSER user
; /* Function user */
100 #define WINPROC_MAGIC ('W' | ('P' << 8) | ('R' << 16) | ('C' << 24))
102 #define WINPROC_THUNKPROC(pproc) \
103 (((pproc)->type == WIN_PROC_16) ? \
104 (WNDPROC16)((pproc)->thunk.t_from32.proc) : \
105 (WNDPROC16)((pproc)->thunk.t_from16.proc))
107 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
108 UINT msg
, WPARAM wParam
,
110 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
111 UINT msg
, WPARAM wParam
,
114 #define MAX_WINPROCS (0x10000 / sizeof(WINDOWPROC))
116 static WINDOWPROC winproc_array
[MAX_WINPROCS
];
117 static WINDOWPROC
*winproc_first_free
;
118 static UINT winproc_used
;
120 static CRITICAL_SECTION winproc_cs
;
121 static CRITICAL_SECTION_DEBUG critsect_debug
=
124 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
125 0, 0, { 0, (DWORD
)(__FILE__
": winproc_cs") }
127 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
129 /* allocate a window procedure from the global array */
130 static WINDOWPROC
*alloc_winproc(void)
132 WINDOWPROC
*ret
= NULL
;
134 EnterCriticalSection( &winproc_cs
);
135 if ((ret
= winproc_first_free
))
136 winproc_first_free
= ret
->next
;
137 else if (winproc_used
< MAX_WINPROCS
)
138 ret
= &winproc_array
[winproc_used
++];
139 LeaveCriticalSection( &winproc_cs
);
143 static void free_winproc( WINDOWPROC
*proc
)
145 EnterCriticalSection( &winproc_cs
);
147 proc
->next
= winproc_first_free
;
148 winproc_first_free
= proc
;
149 LeaveCriticalSection( &winproc_cs
);
152 static BOOL
is_valid_winproc( WINDOWPROC
*proc
)
154 if (proc
< winproc_array
|| proc
>= winproc_array
+ MAX_WINPROCS
) return FALSE
;
155 if (proc
!= winproc_array
+ (proc
- winproc_array
)) return FALSE
;
156 return (proc
->magic
== WINPROC_MAGIC
);
159 static WORD
get_winproc_selector(void)
161 static LONG winproc_selector
;
164 if (!(ret
= winproc_selector
))
167 WORD sel
= wine_ldt_alloc_entries(1);
168 wine_ldt_set_base( &entry
, winproc_array
);
169 wine_ldt_set_limit( &entry
, sizeof(winproc_array
) - 1 );
170 wine_ldt_set_flags( &entry
, WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
171 wine_ldt_set_entry( sel
, &entry
);
172 if (!(ret
= InterlockedCompareExchange( &winproc_selector
, sel
, 0 ))) ret
= sel
;
173 else wine_ldt_free_entries( sel
, 1 ); /* somebody beat us to it */
180 /* Some window procedures modify register they shouldn't, or are not
181 * properly declared stdcall; so we need a small assembly wrapper to
183 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
184 WPARAM wParam
, LPARAM lParam
);
185 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
195 "movl 8(%ebp),%eax\n\t"
197 "leal -12(%ebp),%esp\n\t"
204 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
205 WPARAM wParam
, LPARAM lParam
)
207 return proc( hwnd
, msg
, wParam
, lParam
);
209 #endif /* __i386__ */
211 /**********************************************************************
212 * WINPROC_CallWndProc32
214 * Call a 32-bit WndProc.
216 static LRESULT
WINPROC_CallWndProc( WNDPROC proc
, HWND hwnd
, UINT msg
,
217 WPARAM wParam
, LPARAM lParam
)
222 hwnd
= WIN_GetFullHandle( hwnd
);
224 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
225 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
226 /* To avoid any deadlocks, all the locks on the windows structures
227 must be suspended before the control is passed to the application */
228 iWndsLocks
= WIN_SuspendWndsLock();
229 retvalue
= WINPROC_wrapper( proc
, hwnd
, msg
, wParam
, lParam
);
230 WIN_RestoreWndsLock(iWndsLocks
);
233 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
234 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
, retvalue
);
238 /***********************************************************************
239 * WINPROC_CallWndProc16
241 * Call a 16-bit window procedure
243 static LRESULT WINAPI
WINPROC_CallWndProc16( WNDPROC16 proc
, HWND16 hwnd
,
244 UINT16 msg
, WPARAM16 wParam
,
251 TEB
*teb
= NtCurrentTeb();
254 /* Window procedures want ax = hInstance, ds = es = ss */
256 memset(&context
, 0, sizeof(context
));
257 context
.SegDs
= context
.SegEs
= SELECTOROF(teb
->cur_stack
);
258 context
.SegFs
= wine_get_fs();
259 context
.SegGs
= wine_get_gs();
260 if (!(context
.Eax
= GetWindowWord( HWND_32(hwnd
), GWL_HINSTANCE
))) context
.Eax
= context
.SegDs
;
261 context
.SegCs
= SELECTOROF(proc
);
262 context
.Eip
= OFFSETOF(proc
);
263 context
.Ebp
= OFFSETOF(teb
->cur_stack
)
264 + (WORD
)&((STACK16FRAME
*)0)->bp
;
268 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
269 work if structures passed in lParam are placed in the stack/data
270 segment. Programmers easily make the mistake of converting lParam
271 to a near rather than a far pointer, since Windows apparently
272 allows this. We copy the structures to the 16 bit stack; this is
273 ugly but makes these programs work. */
278 offset
= sizeof(CREATESTRUCT16
); break;
280 offset
= sizeof(DRAWITEMSTRUCT16
); break;
282 offset
= sizeof(COMPAREITEMSTRUCT16
); break;
286 void *s
= MapSL(lParam
);
287 lParam
= stack16_push( offset
);
288 memcpy( MapSL(lParam
), s
, offset
);
292 iWndsLocks
= WIN_SuspendWndsLock();
297 args
[1] = HIWORD(lParam
);
298 args
[0] = LOWORD(lParam
);
299 WOWCallback16Ex( 0, WCB16_REGS
, sizeof(args
), args
, (DWORD
*)&context
);
300 ret
= MAKELONG( LOWORD(context
.Eax
), LOWORD(context
.Edx
) );
302 if (offset
) stack16_pop( offset
);
304 WIN_RestoreWndsLock(iWndsLocks
);
310 /**********************************************************************
313 * Return a pointer to the win proc.
315 static WINDOWPROC
*WINPROC_GetPtr( WNDPROC handle
)
320 /* ptr cannot be < 64K */
321 if (!HIWORD(handle
)) return NULL
;
323 /* Check for a linear pointer */
325 ptr
= (BYTE
*)handle
;
326 /* First check if it is the jmp address */
327 proc
= (WINDOWPROC
*)(ptr
- (int)&((WINDOWPROC
*)0)->jmp
);
328 if (is_valid_winproc(proc
)) return proc
;
330 /* Now it must be the thunk address */
331 proc
= (WINDOWPROC
*)(ptr
- (int)&((WINDOWPROC
*)0)->thunk
);
332 if (is_valid_winproc(proc
)) return proc
;
334 /* Check for a segmented pointer */
336 if (!IsBadReadPtr16( (SEGPTR
)handle
, sizeof(proc
->thunk
) ))
338 ptr
= MapSL( (SEGPTR
)handle
);
339 /* It must be the thunk address */
340 proc
= (WINDOWPROC
*)(ptr
- (int)&((WINDOWPROC
*)0)->thunk
);
341 if (is_valid_winproc(proc
)) return proc
;
348 /**********************************************************************
349 * WINPROC_AllocWinProc
351 * Allocate a new window procedure.
353 static WINDOWPROC
*WINPROC_AllocWinProc( WNDPROC func
, WINDOWPROCTYPE type
,
354 WINDOWPROCUSER user
)
356 static FARPROC16 relay_32A
, relay_32W
;
358 WINDOWPROC
*proc
, *oldproc
;
360 /* Allocate a window procedure */
362 if (!(proc
= alloc_winproc())) return 0;
364 /* Check if the function is already a win proc */
366 if ((oldproc
= WINPROC_GetPtr( func
)))
375 proc
->thunk
.t_from32
.popl_eax
= 0x58; /* popl %eax */
376 proc
->thunk
.t_from32
.pushl_func
= 0x68; /* pushl $proc */
377 proc
->thunk
.t_from32
.proc
= (WNDPROC16
)func
;
378 proc
->thunk
.t_from32
.pushl_eax
= 0x50; /* pushl %eax */
379 proc
->thunk
.t_from32
.jmp
= 0xe9; /* jmp relay*/
380 proc
->thunk
.t_from32
.relay
= /* relative jump */
381 (void(*)())((DWORD
)WINPROC_CallProc32ATo16
-
382 (DWORD
)(&proc
->thunk
.t_from32
.relay
+ 1));
385 if (!relay_32A
) relay_32A
= GetProcAddress16( GetModuleHandle16("user"),
386 "__wine_call_wndproc_32A" );
387 proc
->thunk
.t_from16
.popl_eax
= 0x58; /* popl %eax */
388 proc
->thunk
.t_from16
.pushl_func
= 0x68; /* pushl $proc */
389 proc
->thunk
.t_from16
.proc
= func
;
390 proc
->thunk
.t_from16
.pushl_eax
= 0x50; /* pushl %eax */
391 proc
->thunk
.t_from16
.ljmp
= 0xea; /* ljmp relay*/
392 proc
->thunk
.t_from16
.relay_offset
= OFFSETOF(relay_32A
);
393 proc
->thunk
.t_from16
.relay_sel
= SELECTOROF(relay_32A
);
394 proc
->jmp
.jmp
= 0xe9;
395 /* Fixup relative jump */
396 proc
->jmp
.proc
= (WNDPROC
)((DWORD
)func
- (DWORD
)(&proc
->jmp
.proc
+ 1));
399 if (!relay_32W
) relay_32W
= GetProcAddress16( GetModuleHandle16("user"),
400 "__wine_call_wndproc_32W" );
401 proc
->thunk
.t_from16
.popl_eax
= 0x58; /* popl %eax */
402 proc
->thunk
.t_from16
.pushl_func
= 0x68; /* pushl $proc */
403 proc
->thunk
.t_from16
.proc
= func
;
404 proc
->thunk
.t_from16
.pushl_eax
= 0x50; /* pushl %eax */
405 proc
->thunk
.t_from16
.ljmp
= 0xea; /* ljmp relay*/
406 proc
->thunk
.t_from16
.relay_offset
= OFFSETOF(relay_32W
);
407 proc
->thunk
.t_from16
.relay_sel
= SELECTOROF(relay_32W
);
408 proc
->jmp
.jmp
= 0xe9;
409 /* Fixup relative jump */
410 proc
->jmp
.proc
= (WNDPROC
)((char *)func
- (char *)(&proc
->jmp
.proc
+ 1));
413 /* Should not happen */
416 proc
->magic
= WINPROC_MAGIC
;
421 TRACE("(%p,%d): returning %p\n", func
, type
, proc
);
426 /**********************************************************************
429 * Get a window procedure pointer that can be passed to the Windows program.
431 WNDPROC16
WINPROC_GetProc( WNDPROC proc
, WINDOWPROCTYPE type
)
433 WINDOWPROC
*ptr
= (WINDOWPROC
*)proc
;
435 if (!proc
) return NULL
;
436 if (type
== WIN_PROC_16
) /* We want a 16:16 address */
438 if (ptr
->type
== WIN_PROC_16
)
439 return ptr
->thunk
.t_from32
.proc
;
441 return (WNDPROC16
)MAKESEGPTR( get_winproc_selector(),
442 (char *)&ptr
->thunk
- (char *)winproc_array
);
444 else /* We want a 32-bit address */
446 if (ptr
->type
== WIN_PROC_16
)
447 return (WNDPROC16
)&ptr
->thunk
;
448 else if (type
!= ptr
->type
)
449 /* Have to return the jmp address if types don't match */
450 return (WNDPROC16
)&ptr
->jmp
;
452 /* Some Win16 programs want to get back the proc they set */
453 return (WNDPROC16
)ptr
->thunk
.t_from16
.proc
;
458 /**********************************************************************
461 * Set the window procedure for a window or class. There are
462 * three tree classes of winproc callbacks:
464 * 1) class -> wp - not subclassed
465 * class -> wp -> wp -> wp -> wp - SetClassLong()
467 * 2) window -' / - not subclassed
468 * window -> wp -> wp ' - SetWindowLong()
470 * 3) timer -> wp - SetTimer()
472 * Initially, winproc of the window points to the current winproc
473 * thunk of its class. Subclassing prepends a new thunk to the
474 * window winproc chain at the head of the list. Thus, window thunk
475 * list includes class thunks and the latter are preserved when the
476 * window is destroyed.
479 BOOL
WINPROC_SetProc( WNDPROC
*pFirst
, WNDPROC func
,
480 WINDOWPROCTYPE type
, WINDOWPROCUSER user
)
482 BOOL bRecycle
= FALSE
;
483 WINDOWPROC
*proc
, **ppPrev
;
485 /* Check if function is already in the list */
487 ppPrev
= (WINDOWPROC
**)pFirst
;
488 proc
= WINPROC_GetPtr( func
);
495 if ((*ppPrev
)->user
!= user
)
497 /* terminal thunk is being restored */
499 WINPROC_FreeProc( *pFirst
, (*ppPrev
)->user
);
500 *(WINDOWPROC
**)pFirst
= *ppPrev
;
509 if (((*ppPrev
)->type
== type
) &&
510 (func
== (WNDPROC
)WINPROC_THUNKPROC(*ppPrev
)))
512 if((*ppPrev
)->user
== user
)
518 WINPROC_FreeProc( (WNDPROC
)*ppPrev
, user
);
525 /* WPF_CLASS thunk terminates window thunk list */
526 if ((*ppPrev
)->user
!= user
) break;
527 ppPrev
= &(*ppPrev
)->next
;
532 /* Extract this thunk from the list */
534 *ppPrev
= proc
->next
;
536 else /* Allocate a new one */
538 if (proc
) /* Was already a win proc */
541 func
= (WNDPROC
)WINPROC_THUNKPROC(proc
);
543 proc
= WINPROC_AllocWinProc( func
, type
, user
);
544 if (!proc
) return FALSE
;
547 /* Add the win proc at the head of the list */
549 TRACE("(%p,%p,%d): res=%p\n", *pFirst
, func
, type
, proc
);
550 proc
->next
= *(WINDOWPROC
**)pFirst
;
551 *(WINDOWPROC
**)pFirst
= proc
;
556 /**********************************************************************
559 * Free a list of win procs.
561 void WINPROC_FreeProc( WNDPROC proc
, WINDOWPROCUSER user
)
563 WINDOWPROC
*ptr
= (WINDOWPROC
*)proc
;
566 WINDOWPROC
*next
= ptr
->next
;
567 if (ptr
->user
!= user
) break;
568 TRACE("freeing %p (%d)\n", ptr
, user
);
575 /**********************************************************************
576 * WINPROC_GetProcType
578 * Return the window procedure type.
580 WINDOWPROCTYPE
WINPROC_GetProcType( WNDPROC proc
)
583 (((WINDOWPROC
*)proc
)->magic
!= WINPROC_MAGIC
))
584 return WIN_PROC_INVALID
;
585 return ((WINDOWPROC
*)proc
)->type
;
587 /**********************************************************************
588 * WINPROC_TestCBForStr
590 * Return TRUE if the lparam is a string
592 inline static BOOL
WINPROC_TestCBForStr( HWND hwnd
)
594 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
595 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
597 /**********************************************************************
598 * WINPROC_TestLBForStr
600 * Return TRUE if the lparam is a string
602 inline static BOOL
WINPROC_TestLBForStr( HWND hwnd
)
604 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
605 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
608 /**********************************************************************
609 * WINPROC_MapMsg32ATo32W
611 * Map a message from Ansi to Unicode.
612 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
615 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
616 * the first four bytes are the handle of the icon
617 * when the WM_SETTEXT message has been used to set the icon
619 INT
WINPROC_MapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM
*pwparam
, LPARAM
*plparam
)
624 case WM_ASKCBFORMATNAME
:
626 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0,
627 *pwparam
* sizeof(WCHAR
) + sizeof(LPARAM
) );
629 *ptr
++ = *plparam
; /* Store previous lParam */
630 *plparam
= (LPARAM
)ptr
;
633 /* lparam is string (0-terminated) */
635 case WM_WININICHANGE
:
636 case WM_DEVMODECHANGE
:
642 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*plparam
, -1, NULL
, 0);
643 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
644 len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*plparam
, -1, buf
, len
);
645 *plparam
= (LPARAM
)buf
;
646 return (*plparam
? 1 : -1);
648 case WM_GETTEXTLENGTH
:
649 case CB_GETLBTEXTLEN
:
651 return 1; /* need to map result */
655 UNICODE_STRING usBuffer
;
657 { CREATESTRUCTW cs
; /* new structure */
658 LPCWSTR lpszName
; /* allocated Name */
659 LPCWSTR lpszClass
; /* allocated Class */
662 struct s
*xs
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct s
));
664 xs
->cs
= *(CREATESTRUCTW
*)*plparam
;
665 if (HIWORD(xs
->cs
.lpszName
))
667 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)xs
->cs
.lpszName
);
668 xs
->lpszName
= xs
->cs
.lpszName
= usBuffer
.Buffer
;
670 if (HIWORD(xs
->cs
.lpszClass
))
672 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)xs
->cs
.lpszClass
);
673 xs
->lpszClass
= xs
->cs
.lpszClass
= usBuffer
.Buffer
;
676 if (GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
678 MDICREATESTRUCTW
*mdi_cs
= (MDICREATESTRUCTW
*)HeapAlloc(GetProcessHeap(), 0,
680 *mdi_cs
= *(MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
681 if (HIWORD(mdi_cs
->szTitle
))
683 RtlCreateUnicodeStringFromAsciiz(&usBuffer
, (LPCSTR
)mdi_cs
->szTitle
);
684 mdi_cs
->szTitle
= usBuffer
.Buffer
;
686 if (HIWORD(mdi_cs
->szClass
))
688 RtlCreateUnicodeStringFromAsciiz(&usBuffer
, (LPCSTR
)mdi_cs
->szClass
);
689 mdi_cs
->szClass
= usBuffer
.Buffer
;
691 xs
->cs
.lpCreateParams
= mdi_cs
;
694 *plparam
= (LPARAM
)xs
;
699 MDICREATESTRUCTW
*cs
=
700 (MDICREATESTRUCTW
*)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) );
702 *cs
= *(MDICREATESTRUCTW
*)*plparam
;
703 if (HIWORD(cs
->szClass
))
705 UNICODE_STRING usBuffer
;
706 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)cs
->szClass
);
707 cs
->szClass
= usBuffer
.Buffer
;
709 if (HIWORD(cs
->szTitle
))
711 UNICODE_STRING usBuffer
;
712 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)cs
->szTitle
);
713 cs
->szTitle
= usBuffer
.Buffer
;
715 *plparam
= (LPARAM
)cs
;
721 case LB_INSERTSTRING
:
723 case LB_FINDSTRINGEXACT
:
724 case LB_SELECTSTRING
:
725 if(!*plparam
) return 0;
726 if ( WINPROC_TestLBForStr( hwnd
))
728 UNICODE_STRING usBuffer
;
729 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)*plparam
);
730 *plparam
= (LPARAM
)usBuffer
.Buffer
;
732 return (*plparam
? 1 : -1);
734 case LB_GETTEXT
: /* FIXME: fixed sized buffer */
735 { if ( WINPROC_TestLBForStr( hwnd
))
736 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
738 *ptr
++ = *plparam
; /* Store previous lParam */
739 *plparam
= (LPARAM
)ptr
;
746 case CB_INSERTSTRING
:
747 case CB_FINDSTRINGEXACT
:
749 case CB_SELECTSTRING
:
750 if(!*plparam
) return 0;
751 if ( WINPROC_TestCBForStr( hwnd
))
753 UNICODE_STRING usBuffer
;
754 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)*plparam
);
755 *plparam
= (LPARAM
)usBuffer
.Buffer
;
757 return (*plparam
? 1 : -1);
759 case CB_GETLBTEXT
: /* FIXME: fixed sized buffer */
760 { if ( WINPROC_TestCBForStr( hwnd
))
761 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 * sizeof(WCHAR
) + sizeof(LPARAM
) );
763 *ptr
++ = *plparam
; /* Store previous lParam */
764 *plparam
= (LPARAM
)ptr
;
771 { WORD len
= (WORD
)*plparam
;
772 LPARAM
*ptr
= (LPARAM
*) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(WCHAR
) );
774 *ptr
++ = *plparam
; /* Store previous lParam */
775 *((WORD
*) ptr
) = len
; /* Store the length */
776 *plparam
= (LPARAM
)ptr
;
786 case EM_SETPASSWORDCHAR
:
788 BYTE ch
= LOWORD(*pwparam
);
790 MultiByteToWideChar(CP_ACP
, 0, &ch
, 1, &wch
, 1);
791 *pwparam
= MAKEWPARAM( wch
, HIWORD(*pwparam
) );
799 ch
[0] = (*pwparam
>> 8);
800 ch
[1] = *pwparam
& 0xff;
802 MultiByteToWideChar(CP_ACP
, 0, ch
, 2, &wch
, 1);
804 MultiByteToWideChar(CP_ACP
, 0, &ch
[1], 1, &wch
, 1);
805 *pwparam
= MAKEWPARAM( wch
, HIWORD(*pwparam
) );
809 case WM_PAINTCLIPBOARD
:
810 case WM_SIZECLIPBOARD
:
811 FIXME_(msg
)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg
, hwnd
), msg
);
813 default: /* No translation needed */
819 /**********************************************************************
820 * WINPROC_UnmapMsg32ATo32W
822 * Unmap a message that was mapped from Ansi to Unicode.
824 LRESULT
WINPROC_UnmapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
830 case WM_ASKCBFORMATNAME
:
832 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
833 if (!wParam
) result
= 0;
834 else if (!(result
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1,
835 (LPSTR
)*ptr
, wParam
, NULL
, NULL
)))
837 ((LPSTR
)*ptr
)[wParam
-1] = 0;
840 else result
--; /* do not count terminating null */
841 HeapFree( GetProcessHeap(), 0, ptr
);
844 case WM_GETTEXTLENGTH
:
845 case CB_GETLBTEXTLEN
:
847 /* there may be one DBCS char for each Unicode char */
853 { CREATESTRUCTW cs
; /* new structure */
854 LPWSTR lpszName
; /* allocated Name */
855 LPWSTR lpszClass
; /* allocated Class */
857 struct s
*xs
= (struct s
*)lParam
;
858 if (xs
->lpszName
) HeapFree( GetProcessHeap(), 0, xs
->lpszName
);
859 if (xs
->lpszClass
) HeapFree( GetProcessHeap(), 0, xs
->lpszClass
);
861 if (GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
863 MDICREATESTRUCTW
*mdi_cs
= (MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
864 if (HIWORD(mdi_cs
->szTitle
))
865 HeapFree(GetProcessHeap(), 0, (LPVOID
)mdi_cs
->szTitle
);
866 if (HIWORD(mdi_cs
->szClass
))
867 HeapFree(GetProcessHeap(), 0, (LPVOID
)mdi_cs
->szClass
);
868 HeapFree(GetProcessHeap(), 0, mdi_cs
);
870 HeapFree( GetProcessHeap(), 0, xs
);
876 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
877 if (HIWORD(cs
->szTitle
))
878 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szTitle
);
879 if (HIWORD(cs
->szClass
))
880 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szClass
);
881 HeapFree( GetProcessHeap(), 0, cs
);
886 case WM_WININICHANGE
:
887 case WM_DEVMODECHANGE
:
892 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
897 case LB_INSERTSTRING
:
899 case LB_FINDSTRINGEXACT
:
900 case LB_SELECTSTRING
:
901 if ( WINPROC_TestLBForStr( hwnd
))
902 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
906 if ( WINPROC_TestLBForStr( hwnd
))
908 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
909 result
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1,
910 (LPSTR
)*ptr
, 0x7fffffff, NULL
, NULL
) - 1;
911 HeapFree( GetProcessHeap(), 0, ptr
);
917 case CB_INSERTSTRING
:
919 case CB_FINDSTRINGEXACT
:
920 case CB_SELECTSTRING
:
921 if ( WINPROC_TestCBForStr( hwnd
))
922 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
926 if ( WINPROC_TestCBForStr( hwnd
))
928 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
929 result
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1,
930 (LPSTR
)*ptr
, 0x7fffffff, NULL
, NULL
) - 1;
931 HeapFree( GetProcessHeap(), 0, ptr
);
938 LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lParam */
939 WORD len
= *(WORD
*) lParam
;
940 result
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, result
,
941 (LPSTR
)*ptr
, len
, NULL
, NULL
);
942 if (result
< len
) ((LPSTR
)*ptr
)[result
] = 0;
943 HeapFree( GetProcessHeap(), 0, ptr
);
951 /**********************************************************************
952 * WINPROC_MapMsg32WTo32A
954 * Map a message from Unicode to Ansi.
955 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
957 INT
WINPROC_MapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM
*pwparam
, LPARAM
*plparam
)
962 case WM_ASKCBFORMATNAME
:
964 LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0,
965 *pwparam
+ sizeof(LPARAM
) );
967 *ptr
++ = *plparam
; /* Store previous lParam */
968 *plparam
= (LPARAM
)ptr
;
973 case WM_WININICHANGE
:
974 case WM_DEVMODECHANGE
:
979 if(!*plparam
) return 0;
980 *plparam
= (LPARAM
)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)*plparam
);
981 return (*plparam
? 1 : -1);
986 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( GetProcessHeap(), 0,
989 *cs
= *(CREATESTRUCTA
*)*plparam
;
990 if (HIWORD(cs
->lpszName
))
991 cs
->lpszName
= HEAP_strdupWtoA( GetProcessHeap(), 0,
992 (LPCWSTR
)cs
->lpszName
);
993 if (HIWORD(cs
->lpszClass
))
994 cs
->lpszClass
= HEAP_strdupWtoA( GetProcessHeap(), 0,
995 (LPCWSTR
)cs
->lpszClass
);
997 if (GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
999 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)HeapAlloc(GetProcessHeap(), 0,
1003 HeapFree(GetProcessHeap(), 0, cs
);
1006 *mdi_cs
= *(MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1007 if (HIWORD(mdi_cs
->szTitle
))
1008 mdi_cs
->szTitle
= HEAP_strdupWtoA(GetProcessHeap(), 0,
1009 (LPCWSTR
)mdi_cs
->szTitle
);
1010 if (HIWORD(mdi_cs
->szClass
))
1011 mdi_cs
->szClass
= HEAP_strdupWtoA(GetProcessHeap(), 0,
1012 (LPCWSTR
)mdi_cs
->szClass
);
1013 cs
->lpCreateParams
= (LPVOID
)mdi_cs
;
1015 *plparam
= (LPARAM
)cs
;
1020 MDICREATESTRUCTA
*cs
=
1021 (MDICREATESTRUCTA
*)HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) );
1023 *cs
= *(MDICREATESTRUCTA
*)*plparam
;
1024 if (HIWORD(cs
->szTitle
))
1025 cs
->szTitle
= HEAP_strdupWtoA( GetProcessHeap(), 0,
1026 (LPCWSTR
)cs
->szTitle
);
1027 if (HIWORD(cs
->szClass
))
1028 cs
->szClass
= HEAP_strdupWtoA( GetProcessHeap(), 0,
1029 (LPCWSTR
)cs
->szClass
);
1030 *plparam
= (LPARAM
)cs
;
1036 case LB_INSERTSTRING
:
1038 case LB_FINDSTRINGEXACT
:
1039 case LB_SELECTSTRING
:
1040 if(!*plparam
) return 0;
1041 if ( WINPROC_TestLBForStr( hwnd
))
1042 *plparam
= (LPARAM
)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)*plparam
);
1043 return (*plparam
? 1 : -1);
1045 case LB_GETTEXT
: /* FIXME: fixed sized buffer */
1046 { if ( WINPROC_TestLBForStr( hwnd
))
1047 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM
) );
1048 if (!ptr
) return -1;
1049 *ptr
++ = *plparam
; /* Store previous lParam */
1050 *plparam
= (LPARAM
)ptr
;
1057 case CB_INSERTSTRING
:
1059 case CB_FINDSTRINGEXACT
:
1060 case CB_SELECTSTRING
:
1061 if(!*plparam
) return 0;
1062 if ( WINPROC_TestCBForStr( hwnd
))
1063 *plparam
= (LPARAM
)HEAP_strdupWtoA( GetProcessHeap(), 0, (LPCWSTR
)*plparam
);
1064 return (*plparam
? 1 : -1);
1066 case CB_GETLBTEXT
: /* FIXME: fixed sized buffer */
1067 { if ( WINPROC_TestCBForStr( hwnd
))
1068 { LPARAM
*ptr
= (LPARAM
*)HeapAlloc( GetProcessHeap(), 0, 256 + sizeof(LPARAM
) );
1069 if (!ptr
) return -1;
1070 *ptr
++ = *plparam
; /* Store previous lParam */
1071 *plparam
= (LPARAM
)ptr
;
1076 /* Multiline edit */
1078 { WORD len
= (WORD
)*plparam
;
1079 LPARAM
*ptr
= (LPARAM
*) HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(CHAR
) );
1080 if (!ptr
) return -1;
1081 *ptr
++ = *plparam
; /* Store previous lParam */
1082 *((WORD
*) ptr
) = len
; /* Store the length */
1083 *plparam
= (LPARAM
)ptr
;
1092 case WM_SYSDEADCHAR
:
1093 case EM_SETPASSWORDCHAR
:
1095 WCHAR wch
= LOWORD(*pwparam
);
1097 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
1098 *pwparam
= MAKEWPARAM( ch
, HIWORD(*pwparam
) );
1104 WCHAR wch
= LOWORD(*pwparam
);
1107 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
) == 2)
1108 *pwparam
= MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(*pwparam
) );
1110 *pwparam
= MAKEWPARAM( ch
[0], HIWORD(*pwparam
) );
1114 case WM_PAINTCLIPBOARD
:
1115 case WM_SIZECLIPBOARD
:
1116 FIXME_(msg
)("message %s (%04x) needs translation, please report\n",SPY_GetMsgName(msg
, hwnd
),msg
);
1118 default: /* No translation needed */
1124 /**********************************************************************
1125 * WINPROC_UnmapMsg32WTo32A
1127 * Unmap a message that was mapped from Unicode to Ansi.
1129 LRESULT
WINPROC_UnmapMsg32WTo32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
, LRESULT result
)
1134 case WM_ASKCBFORMATNAME
:
1136 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
1137 if (!wParam
) result
= 0;
1138 else if (!(result
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1,
1139 (LPWSTR
)*ptr
, wParam
)))
1141 ((LPWSTR
)*ptr
)[wParam
-1] = 0;
1142 result
= wParam
- 1;
1144 else result
--; /* do not count terminating null */
1145 HeapFree( GetProcessHeap(), 0, ptr
);
1150 case WM_WININICHANGE
:
1151 case WM_DEVMODECHANGE
:
1156 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
1162 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1163 if (HIWORD(cs
->lpszName
))
1164 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->lpszName
);
1165 if (HIWORD(cs
->lpszClass
))
1166 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->lpszClass
);
1167 if (GetWindowLongA(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1169 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs
->lpCreateParams
;
1170 if (HIWORD(mdi_cs
->szTitle
))
1171 HeapFree(GetProcessHeap(), 0, (LPVOID
)mdi_cs
->szTitle
);
1172 if (HIWORD(mdi_cs
->szClass
))
1173 HeapFree(GetProcessHeap(), 0, (LPVOID
)mdi_cs
->szClass
);
1174 HeapFree(GetProcessHeap(), 0, mdi_cs
);
1176 HeapFree( GetProcessHeap(), 0, cs
);
1182 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
1183 if (HIWORD(cs
->szTitle
))
1184 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szTitle
);
1185 if (HIWORD(cs
->szClass
))
1186 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szClass
);
1187 HeapFree( GetProcessHeap(), 0, cs
);
1193 case LB_INSERTSTRING
:
1195 case LB_FINDSTRINGEXACT
:
1196 case LB_SELECTSTRING
:
1197 if ( WINPROC_TestLBForStr( hwnd
))
1198 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
1202 if ( WINPROC_TestLBForStr( hwnd
))
1204 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
1205 result
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, (LPWSTR
)*ptr
, 0x7fffffff ) - 1;
1206 HeapFree( GetProcessHeap(), 0, ptr
);
1212 case CB_INSERTSTRING
:
1214 case CB_FINDSTRINGEXACT
:
1215 case CB_SELECTSTRING
:
1216 if ( WINPROC_TestCBForStr( hwnd
))
1217 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
1221 if ( WINPROC_TestCBForStr( hwnd
))
1223 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
1224 result
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, -1, (LPWSTR
)*ptr
, 0x7fffffff ) - 1;
1225 HeapFree( GetProcessHeap(), 0, ptr
);
1229 /* Multiline edit */
1232 LPARAM
* ptr
= (LPARAM
*)lParam
- 1; /* get the old lparam */
1233 WORD len
= *(WORD
*)ptr
;
1236 result
= MultiByteToWideChar( CP_ACP
, 0, (LPSTR
)lParam
, result
, (LPWSTR
)*ptr
, len
);
1237 if (result
< len
) ((LPWSTR
)*ptr
)[result
] = 0;
1239 HeapFree( GetProcessHeap(), 0, ptr
);
1246 static UINT
convert_handle_16_to_32(HANDLE16 src
, unsigned int flags
)
1249 UINT sz
= GlobalSize16(src
);
1252 if (!(dst
= GlobalAlloc(flags
, sz
)))
1254 ptr16
= GlobalLock16(src
);
1255 ptr32
= GlobalLock(dst
);
1256 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr32
, ptr16
, sz
);
1257 GlobalUnlock16(src
);
1263 /**********************************************************************
1264 * WINPROC_MapMsg16To32A
1266 * Map a message from 16- to 32-bit Ansi.
1267 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1269 INT
WINPROC_MapMsg16To32A( HWND hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
1270 WPARAM
*pwparam32
, LPARAM
*plparam
)
1272 *pmsg32
= (UINT
)msg16
;
1273 *pwparam32
= (WPARAM
)wParam16
;
1280 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
1281 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1285 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1286 *plparam
= (LPARAM
)WIN_Handle32( HIWORD(*plparam
) );
1289 if ( HIWORD(*plparam
) > CTLCOLOR_STATIC
) return -1;
1290 *pmsg32
= WM_CTLCOLORMSGBOX
+ HIWORD(*plparam
);
1291 *pwparam32
= (WPARAM
)HDC_32(wParam16
);
1292 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1294 case WM_COMPAREITEM
:
1296 COMPAREITEMSTRUCT16
* cis16
= MapSL(*plparam
);
1297 COMPAREITEMSTRUCT
*cis
= (COMPAREITEMSTRUCT
*)
1298 HeapAlloc(GetProcessHeap(), 0, sizeof(*cis
));
1299 if (!cis
) return -1;
1300 cis
->CtlType
= cis16
->CtlType
;
1301 cis
->CtlID
= cis16
->CtlID
;
1302 cis
->hwndItem
= WIN_Handle32( cis16
->hwndItem
);
1303 cis
->itemID1
= cis16
->itemID1
;
1304 cis
->itemData1
= cis16
->itemData1
;
1305 cis
->itemID2
= cis16
->itemID2
;
1306 cis
->itemData2
= cis16
->itemData2
;
1307 cis
->dwLocaleId
= 0; /* FIXME */
1308 *plparam
= (LPARAM
)cis
;
1313 DELETEITEMSTRUCT16
* dis16
= MapSL(*plparam
);
1314 DELETEITEMSTRUCT
*dis
= (DELETEITEMSTRUCT
*)
1315 HeapAlloc(GetProcessHeap(), 0, sizeof(*dis
));
1316 if (!dis
) return -1;
1317 dis
->CtlType
= dis16
->CtlType
;
1318 dis
->CtlID
= dis16
->CtlID
;
1319 dis
->hwndItem
= WIN_Handle32( dis16
->hwndItem
);
1320 dis
->itemData
= dis16
->itemData
;
1321 *plparam
= (LPARAM
)dis
;
1324 case WM_MEASUREITEM
:
1326 MEASUREITEMSTRUCT16
* mis16
= MapSL(*plparam
);
1327 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)
1328 HeapAlloc(GetProcessHeap(), 0,
1329 sizeof(*mis
) + sizeof(LPARAM
));
1330 if (!mis
) return -1;
1331 mis
->CtlType
= mis16
->CtlType
;
1332 mis
->CtlID
= mis16
->CtlID
;
1333 mis
->itemID
= mis16
->itemID
;
1334 mis
->itemWidth
= mis16
->itemWidth
;
1335 mis
->itemHeight
= mis16
->itemHeight
;
1336 mis
->itemData
= mis16
->itemData
;
1337 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1338 *plparam
= (LPARAM
)mis
;
1343 DRAWITEMSTRUCT16
* dis16
= MapSL(*plparam
);
1344 DRAWITEMSTRUCT
*dis
= (DRAWITEMSTRUCT
*)HeapAlloc(GetProcessHeap(), 0,
1346 if (!dis
) return -1;
1347 dis
->CtlType
= dis16
->CtlType
;
1348 dis
->CtlID
= dis16
->CtlID
;
1349 dis
->itemID
= dis16
->itemID
;
1350 dis
->itemAction
= dis16
->itemAction
;
1351 dis
->itemState
= dis16
->itemState
;
1352 dis
->hwndItem
= (dis
->CtlType
== ODT_MENU
) ? (HWND
)HMENU_32(dis16
->hwndItem
)
1353 : WIN_Handle32( dis16
->hwndItem
);
1354 dis
->hDC
= HDC_32(dis16
->hDC
);
1355 dis
->itemData
= dis16
->itemData
;
1356 CONV_RECT16TO32( &dis16
->rcItem
, &dis
->rcItem
);
1357 *plparam
= (LPARAM
)dis
;
1360 case WM_GETMINMAXINFO
:
1362 MINMAXINFO
*mmi
= (MINMAXINFO
*)HeapAlloc( GetProcessHeap(), 0,
1363 sizeof(*mmi
) + sizeof(LPARAM
));
1364 if (!mmi
) return -1;
1365 STRUCT32_MINMAXINFO16to32( MapSL(*plparam
), mmi
);
1366 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1367 *plparam
= (LPARAM
)mmi
;
1372 case WM_WININICHANGE
:
1373 case WM_DEVMODECHANGE
:
1374 case WM_ASKCBFORMATNAME
:
1375 *plparam
= (LPARAM
)MapSL(*plparam
);
1379 MDICREATESTRUCT16
*cs16
= MapSL(*plparam
);
1380 MDICREATESTRUCTA
*cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) + sizeof(LPARAM
) );
1382 STRUCT32_MDICREATESTRUCT16to32A( cs16
, cs
);
1383 cs
->szTitle
= MapSL(cs16
->szTitle
);
1384 cs
->szClass
= MapSL(cs16
->szClass
);
1385 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1386 *plparam
= (LPARAM
)cs
;
1389 case WM_MDIGETACTIVE
:
1390 *plparam
= (LPARAM
)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL
) );
1391 *(BOOL
*)(*plparam
) = 0;
1395 *pmsg32
=WM_MDIREFRESHMENU
;
1396 *pwparam32
= (WPARAM
)HMENU_32(LOWORD(*plparam
));
1397 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1400 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1401 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1404 if((LOWORD(*plparam
) & MF_POPUP
) && (LOWORD(*plparam
) != 0xFFFF))
1406 HMENU hmenu
=HMENU_32(HIWORD(*plparam
));
1407 UINT Pos
=MENU_FindSubMenu( &hmenu
, HMENU_32(wParam16
));
1408 if(Pos
==0xFFFF) Pos
=0; /* NO_SELECTED_ITEM */
1409 *pwparam32
= MAKEWPARAM( Pos
, LOWORD(*plparam
) );
1411 else *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1412 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1414 case WM_MDIACTIVATE
:
1417 *pwparam32
= (WPARAM
)WIN_Handle32( HIWORD(*plparam
) );
1418 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1420 else /* message sent to MDI client */
1421 *pwparam32
= wParam16
;
1425 NCCALCSIZE_PARAMS16
*nc16
;
1426 NCCALCSIZE_PARAMS
*nc
;
1428 nc
= (NCCALCSIZE_PARAMS
*)HeapAlloc( GetProcessHeap(), 0,
1429 sizeof(*nc
) + sizeof(LPARAM
) );
1431 nc16
= MapSL(*plparam
);
1432 CONV_RECT16TO32( &nc16
->rgrc
[0], &nc
->rgrc
[0] );
1435 nc
->lppos
= (WINDOWPOS
*)HeapAlloc( GetProcessHeap(), 0,
1436 sizeof(*nc
->lppos
) );
1437 CONV_RECT16TO32( &nc16
->rgrc
[1], &nc
->rgrc
[1] );
1438 CONV_RECT16TO32( &nc16
->rgrc
[2], &nc
->rgrc
[2] );
1439 if (nc
->lppos
) STRUCT32_WINDOWPOS16to32( MapSL(nc16
->lppos
), nc
->lppos
);
1441 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1442 *plparam
= (LPARAM
)nc
;
1448 CREATESTRUCT16
*cs16
= MapSL(*plparam
);
1449 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)HeapAlloc( GetProcessHeap(), 0,
1450 sizeof(*cs
) + sizeof(LPARAM
) );
1452 STRUCT32_CREATESTRUCT16to32A( cs16
, cs
);
1453 cs
->lpszName
= MapSL(cs16
->lpszName
);
1454 cs
->lpszClass
= MapSL(cs16
->lpszClass
);
1455 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1456 *plparam
= (LPARAM
)cs
;
1459 case WM_PARENTNOTIFY
:
1460 if ((wParam16
== WM_CREATE
) || (wParam16
== WM_DESTROY
))
1462 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
1463 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1466 case WM_WINDOWPOSCHANGING
:
1467 case WM_WINDOWPOSCHANGED
:
1469 WINDOWPOS
*wp
= (WINDOWPOS
*)HeapAlloc( GetProcessHeap(), 0,
1470 sizeof(*wp
) + sizeof(LPARAM
) );
1472 STRUCT32_WINDOWPOS16to32( MapSL(*plparam
), wp
);
1473 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1474 *plparam
= (LPARAM
)wp
;
1480 LPMSG16 msg16
= MapSL(*plparam
);
1481 LPMSG msg32
= (LPMSG
)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG
) );
1483 if (!msg32
) return -1;
1484 msg32
->hwnd
= WIN_Handle32( msg16
->hwnd
);
1485 msg32
->lParam
= msg16
->lParam
;
1486 msg32
->time
= msg16
->time
;
1487 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1488 /* this is right, right? */
1489 if (WINPROC_MapMsg16To32A( msg32
->hwnd
, msg16
->message
,msg16
->wParam
,
1490 &msg32
->message
,&msg32
->wParam
,
1491 &msg32
->lParam
)<0) {
1492 HeapFree( GetProcessHeap(), 0, msg32
);
1495 *plparam
= (LPARAM
)msg32
;
1500 *plparam
= (LPARAM
)MapSL(*plparam
);
1502 case WM_ACTIVATEAPP
:
1503 /* We need this when SetActiveWindow sends a Sendmessage16() to
1504 * a 32bit window. Might be superflous with 32bit interprocess
1505 * message queues. */
1506 if (*plparam
) *plparam
= HTASK_32( *plparam
);
1510 MDINEXTMENU
*next
= HeapAlloc( GetProcessHeap(), 0, sizeof(*next
) );
1511 if (!next
) return -1;
1512 next
->hmenuIn
= (HMENU
)*plparam
;
1513 next
->hmenuNext
= 0;
1515 *plparam
= (LPARAM
)next
;
1518 case WM_PAINTCLIPBOARD
:
1519 case WM_SIZECLIPBOARD
:
1520 FIXME_(msg
)("message %04x needs translation\n",msg16
);
1522 case WM_DDE_INITIATE
:
1523 case WM_DDE_TERMINATE
:
1524 case WM_DDE_UNADVISE
:
1525 case WM_DDE_REQUEST
:
1526 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1536 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1537 lo16
= LOWORD(*plparam
);
1538 hi
= HIWORD(*plparam
);
1539 if (lo16
&& !(lo32
= convert_handle_16_to_32(lo16
, GMEM_DDESHARE
)))
1541 *plparam
= PackDDElParam(msg16
, lo32
, hi
);
1543 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1550 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1552 lo
= LOWORD(*plparam
);
1553 hi
= HIWORD(*plparam
);
1555 if (GlobalGetAtomNameA(hi
, buf
, 2) > 0) flag
|= 1;
1556 if (GlobalSize16(hi
) != 0) flag
|= 2;
1562 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1567 break; /* atom, nothing to do */
1569 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
1572 hi
= convert_handle_16_to_32(hi
, GMEM_DDESHARE
);
1575 *plparam
= PackDDElParam(WM_DDE_ACK
, lo
, hi
);
1577 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1578 case WM_DDE_EXECUTE
:
1579 *plparam
= convert_handle_16_to_32(*plparam
, GMEM_DDESHARE
);
1580 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1581 default: /* No translation needed */
1587 /**********************************************************************
1588 * WINPROC_UnmapMsg16To32A
1590 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1592 LRESULT
WINPROC_UnmapMsg16To32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1597 case WM_COMPAREITEM
:
1600 HeapFree( GetProcessHeap(), 0, (LPVOID
)lParam
);
1602 case WM_MEASUREITEM
:
1604 MEASUREITEMSTRUCT16
*mis16
;
1605 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lParam
;
1606 lParam
= *(LPARAM
*)(mis
+ 1);
1607 mis16
= MapSL(lParam
);
1608 mis16
->itemWidth
= (UINT16
)mis
->itemWidth
;
1609 mis16
->itemHeight
= (UINT16
)mis
->itemHeight
;
1610 HeapFree( GetProcessHeap(), 0, mis
);
1613 case WM_GETMINMAXINFO
:
1615 MINMAXINFO
*mmi
= (MINMAXINFO
*)lParam
;
1616 lParam
= *(LPARAM
*)(mmi
+ 1);
1617 STRUCT32_MINMAXINFO32to16( mmi
, MapSL(lParam
));
1618 HeapFree( GetProcessHeap(), 0, mmi
);
1623 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
1624 lParam
= *(LPARAM
*)(cs
+ 1);
1625 STRUCT32_MDICREATESTRUCT32Ato16( cs
, MapSL(lParam
) );
1626 HeapFree( GetProcessHeap(), 0, cs
);
1629 case WM_MDIGETACTIVE
:
1630 result
= MAKELONG( LOWORD(result
), (BOOL16
)(*(BOOL
*)lParam
) );
1631 HeapFree( GetProcessHeap(), 0, (BOOL
*)lParam
);
1635 NCCALCSIZE_PARAMS16
*nc16
;
1636 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lParam
;
1637 lParam
= *(LPARAM
*)(nc
+ 1);
1638 nc16
= MapSL(lParam
);
1639 CONV_RECT32TO16( &nc
->rgrc
[0], &nc16
->rgrc
[0] );
1642 CONV_RECT32TO16( &nc
->rgrc
[1], &nc16
->rgrc
[1] );
1643 CONV_RECT32TO16( &nc
->rgrc
[2], &nc16
->rgrc
[2] );
1646 STRUCT32_WINDOWPOS32to16( nc
->lppos
, MapSL(nc16
->lppos
));
1647 HeapFree( GetProcessHeap(), 0, nc
->lppos
);
1650 HeapFree( GetProcessHeap(), 0, nc
);
1656 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1657 lParam
= *(LPARAM
*)(cs
+ 1);
1658 STRUCT32_CREATESTRUCT32Ato16( cs
, MapSL(lParam
) );
1659 HeapFree( GetProcessHeap(), 0, cs
);
1662 case WM_WINDOWPOSCHANGING
:
1663 case WM_WINDOWPOSCHANGED
:
1665 WINDOWPOS
*wp
= (WINDOWPOS
*)lParam
;
1666 lParam
= *(LPARAM
*)(wp
+ 1);
1667 STRUCT32_WINDOWPOS32to16(wp
, MapSL(lParam
));
1668 HeapFree( GetProcessHeap(), 0, wp
);
1674 LPMSG msg32
= (LPMSG
)lParam
;
1676 WINPROC_UnmapMsg16To32A( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1678 HeapFree( GetProcessHeap(), 0, msg32
);
1683 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
1684 result
= MAKELONG( HMENU_16(next
->hmenuNext
), HWND_16(next
->hwndNext
) );
1685 HeapFree( GetProcessHeap(), 0, next
);
1693 /**********************************************************************
1694 * WINPROC_MapMsg16To32W
1696 * Map a message from 16- to 32-bit Unicode.
1697 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1699 INT
WINPROC_MapMsg16To32W( HWND hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
1700 WPARAM
*pwparam32
, LPARAM
*plparam
)
1705 *pmsg32
=(UINT
)msg16
;
1706 *pwparam32
= (WPARAM
)wParam16
;
1711 case WM_WININICHANGE
:
1712 case WM_DEVMODECHANGE
:
1713 case WM_ASKCBFORMATNAME
:
1714 *plparam
= (LPARAM
)MapSL(*plparam
);
1715 return WINPROC_MapMsg32ATo32W( hwnd
, *pmsg32
, pwparam32
, plparam
);
1716 case WM_GETTEXTLENGTH
:
1717 case CB_GETLBTEXTLEN
:
1719 return 1; /* need to map result */
1723 CREATESTRUCT16
*cs16
= MapSL(*plparam
);
1724 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)HeapAlloc( GetProcessHeap(), 0,
1725 sizeof(*cs
) + sizeof(LPARAM
) );
1727 STRUCT32_CREATESTRUCT16to32A( cs16
, (CREATESTRUCTA
*)cs
);
1728 cs
->lpszName
= map_str_16_to_32W(cs16
->lpszName
);
1729 cs
->lpszClass
= map_str_16_to_32W(cs16
->lpszClass
);
1730 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1731 *plparam
= (LPARAM
)cs
;
1736 MDICREATESTRUCT16
*cs16
= MapSL(*plparam
);
1737 MDICREATESTRUCTW
*cs
=
1738 (MDICREATESTRUCTW
*)HeapAlloc( GetProcessHeap(), 0,
1739 sizeof(*cs
) + sizeof(LPARAM
) );
1741 STRUCT32_MDICREATESTRUCT16to32A( cs16
, (MDICREATESTRUCTA
*)cs
);
1742 cs
->szTitle
= map_str_16_to_32W(cs16
->szTitle
);
1743 cs
->szClass
= map_str_16_to_32W(cs16
->szClass
);
1744 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1745 *plparam
= (LPARAM
)cs
;
1751 LPMSG16 msg16
= MapSL(*plparam
);
1752 LPMSG msg32
= (LPMSG
)HeapAlloc( GetProcessHeap(), 0, sizeof(MSG
) );
1754 if (!msg32
) return -1;
1755 msg32
->hwnd
= WIN_Handle32( msg16
->hwnd
);
1756 msg32
->lParam
= msg16
->lParam
;
1757 msg32
->time
= msg16
->time
;
1758 CONV_POINT16TO32(&msg16
->pt
,&msg32
->pt
);
1759 /* this is right, right? */
1760 if (WINPROC_MapMsg16To32W(hwnd
, msg16
->message
,msg16
->wParam
,
1761 &msg32
->message
,&msg32
->wParam
,
1762 &msg32
->lParam
)<0) {
1763 HeapFree( GetProcessHeap(), 0, msg32
);
1766 *plparam
= (LPARAM
)msg32
;
1773 MultiByteToWideChar( CP_ACP
, 0, &ch
, 1, &wch
, 1);
1774 *pwparam32
= MAKEWPARAM( wch
, HIWORD(*plparam
) );
1775 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1779 MultiByteToWideChar( CP_ACP
, 0, &ch
, 1, &wch
, 1);
1780 *pwparam32
= MAKEWPARAM( wch
, LOWORD(*plparam
) );
1781 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1786 case WM_SYSDEADCHAR
:
1788 MultiByteToWideChar( CP_ACP
, 0, &ch
, 1, &wch
, 1);
1792 return WINPROC_MapMsg32ATo32W( hwnd
, *pmsg32
, pwparam32
, plparam
);
1794 default: /* No Unicode translation needed */
1795 return WINPROC_MapMsg16To32A( hwnd
, msg16
, wParam16
, pmsg32
,
1796 pwparam32
, plparam
);
1801 /**********************************************************************
1802 * WINPROC_UnmapMsg16To32W
1804 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1806 LRESULT
WINPROC_UnmapMsg16To32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1813 case WM_GETTEXTLENGTH
:
1814 case CB_GETLBTEXTLEN
:
1816 case WM_ASKCBFORMATNAME
:
1817 return WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
, result
);
1821 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
1822 lParam
= *(LPARAM
*)(cs
+ 1);
1823 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs
, MapSL(lParam
) );
1824 unmap_str_16_to_32W( cs
->lpszName
);
1825 unmap_str_16_to_32W( cs
->lpszClass
);
1826 HeapFree( GetProcessHeap(), 0, cs
);
1831 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
1832 lParam
= *(LPARAM
*)(cs
+ 1);
1833 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs
, MapSL(lParam
) );
1834 unmap_str_16_to_32W( cs
->szTitle
);
1835 unmap_str_16_to_32W( cs
->szClass
);
1836 HeapFree( GetProcessHeap(), 0, cs
);
1842 LPMSG msg32
= (LPMSG
)lParam
;
1844 WINPROC_UnmapMsg16To32W( hwnd
, msg32
->message
, msg32
->wParam
, msg32
->lParam
,
1846 HeapFree( GetProcessHeap(), 0, msg32
);
1850 return WINPROC_UnmapMsg16To32A( hwnd
, msg
, wParam
, lParam
, result
);
1855 static HANDLE16
convert_handle_32_to_16(UINT src
, unsigned int flags
)
1858 UINT sz
= GlobalSize((HANDLE
)src
);
1861 if (!(dst
= GlobalAlloc16(flags
, sz
)))
1863 ptr32
= GlobalLock((HANDLE
)src
);
1864 ptr16
= GlobalLock16(dst
);
1865 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr16
, ptr32
, sz
);
1866 GlobalUnlock((HANDLE
)src
);
1867 GlobalUnlock16(dst
);
1873 /**********************************************************************
1874 * WINPROC_MapMsg32ATo16
1876 * Map a message from 32-bit Ansi to 16-bit.
1877 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1879 INT
WINPROC_MapMsg32ATo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
1880 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
1883 *pmsg16
= (UINT16
)msg32
;
1884 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1892 *pmsg16
= (UINT16
)msg32
+ (BM_GETCHECK16
- BM_GETCHECK
);
1901 case EM_SCROLLCARET
:
1904 case EM_GETLINECOUNT
:
1916 case EM_LINEFROMCHAR
:
1917 case EM_SETTABSTOPS
:
1918 case EM_SETPASSWORDCHAR
:
1919 case EM_EMPTYUNDOBUFFER
:
1920 case EM_GETFIRSTVISIBLELINE
:
1921 case EM_SETREADONLY
:
1922 case EM_SETWORDBREAKPROC
:
1923 case EM_GETWORDBREAKPROC
:
1924 case EM_GETPASSWORDCHAR
:
1925 *pmsg16
= (UINT16
)msg32
+ (EM_GETSEL16
- EM_GETSEL
);
1930 case LB_DELETESTRING
:
1931 case LB_GETANCHORINDEX
:
1932 case LB_GETCARETINDEX
:
1935 case LB_GETHORIZONTALEXTENT
:
1936 case LB_GETITEMDATA
:
1937 case LB_GETITEMHEIGHT
:
1939 case LB_GETSELCOUNT
:
1941 case LB_GETTOPINDEX
:
1942 case LB_RESETCONTENT
:
1943 case LB_SELITEMRANGE
:
1944 case LB_SELITEMRANGEEX
:
1945 case LB_SETANCHORINDEX
:
1946 case LB_SETCARETINDEX
:
1947 case LB_SETCOLUMNWIDTH
:
1949 case LB_SETHORIZONTALEXTENT
:
1950 case LB_SETITEMDATA
:
1951 case LB_SETITEMHEIGHT
:
1953 case LB_SETTOPINDEX
:
1954 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1956 case CB_DELETESTRING
:
1958 case CB_GETLBTEXTLEN
:
1960 case CB_RESETCONTENT
:
1964 case CB_SHOWDROPDOWN
:
1965 case CB_SETITEMDATA
:
1966 case CB_SETITEMHEIGHT
:
1967 case CB_GETITEMHEIGHT
:
1968 case CB_SETEXTENDEDUI
:
1969 case CB_GETEXTENDEDUI
:
1970 case CB_GETDROPPEDSTATE
:
1971 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1974 *pmsg16
= CB_GETEDITSEL16
;
1979 case LB_FINDSTRINGEXACT
:
1980 case LB_INSERTSTRING
:
1981 case LB_SELECTSTRING
:
1984 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
1985 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1990 case CB_FINDSTRINGEXACT
:
1991 case CB_INSERTSTRING
:
1992 case CB_SELECTSTRING
:
1994 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
1995 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1998 case LB_GETITEMRECT
:
2000 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
2001 if (!rect
) return -1;
2002 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
2003 *plparam
= MapLS( rect
);
2005 *pmsg16
= LB_GETITEMRECT16
;
2007 case LB_GETSELITEMS
:
2010 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
2011 if (!(items
= HeapAlloc( GetProcessHeap(), 0,
2012 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
2013 *((LPARAM
*)items
)++ = *plparam
; /* Store the previous lParam */
2014 *plparam
= MapLS( items
);
2016 *pmsg16
= LB_GETSELITEMS16
;
2018 case LB_SETTABSTOPS
:
2023 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
2024 if (!(stops
= HeapAlloc( GetProcessHeap(), 0,
2025 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
2026 for (i
= 0; i
< *pwparam16
; i
++) stops
[i
] = *((LPINT
)*plparam
+i
);
2027 *plparam
= MapLS( stops
);
2030 *pmsg16
= LB_SETTABSTOPS16
;
2033 case CB_GETDROPPEDCONTROLRECT
:
2035 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
2036 if (!rect
) return -1;
2037 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
2038 *plparam
= (LPARAM
)MapLS(rect
);
2040 *pmsg16
= CB_GETDROPPEDCONTROLRECT16
;
2044 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
2045 *pmsg16
= LB_GETTEXT16
;
2049 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
2050 *pmsg16
= CB_GETLBTEXT16
;
2055 *plparam
= MAKELONG( (INT16
)(INT
)wParam32
, (INT16
)*plparam
);
2056 *pmsg16
= EM_SETSEL16
;
2063 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
2067 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
2069 case WM_CTLCOLORMSGBOX
:
2070 case WM_CTLCOLOREDIT
:
2071 case WM_CTLCOLORLISTBOX
:
2072 case WM_CTLCOLORBTN
:
2073 case WM_CTLCOLORDLG
:
2074 case WM_CTLCOLORSCROLLBAR
:
2075 case WM_CTLCOLORSTATIC
:
2076 *pmsg16
= WM_CTLCOLOR
;
2077 *plparam
= MAKELPARAM( (HWND16
)*plparam
,
2078 (WORD
)msg32
- WM_CTLCOLORMSGBOX
);
2080 case WM_COMPAREITEM
:
2082 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)*plparam
;
2083 COMPAREITEMSTRUCT16
*cis
= HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16
));
2084 if (!cis
) return -1;
2085 cis
->CtlType
= (UINT16
)cis32
->CtlType
;
2086 cis
->CtlID
= (UINT16
)cis32
->CtlID
;
2087 cis
->hwndItem
= HWND_16( cis32
->hwndItem
);
2088 cis
->itemID1
= (UINT16
)cis32
->itemID1
;
2089 cis
->itemData1
= cis32
->itemData1
;
2090 cis
->itemID2
= (UINT16
)cis32
->itemID2
;
2091 cis
->itemData2
= cis32
->itemData2
;
2092 *plparam
= MapLS( cis
);
2097 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)*plparam
;
2098 DELETEITEMSTRUCT16
*dis
= HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16
) );
2099 if (!dis
) return -1;
2100 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
2101 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
2102 dis
->itemID
= (UINT16
)dis32
->itemID
;
2103 dis
->hwndItem
= (dis
->CtlType
== ODT_MENU
) ? (HWND16
)LOWORD(dis32
->hwndItem
)
2104 : HWND_16( dis32
->hwndItem
);
2105 dis
->itemData
= dis32
->itemData
;
2106 *plparam
= MapLS( dis
);
2111 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)*plparam
;
2112 DRAWITEMSTRUCT16
*dis
= HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16
) );
2113 if (!dis
) return -1;
2114 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
2115 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
2116 dis
->itemID
= (UINT16
)dis32
->itemID
;
2117 dis
->itemAction
= (UINT16
)dis32
->itemAction
;
2118 dis
->itemState
= (UINT16
)dis32
->itemState
;
2119 dis
->hwndItem
= HWND_16( dis32
->hwndItem
);
2120 dis
->hDC
= HDC_16(dis32
->hDC
);
2121 dis
->itemData
= dis32
->itemData
;
2122 CONV_RECT32TO16( &dis32
->rcItem
, &dis
->rcItem
);
2123 *plparam
= MapLS( dis
);
2126 case WM_MEASUREITEM
:
2128 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)*plparam
;
2129 MEASUREITEMSTRUCT16
*mis
= HeapAlloc( GetProcessHeap(), 0, sizeof(*mis
)+sizeof(LPARAM
));
2130 if (!mis
) return -1;
2131 mis
->CtlType
= (UINT16
)mis32
->CtlType
;
2132 mis
->CtlID
= (UINT16
)mis32
->CtlID
;
2133 mis
->itemID
= (UINT16
)mis32
->itemID
;
2134 mis
->itemWidth
= (UINT16
)mis32
->itemWidth
;
2135 mis
->itemHeight
= (UINT16
)mis32
->itemHeight
;
2136 mis
->itemData
= mis32
->itemData
;
2137 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
2138 *plparam
= MapLS( mis
);
2141 case WM_GETMINMAXINFO
:
2143 MINMAXINFO16
*mmi
= HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi
) + sizeof(LPARAM
) );
2144 if (!mmi
) return -1;
2145 STRUCT32_MINMAXINFO32to16( (MINMAXINFO
*)*plparam
, mmi
);
2146 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
2147 *plparam
= MapLS( mmi
);
2151 case WM_ASKCBFORMATNAME
:
2154 *pwparam16
= (WPARAM16
)min( wParam32
, 0xff80 ); /* Must be < 64K */
2155 if (!(str
= HeapAlloc( GetProcessHeap(), 0, *pwparam16
+ sizeof(LPARAM
)))) return -1;
2156 *((LPARAM
*)str
)++ = *plparam
; /* Store the previous lParam */
2157 *plparam
= MapLS( str
);
2162 MDICREATESTRUCT16
*cs
;
2163 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)*plparam
;
2165 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16
) ))) return -1;
2166 STRUCT32_MDICREATESTRUCT32Ato16( cs32
, cs
);
2167 cs
->szTitle
= MapLS( cs32
->szTitle
);
2168 cs
->szClass
= MapLS( cs32
->szClass
);
2169 *plparam
= MapLS( cs
);
2172 case WM_MDIGETACTIVE
:
2175 *plparam
= MAKELPARAM( (HMENU16
)LOWORD(wParam32
),
2176 (HMENU16
)LOWORD(*plparam
) );
2177 *pwparam16
= (*plparam
== 0);
2180 if(HIWORD(wParam32
) & MF_POPUP
)
2183 if (((UINT
)HIWORD(wParam32
) != 0xFFFF) || (*plparam
))
2185 if((hmenu
= GetSubMenu((HMENU
)*plparam
, *pwparam16
)))
2186 *pwparam16
=HMENU_16(hmenu
);
2191 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
2193 case WM_MDIACTIVATE
:
2194 if (GetWindowLongA( hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
2196 *pwparam16
= ((HWND
)*plparam
== hwnd
);
2197 *plparam
= MAKELPARAM( (HWND16
)LOWORD(*plparam
),
2198 (HWND16
)LOWORD(wParam32
) );
2202 *pwparam16
= HWND_16( (HWND
)wParam32
);
2208 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)*plparam
;
2209 NCCALCSIZE_PARAMS16
*nc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*nc
) + sizeof(LPARAM
));
2212 CONV_RECT32TO16( &nc32
->rgrc
[0], &nc
->rgrc
[0] );
2216 CONV_RECT32TO16( &nc32
->rgrc
[1], &nc
->rgrc
[1] );
2217 CONV_RECT32TO16( &nc32
->rgrc
[2], &nc
->rgrc
[2] );
2218 if (!(wp
= HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16
) )))
2220 HeapFree( GetProcessHeap(), 0, nc
);
2223 STRUCT32_WINDOWPOS32to16( nc32
->lppos
, wp
);
2224 nc
->lppos
= MapLS( wp
);
2226 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
2227 *plparam
= MapLS( nc
);
2234 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)*plparam
;
2236 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16
) ))) return -1;
2237 STRUCT32_CREATESTRUCT32Ato16( cs32
, cs
);
2238 cs
->lpszName
= MapLS( cs32
->lpszName
);
2239 cs
->lpszClass
= MapLS( cs32
->lpszClass
);
2240 *plparam
= MapLS( cs
);
2243 case WM_PARENTNOTIFY
:
2244 if ((LOWORD(wParam32
)==WM_CREATE
) || (LOWORD(wParam32
)==WM_DESTROY
))
2245 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
));
2246 /* else nothing to do */
2249 *plparam
= MapLS( (NMHDR
*)*plparam
); /* NMHDR is already 32-bit */
2252 case WM_WININICHANGE
:
2253 case WM_DEVMODECHANGE
:
2254 *plparam
= MapLS( (LPSTR
)*plparam
);
2256 case WM_WINDOWPOSCHANGING
:
2257 case WM_WINDOWPOSCHANGED
:
2259 WINDOWPOS16
*wp
= HeapAlloc( GetProcessHeap(), 0, sizeof(*wp
) + sizeof(LPARAM
) );
2261 STRUCT32_WINDOWPOS32to16( (WINDOWPOS
*)*plparam
, wp
);
2262 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
2263 *plparam
= MapLS( wp
);
2268 LPMSG msg32
= (LPMSG
) *plparam
;
2269 LPMSG16 msg16
= HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16
) );
2271 if (!msg16
) return -1;
2272 msg16
->hwnd
= HWND_16( msg32
->hwnd
);
2273 msg16
->lParam
= msg32
->lParam
;
2274 msg16
->time
= msg32
->time
;
2275 CONV_POINT32TO16(&msg32
->pt
,&msg16
->pt
);
2276 /* this is right, right? */
2277 if (WINPROC_MapMsg32ATo16(msg32
->hwnd
,msg32
->message
,msg32
->wParam
,
2278 &msg16
->message
,&msg16
->wParam
, &msg16
->lParam
)<0)
2280 HeapFree( GetProcessHeap(), 0, msg16
);
2283 *plparam
= MapLS( msg16
);
2288 case WM_ACTIVATEAPP
:
2289 if (*plparam
) *plparam
= HTASK_16( (HANDLE
)*plparam
);
2293 MDINEXTMENU
*next
= (MDINEXTMENU
*)*plparam
;
2294 *plparam
= (LPARAM
)next
->hmenuIn
;
2297 case WM_PAINTCLIPBOARD
:
2298 case WM_SIZECLIPBOARD
:
2299 FIXME_(msg
)("message %04x needs translation\n", msg32
);
2301 /* following messages should not be sent to 16-bit apps */
2304 case WM_CAPTURECHANGED
:
2305 case WM_STYLECHANGING
:
2306 case WM_STYLECHANGED
:
2308 case WM_DDE_INITIATE
:
2309 case WM_DDE_TERMINATE
:
2310 case WM_DDE_UNADVISE
:
2311 case WM_DDE_REQUEST
:
2312 *pwparam16
= HWND_16((HWND
)wParam32
);
2321 *pwparam16
= HWND_16((HWND
)wParam32
);
2322 UnpackDDElParam(msg32
, *plparam
, &lo32
, &hi
);
2323 if (lo32
&& !(lo16
= convert_handle_32_to_16(lo32
, GMEM_DDESHARE
)))
2325 *plparam
= MAKELPARAM(lo16
, hi
);
2327 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2334 *pwparam16
= HWND_16((HWND
)wParam32
);
2336 UnpackDDElParam(msg32
, *plparam
, &lo
, &hi
);
2338 if (GlobalGetAtomNameA((ATOM
)hi
, buf
, sizeof(buf
)) > 0) flag
|= 1;
2339 if (GlobalSize((HANDLE
)hi
) != 0) flag
|= 2;
2345 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2350 break; /* atom, nothing to do */
2352 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
2355 hi
= convert_handle_32_to_16(hi
, GMEM_DDESHARE
);
2358 *plparam
= MAKELPARAM(lo
, hi
);
2360 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2361 case WM_DDE_EXECUTE
:
2362 *plparam
= convert_handle_32_to_16(*plparam
, GMEM_DDESHARE
);
2363 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2364 default: /* No translation needed */
2370 /**********************************************************************
2371 * WINPROC_UnmapMsg32ATo16
2373 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2375 void WINPROC_UnmapMsg32ATo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2384 case LB_FINDSTRINGEXACT
:
2385 case LB_INSERTSTRING
:
2386 case LB_SELECTSTRING
:
2390 case CB_FINDSTRINGEXACT
:
2391 case CB_INSERTSTRING
:
2392 case CB_SELECTSTRING
:
2396 case WM_WININICHANGE
:
2397 case WM_DEVMODECHANGE
:
2398 UnMapLS( (SEGPTR
)p16
->lParam
);
2400 case LB_SETTABSTOPS
:
2401 case WM_COMPAREITEM
:
2405 void *ptr
= MapSL( p16
->lParam
);
2406 UnMapLS( p16
->lParam
);
2407 HeapFree( GetProcessHeap(), 0, ptr
);
2410 case CB_GETDROPPEDCONTROLRECT
:
2411 case LB_GETITEMRECT
:
2413 RECT16
*rect
= MapSL(p16
->lParam
);
2414 UnMapLS( p16
->lParam
);
2415 p16
->lParam
= *(LPARAM
*)(rect
+ 1);
2416 CONV_RECT16TO32( rect
, (RECT
*)(p16
->lParam
));
2417 HeapFree( GetProcessHeap(), 0, rect
);
2420 case LB_GETSELITEMS
:
2423 LPINT16 items
= MapSL(p16
->lParam
);
2424 UnMapLS( p16
->lParam
);
2425 p16
->lParam
= *((LPARAM
*)items
- 1);
2426 for (i
= 0; i
< p16
->wParam
; i
++) *((LPINT
)(p16
->lParam
) + i
) = items
[i
];
2427 HeapFree( GetProcessHeap(), 0, (LPARAM
*)items
- 1 );
2433 *((PUINT
)(wParam
)) = LOWORD(p16
->lResult
);
2435 *((PUINT
)(lParam
)) = HIWORD(p16
->lResult
); /* FIXME: substract 1? */
2438 case WM_MEASUREITEM
:
2440 MEASUREITEMSTRUCT16
*mis
= MapSL(p16
->lParam
);
2441 MEASUREITEMSTRUCT
*mis32
= *(MEASUREITEMSTRUCT
**)(mis
+ 1);
2442 mis32
->itemWidth
= mis
->itemWidth
;
2443 mis32
->itemHeight
= mis
->itemHeight
;
2444 UnMapLS( p16
->lParam
);
2445 HeapFree( GetProcessHeap(), 0, mis
);
2448 case WM_GETMINMAXINFO
:
2450 MINMAXINFO16
*mmi
= MapSL(p16
->lParam
);
2451 UnMapLS( p16
->lParam
);
2452 p16
->lParam
= *(LPARAM
*)(mmi
+ 1);
2453 STRUCT32_MINMAXINFO16to32( mmi
, (MINMAXINFO
*)(p16
->lParam
) );
2454 HeapFree( GetProcessHeap(), 0, mmi
);
2458 case WM_ASKCBFORMATNAME
:
2460 LPSTR str
= MapSL(p16
->lParam
);
2461 UnMapLS( p16
->lParam
);
2462 p16
->lParam
= *((LPARAM
*)str
- 1);
2463 lstrcpynA( (LPSTR
)(p16
->lParam
), str
, p16
->wParam
);
2464 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
- 1 );
2469 MDICREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2470 UnMapLS( cs
->szTitle
);
2471 UnMapLS( cs
->szClass
);
2472 UnMapLS( p16
->lParam
);
2473 HeapFree( GetProcessHeap(), 0, cs
);
2476 case WM_MDIGETACTIVE
:
2477 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(p16
->lResult
);
2478 p16
->lResult
= (LRESULT
)WIN_Handle32( LOWORD(p16
->lResult
) );
2482 NCCALCSIZE_PARAMS
*nc32
;
2483 NCCALCSIZE_PARAMS16
*nc
= MapSL(p16
->lParam
);
2484 UnMapLS( p16
->lParam
);
2485 p16
->lParam
= *(LPARAM
*)(nc
+ 1);
2486 nc32
= (NCCALCSIZE_PARAMS
*)(p16
->lParam
);
2487 CONV_RECT16TO32( &nc
->rgrc
[0], &nc32
->rgrc
[0] );
2490 WINDOWPOS16
*pos
= MapSL(nc
->lppos
);
2491 UnMapLS( nc
->lppos
);
2492 CONV_RECT16TO32( &nc
->rgrc
[1], &nc32
->rgrc
[1] );
2493 CONV_RECT16TO32( &nc
->rgrc
[2], &nc32
->rgrc
[2] );
2494 STRUCT32_WINDOWPOS16to32( pos
, nc32
->lppos
);
2495 HeapFree( GetProcessHeap(), 0, pos
);
2497 HeapFree( GetProcessHeap(), 0, nc
);
2503 CREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2504 UnMapLS( p16
->lParam
);
2505 UnMapLS( cs
->lpszName
);
2506 UnMapLS( cs
->lpszClass
);
2507 HeapFree( GetProcessHeap(), 0, cs
);
2510 case WM_WINDOWPOSCHANGING
:
2511 case WM_WINDOWPOSCHANGED
:
2513 WINDOWPOS16
*wp
= MapSL(p16
->lParam
);
2514 UnMapLS( p16
->lParam
);
2515 p16
->lParam
= *(LPARAM
*)(wp
+ 1);
2516 STRUCT32_WINDOWPOS16to32( wp
, (WINDOWPOS
*)p16
->lParam
);
2517 HeapFree( GetProcessHeap(), 0, wp
);
2521 UnMapLS(p16
->lParam
);
2526 LPMSG16 msg16
= MapSL(p16
->lParam
);
2528 UnMapLS( p16
->lParam
);
2529 msgp16
.wParam
=msg16
->wParam
;
2530 msgp16
.lParam
=msg16
->lParam
;
2531 WINPROC_UnmapMsg32ATo16(((LPMSG
)lParam
)->hwnd
, ((LPMSG
)lParam
)->message
,
2532 ((LPMSG
)lParam
)->wParam
, ((LPMSG
)lParam
)->lParam
,
2534 HeapFree( GetProcessHeap(), 0, msg16
);
2539 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
2540 next
->hmenuNext
= HMENU_32( LOWORD(p16
->lResult
) );
2541 next
->hwndNext
= WIN_Handle32( HIWORD(p16
->lResult
) );
2549 /**********************************************************************
2550 * WINPROC_MapMsg32WTo16
2552 * Map a message from 32-bit Unicode to 16-bit.
2553 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2555 INT
WINPROC_MapMsg32WTo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
2556 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
2562 *pmsg16
= LOWORD(msg32
);
2563 *pwparam16
= LOWORD(wParam32
);
2568 case LB_FINDSTRINGEXACT
:
2569 case LB_INSERTSTRING
:
2570 case LB_SELECTSTRING
:
2573 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2574 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
2579 case CB_FINDSTRINGEXACT
:
2580 case CB_INSERTSTRING
:
2581 case CB_SELECTSTRING
:
2583 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2584 *pmsg16
= (UINT16
)msg32
+ (CB_ADDSTRING16
- CB_ADDSTRING
);
2591 CREATESTRUCTW
*cs32
= (CREATESTRUCTW
*)*plparam
;
2593 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16
) ))) return -1;
2594 STRUCT32_CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs32
, cs
);
2595 cs
->lpszName
= map_str_32W_to_16( cs32
->lpszName
);
2596 cs
->lpszClass
= map_str_32W_to_16( cs32
->lpszClass
);
2597 *plparam
= MapLS(cs
);
2602 MDICREATESTRUCT16
*cs
;
2603 MDICREATESTRUCTW
*cs32
= (MDICREATESTRUCTW
*)*plparam
;
2605 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16
) ))) return -1;
2606 STRUCT32_MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs32
, cs
);
2607 cs
->szTitle
= map_str_32W_to_16( cs32
->szTitle
);
2608 cs
->szClass
= map_str_32W_to_16( cs32
->szClass
);
2609 *plparam
= MapLS(cs
);
2613 case WM_WININICHANGE
:
2614 case WM_DEVMODECHANGE
:
2615 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2618 if ( WINPROC_TestLBForStr( hwnd
))
2620 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2621 if (!str
) return -1;
2622 *pmsg16
= LB_GETTEXT16
;
2623 *plparam
= (LPARAM
)MapLS(str
);
2627 if ( WINPROC_TestCBForStr( hwnd
))
2629 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, 256 ); /* FIXME: fixed sized buffer */
2630 if (!str
) return -1;
2631 *pmsg16
= CB_GETLBTEXT16
;
2632 *plparam
= (LPARAM
)MapLS(str
);
2637 wch
= LOWORD(wParam32
);
2638 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
2640 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
2643 wch
= LOWORD(wParam32
);
2644 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
2646 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
2651 case WM_SYSDEADCHAR
:
2653 WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, &ch
, 1, NULL
, NULL
);
2661 if (WideCharToMultiByte( CP_ACP
, 0, &wch
, 1, ch
, 2, NULL
, NULL
) == 2)
2662 *pwparam16
= (ch
[0] << 8) | ch
[1];
2668 default: /* No Unicode translation needed (?) */
2669 return WINPROC_MapMsg32ATo16( hwnd
, msg32
, wParam32
, pmsg16
,
2670 pwparam16
, plparam
);
2675 /**********************************************************************
2676 * WINPROC_UnmapMsg32WTo16
2678 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2680 void WINPROC_UnmapMsg32WTo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2687 case LB_FINDSTRINGEXACT
:
2688 case LB_INSERTSTRING
:
2689 case LB_SELECTSTRING
:
2694 case CB_FINDSTRINGEXACT
:
2695 case CB_INSERTSTRING
:
2696 case CB_SELECTSTRING
:
2699 case WM_WININICHANGE
:
2700 case WM_DEVMODECHANGE
:
2701 unmap_str_32W_to_16( p16
->lParam
);
2706 CREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2707 UnMapLS( p16
->lParam
);
2708 unmap_str_32W_to_16( cs
->lpszName
);
2709 unmap_str_32W_to_16( cs
->lpszClass
);
2710 HeapFree( GetProcessHeap(), 0, cs
);
2715 MDICREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2716 UnMapLS( p16
->lParam
);
2717 unmap_str_32W_to_16( cs
->szTitle
);
2718 unmap_str_32W_to_16( cs
->szClass
);
2719 HeapFree( GetProcessHeap(), 0, cs
);
2723 case WM_ASKCBFORMATNAME
:
2725 LPSTR str
= MapSL(p16
->lParam
);
2726 UnMapLS( p16
->lParam
);
2727 p16
->lParam
= *((LPARAM
*)str
- 1);
2728 MultiByteToWideChar( CP_ACP
, 0, str
, -1, (LPWSTR
)p16
->lParam
, 0x7fffffff );
2729 p16
->lResult
= strlenW( (LPWSTR
)p16
->lParam
);
2730 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
- 1 );
2734 if ( WINPROC_TestLBForStr( hwnd
))
2736 LPSTR str
= MapSL(p16
->lParam
);
2737 UnMapLS( p16
->lParam
);
2738 p16
->lResult
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, (LPWSTR
)lParam
, 0x7fffffff ) - 1;
2739 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
);
2743 if ( WINPROC_TestCBForStr( hwnd
))
2745 LPSTR str
= MapSL(p16
->lParam
);
2746 UnMapLS( p16
->lParam
);
2747 p16
->lResult
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, (LPWSTR
)lParam
, 0x7fffffff ) - 1;
2748 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
);
2752 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, p16
);
2758 /**********************************************************************
2759 * WINPROC_CallProc32ATo32W
2761 * Call a window procedure, translating args from Ansi to Unicode.
2763 static LRESULT
WINPROC_CallProc32ATo32W( WNDPROC func
, HWND hwnd
,
2764 UINT msg
, WPARAM wParam
,
2770 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2771 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2773 if( (unmap
= WINPROC_MapMsg32ATo32W( hwnd
, msg
, &wParam
, &lParam
)) == -1) {
2774 ERR_(msg
)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2775 SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2778 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2779 if (unmap
) result
= WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
, result
);
2784 /**********************************************************************
2785 * WINPROC_CallProc32WTo32A
2787 * Call a window procedure, translating args from Unicode to Ansi.
2789 static LRESULT
WINPROC_CallProc32WTo32A( WNDPROC func
, HWND hwnd
,
2790 UINT msg
, WPARAM wParam
,
2796 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2797 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2799 if ((unmap
= WINPROC_MapMsg32WTo32A( hwnd
, msg
, &wParam
, &lParam
)) == -1) {
2800 ERR_(msg
)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2801 SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2804 result
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2805 if( unmap
) result
= WINPROC_UnmapMsg32WTo32A( hwnd
, msg
, wParam
, lParam
, result
);
2810 /**********************************************************************
2811 * __wine_call_wndproc_32A (USER.1010)
2813 LRESULT WINAPI
__wine_call_wndproc_32A( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
2819 HWND hwnd32
= WIN_Handle32( hwnd
);
2821 if (WINPROC_MapMsg16To32A( hwnd32
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2823 result
= WINPROC_CallWndProc( func
, hwnd32
, msg32
, wParam32
, lParam
);
2824 return WINPROC_UnmapMsg16To32A( hwnd32
, msg32
, wParam32
, lParam
, result
);
2828 /**********************************************************************
2829 * __wine_call_wndproc_32W (USER.1011)
2831 LRESULT WINAPI
__wine_call_wndproc_32W( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
2837 HWND hwnd32
= WIN_Handle32( hwnd
);
2839 if (WINPROC_MapMsg16To32W( hwnd32
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2841 result
= WINPROC_CallWndProc( func
, hwnd32
, msg32
, wParam32
, lParam
);
2842 return WINPROC_UnmapMsg16To32W( hwnd32
, msg32
, wParam32
, lParam
, result
);
2846 /**********************************************************************
2847 * WINPROC_CallProc32ATo16
2849 * Call a 16-bit window procedure, translating the 32-bit args.
2851 static LRESULT WINAPI
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
,
2852 UINT msg
, WPARAM wParam
,
2858 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2859 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2861 mp16
.lParam
= lParam
;
2862 if (WINPROC_MapMsg32ATo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
, &mp16
.lParam
) == -1)
2864 mp16
.lResult
= WINPROC_CallWndProc16( func
, HWND_16(hwnd
), msg16
,
2865 mp16
.wParam
, mp16
.lParam
);
2866 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2867 return mp16
.lResult
;
2871 /**********************************************************************
2872 * WINPROC_CallProc32WTo16
2874 * Call a 16-bit window procedure, translating the 32-bit args.
2876 static LRESULT WINAPI
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
,
2877 UINT msg
, WPARAM wParam
,
2883 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2884 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2886 mp16
.lParam
= lParam
;
2887 if (WINPROC_MapMsg32WTo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
,
2888 &mp16
.lParam
) == -1)
2890 mp16
.lResult
= WINPROC_CallWndProc16( func
, HWND_16(hwnd
), msg16
,
2891 mp16
.wParam
, mp16
.lParam
);
2892 WINPROC_UnmapMsg32WTo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2893 return mp16
.lResult
;
2897 /**********************************************************************
2898 * CallWindowProc (USER.122)
2900 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2901 WPARAM16 wParam
, LPARAM lParam
)
2905 if (!func
) return 0;
2907 if (!(proc
= WINPROC_GetPtr( (WNDPROC
)func
)))
2908 return WINPROC_CallWndProc16( func
, hwnd
, msg
, wParam
, lParam
);
2911 func
= WINPROC_GetProc( (WNDPROC
)proc
, WIN_PROC_16
);
2912 return WINPROC_CallWndProc16( func
, hwnd
, msg
, wParam
, lParam
);
2918 if (!proc
->thunk
.t_from32
.proc
) return 0;
2919 return WINPROC_CallWndProc16( proc
->thunk
.t_from32
.proc
,
2920 hwnd
, msg
, wParam
, lParam
);
2922 if (!proc
->thunk
.t_from16
.proc
) return 0;
2923 return __wine_call_wndproc_32A( hwnd
, msg
, wParam
, lParam
, proc
->thunk
.t_from16
.proc
);
2925 if (!proc
->thunk
.t_from16
.proc
) return 0;
2926 return __wine_call_wndproc_32W( hwnd
, msg
, wParam
, lParam
, proc
->thunk
.t_from16
.proc
);
2928 WARN_(relay
)("Invalid proc %p\n", proc
);
2934 /**********************************************************************
2935 * CallWindowProcA (USER32.@)
2937 * The CallWindowProc() function invokes the windows procedure _func_,
2938 * with _hwnd_ as the target window, the message specified by _msg_, and
2939 * the message parameters _wParam_ and _lParam_.
2941 * Some kinds of argument conversion may be done, I'm not sure what.
2943 * CallWindowProc() may be used for windows subclassing. Use
2944 * SetWindowLong() to set a new windows procedure for windows of the
2945 * subclass, and handle subclassed messages in the new windows
2946 * procedure. The new windows procedure may then use CallWindowProc()
2947 * with _func_ set to the parent class's windows procedure to dispatch
2948 * the message to the superclass.
2952 * The return value is message dependent.
2958 LRESULT WINAPI
CallWindowProcA(
2959 WNDPROC func
, /* [in] window procedure */
2960 HWND hwnd
, /* [in] target window */
2961 UINT msg
, /* [in] message */
2962 WPARAM wParam
, /* [in] message dependent parameter */
2963 LPARAM lParam
/* [in] message dependent parameter */
2967 if (!func
) return 0;
2969 if (!(proc
= WINPROC_GetPtr( func
)))
2970 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2973 func
= WINPROC_GetProc( (WNDPROC
)proc
, WIN_PROC_32A
);
2974 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2980 if (!proc
->thunk
.t_from32
.proc
) return 0;
2981 return WINPROC_CallProc32ATo16( proc
->thunk
.t_from32
.proc
,
2982 hwnd
, msg
, wParam
, lParam
);
2984 if (!proc
->thunk
.t_from16
.proc
) return 0;
2985 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
2986 hwnd
, msg
, wParam
, lParam
);
2988 if (!proc
->thunk
.t_from16
.proc
) return 0;
2989 return WINPROC_CallProc32ATo32W( proc
->thunk
.t_from16
.proc
,
2990 hwnd
, msg
, wParam
, lParam
);
2992 WARN_(relay
)("Invalid proc %p\n", proc
);
2998 /**********************************************************************
2999 * CallWindowProcW (USER32.@)
3001 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
3002 WPARAM wParam
, LPARAM lParam
)
3006 if (!func
) return 0;
3008 if (!(proc
= WINPROC_GetPtr( (WNDPROC
)func
)))
3009 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
3012 func
= WINPROC_GetProc( (WNDPROC
)proc
, WIN_PROC_32W
);
3013 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
3019 if (!proc
->thunk
.t_from32
.proc
) return 0;
3020 return WINPROC_CallProc32WTo16( proc
->thunk
.t_from32
.proc
,
3021 hwnd
, msg
, wParam
, lParam
);
3023 if (!proc
->thunk
.t_from16
.proc
) return 0;
3024 return WINPROC_CallProc32WTo32A( proc
->thunk
.t_from16
.proc
,
3025 hwnd
, msg
, wParam
, lParam
);
3027 if (!proc
->thunk
.t_from16
.proc
) return 0;
3028 return WINPROC_CallWndProc( proc
->thunk
.t_from16
.proc
,
3029 hwnd
, msg
, wParam
, lParam
);
3031 WARN_(relay
)("Invalid proc %p\n", proc
);