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"
33 #include "wine/winbase16.h"
34 #include "wine/winuser16.h"
38 #include "user_private.h"
41 #include "wine/unicode.h"
42 #include "wine/debug.h"
44 WINE_DECLARE_DEBUG_CHANNEL(msg
);
45 WINE_DECLARE_DEBUG_CHANNEL(relay
);
46 WINE_DEFAULT_DEBUG_CHANNEL(win
);
48 typedef struct tagWINDOWPROC
50 WNDPROC16 proc16
; /* 16-bit window proc */
51 WNDPROC procA
; /* ASCII window proc */
52 WNDPROC procW
; /* Unicode window proc */
55 #define WINPROC_HANDLE (~0UL >> 16)
56 #define MAX_WINPROCS 8192
58 static WINDOWPROC winproc_array
[MAX_WINPROCS
];
59 static UINT winproc_used
;
61 static CRITICAL_SECTION winproc_cs
;
62 static CRITICAL_SECTION_DEBUG critsect_debug
=
65 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
66 0, 0, { (DWORD_PTR
)(__FILE__
": winproc_cs") }
68 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
70 /* find an existing winproc for a given 16-bit function and type */
71 /* FIXME: probably should do something more clever than a linear search */
72 static inline WINDOWPROC
*find_winproc16( WNDPROC16 func
)
76 for (i
= 0; i
< winproc_used
; i
++)
78 if (winproc_array
[i
].proc16
== func
) return &winproc_array
[i
];
83 /* find an existing winproc for a given function and type */
84 /* FIXME: probably should do something more clever than a linear search */
85 static inline WINDOWPROC
*find_winproc( WNDPROC funcA
, WNDPROC funcW
)
89 for (i
= 0; i
< winproc_used
; i
++)
91 if (funcA
&& winproc_array
[i
].procA
!= funcA
) continue;
92 if (funcW
&& winproc_array
[i
].procW
!= funcW
) continue;
93 return &winproc_array
[i
];
98 /* return the window proc for a given handle, or NULL for an invalid handle */
99 static inline WINDOWPROC
*handle_to_proc( WNDPROC handle
)
101 UINT index
= LOWORD(handle
);
102 if ((ULONG_PTR
)handle
>> 16 != WINPROC_HANDLE
) return NULL
;
103 if (index
>= winproc_used
) return NULL
;
104 return &winproc_array
[index
];
107 /* create a handle for a given window proc */
108 static inline WNDPROC
proc_to_handle( WINDOWPROC
*proc
)
110 return (WNDPROC
)(ULONG_PTR
)((proc
- winproc_array
) | (WINPROC_HANDLE
<< 16));
113 /* allocate and initialize a new winproc */
114 static inline WINDOWPROC
*alloc_winproc( WNDPROC funcA
, WNDPROC funcW
)
118 /* check if the function is already a win proc */
119 if (funcA
&& (proc
= handle_to_proc( funcA
))) return proc
;
120 if (funcW
&& (proc
= handle_to_proc( funcW
))) return proc
;
121 if (!funcA
&& !funcW
) return NULL
;
123 EnterCriticalSection( &winproc_cs
);
125 /* check if we already have a winproc for that function */
126 if (!(proc
= find_winproc( funcA
, funcW
)))
128 if (winproc_used
< MAX_WINPROCS
)
130 proc
= &winproc_array
[winproc_used
++];
133 TRACE( "allocated %p for %p/%p (%d/%d used)\n",
134 proc_to_handle(proc
), funcA
, funcW
, winproc_used
, MAX_WINPROCS
);
136 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA
, funcW
);
138 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc
), funcA
, funcW
);
140 LeaveCriticalSection( &winproc_cs
);
147 #include "pshpack1.h"
149 /* Window procedure 16-to-32-bit thunk */
152 BYTE popl_eax
; /* popl %eax (return address) */
153 BYTE pushl_func
; /* pushl $proc */
155 BYTE pushl_eax
; /* pushl %eax */
156 BYTE ljmp
; /* ljmp relay*/
157 DWORD relay_offset
; /* __wine_call_wndproc */
163 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
165 static WINPROC_THUNK
*thunk_array
;
166 static UINT thunk_selector
;
167 static UINT thunk_used
;
169 /* return the window proc for a given handle, or NULL for an invalid handle */
170 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
172 if (HIWORD(handle
) == thunk_selector
)
174 UINT index
= LOWORD(handle
) / sizeof(WINPROC_THUNK
);
175 /* check alignment */
176 if (index
* sizeof(WINPROC_THUNK
) != LOWORD(handle
)) return NULL
;
177 /* check array limits */
178 if (index
>= thunk_used
) return NULL
;
179 return thunk_array
[index
].proc
;
181 return handle_to_proc( (WNDPROC
)handle
);
184 /* allocate a 16-bit thunk for an existing window proc */
185 static WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
187 static FARPROC16 relay
;
190 if (proc
->proc16
) return proc
->proc16
;
192 EnterCriticalSection( &winproc_cs
);
194 if (!thunk_array
) /* allocate the array and its selector */
198 if (!(thunk_selector
= wine_ldt_alloc_entries(1))) goto done
;
199 if (!(thunk_array
= VirtualAlloc( NULL
, MAX_THUNKS
* sizeof(WINPROC_THUNK
), MEM_COMMIT
,
200 PAGE_EXECUTE_READWRITE
))) goto done
;
201 wine_ldt_set_base( &entry
, thunk_array
);
202 wine_ldt_set_limit( &entry
, MAX_THUNKS
* sizeof(WINPROC_THUNK
) - 1 );
203 wine_ldt_set_flags( &entry
, WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
204 wine_ldt_set_entry( thunk_selector
, &entry
);
205 relay
= GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
208 /* check if it already exists */
209 for (i
= 0; i
< thunk_used
; i
++) if (thunk_array
[i
].proc
== proc
) break;
211 if (i
== thunk_used
) /* create a new one */
213 WINPROC_THUNK
*thunk
;
215 if (thunk_used
>= MAX_THUNKS
) goto done
;
216 thunk
= &thunk_array
[thunk_used
++];
217 thunk
->popl_eax
= 0x58; /* popl %eax */
218 thunk
->pushl_func
= 0x68; /* pushl $proc */
220 thunk
->pushl_eax
= 0x50; /* pushl %eax */
221 thunk
->ljmp
= 0xea; /* ljmp relay*/
222 thunk
->relay_offset
= OFFSETOF(relay
);
223 thunk
->relay_sel
= SELECTOROF(relay
);
225 proc
->proc16
= (WNDPROC16
)MAKESEGPTR( thunk_selector
, i
* sizeof(WINPROC_THUNK
) );
227 LeaveCriticalSection( &winproc_cs
);
233 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
235 return handle_to_proc( (WNDPROC
)handle
);
238 static inline WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
243 #endif /* __i386__ */
247 /* Some window procedures modify register they shouldn't, or are not
248 * properly declared stdcall; so we need a small assembly wrapper to
250 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
251 WPARAM wParam
, LPARAM lParam
);
252 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
263 "movl 8(%ebp),%eax\n\t"
265 "leal -12(%ebp),%esp\n\t"
272 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
273 WPARAM wParam
, LPARAM lParam
)
275 return proc( hwnd
, msg
, wParam
, lParam
);
277 #endif /* __i386__ */
280 static void MINMAXINFO32to16( const MINMAXINFO
*from
, MINMAXINFO16
*to
)
282 to
->ptReserved
.x
= from
->ptReserved
.x
;
283 to
->ptReserved
.y
= from
->ptReserved
.y
;
284 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
285 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
286 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
287 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
288 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
289 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
290 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
291 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
294 static void MINMAXINFO16to32( const MINMAXINFO16
*from
, MINMAXINFO
*to
)
296 to
->ptReserved
.x
= from
->ptReserved
.x
;
297 to
->ptReserved
.y
= from
->ptReserved
.y
;
298 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
299 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
300 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
301 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
302 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
303 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
304 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
305 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
308 static void WINDOWPOS32to16( const WINDOWPOS
* from
, WINDOWPOS16
* to
)
310 to
->hwnd
= HWND_16(from
->hwnd
);
311 to
->hwndInsertAfter
= HWND_16(from
->hwndInsertAfter
);
316 to
->flags
= from
->flags
;
319 static void WINDOWPOS16to32( const WINDOWPOS16
* from
, WINDOWPOS
* to
)
321 to
->hwnd
= WIN_Handle32(from
->hwnd
);
322 to
->hwndInsertAfter
= (from
->hwndInsertAfter
== (HWND16
)-1) ?
323 HWND_TOPMOST
: WIN_Handle32(from
->hwndInsertAfter
);
328 to
->flags
= from
->flags
;
331 /* The strings are not copied */
332 static void CREATESTRUCT32Ato16( const CREATESTRUCTA
* from
, CREATESTRUCT16
* to
)
334 to
->lpCreateParams
= (SEGPTR
)from
->lpCreateParams
;
335 to
->hInstance
= HINSTANCE_16(from
->hInstance
);
336 to
->hMenu
= HMENU_16(from
->hMenu
);
337 to
->hwndParent
= HWND_16(from
->hwndParent
);
342 to
->style
= from
->style
;
343 to
->dwExStyle
= from
->dwExStyle
;
346 static void CREATESTRUCT16to32A( const CREATESTRUCT16
* from
, CREATESTRUCTA
*to
)
349 to
->lpCreateParams
= (LPVOID
)from
->lpCreateParams
;
350 to
->hInstance
= HINSTANCE_32(from
->hInstance
);
351 to
->hMenu
= HMENU_32(from
->hMenu
);
352 to
->hwndParent
= WIN_Handle32(from
->hwndParent
);
357 to
->style
= from
->style
;
358 to
->dwExStyle
= from
->dwExStyle
;
361 /* The strings are not copied */
362 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA
* from
, MDICREATESTRUCT16
* to
)
364 to
->hOwner
= HINSTANCE_16(from
->hOwner
);
369 to
->style
= from
->style
;
370 to
->lParam
= from
->lParam
;
373 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16
* from
, MDICREATESTRUCTA
*to
)
375 to
->hOwner
= HINSTANCE_32(from
->hOwner
);
380 to
->style
= from
->style
;
381 to
->lParam
= from
->lParam
;
384 static WPARAM
map_wparam_char_AtoW( WPARAM wParam
, DWORD len
)
389 ch
[0] = (wParam
>> 8);
390 ch
[1] = wParam
& 0xff;
391 if (len
> 1 && ch
[0])
392 RtlMultiByteToUnicodeN( &wch
, sizeof(wch
), NULL
, ch
, 2 );
394 RtlMultiByteToUnicodeN( &wch
, sizeof(wch
), NULL
, ch
+ 1, 1 );
395 return MAKEWPARAM( wch
, HIWORD(wParam
) );
398 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
403 RtlUnicodeToMultiByteN( (LPSTR
)ch
, len
, &len
, &wch
, sizeof(wch
) );
405 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
407 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
410 /**********************************************************************
411 * WINPROC_CallWndProc32
413 * Call a 32-bit WndProc.
415 static LRESULT
WINPROC_CallWndProc( WNDPROC proc
, HWND hwnd
, UINT msg
,
416 WPARAM wParam
, LPARAM lParam
)
422 hwnd
= WIN_GetFullHandle( hwnd
);
424 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
425 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
427 retvalue
= WINPROC_wrapper( proc
, hwnd
, msg
, wParam
, lParam
);
430 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
431 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
, retvalue
);
435 /***********************************************************************
436 * WINPROC_CallWndProc16
438 * Call a 16-bit window procedure
440 static LRESULT WINAPI
WINPROC_CallWndProc16( WNDPROC16 proc
, HWND16 hwnd
,
441 UINT16 msg
, WPARAM16 wParam
,
452 DRAWITEMSTRUCT16 dis16
;
453 COMPAREITEMSTRUCT16 cis16
;
459 /* Window procedures want ax = hInstance, ds = es = ss */
461 memset(&context
, 0, sizeof(context
));
462 context
.SegDs
= context
.SegEs
= SELECTOROF(NtCurrentTeb()->WOW32Reserved
);
463 context
.SegFs
= wine_get_fs();
464 context
.SegGs
= wine_get_gs();
465 if (!(context
.Eax
= GetWindowWord( HWND_32(hwnd
), GWLP_HINSTANCE
))) context
.Eax
= context
.SegDs
;
466 context
.SegCs
= SELECTOROF(proc
);
467 context
.Eip
= OFFSETOF(proc
);
468 context
.Ebp
= OFFSETOF(NtCurrentTeb()->WOW32Reserved
) + (WORD
)&((STACK16FRAME
*)0)->bp
;
472 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
473 work if structures passed in lParam are placed in the stack/data
474 segment. Programmers easily make the mistake of converting lParam
475 to a near rather than a far pointer, since Windows apparently
476 allows this. We copy the structures to the 16 bit stack; this is
477 ugly but makes these programs work. */
482 size
= sizeof(CREATESTRUCT16
); break;
484 size
= sizeof(DRAWITEMSTRUCT16
); break;
486 size
= sizeof(COMPAREITEMSTRUCT16
); break;
490 memcpy( &args
.u
, MapSL(lParam
), size
);
491 lParam
= (SEGPTR
)NtCurrentTeb()->WOW32Reserved
- size
;
495 args
.params
[4] = hwnd
;
496 args
.params
[3] = msg
;
497 args
.params
[2] = wParam
;
498 args
.params
[1] = HIWORD(lParam
);
499 args
.params
[0] = LOWORD(lParam
);
500 WOWCallback16Ex( 0, WCB16_REGS
, sizeof(args
.params
) + size
, &args
, (DWORD
*)&context
);
501 return MAKELONG( LOWORD(context
.Eax
), LOWORD(context
.Edx
) );
505 /**********************************************************************
508 * Get a window procedure pointer that can be passed to the Windows program.
510 WNDPROC16
WINPROC_GetProc16( WNDPROC proc
, BOOL unicode
)
514 if (unicode
) ptr
= alloc_winproc( NULL
, proc
);
515 else ptr
= alloc_winproc( proc
, NULL
);
518 return alloc_win16_thunk( ptr
);
522 /**********************************************************************
525 * Get a window procedure pointer that can be passed to the Windows program.
527 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
529 WINDOWPROC
*ptr
= handle_to_proc( proc
);
531 if (!ptr
) return proc
;
534 if (ptr
->procW
) return ptr
->procW
;
539 if (ptr
->procA
) return ptr
->procA
;
545 /**********************************************************************
546 * WINPROC_AllocProc16
548 * Allocate a window procedure for a window or class.
550 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
551 * lot of windows, it will usually only have a limited number of window procedures, so the
552 * array won't grow too large, and this way we avoid the need to track allocations per window.
554 WNDPROC
WINPROC_AllocProc16( WNDPROC16 func
)
558 if (!func
) return NULL
;
560 /* check if the function is already a win proc */
561 if (!(proc
= handle16_to_proc( func
)))
563 EnterCriticalSection( &winproc_cs
);
565 /* then check if we already have a winproc for that function */
566 if (!(proc
= find_winproc16( func
)))
568 if (winproc_used
< MAX_WINPROCS
)
570 proc
= &winproc_array
[winproc_used
++];
572 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
573 proc_to_handle(proc
), func
, winproc_used
, MAX_WINPROCS
);
575 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func
);
577 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc
), func
);
579 LeaveCriticalSection( &winproc_cs
);
581 return proc_to_handle( proc
);
585 /**********************************************************************
588 * Allocate a window procedure for a window or class.
590 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
591 * lot of windows, it will usually only have a limited number of window procedures, so the
592 * array won't grow too large, and this way we avoid the need to track allocations per window.
594 WNDPROC
WINPROC_AllocProc( WNDPROC funcA
, WNDPROC funcW
)
598 if (!(proc
= alloc_winproc( funcA
, funcW
))) return NULL
;
599 return proc_to_handle( proc
);
603 /**********************************************************************
606 * Return the window procedure type, or the default value if not a winproc handle.
608 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
610 WINDOWPROC
*ptr
= handle_to_proc( proc
);
612 if (!ptr
) return def_val
;
613 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
614 return (ptr
->procW
!= NULL
);
618 /**********************************************************************
619 * WINPROC_TestLBForStr
621 * Return TRUE if the lparam is a string
623 inline static BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
625 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
626 if (msg
<= CB_MSGMAX
)
627 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
629 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
632 /**********************************************************************
633 * WINPROC_MapMsg32ATo32W
635 * Map a message from Ansi to Unicode.
636 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
639 * WM_GETTEXT/WM_SETTEXT and static control with SS_ICON style:
640 * the first four bytes are the handle of the icon
641 * when the WM_SETTEXT message has been used to set the icon
643 INT
WINPROC_MapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM
*pwparam
, LPARAM
*plparam
)
648 case WM_ASKCBFORMATNAME
:
650 LPARAM
*ptr
= HeapAlloc( GetProcessHeap(), 0,
651 *pwparam
* sizeof(WCHAR
) + sizeof(LPARAM
) );
653 *ptr
++ = *plparam
; /* Store previous lParam */
654 *plparam
= (LPARAM
)ptr
;
657 /* lparam is string (0-terminated) */
659 case WM_WININICHANGE
:
660 case WM_DEVMODECHANGE
:
665 if (!*plparam
) return 0;
668 DWORD len
= MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*plparam
, -1, NULL
, 0);
669 WCHAR
*buf
= HeapAlloc(GetProcessHeap(), 0, len
* sizeof(WCHAR
));
670 MultiByteToWideChar(CP_ACP
, 0, (LPCSTR
)*plparam
, -1, buf
, len
);
671 *plparam
= (LPARAM
)buf
;
672 return (*plparam
? 1 : -1);
674 case WM_GETTEXTLENGTH
:
675 case CB_GETLBTEXTLEN
:
677 return 1; /* need to map result */
681 UNICODE_STRING usBuffer
;
683 { CREATESTRUCTW cs
; /* new structure */
684 LPCWSTR lpszName
; /* allocated Name */
685 LPCWSTR lpszClass
; /* allocated Class */
688 struct s
*xs
= HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY
, sizeof(struct s
));
690 xs
->cs
= *(CREATESTRUCTW
*)*plparam
;
691 if (HIWORD(xs
->cs
.lpszName
))
693 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)xs
->cs
.lpszName
);
694 xs
->lpszName
= xs
->cs
.lpszName
= usBuffer
.Buffer
;
696 if (HIWORD(xs
->cs
.lpszClass
))
698 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)xs
->cs
.lpszClass
);
699 xs
->lpszClass
= xs
->cs
.lpszClass
= usBuffer
.Buffer
;
702 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
704 MDICREATESTRUCTW
*mdi_cs
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs
));
705 *mdi_cs
= *(MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
706 if (HIWORD(mdi_cs
->szTitle
))
708 RtlCreateUnicodeStringFromAsciiz(&usBuffer
, (LPCSTR
)mdi_cs
->szTitle
);
709 mdi_cs
->szTitle
= usBuffer
.Buffer
;
711 if (HIWORD(mdi_cs
->szClass
))
713 RtlCreateUnicodeStringFromAsciiz(&usBuffer
, (LPCSTR
)mdi_cs
->szClass
);
714 mdi_cs
->szClass
= usBuffer
.Buffer
;
716 xs
->cs
.lpCreateParams
= mdi_cs
;
719 *plparam
= (LPARAM
)xs
;
724 MDICREATESTRUCTW
*cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) );
726 *cs
= *(MDICREATESTRUCTW
*)*plparam
;
727 if (HIWORD(cs
->szClass
))
729 UNICODE_STRING usBuffer
;
730 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)cs
->szClass
);
731 cs
->szClass
= usBuffer
.Buffer
;
733 if (HIWORD(cs
->szTitle
))
735 UNICODE_STRING usBuffer
;
736 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)cs
->szTitle
);
737 cs
->szTitle
= usBuffer
.Buffer
;
739 *plparam
= (LPARAM
)cs
;
743 /* Listbox / Combobox */
745 case LB_INSERTSTRING
:
747 case LB_FINDSTRINGEXACT
:
748 case LB_SELECTSTRING
:
750 case CB_INSERTSTRING
:
751 case CB_FINDSTRINGEXACT
:
753 case CB_SELECTSTRING
:
754 if(!*plparam
) return 0;
755 if ( WINPROC_TestLBForStr( hwnd
, msg
))
757 UNICODE_STRING usBuffer
;
758 RtlCreateUnicodeStringFromAsciiz(&usBuffer
,(LPCSTR
)*plparam
);
759 *plparam
= (LPARAM
)usBuffer
.Buffer
;
761 return (*plparam
? 1 : -1);
763 case LB_GETTEXT
: /* FIXME: fixed sized buffer */
765 if ( WINPROC_TestLBForStr( hwnd
, msg
))
767 LPARAM
*ptr
= HeapAlloc( GetProcessHeap(), 0, 512 * sizeof(WCHAR
) + sizeof(LPARAM
) );
769 *ptr
++ = *plparam
; /* Store previous lParam */
770 *plparam
= (LPARAM
)ptr
;
776 { WORD len
= (WORD
)*plparam
;
777 LPARAM
*ptr
= HeapAlloc( GetProcessHeap(), 0, sizeof(LPARAM
) + sizeof (WORD
) + len
*sizeof(WCHAR
) );
779 *ptr
++ = *plparam
; /* Store previous lParam */
780 *((WORD
*) ptr
) = len
; /* Store the length */
781 *plparam
= (LPARAM
)ptr
;
791 case EM_SETPASSWORDCHAR
:
792 *pwparam
= map_wparam_char_AtoW( *pwparam
, 1 );
796 *pwparam
= map_wparam_char_AtoW( *pwparam
, 2 );
799 case WM_PAINTCLIPBOARD
:
800 case WM_SIZECLIPBOARD
:
801 FIXME_(msg
)("message %s (0x%x) needs translation, please report\n", SPY_GetMsgName(msg
, hwnd
), msg
);
803 default: /* No translation needed */
809 /**********************************************************************
810 * WINPROC_UnmapMsg32ATo32W
812 * Unmap a message that was mapped from Ansi to Unicode.
814 LRESULT
WINPROC_UnmapMsg32ATo32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
815 LRESULT result
, WNDPROC dispatch
)
820 case WM_ASKCBFORMATNAME
:
822 LPARAM
*ptr
= (LPARAM
*)lParam
- 1;
823 if (!wParam
) result
= 0;
824 else if (!(result
= WideCharToMultiByte( CP_ACP
, 0, (LPWSTR
)lParam
, -1,
825 (LPSTR
)*ptr
, wParam
, NULL
, NULL
)))
827 ((LPSTR
)*ptr
)[wParam
-1] = 0;
830 else result
--; /* do not count terminating null */
831 HeapFree( GetProcessHeap(), 0, ptr
);
834 case WM_GETTEXTLENGTH
:
835 case CB_GETLBTEXTLEN
:
839 /* Determine respective GETTEXT message */
841 (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
842 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
843 /* wParam differs between the messages */
844 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? (WPARAM
)(result
+ 1) : wParam
;
846 WCHAR
* p
= HeapAlloc (GetProcessHeap(), 0, (result
+ 1) * sizeof(WCHAR
));
853 n
= WINPROC_CallWndProc(dispatch
, hwnd
, msgGetText
, wp
, (LPARAM
)p
);
855 n
= SendMessageW (hwnd
, msgGetText
, wp
, (LPARAM
)p
);
857 result
= WideCharToMultiByte( CP_ACP
, 0, p
, n
, NULL
, 0, 0, NULL
);
858 HeapFree (GetProcessHeap(), 0, p
);
866 { CREATESTRUCTW cs
; /* new structure */
867 LPWSTR lpszName
; /* allocated Name */
868 LPWSTR lpszClass
; /* allocated Class */
870 struct s
*xs
= (struct s
*)lParam
;
871 HeapFree( GetProcessHeap(), 0, xs
->lpszName
);
872 HeapFree( GetProcessHeap(), 0, xs
->lpszClass
);
874 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
876 MDICREATESTRUCTW
*mdi_cs
= (MDICREATESTRUCTW
*)xs
->cs
.lpCreateParams
;
877 if (HIWORD(mdi_cs
->szTitle
))
878 HeapFree(GetProcessHeap(), 0, (LPVOID
)mdi_cs
->szTitle
);
879 if (HIWORD(mdi_cs
->szClass
))
880 HeapFree(GetProcessHeap(), 0, (LPVOID
)mdi_cs
->szClass
);
881 HeapFree(GetProcessHeap(), 0, mdi_cs
);
883 HeapFree( GetProcessHeap(), 0, xs
);
889 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
890 if (HIWORD(cs
->szTitle
))
891 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szTitle
);
892 if (HIWORD(cs
->szClass
))
893 HeapFree( GetProcessHeap(), 0, (LPVOID
)cs
->szClass
);
894 HeapFree( GetProcessHeap(), 0, cs
);
899 case WM_WININICHANGE
:
900 case WM_DEVMODECHANGE
:
905 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
908 /* Listbox / Combobox */
910 case LB_INSERTSTRING
:
912 case LB_FINDSTRINGEXACT
:
913 case LB_SELECTSTRING
:
915 case CB_INSERTSTRING
:
917 case CB_FINDSTRINGEXACT
:
918 case CB_SELECTSTRING
:
919 if ( WINPROC_TestLBForStr( hwnd
, msg
))
920 HeapFree( GetProcessHeap(), 0, (void *)lParam
);
925 if ( WINPROC_TestLBForStr( hwnd
, msg
))
927 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 static UINT
convert_handle_16_to_32(HANDLE16 src
, unsigned int flags
)
954 UINT sz
= GlobalSize16(src
);
957 if (!(dst
= GlobalAlloc(flags
, sz
)))
959 ptr16
= GlobalLock16(src
);
960 ptr32
= GlobalLock(dst
);
961 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr32
, ptr16
, sz
);
968 /**********************************************************************
969 * WINPROC_MapMsg16To32A
971 * Map a message from 16- to 32-bit Ansi.
972 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
974 INT
WINPROC_MapMsg16To32A( HWND hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
975 WPARAM
*pwparam32
, LPARAM
*plparam
)
977 *pmsg32
= (UINT
)msg16
;
978 *pwparam32
= (WPARAM
)wParam16
;
985 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
986 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
990 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
991 *plparam
= (LPARAM
)WIN_Handle32( HIWORD(*plparam
) );
994 if ( HIWORD(*plparam
) > CTLCOLOR_STATIC
) return -1;
995 *pmsg32
= WM_CTLCOLORMSGBOX
+ HIWORD(*plparam
);
996 *pwparam32
= (WPARAM
)HDC_32(wParam16
);
997 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1001 COMPAREITEMSTRUCT16
* cis16
= MapSL(*plparam
);
1002 COMPAREITEMSTRUCT
*cis
= HeapAlloc(GetProcessHeap(), 0, sizeof(*cis
));
1003 if (!cis
) return -1;
1004 cis
->CtlType
= cis16
->CtlType
;
1005 cis
->CtlID
= cis16
->CtlID
;
1006 cis
->hwndItem
= WIN_Handle32( cis16
->hwndItem
);
1007 cis
->itemID1
= cis16
->itemID1
;
1008 cis
->itemData1
= cis16
->itemData1
;
1009 cis
->itemID2
= cis16
->itemID2
;
1010 cis
->itemData2
= cis16
->itemData2
;
1011 cis
->dwLocaleId
= 0; /* FIXME */
1012 *plparam
= (LPARAM
)cis
;
1017 PCOPYDATASTRUCT16 pcds16
= MapSL(*plparam
);
1018 PCOPYDATASTRUCT pcds
= HeapAlloc ( GetProcessHeap(), 0, sizeof(*pcds
));
1019 pcds
->dwData
= pcds16
->dwData
;
1020 pcds
->cbData
= pcds16
->cbData
;
1021 pcds
->lpData
= MapSL( pcds16
->lpData
);
1022 *plparam
= (LPARAM
)pcds
;
1027 DELETEITEMSTRUCT16
* dis16
= MapSL(*plparam
);
1028 DELETEITEMSTRUCT
*dis
= HeapAlloc(GetProcessHeap(), 0, sizeof(*dis
));
1029 if (!dis
) return -1;
1030 dis
->CtlType
= dis16
->CtlType
;
1031 dis
->CtlID
= dis16
->CtlID
;
1032 dis
->hwndItem
= WIN_Handle32( dis16
->hwndItem
);
1033 dis
->itemData
= dis16
->itemData
;
1034 *plparam
= (LPARAM
)dis
;
1037 case WM_MEASUREITEM
:
1039 MEASUREITEMSTRUCT16
* mis16
= MapSL(*plparam
);
1040 MEASUREITEMSTRUCT
*mis
= HeapAlloc(GetProcessHeap(), 0,
1041 sizeof(*mis
) + sizeof(LPARAM
));
1042 if (!mis
) return -1;
1043 mis
->CtlType
= mis16
->CtlType
;
1044 mis
->CtlID
= mis16
->CtlID
;
1045 mis
->itemID
= mis16
->itemID
;
1046 mis
->itemWidth
= mis16
->itemWidth
;
1047 mis
->itemHeight
= mis16
->itemHeight
;
1048 mis
->itemData
= mis16
->itemData
;
1049 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1050 *plparam
= (LPARAM
)mis
;
1055 DRAWITEMSTRUCT16
* dis16
= MapSL(*plparam
);
1056 DRAWITEMSTRUCT
*dis
= HeapAlloc(GetProcessHeap(), 0, sizeof(*dis
));
1057 if (!dis
) return -1;
1058 dis
->CtlType
= dis16
->CtlType
;
1059 dis
->CtlID
= dis16
->CtlID
;
1060 dis
->itemID
= dis16
->itemID
;
1061 dis
->itemAction
= dis16
->itemAction
;
1062 dis
->itemState
= dis16
->itemState
;
1063 dis
->hwndItem
= (dis
->CtlType
== ODT_MENU
) ? (HWND
)HMENU_32(dis16
->hwndItem
)
1064 : WIN_Handle32( dis16
->hwndItem
);
1065 dis
->hDC
= HDC_32(dis16
->hDC
);
1066 dis
->itemData
= dis16
->itemData
;
1067 dis
->rcItem
.left
= dis16
->rcItem
.left
;
1068 dis
->rcItem
.top
= dis16
->rcItem
.top
;
1069 dis
->rcItem
.right
= dis16
->rcItem
.right
;
1070 dis
->rcItem
.bottom
= dis16
->rcItem
.bottom
;
1071 *plparam
= (LPARAM
)dis
;
1074 case WM_GETMINMAXINFO
:
1076 MINMAXINFO
*mmi
= HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi
) + sizeof(LPARAM
));
1077 if (!mmi
) return -1;
1078 MINMAXINFO16to32( MapSL(*plparam
), mmi
);
1079 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1080 *plparam
= (LPARAM
)mmi
;
1085 case WM_WININICHANGE
:
1086 case WM_DEVMODECHANGE
:
1087 case WM_ASKCBFORMATNAME
:
1088 *plparam
= (LPARAM
)MapSL(*plparam
);
1092 MDICREATESTRUCT16
*cs16
= MapSL(*plparam
);
1093 MDICREATESTRUCTA
*cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) + sizeof(LPARAM
) );
1095 MDICREATESTRUCT16to32A( cs16
, cs
);
1096 cs
->szTitle
= MapSL(cs16
->szTitle
);
1097 cs
->szClass
= MapSL(cs16
->szClass
);
1098 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1099 *plparam
= (LPARAM
)cs
;
1102 case WM_MDIGETACTIVE
:
1103 *plparam
= (LPARAM
)HeapAlloc( GetProcessHeap(), 0, sizeof(BOOL
) );
1104 *(BOOL
*)(*plparam
) = 0;
1107 if(wParam16
) *pmsg32
=WM_MDIREFRESHMENU
;
1108 *pwparam32
= (WPARAM
)HMENU_32(LOWORD(*plparam
));
1109 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1112 *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1113 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1116 if((LOWORD(*plparam
) & MF_POPUP
) && (LOWORD(*plparam
) != 0xFFFF))
1118 HMENU hmenu
=HMENU_32(HIWORD(*plparam
));
1119 UINT Pos
=MENU_FindSubMenu( &hmenu
, HMENU_32(wParam16
));
1120 if(Pos
==0xFFFF) Pos
=0; /* NO_SELECTED_ITEM */
1121 *pwparam32
= MAKEWPARAM( Pos
, LOWORD(*plparam
) );
1123 else *pwparam32
= MAKEWPARAM( wParam16
, LOWORD(*plparam
) );
1124 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1126 case WM_MDIACTIVATE
:
1129 *pwparam32
= (WPARAM
)WIN_Handle32( HIWORD(*plparam
) );
1130 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1132 else /* message sent to MDI client */
1133 *pwparam32
= wParam16
;
1137 NCCALCSIZE_PARAMS16
*nc16
;
1138 NCCALCSIZE_PARAMS
*nc
;
1140 nc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*nc
) + sizeof(LPARAM
) );
1142 nc16
= MapSL(*plparam
);
1143 nc
->rgrc
[0].left
= nc16
->rgrc
[0].left
;
1144 nc
->rgrc
[0].top
= nc16
->rgrc
[0].top
;
1145 nc
->rgrc
[0].right
= nc16
->rgrc
[0].right
;
1146 nc
->rgrc
[0].bottom
= nc16
->rgrc
[0].bottom
;
1149 nc
->lppos
= HeapAlloc( GetProcessHeap(), 0, sizeof(*nc
->lppos
) );
1150 nc
->rgrc
[1].left
= nc16
->rgrc
[1].left
;
1151 nc
->rgrc
[1].top
= nc16
->rgrc
[1].top
;
1152 nc
->rgrc
[1].right
= nc16
->rgrc
[1].right
;
1153 nc
->rgrc
[1].bottom
= nc16
->rgrc
[1].bottom
;
1154 nc
->rgrc
[2].left
= nc16
->rgrc
[2].left
;
1155 nc
->rgrc
[2].top
= nc16
->rgrc
[2].top
;
1156 nc
->rgrc
[2].right
= nc16
->rgrc
[2].right
;
1157 nc
->rgrc
[2].bottom
= nc16
->rgrc
[2].bottom
;
1158 if (nc
->lppos
) WINDOWPOS16to32( MapSL(nc16
->lppos
), nc
->lppos
);
1160 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
1161 *plparam
= (LPARAM
)nc
;
1167 CREATESTRUCT16
*cs16
= MapSL(*plparam
);
1168 CREATESTRUCTA
*cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) + sizeof(LPARAM
) );
1170 CREATESTRUCT16to32A( cs16
, cs
);
1171 cs
->lpszName
= MapSL(cs16
->lpszName
);
1172 cs
->lpszClass
= MapSL(cs16
->lpszClass
);
1174 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1176 MDICREATESTRUCT16
*mdi_cs16
;
1177 MDICREATESTRUCTA
*mdi_cs
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs
));
1180 HeapFree(GetProcessHeap(), 0, cs
);
1183 mdi_cs16
= (MDICREATESTRUCT16
*)MapSL(cs16
->lpCreateParams
);
1184 MDICREATESTRUCT16to32A(mdi_cs16
, mdi_cs
);
1185 mdi_cs
->szTitle
= MapSL(mdi_cs16
->szTitle
);
1186 mdi_cs
->szClass
= MapSL(mdi_cs16
->szClass
);
1188 cs
->lpCreateParams
= mdi_cs
;
1190 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1191 *plparam
= (LPARAM
)cs
;
1194 case WM_PARENTNOTIFY
:
1195 if ((wParam16
== WM_CREATE
) || (wParam16
== WM_DESTROY
))
1197 *pwparam32
= MAKEWPARAM( wParam16
, HIWORD(*plparam
) );
1198 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1201 case WM_WINDOWPOSCHANGING
:
1202 case WM_WINDOWPOSCHANGED
:
1204 WINDOWPOS
*wp
= HeapAlloc( GetProcessHeap(), 0, sizeof(*wp
) + sizeof(LPARAM
) );
1206 WINDOWPOS16to32( MapSL(*plparam
), wp
);
1207 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
1208 *plparam
= (LPARAM
)wp
;
1214 LPMSG16 msg16
= MapSL(*plparam
);
1215 LPMSG msg32
= HeapAlloc( GetProcessHeap(), 0, sizeof(MSG
) );
1217 if (!msg32
) return -1;
1218 msg32
->hwnd
= WIN_Handle32( msg16
->hwnd
);
1219 msg32
->message
= msg16
->message
;
1220 msg32
->wParam
= msg16
->wParam
;
1221 msg32
->lParam
= msg16
->lParam
;
1222 msg32
->time
= msg16
->time
;
1223 msg32
->pt
.x
= msg16
->pt
.x
;
1224 msg32
->pt
.y
= msg16
->pt
.y
;
1225 *plparam
= (LPARAM
)msg32
;
1230 *plparam
= (LPARAM
)MapSL(*plparam
);
1232 case WM_ACTIVATEAPP
:
1233 /* We need this when SetActiveWindow sends a Sendmessage16() to
1234 * a 32bit window. Might be superflous with 32bit interprocess
1235 * message queues. */
1236 if (*plparam
) *plparam
= HTASK_32( *plparam
);
1240 MDINEXTMENU
*next
= HeapAlloc( GetProcessHeap(), 0, sizeof(*next
) );
1241 if (!next
) return -1;
1242 next
->hmenuIn
= (HMENU
)*plparam
;
1243 next
->hmenuNext
= 0;
1245 *plparam
= (LPARAM
)next
;
1248 case WM_PAINTCLIPBOARD
:
1249 case WM_SIZECLIPBOARD
:
1250 FIXME_(msg
)("message %04x needs translation\n",msg16
);
1252 case WM_DDE_INITIATE
:
1253 case WM_DDE_TERMINATE
:
1254 case WM_DDE_UNADVISE
:
1255 case WM_DDE_REQUEST
:
1256 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1266 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1267 lo16
= LOWORD(*plparam
);
1268 hi
= HIWORD(*plparam
);
1269 if (lo16
&& !(lo32
= convert_handle_16_to_32(lo16
, GMEM_DDESHARE
)))
1271 *plparam
= PackDDElParam(msg16
, lo32
, hi
);
1273 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1280 *pwparam32
= (WPARAM
)WIN_Handle32(wParam16
);
1282 lo
= LOWORD(*plparam
);
1283 hi
= HIWORD(*plparam
);
1285 if (GlobalGetAtomNameA(hi
, buf
, 2) > 0) flag
|= 1;
1286 if (GlobalSize16(hi
) != 0) flag
|= 2;
1292 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1297 break; /* atom, nothing to do */
1299 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
1302 hi
= convert_handle_16_to_32(hi
, GMEM_DDESHARE
);
1305 *plparam
= PackDDElParam(WM_DDE_ACK
, lo
, hi
);
1307 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1308 case WM_DDE_EXECUTE
:
1309 *plparam
= convert_handle_16_to_32(*plparam
, GMEM_DDESHARE
);
1310 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
1311 default: /* No translation needed */
1317 /**********************************************************************
1318 * WINPROC_UnmapMsg16To32A
1320 * Unmap a message that was mapped from 16- to 32-bit Ansi.
1322 LRESULT
WINPROC_UnmapMsg16To32A( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1327 case WM_COMPAREITEM
:
1331 HeapFree( GetProcessHeap(), 0, (LPVOID
)lParam
);
1333 case WM_MEASUREITEM
:
1335 MEASUREITEMSTRUCT16
*mis16
;
1336 MEASUREITEMSTRUCT
*mis
= (MEASUREITEMSTRUCT
*)lParam
;
1337 lParam
= *(LPARAM
*)(mis
+ 1);
1338 mis16
= MapSL(lParam
);
1339 mis16
->itemWidth
= (UINT16
)mis
->itemWidth
;
1340 mis16
->itemHeight
= (UINT16
)mis
->itemHeight
;
1341 HeapFree( GetProcessHeap(), 0, mis
);
1344 case WM_GETMINMAXINFO
:
1346 MINMAXINFO
*mmi
= (MINMAXINFO
*)lParam
;
1347 lParam
= *(LPARAM
*)(mmi
+ 1);
1348 MINMAXINFO32to16( mmi
, MapSL(lParam
));
1349 HeapFree( GetProcessHeap(), 0, mmi
);
1354 MDICREATESTRUCTA
*cs
= (MDICREATESTRUCTA
*)lParam
;
1355 lParam
= *(LPARAM
*)(cs
+ 1);
1356 MDICREATESTRUCT32Ato16( cs
, MapSL(lParam
) );
1357 HeapFree( GetProcessHeap(), 0, cs
);
1360 case WM_MDIGETACTIVE
:
1361 result
= MAKELONG( LOWORD(result
), (BOOL16
)(*(BOOL
*)lParam
) );
1362 HeapFree( GetProcessHeap(), 0, (BOOL
*)lParam
);
1366 NCCALCSIZE_PARAMS16
*nc16
;
1367 NCCALCSIZE_PARAMS
*nc
= (NCCALCSIZE_PARAMS
*)lParam
;
1368 lParam
= *(LPARAM
*)(nc
+ 1);
1369 nc16
= MapSL(lParam
);
1370 nc16
->rgrc
[0].left
= nc
->rgrc
[0].left
;
1371 nc16
->rgrc
[0].top
= nc
->rgrc
[0].top
;
1372 nc16
->rgrc
[0].right
= nc
->rgrc
[0].right
;
1373 nc16
->rgrc
[0].bottom
= nc
->rgrc
[0].bottom
;
1376 nc16
->rgrc
[1].left
= nc
->rgrc
[1].left
;
1377 nc16
->rgrc
[1].top
= nc
->rgrc
[1].top
;
1378 nc16
->rgrc
[1].right
= nc
->rgrc
[1].right
;
1379 nc16
->rgrc
[1].bottom
= nc
->rgrc
[1].bottom
;
1380 nc16
->rgrc
[2].left
= nc
->rgrc
[2].left
;
1381 nc16
->rgrc
[2].top
= nc
->rgrc
[2].top
;
1382 nc16
->rgrc
[2].right
= nc
->rgrc
[2].right
;
1383 nc16
->rgrc
[2].bottom
= nc
->rgrc
[2].bottom
;
1386 WINDOWPOS32to16( nc
->lppos
, MapSL(nc16
->lppos
));
1387 HeapFree( GetProcessHeap(), 0, nc
->lppos
);
1390 HeapFree( GetProcessHeap(), 0, nc
);
1396 CREATESTRUCTA
*cs
= (CREATESTRUCTA
*)lParam
;
1397 lParam
= *(LPARAM
*)(cs
+ 1);
1398 CREATESTRUCT32Ato16( cs
, MapSL(lParam
) );
1400 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1401 HeapFree(GetProcessHeap(), 0, cs
->lpCreateParams
);
1403 HeapFree( GetProcessHeap(), 0, cs
);
1406 case WM_WINDOWPOSCHANGING
:
1407 case WM_WINDOWPOSCHANGED
:
1409 WINDOWPOS
*wp
= (WINDOWPOS
*)lParam
;
1410 lParam
= *(LPARAM
*)(wp
+ 1);
1411 WINDOWPOS32to16(wp
, MapSL(lParam
));
1412 HeapFree( GetProcessHeap(), 0, wp
);
1418 LPMSG msg32
= (LPMSG
)lParam
;
1419 HeapFree( GetProcessHeap(), 0, msg32
);
1424 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
1425 result
= MAKELONG( HMENU_16(next
->hmenuNext
), HWND_16(next
->hwndNext
) );
1426 HeapFree( GetProcessHeap(), 0, next
);
1434 /**********************************************************************
1435 * WINPROC_MapMsg16To32W
1437 * Map a message from 16- to 32-bit Unicode.
1438 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1440 INT
WINPROC_MapMsg16To32W( HWND hwnd
, UINT16 msg16
, WPARAM16 wParam16
, UINT
*pmsg32
,
1441 WPARAM
*pwparam32
, LPARAM
*plparam
)
1443 *pmsg32
=(UINT
)msg16
;
1444 *pwparam32
= (WPARAM
)wParam16
;
1449 case WM_WININICHANGE
:
1450 case WM_DEVMODECHANGE
:
1451 case WM_ASKCBFORMATNAME
:
1452 *plparam
= (LPARAM
)MapSL(*plparam
);
1453 return WINPROC_MapMsg32ATo32W( hwnd
, *pmsg32
, pwparam32
, plparam
);
1454 case WM_GETTEXTLENGTH
:
1455 case CB_GETLBTEXTLEN
:
1457 return 1; /* need to map result */
1461 CREATESTRUCT16
*cs16
= MapSL(*plparam
);
1462 CREATESTRUCTW
*cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) + sizeof(LPARAM
) );
1464 CREATESTRUCT16to32A( cs16
, (CREATESTRUCTA
*)cs
);
1465 cs
->lpszName
= map_str_16_to_32W(cs16
->lpszName
);
1466 cs
->lpszClass
= map_str_16_to_32W(cs16
->lpszClass
);
1468 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1470 MDICREATESTRUCT16
*mdi_cs16
;
1471 MDICREATESTRUCTW
*mdi_cs
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs
));
1474 HeapFree(GetProcessHeap(), 0, cs
);
1477 mdi_cs16
= (MDICREATESTRUCT16
*)MapSL(cs16
->lpCreateParams
);
1478 MDICREATESTRUCT16to32A(mdi_cs16
, (MDICREATESTRUCTA
*)mdi_cs
);
1479 mdi_cs
->szTitle
= map_str_16_to_32W(mdi_cs16
->szTitle
);
1480 mdi_cs
->szClass
= map_str_16_to_32W(mdi_cs16
->szClass
);
1482 cs
->lpCreateParams
= mdi_cs
;
1484 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1485 *plparam
= (LPARAM
)cs
;
1490 MDICREATESTRUCT16
*cs16
= MapSL(*plparam
);
1491 MDICREATESTRUCTW
*cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(*cs
) + sizeof(LPARAM
) );
1493 MDICREATESTRUCT16to32A( cs16
, (MDICREATESTRUCTA
*)cs
);
1494 cs
->szTitle
= map_str_16_to_32W(cs16
->szTitle
);
1495 cs
->szClass
= map_str_16_to_32W(cs16
->szClass
);
1496 *(LPARAM
*)(cs
+ 1) = *plparam
; /* Store the previous lParam */
1497 *plparam
= (LPARAM
)cs
;
1503 LPMSG16 msg16
= MapSL(*plparam
);
1504 LPMSG msg32
= HeapAlloc( GetProcessHeap(), 0, sizeof(MSG
) );
1506 if (!msg32
) return -1;
1507 msg32
->hwnd
= WIN_Handle32( msg16
->hwnd
);
1508 msg32
->message
= msg16
->message
;
1509 msg32
->wParam
= msg16
->wParam
;
1510 msg32
->lParam
= msg16
->lParam
;
1511 msg32
->time
= msg16
->time
;
1512 msg32
->pt
.x
= msg16
->pt
.x
;
1513 msg32
->pt
.y
= msg16
->pt
.y
;
1514 switch(msg32
->message
)
1519 case WM_SYSDEADCHAR
:
1520 msg32
->wParam
= map_wparam_char_AtoW( msg16
->wParam
, 1 );
1523 *plparam
= (LPARAM
)msg32
;
1529 *pwparam32
= MAKEWPARAM( map_wparam_char_AtoW( wParam16
, 1 ), HIWORD(*plparam
) );
1530 *plparam
= (LPARAM
)WIN_Handle32( LOWORD(*plparam
) );
1533 *pwparam32
= MAKEWPARAM( map_wparam_char_AtoW( wParam16
, 1 ), LOWORD(*plparam
) );
1534 *plparam
= (LPARAM
)HMENU_32(HIWORD(*plparam
));
1539 case WM_SYSDEADCHAR
:
1540 *pwparam32
= map_wparam_char_AtoW( wParam16
, 1 );
1543 *pwparam32
= map_wparam_char_AtoW( wParam16
, 2 );
1546 default: /* No Unicode translation needed */
1547 return WINPROC_MapMsg16To32A( hwnd
, msg16
, wParam16
, pmsg32
,
1548 pwparam32
, plparam
);
1553 /**********************************************************************
1554 * WINPROC_UnmapMsg16To32W
1556 * Unmap a message that was mapped from 16- to 32-bit Unicode.
1558 LRESULT
WINPROC_UnmapMsg16To32W( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
1559 LRESULT result
, WNDPROC dispatch
)
1565 case WM_GETTEXTLENGTH
:
1566 case CB_GETLBTEXTLEN
:
1568 case WM_ASKCBFORMATNAME
:
1569 return WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
, result
, dispatch
);
1573 CREATESTRUCTW
*cs
= (CREATESTRUCTW
*)lParam
;
1574 lParam
= *(LPARAM
*)(cs
+ 1);
1575 CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs
, MapSL(lParam
) );
1576 unmap_str_16_to_32W( cs
->lpszName
);
1577 unmap_str_16_to_32W( cs
->lpszClass
);
1579 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1581 MDICREATESTRUCTW
*mdi_cs
= (MDICREATESTRUCTW
*)cs
->lpCreateParams
;
1582 unmap_str_16_to_32W( mdi_cs
->szTitle
);
1583 unmap_str_16_to_32W( mdi_cs
->szClass
);
1584 HeapFree(GetProcessHeap(), 0, cs
->lpCreateParams
);
1586 HeapFree( GetProcessHeap(), 0, cs
);
1591 MDICREATESTRUCTW
*cs
= (MDICREATESTRUCTW
*)lParam
;
1592 lParam
= *(LPARAM
*)(cs
+ 1);
1593 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs
, MapSL(lParam
) );
1594 unmap_str_16_to_32W( cs
->szTitle
);
1595 unmap_str_16_to_32W( cs
->szClass
);
1596 HeapFree( GetProcessHeap(), 0, cs
);
1602 LPMSG msg32
= (LPMSG
)lParam
;
1603 HeapFree( GetProcessHeap(), 0, msg32
);
1607 return WINPROC_UnmapMsg16To32A( hwnd
, msg
, wParam
, lParam
, result
);
1612 static HANDLE16
convert_handle_32_to_16(UINT src
, unsigned int flags
)
1615 UINT sz
= GlobalSize((HANDLE
)src
);
1618 if (!(dst
= GlobalAlloc16(flags
, sz
)))
1620 ptr32
= GlobalLock((HANDLE
)src
);
1621 ptr16
= GlobalLock16(dst
);
1622 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr16
, ptr32
, sz
);
1623 GlobalUnlock((HANDLE
)src
);
1624 GlobalUnlock16(dst
);
1630 /**********************************************************************
1631 * WINPROC_MapMsg32ATo16
1633 * Map a message from 32-bit Ansi to 16-bit.
1634 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
1636 INT
WINPROC_MapMsg32ATo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
1637 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
1640 *pmsg16
= (UINT16
)msg32
;
1641 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
1645 *pmsg16
= SBM_SETRANGE16
;
1646 *plparam
= MAKELPARAM(wParam32
, *plparam
);
1651 *pmsg16
= SBM_GETRANGE16
;
1659 *pmsg16
= (UINT16
)msg32
+ (BM_GETCHECK16
- BM_GETCHECK
);
1668 case EM_SCROLLCARET
:
1671 case EM_GETLINECOUNT
:
1683 case EM_LINEFROMCHAR
:
1684 case EM_SETTABSTOPS
:
1685 case EM_SETPASSWORDCHAR
:
1686 case EM_EMPTYUNDOBUFFER
:
1687 case EM_GETFIRSTVISIBLELINE
:
1688 case EM_SETREADONLY
:
1689 case EM_SETWORDBREAKPROC
:
1690 case EM_GETWORDBREAKPROC
:
1691 case EM_GETPASSWORDCHAR
:
1692 *pmsg16
= (UINT16
)msg32
+ (EM_GETSEL16
- EM_GETSEL
);
1697 case LB_DELETESTRING
:
1698 case LB_GETANCHORINDEX
:
1699 case LB_GETCARETINDEX
:
1702 case LB_GETHORIZONTALEXTENT
:
1703 case LB_GETITEMDATA
:
1704 case LB_GETITEMHEIGHT
:
1706 case LB_GETSELCOUNT
:
1708 case LB_GETTOPINDEX
:
1709 case LB_RESETCONTENT
:
1710 case LB_SELITEMRANGE
:
1711 case LB_SELITEMRANGEEX
:
1712 case LB_SETANCHORINDEX
:
1713 case LB_SETCARETINDEX
:
1714 case LB_SETCOLUMNWIDTH
:
1716 case LB_SETHORIZONTALEXTENT
:
1717 case LB_SETITEMDATA
:
1718 case LB_SETITEMHEIGHT
:
1720 case LB_SETTOPINDEX
:
1721 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1723 case CB_DELETESTRING
:
1725 case CB_GETLBTEXTLEN
:
1727 case CB_RESETCONTENT
:
1731 case CB_SHOWDROPDOWN
:
1732 case CB_SETITEMDATA
:
1733 case CB_SETITEMHEIGHT
:
1734 case CB_GETITEMHEIGHT
:
1735 case CB_SETEXTENDEDUI
:
1736 case CB_GETEXTENDEDUI
:
1737 case CB_GETDROPPEDSTATE
:
1738 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1741 *pmsg16
= CB_GETEDITSEL16
;
1746 case LB_FINDSTRINGEXACT
:
1747 case LB_INSERTSTRING
:
1748 case LB_SELECTSTRING
:
1751 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
1752 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
1757 case CB_FINDSTRINGEXACT
:
1758 case CB_INSERTSTRING
:
1759 case CB_SELECTSTRING
:
1761 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
1762 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
1765 case LB_GETITEMRECT
:
1767 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
1768 if (!rect
) return -1;
1769 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1770 *plparam
= MapLS( rect
);
1772 *pmsg16
= LB_GETITEMRECT16
;
1774 case LB_GETSELITEMS
:
1776 LPARAM
*items
; /* old LPARAM first, then *pwparam16 x INT16 entries */
1778 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
1779 if (!(items
= HeapAlloc( GetProcessHeap(), 0,
1780 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
1781 *items
++ = *plparam
; /* Store the previous lParam */
1782 *plparam
= MapLS( items
);
1784 *pmsg16
= LB_GETSELITEMS16
;
1786 case LB_SETTABSTOPS
:
1791 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
1792 if (!(stops
= HeapAlloc( GetProcessHeap(), 0,
1793 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
1794 for (i
= 0; i
< *pwparam16
; i
++) stops
[i
] = *((LPINT
)*plparam
+i
);
1795 *plparam
= MapLS( stops
);
1798 *pmsg16
= LB_SETTABSTOPS16
;
1801 case CB_GETDROPPEDCONTROLRECT
:
1803 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
1804 if (!rect
) return -1;
1805 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
1806 *plparam
= (LPARAM
)MapLS(rect
);
1808 *pmsg16
= CB_GETDROPPEDCONTROLRECT16
;
1812 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1813 *pmsg16
= LB_GETTEXT16
;
1817 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
1818 *pmsg16
= CB_GETLBTEXT16
;
1823 *plparam
= MAKELONG( (INT16
)(INT
)wParam32
, (INT16
)*plparam
);
1824 *pmsg16
= EM_SETSEL16
;
1831 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
1835 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
1839 PCOPYDATASTRUCT pcds32
= (PCOPYDATASTRUCT
) *plparam
;
1840 PCOPYDATASTRUCT16 pcds
= HeapAlloc( GetProcessHeap(), 0, sizeof( *pcds
));
1841 pcds
->dwData
= pcds32
->dwData
;
1842 pcds
->cbData
= pcds32
->cbData
;
1843 pcds
->lpData
= MapLS( pcds32
->lpData
);
1844 *plparam
= MapLS( pcds
);
1847 case WM_CTLCOLORMSGBOX
:
1848 case WM_CTLCOLOREDIT
:
1849 case WM_CTLCOLORLISTBOX
:
1850 case WM_CTLCOLORBTN
:
1851 case WM_CTLCOLORDLG
:
1852 case WM_CTLCOLORSCROLLBAR
:
1853 case WM_CTLCOLORSTATIC
:
1854 *pmsg16
= WM_CTLCOLOR
;
1855 *plparam
= MAKELPARAM( (HWND16
)*plparam
,
1856 (WORD
)msg32
- WM_CTLCOLORMSGBOX
);
1858 case WM_COMPAREITEM
:
1860 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)*plparam
;
1861 COMPAREITEMSTRUCT16
*cis
= HeapAlloc( GetProcessHeap(), 0, sizeof(COMPAREITEMSTRUCT16
));
1862 if (!cis
) return -1;
1863 cis
->CtlType
= (UINT16
)cis32
->CtlType
;
1864 cis
->CtlID
= (UINT16
)cis32
->CtlID
;
1865 cis
->hwndItem
= HWND_16( cis32
->hwndItem
);
1866 cis
->itemID1
= (UINT16
)cis32
->itemID1
;
1867 cis
->itemData1
= cis32
->itemData1
;
1868 cis
->itemID2
= (UINT16
)cis32
->itemID2
;
1869 cis
->itemData2
= cis32
->itemData2
;
1870 *plparam
= MapLS( cis
);
1875 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)*plparam
;
1876 DELETEITEMSTRUCT16
*dis
= HeapAlloc( GetProcessHeap(), 0, sizeof(DELETEITEMSTRUCT16
) );
1877 if (!dis
) return -1;
1878 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1879 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1880 dis
->itemID
= (UINT16
)dis32
->itemID
;
1881 dis
->hwndItem
= (dis
->CtlType
== ODT_MENU
) ? (HWND16
)LOWORD(dis32
->hwndItem
)
1882 : HWND_16( dis32
->hwndItem
);
1883 dis
->itemData
= dis32
->itemData
;
1884 *plparam
= MapLS( dis
);
1889 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)*plparam
;
1890 DRAWITEMSTRUCT16
*dis
= HeapAlloc( GetProcessHeap(), 0, sizeof(DRAWITEMSTRUCT16
) );
1891 if (!dis
) return -1;
1892 dis
->CtlType
= (UINT16
)dis32
->CtlType
;
1893 dis
->CtlID
= (UINT16
)dis32
->CtlID
;
1894 dis
->itemID
= (UINT16
)dis32
->itemID
;
1895 dis
->itemAction
= (UINT16
)dis32
->itemAction
;
1896 dis
->itemState
= (UINT16
)dis32
->itemState
;
1897 dis
->hwndItem
= HWND_16( dis32
->hwndItem
);
1898 dis
->hDC
= HDC_16(dis32
->hDC
);
1899 dis
->itemData
= dis32
->itemData
;
1900 dis
->rcItem
.left
= dis32
->rcItem
.left
;
1901 dis
->rcItem
.top
= dis32
->rcItem
.top
;
1902 dis
->rcItem
.right
= dis32
->rcItem
.right
;
1903 dis
->rcItem
.bottom
= dis32
->rcItem
.bottom
;
1904 *plparam
= MapLS( dis
);
1907 case WM_MEASUREITEM
:
1909 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)*plparam
;
1910 MEASUREITEMSTRUCT16
*mis
= HeapAlloc( GetProcessHeap(), 0, sizeof(*mis
)+sizeof(LPARAM
));
1911 if (!mis
) return -1;
1912 mis
->CtlType
= (UINT16
)mis32
->CtlType
;
1913 mis
->CtlID
= (UINT16
)mis32
->CtlID
;
1914 mis
->itemID
= (UINT16
)mis32
->itemID
;
1915 mis
->itemWidth
= (UINT16
)mis32
->itemWidth
;
1916 mis
->itemHeight
= (UINT16
)mis32
->itemHeight
;
1917 mis
->itemData
= mis32
->itemData
;
1918 *(LPARAM
*)(mis
+ 1) = *plparam
; /* Store the previous lParam */
1919 *plparam
= MapLS( mis
);
1922 case WM_GETMINMAXINFO
:
1924 MINMAXINFO16
*mmi
= HeapAlloc( GetProcessHeap(), 0, sizeof(*mmi
) + sizeof(LPARAM
) );
1925 if (!mmi
) return -1;
1926 MINMAXINFO32to16( (MINMAXINFO
*)*plparam
, mmi
);
1927 *(LPARAM
*)(mmi
+ 1) = *plparam
; /* Store the previous lParam */
1928 *plparam
= MapLS( mmi
);
1932 case WM_ASKCBFORMATNAME
:
1934 LPARAM
*str
; /* store LPARAM, then *pwparam16 char space */
1935 *pwparam16
= (WPARAM16
)min( wParam32
, 0xff80 ); /* Must be < 64K */
1936 if (!(str
= HeapAlloc( GetProcessHeap(), 0, *pwparam16
+ sizeof(LPARAM
)))) return -1;
1937 *str
++ = *plparam
; /* Store the previous lParam */
1938 *plparam
= MapLS( str
);
1943 MDICREATESTRUCT16
*cs
;
1944 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)*plparam
;
1946 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16
) ))) return -1;
1947 MDICREATESTRUCT32Ato16( cs32
, cs
);
1948 cs
->szTitle
= MapLS( cs32
->szTitle
);
1949 cs
->szClass
= MapLS( cs32
->szClass
);
1950 *plparam
= MapLS( cs
);
1953 case WM_MDIGETACTIVE
:
1956 *plparam
= MAKELPARAM( (HMENU16
)LOWORD(wParam32
),
1957 (HMENU16
)LOWORD(*plparam
) );
1958 *pwparam16
= (*plparam
== 0);
1961 if(HIWORD(wParam32
) & MF_POPUP
)
1964 if (((UINT
)HIWORD(wParam32
) != 0xFFFF) || (*plparam
))
1966 if((hmenu
= GetSubMenu((HMENU
)*plparam
, *pwparam16
)))
1967 *pwparam16
=HMENU_16(hmenu
);
1972 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
1974 case WM_MDIACTIVATE
:
1975 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1977 *pwparam16
= ((HWND
)*plparam
== hwnd
);
1978 *plparam
= MAKELPARAM( (HWND16
)LOWORD(*plparam
),
1979 (HWND16
)LOWORD(wParam32
) );
1983 *pwparam16
= HWND_16( (HWND
)wParam32
);
1989 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)*plparam
;
1990 NCCALCSIZE_PARAMS16
*nc
= HeapAlloc( GetProcessHeap(), 0, sizeof(*nc
) + sizeof(LPARAM
));
1993 nc
->rgrc
[0].left
= nc32
->rgrc
[0].left
;
1994 nc
->rgrc
[0].top
= nc32
->rgrc
[0].top
;
1995 nc
->rgrc
[0].right
= nc32
->rgrc
[0].right
;
1996 nc
->rgrc
[0].bottom
= nc32
->rgrc
[0].bottom
;
2000 nc
->rgrc
[1].left
= nc32
->rgrc
[1].left
;
2001 nc
->rgrc
[1].top
= nc32
->rgrc
[1].top
;
2002 nc
->rgrc
[1].right
= nc32
->rgrc
[1].right
;
2003 nc
->rgrc
[1].bottom
= nc32
->rgrc
[1].bottom
;
2004 nc
->rgrc
[2].left
= nc32
->rgrc
[2].left
;
2005 nc
->rgrc
[2].top
= nc32
->rgrc
[2].top
;
2006 nc
->rgrc
[2].right
= nc32
->rgrc
[2].right
;
2007 nc
->rgrc
[2].bottom
= nc32
->rgrc
[2].bottom
;
2008 if (!(wp
= HeapAlloc( GetProcessHeap(), 0, sizeof(WINDOWPOS16
) )))
2010 HeapFree( GetProcessHeap(), 0, nc
);
2013 WINDOWPOS32to16( nc32
->lppos
, wp
);
2014 nc
->lppos
= MapLS( wp
);
2016 *(LPARAM
*)(nc
+ 1) = *plparam
; /* Store the previous lParam */
2017 *plparam
= MapLS( nc
);
2024 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)*plparam
;
2026 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16
) ))) return -1;
2027 CREATESTRUCT32Ato16( cs32
, cs
);
2028 cs
->lpszName
= MapLS( cs32
->lpszName
);
2029 cs
->lpszClass
= MapLS( cs32
->lpszClass
);
2031 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
2033 MDICREATESTRUCT16
*mdi_cs16
;
2034 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs32
->lpCreateParams
;
2035 mdi_cs16
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16
));
2038 HeapFree(GetProcessHeap(), 0, cs
);
2041 MDICREATESTRUCT32Ato16(mdi_cs
, mdi_cs16
);
2042 mdi_cs16
->szTitle
= MapLS( mdi_cs
->szTitle
);
2043 mdi_cs16
->szClass
= MapLS( mdi_cs
->szClass
);
2044 cs
->lpCreateParams
= MapLS( mdi_cs16
);
2046 *plparam
= MapLS( cs
);
2049 case WM_PARENTNOTIFY
:
2050 if ((LOWORD(wParam32
)==WM_CREATE
) || (LOWORD(wParam32
)==WM_DESTROY
))
2051 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
));
2052 /* else nothing to do */
2055 *plparam
= MapLS( (NMHDR
*)*plparam
); /* NMHDR is already 32-bit */
2058 case WM_WININICHANGE
:
2059 case WM_DEVMODECHANGE
:
2060 *plparam
= MapLS( (LPSTR
)*plparam
);
2062 case WM_WINDOWPOSCHANGING
:
2063 case WM_WINDOWPOSCHANGED
:
2065 WINDOWPOS16
*wp
= HeapAlloc( GetProcessHeap(), 0, sizeof(*wp
) + sizeof(LPARAM
) );
2067 WINDOWPOS32to16( (WINDOWPOS
*)*plparam
, wp
);
2068 *(LPARAM
*)(wp
+ 1) = *plparam
; /* Store the previous lParam */
2069 *plparam
= MapLS( wp
);
2074 LPMSG msg32
= (LPMSG
) *plparam
;
2075 LPMSG16 msg16
= HeapAlloc( GetProcessHeap(), 0, sizeof(MSG16
) );
2077 if (!msg16
) return -1;
2078 msg16
->hwnd
= HWND_16( msg32
->hwnd
);
2079 msg16
->message
= msg32
->message
;
2080 msg16
->wParam
= msg32
->wParam
;
2081 msg16
->lParam
= msg32
->lParam
;
2082 msg16
->time
= msg32
->time
;
2083 msg16
->pt
.x
= msg32
->pt
.x
;
2084 msg16
->pt
.y
= msg32
->pt
.y
;
2085 *plparam
= MapLS( msg16
);
2090 case WM_ACTIVATEAPP
:
2091 if (*plparam
) *plparam
= HTASK_16( (HANDLE
)*plparam
);
2095 MDINEXTMENU
*next
= (MDINEXTMENU
*)*plparam
;
2096 *plparam
= (LPARAM
)next
->hmenuIn
;
2100 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
))
2102 *pmsg16
= WM_PAINTICON
;
2107 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
))
2108 *pmsg16
= WM_ICONERASEBKGND
;
2110 case WM_PAINTCLIPBOARD
:
2111 case WM_SIZECLIPBOARD
:
2112 FIXME_(msg
)("message %04x needs translation\n", msg32
);
2114 /* following messages should not be sent to 16-bit apps */
2117 case WM_CAPTURECHANGED
:
2118 case WM_STYLECHANGING
:
2119 case WM_STYLECHANGED
:
2121 case WM_DDE_INITIATE
:
2122 case WM_DDE_TERMINATE
:
2123 case WM_DDE_UNADVISE
:
2124 case WM_DDE_REQUEST
:
2125 *pwparam16
= HWND_16((HWND
)wParam32
);
2134 *pwparam16
= HWND_16((HWND
)wParam32
);
2135 UnpackDDElParam(msg32
, *plparam
, &lo32
, &hi
);
2136 if (lo32
&& !(lo16
= convert_handle_32_to_16(lo32
, GMEM_DDESHARE
)))
2138 *plparam
= MAKELPARAM(lo16
, hi
);
2140 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2147 *pwparam16
= HWND_16((HWND
)wParam32
);
2149 UnpackDDElParam(msg32
, *plparam
, &lo
, &hi
);
2151 if (GlobalGetAtomNameA((ATOM
)hi
, buf
, sizeof(buf
)) > 0) flag
|= 1;
2152 if (GlobalSize((HANDLE
)hi
) != 0) flag
|= 2;
2158 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2163 break; /* atom, nothing to do */
2165 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
2168 hi
= convert_handle_32_to_16(hi
, GMEM_DDESHARE
);
2171 *plparam
= MAKELPARAM(lo
, hi
);
2173 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2174 case WM_DDE_EXECUTE
:
2175 *plparam
= convert_handle_32_to_16(*plparam
, GMEM_DDESHARE
);
2176 return 0; /* FIXME don't know how to free allocated memory (handle) !! */
2177 default: /* No translation needed */
2183 /**********************************************************************
2184 * WINPROC_UnmapMsg32ATo16
2186 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
2188 void WINPROC_UnmapMsg32ATo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2194 *(LPINT
)wParam
= LOWORD(p16
->lResult
);
2195 *(LPINT
)lParam
= HIWORD(p16
->lResult
);
2202 case LB_FINDSTRINGEXACT
:
2203 case LB_INSERTSTRING
:
2204 case LB_SELECTSTRING
:
2208 case CB_FINDSTRINGEXACT
:
2209 case CB_INSERTSTRING
:
2210 case CB_SELECTSTRING
:
2214 case WM_WININICHANGE
:
2215 case WM_DEVMODECHANGE
:
2216 UnMapLS( (SEGPTR
)p16
->lParam
);
2218 case LB_SETTABSTOPS
:
2219 case WM_COMPAREITEM
:
2223 void *ptr
= MapSL( p16
->lParam
);
2224 UnMapLS( p16
->lParam
);
2225 HeapFree( GetProcessHeap(), 0, ptr
);
2230 PCOPYDATASTRUCT16 pcds
= MapSL( p16
->lParam
);
2231 UnMapLS( p16
->lParam
);
2232 UnMapLS( pcds
->lpData
);
2233 HeapFree( GetProcessHeap(), 0, pcds
);
2236 case CB_GETDROPPEDCONTROLRECT
:
2237 case LB_GETITEMRECT
:
2240 RECT16
*rect
= MapSL(p16
->lParam
);
2241 UnMapLS( p16
->lParam
);
2242 p16
->lParam
= *(LPARAM
*)(rect
+ 1);
2243 r32
= (RECT
*)p16
->lParam
;
2244 r32
->left
= rect
->left
;
2245 r32
->top
= rect
->top
;
2246 r32
->right
= rect
->right
;
2247 r32
->bottom
= rect
->bottom
;
2248 HeapFree( GetProcessHeap(), 0, rect
);
2251 case LB_GETSELITEMS
:
2254 LPINT16 items
= MapSL(p16
->lParam
);
2255 UnMapLS( p16
->lParam
);
2256 p16
->lParam
= *((LPARAM
*)items
- 1);
2257 for (i
= 0; i
< p16
->wParam
; i
++) *((LPINT
)(p16
->lParam
) + i
) = items
[i
];
2258 HeapFree( GetProcessHeap(), 0, (LPARAM
*)items
- 1 );
2264 *((PUINT
)(wParam
)) = LOWORD(p16
->lResult
);
2266 *((PUINT
)(lParam
)) = HIWORD(p16
->lResult
); /* FIXME: substract 1? */
2269 case WM_MEASUREITEM
:
2271 MEASUREITEMSTRUCT16
*mis
= MapSL(p16
->lParam
);
2272 MEASUREITEMSTRUCT
*mis32
= *(MEASUREITEMSTRUCT
**)(mis
+ 1);
2273 mis32
->itemWidth
= mis
->itemWidth
;
2274 mis32
->itemHeight
= mis
->itemHeight
;
2275 UnMapLS( p16
->lParam
);
2276 HeapFree( GetProcessHeap(), 0, mis
);
2279 case WM_GETMINMAXINFO
:
2281 MINMAXINFO16
*mmi
= MapSL(p16
->lParam
);
2282 UnMapLS( p16
->lParam
);
2283 p16
->lParam
= *(LPARAM
*)(mmi
+ 1);
2284 MINMAXINFO16to32( mmi
, (MINMAXINFO
*)(p16
->lParam
) );
2285 HeapFree( GetProcessHeap(), 0, mmi
);
2289 case WM_ASKCBFORMATNAME
:
2291 LPSTR str
= MapSL(p16
->lParam
);
2292 UnMapLS( p16
->lParam
);
2293 p16
->lParam
= *((LPARAM
*)str
- 1);
2294 lstrcpynA( (LPSTR
)(p16
->lParam
), str
, p16
->wParam
);
2295 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
- 1 );
2300 MDICREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2301 UnMapLS( cs
->szTitle
);
2302 UnMapLS( cs
->szClass
);
2303 UnMapLS( p16
->lParam
);
2304 HeapFree( GetProcessHeap(), 0, cs
);
2307 case WM_MDIGETACTIVE
:
2308 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(p16
->lResult
);
2309 p16
->lResult
= (LRESULT
)WIN_Handle32( LOWORD(p16
->lResult
) );
2313 NCCALCSIZE_PARAMS
*nc32
;
2314 NCCALCSIZE_PARAMS16
*nc
= MapSL(p16
->lParam
);
2315 UnMapLS( p16
->lParam
);
2316 p16
->lParam
= *(LPARAM
*)(nc
+ 1);
2317 nc32
= (NCCALCSIZE_PARAMS
*)(p16
->lParam
);
2318 nc32
->rgrc
[0].left
= nc
->rgrc
[0].left
;
2319 nc32
->rgrc
[0].top
= nc
->rgrc
[0].top
;
2320 nc32
->rgrc
[0].right
= nc
->rgrc
[0].right
;
2321 nc32
->rgrc
[0].bottom
= nc
->rgrc
[0].bottom
;
2324 WINDOWPOS16
*pos
= MapSL(nc
->lppos
);
2325 UnMapLS( nc
->lppos
);
2326 nc32
->rgrc
[1].left
= nc
->rgrc
[1].left
;
2327 nc32
->rgrc
[1].top
= nc
->rgrc
[1].top
;
2328 nc32
->rgrc
[1].right
= nc
->rgrc
[1].right
;
2329 nc32
->rgrc
[1].bottom
= nc
->rgrc
[1].bottom
;
2330 nc32
->rgrc
[2].left
= nc
->rgrc
[2].left
;
2331 nc32
->rgrc
[2].top
= nc
->rgrc
[2].top
;
2332 nc32
->rgrc
[2].right
= nc
->rgrc
[2].right
;
2333 nc32
->rgrc
[2].bottom
= nc
->rgrc
[2].bottom
;
2334 WINDOWPOS16to32( pos
, nc32
->lppos
);
2335 HeapFree( GetProcessHeap(), 0, pos
);
2337 HeapFree( GetProcessHeap(), 0, nc
);
2343 CREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2344 UnMapLS( p16
->lParam
);
2345 UnMapLS( cs
->lpszName
);
2346 UnMapLS( cs
->lpszClass
);
2347 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
2349 MDICREATESTRUCT16
*mdi_cs16
= (MDICREATESTRUCT16
*)MapSL(cs
->lpCreateParams
);
2350 UnMapLS( cs
->lpCreateParams
);
2351 UnMapLS( mdi_cs16
->szTitle
);
2352 UnMapLS( mdi_cs16
->szClass
);
2353 HeapFree(GetProcessHeap(), 0, mdi_cs16
);
2355 HeapFree( GetProcessHeap(), 0, cs
);
2358 case WM_WINDOWPOSCHANGING
:
2359 case WM_WINDOWPOSCHANGED
:
2361 WINDOWPOS16
*wp
= MapSL(p16
->lParam
);
2362 UnMapLS( p16
->lParam
);
2363 p16
->lParam
= *(LPARAM
*)(wp
+ 1);
2364 WINDOWPOS16to32( wp
, (WINDOWPOS
*)p16
->lParam
);
2365 HeapFree( GetProcessHeap(), 0, wp
);
2369 UnMapLS(p16
->lParam
);
2374 LPMSG16 msg16
= MapSL(p16
->lParam
);
2375 UnMapLS( p16
->lParam
);
2376 HeapFree( GetProcessHeap(), 0, msg16
);
2381 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
2382 next
->hmenuNext
= HMENU_32( LOWORD(p16
->lResult
) );
2383 next
->hwndNext
= WIN_Handle32( HIWORD(p16
->lResult
) );
2391 /**********************************************************************
2392 * WINPROC_MapMsg32WTo16
2394 * Map a message from 32-bit Unicode to 16-bit.
2395 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
2397 INT
WINPROC_MapMsg32WTo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
2398 UINT16
*pmsg16
, WPARAM16
*pwparam16
,
2401 *pmsg16
= LOWORD(msg32
);
2402 *pwparam16
= LOWORD(wParam32
);
2407 case LB_FINDSTRINGEXACT
:
2408 case LB_INSERTSTRING
:
2409 case LB_SELECTSTRING
:
2412 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2413 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
2418 case CB_FINDSTRINGEXACT
:
2419 case CB_INSERTSTRING
:
2420 case CB_SELECTSTRING
:
2422 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2423 *pmsg16
= (UINT16
)msg32
+ (CB_ADDSTRING16
- CB_ADDSTRING
);
2430 CREATESTRUCTW
*cs32
= (CREATESTRUCTW
*)*plparam
;
2432 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(CREATESTRUCT16
) ))) return -1;
2433 CREATESTRUCT32Ato16( (CREATESTRUCTA
*)cs32
, cs
);
2434 cs
->lpszName
= map_str_32W_to_16( cs32
->lpszName
);
2435 cs
->lpszClass
= map_str_32W_to_16( cs32
->lpszClass
);
2437 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
2439 MDICREATESTRUCT16
*mdi_cs16
;
2440 MDICREATESTRUCTW
*mdi_cs
= (MDICREATESTRUCTW
*)cs32
->lpCreateParams
;
2441 mdi_cs16
= HeapAlloc(GetProcessHeap(), 0, sizeof(*mdi_cs16
));
2444 HeapFree(GetProcessHeap(), 0, cs
);
2447 MDICREATESTRUCT32Ato16((MDICREATESTRUCTA
*)mdi_cs
, mdi_cs16
);
2448 mdi_cs16
->szTitle
= map_str_32W_to_16(mdi_cs
->szTitle
);
2449 mdi_cs16
->szClass
= map_str_32W_to_16(mdi_cs
->szClass
);
2450 cs
->lpCreateParams
= MapLS(mdi_cs16
);
2452 *plparam
= MapLS(cs
);
2457 MDICREATESTRUCT16
*cs
;
2458 MDICREATESTRUCTW
*cs32
= (MDICREATESTRUCTW
*)*plparam
;
2460 if (!(cs
= HeapAlloc( GetProcessHeap(), 0, sizeof(MDICREATESTRUCT16
) ))) return -1;
2461 MDICREATESTRUCT32Ato16( (MDICREATESTRUCTA
*)cs32
, cs
);
2462 cs
->szTitle
= map_str_32W_to_16( cs32
->szTitle
);
2463 cs
->szClass
= map_str_32W_to_16( cs32
->szClass
);
2464 *plparam
= MapLS(cs
);
2468 case WM_WININICHANGE
:
2469 case WM_DEVMODECHANGE
:
2470 *plparam
= map_str_32W_to_16( (LPWSTR
)*plparam
);
2474 if ( WINPROC_TestLBForStr( hwnd
, msg32
))
2476 LPSTR str
= HeapAlloc( GetProcessHeap(), 0, 512 ); /* FIXME: fixed sized buffer */
2477 if (!str
) return -1;
2478 *pmsg16
= (msg32
== LB_GETTEXT
) ? LB_GETTEXT16
: CB_GETLBTEXT16
;
2479 *plparam
= (LPARAM
)MapLS(str
);
2484 *pwparam16
= map_wparam_char_WtoA( wParam32
, 1 );
2485 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
2488 *pwparam16
= map_wparam_char_WtoA( wParam32
, 1 );
2489 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
2494 case WM_SYSDEADCHAR
:
2495 *pwparam16
= map_wparam_char_WtoA( wParam32
, 1 );
2498 *pwparam16
= map_wparam_char_WtoA( wParam32
, 2 );
2501 default: /* No Unicode translation needed (?) */
2502 return WINPROC_MapMsg32ATo16( hwnd
, msg32
, wParam32
, pmsg16
,
2503 pwparam16
, plparam
);
2508 /**********************************************************************
2509 * WINPROC_UnmapMsg32WTo16
2511 * Unmap a message that was mapped from 32-bit Unicode to 16-bit.
2513 void WINPROC_UnmapMsg32WTo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2520 case LB_FINDSTRINGEXACT
:
2521 case LB_INSERTSTRING
:
2522 case LB_SELECTSTRING
:
2527 case CB_FINDSTRINGEXACT
:
2528 case CB_INSERTSTRING
:
2529 case CB_SELECTSTRING
:
2532 case WM_WININICHANGE
:
2533 case WM_DEVMODECHANGE
:
2534 unmap_str_32W_to_16( p16
->lParam
);
2539 CREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2540 UnMapLS( p16
->lParam
);
2541 unmap_str_32W_to_16( cs
->lpszName
);
2542 unmap_str_32W_to_16( cs
->lpszClass
);
2544 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
2546 MDICREATESTRUCT16
*mdi_cs16
= (MDICREATESTRUCT16
*)MapSL(cs
->lpCreateParams
);
2547 UnMapLS( cs
->lpCreateParams
);
2548 unmap_str_32W_to_16(mdi_cs16
->szTitle
);
2549 unmap_str_32W_to_16(mdi_cs16
->szClass
);
2550 HeapFree(GetProcessHeap(), 0, mdi_cs16
);
2552 HeapFree( GetProcessHeap(), 0, cs
);
2557 MDICREATESTRUCT16
*cs
= MapSL(p16
->lParam
);
2558 UnMapLS( p16
->lParam
);
2559 unmap_str_32W_to_16( cs
->szTitle
);
2560 unmap_str_32W_to_16( cs
->szClass
);
2561 HeapFree( GetProcessHeap(), 0, cs
);
2565 case WM_ASKCBFORMATNAME
:
2567 LPSTR str
= MapSL(p16
->lParam
);
2568 UnMapLS( p16
->lParam
);
2569 p16
->lParam
= *((LPARAM
*)str
- 1);
2570 MultiByteToWideChar( CP_ACP
, 0, str
, -1, (LPWSTR
)p16
->lParam
, 0x7fffffff );
2571 p16
->lResult
= strlenW( (LPWSTR
)p16
->lParam
);
2572 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
- 1 );
2577 if ( WINPROC_TestLBForStr( hwnd
, msg
))
2579 LPSTR str
= MapSL(p16
->lParam
);
2580 UnMapLS( p16
->lParam
);
2581 p16
->lResult
= MultiByteToWideChar( CP_ACP
, 0, str
, -1, (LPWSTR
)lParam
, 0x7fffffff ) - 1;
2582 HeapFree( GetProcessHeap(), 0, (LPARAM
*)str
);
2586 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, p16
);
2592 /**********************************************************************
2593 * WINPROC_CallProc32ATo32W
2595 * Call a window procedure, translating args from Ansi to Unicode.
2597 static LRESULT
WINPROC_CallProc32ATo32W( WNDPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
,
2598 LPARAM lParam
, BOOL dialog
)
2603 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2604 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2606 if( (unmap
= WINPROC_MapMsg32ATo32W( hwnd
, msg
, &wParam
, &lParam
)) == -1) {
2607 ERR_(msg
)("Message translation failed. (msg=%s,wp=%08x,lp=%08lx)\n",
2608 SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2611 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2616 LRESULT result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
2617 result
= WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
, result
, NULL
);
2618 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2620 else ret
= WINPROC_UnmapMsg32ATo32W( hwnd
, msg
, wParam
, lParam
, ret
, func
);
2626 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
2628 if (size
>= need
) return static_buffer
;
2629 return HeapAlloc( GetProcessHeap(), 0, need
);
2632 static inline void free_buffer( void *static_buffer
, void *buffer
)
2634 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
2637 /**********************************************************************
2638 * WINPROC_CallProc32WTo32A
2640 * Call a window procedure, translating args from Unicode to Ansi.
2642 static LRESULT
WINPROC_CallProc32WTo32A( WNDPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
,
2643 LPARAM lParam
, BOOL dialog
)
2647 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2648 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2654 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
2657 char buffer
[1024], *cls
, *name
;
2658 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
2659 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
2660 MDICREATESTRUCTA mdi_cs
;
2661 DWORD name_lenA
, name_lenW
, class_lenA
, class_lenW
;
2663 class_lenW
= strlenW(csW
->lpszClass
) * sizeof(WCHAR
);
2664 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
2668 name_lenW
= strlenW(csW
->lpszName
) * sizeof(WCHAR
);
2669 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
2672 name_lenW
= name_lenA
= 0;
2674 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
+ 2 ))) break;
2676 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
2677 cls
[class_lenA
] = 0;
2678 csA
.lpszClass
= cls
;
2682 name
= cls
+ class_lenA
+ 1;
2683 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
2684 name
[name_lenA
] = 0;
2685 csA
.lpszName
= name
;
2688 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
2690 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
2691 mdi_cs
.szTitle
= csA
.lpszName
;
2692 mdi_cs
.szClass
= csA
.lpszClass
;
2693 csA
.lpCreateParams
= &mdi_cs
;
2696 ret
= WINPROC_CallWndProc(func
, hwnd
, msg
, wParam
, (LPARAM
)&csA
);
2697 free_buffer( buffer
, cls
);
2702 case WM_ASKCBFORMATNAME
:
2704 char *ptr
, buffer
[512];
2705 DWORD len
= wParam
* 2;
2707 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
2708 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, len
, (LPARAM
)ptr
);
2711 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, strlen(ptr
)+1 );
2712 ret
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
2713 ((LPWSTR
)lParam
)[ret
] = 0;
2716 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, ret
);
2720 free_buffer( buffer
, ptr
);
2725 case LB_INSERTSTRING
:
2727 case LB_FINDSTRINGEXACT
:
2728 case LB_SELECTSTRING
:
2730 case CB_INSERTSTRING
:
2732 case CB_FINDSTRINGEXACT
:
2733 case CB_SELECTSTRING
:
2734 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
2736 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2741 case WM_WININICHANGE
:
2742 case WM_DEVMODECHANGE
:
2747 if (!lParam
) ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2750 char *ptr
, buffer
[512];
2751 LPCWSTR strW
= (LPCWSTR
)lParam
;
2752 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
2754 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
2755 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
2757 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
2758 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, (LPARAM
)ptr
);
2759 free_buffer( buffer
, ptr
);
2766 char *ptr
, buffer
[1024];
2767 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
2768 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
2769 MDICREATESTRUCTA csA
;
2771 memcpy( &csA
, csW
, sizeof(csA
) );
2773 if (HIWORD(csW
->szTitle
))
2775 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
2776 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
2778 if (HIWORD(csW
->szClass
))
2780 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
2781 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
2784 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
2788 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
2793 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
2794 csA
.szClass
= ptr
+ title_lenA
;
2796 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, (LPARAM
)&csA
);
2797 free_buffer( buffer
, ptr
);
2803 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
2805 char buffer
[512]; /* FIXME: fixed sized buffer */
2808 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, (LPARAM
)buffer
);
2809 result
= dialog
? GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
) : ret
;
2813 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
2814 result
= len
/ sizeof(WCHAR
) - 1;
2815 if (dialog
) SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2819 else ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2824 char *ptr
, buffer
[512];
2825 WORD len
= *(WORD
*)lParam
;
2828 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
2829 *((WORD
*)ptr
) = len
* 2; /* store the length */
2830 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, (LPARAM
)ptr
);
2831 result
= dialog
? GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
) : ret
;
2834 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &result
, buffer
, result
);
2835 result
/= sizeof(WCHAR
);
2836 if (result
< len
) ((LPWSTR
)lParam
)[result
] = 0;
2837 if (dialog
) SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2840 free_buffer( buffer
, ptr
);
2849 case WM_SYSDEADCHAR
:
2850 case EM_SETPASSWORDCHAR
:
2851 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
);
2855 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
);
2858 case WM_PAINTCLIPBOARD
:
2859 case WM_SIZECLIPBOARD
:
2860 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
2861 SPY_GetMsgName(msg
, hwnd
), msg
);
2865 ret
= WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
2873 /**********************************************************************
2874 * WINPROC_CallProc16To32A
2876 static LRESULT
WINPROC_CallProc16To32A( WNDPROC func
, HWND16 hwnd
, UINT16 msg
,
2877 WPARAM16 wParam
, LPARAM lParam
, BOOL dialog
)
2882 HWND hwnd32
= WIN_Handle32( hwnd
);
2884 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2885 func
, hwnd32
, SPY_GetMsgName(msg
, hwnd32
), wParam
, lParam
);
2887 if (WINPROC_MapMsg16To32A( hwnd32
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2889 ret
= WINPROC_CallWndProc( func
, hwnd32
, msg32
, wParam32
, lParam
);
2892 LRESULT result
= GetWindowLongPtrW( hwnd32
, DWLP_MSGRESULT
);
2893 result
= WINPROC_UnmapMsg16To32A( hwnd32
, msg32
, wParam32
, lParam
, result
);
2894 SetWindowLongPtrW( hwnd32
, DWLP_MSGRESULT
, result
);
2896 else ret
= WINPROC_UnmapMsg16To32A( hwnd32
, msg32
, wParam32
, lParam
, ret
);
2902 /**********************************************************************
2903 * WINPROC_CallProc16To32W
2905 static LRESULT
WINPROC_CallProc16To32W( WNDPROC func
, HWND16 hwnd
, UINT16 msg
,
2906 WPARAM16 wParam
, LPARAM lParam
, BOOL dialog
)
2911 HWND hwnd32
= WIN_Handle32( hwnd
);
2913 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2914 func
, hwnd32
, SPY_GetMsgName(msg
, hwnd32
), wParam
, lParam
);
2916 if (WINPROC_MapMsg16To32W( hwnd32
, msg
, wParam
, &msg32
, &wParam32
, &lParam
) == -1)
2919 ret
= WINPROC_CallWndProc( func
, hwnd32
, msg32
, wParam32
, lParam
);
2922 LRESULT result
= GetWindowLongPtrW( hwnd32
, DWLP_MSGRESULT
);
2923 result
= WINPROC_UnmapMsg16To32W( hwnd32
, msg32
, wParam32
, lParam
, result
, NULL
);
2924 SetWindowLongPtrW( hwnd32
, DWLP_MSGRESULT
, result
);
2926 else ret
= WINPROC_UnmapMsg16To32W( hwnd32
, msg32
, wParam32
, lParam
, ret
, func
);
2932 /**********************************************************************
2933 * __wine_call_wndproc (USER.1010)
2935 LRESULT WINAPI
__wine_call_wndproc( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
2938 if (proc
->procA
) return WINPROC_CallProc16To32A( proc
->procA
, hwnd
, msg
, wParam
, lParam
, FALSE
);
2939 else return WINPROC_CallProc16To32W( proc
->procW
, hwnd
, msg
, wParam
, lParam
, FALSE
);
2943 /**********************************************************************
2944 * WINPROC_CallProc32ATo16
2946 * Call a 16-bit window procedure, translating the 32-bit args.
2948 static LRESULT
WINPROC_CallProc32ATo16( WNDPROC16 func
, HWND hwnd
, UINT msg
,
2949 WPARAM wParam
, LPARAM lParam
, BOOL dialog
)
2955 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2956 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2958 mp16
.lParam
= lParam
;
2959 if (WINPROC_MapMsg32ATo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
, &mp16
.lParam
) == -1)
2961 ret
= WINPROC_CallWndProc16( func
, HWND_16(hwnd
), msg16
, mp16
.wParam
, mp16
.lParam
);
2964 mp16
.lResult
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
2965 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2966 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, mp16
.lResult
);
2972 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
2979 /**********************************************************************
2980 * WINPROC_CallProc32WTo16
2982 * Call a 16-bit window procedure, translating the 32-bit args.
2984 static LRESULT
WINPROC_CallProc32WTo16( WNDPROC16 func
, HWND hwnd
, UINT msg
,
2985 WPARAM wParam
, LPARAM lParam
, BOOL dialog
)
2991 TRACE_(msg
)("func %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
2992 func
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
2994 mp16
.lParam
= lParam
;
2995 if (WINPROC_MapMsg32WTo16( hwnd
, msg
, wParam
, &msg16
, &mp16
.wParam
, &mp16
.lParam
) == -1)
2997 ret
= WINPROC_CallWndProc16( func
, HWND_16(hwnd
), msg16
, mp16
.wParam
, mp16
.lParam
);
3000 mp16
.lResult
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
3001 WINPROC_UnmapMsg32WTo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
3002 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, mp16
.lResult
);
3008 WINPROC_UnmapMsg32WTo16( hwnd
, msg
, wParam
, lParam
, &mp16
);
3015 /**********************************************************************
3016 * CallWindowProc (USER.122)
3018 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
3019 WPARAM16 wParam
, LPARAM lParam
)
3023 if (!func
) return 0;
3025 if (!(proc
= handle16_to_proc( func
)))
3026 return WINPROC_CallWndProc16( func
, hwnd
, msg
, wParam
, lParam
);
3028 if (proc
->procA
) return WINPROC_CallProc16To32A( proc
->procA
, hwnd
, msg
, wParam
, lParam
, FALSE
);
3029 if (proc
->procW
) return WINPROC_CallProc16To32W( proc
->procW
, hwnd
, msg
, wParam
, lParam
, FALSE
);
3030 return WINPROC_CallWndProc16( proc
->proc16
, hwnd
, msg
, wParam
, lParam
);
3034 /**********************************************************************
3035 * CallWindowProcA (USER32.@)
3037 * The CallWindowProc() function invokes the windows procedure _func_,
3038 * with _hwnd_ as the target window, the message specified by _msg_, and
3039 * the message parameters _wParam_ and _lParam_.
3041 * Some kinds of argument conversion may be done, I'm not sure what.
3043 * CallWindowProc() may be used for windows subclassing. Use
3044 * SetWindowLong() to set a new windows procedure for windows of the
3045 * subclass, and handle subclassed messages in the new windows
3046 * procedure. The new windows procedure may then use CallWindowProc()
3047 * with _func_ set to the parent class's windows procedure to dispatch
3048 * the message to the superclass.
3052 * The return value is message dependent.
3058 LRESULT WINAPI
CallWindowProcA(
3059 WNDPROC func
, /* [in] window procedure */
3060 HWND hwnd
, /* [in] target window */
3061 UINT msg
, /* [in] message */
3062 WPARAM wParam
, /* [in] message dependent parameter */
3063 LPARAM lParam
/* [in] message dependent parameter */
3067 if (!func
) return 0;
3069 if (!(proc
= handle_to_proc( func
)))
3070 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
3072 if (proc
->procA
) return WINPROC_CallWndProc( proc
->procA
, hwnd
, msg
, wParam
, lParam
);
3073 if (proc
->procW
) return WINPROC_CallProc32ATo32W( proc
->procW
, hwnd
, msg
, wParam
, lParam
, FALSE
);
3074 return WINPROC_CallProc32ATo16( proc
->proc16
, hwnd
, msg
, wParam
, lParam
, FALSE
);
3078 /**********************************************************************
3079 * CallWindowProcW (USER32.@)
3081 * See CallWindowProcA.
3083 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
3084 WPARAM wParam
, LPARAM lParam
)
3088 if (!func
) return 0;
3090 if (!(proc
= handle_to_proc( func
)))
3091 return WINPROC_CallWndProc( func
, hwnd
, msg
, wParam
, lParam
);
3093 if (proc
->procW
) return WINPROC_CallWndProc( proc
->procW
, hwnd
, msg
, wParam
, lParam
);
3094 if (proc
->procA
) return WINPROC_CallProc32WTo32A( proc
->procA
, hwnd
, msg
, wParam
, lParam
, FALSE
);
3095 return WINPROC_CallProc32WTo16( proc
->proc16
, hwnd
, msg
, wParam
, lParam
, FALSE
);
3099 /**********************************************************************
3100 * WINPROC_CallDlgProc16
3102 INT_PTR
WINPROC_CallDlgProc16( DLGPROC16 func
, HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
3106 if (!func
) return 0;
3108 if (!(proc
= handle16_to_proc( (WNDPROC16
)func
)))
3109 return LOWORD( WINPROC_CallWndProc16( (WNDPROC16
)func
, hwnd
, msg
, wParam
, lParam
) );
3111 if (proc
->procA
) return WINPROC_CallProc16To32A( proc
->procA
, hwnd
, msg
, wParam
, lParam
, TRUE
);
3112 if (proc
->procW
) return WINPROC_CallProc16To32W( proc
->procW
, hwnd
, msg
, wParam
, lParam
, TRUE
);
3113 return LOWORD( WINPROC_CallWndProc16( proc
->proc16
, hwnd
, msg
, wParam
, lParam
) );
3117 /**********************************************************************
3118 * WINPROC_CallDlgProcA
3120 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3124 if (!func
) return 0;
3126 if (!(proc
= handle_to_proc( (WNDPROC
)func
)))
3127 return WINPROC_CallWndProc( (WNDPROC
)func
, hwnd
, msg
, wParam
, lParam
);
3129 if (proc
->procA
) return WINPROC_CallWndProc( proc
->procA
, hwnd
, msg
, wParam
, lParam
);
3130 if (proc
->procW
) return WINPROC_CallProc32ATo32W( proc
->procW
, hwnd
, msg
, wParam
, lParam
, TRUE
);
3131 return WINPROC_CallProc32ATo16( proc
->proc16
, hwnd
, msg
, wParam
, lParam
, TRUE
);
3135 /**********************************************************************
3136 * WINPROC_CallDlgProcW
3138 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
3142 if (!func
) return 0;
3144 if (!(proc
= handle_to_proc( (WNDPROC
)func
)))
3145 return WINPROC_CallWndProc( (WNDPROC
)func
, hwnd
, msg
, wParam
, lParam
);
3147 if (proc
->procW
) return WINPROC_CallWndProc( proc
->procW
, hwnd
, msg
, wParam
, lParam
);
3148 if (proc
->procA
) return WINPROC_CallProc32WTo32A( proc
->procA
, hwnd
, msg
, wParam
, lParam
, TRUE
);
3149 return WINPROC_CallProc32WTo16( proc
->proc16
, hwnd
, msg
, wParam
, lParam
, TRUE
);