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"
37 #include "user_private.h"
40 #include "wine/unicode.h"
41 #include "wine/debug.h"
43 WINE_DECLARE_DEBUG_CHANNEL(msg
);
44 WINE_DECLARE_DEBUG_CHANNEL(relay
);
45 WINE_DEFAULT_DEBUG_CHANNEL(win
);
47 typedef struct tagWINDOWPROC
49 WNDPROC16 proc16
; /* 16-bit window proc */
50 WNDPROC procA
; /* ASCII window proc */
51 WNDPROC procW
; /* Unicode window proc */
54 #define WINPROC_HANDLE (~0UL >> 16)
55 #define MAX_WINPROCS 8192
56 #define BUILTIN_WINPROCS 8 /* first BUILTIN_WINPROCS entries are reserved for builtin procs */
58 static WINDOWPROC winproc_array
[MAX_WINPROCS
];
59 static UINT builtin_used
;
60 static UINT winproc_used
= BUILTIN_WINPROCS
;
62 static CRITICAL_SECTION winproc_cs
;
63 static CRITICAL_SECTION_DEBUG critsect_debug
=
66 { &critsect_debug
.ProcessLocksList
, &critsect_debug
.ProcessLocksList
},
67 0, 0, { (DWORD_PTR
)(__FILE__
": winproc_cs") }
69 static CRITICAL_SECTION winproc_cs
= { &critsect_debug
, -1, 0, 0, 0, 0 };
71 static inline void *get_buffer( void *static_buffer
, size_t size
, size_t need
)
73 if (size
>= need
) return static_buffer
;
74 return HeapAlloc( GetProcessHeap(), 0, need
);
77 static inline void free_buffer( void *static_buffer
, void *buffer
)
79 if (buffer
!= static_buffer
) HeapFree( GetProcessHeap(), 0, buffer
);
82 /* find an existing winproc for a given 16-bit function and type */
83 /* FIXME: probably should do something more clever than a linear search */
84 static inline WINDOWPROC
*find_winproc16( WNDPROC16 func
)
88 for (i
= BUILTIN_WINPROCS
; i
< winproc_used
; i
++)
90 if (winproc_array
[i
].proc16
== func
) return &winproc_array
[i
];
95 /* find an existing winproc for a given function and type */
96 /* FIXME: probably should do something more clever than a linear search */
97 static inline WINDOWPROC
*find_winproc( WNDPROC funcA
, WNDPROC funcW
)
101 for (i
= 0; i
< builtin_used
; i
++)
103 /* match either proc, some apps confuse A and W */
104 if (funcA
&& winproc_array
[i
].procA
!= funcA
&& winproc_array
[i
].procW
!= funcA
) continue;
105 if (funcW
&& winproc_array
[i
].procA
!= funcW
&& winproc_array
[i
].procW
!= funcW
) continue;
106 return &winproc_array
[i
];
108 for (i
= BUILTIN_WINPROCS
; i
< winproc_used
; i
++)
110 if (funcA
&& winproc_array
[i
].procA
!= funcA
) continue;
111 if (funcW
&& winproc_array
[i
].procW
!= funcW
) continue;
112 return &winproc_array
[i
];
117 /* find an existing builtin winproc */
118 static inline WINDOWPROC
*find_builtin_proc( WNDPROC func
)
122 for (i
= 0; i
< builtin_used
; i
++)
124 if (winproc_array
[i
].procA
== func
|| winproc_array
[i
].procW
== func
)
125 return &winproc_array
[i
];
130 /* return the window proc for a given handle, or NULL for an invalid handle */
131 static inline WINDOWPROC
*handle_to_proc( WNDPROC handle
)
133 UINT index
= LOWORD(handle
);
134 if ((ULONG_PTR
)handle
>> 16 != WINPROC_HANDLE
) return NULL
;
135 if (index
>= winproc_used
) return NULL
;
136 return &winproc_array
[index
];
139 /* create a handle for a given window proc */
140 static inline WNDPROC
proc_to_handle( WINDOWPROC
*proc
)
142 return (WNDPROC
)(ULONG_PTR
)((proc
- winproc_array
) | (WINPROC_HANDLE
<< 16));
145 /* allocate and initialize a new winproc */
146 static inline WINDOWPROC
*alloc_winproc( WNDPROC funcA
, WNDPROC funcW
)
150 /* check if the function is already a win proc */
151 if (funcA
&& (proc
= handle_to_proc( funcA
))) return proc
;
152 if (funcW
&& (proc
= handle_to_proc( funcW
))) return proc
;
153 if (!funcA
&& !funcW
) return NULL
;
155 EnterCriticalSection( &winproc_cs
);
157 /* check if we already have a winproc for that function */
158 if (!(proc
= find_winproc( funcA
, funcW
)))
162 assert( builtin_used
< BUILTIN_WINPROCS
);
163 proc
= &winproc_array
[builtin_used
++];
166 TRACE( "allocated %p for builtin %p/%p (%d/%d used)\n",
167 proc_to_handle(proc
), funcA
, funcW
, builtin_used
, BUILTIN_WINPROCS
);
169 else if (winproc_used
< MAX_WINPROCS
)
171 proc
= &winproc_array
[winproc_used
++];
174 TRACE( "allocated %p for %c %p (%d/%d used)\n",
175 proc_to_handle(proc
), funcA
? 'A' : 'W', funcA
? funcA
: funcW
,
176 winproc_used
, MAX_WINPROCS
);
178 else FIXME( "too many winprocs, cannot allocate one for %p/%p\n", funcA
, funcW
);
180 else TRACE( "reusing %p for %p/%p\n", proc_to_handle(proc
), funcA
, funcW
);
182 LeaveCriticalSection( &winproc_cs
);
189 #include "pshpack1.h"
191 /* Window procedure 16-to-32-bit thunk */
194 BYTE popl_eax
; /* popl %eax (return address) */
195 BYTE pushl_func
; /* pushl $proc */
197 BYTE pushl_eax
; /* pushl %eax */
198 BYTE ljmp
; /* ljmp relay*/
199 DWORD relay_offset
; /* __wine_call_wndproc */
205 #define MAX_THUNKS (0x10000 / sizeof(WINPROC_THUNK))
207 static WINPROC_THUNK
*thunk_array
;
208 static UINT thunk_selector
;
209 static UINT thunk_used
;
211 /* return the window proc for a given handle, or NULL for an invalid handle */
212 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
214 if (HIWORD(handle
) == thunk_selector
)
216 UINT index
= LOWORD(handle
) / sizeof(WINPROC_THUNK
);
217 /* check alignment */
218 if (index
* sizeof(WINPROC_THUNK
) != LOWORD(handle
)) return NULL
;
219 /* check array limits */
220 if (index
>= thunk_used
) return NULL
;
221 return thunk_array
[index
].proc
;
223 return handle_to_proc( (WNDPROC
)handle
);
226 /* allocate a 16-bit thunk for an existing window proc */
227 static WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
229 static FARPROC16 relay
;
232 if (proc
->proc16
) return proc
->proc16
;
234 EnterCriticalSection( &winproc_cs
);
236 if (!thunk_array
) /* allocate the array and its selector */
240 if (!(thunk_selector
= wine_ldt_alloc_entries(1))) goto done
;
241 if (!(thunk_array
= VirtualAlloc( NULL
, MAX_THUNKS
* sizeof(WINPROC_THUNK
), MEM_COMMIT
,
242 PAGE_EXECUTE_READWRITE
))) goto done
;
243 wine_ldt_set_base( &entry
, thunk_array
);
244 wine_ldt_set_limit( &entry
, MAX_THUNKS
* sizeof(WINPROC_THUNK
) - 1 );
245 wine_ldt_set_flags( &entry
, WINE_LDT_FLAGS_CODE
| WINE_LDT_FLAGS_32BIT
);
246 wine_ldt_set_entry( thunk_selector
, &entry
);
247 relay
= GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
250 /* check if it already exists */
251 for (i
= 0; i
< thunk_used
; i
++) if (thunk_array
[i
].proc
== proc
) break;
253 if (i
== thunk_used
) /* create a new one */
255 WINPROC_THUNK
*thunk
;
257 if (thunk_used
>= MAX_THUNKS
) goto done
;
258 thunk
= &thunk_array
[thunk_used
++];
259 thunk
->popl_eax
= 0x58; /* popl %eax */
260 thunk
->pushl_func
= 0x68; /* pushl $proc */
262 thunk
->pushl_eax
= 0x50; /* pushl %eax */
263 thunk
->ljmp
= 0xea; /* ljmp relay*/
264 thunk
->relay_offset
= OFFSETOF(relay
);
265 thunk
->relay_sel
= SELECTOROF(relay
);
267 proc
->proc16
= (WNDPROC16
)MAKESEGPTR( thunk_selector
, i
* sizeof(WINPROC_THUNK
) );
269 LeaveCriticalSection( &winproc_cs
);
275 static inline WINDOWPROC
*handle16_to_proc( WNDPROC16 handle
)
277 return handle_to_proc( (WNDPROC
)handle
);
280 static inline WNDPROC16
alloc_win16_thunk( WINDOWPROC
*proc
)
285 #endif /* __i386__ */
289 /* Some window procedures modify register they shouldn't, or are not
290 * properly declared stdcall; so we need a small assembly wrapper to
292 extern LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
293 WPARAM wParam
, LPARAM lParam
);
294 __ASM_GLOBAL_FUNC( WINPROC_wrapper
,
305 "movl 8(%ebp),%eax\n\t"
307 "leal -12(%ebp),%esp\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_AtoW( WPARAM wParam
, DWORD len
)
450 ch
[0] = (wParam
>> 8);
451 ch
[1] = wParam
& 0xff;
452 if (len
> 1 && ch
[0])
453 RtlMultiByteToUnicodeN( &wch
, sizeof(wch
), NULL
, ch
, 2 );
455 RtlMultiByteToUnicodeN( &wch
, sizeof(wch
), NULL
, ch
+ 1, 1 );
456 return MAKEWPARAM( wch
, HIWORD(wParam
) );
459 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
464 RtlUnicodeToMultiByteN( (LPSTR
)ch
, len
, &len
, &wch
, sizeof(wch
) );
466 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
468 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
471 /* call a 32-bit window procedure */
472 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
478 hwnd
= WIN_GetFullHandle( hwnd
);
480 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
481 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
483 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
486 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
487 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
491 /* call a 32-bit dialog procedure */
492 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
499 hwnd
= WIN_GetFullHandle( hwnd
);
501 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
502 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
504 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
505 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
508 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
509 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
513 /* call a 16-bit window procedure */
514 static LRESULT
call_window_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
515 LRESULT
*result
, void *arg
)
517 WNDPROC16 proc
= arg
;
526 DRAWITEMSTRUCT16 dis16
;
527 COMPAREITEMSTRUCT16 cis16
;
533 /* Window procedures want ax = hInstance, ds = es = ss */
535 memset(&context
, 0, sizeof(context
));
536 context
.SegDs
= context
.SegEs
= SELECTOROF(NtCurrentTeb()->WOW32Reserved
);
537 context
.SegFs
= wine_get_fs();
538 context
.SegGs
= wine_get_gs();
539 if (!(context
.Eax
= GetWindowWord( HWND_32(hwnd
), GWLP_HINSTANCE
))) context
.Eax
= context
.SegDs
;
540 context
.SegCs
= SELECTOROF(proc
);
541 context
.Eip
= OFFSETOF(proc
);
542 context
.Ebp
= OFFSETOF(NtCurrentTeb()->WOW32Reserved
) + (WORD
)&((STACK16FRAME
*)0)->bp
;
546 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
547 work if structures passed in lParam are placed in the stack/data
548 segment. Programmers easily make the mistake of converting lParam
549 to a near rather than a far pointer, since Windows apparently
550 allows this. We copy the structures to the 16 bit stack; this is
551 ugly but makes these programs work. */
556 size
= sizeof(CREATESTRUCT16
); break;
558 size
= sizeof(DRAWITEMSTRUCT16
); break;
560 size
= sizeof(COMPAREITEMSTRUCT16
); break;
564 memcpy( &args
.u
, MapSL(lParam
), size
);
565 lParam
= PtrToUlong(NtCurrentTeb()->WOW32Reserved
) - size
;
569 args
.params
[4] = hwnd
;
570 args
.params
[3] = msg
;
571 args
.params
[2] = wParam
;
572 args
.params
[1] = HIWORD(lParam
);
573 args
.params
[0] = LOWORD(lParam
);
574 WOWCallback16Ex( 0, WCB16_REGS
, sizeof(args
.params
) + size
, &args
, (DWORD
*)&context
);
575 *result
= MAKELONG( LOWORD(context
.Eax
), LOWORD(context
.Edx
) );
579 /* call a 16-bit dialog procedure */
580 static LRESULT
call_dialog_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wp
, LPARAM lp
,
581 LRESULT
*result
, void *arg
)
583 LRESULT ret
= call_window_proc16( hwnd
, msg
, wp
, lp
, result
, arg
);
584 *result
= GetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
);
588 /* helper callback for 32W->16 conversion */
589 static LRESULT
call_window_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
590 LRESULT
*result
, void *arg
)
592 return WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
595 /* helper callback for 32W->16 conversion */
596 static LRESULT
call_dialog_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
597 LRESULT
*result
, void *arg
)
599 return WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
602 /* helper callback for 16->32W conversion */
603 static LRESULT
call_window_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
604 LRESULT
*result
, void *arg
)
606 return WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wp
, lp
, result
, arg
);
609 /* helper callback for 16->32W conversion */
610 static LRESULT
call_dialog_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
611 LRESULT
*result
, void *arg
)
613 return WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wp
, lp
, result
, arg
);
617 /**********************************************************************
620 * Get a window procedure pointer that can be passed to the Windows program.
622 WNDPROC16
WINPROC_GetProc16( WNDPROC proc
, BOOL unicode
)
626 if (unicode
) ptr
= alloc_winproc( NULL
, proc
);
627 else ptr
= alloc_winproc( proc
, NULL
);
630 return alloc_win16_thunk( ptr
);
634 /**********************************************************************
637 * Get a window procedure pointer that can be passed to the Windows program.
639 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
641 WINDOWPROC
*ptr
= handle_to_proc( proc
);
643 if (!ptr
) return proc
;
646 if (ptr
->procW
) return ptr
->procW
;
651 if (ptr
->procA
) return ptr
->procA
;
657 /**********************************************************************
658 * WINPROC_AllocProc16
660 * Allocate a window procedure for a window or class.
662 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
663 * lot of windows, it will usually only have a limited number of window procedures, so the
664 * array won't grow too large, and this way we avoid the need to track allocations per window.
666 WNDPROC
WINPROC_AllocProc16( WNDPROC16 func
)
670 if (!func
) return NULL
;
672 /* check if the function is already a win proc */
673 if (!(proc
= handle16_to_proc( func
)))
675 EnterCriticalSection( &winproc_cs
);
677 /* then check if we already have a winproc for that function */
678 if (!(proc
= find_winproc16( func
)))
680 if (winproc_used
< MAX_WINPROCS
)
682 proc
= &winproc_array
[winproc_used
++];
684 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
685 proc_to_handle(proc
), func
, winproc_used
, MAX_WINPROCS
);
687 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func
);
689 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc
), func
);
691 LeaveCriticalSection( &winproc_cs
);
693 return proc_to_handle( proc
);
697 /**********************************************************************
700 * Allocate a window procedure for a window or class.
702 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
703 * lot of windows, it will usually only have a limited number of window procedures, so the
704 * array won't grow too large, and this way we avoid the need to track allocations per window.
706 WNDPROC
WINPROC_AllocProc( WNDPROC funcA
, WNDPROC funcW
)
710 if (!(proc
= alloc_winproc( funcA
, funcW
))) return NULL
;
711 return proc_to_handle( proc
);
715 /**********************************************************************
718 * Return the window procedure type, or the default value if not a winproc handle.
720 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
722 WINDOWPROC
*ptr
= handle_to_proc( proc
);
724 if (!ptr
) return def_val
;
725 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
726 return (ptr
->procW
!= NULL
);
730 /**********************************************************************
731 * WINPROC_TestLBForStr
733 * Return TRUE if the lparam is a string
735 static inline BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
737 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
738 if (msg
<= CB_MSGMAX
)
739 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
741 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
746 static UINT_PTR
convert_handle_16_to_32(HANDLE16 src
, unsigned int flags
)
749 UINT sz
= GlobalSize16(src
);
752 if (!(dst
= GlobalAlloc(flags
, sz
)))
754 ptr16
= GlobalLock16(src
);
755 ptr32
= GlobalLock(dst
);
756 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr32
, ptr16
, sz
);
760 return (UINT_PTR
)dst
;
763 static HANDLE16
convert_handle_32_to_16(UINT_PTR src
, unsigned int flags
)
766 UINT sz
= GlobalSize((HANDLE
)src
);
769 if (!(dst
= GlobalAlloc16(flags
, sz
)))
771 ptr32
= GlobalLock((HANDLE
)src
);
772 ptr16
= GlobalLock16(dst
);
773 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr16
, ptr32
, sz
);
774 GlobalUnlock((HANDLE
)src
);
781 /**********************************************************************
782 * WINPROC_CallProcAtoW
784 * Call a window procedure, translating args from Ansi to Unicode.
786 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
787 LPARAM lParam
, LRESULT
*result
, void *arg
)
791 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
792 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
799 WCHAR
*ptr
, buffer
[512];
800 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
801 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
802 MDICREATESTRUCTW mdi_cs
;
803 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
805 if (HIWORD(csA
->lpszClass
))
807 class_lenA
= strlen(csA
->lpszClass
) + 1;
808 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
810 if (HIWORD(csA
->lpszName
))
812 name_lenA
= strlen(csA
->lpszName
) + 1;
813 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
816 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
821 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
825 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
826 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
827 csA
->lpszName
, name_lenA
);
830 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
832 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
833 mdi_cs
.szTitle
= csW
.lpszName
;
834 mdi_cs
.szClass
= csW
.lpszClass
;
835 csW
.lpCreateParams
= &mdi_cs
;
838 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
839 free_buffer( buffer
, ptr
);
845 WCHAR
*ptr
, buffer
[512];
846 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
847 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
848 MDICREATESTRUCTW csW
;
850 memcpy( &csW
, csA
, sizeof(csW
) );
852 if (HIWORD(csA
->szTitle
))
854 title_lenA
= strlen(csA
->szTitle
) + 1;
855 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
857 if (HIWORD(csA
->szClass
))
859 class_lenA
= strlen(csA
->szClass
) + 1;
860 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
863 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
868 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
872 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
873 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
874 csA
->szClass
, class_lenA
);
876 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
877 free_buffer( buffer
, ptr
);
882 case WM_ASKCBFORMATNAME
:
884 WCHAR
*ptr
, buffer
[512];
885 LPSTR str
= (LPSTR
)lParam
;
886 DWORD len
= wParam
* sizeof(WCHAR
);
888 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
889 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
894 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, strlenW(ptr
) * sizeof(WCHAR
) );
898 free_buffer( buffer
, ptr
);
903 case LB_INSERTSTRING
:
905 case LB_FINDSTRINGEXACT
:
906 case LB_SELECTSTRING
:
908 case CB_INSERTSTRING
:
910 case CB_FINDSTRINGEXACT
:
911 case CB_SELECTSTRING
:
912 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
914 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
919 case WM_WININICHANGE
:
920 case WM_DEVMODECHANGE
:
925 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
928 WCHAR
*ptr
, buffer
[512];
929 LPCSTR strA
= (LPCSTR
)lParam
;
930 DWORD lenW
, lenA
= strlen(strA
) + 1;
932 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
933 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
935 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
936 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
937 free_buffer( buffer
, ptr
);
944 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
946 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
948 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
952 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
953 buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
957 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
962 WCHAR
*ptr
, buffer
[512];
963 WORD len
= *(WORD
*)lParam
;
965 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
966 *((WORD
*)ptr
) = len
; /* store the length */
967 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
971 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
972 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
975 free_buffer( buffer
, ptr
);
982 MSG newmsg
= *(MSG
*)lParam
;
983 switch(newmsg
.message
)
989 newmsg
.wParam
= map_wparam_char_AtoW( newmsg
.wParam
, 1 );
992 newmsg
.wParam
= map_wparam_char_AtoW( newmsg
.wParam
, 2 );
995 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
997 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1005 case WM_SYSDEADCHAR
:
1006 case EM_SETPASSWORDCHAR
:
1007 ret
= callback( hwnd
, msg
, map_wparam_char_AtoW(wParam
,1), lParam
, result
, arg
);
1011 ret
= callback( hwnd
, msg
, map_wparam_char_AtoW(wParam
,2), lParam
, result
, arg
);
1014 case WM_GETTEXTLENGTH
:
1015 case CB_GETLBTEXTLEN
:
1017 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1020 WCHAR
*ptr
, buffer
[512];
1022 DWORD len
= *result
+ 1;
1023 /* Determine respective GETTEXT message */
1024 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
1025 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
1026 /* wParam differs between the messages */
1027 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
1029 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
1031 if (callback
== call_window_proc
) /* FIXME: hack */
1032 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
1034 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
1035 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
1037 free_buffer( buffer
, ptr
);
1041 case WM_PAINTCLIPBOARD
:
1042 case WM_SIZECLIPBOARD
:
1043 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
1044 SPY_GetMsgName(msg
, hwnd
), msg
);
1048 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1055 /**********************************************************************
1056 * WINPROC_CallProcWtoA
1058 * Call a window procedure, translating args from Unicode to Ansi.
1060 static LRESULT
WINPROC_CallProcWtoA( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
1061 LPARAM lParam
, LRESULT
*result
, void *arg
)
1065 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1066 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1072 { /* csW->lpszName and csW->lpszClass are NOT supposed to be atoms
1075 char buffer
[1024], *cls
, *name
;
1076 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
1077 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
1078 MDICREATESTRUCTA mdi_cs
;
1079 DWORD name_lenA
, name_lenW
, class_lenA
, class_lenW
;
1081 class_lenW
= strlenW(csW
->lpszClass
) * sizeof(WCHAR
);
1082 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
1086 name_lenW
= strlenW(csW
->lpszName
) * sizeof(WCHAR
);
1087 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
1090 name_lenW
= name_lenA
= 0;
1092 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
+ 2 ))) break;
1094 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
1095 cls
[class_lenA
] = 0;
1096 csA
.lpszClass
= cls
;
1100 name
= cls
+ class_lenA
+ 1;
1101 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
1102 name
[name_lenA
] = 0;
1103 csA
.lpszName
= name
;
1106 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1108 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
1109 mdi_cs
.szTitle
= csA
.lpszName
;
1110 mdi_cs
.szClass
= csA
.lpszClass
;
1111 csA
.lpCreateParams
= &mdi_cs
;
1114 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1115 free_buffer( buffer
, cls
);
1120 case WM_ASKCBFORMATNAME
:
1122 char *ptr
, buffer
[512];
1123 DWORD len
= wParam
* 2;
1125 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
1126 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1131 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, strlen(ptr
)+1 );
1132 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
1134 ((LPWSTR
)lParam
)[*result
] = 0;
1136 free_buffer( buffer
, ptr
);
1141 case LB_INSERTSTRING
:
1143 case LB_FINDSTRINGEXACT
:
1144 case LB_SELECTSTRING
:
1146 case CB_INSERTSTRING
:
1148 case CB_FINDSTRINGEXACT
:
1149 case CB_SELECTSTRING
:
1150 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
1152 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1157 case WM_WININICHANGE
:
1158 case WM_DEVMODECHANGE
:
1163 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1166 char *ptr
, buffer
[512];
1167 LPCWSTR strW
= (LPCWSTR
)lParam
;
1168 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
1170 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
1171 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
1173 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
1174 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1175 free_buffer( buffer
, ptr
);
1182 char *ptr
, buffer
[1024];
1183 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1184 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1185 MDICREATESTRUCTA csA
;
1187 memcpy( &csA
, csW
, sizeof(csA
) );
1189 if (HIWORD(csW
->szTitle
))
1191 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
1192 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
1194 if (HIWORD(csW
->szClass
))
1196 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
1197 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
1200 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
1204 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
1209 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
1210 csA
.szClass
= ptr
+ title_lenA
;
1212 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1213 free_buffer( buffer
, ptr
);
1219 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
1221 char buffer
[512]; /* FIXME: fixed sized buffer */
1223 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
1227 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
1228 *result
= len
/ sizeof(WCHAR
) - 1;
1231 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1236 char *ptr
, buffer
[512];
1237 WORD len
= *(WORD
*)lParam
;
1239 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
1240 *((WORD
*)ptr
) = len
* 2; /* store the length */
1241 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1245 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
1246 *result
= reslen
/ sizeof(WCHAR
);
1247 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 0;
1249 free_buffer( buffer
, ptr
);
1256 MSG newmsg
= *(MSG
*)lParam
;
1257 switch(newmsg
.message
)
1262 case WM_SYSDEADCHAR
:
1263 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
1266 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
1269 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
1271 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1279 case WM_SYSDEADCHAR
:
1280 case EM_SETPASSWORDCHAR
:
1281 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
1285 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
1288 case WM_PAINTCLIPBOARD
:
1289 case WM_SIZECLIPBOARD
:
1290 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
1291 SPY_GetMsgName(msg
, hwnd
), msg
);
1295 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1303 /**********************************************************************
1304 * WINPROC_CallProc16To32A
1306 LRESULT
WINPROC_CallProc16To32A( winproc_callback_t callback
, HWND16 hwnd
, UINT16 msg
,
1307 WPARAM16 wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1310 HWND hwnd32
= WIN_Handle32( hwnd
);
1312 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1313 hwnd32
, SPY_GetMsgName(msg
, hwnd32
), wParam
, lParam
);
1320 CREATESTRUCT16
*cs16
= MapSL(lParam
);
1322 MDICREATESTRUCTA mdi_cs
;
1324 CREATESTRUCT16to32A( cs16
, &cs
);
1325 if (GetWindowLongW(hwnd32
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1327 MDICREATESTRUCT16
*mdi_cs16
= MapSL(cs16
->lpCreateParams
);
1328 MDICREATESTRUCT16to32A(mdi_cs16
, &mdi_cs
);
1329 cs
.lpCreateParams
= &mdi_cs
;
1331 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1332 CREATESTRUCT32Ato16( &cs
, cs16
);
1337 MDICREATESTRUCT16
*cs16
= MapSL(lParam
);
1338 MDICREATESTRUCTA cs
;
1340 MDICREATESTRUCT16to32A( cs16
, &cs
);
1341 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1342 MDICREATESTRUCT32Ato16( &cs
, cs16
);
1345 case WM_MDIACTIVATE
:
1347 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32( HIWORD(lParam
) ),
1348 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1349 else /* message sent to MDI client */
1350 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1352 case WM_MDIGETACTIVE
:
1354 BOOL maximized
= FALSE
;
1355 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&maximized
, result
, arg
);
1356 *result
= MAKELRESULT( LOWORD(*result
), maximized
);
1360 ret
= callback( hwnd32
, wParam
? WM_MDIREFRESHMENU
: WM_MDISETMENU
,
1361 (WPARAM
)HMENU_32(LOWORD(lParam
)), (LPARAM
)HMENU_32(HIWORD(lParam
)),
1364 case WM_GETMINMAXINFO
:
1366 MINMAXINFO16
*mmi16
= MapSL(lParam
);
1369 MINMAXINFO16to32( mmi16
, &mmi
);
1370 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mmi
, result
, arg
);
1371 MINMAXINFO32to16( &mmi
, mmi16
);
1374 case WM_WINDOWPOSCHANGING
:
1375 case WM_WINDOWPOSCHANGED
:
1377 WINDOWPOS16
*winpos16
= MapSL(lParam
);
1380 WINDOWPOS16to32( winpos16
, &winpos
);
1381 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&winpos
, result
, arg
);
1382 WINDOWPOS32to16( &winpos
, winpos16
);
1387 NCCALCSIZE_PARAMS16
*nc16
= MapSL(lParam
);
1388 NCCALCSIZE_PARAMS nc
;
1391 RECT16to32( &nc16
->rgrc
[0], &nc
.rgrc
[0] );
1394 RECT16to32( &nc16
->rgrc
[1], &nc
.rgrc
[1] );
1395 RECT16to32( &nc16
->rgrc
[2], &nc
.rgrc
[2] );
1396 WINDOWPOS16to32( MapSL(nc16
->lppos
), &winpos
);
1399 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&nc
, result
, arg
);
1400 RECT32to16( &nc
.rgrc
[0], &nc16
->rgrc
[0] );
1403 RECT32to16( &nc
.rgrc
[1], &nc16
->rgrc
[1] );
1404 RECT32to16( &nc
.rgrc
[2], &nc16
->rgrc
[2] );
1405 WINDOWPOS32to16( &winpos
, MapSL(nc16
->lppos
) );
1409 case WM_COMPAREITEM
:
1411 COMPAREITEMSTRUCT16
* cis16
= MapSL(lParam
);
1412 COMPAREITEMSTRUCT cis
;
1413 cis
.CtlType
= cis16
->CtlType
;
1414 cis
.CtlID
= cis16
->CtlID
;
1415 cis
.hwndItem
= WIN_Handle32( cis16
->hwndItem
);
1416 cis
.itemID1
= cis16
->itemID1
;
1417 cis
.itemData1
= cis16
->itemData1
;
1418 cis
.itemID2
= cis16
->itemID2
;
1419 cis
.itemData2
= cis16
->itemData2
;
1420 cis
.dwLocaleId
= 0; /* FIXME */
1421 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cis
, result
, arg
);
1426 DELETEITEMSTRUCT16
* dis16
= MapSL(lParam
);
1427 DELETEITEMSTRUCT dis
;
1428 dis
.CtlType
= dis16
->CtlType
;
1429 dis
.CtlID
= dis16
->CtlID
;
1430 dis
.hwndItem
= WIN_Handle32( dis16
->hwndItem
);
1431 dis
.itemData
= dis16
->itemData
;
1432 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1435 case WM_MEASUREITEM
:
1437 MEASUREITEMSTRUCT16
* mis16
= MapSL(lParam
);
1438 MEASUREITEMSTRUCT mis
;
1439 mis
.CtlType
= mis16
->CtlType
;
1440 mis
.CtlID
= mis16
->CtlID
;
1441 mis
.itemID
= mis16
->itemID
;
1442 mis
.itemWidth
= mis16
->itemWidth
;
1443 mis
.itemHeight
= mis16
->itemHeight
;
1444 mis
.itemData
= mis16
->itemData
;
1445 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mis
, result
, arg
);
1446 mis16
->itemWidth
= (UINT16
)mis
.itemWidth
;
1447 mis16
->itemHeight
= (UINT16
)mis
.itemHeight
;
1452 DRAWITEMSTRUCT16
* dis16
= MapSL(lParam
);
1454 dis
.CtlType
= dis16
->CtlType
;
1455 dis
.CtlID
= dis16
->CtlID
;
1456 dis
.itemID
= dis16
->itemID
;
1457 dis
.itemAction
= dis16
->itemAction
;
1458 dis
.itemState
= dis16
->itemState
;
1459 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND
)HMENU_32(dis16
->hwndItem
)
1460 : WIN_Handle32( dis16
->hwndItem
);
1461 dis
.hDC
= HDC_32(dis16
->hDC
);
1462 dis
.itemData
= dis16
->itemData
;
1463 dis
.rcItem
.left
= dis16
->rcItem
.left
;
1464 dis
.rcItem
.top
= dis16
->rcItem
.top
;
1465 dis
.rcItem
.right
= dis16
->rcItem
.right
;
1466 dis
.rcItem
.bottom
= dis16
->rcItem
.bottom
;
1467 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1472 COPYDATASTRUCT16
*cds16
= MapSL(lParam
);
1474 cds
.dwData
= cds16
->dwData
;
1475 cds
.cbData
= cds16
->cbData
;
1476 cds
.lpData
= MapSL(cds16
->lpData
);
1477 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cds
, result
, arg
);
1483 MSG16
*msg16
= MapSL(lParam
);
1485 msg32
.hwnd
= WIN_Handle32( msg16
->hwnd
);
1486 msg32
.message
= msg16
->message
;
1487 msg32
.wParam
= msg16
->wParam
;
1488 msg32
.lParam
= msg16
->lParam
;
1489 msg32
.time
= msg16
->time
;
1490 msg32
.pt
.x
= msg16
->pt
.x
;
1491 msg32
.pt
.y
= msg16
->pt
.y
;
1492 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&msg32
, result
, arg
);
1495 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1500 next
.hmenuIn
= (HMENU
)lParam
;
1503 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&next
, result
, arg
);
1504 *result
= MAKELONG( HMENU_16(next
.hmenuNext
), HWND_16(next
.hwndNext
) );
1511 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1512 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1516 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1517 (LPARAM
)WIN_Handle32( HIWORD(lParam
) ), result
, arg
);
1520 if (HIWORD(lParam
) <= CTLCOLOR_STATIC
)
1521 ret
= callback( hwnd32
, WM_CTLCOLORMSGBOX
+ HIWORD(lParam
),
1522 (WPARAM
)HDC_32(wParam
), (LPARAM
)WIN_Handle32( LOWORD(lParam
) ),
1527 case WM_WININICHANGE
:
1528 case WM_DEVMODECHANGE
:
1529 case WM_ASKCBFORMATNAME
:
1531 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)MapSL(lParam
), result
, arg
);
1534 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1535 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1538 if((LOWORD(lParam
) & MF_POPUP
) && (LOWORD(lParam
) != 0xFFFF))
1540 HMENU hmenu
= HMENU_32(HIWORD(lParam
));
1541 UINT pos
= MENU_FindSubMenu( &hmenu
, HMENU_32(wParam
) );
1542 if (pos
== 0xffff) pos
= 0; /* NO_SELECTED_ITEM */
1545 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1546 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1548 case WM_PARENTNOTIFY
:
1549 if ((wParam
== WM_CREATE
) || (wParam
== WM_DESTROY
))
1550 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1551 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1553 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1555 case WM_ACTIVATEAPP
:
1556 /* We need this when SetActiveWindow sends a Sendmessage16() to
1557 * a 32bit window. Might be superflous with 32bit interprocess
1558 * message queues. */
1559 if (lParam
) lParam
= HTASK_32(lParam
);
1560 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1562 case WM_DDE_INITIATE
:
1563 case WM_DDE_TERMINATE
:
1564 case WM_DDE_UNADVISE
:
1565 case WM_DDE_REQUEST
:
1566 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1572 HANDLE16 lo16
= LOWORD(lParam
);
1574 if (lo16
&& !(lo32
= convert_handle_16_to_32(lo16
, GMEM_DDESHARE
))) break;
1575 lParam
= PackDDElParam( msg
, lo32
, HIWORD(lParam
) );
1576 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1578 break; /* FIXME don't know how to free allocated memory (handle) !! */
1581 UINT_PTR lo
= LOWORD(lParam
);
1582 UINT_PTR hi
= HIWORD(lParam
);
1586 if (GlobalGetAtomNameA(hi
, buf
, 2) > 0) flag
|= 1;
1587 if (GlobalSize16(hi
) != 0) flag
|= 2;
1593 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1598 break; /* atom, nothing to do */
1600 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi
);
1603 hi
= convert_handle_16_to_32(hi
, GMEM_DDESHARE
);
1606 lParam
= PackDDElParam( WM_DDE_ACK
, lo
, hi
);
1607 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1609 break; /* FIXME don't know how to free allocated memory (handle) !! */
1610 case WM_DDE_EXECUTE
:
1611 lParam
= convert_handle_16_to_32( lParam
, GMEM_DDESHARE
);
1612 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1613 break; /* FIXME don't know how to free allocated memory (handle) !! */
1614 case WM_PAINTCLIPBOARD
:
1615 case WM_SIZECLIPBOARD
:
1616 FIXME_(msg
)( "message %04x needs translation\n", msg
);
1619 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1626 /**********************************************************************
1627 * __wine_call_wndproc (USER.1010)
1629 LRESULT WINAPI
__wine_call_wndproc( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
1635 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1637 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1642 /**********************************************************************
1643 * WINPROC_CallProc32ATo16
1645 * Call a 16-bit window procedure, translating the 32-bit args.
1647 LRESULT
WINPROC_CallProc32ATo16( winproc_callback16_t callback
, HWND hwnd
, UINT msg
,
1648 WPARAM wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1652 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1653 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1660 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)lParam
;
1662 MDICREATESTRUCT16 mdi_cs16
;
1663 BOOL mdi_child
= (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
);
1665 CREATESTRUCT32Ato16( cs32
, &cs
);
1666 cs
.lpszName
= MapLS( cs32
->lpszName
);
1667 cs
.lpszClass
= MapLS( cs32
->lpszClass
);
1671 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs32
->lpCreateParams
;
1672 MDICREATESTRUCT32Ato16( mdi_cs
, &mdi_cs16
);
1673 mdi_cs16
.szTitle
= MapLS( mdi_cs
->szTitle
);
1674 mdi_cs16
.szClass
= MapLS( mdi_cs
->szClass
);
1675 cs
.lpCreateParams
= MapLS( &mdi_cs16
);
1677 lParam
= MapLS( &cs
);
1678 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1680 UnMapLS( cs
.lpszName
);
1681 UnMapLS( cs
.lpszClass
);
1684 UnMapLS( cs
.lpCreateParams
);
1685 UnMapLS( mdi_cs16
.szTitle
);
1686 UnMapLS( mdi_cs16
.szClass
);
1692 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)lParam
;
1693 MDICREATESTRUCT16 cs
;
1695 MDICREATESTRUCT32Ato16( cs32
, &cs
);
1696 cs
.szTitle
= MapLS( cs32
->szTitle
);
1697 cs
.szClass
= MapLS( cs32
->szClass
);
1698 lParam
= MapLS( &cs
);
1699 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1701 UnMapLS( cs
.szTitle
);
1702 UnMapLS( cs
.szClass
);
1705 case WM_MDIACTIVATE
:
1706 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1707 ret
= callback( HWND_16(hwnd
), msg
, ((HWND
)lParam
== hwnd
),
1708 MAKELPARAM( LOWORD(lParam
), LOWORD(wParam
) ), result
, arg
);
1710 ret
= callback( HWND_16(hwnd
), msg
, HWND_16( (HWND
)wParam
), 0, result
, arg
);
1712 case WM_MDIGETACTIVE
:
1713 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1714 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(*result
);
1715 *result
= (LRESULT
)WIN_Handle32( LOWORD(*result
) );
1718 ret
= callback( HWND_16(hwnd
), msg
, (lParam
== 0),
1719 MAKELPARAM( LOWORD(wParam
), LOWORD(lParam
) ), result
, arg
);
1721 case WM_GETMINMAXINFO
:
1723 MINMAXINFO
*mmi32
= (MINMAXINFO
*)lParam
;
1726 MINMAXINFO32to16( mmi32
, &mmi
);
1727 lParam
= MapLS( &mmi
);
1728 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1730 MINMAXINFO16to32( &mmi
, mmi32
);
1735 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)lParam
;
1736 NCCALCSIZE_PARAMS16 nc
;
1739 RECT32to16( &nc32
->rgrc
[0], &nc
.rgrc
[0] );
1742 RECT32to16( &nc32
->rgrc
[1], &nc
.rgrc
[1] );
1743 RECT32to16( &nc32
->rgrc
[2], &nc
.rgrc
[2] );
1744 WINDOWPOS32to16( nc32
->lppos
, &winpos
);
1745 nc
.lppos
= MapLS( &winpos
);
1747 lParam
= MapLS( &nc
);
1748 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1750 RECT16to32( &nc
.rgrc
[0], &nc32
->rgrc
[0] );
1753 RECT16to32( &nc
.rgrc
[1], &nc32
->rgrc
[1] );
1754 RECT16to32( &nc
.rgrc
[2], &nc32
->rgrc
[2] );
1755 WINDOWPOS16to32( &winpos
, nc32
->lppos
);
1756 UnMapLS( nc
.lppos
);
1760 case WM_WINDOWPOSCHANGING
:
1761 case WM_WINDOWPOSCHANGED
:
1763 WINDOWPOS
*winpos32
= (WINDOWPOS
*)lParam
;
1766 WINDOWPOS32to16( winpos32
, &winpos
);
1767 lParam
= MapLS( &winpos
);
1768 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1770 WINDOWPOS16to32( &winpos
, winpos32
);
1773 case WM_COMPAREITEM
:
1775 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)lParam
;
1776 COMPAREITEMSTRUCT16 cis
;
1777 cis
.CtlType
= cis32
->CtlType
;
1778 cis
.CtlID
= cis32
->CtlID
;
1779 cis
.hwndItem
= HWND_16( cis32
->hwndItem
);
1780 cis
.itemID1
= cis32
->itemID1
;
1781 cis
.itemData1
= cis32
->itemData1
;
1782 cis
.itemID2
= cis32
->itemID2
;
1783 cis
.itemData2
= cis32
->itemData2
;
1784 lParam
= MapLS( &cis
);
1785 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1791 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)lParam
;
1792 DELETEITEMSTRUCT16 dis
;
1793 dis
.CtlType
= dis32
->CtlType
;
1794 dis
.CtlID
= dis32
->CtlID
;
1795 dis
.itemID
= dis32
->itemID
;
1796 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND16
)LOWORD(dis32
->hwndItem
)
1797 : HWND_16( dis32
->hwndItem
);
1798 dis
.itemData
= dis32
->itemData
;
1799 lParam
= MapLS( &dis
);
1800 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1806 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)lParam
;
1807 DRAWITEMSTRUCT16 dis
;
1808 dis
.CtlType
= dis32
->CtlType
;
1809 dis
.CtlID
= dis32
->CtlID
;
1810 dis
.itemID
= dis32
->itemID
;
1811 dis
.itemAction
= dis32
->itemAction
;
1812 dis
.itemState
= dis32
->itemState
;
1813 dis
.hwndItem
= HWND_16( dis32
->hwndItem
);
1814 dis
.hDC
= HDC_16(dis32
->hDC
);
1815 dis
.itemData
= dis32
->itemData
;
1816 dis
.rcItem
.left
= dis32
->rcItem
.left
;
1817 dis
.rcItem
.top
= dis32
->rcItem
.top
;
1818 dis
.rcItem
.right
= dis32
->rcItem
.right
;
1819 dis
.rcItem
.bottom
= dis32
->rcItem
.bottom
;
1820 lParam
= MapLS( &dis
);
1821 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1825 case WM_MEASUREITEM
:
1827 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)lParam
;
1828 MEASUREITEMSTRUCT16 mis
;
1829 mis
.CtlType
= mis32
->CtlType
;
1830 mis
.CtlID
= mis32
->CtlID
;
1831 mis
.itemID
= mis32
->itemID
;
1832 mis
.itemWidth
= mis32
->itemWidth
;
1833 mis
.itemHeight
= mis32
->itemHeight
;
1834 mis
.itemData
= mis32
->itemData
;
1835 lParam
= MapLS( &mis
);
1836 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1838 mis32
->itemWidth
= mis
.itemWidth
;
1839 mis32
->itemHeight
= mis
.itemHeight
;
1844 COPYDATASTRUCT
*cds32
= (COPYDATASTRUCT
*)lParam
;
1845 COPYDATASTRUCT16 cds
;
1847 cds
.dwData
= cds32
->dwData
;
1848 cds
.cbData
= cds32
->cbData
;
1849 cds
.lpData
= MapLS( cds32
->lpData
);
1850 lParam
= MapLS( &cds
);
1851 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1853 UnMapLS( cds
.lpData
);
1859 MSG
*msg32
= (MSG
*)lParam
;
1862 msg16
.hwnd
= HWND_16( msg32
->hwnd
);
1863 msg16
.message
= msg32
->message
;
1864 msg16
.wParam
= msg32
->wParam
;
1865 msg16
.lParam
= msg32
->lParam
;
1866 msg16
.time
= msg32
->time
;
1867 msg16
.pt
.x
= msg32
->pt
.x
;
1868 msg16
.pt
.y
= msg32
->pt
.y
;
1869 lParam
= MapLS( &msg16
);
1870 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1874 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1878 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
1879 ret
= callback( HWND_16(hwnd
), msg
, wParam
, (LPARAM
)next
->hmenuIn
, result
, arg
);
1880 next
->hmenuNext
= HMENU_32( LOWORD(*result
) );
1881 next
->hwndNext
= WIN_Handle32( HIWORD(*result
) );
1886 case WM_ASKCBFORMATNAME
:
1887 wParam
= min( wParam
, 0xff80 ); /* Must be < 64K */
1891 case WM_WININICHANGE
:
1892 case WM_DEVMODECHANGE
:
1893 lParam
= MapLS( (void *)lParam
);
1894 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1901 ret
= callback( HWND_16(hwnd
), msg
, wParam
, MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ),
1906 ret
= callback( HWND_16(hwnd
), msg
, wParam
, MAKELPARAM( HIWORD(wParam
), (HWND16
)lParam
),
1909 case WM_CTLCOLORMSGBOX
:
1910 case WM_CTLCOLOREDIT
:
1911 case WM_CTLCOLORLISTBOX
:
1912 case WM_CTLCOLORBTN
:
1913 case WM_CTLCOLORDLG
:
1914 case WM_CTLCOLORSCROLLBAR
:
1915 case WM_CTLCOLORSTATIC
:
1916 ret
= callback( HWND_16(hwnd
), WM_CTLCOLOR
, wParam
,
1917 MAKELPARAM( (HWND16
)lParam
, msg
- WM_CTLCOLORMSGBOX
), result
, arg
);
1920 if(HIWORD(wParam
) & MF_POPUP
)
1923 if ((HIWORD(wParam
) != 0xffff) || lParam
)
1925 if ((hmenu
= GetSubMenu( (HMENU
)lParam
, LOWORD(wParam
) )))
1927 ret
= callback( HWND_16(hwnd
), msg
, HMENU_16(hmenu
),
1928 MAKELPARAM( HIWORD(wParam
), (HMENU16
)lParam
), result
, arg
);
1935 ret
= callback( HWND_16(hwnd
), msg
, wParam
,
1936 MAKELPARAM( HIWORD(wParam
), (HMENU16
)lParam
), result
, arg
);
1938 case WM_PARENTNOTIFY
:
1939 if ((LOWORD(wParam
) == WM_CREATE
) || (LOWORD(wParam
) == WM_DESTROY
))
1940 ret
= callback( HWND_16(hwnd
), msg
, wParam
,
1941 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ), result
, arg
);
1943 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1945 case WM_ACTIVATEAPP
:
1946 ret
= callback( HWND_16(hwnd
), msg
, wParam
, HTASK_16( (HANDLE
)lParam
), result
, arg
);
1949 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
))
1950 ret
= callback( HWND_16(hwnd
), WM_PAINTICON
, 1, lParam
, result
, arg
);
1952 ret
= callback( HWND_16(hwnd
), WM_PAINT
, wParam
, lParam
, result
, arg
);
1955 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
)) msg
= WM_ICONERASEBKGND
;
1956 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1958 case WM_DDE_INITIATE
:
1959 case WM_DDE_TERMINATE
:
1960 case WM_DDE_UNADVISE
:
1961 case WM_DDE_REQUEST
:
1962 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
), lParam
, result
, arg
);
1971 UnpackDDElParam( msg
, lParam
, &lo32
, &hi
);
1972 if (lo32
&& !(lo16
= convert_handle_32_to_16(lo32
, GMEM_DDESHARE
))) break;
1973 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
),
1974 MAKELPARAM(lo16
, hi
), result
, arg
);
1976 break; /* FIXME don't know how to free allocated memory (handle) !! */
1983 UnpackDDElParam( msg
, lParam
, &lo
, &hi
);
1985 if (GlobalGetAtomNameA((ATOM
)hi
, buf
, sizeof(buf
)) > 0) flag
|= 1;
1986 if (GlobalSize((HANDLE
)hi
) != 0) flag
|= 2;
1992 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1997 break; /* atom, nothing to do */
1999 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi
);
2002 hi
= convert_handle_32_to_16(hi
, GMEM_DDESHARE
);
2005 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
),
2006 MAKELPARAM(lo
, hi
), result
, arg
);
2008 break; /* FIXME don't know how to free allocated memory (handle) !! */
2009 case WM_DDE_EXECUTE
:
2010 lParam
= convert_handle_32_to_16(lParam
, GMEM_DDESHARE
);
2011 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2012 break; /* FIXME don't know how to free allocated memory (handle) !! */
2014 ret
= callback( HWND_16(hwnd
), SBM_SETRANGE16
, 0, MAKELPARAM(wParam
, lParam
), result
, arg
);
2017 ret
= callback( HWND_16(hwnd
), SBM_GETRANGE16
, wParam
, lParam
, result
, arg
);
2018 *(LPINT
)wParam
= LOWORD(*result
);
2019 *(LPINT
)lParam
= HIWORD(*result
);
2026 ret
= callback( HWND_16(hwnd
), msg
+ BM_GETCHECK16
- BM_GETCHECK
, wParam
, lParam
, result
, arg
);
2034 case EM_SCROLLCARET
:
2037 case EM_GETLINECOUNT
:
2049 case EM_LINEFROMCHAR
:
2050 case EM_SETTABSTOPS
:
2051 case EM_SETPASSWORDCHAR
:
2052 case EM_EMPTYUNDOBUFFER
:
2053 case EM_GETFIRSTVISIBLELINE
:
2054 case EM_SETREADONLY
:
2055 case EM_SETWORDBREAKPROC
:
2056 case EM_GETWORDBREAKPROC
:
2057 case EM_GETPASSWORDCHAR
:
2058 ret
= callback( HWND_16(hwnd
), msg
+ EM_GETSEL16
- EM_GETSEL
, wParam
, lParam
, result
, arg
);
2061 ret
= callback( HWND_16(hwnd
), EM_SETSEL16
, 0, MAKELPARAM( wParam
, lParam
), result
, arg
);
2065 case LB_DELETESTRING
:
2066 case LB_GETANCHORINDEX
:
2067 case LB_GETCARETINDEX
:
2070 case LB_GETHORIZONTALEXTENT
:
2071 case LB_GETITEMDATA
:
2072 case LB_GETITEMHEIGHT
:
2074 case LB_GETSELCOUNT
:
2076 case LB_GETTOPINDEX
:
2077 case LB_RESETCONTENT
:
2078 case LB_SELITEMRANGE
:
2079 case LB_SELITEMRANGEEX
:
2080 case LB_SETANCHORINDEX
:
2081 case LB_SETCARETINDEX
:
2082 case LB_SETCOLUMNWIDTH
:
2084 case LB_SETHORIZONTALEXTENT
:
2085 case LB_SETITEMDATA
:
2086 case LB_SETITEMHEIGHT
:
2088 case LB_SETTOPINDEX
:
2089 ret
= callback( HWND_16(hwnd
), msg
+ LB_ADDSTRING16
- LB_ADDSTRING
, wParam
, lParam
, result
, arg
);
2093 case LB_FINDSTRINGEXACT
:
2094 case LB_INSERTSTRING
:
2095 case LB_SELECTSTRING
:
2099 lParam
= MapLS( (LPSTR
)lParam
);
2100 ret
= callback( HWND_16(hwnd
), msg
+ LB_ADDSTRING16
- LB_ADDSTRING
, wParam
, lParam
, result
, arg
);
2103 case LB_GETSELITEMS
:
2105 INT
*items32
= (INT
*)lParam
;
2106 INT16
*items
, buffer
[512];
2109 wParam
= min( wParam
, 0x7f80 ); /* Must be < 64K */
2110 if (!(items
= get_buffer( buffer
, sizeof(buffer
), wParam
* sizeof(INT16
) ))) break;
2111 lParam
= MapLS( items
);
2112 ret
= callback( HWND_16(hwnd
), LB_GETSELITEMS16
, wParam
, lParam
, result
, arg
);
2114 for (i
= 0; i
< wParam
; i
++) items32
[i
] = items
[i
];
2115 free_buffer( buffer
, items
);
2118 case LB_SETTABSTOPS
:
2121 INT
*stops32
= (INT
*)lParam
;
2122 INT16
*stops
, buffer
[512];
2125 wParam
= min( wParam
, 0x7f80 ); /* Must be < 64K */
2126 if (!(stops
= get_buffer( buffer
, sizeof(buffer
), wParam
* sizeof(INT16
) ))) break;
2127 for (i
= 0; i
< wParam
; i
++) stops
[i
] = stops32
[i
];
2128 lParam
= MapLS( stops
);
2129 ret
= callback( HWND_16(hwnd
), LB_SETTABSTOPS16
, wParam
, lParam
, result
, arg
);
2131 free_buffer( buffer
, stops
);
2133 else ret
= callback( HWND_16(hwnd
), LB_SETTABSTOPS16
, wParam
, lParam
, result
, arg
);
2135 case CB_DELETESTRING
:
2137 case CB_GETLBTEXTLEN
:
2139 case CB_RESETCONTENT
:
2143 case CB_SHOWDROPDOWN
:
2144 case CB_SETITEMDATA
:
2145 case CB_SETITEMHEIGHT
:
2146 case CB_GETITEMHEIGHT
:
2147 case CB_SETEXTENDEDUI
:
2148 case CB_GETEXTENDEDUI
:
2149 case CB_GETDROPPEDSTATE
:
2150 ret
= callback( HWND_16(hwnd
), msg
+ CB_GETEDITSEL16
- CB_GETEDITSEL
, wParam
, lParam
, result
, arg
);
2153 ret
= callback( HWND_16(hwnd
), CB_GETEDITSEL16
, wParam
, lParam
, result
, arg
);
2154 if (wParam
) *((PUINT
)(wParam
)) = LOWORD(*result
);
2155 if (lParam
) *((PUINT
)(lParam
)) = HIWORD(*result
); /* FIXME: substract 1? */
2159 case CB_FINDSTRINGEXACT
:
2160 case CB_INSERTSTRING
:
2161 case CB_SELECTSTRING
:
2164 lParam
= MapLS( (LPSTR
)lParam
);
2165 ret
= callback( HWND_16(hwnd
), msg
+ CB_GETEDITSEL16
- CB_GETEDITSEL
, wParam
, lParam
, result
, arg
);
2168 case LB_GETITEMRECT
:
2169 case CB_GETDROPPEDCONTROLRECT
:
2171 RECT
*r32
= (RECT
*)lParam
;
2173 lParam
= MapLS( &rect
);
2174 ret
= callback( HWND_16(hwnd
),
2175 (msg
== LB_GETITEMRECT
) ? LB_GETITEMRECT16
: CB_GETDROPPEDCONTROLRECT16
,
2176 wParam
, lParam
, result
, arg
);
2178 RECT16to32( &rect
, r32
);
2181 case WM_PAINTCLIPBOARD
:
2182 case WM_SIZECLIPBOARD
:
2183 FIXME_(msg
)( "message %04x needs translation\n", msg
);
2185 /* the following messages should not be sent to 16-bit apps */
2188 case WM_CAPTURECHANGED
:
2189 case WM_STYLECHANGING
:
2190 case WM_STYLECHANGED
:
2193 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2200 /**********************************************************************
2201 * CallWindowProc (USER.122)
2203 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2204 WPARAM16 wParam
, LPARAM lParam
)
2209 if (!func
) return 0;
2211 if (!(proc
= handle16_to_proc( func
)))
2212 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2213 else if (proc
->procA
)
2214 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2215 else if (proc
->procW
)
2216 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2218 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2224 /**********************************************************************
2225 * CallWindowProcA (USER32.@)
2227 * The CallWindowProc() function invokes the windows procedure _func_,
2228 * with _hwnd_ as the target window, the message specified by _msg_, and
2229 * the message parameters _wParam_ and _lParam_.
2231 * Some kinds of argument conversion may be done, I'm not sure what.
2233 * CallWindowProc() may be used for windows subclassing. Use
2234 * SetWindowLong() to set a new windows procedure for windows of the
2235 * subclass, and handle subclassed messages in the new windows
2236 * procedure. The new windows procedure may then use CallWindowProc()
2237 * with _func_ set to the parent class's windows procedure to dispatch
2238 * the message to the superclass.
2242 * The return value is message dependent.
2248 LRESULT WINAPI
CallWindowProcA(
2249 WNDPROC func
, /* [in] window procedure */
2250 HWND hwnd
, /* [in] target window */
2251 UINT msg
, /* [in] message */
2252 WPARAM wParam
, /* [in] message dependent parameter */
2253 LPARAM lParam
/* [in] message dependent parameter */
2258 if (!func
) return 0;
2260 if (!(proc
= handle_to_proc( func
)) && !(proc
= find_builtin_proc( func
)))
2261 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2262 else if (proc
->procA
)
2263 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2264 else if (proc
->procW
)
2265 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2267 WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2272 /**********************************************************************
2273 * CallWindowProcW (USER32.@)
2275 * See CallWindowProcA.
2277 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
2278 WPARAM wParam
, LPARAM lParam
)
2283 if (!func
) return 0;
2285 if (!(proc
= handle_to_proc( func
)) && !(proc
= find_builtin_proc( func
)))
2286 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2287 else if (proc
->procW
)
2288 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2289 else if (proc
->procA
)
2290 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2292 WINPROC_CallProcWtoA( call_window_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2297 /**********************************************************************
2298 * WINPROC_CallDlgProc16
2300 INT_PTR
WINPROC_CallDlgProc16( DLGPROC16 func
, HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
2306 if (!func
) return 0;
2308 if (!(proc
= handle16_to_proc( (WNDPROC16
)func
)))
2310 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2312 else if (proc
->procA
)
2314 ret
= WINPROC_CallProc16To32A( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
,
2315 &result
, proc
->procA
);
2316 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2318 else if (proc
->procW
)
2320 ret
= WINPROC_CallProc16To32A( call_dialog_proc_AtoW
, hwnd
, msg
, wParam
, lParam
,
2321 &result
, proc
->procW
);
2322 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2326 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2332 /**********************************************************************
2333 * WINPROC_CallDlgProcA
2335 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2341 if (!func
) return 0;
2343 if (!(proc
= handle_to_proc( func
)) && !(proc
= find_builtin_proc( func
)))
2344 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2345 else if (proc
->procA
)
2346 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2347 else if (proc
->procW
)
2349 ret
= WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2350 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2354 ret
= WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2355 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2361 /**********************************************************************
2362 * WINPROC_CallDlgProcW
2364 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2370 if (!func
) return 0;
2372 if (!(proc
= handle_to_proc( func
)) && !(proc
= find_builtin_proc( func
)))
2373 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2374 else if (proc
->procW
)
2375 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2376 else if (proc
->procA
)
2378 ret
= WINPROC_CallProcWtoA( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2379 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2383 ret
= WINPROC_CallProcWtoA( call_dialog_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2384 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);