msdasql: Implement IColumnsRowset GetAvailableColumns.
[wine.git] / dlls / user.exe16 / message.c
blob9af217bf5f1626f051a3f19df1993f081413cd8c
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 = (WORD)GetWindowLongA( 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: %Ix 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: %Ix 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 WM_TIMER:
1296 if (wParam & SYSTEM_TIMER_FLAG)
1297 msg = WM_SYSTIMER;
1298 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1299 break;
1300 case SBM_SETRANGE:
1301 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
1302 break;
1303 case SBM_GETRANGE:
1304 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
1305 *(LPINT)wParam = LOWORD(*result);
1306 *(LPINT)lParam = HIWORD(*result);
1307 break;
1308 case BM_GETCHECK:
1309 case BM_SETCHECK:
1310 case BM_GETSTATE:
1311 case BM_SETSTATE:
1312 case BM_SETSTYLE:
1313 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
1314 break;
1315 case EM_GETSEL:
1316 case EM_GETRECT:
1317 case EM_SETRECT:
1318 case EM_SETRECTNP:
1319 case EM_SCROLL:
1320 case EM_LINESCROLL:
1321 case EM_SCROLLCARET:
1322 case EM_GETMODIFY:
1323 case EM_SETMODIFY:
1324 case EM_GETLINECOUNT:
1325 case EM_LINEINDEX:
1326 case EM_SETHANDLE:
1327 case EM_GETHANDLE:
1328 case EM_GETTHUMB:
1329 case EM_LINELENGTH:
1330 case EM_REPLACESEL:
1331 case EM_GETLINE:
1332 case EM_LIMITTEXT:
1333 case EM_CANUNDO:
1334 case EM_UNDO:
1335 case EM_FMTLINES:
1336 case EM_LINEFROMCHAR:
1337 case EM_SETTABSTOPS:
1338 case EM_SETPASSWORDCHAR:
1339 case EM_EMPTYUNDOBUFFER:
1340 case EM_GETFIRSTVISIBLELINE:
1341 case EM_SETREADONLY:
1342 case EM_SETWORDBREAKPROC:
1343 case EM_GETWORDBREAKPROC:
1344 case EM_GETPASSWORDCHAR:
1345 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
1346 break;
1347 case EM_SETSEL:
1348 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
1349 break;
1350 case LB_CARETOFF:
1351 case LB_CARETON:
1352 case LB_DELETESTRING:
1353 case LB_GETANCHORINDEX:
1354 case LB_GETCARETINDEX:
1355 case LB_GETCOUNT:
1356 case LB_GETCURSEL:
1357 case LB_GETHORIZONTALEXTENT:
1358 case LB_GETITEMDATA:
1359 case LB_GETITEMHEIGHT:
1360 case LB_GETSEL:
1361 case LB_GETSELCOUNT:
1362 case LB_GETTEXTLEN:
1363 case LB_GETTOPINDEX:
1364 case LB_RESETCONTENT:
1365 case LB_SELITEMRANGE:
1366 case LB_SELITEMRANGEEX:
1367 case LB_SETANCHORINDEX:
1368 case LB_SETCARETINDEX:
1369 case LB_SETCOLUMNWIDTH:
1370 case LB_SETCURSEL:
1371 case LB_SETHORIZONTALEXTENT:
1372 case LB_SETITEMDATA:
1373 case LB_SETITEMHEIGHT:
1374 case LB_SETSEL:
1375 case LB_SETTOPINDEX:
1376 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1377 break;
1378 case LB_ADDSTRING:
1379 case LB_FINDSTRING:
1380 case LB_FINDSTRINGEXACT:
1381 case LB_INSERTSTRING:
1382 case LB_SELECTSTRING:
1383 case LB_GETTEXT:
1384 case LB_DIR:
1385 case LB_ADDFILE:
1386 lParam = MapLS( (LPSTR)lParam );
1387 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1388 UnMapLS( lParam );
1389 break;
1390 case LB_GETSELITEMS:
1392 INT *items32 = (INT *)lParam;
1393 INT16 *items, buffer[512];
1394 unsigned int i;
1396 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1397 if (!(items = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1398 lParam = MapLS( items );
1399 ret = callback( HWND_16(hwnd), LB_GETSELITEMS16, wParam, lParam, result, arg );
1400 UnMapLS( lParam );
1401 for (i = 0; i < wParam; i++) items32[i] = items[i];
1402 free_buffer( buffer, items );
1404 break;
1405 case LB_SETTABSTOPS:
1406 if (wParam)
1408 INT *stops32 = (INT *)lParam;
1409 INT16 *stops, buffer[512];
1410 unsigned int i;
1412 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1413 if (!(stops = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1414 for (i = 0; i < wParam; i++) stops[i] = stops32[i];
1415 lParam = MapLS( stops );
1416 ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1417 UnMapLS( lParam );
1418 free_buffer( buffer, stops );
1420 else ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1421 break;
1422 case CB_DELETESTRING:
1423 case CB_GETCOUNT:
1424 case CB_GETLBTEXTLEN:
1425 case CB_LIMITTEXT:
1426 case CB_RESETCONTENT:
1427 case CB_SETEDITSEL:
1428 case CB_GETCURSEL:
1429 case CB_SETCURSEL:
1430 case CB_SHOWDROPDOWN:
1431 case CB_SETITEMDATA:
1432 case CB_SETITEMHEIGHT:
1433 case CB_GETITEMHEIGHT:
1434 case CB_SETEXTENDEDUI:
1435 case CB_GETEXTENDEDUI:
1436 case CB_GETDROPPEDSTATE:
1437 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1438 break;
1439 case CB_GETEDITSEL:
1440 ret = callback( HWND_16(hwnd), CB_GETEDITSEL16, wParam, lParam, result, arg );
1441 if (wParam) *((PUINT)(wParam)) = LOWORD(*result);
1442 if (lParam) *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: subtract 1? */
1443 break;
1444 case CB_ADDSTRING:
1445 case CB_FINDSTRING:
1446 case CB_FINDSTRINGEXACT:
1447 case CB_INSERTSTRING:
1448 case CB_SELECTSTRING:
1449 case CB_DIR:
1450 case CB_GETLBTEXT:
1451 lParam = MapLS( (LPSTR)lParam );
1452 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1453 UnMapLS( lParam );
1454 break;
1455 case LB_GETITEMRECT:
1456 case CB_GETDROPPEDCONTROLRECT:
1458 RECT *r32 = (RECT *)lParam;
1459 RECT16 rect;
1460 lParam = MapLS( &rect );
1461 ret = callback( HWND_16(hwnd),
1462 (msg == LB_GETITEMRECT) ? LB_GETITEMRECT16 : CB_GETDROPPEDCONTROLRECT16,
1463 wParam, lParam, result, arg );
1464 UnMapLS( lParam );
1465 RECT16to32( &rect, r32 );
1467 break;
1468 case WM_PAINTCLIPBOARD:
1469 case WM_SIZECLIPBOARD:
1470 FIXME_(msg)( "message %04x needs translation\n", msg );
1471 break;
1472 /* the following messages should not be sent to 16-bit apps */
1473 case WM_SIZING:
1474 case WM_MOVING:
1475 case WM_CAPTURECHANGED:
1476 case WM_STYLECHANGING:
1477 case WM_STYLECHANGED:
1478 break;
1479 default:
1480 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1481 break;
1483 return ret;
1487 /***********************************************************************
1488 * SendMessage (USER.111)
1490 LRESULT WINAPI SendMessage16( HWND16 hwnd16, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1492 LRESULT result;
1493 HWND hwnd = WIN_Handle32( hwnd16 );
1495 if (hwnd != HWND_BROADCAST &&
1496 GetWindowThreadProcessId( hwnd, NULL ) == GetCurrentThreadId())
1498 /* call 16-bit window proc directly */
1499 WNDPROC16 winproc;
1501 /* first the WH_CALLWNDPROC hook */
1502 call_WH_CALLWNDPROC_hook( hwnd16, msg, wparam, lparam );
1504 if (!(winproc = (WNDPROC16)GetWindowLong16( hwnd16, GWLP_WNDPROC ))) return 0;
1506 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx\n", hwnd16, msg, wparam, lparam );
1507 result = CallWindowProc16( winproc, hwnd16, msg, wparam, lparam );
1508 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx returned %08lx\n",
1509 hwnd16, msg, wparam, lparam, result );
1511 else /* map to 32-bit unicode for inter-thread/process message */
1513 WINPROC_CallProc16To32A( send_message_callback, hwnd16, msg, wparam, lparam, &result, NULL );
1515 return result;
1519 /***********************************************************************
1520 * PostMessage (USER.110)
1522 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1524 LRESULT unused;
1525 return WINPROC_CallProc16To32A( post_message_callback, hwnd, msg, wparam, lparam, &unused, NULL );
1529 /***********************************************************************
1530 * PostAppMessage (USER.116)
1532 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1534 LRESULT unused;
1535 DWORD_PTR tid = HTASK_32( hTask );
1537 if (!tid) return FALSE;
1538 return WINPROC_CallProc16To32A( post_thread_message_callback, 0, msg, wparam, lparam,
1539 &unused, (void *)tid );
1543 /**********************************************************************
1544 * CallWindowProc (USER.122)
1546 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
1547 WPARAM16 wParam, LPARAM lParam )
1549 int index = winproc_to_index( func );
1550 LRESULT result;
1552 if (!func) return 0;
1554 if (index == -1 || index >= MAX_WINPROCS32)
1555 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
1556 else
1558 WNDPROC proc = (WNDPROC)func;
1559 if (thunk_array && thunk_array[index].proc) proc = thunk_array[index].proc;
1560 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1562 return result;
1566 /**********************************************************************
1567 * __wine_call_wndproc (USER.1010)
1569 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam, WNDPROC proc )
1571 LRESULT result;
1572 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1573 return result;
1577 /***********************************************************************
1578 * InSendMessage (USER.192)
1580 BOOL16 WINAPI InSendMessage16(void)
1582 return InSendMessage();
1586 /***********************************************************************
1587 * ReplyMessage (USER.115)
1589 void WINAPI ReplyMessage16( LRESULT result )
1591 ReplyMessage( result );
1595 /***********************************************************************
1596 * PeekMessage32 (USER.819)
1598 BOOL16 WINAPI PeekMessage32_16( MSG32_16 *msg16, HWND16 hwnd16,
1599 UINT16 first, UINT16 last, UINT16 flags,
1600 BOOL16 wHaveParamHigh )
1602 MSG msg;
1603 LRESULT unused;
1604 HWND hwnd = WIN_Handle32( hwnd16 );
1606 if(USER16_AlertableWait)
1607 MsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, MWMO_ALERTABLE );
1608 if (!PeekMessageA( &msg, hwnd, first, last, flags )) return FALSE;
1610 msg16->msg.time = msg.time;
1611 msg16->msg.pt.x = (INT16)msg.pt.x;
1612 msg16->msg.pt.y = (INT16)msg.pt.y;
1613 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1614 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1615 &unused, &msg16->msg );
1616 return TRUE;
1620 /***********************************************************************
1621 * DefWindowProc (USER.107)
1623 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1625 LRESULT result;
1626 WINPROC_CallProc16To32A( defwnd_proc_callback, hwnd16, msg, wParam, lParam, &result, 0 );
1627 return result;
1631 /***********************************************************************
1632 * DefDlgProc (USER.308)
1634 LRESULT WINAPI DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1636 LRESULT result;
1637 WINPROC_CallProc16To32A( defdlg_proc_callback, hwnd, msg, wParam, lParam, &result, 0 );
1638 return result;
1642 /***********************************************************************
1643 * PeekMessage (USER.109)
1645 BOOL16 WINAPI PeekMessage16( MSG16 *msg, HWND16 hwnd,
1646 UINT16 first, UINT16 last, UINT16 flags )
1648 return PeekMessage32_16( (MSG32_16 *)msg, hwnd, first, last, flags, FALSE );
1652 /***********************************************************************
1653 * GetMessage32 (USER.820)
1655 BOOL16 WINAPI GetMessage32_16( MSG32_16 *msg16, HWND16 hwnd16, UINT16 first,
1656 UINT16 last, BOOL16 wHaveParamHigh )
1658 MSG msg;
1659 LRESULT unused;
1660 HWND hwnd = WIN_Handle32( hwnd16 );
1662 if(USER16_AlertableWait)
1663 MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, 0, MWMO_ALERTABLE );
1664 GetMessageA( &msg, hwnd, first, last );
1665 msg16->msg.time = msg.time;
1666 msg16->msg.pt.x = (INT16)msg.pt.x;
1667 msg16->msg.pt.y = (INT16)msg.pt.y;
1668 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1669 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1670 &unused, &msg16->msg );
1672 TRACE( "message %04x, hwnd %p, filter(%04x - %04x)\n",
1673 msg16->msg.message, hwnd, first, last );
1675 return msg16->msg.message != WM_QUIT;
1679 /***********************************************************************
1680 * GetMessage (USER.108)
1682 BOOL16 WINAPI GetMessage16( MSG16 *msg, HWND16 hwnd, UINT16 first, UINT16 last )
1684 return GetMessage32_16( (MSG32_16 *)msg, hwnd, first, last, FALSE );
1688 /***********************************************************************
1689 * TranslateMessage32 (USER.821)
1691 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
1693 MSG msg32;
1695 msg32.hwnd = WIN_Handle32( msg->msg.hwnd );
1696 msg32.message = msg->msg.message;
1697 msg32.wParam = MAKEWPARAM( msg->msg.wParam, wHaveParamHigh ? msg->wParamHigh : 0 );
1698 msg32.lParam = msg->msg.lParam;
1699 return TranslateMessage( &msg32 );
1703 /***********************************************************************
1704 * TranslateMessage (USER.113)
1706 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1708 return TranslateMessage32_16( (const MSG32_16 *)msg, FALSE );
1712 /***********************************************************************
1713 * DispatchMessage (USER.114)
1715 LONG WINAPI DispatchMessage16( const MSG16* msg )
1717 WNDPROC16 winproc;
1718 LRESULT retval;
1720 /* Process timer messages */
1721 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1723 if (msg->lParam)
1724 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1725 msg->message, msg->wParam, GetTickCount() );
1728 if (!(winproc = (WNDPROC16)GetWindowLong16( msg->hwnd, GWLP_WNDPROC )))
1730 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1731 return 0;
1733 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx\n", msg->hwnd, msg->message, msg->wParam, msg->lParam );
1734 retval = CallWindowProc16( winproc, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1735 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx returned %08lx\n",
1736 msg->hwnd, msg->message, msg->wParam, msg->lParam, retval );
1737 return retval;
1741 /***********************************************************************
1742 * DispatchMessage32 (USER.822)
1744 LONG WINAPI DispatchMessage32_16( const MSG32_16 *msg16, BOOL16 wHaveParamHigh )
1746 if (wHaveParamHigh == FALSE)
1747 return DispatchMessage16( &msg16->msg );
1748 else
1750 MSG msg;
1752 msg.hwnd = WIN_Handle32( msg16->msg.hwnd );
1753 msg.message = msg16->msg.message;
1754 msg.wParam = MAKEWPARAM( msg16->msg.wParam, msg16->wParamHigh );
1755 msg.lParam = msg16->msg.lParam;
1756 msg.time = msg16->msg.time;
1757 msg.pt.x = msg16->msg.pt.x;
1758 msg.pt.y = msg16->msg.pt.y;
1759 return DispatchMessageA( &msg );
1764 /***********************************************************************
1765 * IsDialogMessage (USER.90)
1767 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, MSG16 *msg16 )
1769 MSG msg;
1770 HWND hwndDlg32;
1772 msg.hwnd = WIN_Handle32(msg16->hwnd);
1773 hwndDlg32 = WIN_Handle32(hwndDlg);
1775 switch(msg16->message)
1777 case WM_KEYDOWN:
1778 case WM_CHAR:
1779 case WM_SYSCHAR:
1780 msg.message = msg16->message;
1781 msg.wParam = msg16->wParam;
1782 msg.lParam = msg16->lParam;
1783 msg.time = msg16->time;
1784 msg.pt.x = msg16->pt.x;
1785 msg.pt.y = msg16->pt.y;
1786 return IsDialogMessageA( hwndDlg32, &msg );
1789 if ((hwndDlg32 != msg.hwnd) && !IsChild( hwndDlg32, msg.hwnd )) return FALSE;
1790 TranslateMessage16( msg16 );
1791 DispatchMessage16( msg16 );
1792 return TRUE;
1796 /***********************************************************************
1797 * MsgWaitForMultipleObjects (USER.640)
1799 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD count, const HANDLE *handles,
1800 BOOL wait_all, DWORD timeout, DWORD mask )
1802 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
1803 wait_all ? MWMO_WAITALL : 0 );
1807 /**********************************************************************
1808 * SetDoubleClickTime (USER.20)
1810 void WINAPI SetDoubleClickTime16( UINT16 interval )
1812 SetDoubleClickTime( interval );
1816 /**********************************************************************
1817 * GetDoubleClickTime (USER.21)
1819 UINT16 WINAPI GetDoubleClickTime16(void)
1821 return GetDoubleClickTime();
1825 /***********************************************************************
1826 * PostQuitMessage (USER.6)
1828 void WINAPI PostQuitMessage16( INT16 exitCode )
1830 PostQuitMessage( exitCode );
1834 /**********************************************************************
1835 * GetKeyState (USER.106)
1837 INT16 WINAPI GetKeyState16(INT16 vkey)
1839 return GetKeyState(vkey);
1843 /**********************************************************************
1844 * GetKeyboardState (USER.222)
1846 BOOL WINAPI GetKeyboardState16( LPBYTE state )
1848 return GetKeyboardState( state );
1852 /**********************************************************************
1853 * SetKeyboardState (USER.223)
1855 BOOL WINAPI SetKeyboardState16( LPBYTE state )
1857 return SetKeyboardState( state );
1861 /***********************************************************************
1862 * SetMessageQueue (USER.266)
1864 BOOL16 WINAPI SetMessageQueue16( INT16 size )
1866 return SetMessageQueue( size );
1870 /***********************************************************************
1871 * UserYield (USER.332)
1873 void WINAPI UserYield16(void)
1875 MSG msg;
1876 PeekMessageW( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
1880 /***********************************************************************
1881 * GetQueueStatus (USER.334)
1883 DWORD WINAPI GetQueueStatus16( UINT16 flags )
1885 return GetQueueStatus( flags );
1889 /***********************************************************************
1890 * GetInputState (USER.335)
1892 BOOL16 WINAPI GetInputState16(void)
1894 return GetInputState();
1898 /**********************************************************************
1899 * TranslateAccelerator (USER.178)
1901 INT16 WINAPI TranslateAccelerator16( HWND16 hwnd, HACCEL16 hAccel, LPMSG16 msg )
1903 MSG msg32;
1905 if (!msg) return 0;
1906 msg32.message = msg->message;
1907 /* msg32.hwnd not used */
1908 msg32.wParam = msg->wParam;
1909 msg32.lParam = msg->lParam;
1910 return TranslateAcceleratorW( WIN_Handle32(hwnd), HACCEL_32(hAccel), &msg32 );
1914 /**********************************************************************
1915 * TranslateMDISysAccel (USER.451)
1917 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1919 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1921 MSG msg32;
1922 msg32.hwnd = WIN_Handle32(msg->hwnd);
1923 msg32.message = msg->message;
1924 msg32.wParam = msg->wParam;
1925 msg32.lParam = msg->lParam;
1926 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1927 return TranslateMDISysAccel( WIN_Handle32(hwndClient), &msg32 );
1929 return 0;
1933 /***********************************************************************
1934 * button_proc16
1936 static LRESULT button_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
1938 static const UINT msg16_offset = BM_GETCHECK16 - BM_GETCHECK;
1940 switch (msg)
1942 case BM_GETCHECK16:
1943 case BM_SETCHECK16:
1944 case BM_GETSTATE16:
1945 case BM_SETSTATE16:
1946 case BM_SETSTYLE16:
1947 return wow_handlers32.button_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
1948 default:
1949 return wow_handlers32.button_proc( hwnd, msg, wParam, lParam, unicode );
1954 /***********************************************************************
1955 * combo_proc16
1957 static LRESULT combo_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
1959 static const UINT msg16_offset = CB_GETEDITSEL16 - CB_GETEDITSEL;
1961 switch (msg)
1963 case CB_INSERTSTRING16:
1964 case CB_SELECTSTRING16:
1965 case CB_FINDSTRING16:
1966 case CB_FINDSTRINGEXACT16:
1967 wParam = (INT)(INT16)wParam;
1968 /* fall through */
1969 case CB_ADDSTRING16:
1971 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
1972 if ((style & CBS_HASSTRINGS) || !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)))
1973 lParam = (LPARAM)MapSL(lParam);
1974 msg -= msg16_offset;
1975 break;
1977 case CB_SETITEMHEIGHT16:
1978 case CB_GETITEMHEIGHT16:
1979 case CB_SETCURSEL16:
1980 case CB_GETLBTEXTLEN16:
1981 case CB_GETITEMDATA16:
1982 case CB_SETITEMDATA16:
1983 wParam = (INT)(INT16)wParam; /* signed integer */
1984 msg -= msg16_offset;
1985 break;
1986 case CB_GETDROPPEDCONTROLRECT16:
1987 lParam = (LPARAM)MapSL(lParam);
1988 if (lParam)
1990 RECT r;
1991 RECT16 *r16 = (RECT16 *)lParam;
1992 wow_handlers32.combo_proc( hwnd, CB_GETDROPPEDCONTROLRECT, wParam, (LPARAM)&r, FALSE );
1993 r16->left = r.left;
1994 r16->top = r.top;
1995 r16->right = r.right;
1996 r16->bottom = r.bottom;
1998 return CB_OKAY;
1999 case CB_DIR16:
2000 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
2001 lParam = (LPARAM)MapSL(lParam);
2002 msg -= msg16_offset;
2003 break;
2004 case CB_GETLBTEXT16:
2005 wParam = (INT)(INT16)wParam;
2006 lParam = (LPARAM)MapSL(lParam);
2007 msg -= msg16_offset;
2008 break;
2009 case CB_GETEDITSEL16:
2010 wParam = lParam = 0; /* just in case */
2011 msg -= msg16_offset;
2012 break;
2013 case CB_LIMITTEXT16:
2014 case CB_SETEDITSEL16:
2015 case CB_DELETESTRING16:
2016 case CB_RESETCONTENT16:
2017 case CB_GETDROPPEDSTATE16:
2018 case CB_SHOWDROPDOWN16:
2019 case CB_GETCOUNT16:
2020 case CB_GETCURSEL16:
2021 case CB_SETEXTENDEDUI16:
2022 case CB_GETEXTENDEDUI16:
2023 msg -= msg16_offset;
2024 break;
2025 default:
2026 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, unicode );
2028 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, FALSE );
2031 /*********************************************************************
2032 * edit_lock_buffer (internal)
2034 * A 16 bit application might send an EM_GETHANDLE message and expect a HLOCAL16
2035 * (16 bit SEG:OFF handler). From that moment on we have to keep using this
2036 * 16 bit memory handler, because it is supposed to be valid at all times after
2037 * EM_GETHANDLE.
2038 * We create a HLOCAL16 buffer in edit_get_handle and copy the text from the
2039 * HLOCAL buffer, when needed
2043 #define GWW_HANDLE16 sizeof(void*)
2045 static void edit_lock_buffer( HWND hwnd )
2047 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2048 HANDLE16 oldDS;
2049 HLOCAL hloc32;
2050 UINT size;
2052 if (!hloc16) return;
2053 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2055 oldDS = CURRENT_DS;
2056 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2057 size = LocalSize16(hloc16);
2058 if (LocalReAlloc( hloc32, size, LMEM_MOVEABLE ))
2060 char *text = MapSL( LocalLock16( hloc16 ));
2061 char *dest = LocalLock( hloc32 );
2062 memcpy( dest, text, size );
2063 LocalUnlock( hloc32 );
2064 LocalUnlock16( hloc16 );
2066 CURRENT_DS = oldDS;
2069 static void edit_unlock_buffer( HWND hwnd )
2071 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2072 HANDLE16 oldDS;
2073 HLOCAL hloc32;
2074 UINT size;
2076 if (!hloc16) return;
2077 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2078 size = LocalSize( hloc32 );
2080 oldDS = CURRENT_DS;
2081 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2082 if (LocalReAlloc16( hloc16, size, LMEM_MOVEABLE ))
2084 char *text = LocalLock( hloc32 );
2085 char *dest = MapSL( LocalLock16( hloc16 ));
2086 memcpy( dest, text, size );
2087 LocalUnlock( hloc32 );
2088 LocalUnlock16( hloc16 );
2090 CURRENT_DS = oldDS;
2093 static HLOCAL16 edit_get_handle( HWND hwnd )
2095 CHAR *textA;
2096 UINT alloc_size;
2097 HLOCAL hloc;
2098 HANDLE16 oldDS;
2099 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2101 if (hloc16) return hloc16;
2103 if (!(hloc = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return 0;
2104 alloc_size = LocalSize( hloc );
2106 oldDS = CURRENT_DS;
2107 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2109 if (!LocalHeapSize16())
2111 if (!LocalInit16(CURRENT_DS, 0, GlobalSize16(CURRENT_DS)))
2113 ERR("could not initialize local heap\n");
2114 goto done;
2118 if (!(hloc16 = LocalAlloc16(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
2120 ERR("could not allocate new 16 bit buffer\n");
2121 goto done;
2124 if (!(textA = MapSL(LocalLock16( hloc16))))
2126 ERR("could not lock new 16 bit buffer\n");
2127 LocalFree16(hloc16);
2128 hloc16 = 0;
2129 goto done;
2131 memcpy( textA, LocalLock( hloc ), alloc_size );
2132 LocalUnlock( hloc );
2133 LocalUnlock16( hloc16 );
2134 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2136 done:
2137 CURRENT_DS = oldDS;
2138 return hloc16;
2141 static void edit_set_handle( HWND hwnd, HLOCAL16 hloc16 )
2143 HINSTANCE16 hInstance = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2144 HANDLE16 oldDS = CURRENT_DS;
2145 HLOCAL hloc32;
2146 INT count;
2147 CHAR *text;
2149 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) return;
2150 if (!hloc16) return;
2152 CURRENT_DS = hInstance;
2153 count = LocalSize16(hloc16);
2154 text = MapSL(LocalLock16(hloc16));
2155 if ((hloc32 = LocalAlloc(LMEM_MOVEABLE, count)))
2157 memcpy( LocalLock(hloc32), text, count );
2158 LocalUnlock(hloc32);
2159 LocalUnlock16(hloc16);
2160 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2162 CURRENT_DS = oldDS;
2163 if (hloc32) wow_handlers32.edit_proc( hwnd, EM_SETHANDLE, (WPARAM)hloc32, 0, FALSE );
2166 static void edit_destroy_handle( HWND hwnd )
2168 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2169 if (hloc16)
2171 HANDLE16 oldDS = CURRENT_DS;
2173 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2174 while (LocalUnlock16(hloc16)) ;
2175 LocalFree16(hloc16);
2176 CURRENT_DS = oldDS;
2177 SetWindowWord( hwnd, GWW_HANDLE16, 0 );
2181 /*********************************************************************
2182 * edit_proc16
2184 static LRESULT edit_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2186 static const UINT msg16_offset = EM_GETSEL16 - EM_GETSEL;
2187 LRESULT result = 0;
2189 edit_lock_buffer( hwnd );
2190 switch (msg)
2192 case EM_SCROLL16:
2193 case EM_SCROLLCARET16:
2194 case EM_GETMODIFY16:
2195 case EM_SETMODIFY16:
2196 case EM_GETLINECOUNT16:
2197 case EM_GETTHUMB16:
2198 case EM_LINELENGTH16:
2199 case EM_LIMITTEXT16:
2200 case EM_CANUNDO16:
2201 case EM_UNDO16:
2202 case EM_FMTLINES16:
2203 case EM_LINEFROMCHAR16:
2204 case EM_SETPASSWORDCHAR16:
2205 case EM_EMPTYUNDOBUFFER16:
2206 case EM_SETREADONLY16:
2207 case EM_GETPASSWORDCHAR16:
2208 /* these messages missing from specs */
2209 case WM_USER+15:
2210 case WM_USER+16:
2211 case WM_USER+19:
2212 case WM_USER+26:
2213 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2214 break;
2215 case EM_GETSEL16:
2216 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, 0, 0, FALSE );
2217 break;
2218 case EM_REPLACESEL16:
2219 case EM_GETLINE16:
2220 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)MapSL(lParam), FALSE );
2221 break;
2222 case EM_LINESCROLL16:
2223 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, (INT)(SHORT)HIWORD(lParam),
2224 (INT)(SHORT)LOWORD(lParam), FALSE );
2225 break;
2226 case EM_LINEINDEX16:
2227 if ((INT16)wParam == -1) wParam = -1;
2228 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2229 break;
2230 case EM_SETSEL16:
2231 if ((short)LOWORD(lParam) == -1)
2233 wParam = -1;
2234 lParam = 0;
2236 else
2238 wParam = LOWORD(lParam);
2239 lParam = HIWORD(lParam);
2241 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2242 break;
2243 case EM_GETRECT16:
2244 if (lParam)
2246 RECT rect;
2247 RECT16 *r16 = MapSL(lParam);
2248 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2249 r16->left = rect.left;
2250 r16->top = rect.top;
2251 r16->right = rect.right;
2252 r16->bottom = rect.bottom;
2254 break;
2255 case EM_SETRECT16:
2256 case EM_SETRECTNP16:
2257 if (lParam)
2259 RECT rect;
2260 RECT16 *r16 = MapSL(lParam);
2261 rect.left = r16->left;
2262 rect.top = r16->top;
2263 rect.right = r16->right;
2264 rect.bottom = r16->bottom;
2265 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2267 break;
2268 case EM_SETHANDLE16:
2269 edit_set_handle( hwnd, (HLOCAL16)wParam );
2270 break;
2271 case EM_GETHANDLE16:
2272 result = edit_get_handle( hwnd );
2273 break;
2274 case EM_SETTABSTOPS16:
2276 INT16 *tabs16 = MapSL(lParam);
2277 INT i, count = wParam, *tabs = NULL;
2278 if (count > 0)
2280 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*tabs) ))) return 0;
2281 for (i = 0; i < count; i++) tabs[i] = tabs16[i];
2283 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, count, (LPARAM)tabs, FALSE );
2284 HeapFree( GetProcessHeap(), 0, tabs );
2285 break;
2287 case EM_GETFIRSTVISIBLELINE16:
2288 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) break;
2289 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2290 break;
2291 case EM_SETWORDBREAKPROC16:
2293 struct word_break_thunk *thunk = add_word_break_thunk( (EDITWORDBREAKPROC16)lParam );
2294 result = wow_handlers32.edit_proc( hwnd, EM_SETWORDBREAKPROC, wParam, (LPARAM)thunk, FALSE );
2295 break;
2297 case EM_GETWORDBREAKPROC16:
2298 result = wow_handlers32.edit_proc( hwnd, EM_GETWORDBREAKPROC, wParam, lParam, FALSE );
2299 result = (LRESULT)get_word_break_thunk( (EDITWORDBREAKPROCA)result );
2300 break;
2301 case WM_NCDESTROY:
2302 edit_destroy_handle( hwnd );
2303 return wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode ); /* no unlock on destroy */
2304 case WM_HSCROLL:
2305 case WM_VSCROLL:
2306 if (LOWORD(wParam) == EM_GETTHUMB16 || LOWORD(wParam) == EM_LINESCROLL16) wParam -= msg16_offset;
2307 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2308 break;
2309 default:
2310 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2311 break;
2313 edit_unlock_buffer( hwnd );
2314 return result;
2318 /***********************************************************************
2319 * listbox_proc16
2321 static LRESULT listbox_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2323 static const UINT msg16_offset = LB_ADDSTRING16 - LB_ADDSTRING;
2324 LRESULT ret;
2326 switch (msg)
2328 case WM_SIZE:
2329 if (is_old_app( hwnd ))
2331 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2332 int height, remaining, item_height;
2333 RECT rect;
2335 /* give a margin for error to old 16 bits programs - if we need
2336 less than the height of the nonclient area, round to the
2337 *next* number of items */
2339 if (!(style & LBS_NOINTEGRALHEIGHT) && !(style & LBS_OWNERDRAWVARIABLE))
2341 GetClientRect( hwnd, &rect );
2342 height = rect.bottom - rect.top;
2343 item_height = wow_handlers32.listbox_proc( hwnd, LB_GETITEMHEIGHT, 0, 0, FALSE );
2344 remaining = item_height ? (height % item_height) : 0;
2345 if ((height > item_height) && remaining)
2347 GetWindowRect( hwnd, &rect );
2348 if ((item_height - remaining) <= rect.bottom - rect.top - height)
2349 remaining = remaining - item_height;
2350 TRACE( "[%p]: changing height %d -> %d\n", hwnd, height, height - remaining );
2351 SetWindowPos( hwnd, 0, 0, 0, rect.right - rect.left,
2352 rect.bottom - rect.top - remaining,
2353 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE );
2354 return 0;
2358 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, unicode );
2360 case LB_RESETCONTENT16:
2361 case LB_DELETESTRING16:
2362 case LB_GETITEMDATA16:
2363 case LB_SETITEMDATA16:
2364 case LB_GETCOUNT16:
2365 case LB_GETTEXTLEN16:
2366 case LB_GETCURSEL16:
2367 case LB_GETTOPINDEX16:
2368 case LB_GETITEMHEIGHT16:
2369 case LB_SETCARETINDEX16:
2370 case LB_GETCARETINDEX16:
2371 case LB_SETTOPINDEX16:
2372 case LB_SETCOLUMNWIDTH16:
2373 case LB_GETSELCOUNT16:
2374 case LB_SELITEMRANGE16:
2375 case LB_SELITEMRANGEEX16:
2376 case LB_GETHORIZONTALEXTENT16:
2377 case LB_SETHORIZONTALEXTENT16:
2378 case LB_GETANCHORINDEX16:
2379 case LB_CARETON16:
2380 case LB_CARETOFF16:
2381 msg -= msg16_offset;
2382 break;
2383 case LB_GETSEL16:
2384 case LB_SETSEL16:
2385 case LB_SETCURSEL16:
2386 case LB_SETANCHORINDEX16:
2387 wParam = (INT)(INT16)wParam;
2388 msg -= msg16_offset;
2389 break;
2390 case LB_INSERTSTRING16:
2391 case LB_FINDSTRING16:
2392 case LB_FINDSTRINGEXACT16:
2393 case LB_SELECTSTRING16:
2394 wParam = (INT)(INT16)wParam;
2395 /* fall through */
2396 case LB_ADDSTRING16:
2397 case LB_ADDFILE16:
2399 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2400 if ((style & LBS_HASSTRINGS) || !(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)))
2401 lParam = (LPARAM)MapSL(lParam);
2402 msg -= msg16_offset;
2403 break;
2405 case LB_GETTEXT16:
2406 lParam = (LPARAM)MapSL(lParam);
2407 msg -= msg16_offset;
2408 break;
2409 case LB_SETITEMHEIGHT16:
2410 lParam = LOWORD(lParam);
2411 msg -= msg16_offset;
2412 break;
2413 case LB_GETITEMRECT16:
2415 RECT rect;
2416 RECT16 *r16 = MapSL(lParam);
2417 ret = wow_handlers32.listbox_proc( hwnd, LB_GETITEMRECT, (INT16)wParam, (LPARAM)&rect, FALSE );
2418 r16->left = rect.left;
2419 r16->top = rect.top;
2420 r16->right = rect.right;
2421 r16->bottom = rect.bottom;
2422 return ret;
2424 case LB_GETSELITEMS16:
2426 INT16 *array16 = MapSL( lParam );
2427 INT i, count = (INT16)wParam, *array;
2428 if (!(array = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*array) ))) return LB_ERRSPACE;
2429 ret = wow_handlers32.listbox_proc( hwnd, LB_GETSELITEMS, count, (LPARAM)array, FALSE );
2430 for (i = 0; i < ret; i++) array16[i] = array[i];
2431 HeapFree( GetProcessHeap(), 0, array );
2432 return ret;
2434 case LB_DIR16:
2435 /* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE
2436 * be set automatically (this is different in Win32) */
2437 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
2438 lParam = (LPARAM)MapSL(lParam);
2439 msg -= msg16_offset;
2440 break;
2441 case LB_SETTABSTOPS16:
2443 INT i, count, *tabs = NULL;
2444 INT16 *tabs16 = MapSL( lParam );
2446 if ((count = (INT16)wParam) > 0)
2448 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*tabs) ))) return LB_ERRSPACE;
2449 for (i = 0; i < count; i++) tabs[i] = tabs16[i] << 1; /* FIXME */
2451 ret = wow_handlers32.listbox_proc( hwnd, LB_SETTABSTOPS, count, (LPARAM)tabs, FALSE );
2452 HeapFree( GetProcessHeap(), 0, tabs );
2453 return ret;
2455 default:
2456 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, unicode );
2458 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, FALSE );
2462 /***********************************************************************
2463 * mdiclient_proc16
2465 static LRESULT mdiclient_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2467 if (msg == WM_CREATE)
2469 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
2470 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2471 BOOL is_win32 = !instance || ((ULONG_PTR)instance >> 16);
2473 /* Translation layer doesn't know what's in the cs->lpCreateParams
2474 * so we have to keep track of what environment we're in. */
2475 if (!is_win32)
2477 void *orig = cs->lpCreateParams;
2478 LRESULT ret;
2479 CLIENTCREATESTRUCT ccs;
2480 CLIENTCREATESTRUCT16 *ccs16 = MapSL( PtrToUlong( orig ));
2482 ccs.hWindowMenu = HMENU_32(ccs16->hWindowMenu);
2483 ccs.idFirstChild = ccs16->idFirstChild;
2484 cs->lpCreateParams = &ccs;
2485 ret = wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2486 cs->lpCreateParams = orig;
2487 return ret;
2490 return wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2494 /***********************************************************************
2495 * scrollbar_proc16
2497 static LRESULT scrollbar_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2499 static const UINT msg16_offset = SBM_SETPOS16 - SBM_SETPOS;
2501 switch (msg)
2503 case SBM_SETPOS16:
2504 case SBM_GETPOS16:
2505 case SBM_ENABLE_ARROWS16:
2506 msg -= msg16_offset;
2507 break;
2508 case SBM_SETRANGE16:
2509 msg = wParam ? SBM_SETRANGEREDRAW : SBM_SETRANGE;
2510 wParam = LOWORD(lParam);
2511 lParam = HIWORD(lParam);
2512 break;
2513 case SBM_GETRANGE16:
2515 INT min, max;
2516 wow_handlers32.scrollbar_proc( hwnd, SBM_GETRANGE, (WPARAM)&min, (LPARAM)&max, FALSE );
2517 return MAKELRESULT(min, max);
2519 default:
2520 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, unicode );
2522 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, FALSE );
2526 /***********************************************************************
2527 * static_proc16
2529 static LRESULT static_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2531 switch (msg)
2533 case WM_NCCREATE:
2535 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
2536 LRESULT ret = wow_handlers32.static_proc( hwnd, msg, wParam, lParam, unicode );
2538 if (!ret) return 0;
2539 if (((ULONG_PTR)cs->hInstance >> 16)) return ret; /* 32-bit instance, nothing to do */
2540 switch (cs->style & SS_TYPEMASK)
2542 case SS_ICON:
2544 HICON16 icon = LoadIcon16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2545 if (!icon) icon = LoadCursor16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2546 if (icon) wow_handlers32.static_proc( hwnd, STM_SETIMAGE, IMAGE_ICON,
2547 (LPARAM)get_icon_32(icon), FALSE );
2548 break;
2550 case SS_BITMAP:
2552 HBITMAP16 bitmap = LoadBitmap16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2553 if (bitmap) wow_handlers32.static_proc( hwnd, STM_SETIMAGE, IMAGE_BITMAP,
2554 (LPARAM)HBITMAP_32(bitmap), FALSE );
2555 break;
2558 return ret;
2560 case STM_SETICON16:
2561 wParam = (WPARAM)get_icon_32( (HICON16)wParam );
2562 return wow_handlers32.static_proc( hwnd, STM_SETICON, wParam, lParam, FALSE );
2563 case STM_GETICON16:
2564 return get_icon_16( (HICON)wow_handlers32.static_proc( hwnd, STM_GETICON, wParam, lParam, FALSE ));
2565 default:
2566 return wow_handlers32.static_proc( hwnd, msg, wParam, lParam, unicode );
2571 /***********************************************************************
2572 * create_window16
2574 HWND create_window16( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE instance, BOOL unicode )
2576 /* map to module handle */
2577 if (instance && !((ULONG_PTR)instance >> 16))
2578 instance = HINSTANCE_32( GetExePtr( HINSTANCE_16(instance) ));
2580 return wow_handlers32.create_window( cs, className, instance, unicode );
2584 static void WINAPI User16CallFreeIcon( ULONG *param, ULONG size )
2586 GlobalFree16( LOWORD(*param) );
2590 static DWORD WINAPI User16ThunkLock( DWORD *param, ULONG size )
2592 if (size != sizeof(DWORD))
2594 DWORD lock;
2595 ReleaseThunkLock( &lock );
2596 return lock;
2598 RestoreThunkLock( *param );
2599 return 0;
2603 void register_wow_handlers(void)
2605 void **callback_table = NtCurrentTeb()->Peb->KernelCallbackTable;
2606 static const struct wow_handlers16 handlers16 =
2608 button_proc16,
2609 combo_proc16,
2610 edit_proc16,
2611 listbox_proc16,
2612 mdiclient_proc16,
2613 scrollbar_proc16,
2614 static_proc16,
2615 create_window16,
2616 call_window_proc_Ato16,
2617 call_dialog_proc_Ato16,
2620 callback_table[NtUserCallFreeIcon] = User16CallFreeIcon;
2621 callback_table[NtUserThunkLock] = User16ThunkLock;
2623 NtUserEnableThunkLock( TRUE );
2625 UserRegisterWowHandlers( &handlers16, &wow_handlers32 );