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 (~0UL >> 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
,
294 "movl 8(%ebp),%eax\n\t"
296 "leal -12(%ebp),%esp\n\t"
303 static inline LRESULT
WINPROC_wrapper( WNDPROC proc
, HWND hwnd
, UINT msg
,
304 WPARAM wParam
, LPARAM lParam
)
306 return proc( hwnd
, msg
, wParam
, lParam
);
308 #endif /* __i386__ */
310 static void RECT16to32( const RECT16
*from
, RECT
*to
)
312 to
->left
= from
->left
;
314 to
->right
= from
->right
;
315 to
->bottom
= from
->bottom
;
318 static void RECT32to16( const RECT
*from
, RECT16
*to
)
320 to
->left
= from
->left
;
322 to
->right
= from
->right
;
323 to
->bottom
= from
->bottom
;
326 static void MINMAXINFO32to16( const MINMAXINFO
*from
, MINMAXINFO16
*to
)
328 to
->ptReserved
.x
= from
->ptReserved
.x
;
329 to
->ptReserved
.y
= from
->ptReserved
.y
;
330 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
331 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
332 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
333 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
334 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
335 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
336 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
337 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
340 static void MINMAXINFO16to32( const MINMAXINFO16
*from
, MINMAXINFO
*to
)
342 to
->ptReserved
.x
= from
->ptReserved
.x
;
343 to
->ptReserved
.y
= from
->ptReserved
.y
;
344 to
->ptMaxSize
.x
= from
->ptMaxSize
.x
;
345 to
->ptMaxSize
.y
= from
->ptMaxSize
.y
;
346 to
->ptMaxPosition
.x
= from
->ptMaxPosition
.x
;
347 to
->ptMaxPosition
.y
= from
->ptMaxPosition
.y
;
348 to
->ptMinTrackSize
.x
= from
->ptMinTrackSize
.x
;
349 to
->ptMinTrackSize
.y
= from
->ptMinTrackSize
.y
;
350 to
->ptMaxTrackSize
.x
= from
->ptMaxTrackSize
.x
;
351 to
->ptMaxTrackSize
.y
= from
->ptMaxTrackSize
.y
;
354 static void WINDOWPOS32to16( const WINDOWPOS
* from
, WINDOWPOS16
* to
)
356 to
->hwnd
= HWND_16(from
->hwnd
);
357 to
->hwndInsertAfter
= HWND_16(from
->hwndInsertAfter
);
362 to
->flags
= from
->flags
;
365 static void WINDOWPOS16to32( const WINDOWPOS16
* from
, WINDOWPOS
* to
)
367 to
->hwnd
= WIN_Handle32(from
->hwnd
);
368 to
->hwndInsertAfter
= (from
->hwndInsertAfter
== (HWND16
)-1) ?
369 HWND_TOPMOST
: WIN_Handle32(from
->hwndInsertAfter
);
374 to
->flags
= from
->flags
;
377 /* The strings are not copied */
378 static void CREATESTRUCT32Ato16( const CREATESTRUCTA
* from
, CREATESTRUCT16
* to
)
380 to
->lpCreateParams
= (SEGPTR
)from
->lpCreateParams
;
381 to
->hInstance
= HINSTANCE_16(from
->hInstance
);
382 to
->hMenu
= HMENU_16(from
->hMenu
);
383 to
->hwndParent
= HWND_16(from
->hwndParent
);
388 to
->style
= from
->style
;
389 to
->dwExStyle
= from
->dwExStyle
;
392 static void CREATESTRUCT16to32A( const CREATESTRUCT16
* from
, CREATESTRUCTA
*to
)
395 to
->lpCreateParams
= (LPVOID
)from
->lpCreateParams
;
396 to
->hInstance
= HINSTANCE_32(from
->hInstance
);
397 to
->hMenu
= HMENU_32(from
->hMenu
);
398 to
->hwndParent
= WIN_Handle32(from
->hwndParent
);
403 to
->style
= from
->style
;
404 to
->dwExStyle
= from
->dwExStyle
;
405 to
->lpszName
= MapSL(from
->lpszName
);
406 to
->lpszClass
= MapSL(from
->lpszClass
);
409 /* The strings are not copied */
410 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA
* from
, MDICREATESTRUCT16
* to
)
412 to
->hOwner
= HINSTANCE_16(from
->hOwner
);
417 to
->style
= from
->style
;
418 to
->lParam
= from
->lParam
;
421 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16
* from
, MDICREATESTRUCTA
*to
)
423 to
->hOwner
= HINSTANCE_32(from
->hOwner
);
428 to
->style
= from
->style
;
429 to
->lParam
= from
->lParam
;
430 to
->szTitle
= MapSL(from
->szTitle
);
431 to
->szClass
= MapSL(from
->szClass
);
434 static WPARAM
map_wparam_char_WtoA( WPARAM wParam
, DWORD len
)
439 RtlUnicodeToMultiByteN( (LPSTR
)ch
, len
, &len
, &wch
, sizeof(wch
) );
441 return MAKEWPARAM( (ch
[0] << 8) | ch
[1], HIWORD(wParam
) );
443 return MAKEWPARAM( ch
[0], HIWORD(wParam
) );
446 /* call a 32-bit window procedure */
447 static LRESULT
call_window_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
453 hwnd
= WIN_GetFullHandle( hwnd
);
455 DPRINTF( "%04x:Call window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
456 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
458 *result
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
461 DPRINTF( "%04x:Ret window proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx\n",
462 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, *result
);
466 /* call a 32-bit dialog procedure */
467 static LRESULT
call_dialog_proc( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
, LRESULT
*result
, void *arg
)
474 hwnd
= WIN_GetFullHandle( hwnd
);
476 DPRINTF( "%04x:Call dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
477 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
);
479 ret
= WINPROC_wrapper( proc
, hwnd
, msg
, wp
, lp
);
480 *result
= GetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
);
483 DPRINTF( "%04x:Ret dialog proc %p (hwnd=%p,msg=%s,wp=%08lx,lp=%08lx) retval=%08lx result=%08lx\n",
484 GetCurrentThreadId(), proc
, hwnd
, SPY_GetMsgName(msg
, hwnd
), wp
, lp
, ret
, *result
);
488 /* call a 16-bit window procedure */
489 static LRESULT
call_window_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
490 LRESULT
*result
, void *arg
)
492 WNDPROC16 proc
= arg
;
501 DRAWITEMSTRUCT16 dis16
;
502 COMPAREITEMSTRUCT16 cis16
;
508 /* Window procedures want ax = hInstance, ds = es = ss */
510 memset(&context
, 0, sizeof(context
));
511 context
.SegDs
= context
.SegEs
= SELECTOROF(NtCurrentTeb()->WOW32Reserved
);
512 context
.SegFs
= wine_get_fs();
513 context
.SegGs
= wine_get_gs();
514 if (!(context
.Eax
= GetWindowWord( HWND_32(hwnd
), GWLP_HINSTANCE
))) context
.Eax
= context
.SegDs
;
515 context
.SegCs
= SELECTOROF(proc
);
516 context
.Eip
= OFFSETOF(proc
);
517 context
.Ebp
= OFFSETOF(NtCurrentTeb()->WOW32Reserved
) + FIELD_OFFSET(STACK16FRAME
, bp
);
521 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
522 work if structures passed in lParam are placed in the stack/data
523 segment. Programmers easily make the mistake of converting lParam
524 to a near rather than a far pointer, since Windows apparently
525 allows this. We copy the structures to the 16 bit stack; this is
526 ugly but makes these programs work. */
531 size
= sizeof(CREATESTRUCT16
); break;
533 size
= sizeof(DRAWITEMSTRUCT16
); break;
535 size
= sizeof(COMPAREITEMSTRUCT16
); break;
539 memcpy( &args
.u
, MapSL(lParam
), size
);
540 lParam
= PtrToUlong(NtCurrentTeb()->WOW32Reserved
) - size
;
544 args
.params
[4] = hwnd
;
545 args
.params
[3] = msg
;
546 args
.params
[2] = wParam
;
547 args
.params
[1] = HIWORD(lParam
);
548 args
.params
[0] = LOWORD(lParam
);
549 WOWCallback16Ex( 0, WCB16_REGS
, sizeof(args
.params
) + size
, &args
, (DWORD
*)&context
);
550 *result
= MAKELONG( LOWORD(context
.Eax
), LOWORD(context
.Edx
) );
554 /* call a 16-bit dialog procedure */
555 static LRESULT
call_dialog_proc16( HWND16 hwnd
, UINT16 msg
, WPARAM16 wp
, LPARAM lp
,
556 LRESULT
*result
, void *arg
)
558 LRESULT ret
= call_window_proc16( hwnd
, msg
, wp
, lp
, result
, arg
);
559 *result
= GetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
);
563 /* helper callback for 32W->16 conversion */
564 static LRESULT
call_window_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
565 LRESULT
*result
, void *arg
)
567 return WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
570 /* helper callback for 32W->16 conversion */
571 static LRESULT
call_dialog_proc_Ato16( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
572 LRESULT
*result
, void *arg
)
574 return WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wp
, lp
, result
, arg
);
577 /* helper callback for 16->32W conversion */
578 static LRESULT
call_window_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
579 LRESULT
*result
, void *arg
)
581 return WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wp
, lp
, result
,
582 arg
, WMCHAR_MAP_CALLWINDOWPROC
);
585 /* helper callback for 16->32W conversion */
586 static LRESULT
call_dialog_proc_AtoW( HWND hwnd
, UINT msg
, WPARAM wp
, LPARAM lp
,
587 LRESULT
*result
, void *arg
)
589 return WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wp
, lp
, result
,
590 arg
, WMCHAR_MAP_CALLWINDOWPROC
);
594 /**********************************************************************
597 * Get a window procedure pointer that can be passed to the Windows program.
599 WNDPROC16
WINPROC_GetProc16( WNDPROC proc
, BOOL unicode
)
603 if (unicode
) ptr
= alloc_winproc( NULL
, proc
);
604 else ptr
= alloc_winproc( proc
, NULL
);
607 return alloc_win16_thunk( ptr
);
611 /**********************************************************************
614 * Get a window procedure pointer that can be passed to the Windows program.
616 WNDPROC
WINPROC_GetProc( WNDPROC proc
, BOOL unicode
)
618 WINDOWPROC
*ptr
= handle_to_proc( proc
);
620 if (!ptr
) return proc
;
623 if (ptr
->procW
) return ptr
->procW
;
628 if (ptr
->procA
) return ptr
->procA
;
634 /**********************************************************************
635 * WINPROC_AllocProc16
637 * Allocate a window procedure for a window or class.
639 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
640 * lot of windows, it will usually only have a limited number of window procedures, so the
641 * array won't grow too large, and this way we avoid the need to track allocations per window.
643 WNDPROC
WINPROC_AllocProc16( WNDPROC16 func
)
647 if (!func
) return NULL
;
649 /* check if the function is already a win proc */
650 if (!(proc
= handle16_to_proc( func
)))
652 EnterCriticalSection( &winproc_cs
);
654 /* then check if we already have a winproc for that function */
655 if (!(proc
= find_winproc16( func
)))
657 if (winproc_used
< MAX_WINPROCS
)
659 proc
= &winproc_array
[winproc_used
++];
661 TRACE( "allocated %p for %p/16-bit (%d/%d used)\n",
662 proc_to_handle(proc
), func
, winproc_used
, MAX_WINPROCS
);
664 else FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func
);
666 else TRACE( "reusing %p for %p/16-bit\n", proc_to_handle(proc
), func
);
668 LeaveCriticalSection( &winproc_cs
);
670 return proc_to_handle( proc
);
674 /**********************************************************************
677 * Allocate a window procedure for a window or class.
679 * Note that allocated winprocs are never freed; the idea is that even if an app creates a
680 * lot of windows, it will usually only have a limited number of window procedures, so the
681 * array won't grow too large, and this way we avoid the need to track allocations per window.
683 WNDPROC
WINPROC_AllocProc( WNDPROC funcA
, WNDPROC funcW
)
687 if (!(proc
= alloc_winproc( funcA
, funcW
))) return NULL
;
688 return proc_to_handle( proc
);
692 /**********************************************************************
695 * Return the window procedure type, or the default value if not a winproc handle.
697 BOOL
WINPROC_IsUnicode( WNDPROC proc
, BOOL def_val
)
699 WINDOWPROC
*ptr
= handle_to_proc( proc
);
701 if (!ptr
) return def_val
;
702 if (ptr
->procA
&& ptr
->procW
) return def_val
; /* can be both */
703 return (ptr
->procW
!= NULL
);
707 /**********************************************************************
708 * WINPROC_TestLBForStr
710 * Return TRUE if the lparam is a string
712 static inline BOOL
WINPROC_TestLBForStr( HWND hwnd
, UINT msg
)
714 DWORD style
= GetWindowLongA( hwnd
, GWL_STYLE
);
715 if (msg
<= CB_MSGMAX
)
716 return (!(style
& (CBS_OWNERDRAWFIXED
| CBS_OWNERDRAWVARIABLE
)) || (style
& CBS_HASSTRINGS
));
718 return (!(style
& (LBS_OWNERDRAWFIXED
| LBS_OWNERDRAWVARIABLE
)) || (style
& LBS_HASSTRINGS
));
723 static UINT_PTR
convert_handle_16_to_32(HANDLE16 src
, unsigned int flags
)
726 UINT sz
= GlobalSize16(src
);
729 if (!(dst
= GlobalAlloc(flags
, sz
)))
731 ptr16
= GlobalLock16(src
);
732 ptr32
= GlobalLock(dst
);
733 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr32
, ptr16
, sz
);
737 return (UINT_PTR
)dst
;
740 static HANDLE16
convert_handle_32_to_16(UINT_PTR src
, unsigned int flags
)
743 UINT sz
= GlobalSize((HANDLE
)src
);
746 if (!(dst
= GlobalAlloc16(flags
, sz
)))
748 ptr32
= GlobalLock((HANDLE
)src
);
749 ptr16
= GlobalLock16(dst
);
750 if (ptr16
!= NULL
&& ptr32
!= NULL
) memcpy(ptr16
, ptr32
, sz
);
751 GlobalUnlock((HANDLE
)src
);
758 /**********************************************************************
759 * WINPROC_CallProcAtoW
761 * Call a window procedure, translating args from Ansi to Unicode.
763 LRESULT
WINPROC_CallProcAtoW( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
764 LPARAM lParam
, LRESULT
*result
, void *arg
, enum wm_char_mapping mapping
)
768 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
769 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
776 WCHAR
*ptr
, buffer
[512];
777 CREATESTRUCTA
*csA
= (CREATESTRUCTA
*)lParam
;
778 CREATESTRUCTW csW
= *(CREATESTRUCTW
*)csA
;
779 MDICREATESTRUCTW mdi_cs
;
780 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
782 if (!IS_INTRESOURCE(csA
->lpszClass
))
784 class_lenA
= strlen(csA
->lpszClass
) + 1;
785 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->lpszClass
, class_lenA
);
787 if (!IS_INTRESOURCE(csA
->lpszName
))
789 name_lenA
= strlen(csA
->lpszName
) + 1;
790 RtlMultiByteToUnicodeSize( &name_lenW
, csA
->lpszName
, name_lenA
);
793 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), class_lenW
+ name_lenW
))) break;
798 RtlMultiByteToUnicodeN( ptr
, class_lenW
, NULL
, csA
->lpszClass
, class_lenA
);
802 csW
.lpszName
= ptr
+ class_lenW
/sizeof(WCHAR
);
803 RtlMultiByteToUnicodeN( ptr
+ class_lenW
/sizeof(WCHAR
), name_lenW
, NULL
,
804 csA
->lpszName
, name_lenA
);
807 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
809 mdi_cs
= *(MDICREATESTRUCTW
*)csA
->lpCreateParams
;
810 mdi_cs
.szTitle
= csW
.lpszName
;
811 mdi_cs
.szClass
= csW
.lpszClass
;
812 csW
.lpCreateParams
= &mdi_cs
;
815 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
816 free_buffer( buffer
, ptr
);
822 WCHAR
*ptr
, buffer
[512];
823 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
824 MDICREATESTRUCTA
*csA
= (MDICREATESTRUCTA
*)lParam
;
825 MDICREATESTRUCTW csW
;
827 memcpy( &csW
, csA
, sizeof(csW
) );
829 if (!IS_INTRESOURCE(csA
->szTitle
))
831 title_lenA
= strlen(csA
->szTitle
) + 1;
832 RtlMultiByteToUnicodeSize( &title_lenW
, csA
->szTitle
, title_lenA
);
834 if (!IS_INTRESOURCE(csA
->szClass
))
836 class_lenA
= strlen(csA
->szClass
) + 1;
837 RtlMultiByteToUnicodeSize( &class_lenW
, csA
->szClass
, class_lenA
);
840 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenW
+ class_lenW
))) break;
845 RtlMultiByteToUnicodeN( ptr
, title_lenW
, NULL
, csA
->szTitle
, title_lenA
);
849 csW
.szClass
= ptr
+ title_lenW
/sizeof(WCHAR
);
850 RtlMultiByteToUnicodeN( ptr
+ title_lenW
/sizeof(WCHAR
), class_lenW
, NULL
,
851 csA
->szClass
, class_lenA
);
853 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csW
, result
, arg
);
854 free_buffer( buffer
, ptr
);
859 case WM_ASKCBFORMATNAME
:
861 WCHAR
*ptr
, buffer
[512];
862 LPSTR str
= (LPSTR
)lParam
;
863 DWORD len
= wParam
* sizeof(WCHAR
);
865 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
866 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
871 RtlUnicodeToMultiByteN( str
, wParam
- 1, &len
, ptr
, strlenW(ptr
) * sizeof(WCHAR
) );
875 free_buffer( buffer
, ptr
);
880 case LB_INSERTSTRING
:
882 case LB_FINDSTRINGEXACT
:
883 case LB_SELECTSTRING
:
885 case CB_INSERTSTRING
:
887 case CB_FINDSTRINGEXACT
:
888 case CB_SELECTSTRING
:
889 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
891 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
896 case WM_WININICHANGE
:
897 case WM_DEVMODECHANGE
:
902 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
905 WCHAR
*ptr
, buffer
[512];
906 LPCSTR strA
= (LPCSTR
)lParam
;
907 DWORD lenW
, lenA
= strlen(strA
) + 1;
909 RtlMultiByteToUnicodeSize( &lenW
, strA
, lenA
);
910 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenW
)))
912 RtlMultiByteToUnicodeN( ptr
, lenW
, NULL
, strA
, lenA
);
913 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
914 free_buffer( buffer
, ptr
);
921 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
923 WCHAR buffer
[512]; /* FIXME: fixed sized buffer */
925 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
929 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, ~0u, &len
,
930 buffer
, (strlenW(buffer
) + 1) * sizeof(WCHAR
) );
934 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
939 WCHAR
*ptr
, buffer
[512];
940 WORD len
= *(WORD
*)lParam
;
942 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
943 *((WORD
*)ptr
) = len
; /* store the length */
944 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
948 RtlUnicodeToMultiByteN( (LPSTR
)lParam
, len
, &reslen
, ptr
, *result
* sizeof(WCHAR
) );
949 if (reslen
< len
) ((LPSTR
)lParam
)[reslen
] = 0;
952 free_buffer( buffer
, ptr
);
959 MSG newmsg
= *(MSG
*)lParam
;
960 if (map_wparam_AtoW( newmsg
.message
, &newmsg
.wParam
, WMCHAR_MAP_NOMAPPING
))
961 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
963 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
972 case EM_SETPASSWORDCHAR
:
974 if (map_wparam_AtoW( msg
, &wParam
, mapping
))
975 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
978 case WM_GETTEXTLENGTH
:
979 case CB_GETLBTEXTLEN
:
981 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
984 WCHAR
*ptr
, buffer
[512];
986 DWORD len
= *result
+ 1;
987 /* Determine respective GETTEXT message */
988 UINT msgGetText
= (msg
== WM_GETTEXTLENGTH
) ? WM_GETTEXT
:
989 ((msg
== CB_GETLBTEXTLEN
) ? CB_GETLBTEXT
: LB_GETTEXT
);
990 /* wParam differs between the messages */
991 WPARAM wp
= (msg
== WM_GETTEXTLENGTH
) ? len
: wParam
;
993 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* sizeof(WCHAR
) ))) break;
995 if (callback
== call_window_proc
) /* FIXME: hack */
996 callback( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
, &tmp
, arg
);
998 tmp
= SendMessageW( hwnd
, msgGetText
, wp
, (LPARAM
)ptr
);
999 RtlUnicodeToMultiByteSize( &len
, ptr
, tmp
* sizeof(WCHAR
) );
1001 free_buffer( buffer
, ptr
);
1005 case WM_PAINTCLIPBOARD
:
1006 case WM_SIZECLIPBOARD
:
1007 FIXME_(msg
)( "message %s (0x%x) needs translation, please report\n",
1008 SPY_GetMsgName(msg
, hwnd
), msg
);
1012 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1019 /**********************************************************************
1020 * WINPROC_CallProcWtoA
1022 * Call a window procedure, translating args from Unicode to Ansi.
1024 static LRESULT
WINPROC_CallProcWtoA( winproc_callback_t callback
, HWND hwnd
, UINT msg
, WPARAM wParam
,
1025 LPARAM lParam
, LRESULT
*result
, void *arg
)
1029 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1030 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1037 char buffer
[1024], *cls
;
1038 CREATESTRUCTW
*csW
= (CREATESTRUCTW
*)lParam
;
1039 CREATESTRUCTA csA
= *(CREATESTRUCTA
*)csW
;
1040 MDICREATESTRUCTA mdi_cs
;
1041 DWORD name_lenA
= 0, name_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1043 if (!IS_INTRESOURCE(csW
->lpszClass
))
1045 class_lenW
= (strlenW(csW
->lpszClass
) + 1) * sizeof(WCHAR
);
1046 RtlUnicodeToMultiByteSize(&class_lenA
, csW
->lpszClass
, class_lenW
);
1048 if (!IS_INTRESOURCE(csW
->lpszName
))
1050 name_lenW
= (strlenW(csW
->lpszName
) + 1) * sizeof(WCHAR
);
1051 RtlUnicodeToMultiByteSize(&name_lenA
, csW
->lpszName
, name_lenW
);
1054 if (!(cls
= get_buffer( buffer
, sizeof(buffer
), class_lenA
+ name_lenA
))) break;
1058 RtlUnicodeToMultiByteN(cls
, class_lenA
, NULL
, csW
->lpszClass
, class_lenW
);
1059 csA
.lpszClass
= cls
;
1063 char *name
= cls
+ class_lenA
;
1064 RtlUnicodeToMultiByteN(name
, name_lenA
, NULL
, csW
->lpszName
, name_lenW
);
1065 csA
.lpszName
= name
;
1068 if (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1070 mdi_cs
= *(MDICREATESTRUCTA
*)csW
->lpCreateParams
;
1071 mdi_cs
.szTitle
= csA
.lpszName
;
1072 mdi_cs
.szClass
= csA
.lpszClass
;
1073 csA
.lpCreateParams
= &mdi_cs
;
1076 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1077 free_buffer( buffer
, cls
);
1082 case WM_ASKCBFORMATNAME
:
1084 char *ptr
, buffer
[512];
1085 DWORD len
= wParam
* 2;
1087 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
))) break;
1088 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1093 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, wParam
*sizeof(WCHAR
), &len
, ptr
, strlen(ptr
)+1 );
1094 *result
= len
/sizeof(WCHAR
) - 1; /* do not count terminating null */
1096 ((LPWSTR
)lParam
)[*result
] = 0;
1098 free_buffer( buffer
, ptr
);
1103 case LB_INSERTSTRING
:
1105 case LB_FINDSTRINGEXACT
:
1106 case LB_SELECTSTRING
:
1108 case CB_INSERTSTRING
:
1110 case CB_FINDSTRINGEXACT
:
1111 case CB_SELECTSTRING
:
1112 if (!lParam
|| !WINPROC_TestLBForStr( hwnd
, msg
))
1114 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1119 case WM_WININICHANGE
:
1120 case WM_DEVMODECHANGE
:
1125 if (!lParam
) ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1128 char *ptr
, buffer
[512];
1129 LPCWSTR strW
= (LPCWSTR
)lParam
;
1130 DWORD lenA
, lenW
= (strlenW(strW
) + 1) * sizeof(WCHAR
);
1132 RtlUnicodeToMultiByteSize( &lenA
, strW
, lenW
);
1133 if ((ptr
= get_buffer( buffer
, sizeof(buffer
), lenA
)))
1135 RtlUnicodeToMultiByteN( ptr
, lenA
, NULL
, strW
, lenW
);
1136 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1137 free_buffer( buffer
, ptr
);
1144 char *ptr
, buffer
[1024];
1145 DWORD title_lenA
= 0, title_lenW
= 0, class_lenA
= 0, class_lenW
= 0;
1146 MDICREATESTRUCTW
*csW
= (MDICREATESTRUCTW
*)lParam
;
1147 MDICREATESTRUCTA csA
;
1149 memcpy( &csA
, csW
, sizeof(csA
) );
1151 if (!IS_INTRESOURCE(csW
->szTitle
))
1153 title_lenW
= (strlenW(csW
->szTitle
) + 1) * sizeof(WCHAR
);
1154 RtlUnicodeToMultiByteSize( &title_lenA
, csW
->szTitle
, title_lenW
);
1156 if (!IS_INTRESOURCE(csW
->szClass
))
1158 class_lenW
= (strlenW(csW
->szClass
) + 1) * sizeof(WCHAR
);
1159 RtlUnicodeToMultiByteSize( &class_lenA
, csW
->szClass
, class_lenW
);
1162 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), title_lenA
+ class_lenA
))) break;
1166 RtlUnicodeToMultiByteN( ptr
, title_lenA
, NULL
, csW
->szTitle
, title_lenW
);
1171 RtlUnicodeToMultiByteN( ptr
+ title_lenA
, class_lenA
, NULL
, csW
->szClass
, class_lenW
);
1172 csA
.szClass
= ptr
+ title_lenA
;
1174 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&csA
, result
, arg
);
1175 free_buffer( buffer
, ptr
);
1181 if (lParam
&& WINPROC_TestLBForStr( hwnd
, msg
))
1183 char buffer
[512]; /* FIXME: fixed sized buffer */
1185 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)buffer
, result
, arg
);
1189 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, ~0u, &len
, buffer
, strlen(buffer
) + 1 );
1190 *result
= len
/ sizeof(WCHAR
) - 1;
1193 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1198 char *ptr
, buffer
[512];
1199 WORD len
= *(WORD
*)lParam
;
1201 if (!(ptr
= get_buffer( buffer
, sizeof(buffer
), len
* 2 ))) break;
1202 *((WORD
*)ptr
) = len
* 2; /* store the length */
1203 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)ptr
, result
, arg
);
1207 RtlMultiByteToUnicodeN( (LPWSTR
)lParam
, len
*sizeof(WCHAR
), &reslen
, ptr
, *result
);
1208 *result
= reslen
/ sizeof(WCHAR
);
1209 if (*result
< len
) ((LPWSTR
)lParam
)[*result
] = 0;
1211 free_buffer( buffer
, ptr
);
1218 MSG newmsg
= *(MSG
*)lParam
;
1219 switch(newmsg
.message
)
1224 case WM_SYSDEADCHAR
:
1225 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 1 );
1228 newmsg
.wParam
= map_wparam_char_WtoA( newmsg
.wParam
, 2 );
1231 ret
= callback( hwnd
, msg
, wParam
, (LPARAM
)&newmsg
, result
, arg
);
1233 else ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1242 RtlUnicodeToMultiByteN( ch
, 2, &len
, &wch
, sizeof(wch
) );
1243 ret
= callback( hwnd
, msg
, (BYTE
)ch
[0], lParam
, result
, arg
);
1244 if (len
== 2) ret
= callback( hwnd
, msg
, (BYTE
)ch
[1], lParam
, result
, arg
);
1252 case WM_SYSDEADCHAR
:
1253 case EM_SETPASSWORDCHAR
:
1254 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,1), lParam
, result
, arg
);
1258 ret
= callback( hwnd
, msg
, map_wparam_char_WtoA(wParam
,2), lParam
, result
, arg
);
1261 case WM_PAINTCLIPBOARD
:
1262 case WM_SIZECLIPBOARD
:
1263 FIXME_(msg
)( "message %s (%04x) needs translation, please report\n",
1264 SPY_GetMsgName(msg
, hwnd
), msg
);
1268 ret
= callback( hwnd
, msg
, wParam
, lParam
, result
, arg
);
1276 /**********************************************************************
1277 * WINPROC_CallProc16To32A
1279 LRESULT
WINPROC_CallProc16To32A( winproc_callback_t callback
, HWND16 hwnd
, UINT16 msg
,
1280 WPARAM16 wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1283 HWND hwnd32
= WIN_Handle32( hwnd
);
1285 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
1286 hwnd32
, SPY_GetMsgName(msg
, hwnd32
), wParam
, lParam
);
1293 CREATESTRUCT16
*cs16
= MapSL(lParam
);
1295 MDICREATESTRUCTA mdi_cs
;
1297 CREATESTRUCT16to32A( cs16
, &cs
);
1298 if (GetWindowLongW(hwnd32
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1300 MDICREATESTRUCT16
*mdi_cs16
= MapSL(cs16
->lpCreateParams
);
1301 MDICREATESTRUCT16to32A(mdi_cs16
, &mdi_cs
);
1302 cs
.lpCreateParams
= &mdi_cs
;
1304 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1305 CREATESTRUCT32Ato16( &cs
, cs16
);
1310 MDICREATESTRUCT16
*cs16
= MapSL(lParam
);
1311 MDICREATESTRUCTA cs
;
1313 MDICREATESTRUCT16to32A( cs16
, &cs
);
1314 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cs
, result
, arg
);
1315 MDICREATESTRUCT32Ato16( &cs
, cs16
);
1318 case WM_MDIACTIVATE
:
1320 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32( HIWORD(lParam
) ),
1321 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1322 else /* message sent to MDI client */
1323 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1325 case WM_MDIGETACTIVE
:
1327 BOOL maximized
= FALSE
;
1328 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&maximized
, result
, arg
);
1329 *result
= MAKELRESULT( LOWORD(*result
), maximized
);
1333 ret
= callback( hwnd32
, wParam
? WM_MDIREFRESHMENU
: WM_MDISETMENU
,
1334 (WPARAM
)HMENU_32(LOWORD(lParam
)), (LPARAM
)HMENU_32(HIWORD(lParam
)),
1337 case WM_GETMINMAXINFO
:
1339 MINMAXINFO16
*mmi16
= MapSL(lParam
);
1342 MINMAXINFO16to32( mmi16
, &mmi
);
1343 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mmi
, result
, arg
);
1344 MINMAXINFO32to16( &mmi
, mmi16
);
1347 case WM_WINDOWPOSCHANGING
:
1348 case WM_WINDOWPOSCHANGED
:
1350 WINDOWPOS16
*winpos16
= MapSL(lParam
);
1353 WINDOWPOS16to32( winpos16
, &winpos
);
1354 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&winpos
, result
, arg
);
1355 WINDOWPOS32to16( &winpos
, winpos16
);
1360 NCCALCSIZE_PARAMS16
*nc16
= MapSL(lParam
);
1361 NCCALCSIZE_PARAMS nc
;
1364 RECT16to32( &nc16
->rgrc
[0], &nc
.rgrc
[0] );
1367 RECT16to32( &nc16
->rgrc
[1], &nc
.rgrc
[1] );
1368 RECT16to32( &nc16
->rgrc
[2], &nc
.rgrc
[2] );
1369 WINDOWPOS16to32( MapSL(nc16
->lppos
), &winpos
);
1372 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&nc
, result
, arg
);
1373 RECT32to16( &nc
.rgrc
[0], &nc16
->rgrc
[0] );
1376 RECT32to16( &nc
.rgrc
[1], &nc16
->rgrc
[1] );
1377 RECT32to16( &nc
.rgrc
[2], &nc16
->rgrc
[2] );
1378 WINDOWPOS32to16( &winpos
, MapSL(nc16
->lppos
) );
1382 case WM_COMPAREITEM
:
1384 COMPAREITEMSTRUCT16
* cis16
= MapSL(lParam
);
1385 COMPAREITEMSTRUCT cis
;
1386 cis
.CtlType
= cis16
->CtlType
;
1387 cis
.CtlID
= cis16
->CtlID
;
1388 cis
.hwndItem
= WIN_Handle32( cis16
->hwndItem
);
1389 cis
.itemID1
= cis16
->itemID1
;
1390 cis
.itemData1
= cis16
->itemData1
;
1391 cis
.itemID2
= cis16
->itemID2
;
1392 cis
.itemData2
= cis16
->itemData2
;
1393 cis
.dwLocaleId
= 0; /* FIXME */
1394 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cis
, result
, arg
);
1399 DELETEITEMSTRUCT16
* dis16
= MapSL(lParam
);
1400 DELETEITEMSTRUCT dis
;
1401 dis
.CtlType
= dis16
->CtlType
;
1402 dis
.CtlID
= dis16
->CtlID
;
1403 dis
.hwndItem
= WIN_Handle32( dis16
->hwndItem
);
1404 dis
.itemData
= dis16
->itemData
;
1405 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1408 case WM_MEASUREITEM
:
1410 MEASUREITEMSTRUCT16
* mis16
= MapSL(lParam
);
1411 MEASUREITEMSTRUCT mis
;
1412 mis
.CtlType
= mis16
->CtlType
;
1413 mis
.CtlID
= mis16
->CtlID
;
1414 mis
.itemID
= mis16
->itemID
;
1415 mis
.itemWidth
= mis16
->itemWidth
;
1416 mis
.itemHeight
= mis16
->itemHeight
;
1417 mis
.itemData
= mis16
->itemData
;
1418 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&mis
, result
, arg
);
1419 mis16
->itemWidth
= (UINT16
)mis
.itemWidth
;
1420 mis16
->itemHeight
= (UINT16
)mis
.itemHeight
;
1425 DRAWITEMSTRUCT16
* dis16
= MapSL(lParam
);
1427 dis
.CtlType
= dis16
->CtlType
;
1428 dis
.CtlID
= dis16
->CtlID
;
1429 dis
.itemID
= dis16
->itemID
;
1430 dis
.itemAction
= dis16
->itemAction
;
1431 dis
.itemState
= dis16
->itemState
;
1432 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND
)HMENU_32(dis16
->hwndItem
)
1433 : WIN_Handle32( dis16
->hwndItem
);
1434 dis
.hDC
= HDC_32(dis16
->hDC
);
1435 dis
.itemData
= dis16
->itemData
;
1436 dis
.rcItem
.left
= dis16
->rcItem
.left
;
1437 dis
.rcItem
.top
= dis16
->rcItem
.top
;
1438 dis
.rcItem
.right
= dis16
->rcItem
.right
;
1439 dis
.rcItem
.bottom
= dis16
->rcItem
.bottom
;
1440 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&dis
, result
, arg
);
1445 COPYDATASTRUCT16
*cds16
= MapSL(lParam
);
1447 cds
.dwData
= cds16
->dwData
;
1448 cds
.cbData
= cds16
->cbData
;
1449 cds
.lpData
= MapSL(cds16
->lpData
);
1450 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&cds
, result
, arg
);
1456 MSG16
*msg16
= MapSL(lParam
);
1458 msg32
.hwnd
= WIN_Handle32( msg16
->hwnd
);
1459 msg32
.message
= msg16
->message
;
1460 msg32
.wParam
= msg16
->wParam
;
1461 msg32
.lParam
= msg16
->lParam
;
1462 msg32
.time
= msg16
->time
;
1463 msg32
.pt
.x
= msg16
->pt
.x
;
1464 msg32
.pt
.y
= msg16
->pt
.y
;
1465 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&msg32
, result
, arg
);
1468 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1473 next
.hmenuIn
= (HMENU
)lParam
;
1476 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)&next
, result
, arg
);
1477 *result
= MAKELONG( HMENU_16(next
.hmenuNext
), HWND_16(next
.hwndNext
) );
1484 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1485 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1489 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1490 (LPARAM
)WIN_Handle32( HIWORD(lParam
) ), result
, arg
);
1493 if (HIWORD(lParam
) <= CTLCOLOR_STATIC
)
1494 ret
= callback( hwnd32
, WM_CTLCOLORMSGBOX
+ HIWORD(lParam
),
1495 (WPARAM
)HDC_32(wParam
), (LPARAM
)WIN_Handle32( LOWORD(lParam
) ),
1500 case WM_WININICHANGE
:
1501 case WM_DEVMODECHANGE
:
1502 case WM_ASKCBFORMATNAME
:
1504 ret
= callback( hwnd32
, msg
, wParam
, (LPARAM
)MapSL(lParam
), result
, arg
);
1507 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1508 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1511 if((LOWORD(lParam
) & MF_POPUP
) && (LOWORD(lParam
) != 0xFFFF))
1513 HMENU hmenu
= HMENU_32(HIWORD(lParam
));
1514 UINT pos
= MENU_FindSubMenu( &hmenu
, HMENU_32(wParam
) );
1515 if (pos
== 0xffff) pos
= 0; /* NO_SELECTED_ITEM */
1518 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, LOWORD(lParam
) ),
1519 (LPARAM
)HMENU_32(HIWORD(lParam
)), result
, arg
);
1521 case WM_PARENTNOTIFY
:
1522 if ((wParam
== WM_CREATE
) || (wParam
== WM_DESTROY
))
1523 ret
= callback( hwnd32
, msg
, MAKEWPARAM( wParam
, HIWORD(lParam
) ),
1524 (LPARAM
)WIN_Handle32( LOWORD(lParam
) ), result
, arg
);
1526 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1528 case WM_ACTIVATEAPP
:
1529 /* We need this when SetActiveWindow sends a Sendmessage16() to
1530 * a 32-bit window. Might be superfluous with 32-bit interprocess
1531 * message queues. */
1532 if (lParam
) lParam
= HTASK_32(lParam
);
1533 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1535 case WM_DDE_INITIATE
:
1536 case WM_DDE_TERMINATE
:
1537 case WM_DDE_UNADVISE
:
1538 case WM_DDE_REQUEST
:
1539 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1545 HANDLE16 lo16
= LOWORD(lParam
);
1547 if (lo16
&& !(lo32
= convert_handle_16_to_32(lo16
, GMEM_DDESHARE
))) break;
1548 lParam
= PackDDElParam( msg
, lo32
, HIWORD(lParam
) );
1549 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1551 break; /* FIXME don't know how to free allocated memory (handle) !! */
1554 UINT_PTR lo
= LOWORD(lParam
);
1555 UINT_PTR hi
= HIWORD(lParam
);
1559 if (GlobalGetAtomNameA(hi
, buf
, 2) > 0) flag
|= 1;
1560 if (GlobalSize16(hi
) != 0) flag
|= 2;
1566 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1571 break; /* atom, nothing to do */
1573 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi
);
1576 hi
= convert_handle_16_to_32(hi
, GMEM_DDESHARE
);
1579 lParam
= PackDDElParam( WM_DDE_ACK
, lo
, hi
);
1580 ret
= callback( hwnd32
, msg
, (WPARAM
)WIN_Handle32(wParam
), lParam
, result
, arg
);
1582 break; /* FIXME don't know how to free allocated memory (handle) !! */
1583 case WM_DDE_EXECUTE
:
1584 lParam
= convert_handle_16_to_32( lParam
, GMEM_DDESHARE
);
1585 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1586 break; /* FIXME don't know how to free allocated memory (handle) !! */
1587 case WM_PAINTCLIPBOARD
:
1588 case WM_SIZECLIPBOARD
:
1589 FIXME_(msg
)( "message %04x needs translation\n", msg
);
1592 ret
= callback( hwnd32
, msg
, wParam
, lParam
, result
, arg
);
1599 /**********************************************************************
1600 * __wine_call_wndproc (USER.1010)
1602 LRESULT WINAPI
__wine_call_wndproc( HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
,
1608 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
1610 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
1615 /**********************************************************************
1616 * WINPROC_CallProc32ATo16
1618 * Call a 16-bit window procedure, translating the 32-bit args.
1620 LRESULT
WINPROC_CallProc32ATo16( winproc_callback16_t callback
, HWND hwnd
, UINT msg
,
1621 WPARAM wParam
, LPARAM lParam
, LRESULT
*result
, void *arg
)
1625 TRACE_(msg
)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
1626 hwnd
, SPY_GetMsgName(msg
, hwnd
), wParam
, lParam
);
1633 CREATESTRUCTA
*cs32
= (CREATESTRUCTA
*)lParam
;
1635 MDICREATESTRUCT16 mdi_cs16
;
1636 BOOL mdi_child
= (GetWindowLongW(hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
);
1638 CREATESTRUCT32Ato16( cs32
, &cs
);
1639 cs
.lpszName
= MapLS( cs32
->lpszName
);
1640 cs
.lpszClass
= MapLS( cs32
->lpszClass
);
1644 MDICREATESTRUCTA
*mdi_cs
= (MDICREATESTRUCTA
*)cs32
->lpCreateParams
;
1645 MDICREATESTRUCT32Ato16( mdi_cs
, &mdi_cs16
);
1646 mdi_cs16
.szTitle
= MapLS( mdi_cs
->szTitle
);
1647 mdi_cs16
.szClass
= MapLS( mdi_cs
->szClass
);
1648 cs
.lpCreateParams
= MapLS( &mdi_cs16
);
1650 lParam
= MapLS( &cs
);
1651 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1653 UnMapLS( cs
.lpszName
);
1654 UnMapLS( cs
.lpszClass
);
1657 UnMapLS( cs
.lpCreateParams
);
1658 UnMapLS( mdi_cs16
.szTitle
);
1659 UnMapLS( mdi_cs16
.szClass
);
1665 MDICREATESTRUCTA
*cs32
= (MDICREATESTRUCTA
*)lParam
;
1666 MDICREATESTRUCT16 cs
;
1668 MDICREATESTRUCT32Ato16( cs32
, &cs
);
1669 cs
.szTitle
= MapLS( cs32
->szTitle
);
1670 cs
.szClass
= MapLS( cs32
->szClass
);
1671 lParam
= MapLS( &cs
);
1672 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1674 UnMapLS( cs
.szTitle
);
1675 UnMapLS( cs
.szClass
);
1678 case WM_MDIACTIVATE
:
1679 if (GetWindowLongW( hwnd
, GWL_EXSTYLE
) & WS_EX_MDICHILD
)
1680 ret
= callback( HWND_16(hwnd
), msg
, ((HWND
)lParam
== hwnd
),
1681 MAKELPARAM( LOWORD(lParam
), LOWORD(wParam
) ), result
, arg
);
1683 ret
= callback( HWND_16(hwnd
), msg
, HWND_16( (HWND
)wParam
), 0, result
, arg
);
1685 case WM_MDIGETACTIVE
:
1686 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1687 if (lParam
) *(BOOL
*)lParam
= (BOOL16
)HIWORD(*result
);
1688 *result
= (LRESULT
)WIN_Handle32( LOWORD(*result
) );
1691 ret
= callback( HWND_16(hwnd
), msg
, (lParam
== 0),
1692 MAKELPARAM( LOWORD(wParam
), LOWORD(lParam
) ), result
, arg
);
1694 case WM_GETMINMAXINFO
:
1696 MINMAXINFO
*mmi32
= (MINMAXINFO
*)lParam
;
1699 MINMAXINFO32to16( mmi32
, &mmi
);
1700 lParam
= MapLS( &mmi
);
1701 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1703 MINMAXINFO16to32( &mmi
, mmi32
);
1708 NCCALCSIZE_PARAMS
*nc32
= (NCCALCSIZE_PARAMS
*)lParam
;
1709 NCCALCSIZE_PARAMS16 nc
;
1712 RECT32to16( &nc32
->rgrc
[0], &nc
.rgrc
[0] );
1715 RECT32to16( &nc32
->rgrc
[1], &nc
.rgrc
[1] );
1716 RECT32to16( &nc32
->rgrc
[2], &nc
.rgrc
[2] );
1717 WINDOWPOS32to16( nc32
->lppos
, &winpos
);
1718 nc
.lppos
= MapLS( &winpos
);
1720 lParam
= MapLS( &nc
);
1721 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1723 RECT16to32( &nc
.rgrc
[0], &nc32
->rgrc
[0] );
1726 RECT16to32( &nc
.rgrc
[1], &nc32
->rgrc
[1] );
1727 RECT16to32( &nc
.rgrc
[2], &nc32
->rgrc
[2] );
1728 WINDOWPOS16to32( &winpos
, nc32
->lppos
);
1729 UnMapLS( nc
.lppos
);
1733 case WM_WINDOWPOSCHANGING
:
1734 case WM_WINDOWPOSCHANGED
:
1736 WINDOWPOS
*winpos32
= (WINDOWPOS
*)lParam
;
1739 WINDOWPOS32to16( winpos32
, &winpos
);
1740 lParam
= MapLS( &winpos
);
1741 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1743 WINDOWPOS16to32( &winpos
, winpos32
);
1746 case WM_COMPAREITEM
:
1748 COMPAREITEMSTRUCT
*cis32
= (COMPAREITEMSTRUCT
*)lParam
;
1749 COMPAREITEMSTRUCT16 cis
;
1750 cis
.CtlType
= cis32
->CtlType
;
1751 cis
.CtlID
= cis32
->CtlID
;
1752 cis
.hwndItem
= HWND_16( cis32
->hwndItem
);
1753 cis
.itemID1
= cis32
->itemID1
;
1754 cis
.itemData1
= cis32
->itemData1
;
1755 cis
.itemID2
= cis32
->itemID2
;
1756 cis
.itemData2
= cis32
->itemData2
;
1757 lParam
= MapLS( &cis
);
1758 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1764 DELETEITEMSTRUCT
*dis32
= (DELETEITEMSTRUCT
*)lParam
;
1765 DELETEITEMSTRUCT16 dis
;
1766 dis
.CtlType
= dis32
->CtlType
;
1767 dis
.CtlID
= dis32
->CtlID
;
1768 dis
.itemID
= dis32
->itemID
;
1769 dis
.hwndItem
= (dis
.CtlType
== ODT_MENU
) ? (HWND16
)LOWORD(dis32
->hwndItem
)
1770 : HWND_16( dis32
->hwndItem
);
1771 dis
.itemData
= dis32
->itemData
;
1772 lParam
= MapLS( &dis
);
1773 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1779 DRAWITEMSTRUCT
*dis32
= (DRAWITEMSTRUCT
*)lParam
;
1780 DRAWITEMSTRUCT16 dis
;
1781 dis
.CtlType
= dis32
->CtlType
;
1782 dis
.CtlID
= dis32
->CtlID
;
1783 dis
.itemID
= dis32
->itemID
;
1784 dis
.itemAction
= dis32
->itemAction
;
1785 dis
.itemState
= dis32
->itemState
;
1786 dis
.hwndItem
= HWND_16( dis32
->hwndItem
);
1787 dis
.hDC
= HDC_16(dis32
->hDC
);
1788 dis
.itemData
= dis32
->itemData
;
1789 dis
.rcItem
.left
= dis32
->rcItem
.left
;
1790 dis
.rcItem
.top
= dis32
->rcItem
.top
;
1791 dis
.rcItem
.right
= dis32
->rcItem
.right
;
1792 dis
.rcItem
.bottom
= dis32
->rcItem
.bottom
;
1793 lParam
= MapLS( &dis
);
1794 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1798 case WM_MEASUREITEM
:
1800 MEASUREITEMSTRUCT
*mis32
= (MEASUREITEMSTRUCT
*)lParam
;
1801 MEASUREITEMSTRUCT16 mis
;
1802 mis
.CtlType
= mis32
->CtlType
;
1803 mis
.CtlID
= mis32
->CtlID
;
1804 mis
.itemID
= mis32
->itemID
;
1805 mis
.itemWidth
= mis32
->itemWidth
;
1806 mis
.itemHeight
= mis32
->itemHeight
;
1807 mis
.itemData
= mis32
->itemData
;
1808 lParam
= MapLS( &mis
);
1809 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1811 mis32
->itemWidth
= mis
.itemWidth
;
1812 mis32
->itemHeight
= mis
.itemHeight
;
1817 COPYDATASTRUCT
*cds32
= (COPYDATASTRUCT
*)lParam
;
1818 COPYDATASTRUCT16 cds
;
1820 cds
.dwData
= cds32
->dwData
;
1821 cds
.cbData
= cds32
->cbData
;
1822 cds
.lpData
= MapLS( cds32
->lpData
);
1823 lParam
= MapLS( &cds
);
1824 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1826 UnMapLS( cds
.lpData
);
1832 MSG
*msg32
= (MSG
*)lParam
;
1835 msg16
.hwnd
= HWND_16( msg32
->hwnd
);
1836 msg16
.message
= msg32
->message
;
1837 msg16
.wParam
= msg32
->wParam
;
1838 msg16
.lParam
= msg32
->lParam
;
1839 msg16
.time
= msg32
->time
;
1840 msg16
.pt
.x
= msg32
->pt
.x
;
1841 msg16
.pt
.y
= msg32
->pt
.y
;
1842 lParam
= MapLS( &msg16
);
1843 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1847 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1851 MDINEXTMENU
*next
= (MDINEXTMENU
*)lParam
;
1852 ret
= callback( HWND_16(hwnd
), msg
, wParam
, (LPARAM
)next
->hmenuIn
, result
, arg
);
1853 next
->hmenuNext
= HMENU_32( LOWORD(*result
) );
1854 next
->hwndNext
= WIN_Handle32( HIWORD(*result
) );
1859 case WM_ASKCBFORMATNAME
:
1860 wParam
= min( wParam
, 0xff80 ); /* Must be < 64K */
1864 case WM_WININICHANGE
:
1865 case WM_DEVMODECHANGE
:
1866 lParam
= MapLS( (void *)lParam
);
1867 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1874 ret
= callback( HWND_16(hwnd
), msg
, wParam
, MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ),
1879 ret
= callback( HWND_16(hwnd
), msg
, wParam
, MAKELPARAM( HIWORD(wParam
), (HWND16
)lParam
),
1882 case WM_CTLCOLORMSGBOX
:
1883 case WM_CTLCOLOREDIT
:
1884 case WM_CTLCOLORLISTBOX
:
1885 case WM_CTLCOLORBTN
:
1886 case WM_CTLCOLORDLG
:
1887 case WM_CTLCOLORSCROLLBAR
:
1888 case WM_CTLCOLORSTATIC
:
1889 ret
= callback( HWND_16(hwnd
), WM_CTLCOLOR
, wParam
,
1890 MAKELPARAM( (HWND16
)lParam
, msg
- WM_CTLCOLORMSGBOX
), result
, arg
);
1893 if(HIWORD(wParam
) & MF_POPUP
)
1896 if ((HIWORD(wParam
) != 0xffff) || lParam
)
1898 if ((hmenu
= GetSubMenu( (HMENU
)lParam
, LOWORD(wParam
) )))
1900 ret
= callback( HWND_16(hwnd
), msg
, HMENU_16(hmenu
),
1901 MAKELPARAM( HIWORD(wParam
), (HMENU16
)lParam
), result
, arg
);
1908 ret
= callback( HWND_16(hwnd
), msg
, wParam
,
1909 MAKELPARAM( HIWORD(wParam
), (HMENU16
)lParam
), result
, arg
);
1911 case WM_PARENTNOTIFY
:
1912 if ((LOWORD(wParam
) == WM_CREATE
) || (LOWORD(wParam
) == WM_DESTROY
))
1913 ret
= callback( HWND_16(hwnd
), msg
, wParam
,
1914 MAKELPARAM( (HWND16
)lParam
, HIWORD(wParam
) ), result
, arg
);
1916 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1918 case WM_ACTIVATEAPP
:
1919 ret
= callback( HWND_16(hwnd
), msg
, wParam
, HTASK_16( (HANDLE
)lParam
), result
, arg
);
1922 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
))
1923 ret
= callback( HWND_16(hwnd
), WM_PAINTICON
, 1, lParam
, result
, arg
);
1925 ret
= callback( HWND_16(hwnd
), WM_PAINT
, wParam
, lParam
, result
, arg
);
1928 if (IsIconic( hwnd
) && GetClassLongPtrW( hwnd
, GCLP_HICON
)) msg
= WM_ICONERASEBKGND
;
1929 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1931 case WM_DDE_INITIATE
:
1932 case WM_DDE_TERMINATE
:
1933 case WM_DDE_UNADVISE
:
1934 case WM_DDE_REQUEST
:
1935 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
), lParam
, result
, arg
);
1944 UnpackDDElParam( msg
, lParam
, &lo32
, &hi
);
1945 if (lo32
&& !(lo16
= convert_handle_32_to_16(lo32
, GMEM_DDESHARE
))) break;
1946 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
),
1947 MAKELPARAM(lo16
, hi
), result
, arg
);
1949 break; /* FIXME don't know how to free allocated memory (handle) !! */
1956 UnpackDDElParam( msg
, lParam
, &lo
, &hi
);
1958 if (GlobalGetAtomNameA((ATOM
)hi
, buf
, sizeof(buf
)) > 0) flag
|= 1;
1959 if (GlobalSize((HANDLE
)hi
) != 0) flag
|= 2;
1965 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1970 break; /* atom, nothing to do */
1972 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi
);
1975 hi
= convert_handle_32_to_16(hi
, GMEM_DDESHARE
);
1978 ret
= callback( HWND_16(hwnd
), msg
, HWND_16((HWND
)wParam
),
1979 MAKELPARAM(lo
, hi
), result
, arg
);
1981 break; /* FIXME don't know how to free allocated memory (handle) !! */
1982 case WM_DDE_EXECUTE
:
1983 lParam
= convert_handle_32_to_16(lParam
, GMEM_DDESHARE
);
1984 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
1985 break; /* FIXME don't know how to free allocated memory (handle) !! */
1987 ret
= callback( HWND_16(hwnd
), SBM_SETRANGE16
, 0, MAKELPARAM(wParam
, lParam
), result
, arg
);
1990 ret
= callback( HWND_16(hwnd
), SBM_GETRANGE16
, wParam
, lParam
, result
, arg
);
1991 *(LPINT
)wParam
= LOWORD(*result
);
1992 *(LPINT
)lParam
= HIWORD(*result
);
1999 ret
= callback( HWND_16(hwnd
), msg
+ BM_GETCHECK16
- BM_GETCHECK
, wParam
, lParam
, result
, arg
);
2007 case EM_SCROLLCARET
:
2010 case EM_GETLINECOUNT
:
2022 case EM_LINEFROMCHAR
:
2023 case EM_SETTABSTOPS
:
2024 case EM_SETPASSWORDCHAR
:
2025 case EM_EMPTYUNDOBUFFER
:
2026 case EM_GETFIRSTVISIBLELINE
:
2027 case EM_SETREADONLY
:
2028 case EM_SETWORDBREAKPROC
:
2029 case EM_GETWORDBREAKPROC
:
2030 case EM_GETPASSWORDCHAR
:
2031 ret
= callback( HWND_16(hwnd
), msg
+ EM_GETSEL16
- EM_GETSEL
, wParam
, lParam
, result
, arg
);
2034 ret
= callback( HWND_16(hwnd
), EM_SETSEL16
, 0, MAKELPARAM( wParam
, lParam
), result
, arg
);
2038 case LB_DELETESTRING
:
2039 case LB_GETANCHORINDEX
:
2040 case LB_GETCARETINDEX
:
2043 case LB_GETHORIZONTALEXTENT
:
2044 case LB_GETITEMDATA
:
2045 case LB_GETITEMHEIGHT
:
2047 case LB_GETSELCOUNT
:
2049 case LB_GETTOPINDEX
:
2050 case LB_RESETCONTENT
:
2051 case LB_SELITEMRANGE
:
2052 case LB_SELITEMRANGEEX
:
2053 case LB_SETANCHORINDEX
:
2054 case LB_SETCARETINDEX
:
2055 case LB_SETCOLUMNWIDTH
:
2057 case LB_SETHORIZONTALEXTENT
:
2058 case LB_SETITEMDATA
:
2059 case LB_SETITEMHEIGHT
:
2061 case LB_SETTOPINDEX
:
2062 ret
= callback( HWND_16(hwnd
), msg
+ LB_ADDSTRING16
- LB_ADDSTRING
, wParam
, lParam
, result
, arg
);
2066 case LB_FINDSTRINGEXACT
:
2067 case LB_INSERTSTRING
:
2068 case LB_SELECTSTRING
:
2072 lParam
= MapLS( (LPSTR
)lParam
);
2073 ret
= callback( HWND_16(hwnd
), msg
+ LB_ADDSTRING16
- LB_ADDSTRING
, wParam
, lParam
, result
, arg
);
2076 case LB_GETSELITEMS
:
2078 INT
*items32
= (INT
*)lParam
;
2079 INT16
*items
, buffer
[512];
2082 wParam
= min( wParam
, 0x7f80 ); /* Must be < 64K */
2083 if (!(items
= get_buffer( buffer
, sizeof(buffer
), wParam
* sizeof(INT16
) ))) break;
2084 lParam
= MapLS( items
);
2085 ret
= callback( HWND_16(hwnd
), LB_GETSELITEMS16
, wParam
, lParam
, result
, arg
);
2087 for (i
= 0; i
< wParam
; i
++) items32
[i
] = items
[i
];
2088 free_buffer( buffer
, items
);
2091 case LB_SETTABSTOPS
:
2094 INT
*stops32
= (INT
*)lParam
;
2095 INT16
*stops
, buffer
[512];
2098 wParam
= min( wParam
, 0x7f80 ); /* Must be < 64K */
2099 if (!(stops
= get_buffer( buffer
, sizeof(buffer
), wParam
* sizeof(INT16
) ))) break;
2100 for (i
= 0; i
< wParam
; i
++) stops
[i
] = stops32
[i
];
2101 lParam
= MapLS( stops
);
2102 ret
= callback( HWND_16(hwnd
), LB_SETTABSTOPS16
, wParam
, lParam
, result
, arg
);
2104 free_buffer( buffer
, stops
);
2106 else ret
= callback( HWND_16(hwnd
), LB_SETTABSTOPS16
, wParam
, lParam
, result
, arg
);
2108 case CB_DELETESTRING
:
2110 case CB_GETLBTEXTLEN
:
2112 case CB_RESETCONTENT
:
2116 case CB_SHOWDROPDOWN
:
2117 case CB_SETITEMDATA
:
2118 case CB_SETITEMHEIGHT
:
2119 case CB_GETITEMHEIGHT
:
2120 case CB_SETEXTENDEDUI
:
2121 case CB_GETEXTENDEDUI
:
2122 case CB_GETDROPPEDSTATE
:
2123 ret
= callback( HWND_16(hwnd
), msg
+ CB_GETEDITSEL16
- CB_GETEDITSEL
, wParam
, lParam
, result
, arg
);
2126 ret
= callback( HWND_16(hwnd
), CB_GETEDITSEL16
, wParam
, lParam
, result
, arg
);
2127 if (wParam
) *((PUINT
)(wParam
)) = LOWORD(*result
);
2128 if (lParam
) *((PUINT
)(lParam
)) = HIWORD(*result
); /* FIXME: substract 1? */
2132 case CB_FINDSTRINGEXACT
:
2133 case CB_INSERTSTRING
:
2134 case CB_SELECTSTRING
:
2137 lParam
= MapLS( (LPSTR
)lParam
);
2138 ret
= callback( HWND_16(hwnd
), msg
+ CB_GETEDITSEL16
- CB_GETEDITSEL
, wParam
, lParam
, result
, arg
);
2141 case LB_GETITEMRECT
:
2142 case CB_GETDROPPEDCONTROLRECT
:
2144 RECT
*r32
= (RECT
*)lParam
;
2146 lParam
= MapLS( &rect
);
2147 ret
= callback( HWND_16(hwnd
),
2148 (msg
== LB_GETITEMRECT
) ? LB_GETITEMRECT16
: CB_GETDROPPEDCONTROLRECT16
,
2149 wParam
, lParam
, result
, arg
);
2151 RECT16to32( &rect
, r32
);
2154 case WM_PAINTCLIPBOARD
:
2155 case WM_SIZECLIPBOARD
:
2156 FIXME_(msg
)( "message %04x needs translation\n", msg
);
2158 /* the following messages should not be sent to 16-bit apps */
2161 case WM_CAPTURECHANGED
:
2162 case WM_STYLECHANGING
:
2163 case WM_STYLECHANGED
:
2166 ret
= callback( HWND_16(hwnd
), msg
, wParam
, lParam
, result
, arg
);
2173 /**********************************************************************
2174 * WINPROC_call_window
2176 * Call the window procedure of the specified window.
2178 BOOL
WINPROC_call_window( HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
,
2179 LRESULT
*result
, BOOL unicode
, enum wm_char_mapping mapping
)
2181 struct user_thread_info
*thread_info
= get_user_thread_info();
2185 if (!(wndPtr
= WIN_GetPtr( hwnd
))) return FALSE
;
2186 if (wndPtr
== WND_OTHER_PROCESS
|| wndPtr
== WND_DESKTOP
) return FALSE
;
2187 if (wndPtr
->tid
!= GetCurrentThreadId())
2189 WIN_ReleasePtr( wndPtr
);
2192 proc
= handle_to_proc( wndPtr
->winproc
);
2193 WIN_ReleasePtr( wndPtr
);
2195 if (!proc
) return TRUE
;
2197 if (thread_info
->recursion_count
> MAX_WINPROC_RECURSION
) return FALSE
;
2198 thread_info
->recursion_count
++;
2203 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
);
2204 else if (proc
->procA
)
2205 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
2207 WINPROC_CallProcWtoA( call_window_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, result
, proc
->proc16
);
2212 call_window_proc( hwnd
, msg
, wParam
, lParam
, result
, proc
->procA
);
2213 else if (proc
->procW
)
2214 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, result
, proc
->procW
, mapping
);
2216 WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wParam
, lParam
, result
, proc
->proc16
);
2218 thread_info
->recursion_count
--;
2223 /**********************************************************************
2224 * CallWindowProc (USER.122)
2226 LRESULT WINAPI
CallWindowProc16( WNDPROC16 func
, HWND16 hwnd
, UINT16 msg
,
2227 WPARAM16 wParam
, LPARAM lParam
)
2232 if (!func
) return 0;
2234 if (!(proc
= handle16_to_proc( func
)))
2235 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2236 else if (proc
->procA
)
2237 WINPROC_CallProc16To32A( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2238 else if (proc
->procW
)
2239 WINPROC_CallProc16To32A( call_window_proc_AtoW
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2241 call_window_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2247 /**********************************************************************
2248 * CallWindowProcA (USER32.@)
2250 * The CallWindowProc() function invokes the windows procedure _func_,
2251 * with _hwnd_ as the target window, the message specified by _msg_, and
2252 * the message parameters _wParam_ and _lParam_.
2254 * Some kinds of argument conversion may be done, I'm not sure what.
2256 * CallWindowProc() may be used for windows subclassing. Use
2257 * SetWindowLong() to set a new windows procedure for windows of the
2258 * subclass, and handle subclassed messages in the new windows
2259 * procedure. The new windows procedure may then use CallWindowProc()
2260 * with _func_ set to the parent class's windows procedure to dispatch
2261 * the message to the superclass.
2265 * The return value is message dependent.
2271 LRESULT WINAPI
CallWindowProcA(
2272 WNDPROC func
, /* [in] window procedure */
2273 HWND hwnd
, /* [in] target window */
2274 UINT msg
, /* [in] message */
2275 WPARAM wParam
, /* [in] message dependent parameter */
2276 LPARAM lParam
/* [in] message dependent parameter */
2281 if (!func
) return 0;
2283 if (!(proc
= handle_to_proc( func
)))
2284 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2285 else if (proc
->procA
)
2286 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2287 else if (proc
->procW
)
2288 WINPROC_CallProcAtoW( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
2289 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
2291 WINPROC_CallProc32ATo16( call_window_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2296 /**********************************************************************
2297 * CallWindowProcW (USER32.@)
2299 * See CallWindowProcA.
2301 LRESULT WINAPI
CallWindowProcW( WNDPROC func
, HWND hwnd
, UINT msg
,
2302 WPARAM wParam
, LPARAM lParam
)
2307 if (!func
) return 0;
2309 if (!(proc
= handle_to_proc( func
)))
2310 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2311 else if (proc
->procW
)
2312 call_window_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2313 else if (proc
->procA
)
2314 WINPROC_CallProcWtoA( call_window_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2316 WINPROC_CallProcWtoA( call_window_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2321 /**********************************************************************
2322 * WINPROC_CallDlgProc16
2324 INT_PTR
WINPROC_CallDlgProc16( DLGPROC16 func
, HWND16 hwnd
, UINT16 msg
, WPARAM16 wParam
, LPARAM lParam
)
2330 if (!func
) return 0;
2332 if (!(proc
= handle16_to_proc( (WNDPROC16
)func
)))
2334 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2336 else if (proc
->procA
)
2338 ret
= WINPROC_CallProc16To32A( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
,
2339 &result
, proc
->procA
);
2340 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2342 else if (proc
->procW
)
2344 ret
= WINPROC_CallProc16To32A( call_dialog_proc_AtoW
, hwnd
, msg
, wParam
, lParam
,
2345 &result
, proc
->procW
);
2346 SetWindowLongPtrW( WIN_Handle32(hwnd
), DWLP_MSGRESULT
, result
);
2350 ret
= call_dialog_proc16( hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2356 /**********************************************************************
2357 * WINPROC_CallDlgProcA
2359 INT_PTR
WINPROC_CallDlgProcA( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2365 if (!func
) return 0;
2367 if (!(proc
= handle_to_proc( func
)))
2368 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2369 else if (proc
->procA
)
2370 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2371 else if (proc
->procW
)
2373 ret
= WINPROC_CallProcAtoW( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
,
2374 proc
->procW
, WMCHAR_MAP_CALLWINDOWPROC
);
2375 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2379 ret
= WINPROC_CallProc32ATo16( call_dialog_proc16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2380 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2386 /**********************************************************************
2387 * WINPROC_CallDlgProcW
2389 INT_PTR
WINPROC_CallDlgProcW( DLGPROC func
, HWND hwnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
2395 if (!func
) return 0;
2397 if (!(proc
= handle_to_proc( func
)))
2398 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, func
);
2399 else if (proc
->procW
)
2400 ret
= call_dialog_proc( hwnd
, msg
, wParam
, lParam
, &result
, proc
->procW
);
2401 else if (proc
->procA
)
2403 ret
= WINPROC_CallProcWtoA( call_dialog_proc
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->procA
);
2404 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);
2408 ret
= WINPROC_CallProcWtoA( call_dialog_proc_Ato16
, hwnd
, msg
, wParam
, lParam
, &result
, proc
->proc16
);
2409 SetWindowLongPtrW( hwnd
, DWLP_MSGRESULT
, result
);