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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
72 if (size
>= need
) return static_buffer
;
73 return HeapAlloc( GetProcessHeap(), 0, need
);
76 static inline void free_buffer( void *static_buffer
, void *buffer
)
78 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
81 /* find an existing winproc for a given 16-bit function and type */
82 /* FIXME: probably should do something more clever than a linear search */
83 static inline WINDOWPROC
*find_winproc16( WNDPROC16 func
)
87 for (i
= 0; i
< winproc_used
; i
++)
89 if (winproc_array
[i
].proc16
== func
) return &winproc_array
[i
];
94 /* find an existing winproc for a given function and type */
95 /* FIXME: probably should do something more clever than a linear search */
96 static inline WINDOWPROC
*find_winproc( WNDPROC funcA
, WNDPROC funcW
)
100 for (i
= 0; i
< winproc_used
; i
++)
102 if (funcA
&& winproc_array
[i
].procA
!= funcA
) continue;
103 if (funcW
&& winproc_array
[i
].procW
!= funcW
) continue;
104 return &winproc_array
[i
];
109 /* return the window proc for a given handle, or NULL for an invalid handle */
110 static inline WINDOWPROC
*handle_to_proc( WNDPROC handle
)
112 UINT index
= LOWORD(handle
);
113 if ((ULONG_PTR
)handle
>> 16 != WINPROC_HANDLE
) return NULL
;
114 if (index
>= winproc_used
) return NULL
;
115 return &winproc_array
[index
];
118 /* create a handle for a given window proc */
119 static inline WNDPROC
proc_to_handle( WINDOWPROC
*proc
)
121 return (WNDPROC
)(ULONG_PTR
)((proc
- winproc_array
) | (WINPROC_HANDLE
<< 16));
124 /* allocate and initialize a new winproc */
125 static inline WINDOWPROC
*alloc_winproc( WNDPROC funcA
, WNDPROC funcW
)
129 /* check if the function is already a win proc */
130 if (funcA
&& (proc
= handle_to_proc( funcA
))) return proc
;
131 if (funcW
&& (proc
= handle_to_proc( funcW
))) return proc
;
132 if (!funcA
&& !funcW
) return NULL
;
134 EnterCriticalSection( &winproc_cs
);
136 /* check if we already have a winproc for that function */
137 if (!(proc
= find_winproc( funcA
, funcW
)))
139 if (winproc_used
< MAX_WINPROCS
)
141 proc
= &winproc_array
[winproc_used
++];
144 TRACE( "allocated %p for %p/%p (%d/%d used)\n",
145 proc_to_handle(proc
), funcA
, funcW
, winproc_used
, MAX_WINPROCS
);
147 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA
, funcW
);
149 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc
), funcA
, funcW
);
151 LeaveCriticalSection( &winproc_cs
);
158 #include "pshpack1.h"
160 /* Window procedure 16-to-32-bit thunk */
163 BYTE popl_eax
; /* popl %eax (return address) */
164 BYTE pushl_func
; /* pushl $proc */
166 BYTE pushl_eax
; /* pushl %eax */
167 BYTE ljmp
; /* ljmp relay*/
168 DWORD relay_offset
; /* __wine_call_wndproc */
174 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
176 static WINPROC_THUNK
*thunk_array
;
177 static UINT thunk_selector
;
178 static UINT thunk_used
;
180 /* return the window proc for a given handle, or NULL for an invalid handle */
181 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
183 if (HIWORD(handle
) == thunk_selector
)
185 UINT index
= LOWORD(handle
) / sizeof(WINPROC_THUNK
);
186 /* check alignment */
187 if (index
* sizeof(WINPROC_THUNK
) != LOWORD(handle
)) return NULL
;
188 /* check array limits */
189 if (index
>= thunk_used
) return NULL
;
190 return thunk_array
[index
].proc
;
192 return handle_to_proc( (WNDPROC
)handle
);
195 /* allocate a 16-bit thunk for an existing window proc */
196 static WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
198 static FARPROC16 relay
;
201 if (proc
->proc16
) return proc
->proc16
;
203 EnterCriticalSection( &winproc_cs
);
205 if (!thunk_array
) /* allocate the array and its selector */
209 if (!(thunk_selector
= wine_ldt_alloc_entries(1))) goto done
;
210 if (!(thunk_array
= VirtualAlloc( NULL
, MAX_THUNKS
* sizeof(WINPROC_THUNK
), MEM_COMMIT
,
211 PAGE_EXECUTE_READWRITE
))) goto done
;
212 wine_ldt_set_base( &entry
, thunk_array
);
213 wine_ldt_set_limit( &entry
, MAX_THUNKS
* sizeof(WINPROC_THUNK
) - 1 );
214 wine_ldt_set_flags( &entry
, WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
215 wine_ldt_set_entry( thunk_selector
, &entry
);
216 relay
= GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
219 /* check if it already exists */
220 for (i
= 0; i
< thunk_used
; i
++) if (thunk_array
[i
].proc
== proc
) break;
222 if (i
== thunk_used
) /* create a new one */
224 WINPROC_THUNK
*thunk
;
226 if (thunk_used
>= MAX_THUNKS
) goto done
;
227 thunk
= &thunk_array
[thunk_used
++];
228 thunk
->popl_eax
= 0x58; /* popl %eax */
229 thunk
->pushl_func
= 0x68; /* pushl $proc */
231 thunk
->pushl_eax
= 0x50; /* pushl %eax */
232 thunk
->ljmp
= 0xea; /* ljmp relay*/
233 thunk
->relay_offset
= OFFSETOF(relay
);
234 thunk
->relay_sel
= SELECTOROF(relay
);
236 proc
->proc16
= (WNDPROC16
)MAKESEGPTR( thunk_selector
, i
* sizeof(WINPROC_THUNK
) );
238 LeaveCriticalSection( &winproc_cs
);
244 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
246 return handle_to_proc( (WNDPROC
)handle
);
249 static inline WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
254 #endif /* __i386__ */
258 /* Some window procedures modify register they shouldn't, or are not
259 * properly declared stdcall; so we need a small assembly wrapper to
261 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
262 WPARAM wParam
, LPARAM lParam
);
263 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
274 "movl 8(%ebp),%eax\n\t"
276 "leal -12(%ebp),%esp\n\t"
283 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
284 WPARAM wParam
, LPARAM lParam
)
286 return proc( hwnd
, msg
, wParam
, lParam
);
288 #endif /* __i386__ */
290 static void RECT16to32( const RECT16
*from
, RECT
*to
)
292 to
->left
= from
->left
;
294 to
->right
= from
->right
;
295 to
->bottom
= from
->bottom
;
298 static void RECT32to16( const RECT
*from
, RECT16
*to
)
300 to
->left
= from
->left
;
302 to
->right
= from
->right
;
303 to
->bottom
= from
->bottom
;
306 static void MINMAXINFO32to16( const MINMAXINFO
*from
, MINMAXINFO16
*to
)
308 to
->ptReserved
.x
= from
->ptReserved
.x
;
309 to
->ptReserved
.y
= from
->ptReserved
.y
;
310 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
311 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
312 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
313 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
314 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
315 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
316 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
317 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
320 static void MINMAXINFO16to32( const MINMAXINFO16
*from
, MINMAXINFO
*to
)
322 to
->ptReserved
.x
= from
->ptReserved
.x
;
323 to
->ptReserved
.y
= from
->ptReserved
.y
;
324 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
325 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
326 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
327 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
328 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
329 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
330 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
331 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
334 static void WINDOWPOS32to16( const WINDOWPOS
* from
, WINDOWPOS16
* to
)
336 to
->hwnd
= HWND_16(from
->hwnd
);
337 to
->hwndInsertAfter
= HWND_16(from
->hwndInsertAfter
);
342 to
->flags
= from
->flags
;
345 static void WINDOWPOS16to32( const WINDOWPOS16
* from
, WINDOWPOS
* to
)
347 to
->hwnd
= WIN_Handle32(from
->hwnd
);
348 to
->hwndInsertAfter
= (from
->hwndInsertAfter
== (HWND16
)-1) ?
349 HWND_TOPMOST
: WIN_Handle32(from
->hwndInsertAfter
);
354 to
->flags
= from
->flags
;
357 /* The strings are not copied */
358 static void CREATESTRUCT32Ato16( const CREATESTRUCTA
* from
, CREATESTRUCT16
* to
)
360 to
->lpCreateParams
= (SEGPTR
)from
->lpCreateParams
;
361 to
->hInstance
= HINSTANCE_16(from
->hInstance
);
362 to
->hMenu
= HMENU_16(from
->hMenu
);
363 to
->hwndParent
= HWND_16(from
->hwndParent
);
368 to
->style
= from
->style
;
369 to
->dwExStyle
= from
->dwExStyle
;
372 static void CREATESTRUCT16to32A( const CREATESTRUCT16
* from
, CREATESTRUCTA
*to
)
375 to
->lpCreateParams
= (LPVOID
)from
->lpCreateParams
;
376 to
->hInstance
= HINSTANCE_32(from
->hInstance
);
377 to
->hMenu
= HMENU_32(from
->hMenu
);
378 to
->hwndParent
= WIN_Handle32(from
->hwndParent
);
383 to
->style
= from
->style
;
384 to
->dwExStyle
= from
->dwExStyle
;
385 to
->lpszName
= MapSL(from
->lpszName
);
386 to
->lpszClass
= MapSL(from
->lpszClass
);
389 /* The strings are not copied */
390 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA
* from
, MDICREATESTRUCT16
* to
)
392 to
->hOwner
= HINSTANCE_16(from
->hOwner
);
397 to
->style
= from
->style
;
398 to
->lParam
= from
->lParam
;
401 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16
* from
, MDICREATESTRUCTA
*to
)
403 to
->hOwner
= HINSTANCE_32(from
->hOwner
);
408 to
->style
= from
->style
;
409 to
->lParam
= from
->lParam
;
410 to
->szTitle
= MapSL(from
->szTitle
);
411 to
->szClass
= MapSL(from
->szClass
);
414 static WPARAM
map_wparam_char_AtoW( WPARAM wParam
, DWORD len
)
419 ch
[0] = (wParam
>> 8);
420 ch
[1] = wParam
& 0xff;
421 if (len
> 1 && ch
[0])
422 RtlMultiByteToUnicodeN( &wch
, sizeof(wch
), NULL
, ch
, 2 );
424 RtlMultiByteToUnicodeN( &wch
, sizeof(wch
), NULL
, ch
+ 1, 1 );
425 return MAKEWPARAM( wch
, HIWORD(wParam
) );
428 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
433 RtlUnicodeToMultiByteN( (LPSTR
)ch
, len
, &len
, &wch
, sizeof(wch
) );
435 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
437 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
440 /* call a 32-bit window procedure */
441 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
447 hwnd
= WIN_GetFullHandle( hwnd
);
449 DPRINTF( "%04lx:Call window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
450 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
452 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
455 DPRINTF( "%04lx:Ret window proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx\n",
456 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
460 /* call a 32-bit dialog procedure */
461 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
468 hwnd
= WIN_GetFullHandle( hwnd
);
470 DPRINTF( "%04lx:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
471 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
473 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
474 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
477 DPRINTF( "%04lx:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08x,lp=%08lx) retval=%08lx result=%08lx\n",
478 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
482 /* call a 16-bit window procedure */
483 static LRESULT
call_window_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
484 LRESULT
*result
, void *arg
)
486 WNDPROC16 proc
= arg
;
495 DRAWITEMSTRUCT16 dis16
;
496 COMPAREITEMSTRUCT16 cis16
;
502 /* Window procedures want ax = hInstance, ds = es = ss */
504 memset(&context
, 0, sizeof(context
));
505 context
.SegDs
= context
.SegEs
= SELECTOROF(NtCurrentTeb()->WOW32Reserved
);
506 context
.SegFs
= wine_get_fs();
507 context
.SegGs
= wine_get_gs();
508 if (!(context
.Eax
= GetWindowWord( HWND_32(hwnd
), GWLP_HINSTANCE
))) context
.Eax
= context
.SegDs
;
509 context
.SegCs
= SELECTOROF(proc
);
510 context
.Eip
= OFFSETOF(proc
);
511 context
.Ebp
= OFFSETOF(NtCurrentTeb()->WOW32Reserved
) + (WORD
)&((STACK16FRAME
*)0)->bp
;
515 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
516 work if structures passed in lParam are placed in the stack/data
517 segment. Programmers easily make the mistake of converting lParam
518 to a near rather than a far pointer, since Windows apparently
519 allows this. We copy the structures to the 16 bit stack; this is
520 ugly but makes these programs work. */
525 size
= sizeof(CREATESTRUCT16
); break;
527 size
= sizeof(DRAWITEMSTRUCT16
); break;
529 size
= sizeof(COMPAREITEMSTRUCT16
); break;
533 memcpy( &args
.u
, MapSL(lParam
), size
);
534 lParam
= (SEGPTR
)NtCurrentTeb()->WOW32Reserved
- size
;
538 args
.params
[4] = hwnd
;
539 args
.params
[3] = msg
;
540 args
.params
[2] = wParam
;
541 args
.params
[1] = HIWORD(lParam
);
542 args
.params
[0] = LOWORD(lParam
);
543 WOWCallback16Ex( 0, WCB16_REGS
, sizeof(args
.params
) + size
, &args
, (DWORD
*)&context
);
544 *result
= MAKELONG( LOWORD(context
.Eax
), LOWORD(context
.Edx
) );
548 /* call a 16-bit dialog procedure */
549 static LRESULT
call_dialog_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wp
, LPARAM lp
,
550 LRESULT
*result
, void *arg
)
552 LRESULT ret
= call_window_proc16( hwnd
, msg
, wp
, lp
, result
, arg
);
553 *result
= GetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
);
557 /* helper callback for 32W->16 conversion */
558 static LRESULT
call_window_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
559 LRESULT
*result
, void *arg
)
561 return WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
564 /* helper callback for 32W->16 conversion */
565 static LRESULT
call_dialog_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
566 LRESULT
*result
, void *arg
)
568 return WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
571 /* helper callback for 16->32W conversion */
572 static LRESULT
call_window_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
573 LRESULT
*result
, void *arg
)
575 return WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wp
, lp
, result
, arg
);
578 /* helper callback for 16->32W conversion */
579 static LRESULT
call_dialog_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
580 LRESULT
*result
, void *arg
)
582 return WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wp
, lp
, result
, arg
);
586 /**********************************************************************
589 * Get a window procedure pointer that can be passed to the Windows program.
591 WNDPROC16
WINPROC_GetProc16( WNDPROC proc
, BOOL unicode
)
595 if (unicode
) ptr
= alloc_winproc( NULL
, proc
);
596 else ptr
= alloc_winproc( proc
, NULL
);
599 return alloc_win16_thunk( ptr
);
603 /**********************************************************************
606 * Get a window procedure pointer that can be passed to the Windows program.
608 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
610 WINDOWPROC
*ptr
= handle_to_proc( proc
);
612 if (!ptr
) return proc
;
615 if (ptr
->procW
) return ptr
->procW
;
620 if (ptr
->procA
) return ptr
->procA
;
626 /**********************************************************************
627 * WINPROC_AllocProc16
629 * Allocate a window procedure for a window or class.
631 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
632 * lot of windows, it will usually only have a limited number of window procedures, so the
633 * array won't grow too large, and this way we avoid the need to track allocations per window.
635 WNDPROC
WINPROC_AllocProc16( WNDPROC16 func
)
639 if (!func
) return NULL
;
641 /* check if the function is already a win proc */
642 if (!(proc
= handle16_to_proc( func
)))
644 EnterCriticalSection( &winproc_cs
);
646 /* then check if we already have a winproc for that function */
647 if (!(proc
= find_winproc16( func
)))
649 if (winproc_used
< MAX_WINPROCS
)
651 proc
= &winproc_array
[winproc_used
++];
653 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
654 proc_to_handle(proc
), func
, winproc_used
, MAX_WINPROCS
);
656 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func
);
658 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc
), func
);
660 LeaveCriticalSection( &winproc_cs
);
662 return proc_to_handle( proc
);
666 /**********************************************************************
669 * Allocate a window procedure for a window or class.
671 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
672 * lot of windows, it will usually only have a limited number of window procedures, so the
673 * array won't grow too large, and this way we avoid the need to track allocations per window.
675 WNDPROC
WINPROC_AllocProc( WNDPROC funcA
, WNDPROC funcW
)
679 if (!(proc
= alloc_winproc( funcA
, funcW
))) return NULL
;
680 return proc_to_handle( proc
);
684 /**********************************************************************
687 * Return the window procedure type, or the default value if not a winproc handle.
689 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
691 WINDOWPROC
*ptr
= handle_to_proc( proc
);
693 if (!ptr
) return def_val
;
694 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
695 return (ptr
->procW
!= NULL
);
699 /**********************************************************************
700 * WINPROC_TestLBForStr
702 * Return TRUE if the lparam is a string
704 inline static BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
706 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
707 if (msg
<= CB_MSGMAX
)
708 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
710 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
715 static UINT
convert_handle_16_to_32(HANDLE16 src
, unsigned int flags
)
718 UINT sz
= GlobalSize16(src
);
721 if (!(dst
= GlobalAlloc(flags
, sz
)))
723 ptr16
= GlobalLock16(src
);
724 ptr32
= GlobalLock(dst
);
725 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr32
, ptr16
, sz
);
732 static HANDLE16
convert_handle_32_to_16(UINT src
, unsigned int flags
)
735 UINT sz
= GlobalSize((HANDLE
)src
);
738 if (!(dst
= GlobalAlloc16(flags
, sz
)))
740 ptr32
= GlobalLock((HANDLE
)src
);
741 ptr16
= GlobalLock16(dst
);
742 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr16
, ptr32
, sz
);
743 GlobalUnlock((HANDLE
)src
);
750 /**********************************************************************
751 * WINPROC_MapMsg32ATo16
753 * Map a message from 32-bit Ansi to 16-bit.
754 * Return value is -1 on error, 0 if OK, 1 if an UnmapMsg call is needed.
756 static INT
WINPROC_MapMsg32ATo16( HWND hwnd
, UINT msg32
, WPARAM wParam32
,
757 UINT16
*pmsg16
, WPARAM16
*pwparam16
, LPARAM
*plparam
)
759 *pmsg16
= (UINT16
)msg32
;
760 *pwparam16
= (WPARAM16
)LOWORD(wParam32
);
765 case LB_DELETESTRING
:
766 case LB_GETANCHORINDEX
:
767 case LB_GETCARETINDEX
:
770 case LB_GETHORIZONTALEXTENT
:
772 case LB_GETITEMHEIGHT
:
777 case LB_RESETCONTENT
:
778 case LB_SELITEMRANGE
:
779 case LB_SELITEMRANGEEX
:
780 case LB_SETANCHORINDEX
:
781 case LB_SETCARETINDEX
:
782 case LB_SETCOLUMNWIDTH
:
784 case LB_SETHORIZONTALEXTENT
:
786 case LB_SETITEMHEIGHT
:
789 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
791 case CB_DELETESTRING
:
793 case CB_GETLBTEXTLEN
:
795 case CB_RESETCONTENT
:
799 case CB_SHOWDROPDOWN
:
801 case CB_SETITEMHEIGHT
:
802 case CB_GETITEMHEIGHT
:
803 case CB_SETEXTENDEDUI
:
804 case CB_GETEXTENDEDUI
:
805 case CB_GETDROPPEDSTATE
:
806 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
809 *pmsg16
= CB_GETEDITSEL16
;
814 case LB_FINDSTRINGEXACT
:
815 case LB_INSERTSTRING
:
816 case LB_SELECTSTRING
:
819 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
820 *pmsg16
= (UINT16
)msg32
+ (LB_ADDSTRING16
- LB_ADDSTRING
);
825 case CB_FINDSTRINGEXACT
:
826 case CB_INSERTSTRING
:
827 case CB_SELECTSTRING
:
829 *plparam
= (LPARAM
)MapLS( (LPSTR
)*plparam
);
830 *pmsg16
= (UINT16
)msg32
+ (CB_GETEDITSEL16
- CB_GETEDITSEL
);
835 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
836 if (!rect
) return -1;
837 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
838 *plparam
= MapLS( rect
);
840 *pmsg16
= LB_GETITEMRECT16
;
844 LPARAM
*items
; /* old LPARAM first, then *pwparam16 x INT16 entries */
846 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
847 if (!(items
= HeapAlloc( GetProcessHeap(), 0,
848 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
849 *items
++ = *plparam
; /* Store the previous lParam */
850 *plparam
= MapLS( items
);
852 *pmsg16
= LB_GETSELITEMS16
;
859 *pwparam16
= (WPARAM16
)min( wParam32
, 0x7f80 ); /* Must be < 64K */
860 if (!(stops
= HeapAlloc( GetProcessHeap(), 0,
861 *pwparam16
* sizeof(INT16
) + sizeof(LPARAM
)))) return -1;
862 for (i
= 0; i
< *pwparam16
; i
++) stops
[i
] = *((LPINT
)*plparam
+i
);
863 *plparam
= MapLS( stops
);
866 *pmsg16
= LB_SETTABSTOPS16
;
869 case CB_GETDROPPEDCONTROLRECT
:
871 RECT16
*rect
= HeapAlloc( GetProcessHeap(), 0, sizeof(RECT16
) + sizeof(LPARAM
) );
872 if (!rect
) return -1;
873 *(LPARAM
*)(rect
+ 1) = *plparam
; /* Store the previous lParam */
874 *plparam
= (LPARAM
)MapLS(rect
);
876 *pmsg16
= CB_GETDROPPEDCONTROLRECT16
;
880 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
881 *pmsg16
= LB_GETTEXT16
;
885 *plparam
= (LPARAM
)MapLS( (LPVOID
)(*plparam
) );
886 *pmsg16
= CB_GETLBTEXT16
;
893 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
) );
897 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HWND16
)*plparam
);
899 case WM_CTLCOLORMSGBOX
:
900 case WM_CTLCOLOREDIT
:
901 case WM_CTLCOLORLISTBOX
:
904 case WM_CTLCOLORSCROLLBAR
:
905 case WM_CTLCOLORSTATIC
:
906 *pmsg16
= WM_CTLCOLOR
;
907 *plparam
= MAKELPARAM( (HWND16
)*plparam
,
908 (WORD
)msg32
- WM_CTLCOLORMSGBOX
);
911 if(HIWORD(wParam32
) & MF_POPUP
)
914 if (((UINT
)HIWORD(wParam32
) != 0xFFFF) || (*plparam
))
916 if((hmenu
= GetSubMenu((HMENU
)*plparam
, *pwparam16
)))
917 *pwparam16
=HMENU_16(hmenu
);
922 *plparam
= MAKELPARAM( HIWORD(wParam32
), (HMENU16
)*plparam
);
924 case WM_PARENTNOTIFY
:
925 if ((LOWORD(wParam32
)==WM_CREATE
) || (LOWORD(wParam32
)==WM_DESTROY
))
926 *plparam
= MAKELPARAM( (HWND16
)*plparam
, HIWORD(wParam32
));
927 /* else nothing to do */
930 if (*plparam
) *plparam
= HTASK_16( (HANDLE
)*plparam
);
933 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
))
935 *pmsg16
= WM_PAINTICON
;
940 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
))
941 *pmsg16
= WM_ICONERASEBKGND
;
943 case WM_PAINTCLIPBOARD
:
944 case WM_SIZECLIPBOARD
:
945 FIXME_(msg
)("message %04x needs translation\n", msg32
);
947 /* following messages should not be sent to 16-bit apps */
950 case WM_CAPTURECHANGED
:
951 case WM_STYLECHANGING
:
952 case WM_STYLECHANGED
:
954 default: /* No translation needed */
960 /**********************************************************************
961 * WINPROC_UnmapMsg32ATo16
963 * Unmap a message that was mapped from 32-bit Ansi to 16-bit.
965 static void WINPROC_UnmapMsg32ATo16( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
966 WPARAM16 wParam16
, LPARAM lParam16
, LRESULT
*result
)
974 case LB_FINDSTRINGEXACT
:
975 case LB_INSERTSTRING
:
976 case LB_SELECTSTRING
:
980 case CB_FINDSTRINGEXACT
:
981 case CB_INSERTSTRING
:
982 case CB_SELECTSTRING
:
985 UnMapLS( (SEGPTR
)lParam16
);
989 void *ptr
= MapSL( lParam16
);
991 HeapFree( GetProcessHeap(), 0, ptr
);
994 case CB_GETDROPPEDCONTROLRECT
:
998 RECT16
*rect
= MapSL(lParam16
);
1000 lParam16
= *(LPARAM
*)(rect
+ 1);
1001 r32
= (RECT
*)lParam16
;
1002 r32
->left
= rect
->left
;
1003 r32
->top
= rect
->top
;
1004 r32
->right
= rect
->right
;
1005 r32
->bottom
= rect
->bottom
;
1006 HeapFree( GetProcessHeap(), 0, rect
);
1009 case LB_GETSELITEMS
:
1012 LPINT16 items
= MapSL(lParam16
);
1013 UnMapLS( lParam16
);
1014 lParam16
= *((LPARAM
*)items
- 1);
1015 for (i
= 0; i
< wParam16
; i
++) *((LPINT
)lParam16
+ i
) = items
[i
];
1016 HeapFree( GetProcessHeap(), 0, (LPARAM
*)items
- 1 );
1022 *((PUINT
)(wParam
)) = LOWORD(*result
);
1024 *((PUINT
)(lParam
)) = HIWORD(*result
); /* FIXME: substract 1? */
1030 /**********************************************************************
1031 * WINPROC_CallProcAtoW
1033 * Call a window procedure, translating args from Ansi to Unicode.
1035 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
1036 LPARAM lParam
, LRESULT
*result
, void *arg
)
1040 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1041 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1048 WCHAR
*ptr
, buffer
[512];
1049 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
1050 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
1051 MDICREATESTRUCTW mdi_cs
;
1052 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1054 if (HIWORD(csA
->lpszClass
))
1056 class_lenA
= strlen(csA
->lpszClass
) + 1;
1057 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
1059 if (HIWORD(csA
->lpszName
))
1061 name_lenA
= strlen(csA
->lpszName
) + 1;
1062 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
1065 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
1069 csW
.lpszClass
= ptr
;
1070 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
1074 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
1075 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
1076 csA
->lpszName
, name_lenA
);
1079 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1081 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
1082 mdi_cs
.szTitle
= csW
.lpszName
;
1083 mdi_cs
.szClass
= csW
.lpszClass
;
1084 csW
.lpCreateParams
= &mdi_cs
;
1087 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
1088 free_buffer( buffer
, ptr
);
1094 WCHAR
*ptr
, buffer
[512];
1095 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1096 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
1097 MDICREATESTRUCTW csW
;
1099 memcpy( &csW
, csA
, sizeof(csW
) );
1101 if (HIWORD(csA
->szTitle
))
1103 title_lenA
= strlen(csA
->szTitle
) + 1;
1104 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
1106 if (HIWORD(csA
->szClass
))
1108 class_lenA
= strlen(csA
->szClass
) + 1;
1109 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
1112 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
1117 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
1121 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
1122 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
1123 csA
->szClass
, class_lenA
);
1125 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
1126 free_buffer( buffer
, ptr
);
1131 case WM_ASKCBFORMATNAME
:
1133 WCHAR
*ptr
, buffer
[512];
1134 LPSTR str
= (LPSTR
)lParam
;
1135 DWORD len
= wParam
* sizeof(WCHAR
);
1137 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
1138 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1139 if (*result
&& wParam
)
1141 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, strlenW(ptr
) * sizeof(WCHAR
) );
1145 free_buffer( buffer
, ptr
);
1150 case LB_INSERTSTRING
:
1152 case LB_FINDSTRINGEXACT
:
1153 case LB_SELECTSTRING
:
1155 case CB_INSERTSTRING
:
1157 case CB_FINDSTRINGEXACT
:
1158 case CB_SELECTSTRING
:
1159 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
1161 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1166 case WM_WININICHANGE
:
1167 case WM_DEVMODECHANGE
:
1172 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1175 WCHAR
*ptr
, buffer
[512];
1176 LPCSTR strA
= (LPCSTR
)lParam
;
1177 DWORD lenW
, lenA
= strlen(strA
) + 1;
1179 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
1180 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
1182 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
1183 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1184 free_buffer( buffer
, ptr
);
1191 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
1193 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
1195 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
1199 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
1200 buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
1204 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1209 WCHAR
*ptr
, buffer
[512];
1210 WORD len
= *(WORD
*)lParam
;
1212 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
1213 *((WORD
*)ptr
) = len
; /* store the length */
1214 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1218 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
1219 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
1222 free_buffer( buffer
, ptr
);
1229 MSG newmsg
= *(MSG
*)lParam
;
1230 switch(newmsg
.message
)
1235 case WM_SYSDEADCHAR
:
1236 newmsg
.wParam
= map_wparam_char_AtoW( newmsg
.wParam
, 1 );
1239 newmsg
.wParam
= map_wparam_char_AtoW( newmsg
.wParam
, 2 );
1242 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
1244 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1252 case WM_SYSDEADCHAR
:
1253 case EM_SETPASSWORDCHAR
:
1254 ret
= callback( hwnd
, msg
, map_wparam_char_AtoW(wParam
,1), lParam
, result
, arg
);
1258 ret
= callback( hwnd
, msg
, map_wparam_char_AtoW(wParam
,2), lParam
, result
, arg
);
1261 case WM_GETTEXTLENGTH
:
1262 case CB_GETLBTEXTLEN
:
1264 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1267 WCHAR
*ptr
, buffer
[512];
1269 DWORD len
= *result
+ 1;
1270 /* Determine respective GETTEXT message */
1271 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
1272 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
1273 /* wParam differs between the messages */
1274 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
1276 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
1278 if (callback
== call_window_proc
) /* FIXME: hack */
1279 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
1281 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
1282 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
1284 free_buffer( buffer
, ptr
);
1288 case WM_PAINTCLIPBOARD
:
1289 case WM_SIZECLIPBOARD
:
1290 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
1291 SPY_GetMsgName(msg
, hwnd
), msg
);
1295 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1302 /**********************************************************************
1303 * WINPROC_CallProcWtoA
1305 * Call a window procedure, translating args from Unicode to Ansi.
1307 static LRESULT
WINPROC_CallProcWtoA( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
1308 LPARAM lParam
, LRESULT
*result
, void *arg
)
1312 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1313 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1319 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
1322 char buffer
[1024], *cls
, *name
;
1323 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
1324 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
1325 MDICREATESTRUCTA mdi_cs
;
1326 DWORD name_lenA
, name_lenW
, class_lenA
, class_lenW
;
1328 class_lenW
= strlenW(csW
->lpszClass
) * sizeof(WCHAR
);
1329 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
1333 name_lenW
= strlenW(csW
->lpszName
) * sizeof(WCHAR
);
1334 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
1337 name_lenW
= name_lenA
= 0;
1339 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
+ 2 ))) break;
1341 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
1342 cls
[class_lenA
] = 0;
1343 csA
.lpszClass
= cls
;
1347 name
= cls
+ class_lenA
+ 1;
1348 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
1349 name
[name_lenA
] = 0;
1350 csA
.lpszName
= name
;
1353 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1355 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
1356 mdi_cs
.szTitle
= csA
.lpszName
;
1357 mdi_cs
.szClass
= csA
.lpszClass
;
1358 csA
.lpCreateParams
= &mdi_cs
;
1361 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1362 free_buffer( buffer
, cls
);
1367 case WM_ASKCBFORMATNAME
:
1369 char *ptr
, buffer
[512];
1370 DWORD len
= wParam
* 2;
1372 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
1373 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1376 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, strlen(ptr
)+1 );
1377 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
1378 ((LPWSTR
)lParam
)[*result
] = 0;
1380 free_buffer( buffer
, ptr
);
1385 case LB_INSERTSTRING
:
1387 case LB_FINDSTRINGEXACT
:
1388 case LB_SELECTSTRING
:
1390 case CB_INSERTSTRING
:
1392 case CB_FINDSTRINGEXACT
:
1393 case CB_SELECTSTRING
:
1394 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
1396 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1401 case WM_WININICHANGE
:
1402 case WM_DEVMODECHANGE
:
1407 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1410 char *ptr
, buffer
[512];
1411 LPCWSTR strW
= (LPCWSTR
)lParam
;
1412 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
1414 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
1415 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
1417 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
1418 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1419 free_buffer( buffer
, ptr
);
1426 char *ptr
, buffer
[1024];
1427 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1428 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1429 MDICREATESTRUCTA csA
;
1431 memcpy( &csA
, csW
, sizeof(csA
) );
1433 if (HIWORD(csW
->szTitle
))
1435 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
1436 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
1438 if (HIWORD(csW
->szClass
))
1440 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
1441 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
1444 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
1448 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
1453 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
1454 csA
.szClass
= ptr
+ title_lenA
;
1456 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1457 free_buffer( buffer
, ptr
);
1463 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
1465 char buffer
[512]; /* FIXME: fixed sized buffer */
1467 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
1471 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
1472 *result
= len
/ sizeof(WCHAR
) - 1;
1475 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1480 char *ptr
, buffer
[512];
1481 WORD len
= *(WORD
*)lParam
;
1483 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
1484 *((WORD
*)ptr
) = len
* 2; /* store the length */
1485 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1489 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
1490 *result
= reslen
/ sizeof(WCHAR
);
1491 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 0;
1493 free_buffer( buffer
, ptr
);
1500 MSG newmsg
= *(MSG
*)lParam
;
1501 switch(newmsg
.message
)
1506 case WM_SYSDEADCHAR
:
1507 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
1510 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
1513 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
1515 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1523 case WM_SYSDEADCHAR
:
1524 case EM_SETPASSWORDCHAR
:
1525 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
1529 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
1532 case WM_PAINTCLIPBOARD
:
1533 case WM_SIZECLIPBOARD
:
1534 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
1535 SPY_GetMsgName(msg
, hwnd
), msg
);
1539 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1547 /**********************************************************************
1548 * WINPROC_CallProc16To32A
1550 LRESULT
WINPROC_CallProc16To32A( winproc_callback_t callback
, HWND16 hwnd
, UINT16 msg
,
1551 WPARAM16 wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1554 HWND hwnd32
= WIN_Handle32( hwnd
);
1556 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1557 hwnd32
, SPY_GetMsgName(msg
, hwnd32
), wParam
, lParam
);
1564 CREATESTRUCT16
*cs16
= MapSL(lParam
);
1566 MDICREATESTRUCTA mdi_cs
;
1568 CREATESTRUCT16to32A( cs16
, &cs
);
1569 if (GetWindowLongW(hwnd32
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1571 MDICREATESTRUCT16
*mdi_cs16
= MapSL(cs16
->lpCreateParams
);
1572 MDICREATESTRUCT16to32A(mdi_cs16
, &mdi_cs
);
1573 cs
.lpCreateParams
= &mdi_cs
;
1575 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1576 CREATESTRUCT32Ato16( &cs
, cs16
);
1581 MDICREATESTRUCT16
*cs16
= MapSL(lParam
);
1582 MDICREATESTRUCTA cs
;
1584 MDICREATESTRUCT16to32A( cs16
, &cs
);
1585 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1586 MDICREATESTRUCT32Ato16( &cs
, cs16
);
1589 case WM_MDIACTIVATE
:
1591 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32( HIWORD(lParam
) ),
1592 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1593 else /* message sent to MDI client */
1594 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1596 case WM_MDIGETACTIVE
:
1598 BOOL maximized
= FALSE
;
1599 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&maximized
, result
, arg
);
1600 *result
= MAKELRESULT( LOWORD(*result
), maximized
);
1604 ret
= callback( hwnd32
, wParam
? WM_MDIREFRESHMENU
: WM_MDISETMENU
,
1605 (WPARAM
)HMENU_32(LOWORD(lParam
)), (LPARAM
)HMENU_32(HIWORD(lParam
)),
1608 case WM_GETMINMAXINFO
:
1610 MINMAXINFO16
*mmi16
= MapSL(lParam
);
1613 MINMAXINFO16to32( mmi16
, &mmi
);
1614 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mmi
, result
, arg
);
1615 MINMAXINFO32to16( &mmi
, mmi16
);
1618 case WM_WINDOWPOSCHANGING
:
1619 case WM_WINDOWPOSCHANGED
:
1621 WINDOWPOS16
*winpos16
= MapSL(lParam
);
1624 WINDOWPOS16to32( winpos16
, &winpos
);
1625 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&winpos
, result
, arg
);
1626 WINDOWPOS32to16( &winpos
, winpos16
);
1631 NCCALCSIZE_PARAMS16
*nc16
= MapSL(lParam
);
1632 NCCALCSIZE_PARAMS nc
;
1635 RECT16to32( &nc16
->rgrc
[0], &nc
.rgrc
[0] );
1638 RECT16to32( &nc16
->rgrc
[1], &nc
.rgrc
[1] );
1639 RECT16to32( &nc16
->rgrc
[2], &nc
.rgrc
[2] );
1640 WINDOWPOS16to32( MapSL(nc16
->lppos
), &winpos
);
1643 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&nc
, result
, arg
);
1644 RECT32to16( &nc
.rgrc
[0], &nc16
->rgrc
[0] );
1647 RECT32to16( &nc
.rgrc
[1], &nc16
->rgrc
[1] );
1648 RECT32to16( &nc
.rgrc
[2], &nc16
->rgrc
[2] );
1649 WINDOWPOS32to16( &winpos
, MapSL(nc16
->lppos
) );
1653 case WM_COMPAREITEM
:
1655 COMPAREITEMSTRUCT16
* cis16
= MapSL(lParam
);
1656 COMPAREITEMSTRUCT cis
;
1657 cis
.CtlType
= cis16
->CtlType
;
1658 cis
.CtlID
= cis16
->CtlID
;
1659 cis
.hwndItem
= WIN_Handle32( cis16
->hwndItem
);
1660 cis
.itemID1
= cis16
->itemID1
;
1661 cis
.itemData1
= cis16
->itemData1
;
1662 cis
.itemID2
= cis16
->itemID2
;
1663 cis
.itemData2
= cis16
->itemData2
;
1664 cis
.dwLocaleId
= 0; /* FIXME */
1665 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cis
, result
, arg
);
1670 DELETEITEMSTRUCT16
* dis16
= MapSL(lParam
);
1671 DELETEITEMSTRUCT dis
;
1672 dis
.CtlType
= dis16
->CtlType
;
1673 dis
.CtlID
= dis16
->CtlID
;
1674 dis
.hwndItem
= WIN_Handle32( dis16
->hwndItem
);
1675 dis
.itemData
= dis16
->itemData
;
1676 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1679 case WM_MEASUREITEM
:
1681 MEASUREITEMSTRUCT16
* mis16
= MapSL(lParam
);
1682 MEASUREITEMSTRUCT mis
;
1683 mis
.CtlType
= mis16
->CtlType
;
1684 mis
.CtlID
= mis16
->CtlID
;
1685 mis
.itemID
= mis16
->itemID
;
1686 mis
.itemWidth
= mis16
->itemWidth
;
1687 mis
.itemHeight
= mis16
->itemHeight
;
1688 mis
.itemData
= mis16
->itemData
;
1689 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mis
, result
, arg
);
1690 mis16
->itemWidth
= (UINT16
)mis
.itemWidth
;
1691 mis16
->itemHeight
= (UINT16
)mis
.itemHeight
;
1696 DRAWITEMSTRUCT16
* dis16
= MapSL(lParam
);
1698 dis
.CtlType
= dis16
->CtlType
;
1699 dis
.CtlID
= dis16
->CtlID
;
1700 dis
.itemID
= dis16
->itemID
;
1701 dis
.itemAction
= dis16
->itemAction
;
1702 dis
.itemState
= dis16
->itemState
;
1703 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND
)HMENU_32(dis16
->hwndItem
)
1704 : WIN_Handle32( dis16
->hwndItem
);
1705 dis
.hDC
= HDC_32(dis16
->hDC
);
1706 dis
.itemData
= dis16
->itemData
;
1707 dis
.rcItem
.left
= dis16
->rcItem
.left
;
1708 dis
.rcItem
.top
= dis16
->rcItem
.top
;
1709 dis
.rcItem
.right
= dis16
->rcItem
.right
;
1710 dis
.rcItem
.bottom
= dis16
->rcItem
.bottom
;
1711 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1716 COPYDATASTRUCT16
*cds16
= MapSL(lParam
);
1718 cds
.dwData
= cds16
->dwData
;
1719 cds
.cbData
= cds16
->cbData
;
1720 cds
.lpData
= MapSL(cds16
->lpData
);
1721 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cds
, result
, arg
);
1727 MSG16
*msg16
= MapSL(lParam
);
1729 msg32
.hwnd
= WIN_Handle32( msg16
->hwnd
);
1730 msg32
.message
= msg16
->message
;
1731 msg32
.wParam
= msg16
->wParam
;
1732 msg32
.lParam
= msg16
->lParam
;
1733 msg32
.time
= msg16
->time
;
1734 msg32
.pt
.x
= msg16
->pt
.x
;
1735 msg32
.pt
.y
= msg16
->pt
.y
;
1736 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&msg32
, result
, arg
);
1739 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1744 next
.hmenuIn
= (HMENU
)lParam
;
1747 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&next
, result
, arg
);
1748 *result
= MAKELONG( HMENU_16(next
.hmenuNext
), HWND_16(next
.hwndNext
) );
1755 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1756 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1760 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1761 (LPARAM
)WIN_Handle32( HIWORD(lParam
) ), result
, arg
);
1764 if (HIWORD(lParam
) <= CTLCOLOR_STATIC
)
1765 ret
= callback( hwnd32
, WM_CTLCOLORMSGBOX
+ HIWORD(lParam
),
1766 (WPARAM
)HDC_32(wParam
), (LPARAM
)WIN_Handle32( LOWORD(lParam
) ),
1771 case WM_WININICHANGE
:
1772 case WM_DEVMODECHANGE
:
1773 case WM_ASKCBFORMATNAME
:
1775 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)MapSL(lParam
), result
, arg
);
1778 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1779 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1782 if((LOWORD(lParam
) & MF_POPUP
) && (LOWORD(lParam
) != 0xFFFF))
1784 HMENU hmenu
= HMENU_32(HIWORD(lParam
));
1785 UINT pos
= MENU_FindSubMenu( &hmenu
, HMENU_32(wParam
) );
1786 if (pos
== 0xffff) pos
= 0; /* NO_SELECTED_ITEM */
1789 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1790 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1792 case WM_PARENTNOTIFY
:
1793 if ((wParam
== WM_CREATE
) || (wParam
== WM_DESTROY
))
1794 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1795 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1797 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1799 case WM_ACTIVATEAPP
:
1800 /* We need this when SetActiveWindow sends a Sendmessage16() to
1801 * a 32bit window. Might be superflous with 32bit interprocess
1802 * message queues. */
1803 ret
= callback( hwnd32
, msg
, wParam
, HTASK_32(lParam
), result
, arg
);
1805 case WM_DDE_INITIATE
:
1806 case WM_DDE_TERMINATE
:
1807 case WM_DDE_UNADVISE
:
1808 case WM_DDE_REQUEST
:
1809 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1815 HANDLE16 lo16
= LOWORD(lParam
);
1817 if (lo16
&& !(lo32
= convert_handle_16_to_32(lo16
, GMEM_DDESHARE
))) break;
1818 lParam
= PackDDElParam( msg
, lo32
, HIWORD(lParam
) );
1819 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1821 break; /* FIXME don't know how to free allocated memory (handle) !! */
1824 UINT lo
= LOWORD(lParam
);
1825 UINT hi
= HIWORD(lParam
);
1829 if (GlobalGetAtomNameA(hi
, buf
, 2) > 0) flag
|= 1;
1830 if (GlobalSize16(hi
) != 0) flag
|= 2;
1836 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1841 break; /* atom, nothing to do */
1843 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
1846 hi
= convert_handle_16_to_32(hi
, GMEM_DDESHARE
);
1849 lParam
= PackDDElParam( WM_DDE_ACK
, lo
, hi
);
1850 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1852 break; /* FIXME don't know how to free allocated memory (handle) !! */
1853 case WM_DDE_EXECUTE
:
1854 lParam
= convert_handle_16_to_32( lParam
, GMEM_DDESHARE
);
1855 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1856 break; /* FIXME don't know how to free allocated memory (handle) !! */
1857 case WM_PAINTCLIPBOARD
:
1858 case WM_SIZECLIPBOARD
:
1859 FIXME_(msg
)( "message %04x needs translation\n", msg
);
1862 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1869 /**********************************************************************
1870 * __wine_call_wndproc (USER.1010)
1872 LRESULT WINAPI
__wine_call_wndproc( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
1878 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1880 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1885 /**********************************************************************
1886 * WINPROC_CallProc32ATo16
1888 * Call a 16-bit window procedure, translating the 32-bit args.
1890 LRESULT
WINPROC_CallProc32ATo16( winproc_callback16_t callback
, HWND hwnd
, UINT msg
,
1891 WPARAM wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1895 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1896 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1903 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)lParam
;
1905 MDICREATESTRUCT16 mdi_cs16
;
1906 BOOL mdi_child
= (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
);
1908 CREATESTRUCT32Ato16( cs32
, &cs
);
1909 cs
.lpszName
= MapLS( cs32
->lpszName
);
1910 cs
.lpszClass
= MapLS( cs32
->lpszClass
);
1914 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs32
->lpCreateParams
;
1915 MDICREATESTRUCT32Ato16( mdi_cs
, &mdi_cs16
);
1916 mdi_cs16
.szTitle
= MapLS( mdi_cs
->szTitle
);
1917 mdi_cs16
.szClass
= MapLS( mdi_cs
->szClass
);
1918 cs
.lpCreateParams
= MapLS( &mdi_cs16
);
1920 lParam
= MapLS( &cs
);
1921 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1923 UnMapLS( cs
.lpszName
);
1924 UnMapLS( cs
.lpszClass
);
1927 UnMapLS( cs
.lpCreateParams
);
1928 UnMapLS( mdi_cs16
.szTitle
);
1929 UnMapLS( mdi_cs16
.szClass
);
1935 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)lParam
;
1936 MDICREATESTRUCT16 cs
;
1938 MDICREATESTRUCT32Ato16( cs32
, &cs
);
1939 cs
.szTitle
= MapLS( cs32
->szTitle
);
1940 cs
.szClass
= MapLS( cs32
->szClass
);
1941 lParam
= MapLS( &cs
);
1942 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1944 UnMapLS( cs
.szTitle
);
1945 UnMapLS( cs
.szClass
);
1948 case WM_MDIACTIVATE
:
1949 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1950 ret
= callback( HWND_16(hwnd
), msg
, ((HWND
)lParam
== hwnd
),
1951 MAKELPARAM( LOWORD(lParam
), LOWORD(wParam
) ), result
, arg
);
1953 ret
= callback( HWND_16(hwnd
), msg
, HWND_16( (HWND
)wParam
), 0, result
, arg
);
1955 case WM_MDIGETACTIVE
:
1956 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1957 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(*result
);
1958 *result
= (LRESULT
)WIN_Handle32( LOWORD(*result
) );
1961 ret
= callback( HWND_16(hwnd
), msg
, (lParam
== 0),
1962 MAKELPARAM( LOWORD(wParam
), LOWORD(lParam
) ), result
, arg
);
1964 case WM_GETMINMAXINFO
:
1966 MINMAXINFO
*mmi32
= (MINMAXINFO
*)lParam
;
1969 MINMAXINFO32to16( mmi32
, &mmi
);
1970 lParam
= MapLS( &mmi
);
1971 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1973 MINMAXINFO16to32( &mmi
, mmi32
);
1978 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)lParam
;
1979 NCCALCSIZE_PARAMS16 nc
;
1982 RECT32to16( &nc32
->rgrc
[0], &nc
.rgrc
[0] );
1985 RECT32to16( &nc32
->rgrc
[1], &nc
.rgrc
[1] );
1986 RECT32to16( &nc32
->rgrc
[2], &nc
.rgrc
[2] );
1987 WINDOWPOS32to16( nc32
->lppos
, &winpos
);
1988 nc
.lppos
= MapLS( &winpos
);
1990 lParam
= MapLS( &nc
);
1991 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1993 RECT16to32( &nc
.rgrc
[0], &nc32
->rgrc
[0] );
1996 RECT16to32( &nc
.rgrc
[1], &nc32
->rgrc
[1] );
1997 RECT16to32( &nc
.rgrc
[2], &nc32
->rgrc
[2] );
1998 WINDOWPOS16to32( &winpos
, nc32
->lppos
);
1999 UnMapLS( nc
.lppos
);
2003 case WM_WINDOWPOSCHANGING
:
2004 case WM_WINDOWPOSCHANGED
:
2006 WINDOWPOS
*winpos32
= (WINDOWPOS
*)lParam
;
2009 WINDOWPOS32to16( winpos32
, &winpos
);
2010 lParam
= MapLS( &winpos
);
2011 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2013 WINDOWPOS16to32( &winpos
, winpos32
);
2016 case WM_COMPAREITEM
:
2018 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)lParam
;
2019 COMPAREITEMSTRUCT16 cis
;
2020 cis
.CtlType
= cis32
->CtlType
;
2021 cis
.CtlID
= cis32
->CtlID
;
2022 cis
.hwndItem
= HWND_16( cis32
->hwndItem
);
2023 cis
.itemID1
= cis32
->itemID1
;
2024 cis
.itemData1
= cis32
->itemData1
;
2025 cis
.itemID2
= cis32
->itemID2
;
2026 cis
.itemData2
= cis32
->itemData2
;
2027 lParam
= MapLS( &cis
);
2028 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2034 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)lParam
;
2035 DELETEITEMSTRUCT16 dis
;
2036 dis
.CtlType
= dis32
->CtlType
;
2037 dis
.CtlID
= dis32
->CtlID
;
2038 dis
.itemID
= dis32
->itemID
;
2039 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND16
)LOWORD(dis32
->hwndItem
)
2040 : HWND_16( dis32
->hwndItem
);
2041 dis
.itemData
= dis32
->itemData
;
2042 lParam
= MapLS( &dis
);
2043 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2049 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)lParam
;
2050 DRAWITEMSTRUCT16 dis
;
2051 dis
.CtlType
= dis32
->CtlType
;
2052 dis
.CtlID
= dis32
->CtlID
;
2053 dis
.itemID
= dis32
->itemID
;
2054 dis
.itemAction
= dis32
->itemAction
;
2055 dis
.itemState
= dis32
->itemState
;
2056 dis
.hwndItem
= HWND_16( dis32
->hwndItem
);
2057 dis
.hDC
= HDC_16(dis32
->hDC
);
2058 dis
.itemData
= dis32
->itemData
;
2059 dis
.rcItem
.left
= dis32
->rcItem
.left
;
2060 dis
.rcItem
.top
= dis32
->rcItem
.top
;
2061 dis
.rcItem
.right
= dis32
->rcItem
.right
;
2062 dis
.rcItem
.bottom
= dis32
->rcItem
.bottom
;
2063 lParam
= MapLS( &dis
);
2064 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2068 case WM_MEASUREITEM
:
2070 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)lParam
;
2071 MEASUREITEMSTRUCT16 mis
;
2072 mis
.CtlType
= mis32
->CtlType
;
2073 mis
.CtlID
= mis32
->CtlID
;
2074 mis
.itemID
= mis32
->itemID
;
2075 mis
.itemWidth
= mis32
->itemWidth
;
2076 mis
.itemHeight
= mis32
->itemHeight
;
2077 mis
.itemData
= mis32
->itemData
;
2078 lParam
= MapLS( &mis
);
2079 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2081 mis32
->itemWidth
= mis
.itemWidth
;
2082 mis32
->itemHeight
= mis
.itemHeight
;
2087 COPYDATASTRUCT
*cds32
= (COPYDATASTRUCT
*)lParam
;
2088 COPYDATASTRUCT16 cds
;
2090 cds
.dwData
= cds32
->dwData
;
2091 cds
.cbData
= cds32
->cbData
;
2092 cds
.lpData
= MapLS( cds32
->lpData
);
2093 lParam
= MapLS( &cds
);
2094 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2096 UnMapLS( cds
.lpData
);
2102 MSG
*msg32
= (MSG
*)lParam
;
2105 msg16
.hwnd
= HWND_16( msg32
->hwnd
);
2106 msg16
.message
= msg32
->message
;
2107 msg16
.wParam
= msg32
->wParam
;
2108 msg16
.lParam
= msg32
->lParam
;
2109 msg16
.time
= msg32
->time
;
2110 msg16
.pt
.x
= msg32
->pt
.x
;
2111 msg16
.pt
.y
= msg32
->pt
.y
;
2112 lParam
= MapLS( &msg16
);
2113 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2117 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2121 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
2122 ret
= callback( HWND_16(hwnd
), msg
, wParam
, (LPARAM
)next
->hmenuIn
, result
, arg
);
2123 next
->hmenuNext
= HMENU_32( LOWORD(*result
) );
2124 next
->hwndNext
= WIN_Handle32( HIWORD(*result
) );
2129 case WM_ASKCBFORMATNAME
:
2130 wParam
= min( wParam
, 0xff80 ); /* Must be < 64K */
2134 case WM_WININICHANGE
:
2135 case WM_DEVMODECHANGE
:
2136 lParam
= MapLS( (void *)lParam
);
2137 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2140 case WM_DDE_INITIATE
:
2141 case WM_DDE_TERMINATE
:
2142 case WM_DDE_UNADVISE
:
2143 case WM_DDE_REQUEST
:
2144 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
), lParam
, result
, arg
);
2153 UnpackDDElParam( msg
, lParam
, &lo32
, &hi
);
2154 if (lo32
&& !(lo16
= convert_handle_32_to_16(lo32
, GMEM_DDESHARE
))) break;
2155 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
),
2156 MAKELPARAM(lo16
, hi
), result
, arg
);
2158 break; /* FIXME don't know how to free allocated memory (handle) !! */
2165 UnpackDDElParam( msg
, lParam
, &lo
, &hi
);
2167 if (GlobalGetAtomNameA((ATOM
)hi
, buf
, sizeof(buf
)) > 0) flag
|= 1;
2168 if (GlobalSize((HANDLE
)hi
) != 0) flag
|= 2;
2174 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
2179 break; /* atom, nothing to do */
2181 MESSAGE("DDE_ACK: %x both atom and handle... choosing handle\n", hi
);
2184 hi
= convert_handle_32_to_16(hi
, GMEM_DDESHARE
);
2187 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
),
2188 MAKELPARAM(lo
, hi
), result
, arg
);
2190 break; /* FIXME don't know how to free allocated memory (handle) !! */
2191 case WM_DDE_EXECUTE
:
2192 lParam
= convert_handle_32_to_16(lParam
, GMEM_DDESHARE
);
2193 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2194 break; /* FIXME don't know how to free allocated memory (handle) !! */
2196 ret
= callback( HWND_16(hwnd
), SBM_SETRANGE16
, 0, MAKELPARAM(wParam
, lParam
), result
, arg
);
2199 ret
= callback( HWND_16(hwnd
), SBM_GETRANGE16
, wParam
, lParam
, result
, arg
);
2200 *(LPINT
)wParam
= LOWORD(*result
);
2201 *(LPINT
)lParam
= HIWORD(*result
);
2208 ret
= callback( HWND_16(hwnd
), msg
+ BM_GETCHECK16
- BM_GETCHECK
, wParam
, lParam
, result
, arg
);
2216 case EM_SCROLLCARET
:
2219 case EM_GETLINECOUNT
:
2231 case EM_LINEFROMCHAR
:
2232 case EM_SETTABSTOPS
:
2233 case EM_SETPASSWORDCHAR
:
2234 case EM_EMPTYUNDOBUFFER
:
2235 case EM_GETFIRSTVISIBLELINE
:
2236 case EM_SETREADONLY
:
2237 case EM_SETWORDBREAKPROC
:
2238 case EM_GETWORDBREAKPROC
:
2239 case EM_GETPASSWORDCHAR
:
2240 ret
= callback( HWND_16(hwnd
), msg
+ EM_GETSEL16
- EM_GETSEL
, wParam
, lParam
, result
, arg
);
2243 ret
= callback( HWND_16(hwnd
), EM_SETSEL16
, 0, MAKELPARAM( wParam
, lParam
), result
, arg
);
2249 LPARAM lParam16
= lParam
;
2250 if (WINPROC_MapMsg32ATo16( hwnd
, msg
, wParam
, &msg16
, &wParam16
, &lParam16
) != -1)
2252 ret
= callback( HWND_16(hwnd
), msg16
, wParam16
, lParam16
, result
, arg
);
2253 WINPROC_UnmapMsg32ATo16( hwnd
, msg
, wParam
, lParam
, wParam16
, lParam16
, result
);
2262 /**********************************************************************
2263 * CallWindowProc (USER.122)
2265 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2266 WPARAM16 wParam
, LPARAM lParam
)
2271 if (!func
) return 0;
2273 if (!(proc
= handle16_to_proc( func
)))
2274 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2275 else if (proc
->procA
)
2276 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2277 else if (proc
->procW
)
2278 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2280 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2286 /**********************************************************************
2287 * CallWindowProcA (USER32.@)
2289 * The CallWindowProc() function invokes the windows procedure _func_,
2290 * with _hwnd_ as the target window, the message specified by _msg_, and
2291 * the message parameters _wParam_ and _lParam_.
2293 * Some kinds of argument conversion may be done, I'm not sure what.
2295 * CallWindowProc() may be used for windows subclassing. Use
2296 * SetWindowLong() to set a new windows procedure for windows of the
2297 * subclass, and handle subclassed messages in the new windows
2298 * procedure. The new windows procedure may then use CallWindowProc()
2299 * with _func_ set to the parent class's windows procedure to dispatch
2300 * the message to the superclass.
2304 * The return value is message dependent.
2310 LRESULT WINAPI
CallWindowProcA(
2311 WNDPROC func
, /* [in] window procedure */
2312 HWND hwnd
, /* [in] target window */
2313 UINT msg
, /* [in] message */
2314 WPARAM wParam
, /* [in] message dependent parameter */
2315 LPARAM lParam
/* [in] message dependent parameter */
2320 if (!func
) return 0;
2322 if (!(proc
= handle_to_proc( func
)))
2323 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2324 else if (proc
->procA
)
2325 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2326 else if (proc
->procW
)
2327 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2329 WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2334 /**********************************************************************
2335 * CallWindowProcW (USER32.@)
2337 * See CallWindowProcA.
2339 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
2340 WPARAM wParam
, LPARAM lParam
)
2345 if (!func
) return 0;
2347 if (!(proc
= handle_to_proc( func
)))
2348 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2349 else if (proc
->procW
)
2350 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2351 else if (proc
->procA
)
2352 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2354 WINPROC_CallProcWtoA( call_window_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2359 /**********************************************************************
2360 * WINPROC_CallDlgProc16
2362 INT_PTR
WINPROC_CallDlgProc16( DLGPROC16 func
, HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
2368 if (!func
) return 0;
2370 if (!(proc
= handle16_to_proc( (WNDPROC16
)func
)))
2372 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2374 else if (proc
->procA
)
2376 ret
= WINPROC_CallProc16To32A( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
,
2377 &result
, proc
->procA
);
2378 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2380 else if (proc
->procW
)
2382 ret
= WINPROC_CallProc16To32A( call_dialog_proc_AtoW
, hwnd
, msg
, wParam
, lParam
,
2383 &result
, proc
->procW
);
2384 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2388 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2394 /**********************************************************************
2395 * WINPROC_CallDlgProcA
2397 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2403 if (!func
) return 0;
2405 if (!(proc
= handle_to_proc( (WNDPROC
)func
)))
2406 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2407 else if (proc
->procA
)
2408 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2409 else if (proc
->procW
)
2411 ret
= WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2412 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2416 ret
= WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2417 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2423 /**********************************************************************
2424 * WINPROC_CallDlgProcW
2426 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2432 if (!func
) return 0;
2434 if (!(proc
= handle_to_proc( (WNDPROC
)func
)))
2435 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2436 else if (proc
->procW
)
2437 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2438 else if (proc
->procA
)
2440 ret
= WINPROC_CallProcWtoA( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2441 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2445 ret
= WINPROC_CallProcWtoA( call_dialog_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2446 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);