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"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
36 #include "user_private.h"
39 #include "wine/unicode.h"
40 #include "wine/debug.h"
42 WINE_DECLARE_DEBUG_CHANNEL(msg
);
43 WINE_DECLARE_DEBUG_CHANNEL(relay
);
44 WINE_DEFAULT_DEBUG_CHANNEL(win
);
46 typedef struct tagWINDOWPROC
48 WNDPROC16 proc16
; /* 16-bit window proc */
49 WNDPROC procA
; /* ASCII window proc */
50 WNDPROC procW
; /* Unicode window proc */
53 #define WINPROC_HANDLE (~0u >> 16)
54 #define MAX_WINPROCS 8192
55 #define BUILTIN_WINPROCS 9 /* first BUILTIN_WINPROCS entries are reserved for builtin procs */
56 #define MAX_WINPROC_RECURSION 64
58 WNDPROC EDIT_winproc_handle
= 0;
60 static WINDOWPROC winproc_array
[MAX_WINPROCS
];
61 static UINT builtin_used
;
62 static UINT winproc_used
= BUILTIN_WINPROCS
;
64 static CRITICAL_SECTION winproc_cs
;
65 static CRITICAL_SECTION_DEBUG critsect_debug
=
68 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
69 0, 0, { (DWORD_PTR
)(__FILE__
": winproc_cs") }
71 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
73 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
75 if (size
>= need
) return static_buffer
;
76 return HeapAlloc( GetProcessHeap(), 0, need
);
79 static inline void free_buffer( void *static_buffer
, void *buffer
)
81 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
84 /* find an existing winproc for a given 16-bit function and type */
85 /* FIXME: probably should do something more clever than a linear search */
86 static inline WINDOWPROC
*find_winproc16( WNDPROC16 func
)
90 for (i
= BUILTIN_WINPROCS
; i
< winproc_used
; i
++)
92 if (winproc_array
[i
].proc16
== func
) return &winproc_array
[i
];
97 /* find an existing winproc for a given function and type */
98 /* FIXME: probably should do something more clever than a linear search */
99 static inline WINDOWPROC
*find_winproc( WNDPROC funcA
, WNDPROC funcW
)
103 for (i
= 0; i
< builtin_used
; i
++)
105 /* match either proc, some apps confuse A and W */
106 if (funcA
&& winproc_array
[i
].procA
!= funcA
&& winproc_array
[i
].procW
!= funcA
) continue;
107 if (funcW
&& winproc_array
[i
].procA
!= funcW
&& winproc_array
[i
].procW
!= funcW
) continue;
108 return &winproc_array
[i
];
110 for (i
= BUILTIN_WINPROCS
; i
< winproc_used
; i
++)
112 if (funcA
&& winproc_array
[i
].procA
!= funcA
) continue;
113 if (funcW
&& winproc_array
[i
].procW
!= funcW
) continue;
114 return &winproc_array
[i
];
119 /* return the window proc for a given handle, or NULL for an invalid handle */
120 static inline WINDOWPROC
*handle_to_proc( WNDPROC handle
)
122 UINT index
= LOWORD(handle
);
123 if ((ULONG_PTR
)handle
>> 16 != WINPROC_HANDLE
) return NULL
;
124 if (index
>= winproc_used
) return NULL
;
125 return &winproc_array
[index
];
128 /* create a handle for a given window proc */
129 static inline WNDPROC
proc_to_handle( WINDOWPROC
*proc
)
131 return (WNDPROC
)(ULONG_PTR
)((proc
- winproc_array
) | (WINPROC_HANDLE
<< 16));
134 /* allocate and initialize a new winproc */
135 static inline WINDOWPROC
*alloc_winproc( WNDPROC funcA
, WNDPROC funcW
)
139 /* check if the function is already a win proc */
140 if (funcA
&& (proc
= handle_to_proc( funcA
))) return proc
;
141 if (funcW
&& (proc
= handle_to_proc( funcW
))) return proc
;
142 if (!funcA
&& !funcW
) return NULL
;
144 EnterCriticalSection( &winproc_cs
);
146 /* check if we already have a winproc for that function */
147 if (!(proc
= find_winproc( funcA
, funcW
)))
151 assert( builtin_used
< BUILTIN_WINPROCS
);
152 proc
= &winproc_array
[builtin_used
++];
155 TRACE( "allocated %p for builtin %p/%p (%d/%d used)\n",
156 proc_to_handle(proc
), funcA
, funcW
, builtin_used
, BUILTIN_WINPROCS
);
158 else if (winproc_used
< MAX_WINPROCS
)
160 proc
= &winproc_array
[winproc_used
++];
163 TRACE( "allocated %p for %c %p (%d/%d used)\n",
164 proc_to_handle(proc
), funcA
? 'A' : 'W', funcA
? funcA
: funcW
,
165 winproc_used
, MAX_WINPROCS
);
167 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA
, funcW
);
169 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc
), funcA
, funcW
);
171 LeaveCriticalSection( &winproc_cs
);
178 #include "pshpack1.h"
180 /* Window procedure 16-to-32-bit thunk */
183 BYTE popl_eax
; /* popl %eax (return address) */
184 BYTE pushl_func
; /* pushl $proc */
186 BYTE pushl_eax
; /* pushl %eax */
187 BYTE ljmp
; /* ljmp relay*/
188 DWORD relay_offset
; /* __wine_call_wndproc */
194 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
196 static WINPROC_THUNK
*thunk_array
;
197 static UINT thunk_selector
;
198 static UINT thunk_used
;
200 /* return the window proc for a given handle, or NULL for an invalid handle */
201 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
203 if (HIWORD(handle
) == thunk_selector
)
205 UINT index
= LOWORD(handle
) / sizeof(WINPROC_THUNK
);
206 /* check alignment */
207 if (index
* sizeof(WINPROC_THUNK
) != LOWORD(handle
)) return NULL
;
208 /* check array limits */
209 if (index
>= thunk_used
) return NULL
;
210 return thunk_array
[index
].proc
;
212 return handle_to_proc( (WNDPROC
)handle
);
215 /* allocate a 16-bit thunk for an existing window proc */
216 static WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
218 static FARPROC16 relay
;
221 if (proc
->proc16
) return proc
->proc16
;
223 EnterCriticalSection( &winproc_cs
);
225 if (!thunk_array
) /* allocate the array and its selector */
229 if (!(thunk_selector
= wine_ldt_alloc_entries(1))) goto done
;
230 if (!(thunk_array
= VirtualAlloc( NULL
, MAX_THUNKS
* sizeof(WINPROC_THUNK
), MEM_COMMIT
,
231 PAGE_EXECUTE_READWRITE
))) goto done
;
232 wine_ldt_set_base( &entry
, thunk_array
);
233 wine_ldt_set_limit( &entry
, MAX_THUNKS
* sizeof(WINPROC_THUNK
) - 1 );
234 wine_ldt_set_flags( &entry
, WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
235 wine_ldt_set_entry( thunk_selector
, &entry
);
236 relay
= GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
239 /* check if it already exists */
240 for (i
= 0; i
< thunk_used
; i
++) if (thunk_array
[i
].proc
== proc
) break;
242 if (i
== thunk_used
) /* create a new one */
244 WINPROC_THUNK
*thunk
;
246 if (thunk_used
>= MAX_THUNKS
) goto done
;
247 thunk
= &thunk_array
[thunk_used
++];
248 thunk
->popl_eax
= 0x58; /* popl %eax */
249 thunk
->pushl_func
= 0x68; /* pushl $proc */
251 thunk
->pushl_eax
= 0x50; /* pushl %eax */
252 thunk
->ljmp
= 0xea; /* ljmp relay*/
253 thunk
->relay_offset
= OFFSETOF(relay
);
254 thunk
->relay_sel
= SELECTOROF(relay
);
256 proc
->proc16
= (WNDPROC16
)MAKESEGPTR( thunk_selector
, i
* sizeof(WINPROC_THUNK
) );
258 LeaveCriticalSection( &winproc_cs
);
264 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
266 return handle_to_proc( (WNDPROC
)handle
);
269 static inline WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
274 #endif /* __i386__ */
278 /* Some window procedures modify register they shouldn't, or are not
279 * properly declared stdcall; so we need a small assembly wrapper to
281 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
282 WPARAM wParam
, LPARAM lParam
);
283 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
285 __ASM_CFI(".cfi_adjust_cfa_offset 4\n\t")
286 __ASM_CFI(".cfi_rel_offset %ebp,0\n\t")
288 __ASM_CFI(".cfi_def_cfa_register %ebp\n\t")
290 __ASM_CFI(".cfi_rel_offset %edi,-4\n\t")
292 __ASM_CFI(".cfi_rel_offset %esi,-8\n\t")
294 __ASM_CFI(".cfi_rel_offset %ebx,-12\n\t")
300 "movl 8(%ebp),%eax\n\t"
302 "leal -12(%ebp),%esp\n\t"
304 __ASM_CFI(".cfi_same_value %ebx\n\t")
306 __ASM_CFI(".cfi_same_value %esi\n\t")
308 __ASM_CFI(".cfi_same_value %edi\n\t")
310 __ASM_CFI(".cfi_def_cfa %esp,4\n\t")
311 __ASM_CFI(".cfi_same_value %ebp\n\t")
314 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
315 WPARAM wParam
, LPARAM lParam
)
317 return proc( hwnd
, msg
, wParam
, lParam
);
319 #endif /* __i386__ */
321 static void RECT16to32( const RECT16
*from
, RECT
*to
)
323 to
->left
= from
->left
;
325 to
->right
= from
->right
;
326 to
->bottom
= from
->bottom
;
329 static void RECT32to16( const RECT
*from
, RECT16
*to
)
331 to
->left
= from
->left
;
333 to
->right
= from
->right
;
334 to
->bottom
= from
->bottom
;
337 static void MINMAXINFO32to16( const MINMAXINFO
*from
, MINMAXINFO16
*to
)
339 to
->ptReserved
.x
= from
->ptReserved
.x
;
340 to
->ptReserved
.y
= from
->ptReserved
.y
;
341 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
342 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
343 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
344 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
345 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
346 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
347 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
348 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
351 static void MINMAXINFO16to32( const MINMAXINFO16
*from
, MINMAXINFO
*to
)
353 to
->ptReserved
.x
= from
->ptReserved
.x
;
354 to
->ptReserved
.y
= from
->ptReserved
.y
;
355 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
356 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
357 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
358 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
359 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
360 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
361 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
362 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
365 static void WINDOWPOS32to16( const WINDOWPOS
* from
, WINDOWPOS16
* to
)
367 to
->hwnd
= HWND_16(from
->hwnd
);
368 to
->hwndInsertAfter
= HWND_16(from
->hwndInsertAfter
);
373 to
->flags
= from
->flags
;
376 static void WINDOWPOS16to32( const WINDOWPOS16
* from
, WINDOWPOS
* to
)
378 to
->hwnd
= WIN_Handle32(from
->hwnd
);
379 to
->hwndInsertAfter
= (from
->hwndInsertAfter
== (HWND16
)-1) ?
380 HWND_TOPMOST
: WIN_Handle32(from
->hwndInsertAfter
);
385 to
->flags
= from
->flags
;
388 /* The strings are not copied */
389 static void CREATESTRUCT32Ato16( const CREATESTRUCTA
* from
, CREATESTRUCT16
* to
)
391 to
->lpCreateParams
= (SEGPTR
)from
->lpCreateParams
;
392 to
->hInstance
= HINSTANCE_16(from
->hInstance
);
393 to
->hMenu
= HMENU_16(from
->hMenu
);
394 to
->hwndParent
= HWND_16(from
->hwndParent
);
399 to
->style
= from
->style
;
400 to
->dwExStyle
= from
->dwExStyle
;
403 static void CREATESTRUCT16to32A( const CREATESTRUCT16
* from
, CREATESTRUCTA
*to
)
406 to
->lpCreateParams
= (LPVOID
)from
->lpCreateParams
;
407 to
->hInstance
= HINSTANCE_32(from
->hInstance
);
408 to
->hMenu
= HMENU_32(from
->hMenu
);
409 to
->hwndParent
= WIN_Handle32(from
->hwndParent
);
414 to
->style
= from
->style
;
415 to
->dwExStyle
= from
->dwExStyle
;
416 to
->lpszName
= MapSL(from
->lpszName
);
417 to
->lpszClass
= MapSL(from
->lpszClass
);
420 /* The strings are not copied */
421 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA
* from
, MDICREATESTRUCT16
* to
)
423 to
->hOwner
= HINSTANCE_16(from
->hOwner
);
428 to
->style
= from
->style
;
429 to
->lParam
= from
->lParam
;
432 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16
* from
, MDICREATESTRUCTA
*to
)
434 to
->hOwner
= HINSTANCE_32(from
->hOwner
);
439 to
->style
= from
->style
;
440 to
->lParam
= from
->lParam
;
441 to
->szTitle
= MapSL(from
->szTitle
);
442 to
->szClass
= MapSL(from
->szClass
);
445 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
450 RtlUnicodeToMultiByteN( (LPSTR
)ch
, len
, &len
, &wch
, sizeof(wch
) );
452 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
454 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
457 /* call a 32-bit window procedure */
458 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
464 hwnd
= WIN_GetFullHandle( hwnd
);
466 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
467 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
469 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
472 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
473 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
477 /* call a 32-bit dialog procedure */
478 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
485 hwnd
= WIN_GetFullHandle( hwnd
);
487 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
488 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
490 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
491 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
494 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
495 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
499 /* call a 16-bit window procedure */
500 static LRESULT
call_window_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
501 LRESULT
*result
, void *arg
)
503 WNDPROC16 proc
= arg
;
512 DRAWITEMSTRUCT16 dis16
;
513 COMPAREITEMSTRUCT16 cis16
;
519 /* Window procedures want ax = hInstance, ds = es = ss */
521 memset(&context
, 0, sizeof(context
));
522 context
.SegDs
= context
.SegEs
= SELECTOROF(NtCurrentTeb()->WOW32Reserved
);
523 context
.SegFs
= wine_get_fs();
524 context
.SegGs
= wine_get_gs();
525 if (!(context
.Eax
= GetWindowWord( HWND_32(hwnd
), GWLP_HINSTANCE
))) context
.Eax
= context
.SegDs
;
526 context
.SegCs
= SELECTOROF(proc
);
527 context
.Eip
= OFFSETOF(proc
);
528 context
.Ebp
= OFFSETOF(NtCurrentTeb()->WOW32Reserved
) + FIELD_OFFSET(STACK16FRAME
, bp
);
532 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
533 work if structures passed in lParam are placed in the stack/data
534 segment. Programmers easily make the mistake of converting lParam
535 to a near rather than a far pointer, since Windows apparently
536 allows this. We copy the structures to the 16 bit stack; this is
537 ugly but makes these programs work. */
542 size
= sizeof(CREATESTRUCT16
); break;
544 size
= sizeof(DRAWITEMSTRUCT16
); break;
546 size
= sizeof(COMPAREITEMSTRUCT16
); break;
550 memcpy( &args
.u
, MapSL(lParam
), size
);
551 lParam
= PtrToUlong(NtCurrentTeb()->WOW32Reserved
) - size
;
555 args
.params
[4] = hwnd
;
556 args
.params
[3] = msg
;
557 args
.params
[2] = wParam
;
558 args
.params
[1] = HIWORD(lParam
);
559 args
.params
[0] = LOWORD(lParam
);
560 WOWCallback16Ex( 0, WCB16_REGS
, sizeof(args
.params
) + size
, &args
, (DWORD
*)&context
);
561 *result
= MAKELONG( LOWORD(context
.Eax
), LOWORD(context
.Edx
) );
565 /* call a 16-bit dialog procedure */
566 static LRESULT
call_dialog_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wp
, LPARAM lp
,
567 LRESULT
*result
, void *arg
)
569 LRESULT ret
= call_window_proc16( hwnd
, msg
, wp
, lp
, result
, arg
);
570 *result
= GetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
);
574 /* helper callback for 32W->16 conversion */
575 static LRESULT
call_window_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
576 LRESULT
*result
, void *arg
)
578 return WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
581 /* helper callback for 32W->16 conversion */
582 static LRESULT
call_dialog_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
583 LRESULT
*result
, void *arg
)
585 return WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
588 /* helper callback for 16->32W conversion */
589 static LRESULT
call_window_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
590 LRESULT
*result
, void *arg
)
592 return WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wp
, lp
, result
,
593 arg
, WMCHAR_MAP_CALLWINDOWPROC
);
596 /* helper callback for 16->32W conversion */
597 static LRESULT
call_dialog_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
598 LRESULT
*result
, void *arg
)
600 return WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wp
, lp
, result
,
601 arg
, WMCHAR_MAP_CALLWINDOWPROC
);
605 /**********************************************************************
608 * Get a window procedure pointer that can be passed to the Windows program.
610 WNDPROC16
WINPROC_GetProc16( WNDPROC proc
, BOOL unicode
)
614 if (unicode
) ptr
= alloc_winproc( NULL
, proc
);
615 else ptr
= alloc_winproc( proc
, NULL
);
618 return alloc_win16_thunk( ptr
);
622 /**********************************************************************
625 * Get a window procedure pointer that can be passed to the Windows program.
627 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
629 WINDOWPROC
*ptr
= handle_to_proc( proc
);
631 if (!ptr
) return proc
;
634 if (ptr
->procW
) return ptr
->procW
;
639 if (ptr
->procA
) return ptr
->procA
;
645 /**********************************************************************
646 * WINPROC_AllocProc16
648 * Allocate a window procedure for a window or class.
650 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
651 * lot of windows, it will usually only have a limited number of window procedures, so the
652 * array won't grow too large, and this way we avoid the need to track allocations per window.
654 WNDPROC
WINPROC_AllocProc16( WNDPROC16 func
)
658 if (!func
) return NULL
;
660 /* check if the function is already a win proc */
661 if (!(proc
= handle16_to_proc( func
)))
663 EnterCriticalSection( &winproc_cs
);
665 /* then check if we already have a winproc for that function */
666 if (!(proc
= find_winproc16( func
)))
668 if (winproc_used
< MAX_WINPROCS
)
670 proc
= &winproc_array
[winproc_used
++];
672 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
673 proc_to_handle(proc
), func
, winproc_used
, MAX_WINPROCS
);
675 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func
);
677 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc
), func
);
679 LeaveCriticalSection( &winproc_cs
);
681 return proc_to_handle( proc
);
685 /**********************************************************************
688 * Allocate a window procedure for a window or class.
690 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
691 * lot of windows, it will usually only have a limited number of window procedures, so the
692 * array won't grow too large, and this way we avoid the need to track allocations per window.
694 WNDPROC
WINPROC_AllocProc( WNDPROC funcA
, WNDPROC funcW
)
698 if (!(proc
= alloc_winproc( funcA
, funcW
))) return NULL
;
699 return proc_to_handle( proc
);
703 /**********************************************************************
706 * Return the window procedure type, or the default value if not a winproc handle.
708 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
710 WINDOWPROC
*ptr
= handle_to_proc( proc
);
712 if (!ptr
) return def_val
;
713 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
714 return (ptr
->procW
!= NULL
);
718 /**********************************************************************
719 * WINPROC_TestLBForStr
721 * Return TRUE if the lparam is a string
723 static inline BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
725 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
726 if (msg
<= CB_MSGMAX
)
727 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
729 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
734 static UINT_PTR
convert_handle_16_to_32(HANDLE16 src
, unsigned int flags
)
737 UINT sz
= GlobalSize16(src
);
740 if (!(dst
= GlobalAlloc(flags
, sz
)))
742 ptr16
= GlobalLock16(src
);
743 ptr32
= GlobalLock(dst
);
744 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr32
, ptr16
, sz
);
748 return (UINT_PTR
)dst
;
751 static HANDLE16
convert_handle_32_to_16(UINT_PTR src
, unsigned int flags
)
754 UINT sz
= GlobalSize((HANDLE
)src
);
757 if (!(dst
= GlobalAlloc16(flags
, sz
)))
759 ptr32
= GlobalLock((HANDLE
)src
);
760 ptr16
= GlobalLock16(dst
);
761 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr16
, ptr32
, sz
);
762 GlobalUnlock((HANDLE
)src
);
769 /**********************************************************************
770 * WINPROC_CallProcAtoW
772 * Call a window procedure, translating args from Ansi to Unicode.
774 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
775 LPARAM lParam
, LRESULT
*result
, void *arg
, enum wm_char_mapping mapping
)
779 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
780 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
787 WCHAR
*ptr
, buffer
[512];
788 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
789 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
790 MDICREATESTRUCTW mdi_cs
;
791 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
793 if (!IS_INTRESOURCE(csA
->lpszClass
))
795 class_lenA
= strlen(csA
->lpszClass
) + 1;
796 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
798 if (!IS_INTRESOURCE(csA
->lpszName
))
800 name_lenA
= strlen(csA
->lpszName
) + 1;
801 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
804 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
809 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
813 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
814 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
815 csA
->lpszName
, name_lenA
);
818 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
820 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
821 mdi_cs
.szTitle
= csW
.lpszName
;
822 mdi_cs
.szClass
= csW
.lpszClass
;
823 csW
.lpCreateParams
= &mdi_cs
;
826 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
827 free_buffer( buffer
, ptr
);
833 WCHAR
*ptr
, buffer
[512];
834 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
835 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
836 MDICREATESTRUCTW csW
;
838 memcpy( &csW
, csA
, sizeof(csW
) );
840 if (!IS_INTRESOURCE(csA
->szTitle
))
842 title_lenA
= strlen(csA
->szTitle
) + 1;
843 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
845 if (!IS_INTRESOURCE(csA
->szClass
))
847 class_lenA
= strlen(csA
->szClass
) + 1;
848 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
851 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
856 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
860 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
861 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
862 csA
->szClass
, class_lenA
);
864 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
865 free_buffer( buffer
, ptr
);
870 case WM_ASKCBFORMATNAME
:
872 WCHAR
*ptr
, buffer
[512];
873 LPSTR str
= (LPSTR
)lParam
;
874 DWORD len
= wParam
* sizeof(WCHAR
);
876 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
877 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
882 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, strlenW(ptr
) * sizeof(WCHAR
) );
886 free_buffer( buffer
, ptr
);
891 case LB_INSERTSTRING
:
893 case LB_FINDSTRINGEXACT
:
894 case LB_SELECTSTRING
:
896 case CB_INSERTSTRING
:
898 case CB_FINDSTRINGEXACT
:
899 case CB_SELECTSTRING
:
900 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
902 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
907 case WM_WININICHANGE
:
908 case WM_DEVMODECHANGE
:
913 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
916 WCHAR
*ptr
, buffer
[512];
917 LPCSTR strA
= (LPCSTR
)lParam
;
918 DWORD lenW
, lenA
= strlen(strA
) + 1;
920 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
921 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
923 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
924 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
925 free_buffer( buffer
, ptr
);
932 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
934 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
936 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
940 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
941 buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
945 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
950 WCHAR
*ptr
, buffer
[512];
951 WORD len
= *(WORD
*)lParam
;
953 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
954 *((WORD
*)ptr
) = len
; /* store the length */
955 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
959 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
960 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
963 free_buffer( buffer
, ptr
);
970 MSG newmsg
= *(MSG
*)lParam
;
971 if (map_wparam_AtoW( newmsg
.message
, &newmsg
.wParam
, WMCHAR_MAP_NOMAPPING
))
972 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
974 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
983 case EM_SETPASSWORDCHAR
:
985 if (map_wparam_AtoW( msg
, &wParam
, mapping
))
986 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
989 case WM_GETTEXTLENGTH
:
990 case CB_GETLBTEXTLEN
:
992 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
995 WCHAR
*ptr
, buffer
[512];
997 DWORD len
= *result
+ 1;
998 /* Determine respective GETTEXT message */
999 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
1000 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
1001 /* wParam differs between the messages */
1002 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
1004 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
1006 if (callback
== call_window_proc
) /* FIXME: hack */
1007 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
1009 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
1010 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
1012 free_buffer( buffer
, ptr
);
1016 case WM_PAINTCLIPBOARD
:
1017 case WM_SIZECLIPBOARD
:
1018 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
1019 SPY_GetMsgName(msg
, hwnd
), msg
);
1023 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1030 /**********************************************************************
1031 * WINPROC_CallProcWtoA
1033 * Call a window procedure, translating args from Unicode to Ansi.
1035 static LRESULT
WINPROC_CallProcWtoA( 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=%08lx,lp=%08lx)\n",
1041 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1048 char buffer
[1024], *cls
;
1049 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
1050 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
1051 MDICREATESTRUCTA mdi_cs
;
1052 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1054 if (!IS_INTRESOURCE(csW
->lpszClass
))
1056 class_lenW
= (strlenW(csW
->lpszClass
) + 1) * sizeof(WCHAR
);
1057 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
1059 if (!IS_INTRESOURCE(csW
->lpszName
))
1061 name_lenW
= (strlenW(csW
->lpszName
) + 1) * sizeof(WCHAR
);
1062 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
1065 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
))) break;
1069 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
1070 csA
.lpszClass
= cls
;
1074 char *name
= cls
+ class_lenA
;
1075 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
1076 csA
.lpszName
= name
;
1079 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1081 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
1082 mdi_cs
.szTitle
= csA
.lpszName
;
1083 mdi_cs
.szClass
= csA
.lpszClass
;
1084 csA
.lpCreateParams
= &mdi_cs
;
1087 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1088 free_buffer( buffer
, cls
);
1093 case WM_ASKCBFORMATNAME
:
1095 char *ptr
, buffer
[512];
1096 DWORD len
= wParam
* 2;
1098 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
1099 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1104 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, strlen(ptr
)+1 );
1105 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
1107 ((LPWSTR
)lParam
)[*result
] = 0;
1109 free_buffer( buffer
, ptr
);
1114 case LB_INSERTSTRING
:
1116 case LB_FINDSTRINGEXACT
:
1117 case LB_SELECTSTRING
:
1119 case CB_INSERTSTRING
:
1121 case CB_FINDSTRINGEXACT
:
1122 case CB_SELECTSTRING
:
1123 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
1125 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1130 case WM_WININICHANGE
:
1131 case WM_DEVMODECHANGE
:
1136 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1139 char *ptr
, buffer
[512];
1140 LPCWSTR strW
= (LPCWSTR
)lParam
;
1141 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
1143 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
1144 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
1146 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
1147 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1148 free_buffer( buffer
, ptr
);
1155 char *ptr
, buffer
[1024];
1156 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1157 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1158 MDICREATESTRUCTA csA
;
1160 memcpy( &csA
, csW
, sizeof(csA
) );
1162 if (!IS_INTRESOURCE(csW
->szTitle
))
1164 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
1165 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
1167 if (!IS_INTRESOURCE(csW
->szClass
))
1169 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
1170 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
1173 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
1177 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
1182 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
1183 csA
.szClass
= ptr
+ title_lenA
;
1185 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1186 free_buffer( buffer
, ptr
);
1192 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
1194 char buffer
[512]; /* FIXME: fixed sized buffer */
1196 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
1200 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
1201 *result
= len
/ sizeof(WCHAR
) - 1;
1204 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1209 char *ptr
, buffer
[512];
1210 WORD len
= *(WORD
*)lParam
;
1212 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
1213 *((WORD
*)ptr
) = len
* 2; /* store the length */
1214 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1218 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
1219 *result
= reslen
/ sizeof(WCHAR
);
1220 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 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_WtoA( newmsg
.wParam
, 1 );
1239 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
1242 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
1244 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1253 RtlUnicodeToMultiByteN( ch
, 2, &len
, &wch
, sizeof(wch
) );
1254 ret
= callback( hwnd
, msg
, (BYTE
)ch
[0], lParam
, result
, arg
);
1255 if (len
== 2) ret
= callback( hwnd
, msg
, (BYTE
)ch
[1], lParam
, result
, arg
);
1263 case WM_SYSDEADCHAR
:
1264 case EM_SETPASSWORDCHAR
:
1265 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
1269 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
1272 case WM_PAINTCLIPBOARD
:
1273 case WM_SIZECLIPBOARD
:
1274 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
1275 SPY_GetMsgName(msg
, hwnd
), msg
);
1279 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1287 /**********************************************************************
1288 * WINPROC_CallProc16To32A
1290 LRESULT
WINPROC_CallProc16To32A( winproc_callback_t callback
, HWND16 hwnd
, UINT16 msg
,
1291 WPARAM16 wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1294 HWND hwnd32
= WIN_Handle32( hwnd
);
1296 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1297 hwnd32
, SPY_GetMsgName(msg
, hwnd32
), wParam
, lParam
);
1304 CREATESTRUCT16
*cs16
= MapSL(lParam
);
1306 MDICREATESTRUCTA mdi_cs
;
1308 CREATESTRUCT16to32A( cs16
, &cs
);
1309 if (GetWindowLongW(hwnd32
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1311 MDICREATESTRUCT16
*mdi_cs16
= MapSL(cs16
->lpCreateParams
);
1312 MDICREATESTRUCT16to32A(mdi_cs16
, &mdi_cs
);
1313 cs
.lpCreateParams
= &mdi_cs
;
1315 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1316 CREATESTRUCT32Ato16( &cs
, cs16
);
1321 MDICREATESTRUCT16
*cs16
= MapSL(lParam
);
1322 MDICREATESTRUCTA cs
;
1324 MDICREATESTRUCT16to32A( cs16
, &cs
);
1325 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1326 MDICREATESTRUCT32Ato16( &cs
, cs16
);
1329 case WM_MDIACTIVATE
:
1331 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32( HIWORD(lParam
) ),
1332 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1333 else /* message sent to MDI client */
1334 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1336 case WM_MDIGETACTIVE
:
1338 BOOL maximized
= FALSE
;
1339 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&maximized
, result
, arg
);
1340 *result
= MAKELRESULT( LOWORD(*result
), maximized
);
1344 ret
= callback( hwnd32
, wParam
? WM_MDIREFRESHMENU
: WM_MDISETMENU
,
1345 (WPARAM
)HMENU_32(LOWORD(lParam
)), (LPARAM
)HMENU_32(HIWORD(lParam
)),
1348 case WM_GETMINMAXINFO
:
1350 MINMAXINFO16
*mmi16
= MapSL(lParam
);
1353 MINMAXINFO16to32( mmi16
, &mmi
);
1354 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mmi
, result
, arg
);
1355 MINMAXINFO32to16( &mmi
, mmi16
);
1358 case WM_WINDOWPOSCHANGING
:
1359 case WM_WINDOWPOSCHANGED
:
1361 WINDOWPOS16
*winpos16
= MapSL(lParam
);
1364 WINDOWPOS16to32( winpos16
, &winpos
);
1365 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&winpos
, result
, arg
);
1366 WINDOWPOS32to16( &winpos
, winpos16
);
1371 NCCALCSIZE_PARAMS16
*nc16
= MapSL(lParam
);
1372 NCCALCSIZE_PARAMS nc
;
1375 RECT16to32( &nc16
->rgrc
[0], &nc
.rgrc
[0] );
1378 RECT16to32( &nc16
->rgrc
[1], &nc
.rgrc
[1] );
1379 RECT16to32( &nc16
->rgrc
[2], &nc
.rgrc
[2] );
1380 WINDOWPOS16to32( MapSL(nc16
->lppos
), &winpos
);
1383 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&nc
, result
, arg
);
1384 RECT32to16( &nc
.rgrc
[0], &nc16
->rgrc
[0] );
1387 RECT32to16( &nc
.rgrc
[1], &nc16
->rgrc
[1] );
1388 RECT32to16( &nc
.rgrc
[2], &nc16
->rgrc
[2] );
1389 WINDOWPOS32to16( &winpos
, MapSL(nc16
->lppos
) );
1393 case WM_COMPAREITEM
:
1395 COMPAREITEMSTRUCT16
* cis16
= MapSL(lParam
);
1396 COMPAREITEMSTRUCT cis
;
1397 cis
.CtlType
= cis16
->CtlType
;
1398 cis
.CtlID
= cis16
->CtlID
;
1399 cis
.hwndItem
= WIN_Handle32( cis16
->hwndItem
);
1400 cis
.itemID1
= cis16
->itemID1
;
1401 cis
.itemData1
= cis16
->itemData1
;
1402 cis
.itemID2
= cis16
->itemID2
;
1403 cis
.itemData2
= cis16
->itemData2
;
1404 cis
.dwLocaleId
= 0; /* FIXME */
1405 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cis
, result
, arg
);
1410 DELETEITEMSTRUCT16
* dis16
= MapSL(lParam
);
1411 DELETEITEMSTRUCT dis
;
1412 dis
.CtlType
= dis16
->CtlType
;
1413 dis
.CtlID
= dis16
->CtlID
;
1414 dis
.hwndItem
= WIN_Handle32( dis16
->hwndItem
);
1415 dis
.itemData
= dis16
->itemData
;
1416 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1419 case WM_MEASUREITEM
:
1421 MEASUREITEMSTRUCT16
* mis16
= MapSL(lParam
);
1422 MEASUREITEMSTRUCT mis
;
1423 mis
.CtlType
= mis16
->CtlType
;
1424 mis
.CtlID
= mis16
->CtlID
;
1425 mis
.itemID
= mis16
->itemID
;
1426 mis
.itemWidth
= mis16
->itemWidth
;
1427 mis
.itemHeight
= mis16
->itemHeight
;
1428 mis
.itemData
= mis16
->itemData
;
1429 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mis
, result
, arg
);
1430 mis16
->itemWidth
= (UINT16
)mis
.itemWidth
;
1431 mis16
->itemHeight
= (UINT16
)mis
.itemHeight
;
1436 DRAWITEMSTRUCT16
* dis16
= MapSL(lParam
);
1438 dis
.CtlType
= dis16
->CtlType
;
1439 dis
.CtlID
= dis16
->CtlID
;
1440 dis
.itemID
= dis16
->itemID
;
1441 dis
.itemAction
= dis16
->itemAction
;
1442 dis
.itemState
= dis16
->itemState
;
1443 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND
)HMENU_32(dis16
->hwndItem
)
1444 : WIN_Handle32( dis16
->hwndItem
);
1445 dis
.hDC
= HDC_32(dis16
->hDC
);
1446 dis
.itemData
= dis16
->itemData
;
1447 dis
.rcItem
.left
= dis16
->rcItem
.left
;
1448 dis
.rcItem
.top
= dis16
->rcItem
.top
;
1449 dis
.rcItem
.right
= dis16
->rcItem
.right
;
1450 dis
.rcItem
.bottom
= dis16
->rcItem
.bottom
;
1451 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1456 COPYDATASTRUCT16
*cds16
= MapSL(lParam
);
1458 cds
.dwData
= cds16
->dwData
;
1459 cds
.cbData
= cds16
->cbData
;
1460 cds
.lpData
= MapSL(cds16
->lpData
);
1461 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cds
, result
, arg
);
1467 MSG16
*msg16
= MapSL(lParam
);
1469 msg32
.hwnd
= WIN_Handle32( msg16
->hwnd
);
1470 msg32
.message
= msg16
->message
;
1471 msg32
.wParam
= msg16
->wParam
;
1472 msg32
.lParam
= msg16
->lParam
;
1473 msg32
.time
= msg16
->time
;
1474 msg32
.pt
.x
= msg16
->pt
.x
;
1475 msg32
.pt
.y
= msg16
->pt
.y
;
1476 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&msg32
, result
, arg
);
1479 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1484 next
.hmenuIn
= (HMENU
)lParam
;
1487 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&next
, result
, arg
);
1488 *result
= MAKELONG( HMENU_16(next
.hmenuNext
), HWND_16(next
.hwndNext
) );
1495 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1496 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1500 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1501 (LPARAM
)WIN_Handle32( HIWORD(lParam
) ), result
, arg
);
1504 if (HIWORD(lParam
) <= CTLCOLOR_STATIC
)
1505 ret
= callback( hwnd32
, WM_CTLCOLORMSGBOX
+ HIWORD(lParam
),
1506 (WPARAM
)HDC_32(wParam
), (LPARAM
)WIN_Handle32( LOWORD(lParam
) ),
1511 case WM_WININICHANGE
:
1512 case WM_DEVMODECHANGE
:
1513 case WM_ASKCBFORMATNAME
:
1515 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)MapSL(lParam
), result
, arg
);
1518 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1519 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1522 if((LOWORD(lParam
) & MF_POPUP
) && (LOWORD(lParam
) != 0xFFFF))
1524 HMENU hmenu
= HMENU_32(HIWORD(lParam
));
1525 UINT pos
= MENU_FindSubMenu( &hmenu
, HMENU_32(wParam
) );
1526 if (pos
== 0xffff) pos
= 0; /* NO_SELECTED_ITEM */
1529 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1530 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1532 case WM_PARENTNOTIFY
:
1533 if ((wParam
== WM_CREATE
) || (wParam
== WM_DESTROY
))
1534 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1535 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1537 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1539 case WM_ACTIVATEAPP
:
1540 /* We need this when SetActiveWindow sends a Sendmessage16() to
1541 * a 32-bit window. Might be superfluous with 32-bit interprocess
1542 * message queues. */
1543 if (lParam
) lParam
= HTASK_32(lParam
);
1544 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1546 case WM_DDE_INITIATE
:
1547 case WM_DDE_TERMINATE
:
1548 case WM_DDE_UNADVISE
:
1549 case WM_DDE_REQUEST
:
1550 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1556 HANDLE16 lo16
= LOWORD(lParam
);
1558 if (lo16
&& !(lo32
= convert_handle_16_to_32(lo16
, GMEM_DDESHARE
))) break;
1559 lParam
= PackDDElParam( msg
, lo32
, HIWORD(lParam
) );
1560 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1562 break; /* FIXME don't know how to free allocated memory (handle) !! */
1565 UINT_PTR lo
= LOWORD(lParam
);
1566 UINT_PTR hi
= HIWORD(lParam
);
1570 if (GlobalGetAtomNameA(hi
, buf
, 2) > 0) flag
|= 1;
1571 if (GlobalSize16(hi
) != 0) flag
|= 2;
1577 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1582 break; /* atom, nothing to do */
1584 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi
);
1587 hi
= convert_handle_16_to_32(hi
, GMEM_DDESHARE
);
1590 lParam
= PackDDElParam( WM_DDE_ACK
, lo
, hi
);
1591 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1593 break; /* FIXME don't know how to free allocated memory (handle) !! */
1594 case WM_DDE_EXECUTE
:
1595 lParam
= convert_handle_16_to_32( lParam
, GMEM_DDESHARE
);
1596 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1597 break; /* FIXME don't know how to free allocated memory (handle) !! */
1598 case WM_PAINTCLIPBOARD
:
1599 case WM_SIZECLIPBOARD
:
1600 FIXME_(msg
)( "message %04x needs translation\n", msg
);
1603 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1610 /**********************************************************************
1611 * __wine_call_wndproc (USER.1010)
1613 LRESULT WINAPI
__wine_call_wndproc( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
1619 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1621 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1626 /**********************************************************************
1627 * WINPROC_CallProc32ATo16
1629 * Call a 16-bit window procedure, translating the 32-bit args.
1631 LRESULT
WINPROC_CallProc32ATo16( winproc_callback16_t callback
, HWND hwnd
, UINT msg
,
1632 WPARAM wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1636 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1637 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1644 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)lParam
;
1646 MDICREATESTRUCT16 mdi_cs16
;
1647 BOOL mdi_child
= (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
);
1649 CREATESTRUCT32Ato16( cs32
, &cs
);
1650 cs
.lpszName
= MapLS( cs32
->lpszName
);
1651 cs
.lpszClass
= MapLS( cs32
->lpszClass
);
1655 MDICREATESTRUCTA
*mdi_cs
= cs32
->lpCreateParams
;
1656 MDICREATESTRUCT32Ato16( mdi_cs
, &mdi_cs16
);
1657 mdi_cs16
.szTitle
= MapLS( mdi_cs
->szTitle
);
1658 mdi_cs16
.szClass
= MapLS( mdi_cs
->szClass
);
1659 cs
.lpCreateParams
= MapLS( &mdi_cs16
);
1661 lParam
= MapLS( &cs
);
1662 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1664 UnMapLS( cs
.lpszName
);
1665 UnMapLS( cs
.lpszClass
);
1668 UnMapLS( cs
.lpCreateParams
);
1669 UnMapLS( mdi_cs16
.szTitle
);
1670 UnMapLS( mdi_cs16
.szClass
);
1676 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)lParam
;
1677 MDICREATESTRUCT16 cs
;
1679 MDICREATESTRUCT32Ato16( cs32
, &cs
);
1680 cs
.szTitle
= MapLS( cs32
->szTitle
);
1681 cs
.szClass
= MapLS( cs32
->szClass
);
1682 lParam
= MapLS( &cs
);
1683 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1685 UnMapLS( cs
.szTitle
);
1686 UnMapLS( cs
.szClass
);
1689 case WM_MDIACTIVATE
:
1690 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1691 ret
= callback( HWND_16(hwnd
), msg
, ((HWND
)lParam
== hwnd
),
1692 MAKELPARAM( LOWORD(lParam
), LOWORD(wParam
) ), result
, arg
);
1694 ret
= callback( HWND_16(hwnd
), msg
, HWND_16( wParam
), 0, result
, arg
);
1696 case WM_MDIGETACTIVE
:
1697 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1698 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(*result
);
1699 *result
= (LRESULT
)WIN_Handle32( LOWORD(*result
) );
1702 ret
= callback( HWND_16(hwnd
), msg
, (lParam
== 0),
1703 MAKELPARAM( LOWORD(wParam
), LOWORD(lParam
) ), result
, arg
);
1705 case WM_GETMINMAXINFO
:
1707 MINMAXINFO
*mmi32
= (MINMAXINFO
*)lParam
;
1710 MINMAXINFO32to16( mmi32
, &mmi
);
1711 lParam
= MapLS( &mmi
);
1712 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1714 MINMAXINFO16to32( &mmi
, mmi32
);
1719 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)lParam
;
1720 NCCALCSIZE_PARAMS16 nc
;
1723 RECT32to16( &nc32
->rgrc
[0], &nc
.rgrc
[0] );
1726 RECT32to16( &nc32
->rgrc
[1], &nc
.rgrc
[1] );
1727 RECT32to16( &nc32
->rgrc
[2], &nc
.rgrc
[2] );
1728 WINDOWPOS32to16( nc32
->lppos
, &winpos
);
1729 nc
.lppos
= MapLS( &winpos
);
1731 lParam
= MapLS( &nc
);
1732 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1734 RECT16to32( &nc
.rgrc
[0], &nc32
->rgrc
[0] );
1737 RECT16to32( &nc
.rgrc
[1], &nc32
->rgrc
[1] );
1738 RECT16to32( &nc
.rgrc
[2], &nc32
->rgrc
[2] );
1739 WINDOWPOS16to32( &winpos
, nc32
->lppos
);
1740 UnMapLS( nc
.lppos
);
1744 case WM_WINDOWPOSCHANGING
:
1745 case WM_WINDOWPOSCHANGED
:
1747 WINDOWPOS
*winpos32
= (WINDOWPOS
*)lParam
;
1750 WINDOWPOS32to16( winpos32
, &winpos
);
1751 lParam
= MapLS( &winpos
);
1752 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1754 WINDOWPOS16to32( &winpos
, winpos32
);
1757 case WM_COMPAREITEM
:
1759 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)lParam
;
1760 COMPAREITEMSTRUCT16 cis
;
1761 cis
.CtlType
= cis32
->CtlType
;
1762 cis
.CtlID
= cis32
->CtlID
;
1763 cis
.hwndItem
= HWND_16( cis32
->hwndItem
);
1764 cis
.itemID1
= cis32
->itemID1
;
1765 cis
.itemData1
= cis32
->itemData1
;
1766 cis
.itemID2
= cis32
->itemID2
;
1767 cis
.itemData2
= cis32
->itemData2
;
1768 lParam
= MapLS( &cis
);
1769 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1775 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)lParam
;
1776 DELETEITEMSTRUCT16 dis
;
1777 dis
.CtlType
= dis32
->CtlType
;
1778 dis
.CtlID
= dis32
->CtlID
;
1779 dis
.itemID
= dis32
->itemID
;
1780 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND16
)LOWORD(dis32
->hwndItem
)
1781 : HWND_16( dis32
->hwndItem
);
1782 dis
.itemData
= dis32
->itemData
;
1783 lParam
= MapLS( &dis
);
1784 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1790 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)lParam
;
1791 DRAWITEMSTRUCT16 dis
;
1792 dis
.CtlType
= dis32
->CtlType
;
1793 dis
.CtlID
= dis32
->CtlID
;
1794 dis
.itemID
= dis32
->itemID
;
1795 dis
.itemAction
= dis32
->itemAction
;
1796 dis
.itemState
= dis32
->itemState
;
1797 dis
.hwndItem
= HWND_16( dis32
->hwndItem
);
1798 dis
.hDC
= HDC_16(dis32
->hDC
);
1799 dis
.itemData
= dis32
->itemData
;
1800 dis
.rcItem
.left
= dis32
->rcItem
.left
;
1801 dis
.rcItem
.top
= dis32
->rcItem
.top
;
1802 dis
.rcItem
.right
= dis32
->rcItem
.right
;
1803 dis
.rcItem
.bottom
= dis32
->rcItem
.bottom
;
1804 lParam
= MapLS( &dis
);
1805 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1809 case WM_MEASUREITEM
:
1811 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)lParam
;
1812 MEASUREITEMSTRUCT16 mis
;
1813 mis
.CtlType
= mis32
->CtlType
;
1814 mis
.CtlID
= mis32
->CtlID
;
1815 mis
.itemID
= mis32
->itemID
;
1816 mis
.itemWidth
= mis32
->itemWidth
;
1817 mis
.itemHeight
= mis32
->itemHeight
;
1818 mis
.itemData
= mis32
->itemData
;
1819 lParam
= MapLS( &mis
);
1820 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1822 mis32
->itemWidth
= mis
.itemWidth
;
1823 mis32
->itemHeight
= mis
.itemHeight
;
1828 COPYDATASTRUCT
*cds32
= (COPYDATASTRUCT
*)lParam
;
1829 COPYDATASTRUCT16 cds
;
1831 cds
.dwData
= cds32
->dwData
;
1832 cds
.cbData
= cds32
->cbData
;
1833 cds
.lpData
= MapLS( cds32
->lpData
);
1834 lParam
= MapLS( &cds
);
1835 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1837 UnMapLS( cds
.lpData
);
1843 MSG
*msg32
= (MSG
*)lParam
;
1846 msg16
.hwnd
= HWND_16( msg32
->hwnd
);
1847 msg16
.message
= msg32
->message
;
1848 msg16
.wParam
= msg32
->wParam
;
1849 msg16
.lParam
= msg32
->lParam
;
1850 msg16
.time
= msg32
->time
;
1851 msg16
.pt
.x
= msg32
->pt
.x
;
1852 msg16
.pt
.y
= msg32
->pt
.y
;
1853 lParam
= MapLS( &msg16
);
1854 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1858 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1862 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
1863 ret
= callback( HWND_16(hwnd
), msg
, wParam
, (LPARAM
)next
->hmenuIn
, result
, arg
);
1864 next
->hmenuNext
= HMENU_32( LOWORD(*result
) );
1865 next
->hwndNext
= WIN_Handle32( HIWORD(*result
) );
1870 case WM_ASKCBFORMATNAME
:
1871 wParam
= min( wParam
, 0xff80 ); /* Must be < 64K */
1875 case WM_WININICHANGE
:
1876 case WM_DEVMODECHANGE
:
1877 lParam
= MapLS( (void *)lParam
);
1878 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1885 ret
= callback( HWND_16(hwnd
), msg
, wParam
, MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ),
1890 ret
= callback( HWND_16(hwnd
), msg
, wParam
, MAKELPARAM( HIWORD(wParam
), (HWND16
)lParam
),
1893 case WM_CTLCOLORMSGBOX
:
1894 case WM_CTLCOLOREDIT
:
1895 case WM_CTLCOLORLISTBOX
:
1896 case WM_CTLCOLORBTN
:
1897 case WM_CTLCOLORDLG
:
1898 case WM_CTLCOLORSCROLLBAR
:
1899 case WM_CTLCOLORSTATIC
:
1900 ret
= callback( HWND_16(hwnd
), WM_CTLCOLOR
, wParam
,
1901 MAKELPARAM( (HWND16
)lParam
, msg
- WM_CTLCOLORMSGBOX
), result
, arg
);
1904 if(HIWORD(wParam
) & MF_POPUP
)
1907 if ((HIWORD(wParam
) != 0xffff) || lParam
)
1909 if ((hmenu
= GetSubMenu( (HMENU
)lParam
, LOWORD(wParam
) )))
1911 ret
= callback( HWND_16(hwnd
), msg
, HMENU_16(hmenu
),
1912 MAKELPARAM( HIWORD(wParam
), (HMENU16
)lParam
), result
, arg
);
1919 ret
= callback( HWND_16(hwnd
), msg
, wParam
,
1920 MAKELPARAM( HIWORD(wParam
), (HMENU16
)lParam
), result
, arg
);
1922 case WM_PARENTNOTIFY
:
1923 if ((LOWORD(wParam
) == WM_CREATE
) || (LOWORD(wParam
) == WM_DESTROY
))
1924 ret
= callback( HWND_16(hwnd
), msg
, wParam
,
1925 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ), result
, arg
);
1927 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1929 case WM_ACTIVATEAPP
:
1930 ret
= callback( HWND_16(hwnd
), msg
, wParam
, HTASK_16( lParam
), result
, arg
);
1933 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
))
1934 ret
= callback( HWND_16(hwnd
), WM_PAINTICON
, 1, lParam
, result
, arg
);
1936 ret
= callback( HWND_16(hwnd
), WM_PAINT
, wParam
, lParam
, result
, arg
);
1939 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
)) msg
= WM_ICONERASEBKGND
;
1940 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1942 case WM_DDE_INITIATE
:
1943 case WM_DDE_TERMINATE
:
1944 case WM_DDE_UNADVISE
:
1945 case WM_DDE_REQUEST
:
1946 ret
= callback( HWND_16(hwnd
), msg
, HWND_16(wParam
), lParam
, result
, arg
);
1955 UnpackDDElParam( msg
, lParam
, &lo32
, &hi
);
1956 if (lo32
&& !(lo16
= convert_handle_32_to_16(lo32
, GMEM_DDESHARE
))) break;
1957 ret
= callback( HWND_16(hwnd
), msg
, HWND_16(wParam
),
1958 MAKELPARAM(lo16
, hi
), result
, arg
);
1960 break; /* FIXME don't know how to free allocated memory (handle) !! */
1967 UnpackDDElParam( msg
, lParam
, &lo
, &hi
);
1969 if (GlobalGetAtomNameA((ATOM
)hi
, buf
, sizeof(buf
)) > 0) flag
|= 1;
1970 if (GlobalSize((HANDLE
)hi
) != 0) flag
|= 2;
1976 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1981 break; /* atom, nothing to do */
1983 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi
);
1986 hi
= convert_handle_32_to_16(hi
, GMEM_DDESHARE
);
1989 ret
= callback( HWND_16(hwnd
), msg
, HWND_16(wParam
),
1990 MAKELPARAM(lo
, hi
), result
, arg
);
1992 break; /* FIXME don't know how to free allocated memory (handle) !! */
1993 case WM_DDE_EXECUTE
:
1994 lParam
= convert_handle_32_to_16(lParam
, GMEM_DDESHARE
);
1995 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1996 break; /* FIXME don't know how to free allocated memory (handle) !! */
1998 ret
= callback( HWND_16(hwnd
), SBM_SETRANGE16
, 0, MAKELPARAM(wParam
, lParam
), result
, arg
);
2001 ret
= callback( HWND_16(hwnd
), SBM_GETRANGE16
, wParam
, lParam
, result
, arg
);
2002 *(LPINT
)wParam
= LOWORD(*result
);
2003 *(LPINT
)lParam
= HIWORD(*result
);
2010 ret
= callback( HWND_16(hwnd
), msg
+ BM_GETCHECK16
- BM_GETCHECK
, wParam
, lParam
, result
, arg
);
2018 case EM_SCROLLCARET
:
2021 case EM_GETLINECOUNT
:
2033 case EM_LINEFROMCHAR
:
2034 case EM_SETTABSTOPS
:
2035 case EM_SETPASSWORDCHAR
:
2036 case EM_EMPTYUNDOBUFFER
:
2037 case EM_GETFIRSTVISIBLELINE
:
2038 case EM_SETREADONLY
:
2039 case EM_SETWORDBREAKPROC
:
2040 case EM_GETWORDBREAKPROC
:
2041 case EM_GETPASSWORDCHAR
:
2042 ret
= callback( HWND_16(hwnd
), msg
+ EM_GETSEL16
- EM_GETSEL
, wParam
, lParam
, result
, arg
);
2045 ret
= callback( HWND_16(hwnd
), EM_SETSEL16
, 0, MAKELPARAM( wParam
, lParam
), result
, arg
);
2049 case LB_DELETESTRING
:
2050 case LB_GETANCHORINDEX
:
2051 case LB_GETCARETINDEX
:
2054 case LB_GETHORIZONTALEXTENT
:
2055 case LB_GETITEMDATA
:
2056 case LB_GETITEMHEIGHT
:
2058 case LB_GETSELCOUNT
:
2060 case LB_GETTOPINDEX
:
2061 case LB_RESETCONTENT
:
2062 case LB_SELITEMRANGE
:
2063 case LB_SELITEMRANGEEX
:
2064 case LB_SETANCHORINDEX
:
2065 case LB_SETCARETINDEX
:
2066 case LB_SETCOLUMNWIDTH
:
2068 case LB_SETHORIZONTALEXTENT
:
2069 case LB_SETITEMDATA
:
2070 case LB_SETITEMHEIGHT
:
2072 case LB_SETTOPINDEX
:
2073 ret
= callback( HWND_16(hwnd
), msg
+ LB_ADDSTRING16
- LB_ADDSTRING
, wParam
, lParam
, result
, arg
);
2077 case LB_FINDSTRINGEXACT
:
2078 case LB_INSERTSTRING
:
2079 case LB_SELECTSTRING
:
2083 lParam
= MapLS( (LPSTR
)lParam
);
2084 ret
= callback( HWND_16(hwnd
), msg
+ LB_ADDSTRING16
- LB_ADDSTRING
, wParam
, lParam
, result
, arg
);
2087 case LB_GETSELITEMS
:
2089 INT
*items32
= (INT
*)lParam
;
2090 INT16
*items
, buffer
[512];
2093 wParam
= min( wParam
, 0x7f80 ); /* Must be < 64K */
2094 if (!(items
= get_buffer( buffer
, sizeof(buffer
), wParam
* sizeof(INT16
) ))) break;
2095 lParam
= MapLS( items
);
2096 ret
= callback( HWND_16(hwnd
), LB_GETSELITEMS16
, wParam
, lParam
, result
, arg
);
2098 for (i
= 0; i
< wParam
; i
++) items32
[i
] = items
[i
];
2099 free_buffer( buffer
, items
);
2102 case LB_SETTABSTOPS
:
2105 INT
*stops32
= (INT
*)lParam
;
2106 INT16
*stops
, buffer
[512];
2109 wParam
= min( wParam
, 0x7f80 ); /* Must be < 64K */
2110 if (!(stops
= get_buffer( buffer
, sizeof(buffer
), wParam
* sizeof(INT16
) ))) break;
2111 for (i
= 0; i
< wParam
; i
++) stops
[i
] = stops32
[i
];
2112 lParam
= MapLS( stops
);
2113 ret
= callback( HWND_16(hwnd
), LB_SETTABSTOPS16
, wParam
, lParam
, result
, arg
);
2115 free_buffer( buffer
, stops
);
2117 else ret
= callback( HWND_16(hwnd
), LB_SETTABSTOPS16
, wParam
, lParam
, result
, arg
);
2119 case CB_DELETESTRING
:
2121 case CB_GETLBTEXTLEN
:
2123 case CB_RESETCONTENT
:
2127 case CB_SHOWDROPDOWN
:
2128 case CB_SETITEMDATA
:
2129 case CB_SETITEMHEIGHT
:
2130 case CB_GETITEMHEIGHT
:
2131 case CB_SETEXTENDEDUI
:
2132 case CB_GETEXTENDEDUI
:
2133 case CB_GETDROPPEDSTATE
:
2134 ret
= callback( HWND_16(hwnd
), msg
+ CB_GETEDITSEL16
- CB_GETEDITSEL
, wParam
, lParam
, result
, arg
);
2137 ret
= callback( HWND_16(hwnd
), CB_GETEDITSEL16
, wParam
, lParam
, result
, arg
);
2138 if (wParam
) *((PUINT
)(wParam
)) = LOWORD(*result
);
2139 if (lParam
) *((PUINT
)(lParam
)) = HIWORD(*result
); /* FIXME: substract 1? */
2143 case CB_FINDSTRINGEXACT
:
2144 case CB_INSERTSTRING
:
2145 case CB_SELECTSTRING
:
2148 lParam
= MapLS( (LPSTR
)lParam
);
2149 ret
= callback( HWND_16(hwnd
), msg
+ CB_GETEDITSEL16
- CB_GETEDITSEL
, wParam
, lParam
, result
, arg
);
2152 case LB_GETITEMRECT
:
2153 case CB_GETDROPPEDCONTROLRECT
:
2155 RECT
*r32
= (RECT
*)lParam
;
2157 lParam
= MapLS( &rect
);
2158 ret
= callback( HWND_16(hwnd
),
2159 (msg
== LB_GETITEMRECT
) ? LB_GETITEMRECT16
: CB_GETDROPPEDCONTROLRECT16
,
2160 wParam
, lParam
, result
, arg
);
2162 RECT16to32( &rect
, r32
);
2165 case WM_PAINTCLIPBOARD
:
2166 case WM_SIZECLIPBOARD
:
2167 FIXME_(msg
)( "message %04x needs translation\n", msg
);
2169 /* the following messages should not be sent to 16-bit apps */
2172 case WM_CAPTURECHANGED
:
2173 case WM_STYLECHANGING
:
2174 case WM_STYLECHANGED
:
2177 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2184 /**********************************************************************
2185 * WINPROC_call_window
2187 * Call the window procedure of the specified window.
2189 BOOL
WINPROC_call_window( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2190 LRESULT
*result
, BOOL unicode
, enum wm_char_mapping mapping
)
2192 struct user_thread_info
*thread_info
= get_user_thread_info();
2196 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return FALSE
;
2197 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
2198 if (wndPtr
->tid
!= GetCurrentThreadId())
2200 WIN_ReleasePtr( wndPtr
);
2203 proc
= handle_to_proc( wndPtr
->winproc
);
2204 WIN_ReleasePtr( wndPtr
);
2206 if (!proc
) return TRUE
;
2208 if (thread_info
->recursion_count
> MAX_WINPROC_RECURSION
) return FALSE
;
2209 thread_info
->recursion_count
++;
2214 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
2215 else if (proc
->procA
)
2216 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
2218 WINPROC_CallProcWtoA( call_window_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, result
, proc
->proc16
);
2223 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
2224 else if (proc
->procW
)
2225 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
2227 WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wParam
, lParam
, result
, proc
->proc16
);
2229 thread_info
->recursion_count
--;
2234 /**********************************************************************
2235 * CallWindowProc (USER.122)
2237 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2238 WPARAM16 wParam
, LPARAM lParam
)
2243 if (!func
) return 0;
2245 if (!(proc
= handle16_to_proc( func
)))
2246 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2247 else if (proc
->procA
)
2248 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2249 else if (proc
->procW
)
2250 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2252 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2258 /**********************************************************************
2259 * CallWindowProcA (USER32.@)
2261 * The CallWindowProc() function invokes the windows procedure _func_,
2262 * with _hwnd_ as the target window, the message specified by _msg_, and
2263 * the message parameters _wParam_ and _lParam_.
2265 * Some kinds of argument conversion may be done, I'm not sure what.
2267 * CallWindowProc() may be used for windows subclassing. Use
2268 * SetWindowLong() to set a new windows procedure for windows of the
2269 * subclass, and handle subclassed messages in the new windows
2270 * procedure. The new windows procedure may then use CallWindowProc()
2271 * with _func_ set to the parent class's windows procedure to dispatch
2272 * the message to the superclass.
2276 * The return value is message dependent.
2282 LRESULT WINAPI
CallWindowProcA(
2283 WNDPROC func
, /* [in] window procedure */
2284 HWND hwnd
, /* [in] target window */
2285 UINT msg
, /* [in] message */
2286 WPARAM wParam
, /* [in] message dependent parameter */
2287 LPARAM lParam
/* [in] message dependent parameter */
2292 if (!func
) return 0;
2294 if (!(proc
= handle_to_proc( func
)))
2295 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2296 else if (proc
->procA
)
2297 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2298 else if (proc
->procW
)
2299 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
2300 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
2302 WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2307 /**********************************************************************
2308 * CallWindowProcW (USER32.@)
2310 * See CallWindowProcA.
2312 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
2313 WPARAM wParam
, LPARAM lParam
)
2318 if (!func
) return 0;
2320 if (!(proc
= handle_to_proc( func
)))
2321 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2322 else if (proc
->procW
)
2323 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2324 else if (proc
->procA
)
2325 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2327 WINPROC_CallProcWtoA( call_window_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2332 /**********************************************************************
2333 * WINPROC_CallDlgProc16
2335 INT_PTR
WINPROC_CallDlgProc16( DLGPROC16 func
, HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
2341 if (!func
) return 0;
2343 if (!(proc
= handle16_to_proc( (WNDPROC16
)func
)))
2345 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2347 else if (proc
->procA
)
2349 ret
= WINPROC_CallProc16To32A( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
,
2350 &result
, proc
->procA
);
2351 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2353 else if (proc
->procW
)
2355 ret
= WINPROC_CallProc16To32A( call_dialog_proc_AtoW
, hwnd
, msg
, wParam
, lParam
,
2356 &result
, proc
->procW
);
2357 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2361 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2367 /**********************************************************************
2368 * WINPROC_CallDlgProcA
2370 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2376 if (!func
) return 0;
2378 if (!(proc
= handle_to_proc( func
)))
2379 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2380 else if (proc
->procA
)
2381 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2382 else if (proc
->procW
)
2384 ret
= WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
2385 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
2386 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2390 ret
= WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2391 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2397 /**********************************************************************
2398 * WINPROC_CallDlgProcW
2400 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2406 if (!func
) return 0;
2408 if (!(proc
= handle_to_proc( func
)))
2409 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2410 else if (proc
->procW
)
2411 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2412 else if (proc
->procA
)
2414 ret
= WINPROC_CallProcWtoA( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2415 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2419 ret
= WINPROC_CallProcWtoA( call_dialog_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2420 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);