winevulkan: Update to VK spec version 1.2.195.
[wine.git] / dlls / user.exe16 / message.c
blob93e2cc018bf4e569bb470f55e2c25743dfc7a818
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 call_window_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
82 LRESULT *result, void *arg )
84 WNDPROC proc = arg;
85 *result = CallWindowProcA( proc, hwnd, msg, wp, lp );
86 return *result;
90 /**********************************************************************
91 * Support for window procedure thunks
94 #include "pshpack1.h"
95 typedef struct
97 WORD popl_eax; /* popl %eax (return address) */
98 WORD pushl_func; /* pushl $proc */
99 WNDPROC proc;
100 WORD pushl_eax; /* pushl %eax */
101 BYTE ljmp; /* ljmp relay*/
102 FARPROC16 relay; /* __wine_call_wndproc */
103 } WINPROC_THUNK;
104 #include "poppack.h"
106 #define WINPROC_HANDLE (~0u >> 16)
107 #define MAX_WINPROCS32 4096
108 #define MAX_WINPROCS16 1024
110 static WNDPROC16 winproc16_array[MAX_WINPROCS16];
111 static unsigned int winproc16_used;
113 static WINPROC_THUNK *thunk_array;
114 static UINT thunk_selector;
116 /* return the window proc index for a given handle, or -1 for an invalid handle
117 * indices 0 .. MAX_WINPROCS32-1 are for 32-bit procs,
118 * indices MAX_WINPROCS32 .. MAX_WINPROCS32+MAX_WINPROCS16-1 for 16-bit procs */
119 static int winproc_to_index( WNDPROC16 handle )
121 unsigned int index;
123 if (HIWORD(handle) == thunk_selector)
125 index = LOWORD(handle) / sizeof(WINPROC_THUNK);
126 /* check alignment */
127 if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return -1;
128 /* check array limits */
129 if (index >= MAX_WINPROCS32) return -1;
131 else
133 index = LOWORD(handle);
134 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return -1;
135 /* check array limits */
136 if (index >= winproc16_used + MAX_WINPROCS32) return -1;
138 return index;
141 /* allocate a 16-bit thunk for an existing window proc */
142 static WNDPROC16 alloc_win16_thunk( WNDPROC handle )
144 static FARPROC16 relay;
145 WINPROC_THUNK *thunk;
146 UINT index = LOWORD( handle );
148 if (index >= MAX_WINPROCS32) /* already a 16-bit proc */
149 return winproc16_array[index - MAX_WINPROCS32];
151 if (!thunk_array) /* allocate the array and its selector */
153 assert( MAX_WINPROCS16 * sizeof(WINPROC_THUNK) <= 0x10000 );
155 if (!(thunk_selector = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
156 MAX_WINPROCS16 * sizeof(WINPROC_THUNK) )))
157 return NULL;
158 PrestoChangoSelector16( thunk_selector, thunk_selector );
159 thunk_array = GlobalLock16( thunk_selector );
160 relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
163 thunk = &thunk_array[index];
164 thunk->popl_eax = 0x5866; /* popl %eax */
165 thunk->pushl_func = 0x6866; /* pushl $proc */
166 thunk->proc = handle;
167 thunk->pushl_eax = 0x5066; /* pushl %eax */
168 thunk->ljmp = 0xea; /* ljmp relay*/
169 thunk->relay = relay;
170 return (WNDPROC16)MAKESEGPTR( thunk_selector, index * sizeof(WINPROC_THUNK) );
173 /**********************************************************************
174 * WINPROC_AllocProc16
176 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
178 int index;
179 WNDPROC ret;
181 if (!func) return NULL;
183 /* check if the function is already a win proc */
184 if ((index = winproc_to_index( func )) != -1)
185 return (WNDPROC)(ULONG_PTR)(index | (WINPROC_HANDLE << 16));
187 /* then check if we already have a winproc for that function */
188 for (index = 0; index < winproc16_used; index++)
189 if (winproc16_array[index] == func) goto done;
191 if (winproc16_used >= MAX_WINPROCS16)
193 FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
194 return NULL;
196 winproc16_array[winproc16_used++] = func;
198 done:
199 ret = (WNDPROC)(ULONG_PTR)((index + MAX_WINPROCS32) | (WINPROC_HANDLE << 16));
200 TRACE( "returning %p for %p/16-bit (%d/%d used)\n",
201 ret, func, winproc16_used, MAX_WINPROCS16 );
202 return ret;
205 /**********************************************************************
206 * WINPROC_GetProc16
208 * Get a window procedure pointer that can be passed to the Windows program.
210 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
212 WNDPROC winproc = wow_handlers32.alloc_winproc( proc, unicode );
214 if ((ULONG_PTR)winproc >> 16 != WINPROC_HANDLE) return (WNDPROC16)winproc;
215 return alloc_win16_thunk( winproc );
218 /* call a 16-bit window procedure */
219 static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
220 LRESULT *result, void *arg )
222 DPI_AWARENESS_CONTEXT awareness;
223 WNDPROC16 func = arg;
224 int index = winproc_to_index( func );
225 CONTEXT context;
226 size_t size = 0;
227 struct
229 WORD params[5];
230 union
232 CREATESTRUCT16 cs16;
233 DRAWITEMSTRUCT16 dis16;
234 COMPAREITEMSTRUCT16 cis16;
235 } u;
236 } args;
238 if (index >= MAX_WINPROCS32) func = winproc16_array[index - MAX_WINPROCS32];
240 /* Window procedures want ax = hInstance, ds = es = ss */
242 memset(&context, 0, sizeof(context));
243 context.SegDs = context.SegEs = CURRENT_SS;
244 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
245 context.SegCs = SELECTOROF(func);
246 context.Eip = OFFSETOF(func);
247 context.Ebp = CURRENT_SP + FIELD_OFFSET(STACK16FRAME, bp);
249 if (lParam)
251 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
252 work if structures passed in lParam are placed in the stack/data
253 segment. Programmers easily make the mistake of converting lParam
254 to a near rather than a far pointer, since Windows apparently
255 allows this. We copy the structures to the 16 bit stack; this is
256 ugly but makes these programs work. */
257 switch (msg)
259 case WM_CREATE:
260 case WM_NCCREATE:
261 size = sizeof(CREATESTRUCT16); break;
262 case WM_DRAWITEM:
263 size = sizeof(DRAWITEMSTRUCT16); break;
264 case WM_COMPAREITEM:
265 size = sizeof(COMPAREITEMSTRUCT16); break;
267 if (size)
269 memcpy( &args.u, MapSL(lParam), size );
270 lParam = MAKESEGPTR( CURRENT_SS, CURRENT_SP - size );
274 awareness = SetThreadDpiAwarenessContext( GetWindowDpiAwarenessContext( HWND_32(hwnd) ));
275 args.params[4] = hwnd;
276 args.params[3] = msg;
277 args.params[2] = wParam;
278 args.params[1] = HIWORD(lParam);
279 args.params[0] = LOWORD(lParam);
280 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
281 *result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
282 SetThreadDpiAwarenessContext( awareness );
283 return *result;
286 static LRESULT call_dialog_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
287 LRESULT *result, void *arg )
289 LRESULT ret = call_window_proc16( hwnd, msg, wp, lp, result, arg );
290 *result = GetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT );
291 return LOWORD(ret);
294 static LRESULT call_window_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
295 LRESULT *result, void *arg )
297 return WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wp, lp, result, arg );
300 static LRESULT call_dialog_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
301 LRESULT *result, void *arg )
303 return WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wp, lp, result, arg );
308 /**********************************************************************
309 * Support for Edit word break proc thunks
312 #define MAX_THUNKS 32
314 #include <pshpack1.h>
315 static struct word_break_thunk
317 BYTE popl_eax; /* popl %eax (return address) */
318 BYTE pushl_proc16; /* pushl proc16 */
319 EDITWORDBREAKPROC16 proc16;
320 BYTE pushl_eax; /* pushl %eax */
321 BYTE jmp; /* ljmp call_word_break_proc16 */
322 DWORD callback;
323 } *word_break_thunks;
324 #include <poppack.h>
326 /**********************************************************************
327 * call_word_break_proc16
329 static INT16 CALLBACK call_word_break_proc16( SEGPTR proc16, LPSTR text, INT index, INT count, INT action )
331 SEGPTR segptr;
332 WORD args[5];
333 DWORD result;
335 segptr = MapLS( text );
336 args[4] = SELECTOROF(segptr);
337 args[3] = OFFSETOF(segptr);
338 args[2] = index;
339 args[1] = count;
340 args[0] = action;
341 WOWCallback16Ex( proc16, WCB16_PASCAL, sizeof(args), args, &result );
342 UnMapLS( segptr );
343 return LOWORD(result);
346 /******************************************************************
347 * add_word_break_thunk
349 static struct word_break_thunk *add_word_break_thunk( EDITWORDBREAKPROC16 proc16 )
351 struct word_break_thunk *thunk;
353 if (!word_break_thunks)
355 word_break_thunks = VirtualAlloc( NULL, MAX_THUNKS * sizeof(*thunk),
356 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
357 if (!word_break_thunks) return NULL;
359 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
361 thunk->popl_eax = 0x58; /* popl %eax */
362 thunk->pushl_proc16 = 0x68; /* pushl proc16 */
363 thunk->pushl_eax = 0x50; /* pushl %eax */
364 thunk->jmp = 0xe9; /* jmp call_word_break_proc16 */
365 thunk->callback = (char *)call_word_break_proc16 - (char *)(&thunk->callback + 1);
368 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
369 if (thunk->proc16 == proc16) return thunk;
371 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
373 if (thunk->proc16) continue;
374 thunk->proc16 = proc16;
375 return thunk;
377 FIXME("Out of word break thunks\n");
378 return NULL;
381 /******************************************************************
382 * get_word_break_thunk
384 static EDITWORDBREAKPROC16 get_word_break_thunk( EDITWORDBREAKPROCA proc )
386 struct word_break_thunk *thunk = (struct word_break_thunk *)proc;
387 if (word_break_thunks && thunk >= word_break_thunks && thunk < &word_break_thunks[MAX_THUNKS])
388 return thunk->proc16;
389 return NULL;
393 /***********************************************************************
394 * Support for 16<->32 message mapping
397 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
399 if (size >= need) return static_buffer;
400 return HeapAlloc( GetProcessHeap(), 0, need );
403 static inline void free_buffer( void *static_buffer, void *buffer )
405 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
408 static void RECT16to32( const RECT16 *from, RECT *to )
410 to->left = from->left;
411 to->top = from->top;
412 to->right = from->right;
413 to->bottom = from->bottom;
416 static void RECT32to16( const RECT *from, RECT16 *to )
418 to->left = from->left;
419 to->top = from->top;
420 to->right = from->right;
421 to->bottom = from->bottom;
424 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
426 to->ptReserved.x = from->ptReserved.x;
427 to->ptReserved.y = from->ptReserved.y;
428 to->ptMaxSize.x = from->ptMaxSize.x;
429 to->ptMaxSize.y = from->ptMaxSize.y;
430 to->ptMaxPosition.x = from->ptMaxPosition.x;
431 to->ptMaxPosition.y = from->ptMaxPosition.y;
432 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
433 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
434 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
435 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
438 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
440 to->ptReserved.x = from->ptReserved.x;
441 to->ptReserved.y = from->ptReserved.y;
442 to->ptMaxSize.x = from->ptMaxSize.x;
443 to->ptMaxSize.y = from->ptMaxSize.y;
444 to->ptMaxPosition.x = from->ptMaxPosition.x;
445 to->ptMaxPosition.y = from->ptMaxPosition.y;
446 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
447 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
448 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
449 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
452 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
454 to->hwnd = HWND_16(from->hwnd);
455 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
456 to->x = from->x;
457 to->y = from->y;
458 to->cx = from->cx;
459 to->cy = from->cy;
460 to->flags = from->flags;
463 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
465 to->hwnd = WIN_Handle32(from->hwnd);
466 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
467 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
468 to->x = from->x;
469 to->y = from->y;
470 to->cx = from->cx;
471 to->cy = from->cy;
472 to->flags = from->flags;
475 /* The strings are not copied */
476 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
478 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
479 to->hInstance = HINSTANCE_16(from->hInstance);
480 to->hMenu = HMENU_16(from->hMenu);
481 to->hwndParent = HWND_16(from->hwndParent);
482 to->cy = from->cy;
483 to->cx = from->cx;
484 to->y = from->y;
485 to->x = from->x;
486 to->style = from->style;
487 to->dwExStyle = from->dwExStyle;
490 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
493 to->lpCreateParams = (LPVOID)from->lpCreateParams;
494 to->hInstance = HINSTANCE_32(from->hInstance);
495 to->hMenu = HMENU_32(from->hMenu);
496 to->hwndParent = WIN_Handle32(from->hwndParent);
497 to->cy = from->cy;
498 to->cx = from->cx;
499 to->y = from->y;
500 to->x = from->x;
501 to->style = from->style;
502 to->dwExStyle = from->dwExStyle;
503 to->lpszName = MapSL(from->lpszName);
504 to->lpszClass = MapSL(from->lpszClass);
507 /* The strings are not copied */
508 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
510 to->hOwner = HINSTANCE_16(from->hOwner);
511 to->x = from->x;
512 to->y = from->y;
513 to->cx = from->cx;
514 to->cy = from->cy;
515 to->style = from->style;
516 to->lParam = from->lParam;
519 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
521 to->hOwner = HINSTANCE_32(from->hOwner);
522 to->x = from->x;
523 to->y = from->y;
524 to->cx = from->cx;
525 to->cy = from->cy;
526 to->style = from->style;
527 to->lParam = from->lParam;
528 to->szTitle = MapSL(from->szTitle);
529 to->szClass = MapSL(from->szClass);
532 static UINT_PTR convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
534 HANDLE dst;
535 UINT sz = GlobalSize16(src);
536 LPSTR ptr16, ptr32;
538 if (!(dst = GlobalAlloc(flags, sz)))
539 return 0;
540 ptr16 = GlobalLock16(src);
541 ptr32 = GlobalLock(dst);
542 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
543 GlobalUnlock16(src);
544 GlobalUnlock(dst);
546 return (UINT_PTR)dst;
549 static HANDLE16 convert_handle_32_to_16(UINT_PTR src, unsigned int flags)
551 HANDLE16 dst;
552 UINT sz = GlobalSize((HANDLE)src);
553 LPSTR ptr16, ptr32;
555 if (!(dst = GlobalAlloc16(flags, sz)))
556 return 0;
557 ptr32 = GlobalLock((HANDLE)src);
558 ptr16 = GlobalLock16(dst);
559 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
560 GlobalUnlock((HANDLE)src);
561 GlobalUnlock16(dst);
563 return dst;
566 static BOOL is_old_app( HWND hwnd )
568 HINSTANCE inst = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
569 return inst && !((ULONG_PTR)inst >> 16) && (GetExpWinVer16(LOWORD(inst)) & 0xFF00) == 0x0300;
572 static int find_sub_menu( HMENU *hmenu, HMENU16 target )
574 int i, pos, count = GetMenuItemCount( *hmenu );
576 for (i = 0; i < count; i++)
578 HMENU sub = GetSubMenu( *hmenu, i );
579 if (!sub) continue;
580 if (HMENU_16(sub) == target) return i;
581 if ((pos = find_sub_menu( &sub, target )) != -1)
583 *hmenu = sub;
584 return pos;
587 return -1;
590 /**********************************************************************
591 * WINPROC_CallProc16To32A
593 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
594 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
596 LRESULT ret = 0;
597 HWND hwnd32 = WIN_Handle32( hwnd );
599 switch(msg)
601 case WM_NCCREATE:
602 case WM_CREATE:
604 CREATESTRUCT16 *cs16 = MapSL(lParam);
605 CREATESTRUCTA cs;
606 MDICREATESTRUCTA mdi_cs;
608 CREATESTRUCT16to32A( cs16, &cs );
609 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
611 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
612 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
613 cs.lpCreateParams = &mdi_cs;
615 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
616 CREATESTRUCT32Ato16( &cs, cs16 );
618 break;
619 case WM_MDICREATE:
621 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
622 MDICREATESTRUCTA cs;
624 MDICREATESTRUCT16to32A( cs16, &cs );
625 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
626 MDICREATESTRUCT32Ato16( &cs, cs16 );
628 break;
629 case WM_MDIACTIVATE:
630 if (lParam)
631 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
632 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
633 else /* message sent to MDI client */
634 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
635 break;
636 case WM_MDIGETACTIVE:
638 BOOL maximized = FALSE;
639 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
640 *result = MAKELRESULT( LOWORD(*result), maximized );
642 break;
643 case WM_MDISETMENU:
644 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
645 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
646 result, arg );
647 break;
648 case WM_GETMINMAXINFO:
650 MINMAXINFO16 *mmi16 = MapSL(lParam);
651 MINMAXINFO mmi;
653 MINMAXINFO16to32( mmi16, &mmi );
654 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
655 MINMAXINFO32to16( &mmi, mmi16 );
657 break;
658 case WM_WINDOWPOSCHANGING:
659 case WM_WINDOWPOSCHANGED:
661 WINDOWPOS16 *winpos16 = MapSL(lParam);
662 WINDOWPOS winpos;
664 WINDOWPOS16to32( winpos16, &winpos );
665 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
666 WINDOWPOS32to16( &winpos, winpos16 );
668 break;
669 case WM_NCCALCSIZE:
671 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
672 NCCALCSIZE_PARAMS nc;
673 WINDOWPOS winpos;
675 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
676 if (wParam)
678 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
679 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
680 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
681 nc.lppos = &winpos;
683 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
684 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
685 if (wParam)
687 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
688 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
689 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
692 break;
693 case WM_COMPAREITEM:
695 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
696 COMPAREITEMSTRUCT cis;
697 cis.CtlType = cis16->CtlType;
698 cis.CtlID = cis16->CtlID;
699 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
700 cis.itemID1 = cis16->itemID1;
701 cis.itemData1 = cis16->itemData1;
702 cis.itemID2 = cis16->itemID2;
703 cis.itemData2 = cis16->itemData2;
704 cis.dwLocaleId = 0; /* FIXME */
705 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
707 break;
708 case WM_DELETEITEM:
710 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
711 DELETEITEMSTRUCT dis;
712 dis.CtlType = dis16->CtlType;
713 dis.CtlID = dis16->CtlID;
714 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
715 dis.itemData = dis16->itemData;
716 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
718 break;
719 case WM_MEASUREITEM:
721 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
722 MEASUREITEMSTRUCT mis;
723 mis.CtlType = mis16->CtlType;
724 mis.CtlID = mis16->CtlID;
725 mis.itemID = mis16->itemID;
726 mis.itemWidth = mis16->itemWidth;
727 mis.itemHeight = mis16->itemHeight;
728 mis.itemData = mis16->itemData;
729 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
730 mis16->itemWidth = (UINT16)mis.itemWidth;
731 mis16->itemHeight = (UINT16)mis.itemHeight;
733 break;
734 case WM_DRAWITEM:
736 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
737 DRAWITEMSTRUCT dis;
738 dis.CtlType = dis16->CtlType;
739 dis.CtlID = dis16->CtlID;
740 dis.itemID = dis16->itemID;
741 dis.itemAction = dis16->itemAction;
742 dis.itemState = dis16->itemState;
743 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
744 : WIN_Handle32( dis16->hwndItem );
745 dis.hDC = HDC_32(dis16->hDC);
746 dis.itemData = dis16->itemData;
747 dis.rcItem.left = dis16->rcItem.left;
748 dis.rcItem.top = dis16->rcItem.top;
749 dis.rcItem.right = dis16->rcItem.right;
750 dis.rcItem.bottom = dis16->rcItem.bottom;
751 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
753 break;
754 case WM_COPYDATA:
756 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
757 COPYDATASTRUCT cds;
758 cds.dwData = cds16->dwData;
759 cds.cbData = cds16->cbData;
760 cds.lpData = MapSL(cds16->lpData);
761 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
763 break;
764 case WM_GETDLGCODE:
765 if (lParam)
767 MSG16 *msg16 = MapSL(lParam);
768 MSG msg32;
769 msg32.hwnd = WIN_Handle32( msg16->hwnd );
770 msg32.message = msg16->message;
771 msg32.wParam = msg16->wParam;
772 msg32.lParam = msg16->lParam;
773 msg32.time = msg16->time;
774 msg32.pt.x = msg16->pt.x;
775 msg32.pt.y = msg16->pt.y;
776 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
778 else
779 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
780 break;
781 case WM_NEXTMENU:
783 MDINEXTMENU next;
784 next.hmenuIn = (HMENU)lParam;
785 next.hmenuNext = 0;
786 next.hwndNext = 0;
787 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
788 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
790 break;
791 case WM_ACTIVATE:
792 case WM_CHARTOITEM:
793 case WM_COMMAND:
794 case WM_VKEYTOITEM:
795 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
796 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
797 break;
798 case WM_HSCROLL:
799 case WM_VSCROLL:
800 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
801 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
802 break;
803 case WM_CTLCOLOR:
804 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
805 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
806 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
807 result, arg );
808 break;
809 case WM_GETTEXT:
810 case WM_SETTEXT:
811 case WM_WININICHANGE:
812 case WM_DEVMODECHANGE:
813 case WM_ASKCBFORMATNAME:
814 case WM_NOTIFY:
815 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
816 break;
817 case WM_MENUCHAR:
818 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
819 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
820 break;
821 case WM_MENUSELECT:
822 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
824 HMENU hmenu = HMENU_32(HIWORD(lParam));
825 int pos = find_sub_menu( &hmenu, wParam );
826 if (pos == -1) pos = 0;
827 wParam = pos;
829 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
830 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
831 break;
832 case WM_PARENTNOTIFY:
833 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
834 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
835 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
836 else
837 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
838 break;
839 case WM_ACTIVATEAPP:
840 /* We need this when SetActiveWindow sends a Sendmessage16() to
841 * a 32-bit window. Might be superfluous with 32-bit interprocess
842 * message queues. */
843 if (lParam) lParam = HTASK_32(lParam);
844 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
845 break;
846 case WM_DDE_INITIATE:
847 case WM_DDE_TERMINATE:
848 case WM_DDE_UNADVISE:
849 case WM_DDE_REQUEST:
850 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
851 break;
852 case WM_DDE_ADVISE:
853 case WM_DDE_DATA:
854 case WM_DDE_POKE:
856 HANDLE16 lo16 = LOWORD(lParam);
857 UINT_PTR lo32 = 0;
858 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
859 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
860 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
862 break; /* FIXME don't know how to free allocated memory (handle) !! */
863 case WM_DDE_ACK:
865 UINT_PTR lo = LOWORD(lParam);
866 UINT_PTR hi = HIWORD(lParam);
867 int flag = 0;
868 char buf[2];
870 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
871 if (GlobalSize16(hi) != 0) flag |= 2;
872 switch (flag)
874 case 0:
875 if (hi)
877 WARN("DDE_ACK: neither atom nor handle!!!\n");
878 hi = 0;
880 break;
881 case 1:
882 break; /* atom, nothing to do */
883 case 3:
884 WARN("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
885 /* fall through */
886 case 2:
887 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
888 break;
890 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
891 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
893 break; /* FIXME don't know how to free allocated memory (handle) !! */
894 case WM_DDE_EXECUTE:
895 lParam = convert_handle_16_to_32( HIWORD(lParam), GMEM_DDESHARE );
896 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
897 break; /* FIXME don't know how to free allocated memory (handle) !! */
898 case WM_PAINTCLIPBOARD:
899 case WM_SIZECLIPBOARD:
900 FIXME_(msg)( "message %04x needs translation\n", msg );
901 break;
902 default:
903 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
904 break;
906 return ret;
910 /**********************************************************************
911 * WINPROC_CallProc32ATo16
913 * Call a 16-bit window procedure, translating the 32-bit args.
915 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
916 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
918 LRESULT ret = 0;
920 switch(msg)
922 case WM_NCCREATE:
923 case WM_CREATE:
925 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
926 CREATESTRUCT16 cs;
927 MDICREATESTRUCT16 mdi_cs16;
928 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
930 CREATESTRUCT32Ato16( cs32, &cs );
931 cs.lpszName = MapLS( cs32->lpszName );
932 cs.lpszClass = MapLS( cs32->lpszClass );
934 if (mdi_child)
936 MDICREATESTRUCTA *mdi_cs = cs32->lpCreateParams;
937 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
938 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
939 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
940 cs.lpCreateParams = MapLS( &mdi_cs16 );
942 lParam = MapLS( &cs );
943 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
944 UnMapLS( lParam );
945 UnMapLS( cs.lpszName );
946 UnMapLS( cs.lpszClass );
947 if (mdi_child)
949 UnMapLS( cs.lpCreateParams );
950 UnMapLS( mdi_cs16.szTitle );
951 UnMapLS( mdi_cs16.szClass );
954 break;
955 case WM_MDICREATE:
957 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
958 MDICREATESTRUCT16 cs;
960 MDICREATESTRUCT32Ato16( cs32, &cs );
961 cs.szTitle = MapLS( cs32->szTitle );
962 cs.szClass = MapLS( cs32->szClass );
963 lParam = MapLS( &cs );
964 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
965 UnMapLS( lParam );
966 UnMapLS( cs.szTitle );
967 UnMapLS( cs.szClass );
969 break;
970 case WM_MDIACTIVATE:
971 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
972 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
973 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
974 else
975 ret = callback( HWND_16(hwnd), msg, HWND_16( wParam ), 0, result, arg );
976 break;
977 case WM_MDIGETACTIVE:
978 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
979 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
980 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
981 break;
982 case WM_MDISETMENU:
983 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
984 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
985 break;
986 case WM_GETMINMAXINFO:
988 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
989 MINMAXINFO16 mmi;
991 MINMAXINFO32to16( mmi32, &mmi );
992 lParam = MapLS( &mmi );
993 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
994 UnMapLS( lParam );
995 MINMAXINFO16to32( &mmi, mmi32 );
997 break;
998 case WM_NCCALCSIZE:
1000 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
1001 NCCALCSIZE_PARAMS16 nc;
1002 WINDOWPOS16 winpos;
1004 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
1005 if (wParam)
1007 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
1008 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
1009 WINDOWPOS32to16( nc32->lppos, &winpos );
1010 nc.lppos = MapLS( &winpos );
1012 lParam = MapLS( &nc );
1013 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1014 UnMapLS( lParam );
1015 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
1016 if (wParam)
1018 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
1019 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
1020 WINDOWPOS16to32( &winpos, nc32->lppos );
1021 UnMapLS( nc.lppos );
1024 break;
1025 case WM_WINDOWPOSCHANGING:
1026 case WM_WINDOWPOSCHANGED:
1028 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
1029 WINDOWPOS16 winpos;
1031 WINDOWPOS32to16( winpos32, &winpos );
1032 lParam = MapLS( &winpos );
1033 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1034 UnMapLS( lParam );
1035 WINDOWPOS16to32( &winpos, winpos32 );
1037 break;
1038 case WM_COMPAREITEM:
1040 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
1041 COMPAREITEMSTRUCT16 cis;
1042 cis.CtlType = cis32->CtlType;
1043 cis.CtlID = cis32->CtlID;
1044 cis.hwndItem = HWND_16( cis32->hwndItem );
1045 cis.itemID1 = cis32->itemID1;
1046 cis.itemData1 = cis32->itemData1;
1047 cis.itemID2 = cis32->itemID2;
1048 cis.itemData2 = cis32->itemData2;
1049 lParam = MapLS( &cis );
1050 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1051 UnMapLS( lParam );
1053 break;
1054 case WM_DELETEITEM:
1056 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
1057 DELETEITEMSTRUCT16 dis;
1058 dis.CtlType = dis32->CtlType;
1059 dis.CtlID = dis32->CtlID;
1060 dis.itemID = dis32->itemID;
1061 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1062 : HWND_16( dis32->hwndItem );
1063 dis.itemData = dis32->itemData;
1064 lParam = MapLS( &dis );
1065 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1066 UnMapLS( lParam );
1068 break;
1069 case WM_DRAWITEM:
1071 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
1072 DRAWITEMSTRUCT16 dis;
1073 dis.CtlType = dis32->CtlType;
1074 dis.CtlID = dis32->CtlID;
1075 dis.itemID = dis32->itemID;
1076 dis.itemAction = dis32->itemAction;
1077 dis.itemState = dis32->itemState;
1078 dis.hwndItem = HWND_16( dis32->hwndItem );
1079 dis.hDC = HDC_16(dis32->hDC);
1080 dis.itemData = dis32->itemData;
1081 dis.rcItem.left = dis32->rcItem.left;
1082 dis.rcItem.top = dis32->rcItem.top;
1083 dis.rcItem.right = dis32->rcItem.right;
1084 dis.rcItem.bottom = dis32->rcItem.bottom;
1085 lParam = MapLS( &dis );
1086 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1087 UnMapLS( lParam );
1089 break;
1090 case WM_MEASUREITEM:
1092 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
1093 MEASUREITEMSTRUCT16 mis;
1094 mis.CtlType = mis32->CtlType;
1095 mis.CtlID = mis32->CtlID;
1096 mis.itemID = mis32->itemID;
1097 mis.itemWidth = mis32->itemWidth;
1098 mis.itemHeight = mis32->itemHeight;
1099 mis.itemData = mis32->itemData;
1100 lParam = MapLS( &mis );
1101 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1102 UnMapLS( lParam );
1103 mis32->itemWidth = mis.itemWidth;
1104 mis32->itemHeight = mis.itemHeight;
1106 break;
1107 case WM_COPYDATA:
1109 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
1110 COPYDATASTRUCT16 cds;
1112 cds.dwData = cds32->dwData;
1113 cds.cbData = cds32->cbData;
1114 cds.lpData = MapLS( cds32->lpData );
1115 lParam = MapLS( &cds );
1116 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1117 UnMapLS( lParam );
1118 UnMapLS( cds.lpData );
1120 break;
1121 case WM_GETDLGCODE:
1122 if (lParam)
1124 MSG *msg32 = (MSG *)lParam;
1125 MSG16 msg16;
1127 msg16.hwnd = HWND_16( msg32->hwnd );
1128 msg16.message = msg32->message;
1129 msg16.wParam = msg32->wParam;
1130 msg16.lParam = msg32->lParam;
1131 msg16.time = msg32->time;
1132 msg16.pt.x = msg32->pt.x;
1133 msg16.pt.y = msg32->pt.y;
1134 lParam = MapLS( &msg16 );
1135 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1136 UnMapLS( lParam );
1138 else
1139 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1140 break;
1141 case WM_NEXTMENU:
1143 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1144 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
1145 next->hmenuNext = HMENU_32( LOWORD(*result) );
1146 next->hwndNext = WIN_Handle32( HIWORD(*result) );
1147 *result = 0;
1149 break;
1150 case WM_GETTEXT:
1151 case WM_ASKCBFORMATNAME:
1152 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
1153 /* fall through */
1154 case WM_NOTIFY:
1155 case WM_SETTEXT:
1156 case WM_WININICHANGE:
1157 case WM_DEVMODECHANGE:
1158 lParam = MapLS( (void *)lParam );
1159 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1160 UnMapLS( lParam );
1161 break;
1162 case WM_ACTIVATE:
1163 case WM_CHARTOITEM:
1164 case WM_COMMAND:
1165 case WM_VKEYTOITEM:
1166 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ),
1167 result, arg );
1168 break;
1169 case WM_HSCROLL:
1170 case WM_VSCROLL:
1171 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( HIWORD(wParam), (HWND16)lParam ),
1172 result, arg );
1173 break;
1174 case WM_CTLCOLORMSGBOX:
1175 case WM_CTLCOLOREDIT:
1176 case WM_CTLCOLORLISTBOX:
1177 case WM_CTLCOLORBTN:
1178 case WM_CTLCOLORDLG:
1179 case WM_CTLCOLORSCROLLBAR:
1180 case WM_CTLCOLORSTATIC:
1181 ret = callback( HWND_16(hwnd), WM_CTLCOLOR, wParam,
1182 MAKELPARAM( (HWND16)lParam, msg - WM_CTLCOLORMSGBOX ), result, arg );
1183 break;
1184 case WM_MENUSELECT:
1185 if(HIWORD(wParam) & MF_POPUP)
1187 HMENU hmenu;
1188 if ((HIWORD(wParam) != 0xffff) || lParam)
1190 if ((hmenu = GetSubMenu( (HMENU)lParam, LOWORD(wParam) )))
1192 ret = callback( HWND_16(hwnd), msg, HMENU_16(hmenu),
1193 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1194 break;
1198 /* fall through */
1199 case WM_MENUCHAR:
1200 ret = callback( HWND_16(hwnd), msg, wParam,
1201 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1202 break;
1203 case WM_PARENTNOTIFY:
1204 if ((LOWORD(wParam) == WM_CREATE) || (LOWORD(wParam) == WM_DESTROY))
1205 ret = callback( HWND_16(hwnd), msg, wParam,
1206 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ), result, arg );
1207 else
1208 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1209 break;
1210 case WM_ACTIVATEAPP:
1211 ret = callback( HWND_16(hwnd), msg, wParam, HTASK_16( lParam ), result, arg );
1212 break;
1213 case WM_PAINT:
1214 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
1215 ret = callback( HWND_16(hwnd), WM_PAINTICON, 1, lParam, result, arg );
1216 else
1217 ret = callback( HWND_16(hwnd), WM_PAINT, wParam, lParam, result, arg );
1218 break;
1219 case WM_ERASEBKGND:
1220 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON )) msg = WM_ICONERASEBKGND;
1221 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1222 break;
1223 case WM_DDE_INITIATE:
1224 case WM_DDE_TERMINATE:
1225 case WM_DDE_UNADVISE:
1226 case WM_DDE_REQUEST:
1227 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam), lParam, result, arg );
1228 break;
1229 case WM_DDE_ADVISE:
1230 case WM_DDE_DATA:
1231 case WM_DDE_POKE:
1233 UINT_PTR lo32, hi;
1234 HANDLE16 lo16 = 0;
1236 UnpackDDElParam( msg, lParam, &lo32, &hi );
1237 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
1238 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1239 MAKELPARAM(lo16, hi), result, arg );
1241 break; /* FIXME don't know how to free allocated memory (handle) !! */
1242 case WM_DDE_ACK:
1244 UINT_PTR lo, hi;
1245 int flag = 0;
1246 char buf[2];
1248 UnpackDDElParam( msg, lParam, &lo, &hi );
1250 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
1251 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
1252 switch (flag)
1254 case 0:
1255 if (hi)
1257 WARN("DDE_ACK: neither atom nor handle!!!\n");
1258 hi = 0;
1260 break;
1261 case 1:
1262 break; /* atom, nothing to do */
1263 case 3:
1264 WARN("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
1265 /* fall through */
1266 case 2:
1267 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
1268 break;
1270 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1271 MAKELPARAM(lo, hi), result, arg );
1273 break; /* FIXME don't know how to free allocated memory (handle) !! */
1274 case WM_DDE_EXECUTE:
1275 lParam = MAKELPARAM( 0, convert_handle_32_to_16( lParam, GMEM_DDESHARE ));
1276 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1277 break; /* FIXME don't know how to free allocated memory (handle) !! */
1278 case SBM_SETRANGE:
1279 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
1280 break;
1281 case SBM_GETRANGE:
1282 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
1283 *(LPINT)wParam = LOWORD(*result);
1284 *(LPINT)lParam = HIWORD(*result);
1285 break;
1286 case BM_GETCHECK:
1287 case BM_SETCHECK:
1288 case BM_GETSTATE:
1289 case BM_SETSTATE:
1290 case BM_SETSTYLE:
1291 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
1292 break;
1293 case EM_GETSEL:
1294 case EM_GETRECT:
1295 case EM_SETRECT:
1296 case EM_SETRECTNP:
1297 case EM_SCROLL:
1298 case EM_LINESCROLL:
1299 case EM_SCROLLCARET:
1300 case EM_GETMODIFY:
1301 case EM_SETMODIFY:
1302 case EM_GETLINECOUNT:
1303 case EM_LINEINDEX:
1304 case EM_SETHANDLE:
1305 case EM_GETHANDLE:
1306 case EM_GETTHUMB:
1307 case EM_LINELENGTH:
1308 case EM_REPLACESEL:
1309 case EM_GETLINE:
1310 case EM_LIMITTEXT:
1311 case EM_CANUNDO:
1312 case EM_UNDO:
1313 case EM_FMTLINES:
1314 case EM_LINEFROMCHAR:
1315 case EM_SETTABSTOPS:
1316 case EM_SETPASSWORDCHAR:
1317 case EM_EMPTYUNDOBUFFER:
1318 case EM_GETFIRSTVISIBLELINE:
1319 case EM_SETREADONLY:
1320 case EM_SETWORDBREAKPROC:
1321 case EM_GETWORDBREAKPROC:
1322 case EM_GETPASSWORDCHAR:
1323 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
1324 break;
1325 case EM_SETSEL:
1326 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
1327 break;
1328 case LB_CARETOFF:
1329 case LB_CARETON:
1330 case LB_DELETESTRING:
1331 case LB_GETANCHORINDEX:
1332 case LB_GETCARETINDEX:
1333 case LB_GETCOUNT:
1334 case LB_GETCURSEL:
1335 case LB_GETHORIZONTALEXTENT:
1336 case LB_GETITEMDATA:
1337 case LB_GETITEMHEIGHT:
1338 case LB_GETSEL:
1339 case LB_GETSELCOUNT:
1340 case LB_GETTEXTLEN:
1341 case LB_GETTOPINDEX:
1342 case LB_RESETCONTENT:
1343 case LB_SELITEMRANGE:
1344 case LB_SELITEMRANGEEX:
1345 case LB_SETANCHORINDEX:
1346 case LB_SETCARETINDEX:
1347 case LB_SETCOLUMNWIDTH:
1348 case LB_SETCURSEL:
1349 case LB_SETHORIZONTALEXTENT:
1350 case LB_SETITEMDATA:
1351 case LB_SETITEMHEIGHT:
1352 case LB_SETSEL:
1353 case LB_SETTOPINDEX:
1354 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1355 break;
1356 case LB_ADDSTRING:
1357 case LB_FINDSTRING:
1358 case LB_FINDSTRINGEXACT:
1359 case LB_INSERTSTRING:
1360 case LB_SELECTSTRING:
1361 case LB_GETTEXT:
1362 case LB_DIR:
1363 case LB_ADDFILE:
1364 lParam = MapLS( (LPSTR)lParam );
1365 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1366 UnMapLS( lParam );
1367 break;
1368 case LB_GETSELITEMS:
1370 INT *items32 = (INT *)lParam;
1371 INT16 *items, buffer[512];
1372 unsigned int i;
1374 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1375 if (!(items = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1376 lParam = MapLS( items );
1377 ret = callback( HWND_16(hwnd), LB_GETSELITEMS16, wParam, lParam, result, arg );
1378 UnMapLS( lParam );
1379 for (i = 0; i < wParam; i++) items32[i] = items[i];
1380 free_buffer( buffer, items );
1382 break;
1383 case LB_SETTABSTOPS:
1384 if (wParam)
1386 INT *stops32 = (INT *)lParam;
1387 INT16 *stops, buffer[512];
1388 unsigned int i;
1390 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1391 if (!(stops = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1392 for (i = 0; i < wParam; i++) stops[i] = stops32[i];
1393 lParam = MapLS( stops );
1394 ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1395 UnMapLS( lParam );
1396 free_buffer( buffer, stops );
1398 else ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1399 break;
1400 case CB_DELETESTRING:
1401 case CB_GETCOUNT:
1402 case CB_GETLBTEXTLEN:
1403 case CB_LIMITTEXT:
1404 case CB_RESETCONTENT:
1405 case CB_SETEDITSEL:
1406 case CB_GETCURSEL:
1407 case CB_SETCURSEL:
1408 case CB_SHOWDROPDOWN:
1409 case CB_SETITEMDATA:
1410 case CB_SETITEMHEIGHT:
1411 case CB_GETITEMHEIGHT:
1412 case CB_SETEXTENDEDUI:
1413 case CB_GETEXTENDEDUI:
1414 case CB_GETDROPPEDSTATE:
1415 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1416 break;
1417 case CB_GETEDITSEL:
1418 ret = callback( HWND_16(hwnd), CB_GETEDITSEL16, wParam, lParam, result, arg );
1419 if (wParam) *((PUINT)(wParam)) = LOWORD(*result);
1420 if (lParam) *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: subtract 1? */
1421 break;
1422 case CB_ADDSTRING:
1423 case CB_FINDSTRING:
1424 case CB_FINDSTRINGEXACT:
1425 case CB_INSERTSTRING:
1426 case CB_SELECTSTRING:
1427 case CB_DIR:
1428 case CB_GETLBTEXT:
1429 lParam = MapLS( (LPSTR)lParam );
1430 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1431 UnMapLS( lParam );
1432 break;
1433 case LB_GETITEMRECT:
1434 case CB_GETDROPPEDCONTROLRECT:
1436 RECT *r32 = (RECT *)lParam;
1437 RECT16 rect;
1438 lParam = MapLS( &rect );
1439 ret = callback( HWND_16(hwnd),
1440 (msg == LB_GETITEMRECT) ? LB_GETITEMRECT16 : CB_GETDROPPEDCONTROLRECT16,
1441 wParam, lParam, result, arg );
1442 UnMapLS( lParam );
1443 RECT16to32( &rect, r32 );
1445 break;
1446 case WM_PAINTCLIPBOARD:
1447 case WM_SIZECLIPBOARD:
1448 FIXME_(msg)( "message %04x needs translation\n", msg );
1449 break;
1450 /* the following messages should not be sent to 16-bit apps */
1451 case WM_SIZING:
1452 case WM_MOVING:
1453 case WM_CAPTURECHANGED:
1454 case WM_STYLECHANGING:
1455 case WM_STYLECHANGED:
1456 break;
1457 default:
1458 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1459 break;
1461 return ret;
1465 /***********************************************************************
1466 * SendMessage (USER.111)
1468 LRESULT WINAPI SendMessage16( HWND16 hwnd16, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1470 LRESULT result;
1471 HWND hwnd = WIN_Handle32( hwnd16 );
1473 if (hwnd != HWND_BROADCAST &&
1474 GetWindowThreadProcessId( hwnd, NULL ) == GetCurrentThreadId())
1476 /* call 16-bit window proc directly */
1477 WNDPROC16 winproc;
1479 /* first the WH_CALLWNDPROC hook */
1480 call_WH_CALLWNDPROC_hook( hwnd16, msg, wparam, lparam );
1482 if (!(winproc = (WNDPROC16)GetWindowLong16( hwnd16, GWLP_WNDPROC ))) return 0;
1484 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx\n", hwnd16, msg, wparam, lparam );
1485 result = CallWindowProc16( winproc, hwnd16, msg, wparam, lparam );
1486 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx returned %08lx\n",
1487 hwnd16, msg, wparam, lparam, result );
1489 else /* map to 32-bit unicode for inter-thread/process message */
1491 WINPROC_CallProc16To32A( send_message_callback, hwnd16, msg, wparam, lparam, &result, NULL );
1493 return result;
1497 /***********************************************************************
1498 * PostMessage (USER.110)
1500 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1502 LRESULT unused;
1503 return WINPROC_CallProc16To32A( post_message_callback, hwnd, msg, wparam, lparam, &unused, NULL );
1507 /***********************************************************************
1508 * PostAppMessage (USER.116)
1510 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1512 LRESULT unused;
1513 DWORD_PTR tid = HTASK_32( hTask );
1515 if (!tid) return FALSE;
1516 return WINPROC_CallProc16To32A( post_thread_message_callback, 0, msg, wparam, lparam,
1517 &unused, (void *)tid );
1521 /**********************************************************************
1522 * CallWindowProc (USER.122)
1524 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
1525 WPARAM16 wParam, LPARAM lParam )
1527 int index = winproc_to_index( func );
1528 LRESULT result;
1530 if (!func) return 0;
1532 if (index == -1 || index >= MAX_WINPROCS32)
1533 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
1534 else
1536 WNDPROC proc = (WNDPROC)func;
1537 if (thunk_array && thunk_array[index].proc) proc = thunk_array[index].proc;
1538 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1540 return result;
1544 /**********************************************************************
1545 * __wine_call_wndproc (USER.1010)
1547 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam, WNDPROC proc )
1549 LRESULT result;
1550 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1551 return result;
1555 /***********************************************************************
1556 * InSendMessage (USER.192)
1558 BOOL16 WINAPI InSendMessage16(void)
1560 return InSendMessage();
1564 /***********************************************************************
1565 * ReplyMessage (USER.115)
1567 void WINAPI ReplyMessage16( LRESULT result )
1569 ReplyMessage( result );
1573 /***********************************************************************
1574 * PeekMessage32 (USER.819)
1576 BOOL16 WINAPI PeekMessage32_16( MSG32_16 *msg16, HWND16 hwnd16,
1577 UINT16 first, UINT16 last, UINT16 flags,
1578 BOOL16 wHaveParamHigh )
1580 MSG msg;
1581 LRESULT unused;
1582 HWND hwnd = WIN_Handle32( hwnd16 );
1584 if(USER16_AlertableWait)
1585 MsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, MWMO_ALERTABLE );
1586 if (!PeekMessageA( &msg, hwnd, first, last, flags )) return FALSE;
1588 msg16->msg.time = msg.time;
1589 msg16->msg.pt.x = (INT16)msg.pt.x;
1590 msg16->msg.pt.y = (INT16)msg.pt.y;
1591 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1592 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1593 &unused, &msg16->msg );
1594 return TRUE;
1598 /***********************************************************************
1599 * DefWindowProc (USER.107)
1601 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1603 LRESULT result;
1604 HWND hwnd = WIN_Handle32( hwnd16 );
1606 switch(msg)
1608 case WM_NCCREATE:
1610 CREATESTRUCT16 *cs16 = MapSL(lParam);
1611 CREATESTRUCTA cs32;
1613 cs32.lpCreateParams = ULongToPtr(cs16->lpCreateParams);
1614 cs32.hInstance = HINSTANCE_32(cs16->hInstance);
1615 cs32.hMenu = HMENU_32(cs16->hMenu);
1616 cs32.hwndParent = WIN_Handle32(cs16->hwndParent);
1617 cs32.cy = cs16->cy;
1618 cs32.cx = cs16->cx;
1619 cs32.y = cs16->y;
1620 cs32.x = cs16->x;
1621 cs32.style = cs16->style;
1622 cs32.dwExStyle = cs16->dwExStyle;
1623 cs32.lpszName = MapSL(cs16->lpszName);
1624 cs32.lpszClass = MapSL(cs16->lpszClass);
1625 return DefWindowProcA( hwnd, msg, wParam, (LPARAM)&cs32 );
1627 case WM_NCCALCSIZE:
1629 RECT16 *rect16 = MapSL(lParam);
1630 RECT rect32;
1632 rect32.left = rect16->left;
1633 rect32.top = rect16->top;
1634 rect32.right = rect16->right;
1635 rect32.bottom = rect16->bottom;
1637 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)&rect32 );
1639 rect16->left = rect32.left;
1640 rect16->top = rect32.top;
1641 rect16->right = rect32.right;
1642 rect16->bottom = rect32.bottom;
1643 return result;
1645 case WM_WINDOWPOSCHANGING:
1646 case WM_WINDOWPOSCHANGED:
1648 WINDOWPOS16 *pos16 = MapSL(lParam);
1649 WINDOWPOS pos32;
1651 pos32.hwnd = WIN_Handle32(pos16->hwnd);
1652 pos32.hwndInsertAfter = WIN_Handle32(pos16->hwndInsertAfter);
1653 pos32.x = pos16->x;
1654 pos32.y = pos16->y;
1655 pos32.cx = pos16->cx;
1656 pos32.cy = pos16->cy;
1657 pos32.flags = pos16->flags;
1659 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)&pos32 );
1661 pos16->hwnd = HWND_16(pos32.hwnd);
1662 pos16->hwndInsertAfter = HWND_16(pos32.hwndInsertAfter);
1663 pos16->x = pos32.x;
1664 pos16->y = pos32.y;
1665 pos16->cx = pos32.cx;
1666 pos16->cy = pos32.cy;
1667 pos16->flags = pos32.flags;
1668 return result;
1670 case WM_GETTEXT:
1671 case WM_SETTEXT:
1672 return DefWindowProcA( hwnd, msg, wParam, (LPARAM)MapSL(lParam) );
1673 default:
1674 return DefWindowProcA( hwnd, msg, wParam, lParam );
1679 /***********************************************************************
1680 * DefDlgProc (USER.308)
1682 LRESULT WINAPI DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1684 LRESULT result;
1685 WINPROC_CallProc16To32A( defdlg_proc_callback, hwnd, msg, wParam, lParam, &result, 0 );
1686 return result;
1690 /***********************************************************************
1691 * PeekMessage (USER.109)
1693 BOOL16 WINAPI PeekMessage16( MSG16 *msg, HWND16 hwnd,
1694 UINT16 first, UINT16 last, UINT16 flags )
1696 return PeekMessage32_16( (MSG32_16 *)msg, hwnd, first, last, flags, FALSE );
1700 /***********************************************************************
1701 * GetMessage32 (USER.820)
1703 BOOL16 WINAPI GetMessage32_16( MSG32_16 *msg16, HWND16 hwnd16, UINT16 first,
1704 UINT16 last, BOOL16 wHaveParamHigh )
1706 MSG msg;
1707 LRESULT unused;
1708 HWND hwnd = WIN_Handle32( hwnd16 );
1710 if(USER16_AlertableWait)
1711 MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, 0, MWMO_ALERTABLE );
1712 GetMessageA( &msg, hwnd, first, last );
1713 msg16->msg.time = msg.time;
1714 msg16->msg.pt.x = (INT16)msg.pt.x;
1715 msg16->msg.pt.y = (INT16)msg.pt.y;
1716 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1717 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1718 &unused, &msg16->msg );
1720 TRACE( "message %04x, hwnd %p, filter(%04x - %04x)\n",
1721 msg16->msg.message, hwnd, first, last );
1723 return msg16->msg.message != WM_QUIT;
1727 /***********************************************************************
1728 * GetMessage (USER.108)
1730 BOOL16 WINAPI GetMessage16( MSG16 *msg, HWND16 hwnd, UINT16 first, UINT16 last )
1732 return GetMessage32_16( (MSG32_16 *)msg, hwnd, first, last, FALSE );
1736 /***********************************************************************
1737 * TranslateMessage32 (USER.821)
1739 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
1741 MSG msg32;
1743 msg32.hwnd = WIN_Handle32( msg->msg.hwnd );
1744 msg32.message = msg->msg.message;
1745 msg32.wParam = MAKEWPARAM( msg->msg.wParam, wHaveParamHigh ? msg->wParamHigh : 0 );
1746 msg32.lParam = msg->msg.lParam;
1747 return TranslateMessage( &msg32 );
1751 /***********************************************************************
1752 * TranslateMessage (USER.113)
1754 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1756 return TranslateMessage32_16( (const MSG32_16 *)msg, FALSE );
1760 /***********************************************************************
1761 * DispatchMessage (USER.114)
1763 LONG WINAPI DispatchMessage16( const MSG16* msg )
1765 WNDPROC16 winproc;
1766 LRESULT retval;
1768 /* Process timer messages */
1769 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1771 if (msg->lParam)
1772 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1773 msg->message, msg->wParam, GetTickCount() );
1776 if (!(winproc = (WNDPROC16)GetWindowLong16( msg->hwnd, GWLP_WNDPROC )))
1778 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1779 return 0;
1781 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx\n", msg->hwnd, msg->message, msg->wParam, msg->lParam );
1782 retval = CallWindowProc16( winproc, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1783 TRACE_(message)("(0x%04x) [%04x] wp=%04x lp=%08lx returned %08lx\n",
1784 msg->hwnd, msg->message, msg->wParam, msg->lParam, retval );
1785 return retval;
1789 /***********************************************************************
1790 * DispatchMessage32 (USER.822)
1792 LONG WINAPI DispatchMessage32_16( const MSG32_16 *msg16, BOOL16 wHaveParamHigh )
1794 if (wHaveParamHigh == FALSE)
1795 return DispatchMessage16( &msg16->msg );
1796 else
1798 MSG msg;
1800 msg.hwnd = WIN_Handle32( msg16->msg.hwnd );
1801 msg.message = msg16->msg.message;
1802 msg.wParam = MAKEWPARAM( msg16->msg.wParam, msg16->wParamHigh );
1803 msg.lParam = msg16->msg.lParam;
1804 msg.time = msg16->msg.time;
1805 msg.pt.x = msg16->msg.pt.x;
1806 msg.pt.y = msg16->msg.pt.y;
1807 return DispatchMessageA( &msg );
1812 /***********************************************************************
1813 * IsDialogMessage (USER.90)
1815 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, MSG16 *msg16 )
1817 MSG msg;
1818 HWND hwndDlg32;
1820 msg.hwnd = WIN_Handle32(msg16->hwnd);
1821 hwndDlg32 = WIN_Handle32(hwndDlg);
1823 switch(msg16->message)
1825 case WM_KEYDOWN:
1826 case WM_CHAR:
1827 case WM_SYSCHAR:
1828 msg.message = msg16->message;
1829 msg.wParam = msg16->wParam;
1830 msg.lParam = msg16->lParam;
1831 msg.time = msg16->time;
1832 msg.pt.x = msg16->pt.x;
1833 msg.pt.y = msg16->pt.y;
1834 return IsDialogMessageA( hwndDlg32, &msg );
1837 if ((hwndDlg32 != msg.hwnd) && !IsChild( hwndDlg32, msg.hwnd )) return FALSE;
1838 TranslateMessage16( msg16 );
1839 DispatchMessage16( msg16 );
1840 return TRUE;
1844 /***********************************************************************
1845 * MsgWaitForMultipleObjects (USER.640)
1847 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD count, const HANDLE *handles,
1848 BOOL wait_all, DWORD timeout, DWORD mask )
1850 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
1851 wait_all ? MWMO_WAITALL : 0 );
1855 /**********************************************************************
1856 * SetDoubleClickTime (USER.20)
1858 void WINAPI SetDoubleClickTime16( UINT16 interval )
1860 SetDoubleClickTime( interval );
1864 /**********************************************************************
1865 * GetDoubleClickTime (USER.21)
1867 UINT16 WINAPI GetDoubleClickTime16(void)
1869 return GetDoubleClickTime();
1873 /***********************************************************************
1874 * PostQuitMessage (USER.6)
1876 void WINAPI PostQuitMessage16( INT16 exitCode )
1878 PostQuitMessage( exitCode );
1882 /**********************************************************************
1883 * GetKeyState (USER.106)
1885 INT16 WINAPI GetKeyState16(INT16 vkey)
1887 return GetKeyState(vkey);
1891 /**********************************************************************
1892 * GetKeyboardState (USER.222)
1894 BOOL WINAPI GetKeyboardState16( LPBYTE state )
1896 return GetKeyboardState( state );
1900 /**********************************************************************
1901 * SetKeyboardState (USER.223)
1903 BOOL WINAPI SetKeyboardState16( LPBYTE state )
1905 return SetKeyboardState( state );
1909 /***********************************************************************
1910 * SetMessageQueue (USER.266)
1912 BOOL16 WINAPI SetMessageQueue16( INT16 size )
1914 return SetMessageQueue( size );
1918 /***********************************************************************
1919 * UserYield (USER.332)
1921 void WINAPI UserYield16(void)
1923 MSG msg;
1924 PeekMessageW( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
1928 /***********************************************************************
1929 * GetQueueStatus (USER.334)
1931 DWORD WINAPI GetQueueStatus16( UINT16 flags )
1933 return GetQueueStatus( flags );
1937 /***********************************************************************
1938 * GetInputState (USER.335)
1940 BOOL16 WINAPI GetInputState16(void)
1942 return GetInputState();
1946 /**********************************************************************
1947 * TranslateAccelerator (USER.178)
1949 INT16 WINAPI TranslateAccelerator16( HWND16 hwnd, HACCEL16 hAccel, LPMSG16 msg )
1951 MSG msg32;
1953 if (!msg) return 0;
1954 msg32.message = msg->message;
1955 /* msg32.hwnd not used */
1956 msg32.wParam = msg->wParam;
1957 msg32.lParam = msg->lParam;
1958 return TranslateAcceleratorW( WIN_Handle32(hwnd), HACCEL_32(hAccel), &msg32 );
1962 /**********************************************************************
1963 * TranslateMDISysAccel (USER.451)
1965 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1967 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1969 MSG msg32;
1970 msg32.hwnd = WIN_Handle32(msg->hwnd);
1971 msg32.message = msg->message;
1972 msg32.wParam = msg->wParam;
1973 msg32.lParam = msg->lParam;
1974 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1975 return TranslateMDISysAccel( WIN_Handle32(hwndClient), &msg32 );
1977 return 0;
1981 /***********************************************************************
1982 * button_proc16
1984 static LRESULT button_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
1986 static const UINT msg16_offset = BM_GETCHECK16 - BM_GETCHECK;
1988 switch (msg)
1990 case BM_GETCHECK16:
1991 case BM_SETCHECK16:
1992 case BM_GETSTATE16:
1993 case BM_SETSTATE16:
1994 case BM_SETSTYLE16:
1995 return wow_handlers32.button_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
1996 default:
1997 return wow_handlers32.button_proc( hwnd, msg, wParam, lParam, unicode );
2002 /***********************************************************************
2003 * combo_proc16
2005 static LRESULT combo_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2007 static const UINT msg16_offset = CB_GETEDITSEL16 - CB_GETEDITSEL;
2009 switch (msg)
2011 case CB_INSERTSTRING16:
2012 case CB_SELECTSTRING16:
2013 case CB_FINDSTRING16:
2014 case CB_FINDSTRINGEXACT16:
2015 wParam = (INT)(INT16)wParam;
2016 /* fall through */
2017 case CB_ADDSTRING16:
2019 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2020 if ((style & CBS_HASSTRINGS) || !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)))
2021 lParam = (LPARAM)MapSL(lParam);
2022 msg -= msg16_offset;
2023 break;
2025 case CB_SETITEMHEIGHT16:
2026 case CB_GETITEMHEIGHT16:
2027 case CB_SETCURSEL16:
2028 case CB_GETLBTEXTLEN16:
2029 case CB_GETITEMDATA16:
2030 case CB_SETITEMDATA16:
2031 wParam = (INT)(INT16)wParam; /* signed integer */
2032 msg -= msg16_offset;
2033 break;
2034 case CB_GETDROPPEDCONTROLRECT16:
2035 lParam = (LPARAM)MapSL(lParam);
2036 if (lParam)
2038 RECT r;
2039 RECT16 *r16 = (RECT16 *)lParam;
2040 wow_handlers32.combo_proc( hwnd, CB_GETDROPPEDCONTROLRECT, wParam, (LPARAM)&r, FALSE );
2041 r16->left = r.left;
2042 r16->top = r.top;
2043 r16->right = r.right;
2044 r16->bottom = r.bottom;
2046 return CB_OKAY;
2047 case CB_DIR16:
2048 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
2049 lParam = (LPARAM)MapSL(lParam);
2050 msg -= msg16_offset;
2051 break;
2052 case CB_GETLBTEXT16:
2053 wParam = (INT)(INT16)wParam;
2054 lParam = (LPARAM)MapSL(lParam);
2055 msg -= msg16_offset;
2056 break;
2057 case CB_GETEDITSEL16:
2058 wParam = lParam = 0; /* just in case */
2059 msg -= msg16_offset;
2060 break;
2061 case CB_LIMITTEXT16:
2062 case CB_SETEDITSEL16:
2063 case CB_DELETESTRING16:
2064 case CB_RESETCONTENT16:
2065 case CB_GETDROPPEDSTATE16:
2066 case CB_SHOWDROPDOWN16:
2067 case CB_GETCOUNT16:
2068 case CB_GETCURSEL16:
2069 case CB_SETEXTENDEDUI16:
2070 case CB_GETEXTENDEDUI16:
2071 msg -= msg16_offset;
2072 break;
2073 default:
2074 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, unicode );
2076 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, FALSE );
2079 /*********************************************************************
2080 * edit_lock_buffer (internal)
2082 * A 16 bit application might send an EM_GETHANDLE message and expect a HLOCAL16
2083 * (16 bit SEG:OFF handler). From that moment on we have to keep using this
2084 * 16 bit memory handler, because it is supposed to be valid at all times after
2085 * EM_GETHANDLE.
2086 * We create a HLOCAL16 buffer in edit_get_handle and copy the text from the
2087 * HLOCAL buffer, when needed
2091 #define GWW_HANDLE16 sizeof(void*)
2093 static void edit_lock_buffer( HWND hwnd )
2095 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2096 HANDLE16 oldDS;
2097 HLOCAL hloc32;
2098 UINT size;
2100 if (!hloc16) return;
2101 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2103 oldDS = CURRENT_DS;
2104 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2105 size = LocalSize16(hloc16);
2106 if (LocalReAlloc( hloc32, size, LMEM_MOVEABLE ))
2108 char *text = MapSL( LocalLock16( hloc16 ));
2109 char *dest = LocalLock( hloc32 );
2110 memcpy( dest, text, size );
2111 LocalUnlock( hloc32 );
2112 LocalUnlock16( hloc16 );
2114 CURRENT_DS = oldDS;
2117 static void edit_unlock_buffer( HWND hwnd )
2119 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2120 HANDLE16 oldDS;
2121 HLOCAL hloc32;
2122 UINT size;
2124 if (!hloc16) return;
2125 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2126 size = LocalSize( hloc32 );
2128 oldDS = CURRENT_DS;
2129 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2130 if (LocalReAlloc16( hloc16, size, LMEM_MOVEABLE ))
2132 char *text = LocalLock( hloc32 );
2133 char *dest = MapSL( LocalLock16( hloc16 ));
2134 memcpy( dest, text, size );
2135 LocalUnlock( hloc32 );
2136 LocalUnlock16( hloc16 );
2138 CURRENT_DS = oldDS;
2141 static HLOCAL16 edit_get_handle( HWND hwnd )
2143 CHAR *textA;
2144 UINT alloc_size;
2145 HLOCAL hloc;
2146 HANDLE16 oldDS;
2147 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2149 if (hloc16) return hloc16;
2151 if (!(hloc = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return 0;
2152 alloc_size = LocalSize( hloc );
2154 oldDS = CURRENT_DS;
2155 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2157 if (!LocalHeapSize16())
2159 if (!LocalInit16(CURRENT_DS, 0, GlobalSize16(CURRENT_DS)))
2161 ERR("could not initialize local heap\n");
2162 goto done;
2166 if (!(hloc16 = LocalAlloc16(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
2168 ERR("could not allocate new 16 bit buffer\n");
2169 goto done;
2172 if (!(textA = MapSL(LocalLock16( hloc16))))
2174 ERR("could not lock new 16 bit buffer\n");
2175 LocalFree16(hloc16);
2176 hloc16 = 0;
2177 goto done;
2179 memcpy( textA, LocalLock( hloc ), alloc_size );
2180 LocalUnlock( hloc );
2181 LocalUnlock16( hloc16 );
2182 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2184 done:
2185 CURRENT_DS = oldDS;
2186 return hloc16;
2189 static void edit_set_handle( HWND hwnd, HLOCAL16 hloc16 )
2191 HINSTANCE16 hInstance = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2192 HANDLE16 oldDS = CURRENT_DS;
2193 HLOCAL hloc32;
2194 INT count;
2195 CHAR *text;
2197 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) return;
2198 if (!hloc16) return;
2200 CURRENT_DS = hInstance;
2201 count = LocalSize16(hloc16);
2202 text = MapSL(LocalLock16(hloc16));
2203 if ((hloc32 = LocalAlloc(LMEM_MOVEABLE, count)))
2205 memcpy( LocalLock(hloc32), text, count );
2206 LocalUnlock(hloc32);
2207 LocalUnlock16(hloc16);
2208 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2210 CURRENT_DS = oldDS;
2211 if (hloc32) wow_handlers32.edit_proc( hwnd, EM_SETHANDLE, (WPARAM)hloc32, 0, FALSE );
2214 static void edit_destroy_handle( HWND hwnd )
2216 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2217 if (hloc16)
2219 HANDLE16 oldDS = CURRENT_DS;
2221 CURRENT_DS = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2222 while (LocalUnlock16(hloc16)) ;
2223 LocalFree16(hloc16);
2224 CURRENT_DS = oldDS;
2225 SetWindowWord( hwnd, GWW_HANDLE16, 0 );
2229 /*********************************************************************
2230 * edit_proc16
2232 static LRESULT edit_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2234 static const UINT msg16_offset = EM_GETSEL16 - EM_GETSEL;
2235 LRESULT result = 0;
2237 edit_lock_buffer( hwnd );
2238 switch (msg)
2240 case EM_SCROLL16:
2241 case EM_SCROLLCARET16:
2242 case EM_GETMODIFY16:
2243 case EM_SETMODIFY16:
2244 case EM_GETLINECOUNT16:
2245 case EM_GETTHUMB16:
2246 case EM_LINELENGTH16:
2247 case EM_LIMITTEXT16:
2248 case EM_CANUNDO16:
2249 case EM_UNDO16:
2250 case EM_FMTLINES16:
2251 case EM_LINEFROMCHAR16:
2252 case EM_SETPASSWORDCHAR16:
2253 case EM_EMPTYUNDOBUFFER16:
2254 case EM_SETREADONLY16:
2255 case EM_GETPASSWORDCHAR16:
2256 /* these messages missing from specs */
2257 case WM_USER+15:
2258 case WM_USER+16:
2259 case WM_USER+19:
2260 case WM_USER+26:
2261 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2262 break;
2263 case EM_GETSEL16:
2264 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, 0, 0, FALSE );
2265 break;
2266 case EM_REPLACESEL16:
2267 case EM_GETLINE16:
2268 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)MapSL(lParam), FALSE );
2269 break;
2270 case EM_LINESCROLL16:
2271 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, (INT)(SHORT)HIWORD(lParam),
2272 (INT)(SHORT)LOWORD(lParam), FALSE );
2273 break;
2274 case EM_LINEINDEX16:
2275 if ((INT16)wParam == -1) wParam = -1;
2276 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2277 break;
2278 case EM_SETSEL16:
2279 if ((short)LOWORD(lParam) == -1)
2281 wParam = -1;
2282 lParam = 0;
2284 else
2286 wParam = LOWORD(lParam);
2287 lParam = HIWORD(lParam);
2289 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2290 break;
2291 case EM_GETRECT16:
2292 if (lParam)
2294 RECT rect;
2295 RECT16 *r16 = MapSL(lParam);
2296 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2297 r16->left = rect.left;
2298 r16->top = rect.top;
2299 r16->right = rect.right;
2300 r16->bottom = rect.bottom;
2302 break;
2303 case EM_SETRECT16:
2304 case EM_SETRECTNP16:
2305 if (lParam)
2307 RECT rect;
2308 RECT16 *r16 = MapSL(lParam);
2309 rect.left = r16->left;
2310 rect.top = r16->top;
2311 rect.right = r16->right;
2312 rect.bottom = r16->bottom;
2313 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2315 break;
2316 case EM_SETHANDLE16:
2317 edit_set_handle( hwnd, (HLOCAL16)wParam );
2318 break;
2319 case EM_GETHANDLE16:
2320 result = edit_get_handle( hwnd );
2321 break;
2322 case EM_SETTABSTOPS16:
2324 INT16 *tabs16 = MapSL(lParam);
2325 INT i, count = wParam, *tabs = NULL;
2326 if (count > 0)
2328 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*tabs) ))) return 0;
2329 for (i = 0; i < count; i++) tabs[i] = tabs16[i];
2331 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, count, (LPARAM)tabs, FALSE );
2332 HeapFree( GetProcessHeap(), 0, tabs );
2333 break;
2335 case EM_GETFIRSTVISIBLELINE16:
2336 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) break;
2337 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2338 break;
2339 case EM_SETWORDBREAKPROC16:
2341 struct word_break_thunk *thunk = add_word_break_thunk( (EDITWORDBREAKPROC16)lParam );
2342 result = wow_handlers32.edit_proc( hwnd, EM_SETWORDBREAKPROC, wParam, (LPARAM)thunk, FALSE );
2343 break;
2345 case EM_GETWORDBREAKPROC16:
2346 result = wow_handlers32.edit_proc( hwnd, EM_GETWORDBREAKPROC, wParam, lParam, FALSE );
2347 result = (LRESULT)get_word_break_thunk( (EDITWORDBREAKPROCA)result );
2348 break;
2349 case WM_NCDESTROY:
2350 edit_destroy_handle( hwnd );
2351 return wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode ); /* no unlock on destroy */
2352 case WM_HSCROLL:
2353 case WM_VSCROLL:
2354 if (LOWORD(wParam) == EM_GETTHUMB16 || LOWORD(wParam) == EM_LINESCROLL16) wParam -= msg16_offset;
2355 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2356 break;
2357 default:
2358 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2359 break;
2361 edit_unlock_buffer( hwnd );
2362 return result;
2366 /***********************************************************************
2367 * listbox_proc16
2369 static LRESULT listbox_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2371 static const UINT msg16_offset = LB_ADDSTRING16 - LB_ADDSTRING;
2372 LRESULT ret;
2374 switch (msg)
2376 case WM_SIZE:
2377 if (is_old_app( hwnd ))
2379 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2380 int height, remaining, item_height;
2381 RECT rect;
2383 /* give a margin for error to old 16 bits programs - if we need
2384 less than the height of the nonclient area, round to the
2385 *next* number of items */
2387 if (!(style & LBS_NOINTEGRALHEIGHT) && !(style & LBS_OWNERDRAWVARIABLE))
2389 GetClientRect( hwnd, &rect );
2390 height = rect.bottom - rect.top;
2391 item_height = wow_handlers32.listbox_proc( hwnd, LB_GETITEMHEIGHT, 0, 0, FALSE );
2392 remaining = item_height ? (height % item_height) : 0;
2393 if ((height > item_height) && remaining)
2395 GetWindowRect( hwnd, &rect );
2396 if ((item_height - remaining) <= rect.bottom - rect.top - height)
2397 remaining = remaining - item_height;
2398 TRACE( "[%p]: changing height %d -> %d\n", hwnd, height, height - remaining );
2399 SetWindowPos( hwnd, 0, 0, 0, rect.right - rect.left,
2400 rect.bottom - rect.top - remaining,
2401 SWP_NOZORDER | SWP_NOACTIVATE | SWP_NOMOVE );
2402 return 0;
2406 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, unicode );
2408 case LB_RESETCONTENT16:
2409 case LB_DELETESTRING16:
2410 case LB_GETITEMDATA16:
2411 case LB_SETITEMDATA16:
2412 case LB_GETCOUNT16:
2413 case LB_GETTEXTLEN16:
2414 case LB_GETCURSEL16:
2415 case LB_GETTOPINDEX16:
2416 case LB_GETITEMHEIGHT16:
2417 case LB_SETCARETINDEX16:
2418 case LB_GETCARETINDEX16:
2419 case LB_SETTOPINDEX16:
2420 case LB_SETCOLUMNWIDTH16:
2421 case LB_GETSELCOUNT16:
2422 case LB_SELITEMRANGE16:
2423 case LB_SELITEMRANGEEX16:
2424 case LB_GETHORIZONTALEXTENT16:
2425 case LB_SETHORIZONTALEXTENT16:
2426 case LB_GETANCHORINDEX16:
2427 case LB_CARETON16:
2428 case LB_CARETOFF16:
2429 msg -= msg16_offset;
2430 break;
2431 case LB_GETSEL16:
2432 case LB_SETSEL16:
2433 case LB_SETCURSEL16:
2434 case LB_SETANCHORINDEX16:
2435 wParam = (INT)(INT16)wParam;
2436 msg -= msg16_offset;
2437 break;
2438 case LB_INSERTSTRING16:
2439 case LB_FINDSTRING16:
2440 case LB_FINDSTRINGEXACT16:
2441 case LB_SELECTSTRING16:
2442 wParam = (INT)(INT16)wParam;
2443 /* fall through */
2444 case LB_ADDSTRING16:
2445 case LB_ADDFILE16:
2447 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2448 if ((style & LBS_HASSTRINGS) || !(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)))
2449 lParam = (LPARAM)MapSL(lParam);
2450 msg -= msg16_offset;
2451 break;
2453 case LB_GETTEXT16:
2454 lParam = (LPARAM)MapSL(lParam);
2455 msg -= msg16_offset;
2456 break;
2457 case LB_SETITEMHEIGHT16:
2458 lParam = LOWORD(lParam);
2459 msg -= msg16_offset;
2460 break;
2461 case LB_GETITEMRECT16:
2463 RECT rect;
2464 RECT16 *r16 = MapSL(lParam);
2465 ret = wow_handlers32.listbox_proc( hwnd, LB_GETITEMRECT, (INT16)wParam, (LPARAM)&rect, FALSE );
2466 r16->left = rect.left;
2467 r16->top = rect.top;
2468 r16->right = rect.right;
2469 r16->bottom = rect.bottom;
2470 return ret;
2472 case LB_GETSELITEMS16:
2474 INT16 *array16 = MapSL( lParam );
2475 INT i, count = (INT16)wParam, *array;
2476 if (!(array = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*array) ))) return LB_ERRSPACE;
2477 ret = wow_handlers32.listbox_proc( hwnd, LB_GETSELITEMS, count, (LPARAM)array, FALSE );
2478 for (i = 0; i < ret; i++) array16[i] = array[i];
2479 HeapFree( GetProcessHeap(), 0, array );
2480 return ret;
2482 case LB_DIR16:
2483 /* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE
2484 * be set automatically (this is different in Win32) */
2485 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
2486 lParam = (LPARAM)MapSL(lParam);
2487 msg -= msg16_offset;
2488 break;
2489 case LB_SETTABSTOPS16:
2491 INT i, count, *tabs = NULL;
2492 INT16 *tabs16 = MapSL( lParam );
2494 if ((count = (INT16)wParam) > 0)
2496 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*tabs) ))) return LB_ERRSPACE;
2497 for (i = 0; i < count; i++) tabs[i] = tabs16[i] << 1; /* FIXME */
2499 ret = wow_handlers32.listbox_proc( hwnd, LB_SETTABSTOPS, count, (LPARAM)tabs, FALSE );
2500 HeapFree( GetProcessHeap(), 0, tabs );
2501 return ret;
2503 default:
2504 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, unicode );
2506 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, FALSE );
2510 /***********************************************************************
2511 * mdiclient_proc16
2513 static LRESULT mdiclient_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2515 if (msg == WM_CREATE)
2517 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
2518 HINSTANCE instance = (HINSTANCE)GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2519 BOOL is_win32 = !instance || ((ULONG_PTR)instance >> 16);
2521 /* Translation layer doesn't know what's in the cs->lpCreateParams
2522 * so we have to keep track of what environment we're in. */
2523 if (!is_win32)
2525 void *orig = cs->lpCreateParams;
2526 LRESULT ret;
2527 CLIENTCREATESTRUCT ccs;
2528 CLIENTCREATESTRUCT16 *ccs16 = MapSL( PtrToUlong( orig ));
2530 ccs.hWindowMenu = HMENU_32(ccs16->hWindowMenu);
2531 ccs.idFirstChild = ccs16->idFirstChild;
2532 cs->lpCreateParams = &ccs;
2533 ret = wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2534 cs->lpCreateParams = orig;
2535 return ret;
2538 return wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2542 /***********************************************************************
2543 * scrollbar_proc16
2545 static LRESULT scrollbar_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2547 static const UINT msg16_offset = SBM_SETPOS16 - SBM_SETPOS;
2549 switch (msg)
2551 case SBM_SETPOS16:
2552 case SBM_GETPOS16:
2553 case SBM_ENABLE_ARROWS16:
2554 msg -= msg16_offset;
2555 break;
2556 case SBM_SETRANGE16:
2557 msg = wParam ? SBM_SETRANGEREDRAW : SBM_SETRANGE;
2558 wParam = LOWORD(lParam);
2559 lParam = HIWORD(lParam);
2560 break;
2561 case SBM_GETRANGE16:
2563 INT min, max;
2564 wow_handlers32.scrollbar_proc( hwnd, SBM_GETRANGE, (WPARAM)&min, (LPARAM)&max, FALSE );
2565 return MAKELRESULT(min, max);
2567 default:
2568 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, unicode );
2570 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, FALSE );
2574 /***********************************************************************
2575 * static_proc16
2577 static LRESULT static_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2579 switch (msg)
2581 case WM_NCCREATE:
2583 CREATESTRUCTA *cs = (CREATESTRUCTA *)lParam;
2584 LRESULT ret = wow_handlers32.static_proc( hwnd, msg, wParam, lParam, unicode );
2586 if (!ret) return 0;
2587 if (((ULONG_PTR)cs->hInstance >> 16)) return ret; /* 32-bit instance, nothing to do */
2588 switch (cs->style & SS_TYPEMASK)
2590 case SS_ICON:
2592 HICON16 icon = LoadIcon16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2593 if (!icon) icon = LoadCursor16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2594 if (icon) wow_handlers32.static_proc( hwnd, STM_SETIMAGE, IMAGE_ICON,
2595 (LPARAM)get_icon_32(icon), FALSE );
2596 break;
2598 case SS_BITMAP:
2600 HBITMAP16 bitmap = LoadBitmap16( HINSTANCE_16(cs->hInstance), cs->lpszName );
2601 if (bitmap) wow_handlers32.static_proc( hwnd, STM_SETIMAGE, IMAGE_BITMAP,
2602 (LPARAM)HBITMAP_32(bitmap), FALSE );
2603 break;
2606 return ret;
2608 case STM_SETICON16:
2609 wParam = (WPARAM)get_icon_32( (HICON16)wParam );
2610 return wow_handlers32.static_proc( hwnd, STM_SETICON, wParam, lParam, FALSE );
2611 case STM_GETICON16:
2612 return get_icon_16( (HICON)wow_handlers32.static_proc( hwnd, STM_GETICON, wParam, lParam, FALSE ));
2613 default:
2614 return wow_handlers32.static_proc( hwnd, msg, wParam, lParam, unicode );
2619 /***********************************************************************
2620 * wait_message16
2622 static DWORD wait_message16( DWORD count, const HANDLE *handles, DWORD timeout, DWORD mask, DWORD flags )
2624 DWORD lock, ret;
2626 ReleaseThunkLock( &lock );
2627 ret = wow_handlers32.wait_message( count, handles, timeout, mask, flags );
2628 RestoreThunkLock( lock );
2629 return ret;
2633 /***********************************************************************
2634 * create_window16
2636 HWND create_window16( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE instance, BOOL unicode )
2638 /* map to module handle */
2639 if (instance && !((ULONG_PTR)instance >> 16))
2640 instance = HINSTANCE_32( GetExePtr( HINSTANCE_16(instance) ));
2642 return wow_handlers32.create_window( cs, className, instance, unicode );
2646 /***********************************************************************
2647 * free_icon_param
2649 static void free_icon_param( ULONG_PTR param )
2651 GlobalFree16( LOWORD(param) );
2655 void register_wow_handlers(void)
2657 static const struct wow_handlers16 handlers16 =
2659 button_proc16,
2660 combo_proc16,
2661 edit_proc16,
2662 listbox_proc16,
2663 mdiclient_proc16,
2664 scrollbar_proc16,
2665 static_proc16,
2666 wait_message16,
2667 create_window16,
2668 call_window_proc_Ato16,
2669 call_dialog_proc_Ato16,
2670 free_icon_param
2673 UserRegisterWowHandlers( &handlers16, &wow_handlers32 );