d3d10: Return the read value from read_dword().
[wine.git] / dlls / user.exe16 / message.c
blob5d388a55312b9ede0f205b257ed1736464fd8f3b
1 /*
2 * 16-bit messaging support
4 * Copyright 2001 Alexandre Julliard
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
21 #include <assert.h>
22 #include <stdarg.h>
23 #include <string.h>
25 #include "wine/winuser16.h"
26 #include "wownt32.h"
27 #include "winerror.h"
28 #include "dde.h"
29 #include "user_private.h"
30 #include "wine/debug.h"
32 WINE_DEFAULT_DEBUG_CHANNEL(msg);
33 WINE_DECLARE_DEBUG_CHANNEL(message);
35 DWORD USER16_AlertableWait = 0;
37 struct wow_handlers32 wow_handlers32;
39 static LRESULT send_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
40 LRESULT *result, void *arg )
42 *result = SendMessageA( hwnd, msg, wp, lp );
43 return *result;
46 static LRESULT post_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
47 LRESULT *result, void *arg )
49 *result = 0;
50 return PostMessageA( hwnd, msg, wp, lp );
53 static LRESULT post_thread_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
54 LRESULT *result, void *arg )
56 DWORD_PTR tid = (DWORD_PTR)arg;
57 *result = 0;
58 return PostThreadMessageA( tid, msg, wp, lp );
61 static LRESULT get_message_callback( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
62 LRESULT *result, void *arg )
64 MSG16 *msg16 = arg;
66 msg16->hwnd = hwnd;
67 msg16->message = msg;
68 msg16->wParam = wp;
69 msg16->lParam = lp;
70 *result = 0;
71 return 0;
74 static LRESULT defdlg_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
75 LRESULT *result, void *arg )
77 *result = DefDlgProcA( hwnd, msg, wp, lp );
78 return *result;
81 static LRESULT defwnd_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
82 LRESULT *result, void *arg )
84 return *result = DefWindowProcA( hwnd, msg, wp, lp );
87 static LRESULT call_window_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
88 LRESULT *result, void *arg )
90 WNDPROC proc = arg;
91 *result = CallWindowProcA( proc, hwnd, msg, wp, lp );
92 return *result;
96 /**********************************************************************
97 * Support for window procedure thunks
100 #include "pshpack1.h"
101 typedef struct
103 WORD popl_eax; /* popl %eax (return address) */
104 WORD pushl_func; /* pushl $proc */
105 WNDPROC proc;
106 WORD pushl_eax; /* pushl %eax */
107 BYTE ljmp; /* ljmp relay*/
108 FARPROC16 relay; /* __wine_call_wndproc */
109 } WINPROC_THUNK;
110 #include "poppack.h"
112 #define WINPROC_HANDLE (~0u >> 16)
113 #define MAX_WINPROCS32 4096
114 #define MAX_WINPROCS16 1024
116 static WNDPROC16 winproc16_array[MAX_WINPROCS16];
117 static unsigned int winproc16_used;
119 static WINPROC_THUNK *thunk_array;
120 static UINT thunk_selector;
122 /* return the window proc index for a given handle, or -1 for an invalid handle
123 * indices 0 .. MAX_WINPROCS32-1 are for 32-bit procs,
124 * indices MAX_WINPROCS32 .. MAX_WINPROCS32+MAX_WINPROCS16-1 for 16-bit procs */
125 static int winproc_to_index( WNDPROC16 handle )
127 unsigned int index;
129 if (HIWORD(handle) == thunk_selector)
131 index = LOWORD(handle) / sizeof(WINPROC_THUNK);
132 /* check alignment */
133 if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return -1;
134 /* check array limits */
135 if (index >= MAX_WINPROCS32) return -1;
137 else
139 index = LOWORD(handle);
140 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return -1;
141 /* check array limits */
142 if (index >= winproc16_used + MAX_WINPROCS32) return -1;
144 return index;
147 /* allocate a 16-bit thunk for an existing window proc */
148 static WNDPROC16 alloc_win16_thunk( WNDPROC handle )
150 static FARPROC16 relay;
151 WINPROC_THUNK *thunk;
152 UINT index = LOWORD( handle );
154 if (index >= MAX_WINPROCS32) /* already a 16-bit proc */
155 return winproc16_array[index - MAX_WINPROCS32];
157 if (!thunk_array) /* allocate the array and its selector */
159 assert( MAX_WINPROCS16 * sizeof(WINPROC_THUNK) <= 0x10000 );
161 if (!(thunk_selector = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
162 MAX_WINPROCS16 * sizeof(WINPROC_THUNK) )))
163 return NULL;
164 FarSetOwner16( thunk_selector, 0 );
165 PrestoChangoSelector16( thunk_selector, thunk_selector );
166 thunk_array = GlobalLock16( thunk_selector );
167 relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
170 thunk = &thunk_array[index];
171 thunk->popl_eax = 0x5866; /* popl %eax */
172 thunk->pushl_func = 0x6866; /* pushl $proc */
173 thunk->proc = handle;
174 thunk->pushl_eax = 0x5066; /* pushl %eax */
175 thunk->ljmp = 0xea; /* ljmp relay*/
176 thunk->relay = relay;
177 return (WNDPROC16)MAKESEGPTR( thunk_selector, index * sizeof(WINPROC_THUNK) );
180 /**********************************************************************
181 * WINPROC_AllocProc16
183 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
185 int index;
186 WNDPROC ret;
188 if (!func) return NULL;
190 /* check if the function is already a win proc */
191 if ((index = winproc_to_index( func )) != -1)
192 return (WNDPROC)(ULONG_PTR)(index | (WINPROC_HANDLE << 16));
194 /* then check if we already have a winproc for that function */
195 for (index = 0; index < winproc16_used; index++)
196 if (winproc16_array[index] == func) goto done;
198 if (winproc16_used >= MAX_WINPROCS16)
200 FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
201 return NULL;
203 winproc16_array[winproc16_used++] = func;
205 done:
206 ret = (WNDPROC)(ULONG_PTR)((index + MAX_WINPROCS32) | (WINPROC_HANDLE << 16));
207 TRACE( "returning %p for %p/16-bit (%d/%d used)\n",
208 ret, func, winproc16_used, MAX_WINPROCS16 );
209 return ret;
212 /**********************************************************************
213 * WINPROC_GetProc16
215 * Get a window procedure pointer that can be passed to the Windows program.
217 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
219 WNDPROC winproc = wow_handlers32.alloc_winproc( proc, unicode );
221 if ((ULONG_PTR)winproc >> 16 != WINPROC_HANDLE) return (WNDPROC16)winproc;
222 return alloc_win16_thunk( winproc );
225 /* call a 16-bit window procedure */
226 static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
227 LRESULT *result, void *arg )
229 DPI_AWARENESS_CONTEXT awareness;
230 WNDPROC16 func = arg;
231 int index = winproc_to_index( func );
232 CONTEXT context;
233 size_t size = 0;
234 struct
236 WORD params[5];
237 union
239 CREATESTRUCT16 cs16;
240 DRAWITEMSTRUCT16 dis16;
241 COMPAREITEMSTRUCT16 cis16;
242 } u;
243 } args;
245 if (index >= MAX_WINPROCS32) func = winproc16_array[index - MAX_WINPROCS32];
247 /* Window procedures want ax = hInstance, ds = es = ss */
249 memset(&context, 0, sizeof(context));
250 context.SegDs = context.SegEs = CURRENT_SS;
251 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
252 context.SegCs = SELECTOROF(func);
253 context.Eip = OFFSETOF(func);
254 context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME, bp);
256 if (lParam)
258 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
259 work if structures passed in lParam are placed in the stack/data
260 segment. Programmers easily make the mistake of converting lParam
261 to a near rather than a far pointer, since Windows apparently
262 allows this. We copy the structures to the 16 bit stack; this is
263 ugly but makes these programs work. */
264 switch (msg)
266 case WM_CREATE:
267 case WM_NCCREATE:
268 size = sizeof(CREATESTRUCT16); break;
269 case WM_DRAWITEM:
270 size = sizeof(DRAWITEMSTRUCT16); break;
271 case WM_COMPAREITEM:
272 size = sizeof(COMPAREITEMSTRUCT16); break;
274 if (size)
276 memcpy( &args.u, MapSL(lParam), size );
277 lParam = MAKESEGPTR( CURRENT_SS, CURRENT_SP - size );
281 awareness = SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( HWND_32(hwnd) ));
282 args.params[4] = hwnd;
283 args.params[3] = msg;
284 args.params[2] = wParam;
285 args.params[1] = HIWORD(lParam);
286 args.params[0] = LOWORD(lParam);
287 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
288 *result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
289 SetThreadDpiAwarenessContext( awareness );
290 return *result;
293 static LRESULT call_dialog_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
294 LRESULT *result, void *arg )
296 LRESULT ret = call_window_proc16( hwnd, msg, wp, lp, result, arg );
297 *result = GetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT );
298 return LOWORD(ret);
301 static LRESULT call_window_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
302 LRESULT *result, void *arg )
304 return WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wp, lp, result, arg );
307 static LRESULT call_dialog_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
308 LRESULT *result, void *arg )
310 return WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wp, lp, result, arg );
315 /**********************************************************************
316 * Support for Edit word break proc thunks
319 #define MAX_THUNKS 32
321 #include <pshpack1.h>
322 static struct word_break_thunk
324 BYTE popl_eax; /* popl %eax (return address) */
325 BYTE pushl_proc16; /* pushl proc16 */
326 EDITWORDBREAKPROC16 proc16;
327 BYTE pushl_eax; /* pushl %eax */
328 BYTE jmp; /* ljmp call_word_break_proc16 */
329 DWORD callback;
330 } *word_break_thunks;
331 #include <poppack.h>
333 /**********************************************************************
334 * call_word_break_proc16
336 static INT16 CALLBACK call_word_break_proc16( SEGPTR proc16, LPSTR text, INT index, INT count, INT action )
338 SEGPTR segptr;
339 WORD args[5];
340 DWORD result;
342 segptr = MapLS( text );
343 args[4] = SELECTOROF(segptr);
344 args[3] = OFFSETOF(segptr);
345 args[2] = index;
346 args[1] = count;
347 args[0] = action;
348 WOWCallback16Ex( proc16, WCB16_PASCAL, sizeof(args), args, &result );
349 UnMapLS( segptr );
350 return LOWORD(result);
353 /******************************************************************
354 * add_word_break_thunk
356 static struct word_break_thunk *add_word_break_thunk( EDITWORDBREAKPROC16 proc16 )
358 struct word_break_thunk *thunk;
360 if (!word_break_thunks)
362 word_break_thunks = VirtualAlloc( NULL, MAX_THUNKS * sizeof(*thunk),
363 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
364 if (!word_break_thunks) return NULL;
366 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
368 thunk->popl_eax = 0x58; /* popl %eax */
369 thunk->pushl_proc16 = 0x68; /* pushl proc16 */
370 thunk->pushl_eax = 0x50; /* pushl %eax */
371 thunk->jmp = 0xe9; /* jmp call_word_break_proc16 */
372 thunk->callback = (char *)call_word_break_proc16 - (char *)(&thunk->callback + 1);
375 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
376 if (thunk->proc16 == proc16) return thunk;
378 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
380 if (thunk->proc16) continue;
381 thunk->proc16 = proc16;
382 return thunk;
384 FIXME("Out of word break thunks\n");
385 return NULL;
388 /******************************************************************
389 * get_word_break_thunk
391 static EDITWORDBREAKPROC16 get_word_break_thunk( EDITWORDBREAKPROCA proc )
393 struct word_break_thunk *thunk = (struct word_break_thunk *)proc;
394 if (word_break_thunks && thunk >= word_break_thunks && thunk < &word_break_thunks[MAX_THUNKS])
395 return thunk->proc16;
396 return NULL;
400 /***********************************************************************
401 * Support for 16<->32 message mapping
404 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
406 if (size >= need) return static_buffer;
407 return HeapAlloc( GetProcessHeap(), 0, need );
410 static inline void free_buffer( void *static_buffer, void *buffer )
412 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
415 static void RECT16to32( const RECT16 *from, RECT *to )
417 to->left = from->left;
418 to->top = from->top;
419 to->right = from->right;
420 to->bottom = from->bottom;
423 static void RECT32to16( const RECT *from, RECT16 *to )
425 to->left = from->left;
426 to->top = from->top;
427 to->right = from->right;
428 to->bottom = from->bottom;
431 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
433 to->ptReserved.x = from->ptReserved.x;
434 to->ptReserved.y = from->ptReserved.y;
435 to->ptMaxSize.x = from->ptMaxSize.x;
436 to->ptMaxSize.y = from->ptMaxSize.y;
437 to->ptMaxPosition.x = from->ptMaxPosition.x;
438 to->ptMaxPosition.y = from->ptMaxPosition.y;
439 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
440 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
441 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
442 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
445 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
447 to->ptReserved.x = from->ptReserved.x;
448 to->ptReserved.y = from->ptReserved.y;
449 to->ptMaxSize.x = from->ptMaxSize.x;
450 to->ptMaxSize.y = from->ptMaxSize.y;
451 to->ptMaxPosition.x = from->ptMaxPosition.x;
452 to->ptMaxPosition.y = from->ptMaxPosition.y;
453 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
454 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
455 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
456 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
459 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
461 to->hwnd = HWND_16(from->hwnd);
462 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
463 to->x = from->x;
464 to->y = from->y;
465 to->cx = from->cx;
466 to->cy = from->cy;
467 to->flags = from->flags;
470 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
472 to->hwnd = WIN_Handle32(from->hwnd);
473 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
474 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
475 to->x = from->x;
476 to->y = from->y;
477 to->cx = from->cx;
478 to->cy = from->cy;
479 to->flags = from->flags;
482 /* The strings are not copied */
483 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
485 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
486 to->hInstance = HINSTANCE_16(from->hInstance);
487 to->hMenu = HMENU_16(from->hMenu);
488 to->hwndParent = HWND_16(from->hwndParent);
489 to->cy = from->cy;
490 to->cx = from->cx;
491 to->y = from->y;
492 to->x = from->x;
493 to->style = from->style;
494 to->dwExStyle = from->dwExStyle;
497 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
500 to->lpCreateParams = (LPVOID)from->lpCreateParams;
501 to->hInstance = HINSTANCE_32(from->hInstance);
502 to->hMenu = HMENU_32(from->hMenu);
503 to->hwndParent = WIN_Handle32(from->hwndParent);
504 to->cy = from->cy;
505 to->cx = from->cx;
506 to->y = from->y;
507 to->x = from->x;
508 to->style = from->style;
509 to->dwExStyle = from->dwExStyle;
510 to->lpszName = MapSL(from->lpszName);
511 to->lpszClass = MapSL(from->lpszClass);
514 /* The strings are not copied */
515 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
517 to->hOwner = HINSTANCE_16(from->hOwner);
518 to->x = from->x;
519 to->y = from->y;
520 to->cx = from->cx;
521 to->cy = from->cy;
522 to->style = from->style;
523 to->lParam = from->lParam;
526 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
528 to->hOwner = HINSTANCE_32(from->hOwner);
529 to->x = from->x;
530 to->y = from->y;
531 to->cx = from->cx;
532 to->cy = from->cy;
533 to->style = from->style;
534 to->lParam = from->lParam;
535 to->szTitle = MapSL(from->szTitle);
536 to->szClass = MapSL(from->szClass);
539 static UINT_PTR convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
541 HANDLE dst;
542 UINT sz = GlobalSize16(src);
543 LPSTR ptr16, ptr32;
545 if (!(dst = GlobalAlloc(flags, sz)))
546 return 0;
547 ptr16 = GlobalLock16(src);
548 ptr32 = GlobalLock(dst);
549 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
550 GlobalUnlock16(src);
551 GlobalUnlock(dst);
553 return (UINT_PTR)dst;
556 static HANDLE16 convert_handle_32_to_16(UINT_PTR src, unsigned int flags)
558 HANDLE16 dst;
559 UINT sz = GlobalSize((HANDLE)src);
560 LPSTR ptr16, ptr32;
562 if (!(dst = GlobalAlloc16(flags, sz)))
563 return 0;
564 ptr32 = GlobalLock((HANDLE)src);
565 ptr16 = GlobalLock16(dst);
566 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
567 GlobalUnlock((HANDLE)src);
568 GlobalUnlock16(dst);
570 return dst;
573 static BOOL is_old_app( HWND hwnd )
575 HINSTANCE inst = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
576 return inst && !((ULONG_PTR)inst >> 16) && (GetExpWinVer16(LOWORD(inst)) & 0xFF00) == 0x0300;
579 static int find_sub_menu( HMENU *hmenu, HMENU16 target )
581 int i, pos, count = GetMenuItemCount( *hmenu );
583 for (i = 0; i < count; i++)
585 HMENU sub = GetSubMenu( *hmenu, i );
586 if (!sub) continue;
587 if (HMENU_16(sub) == target) return i;
588 if ((pos = find_sub_menu( &sub, target )) != -1)
590 *hmenu = sub;
591 return pos;
594 return -1;
597 /**********************************************************************
598 * WINPROC_CallProc16To32A
600 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
601 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
603 LRESULT ret = 0;
604 HWND hwnd32 = WIN_Handle32( hwnd );
606 switch(msg)
608 case WM_NCCREATE:
609 case WM_CREATE:
611 CREATESTRUCT16 *cs16 = MapSL(lParam);
612 CREATESTRUCTA cs;
613 MDICREATESTRUCTA mdi_cs;
614 SEGPTR mdi_cs_segptr = 0;
616 CREATESTRUCT16to32A( cs16, &cs );
617 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
619 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
620 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
621 cs.lpCreateParams = &mdi_cs;
622 mdi_cs_segptr = cs16->lpCreateParams;
624 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
625 CREATESTRUCT32Ato16( &cs, cs16 );
626 if (mdi_cs_segptr)
628 MDICREATESTRUCT32Ato16( &mdi_cs, MapSL( mdi_cs_segptr ) );
629 cs16->lpCreateParams = mdi_cs_segptr;
632 break;
633 case WM_MDICREATE:
635 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
636 MDICREATESTRUCTA cs;
638 MDICREATESTRUCT16to32A( cs16, &cs );
639 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
640 MDICREATESTRUCT32Ato16( &cs, cs16 );
642 break;
643 case WM_MDIACTIVATE:
644 if (lParam)
645 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
646 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
647 else /* message sent to MDI client */
648 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
649 break;
650 case WM_MDIGETACTIVE:
652 BOOL maximized = FALSE;
653 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
654 *result = MAKELRESULT( LOWORD(*result), maximized );
656 break;
657 case WM_MDISETMENU:
658 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
659 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
660 result, arg );
661 break;
662 case WM_GETMINMAXINFO:
664 MINMAXINFO16 *mmi16 = MapSL(lParam);
665 MINMAXINFO mmi;
667 MINMAXINFO16to32( mmi16, &mmi );
668 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
669 MINMAXINFO32to16( &mmi, mmi16 );
671 break;
672 case WM_WINDOWPOSCHANGING:
673 case WM_WINDOWPOSCHANGED:
675 WINDOWPOS16 *winpos16 = MapSL(lParam);
676 WINDOWPOS winpos;
678 WINDOWPOS16to32( winpos16, &winpos );
679 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
680 WINDOWPOS32to16( &winpos, winpos16 );
682 break;
683 case WM_NCCALCSIZE:
685 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
686 NCCALCSIZE_PARAMS nc;
687 WINDOWPOS winpos;
689 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
690 if (wParam)
692 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
693 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
694 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
695 nc.lppos = &winpos;
697 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
698 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
699 if (wParam)
701 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
702 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
703 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
706 break;
707 case WM_COMPAREITEM:
709 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
710 COMPAREITEMSTRUCT cis;
711 cis.CtlType = cis16->CtlType;
712 cis.CtlID = cis16->CtlID;
713 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
714 cis.itemID1 = cis16->itemID1;
715 cis.itemData1 = cis16->itemData1;
716 cis.itemID2 = cis16->itemID2;
717 cis.itemData2 = cis16->itemData2;
718 cis.dwLocaleId = 0; /* FIXME */
719 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
721 break;
722 case WM_DELETEITEM:
724 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
725 DELETEITEMSTRUCT dis;
726 dis.CtlType = dis16->CtlType;
727 dis.CtlID = dis16->CtlID;
728 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
729 dis.itemData = dis16->itemData;
730 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
732 break;
733 case WM_MEASUREITEM:
735 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
736 MEASUREITEMSTRUCT mis;
737 mis.CtlType = mis16->CtlType;
738 mis.CtlID = mis16->CtlID;
739 mis.itemID = mis16->itemID;
740 mis.itemWidth = mis16->itemWidth;
741 mis.itemHeight = mis16->itemHeight;
742 mis.itemData = mis16->itemData;
743 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
744 mis16->itemWidth = (UINT16)mis.itemWidth;
745 mis16->itemHeight = (UINT16)mis.itemHeight;
747 break;
748 case WM_DRAWITEM:
750 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
751 DRAWITEMSTRUCT dis;
752 dis.CtlType = dis16->CtlType;
753 dis.CtlID = dis16->CtlID;
754 dis.itemID = dis16->itemID;
755 dis.itemAction = dis16->itemAction;
756 dis.itemState = dis16->itemState;
757 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
758 : WIN_Handle32( dis16->hwndItem );
759 dis.hDC = HDC_32(dis16->hDC);
760 dis.itemData = dis16->itemData;
761 dis.rcItem.left = dis16->rcItem.left;
762 dis.rcItem.top = dis16->rcItem.top;
763 dis.rcItem.right = dis16->rcItem.right;
764 dis.rcItem.bottom = dis16->rcItem.bottom;
765 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
767 break;
768 case WM_COPYDATA:
770 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
771 COPYDATASTRUCT cds;
772 cds.dwData = cds16->dwData;
773 cds.cbData = cds16->cbData;
774 cds.lpData = MapSL(cds16->lpData);
775 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
777 break;
778 case WM_GETDLGCODE:
779 if (lParam)
781 MSG16 *msg16 = MapSL(lParam);
782 MSG msg32;
783 msg32.hwnd = WIN_Handle32( msg16->hwnd );
784 msg32.message = msg16->message;
785 msg32.wParam = msg16->wParam;
786 msg32.lParam = msg16->lParam;
787 msg32.time = msg16->time;
788 msg32.pt.x = msg16->pt.x;
789 msg32.pt.y = msg16->pt.y;
790 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
792 else
793 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
794 break;
795 case WM_NEXTMENU:
797 MDINEXTMENU next;
798 next.hmenuIn = (HMENU)lParam;
799 next.hmenuNext = 0;
800 next.hwndNext = 0;
801 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
802 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
804 break;
805 case WM_ACTIVATE:
806 case WM_CHARTOITEM:
807 case WM_COMMAND:
808 case WM_VKEYTOITEM:
809 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
810 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
811 break;
812 case WM_HSCROLL:
813 case WM_VSCROLL:
814 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
815 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
816 break;
817 case WM_CTLCOLOR:
818 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
819 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
820 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
821 result, arg );
822 break;
823 case WM_GETTEXT:
824 case WM_SETTEXT:
825 case WM_WININICHANGE:
826 case WM_DEVMODECHANGE:
827 case WM_ASKCBFORMATNAME:
828 case WM_NOTIFY:
829 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
830 break;
831 case WM_MENUCHAR:
832 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
833 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
834 break;
835 case WM_MENUSELECT:
836 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
838 HMENU hmenu = HMENU_32(HIWORD(lParam));
839 int pos = find_sub_menu( &hmenu, wParam );
840 if (pos == -1) pos = 0;
841 wParam = pos;
843 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
844 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
845 break;
846 case WM_PARENTNOTIFY:
847 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
848 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
849 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
850 else
851 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
852 break;
853 case WM_ACTIVATEAPP:
854 /* We need this when SetActiveWindow sends a Sendmessage16() to
855 * a 32-bit window. Might be superfluous with 32-bit interprocess
856 * message queues. */
857 if (lParam) lParam = HTASK_32(lParam);
858 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
859 break;
860 case WM_DDE_INITIATE:
861 case WM_DDE_TERMINATE:
862 case WM_DDE_UNADVISE:
863 case WM_DDE_REQUEST:
864 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
865 break;
866 case WM_DDE_ADVISE:
867 case WM_DDE_DATA:
868 case WM_DDE_POKE:
870 HANDLE16 lo16 = LOWORD(lParam);
871 UINT_PTR lo32 = 0;
872 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
873 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
874 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
876 break; /* FIXME don't know how to free allocated memory (handle) !! */
877 case WM_DDE_ACK:
879 UINT_PTR lo = LOWORD(lParam);
880 UINT_PTR hi = HIWORD(lParam);
881 int flag = 0;
882 char buf[2];
884 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
885 if (GlobalSize16(hi) != 0) flag |= 2;
886 switch (flag)
888 case 0:
889 if (hi)
891 WARN("DDE_ACK: neither atom nor handle!!!\n");
892 hi = 0;
894 break;
895 case 1:
896 break; /* atom, nothing to do */
897 case 3:
898 WARN("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
899 /* fall through */
900 case 2:
901 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
902 break;
904 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
905 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
907 break; /* FIXME don't know how to free allocated memory (handle) !! */
908 case WM_DDE_EXECUTE:
909 lParam = convert_handle_16_to_32( HIWORD(lParam), GMEM_DDESHARE );
910 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
911 break; /* FIXME don't know how to free allocated memory (handle) !! */
912 case WM_PAINTCLIPBOARD:
913 case WM_SIZECLIPBOARD:
914 FIXME_(msg)( "message %04x needs translation\n", msg );
915 break;
916 case WM_ERASEBKGND:
917 ret = callback( hwnd32, msg, (WPARAM)HDC_32(wParam), lParam, result, arg );
918 break;
919 default:
920 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
921 break;
923 return ret;
927 /**********************************************************************
928 * WINPROC_CallProc32ATo16
930 * Call a 16-bit window procedure, translating the 32-bit args.
932 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
933 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
935 LRESULT ret = 0;
937 switch(msg)
939 case WM_NCCREATE:
940 case WM_CREATE:
942 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
943 CREATESTRUCT16 cs;
944 MDICREATESTRUCT16 mdi_cs16;
945 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
947 CREATESTRUCT32Ato16( cs32, &cs );
948 cs.lpszName = MapLS( cs32->lpszName );
949 cs.lpszClass = MapLS( cs32->lpszClass );
951 if (mdi_child)
953 MDICREATESTRUCTA *mdi_cs = cs32->lpCreateParams;
954 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
955 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
956 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
957 cs.lpCreateParams = MapLS( &mdi_cs16 );
959 lParam = MapLS( &cs );
960 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
961 UnMapLS( lParam );
962 UnMapLS( cs.lpszName );
963 UnMapLS( cs.lpszClass );
964 if (mdi_child)
966 UnMapLS( cs.lpCreateParams );
967 UnMapLS( mdi_cs16.szTitle );
968 UnMapLS( mdi_cs16.szClass );
971 break;
972 case WM_MDICREATE:
974 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
975 MDICREATESTRUCT16 cs;
977 MDICREATESTRUCT32Ato16( cs32, &cs );
978 cs.szTitle = MapLS( cs32->szTitle );
979 cs.szClass = MapLS( cs32->szClass );
980 lParam = MapLS( &cs );
981 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
982 UnMapLS( lParam );
983 UnMapLS( cs.szTitle );
984 UnMapLS( cs.szClass );
986 break;
987 case WM_MDIACTIVATE:
988 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
989 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
990 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
991 else
992 ret = callback( HWND_16(hwnd), msg, HWND_16( wParam ), 0, result, arg );
993 break;
994 case WM_MDIGETACTIVE:
995 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
996 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
997 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
998 break;
999 case WM_MDISETMENU:
1000 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
1001 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
1002 break;
1003 case WM_GETMINMAXINFO:
1005 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
1006 MINMAXINFO16 mmi;
1008 MINMAXINFO32to16( mmi32, &mmi );
1009 lParam = MapLS( &mmi );
1010 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1011 UnMapLS( lParam );
1012 MINMAXINFO16to32( &mmi, mmi32 );
1014 break;
1015 case WM_NCCALCSIZE:
1017 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
1018 NCCALCSIZE_PARAMS16 nc;
1019 WINDOWPOS16 winpos;
1021 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
1022 if (wParam)
1024 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
1025 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
1026 WINDOWPOS32to16( nc32->lppos, &winpos );
1027 nc.lppos = MapLS( &winpos );
1029 lParam = MapLS( &nc );
1030 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1031 UnMapLS( lParam );
1032 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
1033 if (wParam)
1035 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
1036 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
1037 WINDOWPOS16to32( &winpos, nc32->lppos );
1038 UnMapLS( nc.lppos );
1041 break;
1042 case WM_WINDOWPOSCHANGING:
1043 case WM_WINDOWPOSCHANGED:
1045 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
1046 WINDOWPOS16 winpos;
1048 WINDOWPOS32to16( winpos32, &winpos );
1049 lParam = MapLS( &winpos );
1050 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1051 UnMapLS( lParam );
1052 WINDOWPOS16to32( &winpos, winpos32 );
1054 break;
1055 case WM_COMPAREITEM:
1057 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
1058 COMPAREITEMSTRUCT16 cis;
1059 cis.CtlType = cis32->CtlType;
1060 cis.CtlID = cis32->CtlID;
1061 cis.hwndItem = HWND_16( cis32->hwndItem );
1062 cis.itemID1 = cis32->itemID1;
1063 cis.itemData1 = cis32->itemData1;
1064 cis.itemID2 = cis32->itemID2;
1065 cis.itemData2 = cis32->itemData2;
1066 lParam = MapLS( &cis );
1067 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1068 UnMapLS( lParam );
1070 break;
1071 case WM_DELETEITEM:
1073 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
1074 DELETEITEMSTRUCT16 dis;
1075 dis.CtlType = dis32->CtlType;
1076 dis.CtlID = dis32->CtlID;
1077 dis.itemID = dis32->itemID;
1078 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1079 : HWND_16( dis32->hwndItem );
1080 dis.itemData = dis32->itemData;
1081 lParam = MapLS( &dis );
1082 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1083 UnMapLS( lParam );
1085 break;
1086 case WM_DRAWITEM:
1088 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
1089 DRAWITEMSTRUCT16 dis;
1090 dis.CtlType = dis32->CtlType;
1091 dis.CtlID = dis32->CtlID;
1092 dis.itemID = dis32->itemID;
1093 dis.itemAction = dis32->itemAction;
1094 dis.itemState = dis32->itemState;
1095 dis.hwndItem = HWND_16( dis32->hwndItem );
1096 dis.hDC = HDC_16(dis32->hDC);
1097 dis.itemData = dis32->itemData;
1098 dis.rcItem.left = dis32->rcItem.left;
1099 dis.rcItem.top = dis32->rcItem.top;
1100 dis.rcItem.right = dis32->rcItem.right;
1101 dis.rcItem.bottom = dis32->rcItem.bottom;
1102 lParam = MapLS( &dis );
1103 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1104 UnMapLS( lParam );
1106 break;
1107 case WM_MEASUREITEM:
1109 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
1110 MEASUREITEMSTRUCT16 mis;
1111 mis.CtlType = mis32->CtlType;
1112 mis.CtlID = mis32->CtlID;
1113 mis.itemID = mis32->itemID;
1114 mis.itemWidth = mis32->itemWidth;
1115 mis.itemHeight = mis32->itemHeight;
1116 mis.itemData = mis32->itemData;
1117 lParam = MapLS( &mis );
1118 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1119 UnMapLS( lParam );
1120 mis32->itemWidth = mis.itemWidth;
1121 mis32->itemHeight = mis.itemHeight;
1123 break;
1124 case WM_COPYDATA:
1126 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
1127 COPYDATASTRUCT16 cds;
1129 cds.dwData = cds32->dwData;
1130 cds.cbData = cds32->cbData;
1131 cds.lpData = MapLS( cds32->lpData );
1132 lParam = MapLS( &cds );
1133 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1134 UnMapLS( lParam );
1135 UnMapLS( cds.lpData );
1137 break;
1138 case WM_GETDLGCODE:
1139 if (lParam)
1141 MSG *msg32 = (MSG *)lParam;
1142 MSG16 msg16;
1144 msg16.hwnd = HWND_16( msg32->hwnd );
1145 msg16.message = msg32->message;
1146 msg16.wParam = msg32->wParam;
1147 msg16.lParam = msg32->lParam;
1148 msg16.time = msg32->time;
1149 msg16.pt.x = msg32->pt.x;
1150 msg16.pt.y = msg32->pt.y;
1151 lParam = MapLS( &msg16 );
1152 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1153 UnMapLS( lParam );
1155 else
1156 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1157 break;
1158 case WM_NEXTMENU:
1160 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1161 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
1162 next->hmenuNext = HMENU_32( LOWORD(*result) );
1163 next->hwndNext = WIN_Handle32( HIWORD(*result) );
1164 *result = 0;
1166 break;
1167 case WM_GETTEXT:
1168 case WM_ASKCBFORMATNAME:
1169 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
1170 /* fall through */
1171 case WM_NOTIFY:
1172 case WM_SETTEXT:
1173 case WM_WININICHANGE:
1174 case WM_DEVMODECHANGE:
1175 lParam = MapLS( (void *)lParam );
1176 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1177 UnMapLS( lParam );
1178 break;
1179 case WM_ACTIVATE:
1180 case WM_CHARTOITEM:
1181 case WM_COMMAND:
1182 case WM_VKEYTOITEM:
1183 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ),
1184 result, arg );
1185 break;
1186 case WM_HSCROLL:
1187 case WM_VSCROLL:
1188 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( HIWORD(wParam), (HWND16)lParam ),
1189 result, arg );
1190 break;
1191 case WM_CTLCOLORMSGBOX:
1192 case WM_CTLCOLOREDIT:
1193 case WM_CTLCOLORLISTBOX:
1194 case WM_CTLCOLORBTN:
1195 case WM_CTLCOLORDLG:
1196 case WM_CTLCOLORSCROLLBAR:
1197 case WM_CTLCOLORSTATIC:
1198 ret = callback( HWND_16(hwnd), WM_CTLCOLOR, wParam,
1199 MAKELPARAM( (HWND16)lParam, msg - WM_CTLCOLORMSGBOX ), result, arg );
1200 break;
1201 case WM_MENUSELECT:
1202 if(HIWORD(wParam) & MF_POPUP)
1204 HMENU hmenu;
1205 if ((HIWORD(wParam) != 0xffff) || lParam)
1207 if ((hmenu = GetSubMenu( (HMENU)lParam, LOWORD(wParam) )))
1209 ret = callback( HWND_16(hwnd), msg, HMENU_16(hmenu),
1210 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1211 break;
1215 /* fall through */
1216 case WM_MENUCHAR:
1217 ret = callback( HWND_16(hwnd), msg, wParam,
1218 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1219 break;
1220 case WM_PARENTNOTIFY:
1221 if ((LOWORD(wParam) == WM_CREATE) || (LOWORD(wParam) == WM_DESTROY))
1222 ret = callback( HWND_16(hwnd), msg, wParam,
1223 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ), result, arg );
1224 else
1225 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1226 break;
1227 case WM_ACTIVATEAPP:
1228 ret = callback( HWND_16(hwnd), msg, wParam, HTASK_16( lParam ), result, arg );
1229 break;
1230 case WM_PAINT:
1231 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
1232 ret = callback( HWND_16(hwnd), WM_PAINTICON, 1, lParam, result, arg );
1233 else
1234 ret = callback( HWND_16(hwnd), WM_PAINT, wParam, lParam, result, arg );
1235 break;
1236 case WM_ERASEBKGND:
1237 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON )) msg = WM_ICONERASEBKGND;
1238 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1239 break;
1240 case WM_DDE_INITIATE:
1241 case WM_DDE_TERMINATE:
1242 case WM_DDE_UNADVISE:
1243 case WM_DDE_REQUEST:
1244 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam), lParam, result, arg );
1245 break;
1246 case WM_DDE_ADVISE:
1247 case WM_DDE_DATA:
1248 case WM_DDE_POKE:
1250 UINT_PTR lo32, hi;
1251 HANDLE16 lo16 = 0;
1253 UnpackDDElParam( msg, lParam, &lo32, &hi );
1254 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
1255 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1256 MAKELPARAM(lo16, hi), result, arg );
1258 break; /* FIXME don't know how to free allocated memory (handle) !! */
1259 case WM_DDE_ACK:
1261 UINT_PTR lo, hi;
1262 int flag = 0;
1263 char buf[2];
1265 UnpackDDElParam( msg, lParam, &lo, &hi );
1267 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
1268 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
1269 switch (flag)
1271 case 0:
1272 if (hi)
1274 WARN("DDE_ACK: neither atom nor handle!!!\n");
1275 hi = 0;
1277 break;
1278 case 1:
1279 break; /* atom, nothing to do */
1280 case 3:
1281 WARN("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
1282 /* fall through */
1283 case 2:
1284 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
1285 break;
1287 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1288 MAKELPARAM(lo, hi), result, arg );
1290 break; /* FIXME don't know how to free allocated memory (handle) !! */
1291 case WM_DDE_EXECUTE:
1292 lParam = MAKELPARAM( 0, convert_handle_32_to_16( lParam, GMEM_DDESHARE ));
1293 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1294 break; /* FIXME don't know how to free allocated memory (handle) !! */
1295 case SBM_SETRANGE:
1296 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
1297 break;
1298 case SBM_GETRANGE:
1299 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
1300 *(LPINT)wParam = LOWORD(*result);
1301 *(LPINT)lParam = HIWORD(*result);
1302 break;
1303 case BM_GETCHECK:
1304 case BM_SETCHECK:
1305 case BM_GETSTATE:
1306 case BM_SETSTATE:
1307 case BM_SETSTYLE:
1308 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
1309 break;
1310 case EM_GETSEL:
1311 case EM_GETRECT:
1312 case EM_SETRECT:
1313 case EM_SETRECTNP:
1314 case EM_SCROLL:
1315 case EM_LINESCROLL:
1316 case EM_SCROLLCARET:
1317 case EM_GETMODIFY:
1318 case EM_SETMODIFY:
1319 case EM_GETLINECOUNT:
1320 case EM_LINEINDEX:
1321 case EM_SETHANDLE:
1322 case EM_GETHANDLE:
1323 case EM_GETTHUMB:
1324 case EM_LINELENGTH:
1325 case EM_REPLACESEL:
1326 case EM_GETLINE:
1327 case EM_LIMITTEXT:
1328 case EM_CANUNDO:
1329 case EM_UNDO:
1330 case EM_FMTLINES:
1331 case EM_LINEFROMCHAR:
1332 case EM_SETTABSTOPS:
1333 case EM_SETPASSWORDCHAR:
1334 case EM_EMPTYUNDOBUFFER:
1335 case EM_GETFIRSTVISIBLELINE:
1336 case EM_SETREADONLY:
1337 case EM_SETWORDBREAKPROC:
1338 case EM_GETWORDBREAKPROC:
1339 case EM_GETPASSWORDCHAR:
1340 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
1341 break;
1342 case EM_SETSEL:
1343 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
1344 break;
1345 case LB_CARETOFF:
1346 case LB_CARETON:
1347 case LB_DELETESTRING:
1348 case LB_GETANCHORINDEX:
1349 case LB_GETCARETINDEX:
1350 case LB_GETCOUNT:
1351 case LB_GETCURSEL:
1352 case LB_GETHORIZONTALEXTENT:
1353 case LB_GETITEMDATA:
1354 case LB_GETITEMHEIGHT:
1355 case LB_GETSEL:
1356 case LB_GETSELCOUNT:
1357 case LB_GETTEXTLEN:
1358 case LB_GETTOPINDEX:
1359 case LB_RESETCONTENT:
1360 case LB_SELITEMRANGE:
1361 case LB_SELITEMRANGEEX:
1362 case LB_SETANCHORINDEX:
1363 case LB_SETCARETINDEX:
1364 case LB_SETCOLUMNWIDTH:
1365 case LB_SETCURSEL:
1366 case LB_SETHORIZONTALEXTENT:
1367 case LB_SETITEMDATA:
1368 case LB_SETITEMHEIGHT:
1369 case LB_SETSEL:
1370 case LB_SETTOPINDEX:
1371 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1372 break;
1373 case LB_ADDSTRING:
1374 case LB_FINDSTRING:
1375 case LB_FINDSTRINGEXACT:
1376 case LB_INSERTSTRING:
1377 case LB_SELECTSTRING:
1378 case LB_GETTEXT:
1379 case LB_DIR:
1380 case LB_ADDFILE:
1381 lParam = MapLS( (LPSTR)lParam );
1382 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1383 UnMapLS( lParam );
1384 break;
1385 case LB_GETSELITEMS:
1387 INT *items32 = (INT *)lParam;
1388 INT16 *items, buffer[512];
1389 unsigned int i;
1391 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1392 if (!(items = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1393 lParam = MapLS( items );
1394 ret = callback( HWND_16(hwnd), LB_GETSELITEMS16, wParam, lParam, result, arg );
1395 UnMapLS( lParam );
1396 for (i = 0; i < wParam; i++) items32[i] = items[i];
1397 free_buffer( buffer, items );
1399 break;
1400 case LB_SETTABSTOPS:
1401 if (wParam)
1403 INT *stops32 = (INT *)lParam;
1404 INT16 *stops, buffer[512];
1405 unsigned int i;
1407 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1408 if (!(stops = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1409 for (i = 0; i < wParam; i++) stops[i] = stops32[i];
1410 lParam = MapLS( stops );
1411 ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1412 UnMapLS( lParam );
1413 free_buffer( buffer, stops );
1415 else ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1416 break;
1417 case CB_DELETESTRING:
1418 case CB_GETCOUNT:
1419 case CB_GETLBTEXTLEN:
1420 case CB_LIMITTEXT:
1421 case CB_RESETCONTENT:
1422 case CB_SETEDITSEL:
1423 case CB_GETCURSEL:
1424 case CB_SETCURSEL:
1425 case CB_SHOWDROPDOWN:
1426 case CB_SETITEMDATA:
1427 case CB_SETITEMHEIGHT:
1428 case CB_GETITEMHEIGHT:
1429 case CB_SETEXTENDEDUI:
1430 case CB_GETEXTENDEDUI:
1431 case CB_GETDROPPEDSTATE:
1432 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1433 break;
1434 case CB_GETEDITSEL:
1435 ret = callback( HWND_16(hwnd), CB_GETEDITSEL16, wParam, lParam, result, arg );
1436 if (wParam) *((PUINT)(wParam)) = LOWORD(*result);
1437 if (lParam) *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: subtract 1? */
1438 break;
1439 case CB_ADDSTRING:
1440 case CB_FINDSTRING:
1441 case CB_FINDSTRINGEXACT:
1442 case CB_INSERTSTRING:
1443 case CB_SELECTSTRING:
1444 case CB_DIR:
1445 case CB_GETLBTEXT:
1446 lParam = MapLS( (LPSTR)lParam );
1447 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1448 UnMapLS( lParam );
1449 break;
1450 case LB_GETITEMRECT:
1451 case CB_GETDROPPEDCONTROLRECT:
1453 RECT *r32 = (RECT *)lParam;
1454 RECT16 rect;
1455 lParam = MapLS( &rect );
1456 ret = callback( HWND_16(hwnd),
1457 (msg == LB_GETITEMRECT) ? LB_GETITEMRECT16 : CB_GETDROPPEDCONTROLRECT16,
1458 wParam, lParam, result, arg );
1459 UnMapLS( lParam );
1460 RECT16to32( &rect, r32 );
1462 break;
1463 case WM_PAINTCLIPBOARD:
1464 case WM_SIZECLIPBOARD:
1465 FIXME_(msg)( "message %04x needs translation\n", msg );
1466 break;
1467 /* the following messages should not be sent to 16-bit apps */
1468 case WM_SIZING:
1469 case WM_MOVING:
1470 case WM_CAPTURECHANGED:
1471 case WM_STYLECHANGING:
1472 case WM_STYLECHANGED:
1473 break;
1474 default:
1475 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1476 break;
1478 return ret;
1482 /***********************************************************************
1483 * SendMessage (USER.111)
1485 LRESULT WINAPI SendMessage16( HWND16 hwnd16, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1487 LRESULT result;
1488 HWND hwnd = WIN_Handle32( hwnd16 );
1490 if (hwnd != HWND_BROADCAST &&
1491 GetWindowThreadProcessId( hwnd, NULL ) == GetCurrentThreadId())
1493 /* call 16-bit window proc directly */
1494 WNDPROC16 winproc;
1496 /* first the WH_CALLWNDPROC hook */
1497 call_WH_CALLWNDPROC_hook( hwnd16, msg, wparam, lparam );
1499 if (!(winproc = (WNDPROC16)GetWindowLong16( hwnd16, GWLP_WNDPROC ))) return 0;
1501 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx\n", hwnd16, msg, wparam, lparam );
1502 result = CallWindowProc16( winproc, hwnd16, msg, wparam, lparam );
1503 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx returned %08lx\n",
1504 hwnd16, msg, wparam, lparam, result );
1506 else /* map to 32-bit unicode for inter-thread/process message */
1508 WINPROC_CallProc16To32A( send_message_callback, hwnd16, msg, wparam, lparam, &result, NULL );
1510 return result;
1514 /***********************************************************************
1515 * PostMessage (USER.110)
1517 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1519 LRESULT unused;
1520 return WINPROC_CallProc16To32A( post_message_callback, hwnd, msg, wparam, lparam, &unused, NULL );
1524 /***********************************************************************
1525 * PostAppMessage (USER.116)
1527 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1529 LRESULT unused;
1530 DWORD_PTR tid = HTASK_32( hTask );
1532 if (!tid) return FALSE;
1533 return WINPROC_CallProc16To32A( post_thread_message_callback, 0, msg, wparam, lparam,
1534 &unused, (void *)tid );
1538 /**********************************************************************
1539 * CallWindowProc (USER.122)
1541 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
1542 WPARAM16 wParam, LPARAM lParam )
1544 int index = winproc_to_index( func );
1545 LRESULT result;
1547 if (!func) return 0;
1549 if (index == -1 || index >= MAX_WINPROCS32)
1550 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
1551 else
1553 WNDPROC proc = (WNDPROC)func;
1554 if (thunk_array && thunk_array[index].proc) proc = thunk_array[index].proc;
1555 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1557 return result;
1561 /**********************************************************************
1562 * __wine_call_wndproc (USER.1010)
1564 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam, WNDPROC proc )
1566 LRESULT result;
1567 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1568 return result;
1572 /***********************************************************************
1573 * InSendMessage (USER.192)
1575 BOOL16 WINAPI InSendMessage16(void)
1577 return InSendMessage();
1581 /***********************************************************************
1582 * ReplyMessage (USER.115)
1584 void WINAPI ReplyMessage16( LRESULT result )
1586 ReplyMessage( result );
1590 /***********************************************************************
1591 * PeekMessage32 (USER.819)
1593 BOOL16 WINAPI PeekMessage32_16( MSG32_16 *msg16, HWND16 hwnd16,
1594 UINT16 first, UINT16 last, UINT16 flags,
1595 BOOL16 wHaveParamHigh )
1597 MSG msg;
1598 LRESULT unused;
1599 HWND hwnd = WIN_Handle32( hwnd16 );
1601 if(USER16_AlertableWait)
1602 MsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, MWMO_ALERTABLE );
1603 if (!PeekMessageA( &msg, hwnd, first, last, flags )) return FALSE;
1605 msg16->msg.time = msg.time;
1606 msg16->msg.pt.x = (INT16)msg.pt.x;
1607 msg16->msg.pt.y = (INT16)msg.pt.y;
1608 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1609 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1610 &unused, &msg16->msg );
1611 return TRUE;
1615 /***********************************************************************
1616 * DefWindowProc (USER.107)
1618 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1620 LRESULT result;
1621 WINPROC_CallProc16To32A( defwnd_proc_callback, hwnd16, msg, wParam, lParam, &result, 0 );
1622 return result;
1626 /***********************************************************************
1627 * DefDlgProc (USER.308)
1629 LRESULT WINAPI DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1631 LRESULT result;
1632 WINPROC_CallProc16To32A( defdlg_proc_callback, hwnd, msg, wParam, lParam, &result, 0 );
1633 return result;
1637 /***********************************************************************
1638 * PeekMessage (USER.109)
1640 BOOL16 WINAPI PeekMessage16( MSG16 *msg, HWND16 hwnd,
1641 UINT16 first, UINT16 last, UINT16 flags )
1643 return PeekMessage32_16( (MSG32_16 *)msg, hwnd, first, last, flags, FALSE );
1647 /***********************************************************************
1648 * GetMessage32 (USER.820)
1650 BOOL16 WINAPI GetMessage32_16( MSG32_16 *msg16, HWND16 hwnd16, UINT16 first,
1651 UINT16 last, BOOL16 wHaveParamHigh )
1653 MSG msg;
1654 LRESULT unused;
1655 HWND hwnd = WIN_Handle32( hwnd16 );
1657 if(USER16_AlertableWait)
1658 MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, 0, MWMO_ALERTABLE );
1659 GetMessageA( &msg, hwnd, first, last );
1660 msg16->msg.time = msg.time;
1661 msg16->msg.pt.x = (INT16)msg.pt.x;
1662 msg16->msg.pt.y = (INT16)msg.pt.y;
1663 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1664 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1665 &unused, &msg16->msg );
1667 TRACE( "message %04x, hwnd %p, filter(%04x - %04x)\n",
1668 msg16->msg.message, hwnd, first, last );
1670 return msg16->msg.message != WM_QUIT;
1674 /***********************************************************************
1675 * GetMessage (USER.108)
1677 BOOL16 WINAPI GetMessage16( MSG16 *msg, HWND16 hwnd, UINT16 first, UINT16 last )
1679 return GetMessage32_16( (MSG32_16 *)msg, hwnd, first, last, FALSE );
1683 /***********************************************************************
1684 * TranslateMessage32 (USER.821)
1686 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
1688 MSG msg32;
1690 msg32.hwnd = WIN_Handle32( msg->msg.hwnd );
1691 msg32.message = msg->msg.message;
1692 msg32.wParam = MAKEWPARAM( msg->msg.wParam, wHaveParamHigh ? msg->wParamHigh : 0 );
1693 msg32.lParam = msg->msg.lParam;
1694 return TranslateMessage( &msg32 );
1698 /***********************************************************************
1699 * TranslateMessage (USER.113)
1701 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1703 return TranslateMessage32_16( (const MSG32_16 *)msg, FALSE );
1707 /***********************************************************************
1708 * DispatchMessage (USER.114)
1710 LONG WINAPI DispatchMessage16( const MSG16* msg )
1712 WNDPROC16 winproc;
1713 LRESULT retval;
1715 /* Process timer messages */
1716 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1718 if (msg->lParam)
1719 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1720 msg->message, msg->wParam, GetTickCount() );
1723 if (!(winproc = (WNDPROC16)GetWindowLong16( msg->hwnd, GWLP_WNDPROC )))
1725 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1726 return 0;
1728 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx\n", msg->hwnd, msg->message, msg->wParam, msg->lParam );
1729 retval = CallWindowProc16( winproc, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1730 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx returned %08lx\n",
1731 msg->hwnd, msg->message, msg->wParam, msg->lParam, retval );
1732 return retval;
1736 /***********************************************************************
1737 * DispatchMessage32 (USER.822)
1739 LONG WINAPI DispatchMessage32_16( const MSG32_16 *msg16, BOOL16 wHaveParamHigh )
1741 if (wHaveParamHigh == FALSE)
1742 return DispatchMessage16( &msg16->msg );
1743 else
1745 MSG msg;
1747 msg.hwnd = WIN_Handle32( msg16->msg.hwnd );
1748 msg.message = msg16->msg.message;
1749 msg.wParam = MAKEWPARAM( msg16->msg.wParam, msg16->wParamHigh );
1750 msg.lParam = msg16->msg.lParam;
1751 msg.time = msg16->msg.time;
1752 msg.pt.x = msg16->msg.pt.x;
1753 msg.pt.y = msg16->msg.pt.y;
1754 return DispatchMessageA( &msg );
1759 /***********************************************************************
1760 * IsDialogMessage (USER.90)
1762 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, MSG16 *msg16 )
1764 MSG msg;
1765 HWND hwndDlg32;
1767 msg.hwnd = WIN_Handle32(msg16->hwnd);
1768 hwndDlg32 = WIN_Handle32(hwndDlg);
1770 switch(msg16->message)
1772 case WM_KEYDOWN:
1773 case WM_CHAR:
1774 case WM_SYSCHAR:
1775 msg.message = msg16->message;
1776 msg.wParam = msg16->wParam;
1777 msg.lParam = msg16->lParam;
1778 msg.time = msg16->time;
1779 msg.pt.x = msg16->pt.x;
1780 msg.pt.y = msg16->pt.y;
1781 return IsDialogMessageA( hwndDlg32, &msg );
1784 if ((hwndDlg32 != msg.hwnd) && !IsChild( hwndDlg32, msg.hwnd )) return FALSE;
1785 TranslateMessage16( msg16 );
1786 DispatchMessage16( msg16 );
1787 return TRUE;
1791 /***********************************************************************
1792 * MsgWaitForMultipleObjects (USER.640)
1794 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD count, const HANDLE *handles,
1795 BOOL wait_all, DWORD timeout, DWORD mask )
1797 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
1798 wait_all ? MWMO_WAITALL : 0 );
1802 /**********************************************************************
1803 * SetDoubleClickTime (USER.20)
1805 void WINAPI SetDoubleClickTime16( UINT16 interval )
1807 SetDoubleClickTime( interval );
1811 /**********************************************************************
1812 * GetDoubleClickTime (USER.21)
1814 UINT16 WINAPI GetDoubleClickTime16(void)
1816 return GetDoubleClickTime();
1820 /***********************************************************************
1821 * PostQuitMessage (USER.6)
1823 void WINAPI PostQuitMessage16( INT16 exitCode )
1825 PostQuitMessage( exitCode );
1829 /**********************************************************************
1830 * GetKeyState (USER.106)
1832 INT16 WINAPI GetKeyState16(INT16 vkey)
1834 return GetKeyState(vkey);
1838 /**********************************************************************
1839 * GetKeyboardState (USER.222)
1841 BOOL WINAPI GetKeyboardState16( LPBYTE state )
1843 return GetKeyboardState( state );
1847 /**********************************************************************
1848 * SetKeyboardState (USER.223)
1850 BOOL WINAPI SetKeyboardState16( LPBYTE state )
1852 return SetKeyboardState( state );
1856 /***********************************************************************
1857 * SetMessageQueue (USER.266)
1859 BOOL16 WINAPI SetMessageQueue16( INT16 size )
1861 return SetMessageQueue( size );
1865 /***********************************************************************
1866 * UserYield (USER.332)
1868 void WINAPI UserYield16(void)
1870 MSG msg;
1871 PeekMessageW( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
1875 /***********************************************************************
1876 * GetQueueStatus (USER.334)
1878 DWORD WINAPI GetQueueStatus16( UINT16 flags )
1880 return GetQueueStatus( flags );
1884 /***********************************************************************
1885 * GetInputState (USER.335)
1887 BOOL16 WINAPI GetInputState16(void)
1889 return GetInputState();
1893 /**********************************************************************
1894 * TranslateAccelerator (USER.178)
1896 INT16 WINAPI TranslateAccelerator16( HWND16 hwnd, HACCEL16 hAccel, LPMSG16 msg )
1898 MSG msg32;
1900 if (!msg) return 0;
1901 msg32.message = msg->message;
1902 /* msg32.hwnd not used */
1903 msg32.wParam = msg->wParam;
1904 msg32.lParam = msg->lParam;
1905 return TranslateAcceleratorW( WIN_Handle32(hwnd), HACCEL_32(hAccel), &msg32 );
1909 /**********************************************************************
1910 * TranslateMDISysAccel (USER.451)
1912 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1914 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1916 MSG msg32;
1917 msg32.hwnd = WIN_Handle32(msg->hwnd);
1918 msg32.message = msg->message;
1919 msg32.wParam = msg->wParam;
1920 msg32.lParam = msg->lParam;
1921 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1922 return TranslateMDISysAccel( WIN_Handle32(hwndClient), &msg32 );
1924 return 0;
1928 /***********************************************************************
1929 * button_proc16
1931 static LRESULT button_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
1933 static const UINT msg16_offset = BM_GETCHECK16 - BM_GETCHECK;
1935 switch (msg)
1937 case BM_GETCHECK16:
1938 case BM_SETCHECK16:
1939 case BM_GETSTATE16:
1940 case BM_SETSTATE16:
1941 case BM_SETSTYLE16:
1942 return wow_handlers32.button_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
1943 default:
1944 return wow_handlers32.button_proc( hwnd, msg, wParam, lParam, unicode );
1949 /***********************************************************************
1950 * combo_proc16
1952 static LRESULT combo_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
1954 static const UINT msg16_offset = CB_GETEDITSEL16 - CB_GETEDITSEL;
1956 switch (msg)
1958 case CB_INSERTSTRING16:
1959 case CB_SELECTSTRING16:
1960 case CB_FINDSTRING16:
1961 case CB_FINDSTRINGEXACT16:
1962 wParam = (INT)(INT16)wParam;
1963 /* fall through */
1964 case CB_ADDSTRING16:
1966 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
1967 if ((style & CBS_HASSTRINGS) || !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)))
1968 lParam = (LPARAM)MapSL(lParam);
1969 msg -= msg16_offset;
1970 break;
1972 case CB_SETITEMHEIGHT16:
1973 case CB_GETITEMHEIGHT16:
1974 case CB_SETCURSEL16:
1975 case CB_GETLBTEXTLEN16:
1976 case CB_GETITEMDATA16:
1977 case CB_SETITEMDATA16:
1978 wParam = (INT)(INT16)wParam; /* signed integer */
1979 msg -= msg16_offset;
1980 break;
1981 case CB_GETDROPPEDCONTROLRECT16:
1982 lParam = (LPARAM)MapSL(lParam);
1983 if (lParam)
1985 RECT r;
1986 RECT16 *r16 = (RECT16 *)lParam;
1987 wow_handlers32.combo_proc( hwnd, CB_GETDROPPEDCONTROLRECT, wParam, (LPARAM)&r, FALSE );
1988 r16->left = r.left;
1989 r16->top = r.top;
1990 r16->right = r.right;
1991 r16->bottom = r.bottom;
1993 return CB_OKAY;
1994 case CB_DIR16:
1995 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
1996 lParam = (LPARAM)MapSL(lParam);
1997 msg -= msg16_offset;
1998 break;
1999 case CB_GETLBTEXT16:
2000 wParam = (INT)(INT16)wParam;
2001 lParam = (LPARAM)MapSL(lParam);
2002 msg -= msg16_offset;
2003 break;
2004 case CB_GETEDITSEL16:
2005 wParam = lParam = 0; /* just in case */
2006 msg -= msg16_offset;
2007 break;
2008 case CB_LIMITTEXT16:
2009 case CB_SETEDITSEL16:
2010 case CB_DELETESTRING16:
2011 case CB_RESETCONTENT16:
2012 case CB_GETDROPPEDSTATE16:
2013 case CB_SHOWDROPDOWN16:
2014 case CB_GETCOUNT16:
2015 case CB_GETCURSEL16:
2016 case CB_SETEXTENDEDUI16:
2017 case CB_GETEXTENDEDUI16:
2018 msg -= msg16_offset;
2019 break;
2020 default:
2021 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, unicode );
2023 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, FALSE );
2026 /*********************************************************************
2027 * edit_lock_buffer (internal)
2029 * A 16 bit application might send an EM_GETHANDLE message and expect a HLOCAL16
2030 * (16 bit SEG:OFF handler). From that moment on we have to keep using this
2031 * 16 bit memory handler, because it is supposed to be valid at all times after
2032 * EM_GETHANDLE.
2033 * We create a HLOCAL16 buffer in edit_get_handle and copy the text from the
2034 * HLOCAL buffer, when needed
2038 #define GWW_HANDLE16 sizeof(void*)
2040 static void edit_lock_buffer( HWND hwnd )
2042 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2043 HANDLE16 oldDS;
2044 HLOCAL hloc32;
2045 UINT size;
2047 if (!hloc16) return;
2048 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2050 oldDS = CURRENT_DS;
2051 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2052 size = LocalSize16(hloc16);
2053 if (LocalReAlloc( hloc32, size, LMEM_MOVEABLE ))
2055 char *text = MapSL( LocalLock16( hloc16 ));
2056 char *dest = LocalLock( hloc32 );
2057 memcpy( dest, text, size );
2058 LocalUnlock( hloc32 );
2059 LocalUnlock16( hloc16 );
2061 CURRENT_DS = oldDS;
2064 static void edit_unlock_buffer( HWND hwnd )
2066 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2067 HANDLE16 oldDS;
2068 HLOCAL hloc32;
2069 UINT size;
2071 if (!hloc16) return;
2072 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2073 size = LocalSize( hloc32 );
2075 oldDS = CURRENT_DS;
2076 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2077 if (LocalReAlloc16( hloc16, size, LMEM_MOVEABLE ))
2079 char *text = LocalLock( hloc32 );
2080 char *dest = MapSL( LocalLock16( hloc16 ));
2081 memcpy( dest, text, size );
2082 LocalUnlock( hloc32 );
2083 LocalUnlock16( hloc16 );
2085 CURRENT_DS = oldDS;
2088 static HLOCAL16 edit_get_handle( HWND hwnd )
2090 CHAR *textA;
2091 UINT alloc_size;
2092 HLOCAL hloc;
2093 HANDLE16 oldDS;
2094 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2096 if (hloc16) return hloc16;
2098 if (!(hloc = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return 0;
2099 alloc_size = LocalSize( hloc );
2101 oldDS = CURRENT_DS;
2102 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2104 if (!LocalHeapSize16())
2106 if (!LocalInit16(CURRENT_DS, 0, GlobalSize16(CURRENT_DS)))
2108 ERR("could not initialize local heap\n");
2109 goto done;
2113 if (!(hloc16 = LocalAlloc16(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
2115 ERR("could not allocate new 16 bit buffer\n");
2116 goto done;
2119 if (!(textA = MapSL(LocalLock16( hloc16))))
2121 ERR("could not lock new 16 bit buffer\n");
2122 LocalFree16(hloc16);
2123 hloc16 = 0;
2124 goto done;
2126 memcpy( textA, LocalLock( hloc ), alloc_size );
2127 LocalUnlock( hloc );
2128 LocalUnlock16( hloc16 );
2129 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2131 done:
2132 CURRENT_DS = oldDS;
2133 return hloc16;
2136 static void edit_set_handle( HWND hwnd, HLOCAL16 hloc16 )
2138 HINSTANCE16 hInstance = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2139 HANDLE16 oldDS = CURRENT_DS;
2140 HLOCAL hloc32;
2141 INT count;
2142 CHAR *text;
2144 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) return;
2145 if (!hloc16) return;
2147 CURRENT_DS = hInstance;
2148 count = LocalSize16(hloc16);
2149 text = MapSL(LocalLock16(hloc16));
2150 if ((hloc32 = LocalAlloc(LMEM_MOVEABLE, count)))
2152 memcpy( LocalLock(hloc32), text, count );
2153 LocalUnlock(hloc32);
2154 LocalUnlock16(hloc16);
2155 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2157 CURRENT_DS = oldDS;
2158 if (hloc32) wow_handlers32.edit_proc( hwnd, EM_SETHANDLE, (WPARAM)hloc32, 0, FALSE );
2161 static void edit_destroy_handle( HWND hwnd )
2163 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2164 if (hloc16)
2166 HANDLE16 oldDS = CURRENT_DS;
2168 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2169 while (LocalUnlock16(hloc16)) ;
2170 LocalFree16(hloc16);
2171 CURRENT_DS = oldDS;
2172 SetWindowWord( hwnd, GWW_HANDLE16, 0 );
2176 /*********************************************************************
2177 * edit_proc16
2179 static LRESULT edit_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2181 static const UINT msg16_offset = EM_GETSEL16 - EM_GETSEL;
2182 LRESULT result = 0;
2184 edit_lock_buffer( hwnd );
2185 switch (msg)
2187 case EM_SCROLL16:
2188 case EM_SCROLLCARET16:
2189 case EM_GETMODIFY16:
2190 case EM_SETMODIFY16:
2191 case EM_GETLINECOUNT16:
2192 case EM_GETTHUMB16:
2193 case EM_LINELENGTH16:
2194 case EM_LIMITTEXT16:
2195 case EM_CANUNDO16:
2196 case EM_UNDO16:
2197 case EM_FMTLINES16:
2198 case EM_LINEFROMCHAR16:
2199 case EM_SETPASSWORDCHAR16:
2200 case EM_EMPTYUNDOBUFFER16:
2201 case EM_SETREADONLY16:
2202 case EM_GETPASSWORDCHAR16:
2203 /* these messages missing from specs */
2204 case WM_USER+15:
2205 case WM_USER+16:
2206 case WM_USER+19:
2207 case WM_USER+26:
2208 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2209 break;
2210 case EM_GETSEL16:
2211 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, 0, 0, FALSE );
2212 break;
2213 case EM_REPLACESEL16:
2214 case EM_GETLINE16:
2215 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)MapSL(lParam), FALSE );
2216 break;
2217 case EM_LINESCROLL16:
2218 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, (INT)(SHORT)HIWORD(lParam),
2219 (INT)(SHORT)LOWORD(lParam), FALSE );
2220 break;
2221 case EM_LINEINDEX16:
2222 if ((INT16)wParam == -1) wParam = -1;
2223 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2224 break;
2225 case EM_SETSEL16:
2226 if ((short)LOWORD(lParam) == -1)
2228 wParam = -1;
2229 lParam = 0;
2231 else
2233 wParam = LOWORD(lParam);
2234 lParam = HIWORD(lParam);
2236 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2237 break;
2238 case EM_GETRECT16:
2239 if (lParam)
2241 RECT rect;
2242 RECT16 *r16 = MapSL(lParam);
2243 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2244 r16->left = rect.left;
2245 r16->top = rect.top;
2246 r16->right = rect.right;
2247 r16->bottom = rect.bottom;
2249 break;
2250 case EM_SETRECT16:
2251 case EM_SETRECTNP16:
2252 if (lParam)
2254 RECT rect;
2255 RECT16 *r16 = MapSL(lParam);
2256 rect.left = r16->left;
2257 rect.top = r16->top;
2258 rect.right = r16->right;
2259 rect.bottom = r16->bottom;
2260 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2262 break;
2263 case EM_SETHANDLE16:
2264 edit_set_handle( hwnd, (HLOCAL16)wParam );
2265 break;
2266 case EM_GETHANDLE16:
2267 result = edit_get_handle( hwnd );
2268 break;
2269 case EM_SETTABSTOPS16:
2271 INT16 *tabs16 = MapSL(lParam);
2272 INT i, count = wParam, *tabs = NULL;
2273 if (count > 0)
2275 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*tabs) ))) return 0;
2276 for (i = 0; i < count; i++) tabs[i] = tabs16[i];
2278 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, count, (LPARAM)tabs, FALSE );
2279 HeapFree( GetProcessHeap(), 0, tabs );
2280 break;
2282 case EM_GETFIRSTVISIBLELINE16:
2283 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) break;
2284 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2285 break;
2286 case EM_SETWORDBREAKPROC16:
2288 struct word_break_thunk *thunk = add_word_break_thunk( (EDITWORDBREAKPROC16)lParam );
2289 result = wow_handlers32.edit_proc( hwnd, EM_SETWORDBREAKPROC, wParam, (LPARAM)thunk, FALSE );
2290 break;
2292 case EM_GETWORDBREAKPROC16:
2293 result = wow_handlers32.edit_proc( hwnd, EM_GETWORDBREAKPROC, wParam, lParam, FALSE );
2294 result = (LRESULT)get_word_break_thunk( (EDITWORDBREAKPROCA)result );
2295 break;
2296 case WM_NCDESTROY:
2297 edit_destroy_handle( hwnd );
2298 return wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode ); /* no unlock on destroy */
2299 case WM_HSCROLL:
2300 case WM_VSCROLL:
2301 if (LOWORD(wParam) == EM_GETTHUMB16 || LOWORD(wParam) == EM_LINESCROLL16) wParam -= msg16_offset;
2302 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2303 break;
2304 default:
2305 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2306 break;
2308 edit_unlock_buffer( hwnd );
2309 return result;
2313 /***********************************************************************
2314 * listbox_proc16
2316 static LRESULT listbox_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2318 static const UINT msg16_offset = LB_ADDSTRING16 - LB_ADDSTRING;
2319 LRESULT ret;
2321 switch (msg)
2323 case WM_SIZE:
2324 if (is_old_app( hwnd ))
2326 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2327 int height, remaining, item_height;
2328 RECT rect;
2330 /* give a margin for error to old 16 bits programs - if we need
2331 less than the height of the nonclient area, round to the
2332 *next* number of items */
2334 if (!(style & LBS_NOINTEGRALHEIGHT) && !(style & LBS_OWNERDRAWVARIABLE))
2336 GetClientRect( hwnd, &rect );
2337 height = rect.bottom - rect.top;
2338 item_height = wow_handlers32.listbox_proc( hwnd, LB_GETITEMHEIGHT, 0, 0, FALSE );
2339 remaining = item_height ? (height % item_height) : 0;
2340 if ((height > item_height) && remaining)
2342 GetWindowRect( hwnd, &rect );
2343 if ((item_height - remaining) <= rect.bottom - rect.top - height)
2344 remaining = remaining - item_height;
2345 TRACE( "[%p]: changing height %d -> %d\n", hwnd, height, height - remaining );
2346 SetWindowPos( hwnd, 0, 0, 0, rect.right - rect.left,
2347 rect.bottom - rect.top - remaining,
2348 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE );
2349 return 0;
2353 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, unicode );
2355 case LB_RESETCONTENT16:
2356 case LB_DELETESTRING16:
2357 case LB_GETITEMDATA16:
2358 case LB_SETITEMDATA16:
2359 case LB_GETCOUNT16:
2360 case LB_GETTEXTLEN16:
2361 case LB_GETCURSEL16:
2362 case LB_GETTOPINDEX16:
2363 case LB_GETITEMHEIGHT16:
2364 case LB_SETCARETINDEX16:
2365 case LB_GETCARETINDEX16:
2366 case LB_SETTOPINDEX16:
2367 case LB_SETCOLUMNWIDTH16:
2368 case LB_GETSELCOUNT16:
2369 case LB_SELITEMRANGE16:
2370 case LB_SELITEMRANGEEX16:
2371 case LB_GETHORIZONTALEXTENT16:
2372 case LB_SETHORIZONTALEXTENT16:
2373 case LB_GETANCHORINDEX16:
2374 case LB_CARETON16:
2375 case LB_CARETOFF16:
2376 msg -= msg16_offset;
2377 break;
2378 case LB_GETSEL16:
2379 case LB_SETSEL16:
2380 case LB_SETCURSEL16:
2381 case LB_SETANCHORINDEX16:
2382 wParam = (INT)(INT16)wParam;
2383 msg -= msg16_offset;
2384 break;
2385 case LB_INSERTSTRING16:
2386 case LB_FINDSTRING16:
2387 case LB_FINDSTRINGEXACT16:
2388 case LB_SELECTSTRING16:
2389 wParam = (INT)(INT16)wParam;
2390 /* fall through */
2391 case LB_ADDSTRING16:
2392 case LB_ADDFILE16:
2394 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2395 if ((style & LBS_HASSTRINGS) || !(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)))
2396 lParam = (LPARAM)MapSL(lParam);
2397 msg -= msg16_offset;
2398 break;
2400 case LB_GETTEXT16:
2401 lParam = (LPARAM)MapSL(lParam);
2402 msg -= msg16_offset;
2403 break;
2404 case LB_SETITEMHEIGHT16:
2405 lParam = LOWORD(lParam);
2406 msg -= msg16_offset;
2407 break;
2408 case LB_GETITEMRECT16:
2410 RECT rect;
2411 RECT16 *r16 = MapSL(lParam);
2412 ret = wow_handlers32.listbox_proc( hwnd, LB_GETITEMRECT, (INT16)wParam, (LPARAM)&rect, FALSE );
2413 r16->left = rect.left;
2414 r16->top = rect.top;
2415 r16->right = rect.right;
2416 r16->bottom = rect.bottom;
2417 return ret;
2419 case LB_GETSELITEMS16:
2421 INT16 *array16 = MapSL( lParam );
2422 INT i, count = (INT16)wParam, *array;
2423 if (!(array = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*array) ))) return LB_ERRSPACE;
2424 ret = wow_handlers32.listbox_proc( hwnd, LB_GETSELITEMS, count, (LPARAM)array, FALSE );
2425 for (i = 0; i < ret; i++) array16[i] = array[i];
2426 HeapFree( GetProcessHeap(), 0, array );
2427 return ret;
2429 case LB_DIR16:
2430 /* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE
2431 * be set automatically (this is different in Win32) */
2432 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
2433 lParam = (LPARAM)MapSL(lParam);
2434 msg -= msg16_offset;
2435 break;
2436 case LB_SETTABSTOPS16:
2438 INT i, count, *tabs = NULL;
2439 INT16 *tabs16 = MapSL( lParam );
2441 if ((count = (INT16)wParam) > 0)
2443 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*tabs) ))) return LB_ERRSPACE;
2444 for (i = 0; i < count; i++) tabs[i] = tabs16[i] << 1; /* FIXME */
2446 ret = wow_handlers32.listbox_proc( hwnd, LB_SETTABSTOPS, count, (LPARAM)tabs, FALSE );
2447 HeapFree( GetProcessHeap(), 0, tabs );
2448 return ret;
2450 default:
2451 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, unicode );
2453 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, FALSE );
2457 /***********************************************************************
2458 * mdiclient_proc16
2460 static LRESULT mdiclient_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2462 if (msg == WM_CREATE)
2464 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
2465 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2466 BOOL is_win32 = !instance || ((ULONG_PTR)instance >> 16);
2468 /* Translation layer doesn't know what's in the cs->lpCreateParams
2469 * so we have to keep track of what environment we're in. */
2470 if (!is_win32)
2472 void *orig = cs->lpCreateParams;
2473 LRESULT ret;
2474 CLIENTCREATESTRUCT ccs;
2475 CLIENTCREATESTRUCT16 *ccs16 = MapSL( PtrToUlong( orig ));
2477 ccs.hWindowMenu = HMENU_32(ccs16->hWindowMenu);
2478 ccs.idFirstChild = ccs16->idFirstChild;
2479 cs->lpCreateParams = &ccs;
2480 ret = wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2481 cs->lpCreateParams = orig;
2482 return ret;
2485 return wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2489 /***********************************************************************
2490 * scrollbar_proc16
2492 static LRESULT scrollbar_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2494 static const UINT msg16_offset = SBM_SETPOS16 - SBM_SETPOS;
2496 switch (msg)
2498 case SBM_SETPOS16:
2499 case SBM_GETPOS16:
2500 case SBM_ENABLE_ARROWS16:
2501 msg -= msg16_offset;
2502 break;
2503 case SBM_SETRANGE16:
2504 msg = wParam ? SBM_SETRANGEREDRAW : SBM_SETRANGE;
2505 wParam = LOWORD(lParam);
2506 lParam = HIWORD(lParam);
2507 break;
2508 case SBM_GETRANGE16:
2510 INT min, max;
2511 wow_handlers32.scrollbar_proc( hwnd, SBM_GETRANGE, (WPARAM)&min, (LPARAM)&max, FALSE );
2512 return MAKELRESULT(min, max);
2514 default:
2515 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, unicode );
2517 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, FALSE );
2521 /***********************************************************************
2522 * static_proc16
2524 static LRESULT static_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2526 switch (msg)
2528 case WM_NCCREATE:
2530 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
2531 LRESULT ret = wow_handlers32.static_proc( hwnd, msg, wParam, lParam, unicode );
2533 if (!ret) return 0;
2534 if (((ULONG_PTR)cs->hInstance >> 16)) return ret; /* 32-bit instance, nothing to do */
2535 switch (cs->style & SS_TYPEMASK)
2537 case SS_ICON:
2539 HICON16 icon = LoadIcon16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2540 if (!icon) icon = LoadCursor16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2541 if (icon) wow_handlers32.static_proc( hwnd, STM_SETIMAGE, IMAGE_ICON,
2542 (LPARAM)get_icon_32(icon), FALSE );
2543 break;
2545 case SS_BITMAP:
2547 HBITMAP16 bitmap = LoadBitmap16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2548 if (bitmap) wow_handlers32.static_proc( hwnd, STM_SETIMAGE, IMAGE_BITMAP,
2549 (LPARAM)HBITMAP_32(bitmap), FALSE );
2550 break;
2553 return ret;
2555 case STM_SETICON16:
2556 wParam = (WPARAM)get_icon_32( (HICON16)wParam );
2557 return wow_handlers32.static_proc( hwnd, STM_SETICON, wParam, lParam, FALSE );
2558 case STM_GETICON16:
2559 return get_icon_16( (HICON)wow_handlers32.static_proc( hwnd, STM_GETICON, wParam, lParam, FALSE ));
2560 default:
2561 return wow_handlers32.static_proc( hwnd, msg, wParam, lParam, unicode );
2566 /***********************************************************************
2567 * wait_message16
2569 static DWORD wait_message16( DWORD count, const HANDLE *handles, DWORD timeout, DWORD mask, DWORD flags )
2571 DWORD lock, ret;
2573 ReleaseThunkLock( &lock );
2574 ret = wow_handlers32.wait_message( count, handles, timeout, mask, flags );
2575 RestoreThunkLock( lock );
2576 return ret;
2580 /***********************************************************************
2581 * create_window16
2583 HWND create_window16( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE instance, BOOL unicode )
2585 /* map to module handle */
2586 if (instance && !((ULONG_PTR)instance >> 16))
2587 instance = HINSTANCE_32( GetExePtr( HINSTANCE_16(instance) ));
2589 return wow_handlers32.create_window( cs, className, instance, unicode );
2593 /***********************************************************************
2594 * free_icon_param
2596 static void free_icon_param( ULONG_PTR param )
2598 GlobalFree16( LOWORD(param) );
2602 void register_wow_handlers(void)
2604 static const struct wow_handlers16 handlers16 =
2606 button_proc16,
2607 combo_proc16,
2608 edit_proc16,
2609 listbox_proc16,
2610 mdiclient_proc16,
2611 scrollbar_proc16,
2612 static_proc16,
2613 wait_message16,
2614 create_window16,
2615 call_window_proc_Ato16,
2616 call_dialog_proc_Ato16,
2617 free_icon_param
2620 UserRegisterWowHandlers( &handlers16, &wow_handlers32 );