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
22 #include "wine/port.h"
28 #include "wine/winuser16.h"
33 #include "user_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(msg);
39 DWORD USER16_AlertableWait = 0;
41 static struct wow_handlers32 wow_handlers32;
43 static LRESULT cwp_hook_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
44 LRESULT *result, void *arg )
53 return HOOK_CallHooks( WH_CALLWNDPROC, HC_ACTION, 1, (LPARAM)&cwp, FALSE );
56 static LRESULT send_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
57 LRESULT *result, void *arg )
59 *result = SendMessageA( hwnd, msg, wp, lp );
63 static LRESULT post_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
64 LRESULT *result, void *arg )
67 return PostMessageA( hwnd, msg, wp, lp );
70 static LRESULT post_thread_message_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
71 LRESULT *result, void *arg )
73 DWORD_PTR tid = (DWORD_PTR)arg;
75 return PostThreadMessageA( tid, msg, wp, lp );
78 static LRESULT get_message_callback( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
79 LRESULT *result, void *arg )
91 static LRESULT defdlg_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
92 LRESULT *result, void *arg )
94 *result = DefDlgProcA( hwnd, msg, wp, lp );
98 static LRESULT call_window_proc_callback( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
99 LRESULT *result, void *arg )
102 *result = CallWindowProcA( proc, hwnd, msg, wp, lp );
107 /**********************************************************************
108 * Support for window procedure thunks
111 #include "pshpack1.h"
114 BYTE popl_eax; /* popl %eax (return address) */
115 BYTE pushl_func; /* pushl $proc */
117 BYTE pushl_eax; /* pushl %eax */
118 BYTE ljmp; /* ljmp relay*/
119 DWORD relay_offset; /* __wine_call_wndproc */
124 #define WINPROC_HANDLE (~0u >> 16)
125 #define MAX_WINPROCS32 4096
126 #define MAX_WINPROCS16 1024
128 static WNDPROC16 winproc16_array[MAX_WINPROCS16];
129 static unsigned int winproc16_used;
131 static WINPROC_THUNK *thunk_array;
132 static UINT thunk_selector;
134 /* return the window proc index for a given handle, or -1 for an invalid handle
135 * indices 0 .. MAX_WINPROCS32-1 are for 32-bit procs,
136 * indices MAX_WINPROCS32 .. MAX_WINPROCS32+MAX_WINPROCS16-1 for 16-bit procs */
137 static int winproc_to_index( WNDPROC16 handle )
141 if (HIWORD(handle) == thunk_selector)
143 index = LOWORD(handle) / sizeof(WINPROC_THUNK);
144 /* check alignment */
145 if (index * sizeof(WINPROC_THUNK) != LOWORD(handle)) return -1;
146 /* check array limits */
147 if (index >= MAX_WINPROCS32) return -1;
151 index = LOWORD(handle);
152 if ((ULONG_PTR)handle >> 16 != WINPROC_HANDLE) return -1;
153 /* check array limits */
154 if (index >= winproc16_used + MAX_WINPROCS32) return -1;
159 /* allocate a 16-bit thunk for an existing window proc */
160 static WNDPROC16 alloc_win16_thunk( WNDPROC handle )
162 static FARPROC16 relay;
163 WINPROC_THUNK *thunk;
164 UINT index = LOWORD( handle );
166 if (index >= MAX_WINPROCS32) return (WNDPROC16)handle; /* already a 16-bit proc */
168 if (!thunk_array) /* allocate the array and its selector */
172 assert( MAX_WINPROCS16 * sizeof(WINPROC_THUNK) <= 0x10000 );
174 if (!(thunk_selector = wine_ldt_alloc_entries(1))) return NULL;
175 if (!(thunk_array = VirtualAlloc( NULL, MAX_WINPROCS16 * sizeof(WINPROC_THUNK), MEM_COMMIT,
176 PAGE_EXECUTE_READWRITE ))) return NULL;
177 wine_ldt_set_base( &entry, thunk_array );
178 wine_ldt_set_limit( &entry, MAX_WINPROCS16 * sizeof(WINPROC_THUNK) - 1 );
179 wine_ldt_set_flags( &entry, WINE_LDT_FLAGS_CODE | WINE_LDT_FLAGS_32BIT );
180 wine_ldt_set_entry( thunk_selector, &entry );
181 relay = GetProcAddress16( GetModuleHandle16("user"), "__wine_call_wndproc" );
184 thunk = &thunk_array[index];
185 thunk->popl_eax = 0x58; /* popl %eax */
186 thunk->pushl_func = 0x68; /* pushl $proc */
187 thunk->proc = handle;
188 thunk->pushl_eax = 0x50; /* pushl %eax */
189 thunk->ljmp = 0xea; /* ljmp relay*/
190 thunk->relay_offset = OFFSETOF(relay);
191 thunk->relay_sel = SELECTOROF(relay);
192 return (WNDPROC16)MAKESEGPTR( thunk_selector, index * sizeof(WINPROC_THUNK) );
195 /**********************************************************************
196 * WINPROC_AllocProc16
198 WNDPROC WINPROC_AllocProc16( WNDPROC16 func )
203 if (!func) return NULL;
205 /* check if the function is already a win proc */
206 if ((index = winproc_to_index( func )) != -1)
207 return (WNDPROC)(ULONG_PTR)(index | (WINPROC_HANDLE << 16));
209 /* then check if we already have a winproc for that function */
210 for (index = 0; index < winproc16_used; index++)
211 if (winproc16_array[index] == func) goto done;
213 if (winproc16_used >= MAX_WINPROCS16)
215 FIXME( "too many winprocs, cannot allocate one for 16-bit %p\n", func );
218 winproc16_array[winproc16_used++] = func;
221 ret = (WNDPROC)(ULONG_PTR)((index + MAX_WINPROCS32) | (WINPROC_HANDLE << 16));
222 TRACE( "returning %p for %p/16-bit (%d/%d used)\n",
223 ret, func, winproc16_used, MAX_WINPROCS16 );
227 /**********************************************************************
230 * Get a window procedure pointer that can be passed to the Windows program.
232 WNDPROC16 WINPROC_GetProc16( WNDPROC proc, BOOL unicode )
234 WNDPROC winproc = wow_handlers32.alloc_winproc( proc, unicode );
236 if ((ULONG_PTR)winproc >> 16 != WINPROC_HANDLE) return (WNDPROC16)winproc;
237 return alloc_win16_thunk( winproc );
240 /* call a 16-bit window procedure */
241 static LRESULT call_window_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam,
242 LRESULT *result, void *arg )
244 WNDPROC16 func = arg;
245 int index = winproc_to_index( func );
254 DRAWITEMSTRUCT16 dis16;
255 COMPAREITEMSTRUCT16 cis16;
261 if (index >= MAX_WINPROCS32) func = winproc16_array[index - MAX_WINPROCS32];
263 /* Window procedures want ax = hInstance, ds = es = ss */
265 memset(&context, 0, sizeof(context));
266 context.SegDs = context.SegEs = SELECTOROF(NtCurrentTeb()->WOW32Reserved);
267 context.SegFs = wine_get_fs();
268 context.SegGs = wine_get_gs();
269 if (!(context.Eax = GetWindowWord( HWND_32(hwnd), GWLP_HINSTANCE ))) context.Eax = context.SegDs;
270 context.SegCs = SELECTOROF(func);
271 context.Eip = OFFSETOF(func);
272 context.Ebp = OFFSETOF(NtCurrentTeb()->WOW32Reserved) + FIELD_OFFSET(STACK16FRAME, bp);
276 /* Some programs (eg. the "Undocumented Windows" examples, JWP) only
277 work if structures passed in lParam are placed in the stack/data
278 segment. Programmers easily make the mistake of converting lParam
279 to a near rather than a far pointer, since Windows apparently
280 allows this. We copy the structures to the 16 bit stack; this is
281 ugly but makes these programs work. */
286 size = sizeof(CREATESTRUCT16); break;
288 size = sizeof(DRAWITEMSTRUCT16); break;
290 size = sizeof(COMPAREITEMSTRUCT16); break;
294 memcpy( &args.u, MapSL(lParam), size );
295 lParam = PtrToUlong(NtCurrentTeb()->WOW32Reserved) - size;
299 args.params[4] = hwnd;
300 args.params[3] = msg;
301 args.params[2] = wParam;
302 args.params[1] = HIWORD(lParam);
303 args.params[0] = LOWORD(lParam);
304 WOWCallback16Ex( 0, WCB16_REGS, sizeof(args.params) + size, &args, (DWORD *)&context );
305 *result = MAKELONG( LOWORD(context.Eax), LOWORD(context.Edx) );
309 static LRESULT call_dialog_proc16( HWND16 hwnd, UINT16 msg, WPARAM16 wp, LPARAM lp,
310 LRESULT *result, void *arg )
312 LRESULT ret = call_window_proc16( hwnd, msg, wp, lp, result, arg );
313 *result = GetWindowLongPtrW( WIN_Handle32(hwnd), DWLP_MSGRESULT );
317 static LRESULT call_window_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
318 LRESULT *result, void *arg )
320 return WINPROC_CallProc32ATo16( call_window_proc16, hwnd, msg, wp, lp, result, arg );
323 static LRESULT call_dialog_proc_Ato16( HWND hwnd, UINT msg, WPARAM wp, LPARAM lp,
324 LRESULT *result, void *arg )
326 return WINPROC_CallProc32ATo16( call_dialog_proc16, hwnd, msg, wp, lp, result, arg );
331 /**********************************************************************
332 * Support for Edit word break proc thunks
335 #define MAX_THUNKS 32
337 #include <pshpack1.h>
338 static struct word_break_thunk
340 BYTE popl_eax; /* popl %eax (return address) */
341 BYTE pushl_proc16; /* pushl proc16 */
342 EDITWORDBREAKPROC16 proc16;
343 BYTE pushl_eax; /* pushl %eax */
344 BYTE jmp; /* ljmp call_word_break_proc16 */
346 } *word_break_thunks;
349 /**********************************************************************
350 * call_word_break_proc16
352 static INT16 CALLBACK call_word_break_proc16( SEGPTR proc16, LPSTR text, INT index, INT count, INT action )
358 segptr = MapLS( text );
359 args[4] = SELECTOROF(segptr);
360 args[3] = OFFSETOF(segptr);
364 WOWCallback16Ex( proc16, WCB16_PASCAL, sizeof(args), args, &result );
366 return LOWORD(result);
369 /******************************************************************
370 * add_word_break_thunk
372 static struct word_break_thunk *add_word_break_thunk( EDITWORDBREAKPROC16 proc16 )
374 struct word_break_thunk *thunk;
376 if (!word_break_thunks)
378 word_break_thunks = VirtualAlloc( NULL, MAX_THUNKS * sizeof(*thunk),
379 MEM_COMMIT, PAGE_EXECUTE_READWRITE );
380 if (!word_break_thunks) return NULL;
382 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
384 thunk->popl_eax = 0x58; /* popl %eax */
385 thunk->pushl_proc16 = 0x68; /* pushl proc16 */
386 thunk->pushl_eax = 0x50; /* pushl %eax */
387 thunk->jmp = 0xe9; /* jmp call_word_break_proc16 */
388 thunk->callback = (char *)call_word_break_proc16 - (char *)(&thunk->callback + 1);
391 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
392 if (thunk->proc16 == proc16) return thunk;
394 for (thunk = word_break_thunks; thunk < &word_break_thunks[MAX_THUNKS]; thunk++)
396 if (thunk->proc16) continue;
397 thunk->proc16 = proc16;
400 FIXME("Out of word break thunks\n");
404 /******************************************************************
405 * get_word_break_thunk
407 static EDITWORDBREAKPROC16 get_word_break_thunk( EDITWORDBREAKPROCA proc )
409 struct word_break_thunk *thunk = (struct word_break_thunk *)proc;
410 if (word_break_thunks && thunk >= word_break_thunks && thunk < &word_break_thunks[MAX_THUNKS])
411 return thunk->proc16;
416 /***********************************************************************
417 * Support for 16<->32 message mapping
420 static inline void *get_buffer( void *static_buffer, size_t size, size_t need )
422 if (size >= need) return static_buffer;
423 return HeapAlloc( GetProcessHeap(), 0, need );
426 static inline void free_buffer( void *static_buffer, void *buffer )
428 if (buffer != static_buffer) HeapFree( GetProcessHeap(), 0, buffer );
431 static void RECT16to32( const RECT16 *from, RECT *to )
433 to->left = from->left;
435 to->right = from->right;
436 to->bottom = from->bottom;
439 static void RECT32to16( const RECT *from, RECT16 *to )
441 to->left = from->left;
443 to->right = from->right;
444 to->bottom = from->bottom;
447 static void MINMAXINFO32to16( const MINMAXINFO *from, MINMAXINFO16 *to )
449 to->ptReserved.x = from->ptReserved.x;
450 to->ptReserved.y = from->ptReserved.y;
451 to->ptMaxSize.x = from->ptMaxSize.x;
452 to->ptMaxSize.y = from->ptMaxSize.y;
453 to->ptMaxPosition.x = from->ptMaxPosition.x;
454 to->ptMaxPosition.y = from->ptMaxPosition.y;
455 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
456 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
457 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
458 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
461 static void MINMAXINFO16to32( const MINMAXINFO16 *from, MINMAXINFO *to )
463 to->ptReserved.x = from->ptReserved.x;
464 to->ptReserved.y = from->ptReserved.y;
465 to->ptMaxSize.x = from->ptMaxSize.x;
466 to->ptMaxSize.y = from->ptMaxSize.y;
467 to->ptMaxPosition.x = from->ptMaxPosition.x;
468 to->ptMaxPosition.y = from->ptMaxPosition.y;
469 to->ptMinTrackSize.x = from->ptMinTrackSize.x;
470 to->ptMinTrackSize.y = from->ptMinTrackSize.y;
471 to->ptMaxTrackSize.x = from->ptMaxTrackSize.x;
472 to->ptMaxTrackSize.y = from->ptMaxTrackSize.y;
475 static void WINDOWPOS32to16( const WINDOWPOS* from, WINDOWPOS16* to )
477 to->hwnd = HWND_16(from->hwnd);
478 to->hwndInsertAfter = HWND_16(from->hwndInsertAfter);
483 to->flags = from->flags;
486 static void WINDOWPOS16to32( const WINDOWPOS16* from, WINDOWPOS* to )
488 to->hwnd = WIN_Handle32(from->hwnd);
489 to->hwndInsertAfter = (from->hwndInsertAfter == (HWND16)-1) ?
490 HWND_TOPMOST : WIN_Handle32(from->hwndInsertAfter);
495 to->flags = from->flags;
498 /* The strings are not copied */
499 static void CREATESTRUCT32Ato16( const CREATESTRUCTA* from, CREATESTRUCT16* to )
501 to->lpCreateParams = (SEGPTR)from->lpCreateParams;
502 to->hInstance = HINSTANCE_16(from->hInstance);
503 to->hMenu = HMENU_16(from->hMenu);
504 to->hwndParent = HWND_16(from->hwndParent);
509 to->style = from->style;
510 to->dwExStyle = from->dwExStyle;
513 static void CREATESTRUCT16to32A( const CREATESTRUCT16* from, CREATESTRUCTA *to )
516 to->lpCreateParams = (LPVOID)from->lpCreateParams;
517 to->hInstance = HINSTANCE_32(from->hInstance);
518 to->hMenu = HMENU_32(from->hMenu);
519 to->hwndParent = WIN_Handle32(from->hwndParent);
524 to->style = from->style;
525 to->dwExStyle = from->dwExStyle;
526 to->lpszName = MapSL(from->lpszName);
527 to->lpszClass = MapSL(from->lpszClass);
530 /* The strings are not copied */
531 static void MDICREATESTRUCT32Ato16( const MDICREATESTRUCTA* from, MDICREATESTRUCT16* to )
533 to->hOwner = HINSTANCE_16(from->hOwner);
538 to->style = from->style;
539 to->lParam = from->lParam;
542 static void MDICREATESTRUCT16to32A( const MDICREATESTRUCT16* from, MDICREATESTRUCTA *to )
544 to->hOwner = HINSTANCE_32(from->hOwner);
549 to->style = from->style;
550 to->lParam = from->lParam;
551 to->szTitle = MapSL(from->szTitle);
552 to->szClass = MapSL(from->szClass);
555 static UINT_PTR convert_handle_16_to_32(HANDLE16 src, unsigned int flags)
558 UINT sz = GlobalSize16(src);
561 if (!(dst = GlobalAlloc(flags, sz)))
563 ptr16 = GlobalLock16(src);
564 ptr32 = GlobalLock(dst);
565 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr32, ptr16, sz);
569 return (UINT_PTR)dst;
572 static HANDLE16 convert_handle_32_to_16(UINT_PTR src, unsigned int flags)
575 UINT sz = GlobalSize((HANDLE)src);
578 if (!(dst = GlobalAlloc16(flags, sz)))
580 ptr32 = GlobalLock((HANDLE)src);
581 ptr16 = GlobalLock16(dst);
582 if (ptr16 != NULL && ptr32 != NULL) memcpy(ptr16, ptr32, sz);
583 GlobalUnlock((HANDLE)src);
589 /**********************************************************************
590 * WINPROC_CallProc16To32A
592 LRESULT WINPROC_CallProc16To32A( winproc_callback_t callback, HWND16 hwnd, UINT16 msg,
593 WPARAM16 wParam, LPARAM lParam, LRESULT *result, void *arg )
596 HWND hwnd32 = WIN_Handle32( hwnd );
598 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08x,lp=%08lx)\n",
599 hwnd32, SPY_GetMsgName(msg, hwnd32), wParam, lParam);
606 CREATESTRUCT16 *cs16 = MapSL(lParam);
608 MDICREATESTRUCTA mdi_cs;
610 CREATESTRUCT16to32A( cs16, &cs );
611 if (GetWindowLongW(hwnd32, GWL_EXSTYLE) & WS_EX_MDICHILD)
613 MDICREATESTRUCT16 *mdi_cs16 = MapSL(cs16->lpCreateParams);
614 MDICREATESTRUCT16to32A(mdi_cs16, &mdi_cs);
615 cs.lpCreateParams = &mdi_cs;
617 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
618 CREATESTRUCT32Ato16( &cs, cs16 );
623 MDICREATESTRUCT16 *cs16 = MapSL(lParam);
626 MDICREATESTRUCT16to32A( cs16, &cs );
627 ret = callback( hwnd32, msg, wParam, (LPARAM)&cs, result, arg );
628 MDICREATESTRUCT32Ato16( &cs, cs16 );
633 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32( HIWORD(lParam) ),
634 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
635 else /* message sent to MDI client */
636 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
638 case WM_MDIGETACTIVE:
640 BOOL maximized = FALSE;
641 ret = callback( hwnd32, msg, wParam, (LPARAM)&maximized, result, arg );
642 *result = MAKELRESULT( LOWORD(*result), maximized );
646 ret = callback( hwnd32, wParam ? WM_MDIREFRESHMENU : WM_MDISETMENU,
647 (WPARAM)HMENU_32(LOWORD(lParam)), (LPARAM)HMENU_32(HIWORD(lParam)),
650 case WM_GETMINMAXINFO:
652 MINMAXINFO16 *mmi16 = MapSL(lParam);
655 MINMAXINFO16to32( mmi16, &mmi );
656 ret = callback( hwnd32, msg, wParam, (LPARAM)&mmi, result, arg );
657 MINMAXINFO32to16( &mmi, mmi16 );
660 case WM_WINDOWPOSCHANGING:
661 case WM_WINDOWPOSCHANGED:
663 WINDOWPOS16 *winpos16 = MapSL(lParam);
666 WINDOWPOS16to32( winpos16, &winpos );
667 ret = callback( hwnd32, msg, wParam, (LPARAM)&winpos, result, arg );
668 WINDOWPOS32to16( &winpos, winpos16 );
673 NCCALCSIZE_PARAMS16 *nc16 = MapSL(lParam);
674 NCCALCSIZE_PARAMS nc;
677 RECT16to32( &nc16->rgrc[0], &nc.rgrc[0] );
680 RECT16to32( &nc16->rgrc[1], &nc.rgrc[1] );
681 RECT16to32( &nc16->rgrc[2], &nc.rgrc[2] );
682 WINDOWPOS16to32( MapSL(nc16->lppos), &winpos );
685 ret = callback( hwnd32, msg, wParam, (LPARAM)&nc, result, arg );
686 RECT32to16( &nc.rgrc[0], &nc16->rgrc[0] );
689 RECT32to16( &nc.rgrc[1], &nc16->rgrc[1] );
690 RECT32to16( &nc.rgrc[2], &nc16->rgrc[2] );
691 WINDOWPOS32to16( &winpos, MapSL(nc16->lppos) );
697 COMPAREITEMSTRUCT16* cis16 = MapSL(lParam);
698 COMPAREITEMSTRUCT cis;
699 cis.CtlType = cis16->CtlType;
700 cis.CtlID = cis16->CtlID;
701 cis.hwndItem = WIN_Handle32( cis16->hwndItem );
702 cis.itemID1 = cis16->itemID1;
703 cis.itemData1 = cis16->itemData1;
704 cis.itemID2 = cis16->itemID2;
705 cis.itemData2 = cis16->itemData2;
706 cis.dwLocaleId = 0; /* FIXME */
707 ret = callback( hwnd32, msg, wParam, (LPARAM)&cis, result, arg );
712 DELETEITEMSTRUCT16* dis16 = MapSL(lParam);
713 DELETEITEMSTRUCT dis;
714 dis.CtlType = dis16->CtlType;
715 dis.CtlID = dis16->CtlID;
716 dis.hwndItem = WIN_Handle32( dis16->hwndItem );
717 dis.itemData = dis16->itemData;
718 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
723 MEASUREITEMSTRUCT16* mis16 = MapSL(lParam);
724 MEASUREITEMSTRUCT mis;
725 mis.CtlType = mis16->CtlType;
726 mis.CtlID = mis16->CtlID;
727 mis.itemID = mis16->itemID;
728 mis.itemWidth = mis16->itemWidth;
729 mis.itemHeight = mis16->itemHeight;
730 mis.itemData = mis16->itemData;
731 ret = callback( hwnd32, msg, wParam, (LPARAM)&mis, result, arg );
732 mis16->itemWidth = (UINT16)mis.itemWidth;
733 mis16->itemHeight = (UINT16)mis.itemHeight;
738 DRAWITEMSTRUCT16* dis16 = MapSL(lParam);
740 dis.CtlType = dis16->CtlType;
741 dis.CtlID = dis16->CtlID;
742 dis.itemID = dis16->itemID;
743 dis.itemAction = dis16->itemAction;
744 dis.itemState = dis16->itemState;
745 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND)HMENU_32(dis16->hwndItem)
746 : WIN_Handle32( dis16->hwndItem );
747 dis.hDC = HDC_32(dis16->hDC);
748 dis.itemData = dis16->itemData;
749 dis.rcItem.left = dis16->rcItem.left;
750 dis.rcItem.top = dis16->rcItem.top;
751 dis.rcItem.right = dis16->rcItem.right;
752 dis.rcItem.bottom = dis16->rcItem.bottom;
753 ret = callback( hwnd32, msg, wParam, (LPARAM)&dis, result, arg );
758 COPYDATASTRUCT16 *cds16 = MapSL(lParam);
760 cds.dwData = cds16->dwData;
761 cds.cbData = cds16->cbData;
762 cds.lpData = MapSL(cds16->lpData);
763 ret = callback( hwnd32, msg, wParam, (LPARAM)&cds, result, arg );
769 MSG16 *msg16 = MapSL(lParam);
771 msg32.hwnd = WIN_Handle32( msg16->hwnd );
772 msg32.message = msg16->message;
773 msg32.wParam = msg16->wParam;
774 msg32.lParam = msg16->lParam;
775 msg32.time = msg16->time;
776 msg32.pt.x = msg16->pt.x;
777 msg32.pt.y = msg16->pt.y;
778 ret = callback( hwnd32, msg, wParam, (LPARAM)&msg32, result, arg );
781 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
786 next.hmenuIn = (HMENU)lParam;
789 ret = callback( hwnd32, msg, wParam, (LPARAM)&next, result, arg );
790 *result = MAKELONG( HMENU_16(next.hmenuNext), HWND_16(next.hwndNext) );
797 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
798 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
802 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
803 (LPARAM)WIN_Handle32( HIWORD(lParam) ), result, arg );
806 if (HIWORD(lParam) <= CTLCOLOR_STATIC)
807 ret = callback( hwnd32, WM_CTLCOLORMSGBOX + HIWORD(lParam),
808 (WPARAM)HDC_32(wParam), (LPARAM)WIN_Handle32( LOWORD(lParam) ),
813 case WM_WININICHANGE:
814 case WM_DEVMODECHANGE:
815 case WM_ASKCBFORMATNAME:
817 ret = callback( hwnd32, msg, wParam, (LPARAM)MapSL(lParam), result, arg );
820 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
821 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
824 if((LOWORD(lParam) & MF_POPUP) && (LOWORD(lParam) != 0xFFFF))
826 HMENU hmenu = HMENU_32(HIWORD(lParam));
827 UINT pos = MENU_FindSubMenu( &hmenu, HMENU_32(wParam) );
828 if (pos == 0xffff) pos = 0; /* NO_SELECTED_ITEM */
831 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, LOWORD(lParam) ),
832 (LPARAM)HMENU_32(HIWORD(lParam)), result, arg );
834 case WM_PARENTNOTIFY:
835 if ((wParam == WM_CREATE) || (wParam == WM_DESTROY))
836 ret = callback( hwnd32, msg, MAKEWPARAM( wParam, HIWORD(lParam) ),
837 (LPARAM)WIN_Handle32( LOWORD(lParam) ), result, arg );
839 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
842 /* We need this when SetActiveWindow sends a Sendmessage16() to
843 * a 32-bit window. Might be superfluous with 32-bit interprocess
845 if (lParam) lParam = HTASK_32(lParam);
846 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
848 case WM_DDE_INITIATE:
849 case WM_DDE_TERMINATE:
850 case WM_DDE_UNADVISE:
852 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
858 HANDLE16 lo16 = LOWORD(lParam);
860 if (lo16 && !(lo32 = convert_handle_16_to_32(lo16, GMEM_DDESHARE))) break;
861 lParam = PackDDElParam( msg, lo32, HIWORD(lParam) );
862 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
864 break; /* FIXME don't know how to free allocated memory (handle) !! */
867 UINT_PTR lo = LOWORD(lParam);
868 UINT_PTR hi = HIWORD(lParam);
872 if (GlobalGetAtomNameA(hi, buf, 2) > 0) flag |= 1;
873 if (GlobalSize16(hi) != 0) flag |= 2;
879 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
884 break; /* atom, nothing to do */
886 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
889 hi = convert_handle_16_to_32(hi, GMEM_DDESHARE);
892 lParam = PackDDElParam( WM_DDE_ACK, lo, hi );
893 ret = callback( hwnd32, msg, (WPARAM)WIN_Handle32(wParam), lParam, result, arg );
895 break; /* FIXME don't know how to free allocated memory (handle) !! */
897 lParam = convert_handle_16_to_32( lParam, GMEM_DDESHARE );
898 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
899 break; /* FIXME don't know how to free allocated memory (handle) !! */
900 case WM_PAINTCLIPBOARD:
901 case WM_SIZECLIPBOARD:
902 FIXME_(msg)( "message %04x needs translation\n", msg );
905 ret = callback( hwnd32, msg, wParam, lParam, result, arg );
912 /**********************************************************************
913 * WINPROC_CallProc32ATo16
915 * Call a 16-bit window procedure, translating the 32-bit args.
917 LRESULT WINPROC_CallProc32ATo16( winproc_callback16_t callback, HWND hwnd, UINT msg,
918 WPARAM wParam, LPARAM lParam, LRESULT *result, void *arg )
922 TRACE_(msg)("(hwnd=%p,msg=%s,wp=%08lx,lp=%08lx)\n",
923 hwnd, SPY_GetMsgName(msg, hwnd), wParam, lParam);
930 CREATESTRUCTA *cs32 = (CREATESTRUCTA *)lParam;
932 MDICREATESTRUCT16 mdi_cs16;
933 BOOL mdi_child = (GetWindowLongW(hwnd, GWL_EXSTYLE) & WS_EX_MDICHILD);
935 CREATESTRUCT32Ato16( cs32, &cs );
936 cs.lpszName = MapLS( cs32->lpszName );
937 cs.lpszClass = MapLS( cs32->lpszClass );
941 MDICREATESTRUCTA *mdi_cs = cs32->lpCreateParams;
942 MDICREATESTRUCT32Ato16( mdi_cs, &mdi_cs16 );
943 mdi_cs16.szTitle = MapLS( mdi_cs->szTitle );
944 mdi_cs16.szClass = MapLS( mdi_cs->szClass );
945 cs.lpCreateParams = MapLS( &mdi_cs16 );
947 lParam = MapLS( &cs );
948 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
950 UnMapLS( cs.lpszName );
951 UnMapLS( cs.lpszClass );
954 UnMapLS( cs.lpCreateParams );
955 UnMapLS( mdi_cs16.szTitle );
956 UnMapLS( mdi_cs16.szClass );
962 MDICREATESTRUCTA *cs32 = (MDICREATESTRUCTA *)lParam;
963 MDICREATESTRUCT16 cs;
965 MDICREATESTRUCT32Ato16( cs32, &cs );
966 cs.szTitle = MapLS( cs32->szTitle );
967 cs.szClass = MapLS( cs32->szClass );
968 lParam = MapLS( &cs );
969 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
971 UnMapLS( cs.szTitle );
972 UnMapLS( cs.szClass );
976 if (GetWindowLongW( hwnd, GWL_EXSTYLE ) & WS_EX_MDICHILD)
977 ret = callback( HWND_16(hwnd), msg, ((HWND)lParam == hwnd),
978 MAKELPARAM( LOWORD(lParam), LOWORD(wParam) ), result, arg );
980 ret = callback( HWND_16(hwnd), msg, HWND_16( wParam ), 0, result, arg );
982 case WM_MDIGETACTIVE:
983 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
984 if (lParam) *(BOOL *)lParam = (BOOL16)HIWORD(*result);
985 *result = (LRESULT)WIN_Handle32( LOWORD(*result) );
988 ret = callback( HWND_16(hwnd), msg, (lParam == 0),
989 MAKELPARAM( LOWORD(wParam), LOWORD(lParam) ), result, arg );
991 case WM_GETMINMAXINFO:
993 MINMAXINFO *mmi32 = (MINMAXINFO *)lParam;
996 MINMAXINFO32to16( mmi32, &mmi );
997 lParam = MapLS( &mmi );
998 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1000 MINMAXINFO16to32( &mmi, mmi32 );
1005 NCCALCSIZE_PARAMS *nc32 = (NCCALCSIZE_PARAMS *)lParam;
1006 NCCALCSIZE_PARAMS16 nc;
1009 RECT32to16( &nc32->rgrc[0], &nc.rgrc[0] );
1012 RECT32to16( &nc32->rgrc[1], &nc.rgrc[1] );
1013 RECT32to16( &nc32->rgrc[2], &nc.rgrc[2] );
1014 WINDOWPOS32to16( nc32->lppos, &winpos );
1015 nc.lppos = MapLS( &winpos );
1017 lParam = MapLS( &nc );
1018 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1020 RECT16to32( &nc.rgrc[0], &nc32->rgrc[0] );
1023 RECT16to32( &nc.rgrc[1], &nc32->rgrc[1] );
1024 RECT16to32( &nc.rgrc[2], &nc32->rgrc[2] );
1025 WINDOWPOS16to32( &winpos, nc32->lppos );
1026 UnMapLS( nc.lppos );
1030 case WM_WINDOWPOSCHANGING:
1031 case WM_WINDOWPOSCHANGED:
1033 WINDOWPOS *winpos32 = (WINDOWPOS *)lParam;
1036 WINDOWPOS32to16( winpos32, &winpos );
1037 lParam = MapLS( &winpos );
1038 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1040 WINDOWPOS16to32( &winpos, winpos32 );
1043 case WM_COMPAREITEM:
1045 COMPAREITEMSTRUCT *cis32 = (COMPAREITEMSTRUCT *)lParam;
1046 COMPAREITEMSTRUCT16 cis;
1047 cis.CtlType = cis32->CtlType;
1048 cis.CtlID = cis32->CtlID;
1049 cis.hwndItem = HWND_16( cis32->hwndItem );
1050 cis.itemID1 = cis32->itemID1;
1051 cis.itemData1 = cis32->itemData1;
1052 cis.itemID2 = cis32->itemID2;
1053 cis.itemData2 = cis32->itemData2;
1054 lParam = MapLS( &cis );
1055 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1061 DELETEITEMSTRUCT *dis32 = (DELETEITEMSTRUCT *)lParam;
1062 DELETEITEMSTRUCT16 dis;
1063 dis.CtlType = dis32->CtlType;
1064 dis.CtlID = dis32->CtlID;
1065 dis.itemID = dis32->itemID;
1066 dis.hwndItem = (dis.CtlType == ODT_MENU) ? (HWND16)LOWORD(dis32->hwndItem)
1067 : HWND_16( dis32->hwndItem );
1068 dis.itemData = dis32->itemData;
1069 lParam = MapLS( &dis );
1070 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1076 DRAWITEMSTRUCT *dis32 = (DRAWITEMSTRUCT *)lParam;
1077 DRAWITEMSTRUCT16 dis;
1078 dis.CtlType = dis32->CtlType;
1079 dis.CtlID = dis32->CtlID;
1080 dis.itemID = dis32->itemID;
1081 dis.itemAction = dis32->itemAction;
1082 dis.itemState = dis32->itemState;
1083 dis.hwndItem = HWND_16( dis32->hwndItem );
1084 dis.hDC = HDC_16(dis32->hDC);
1085 dis.itemData = dis32->itemData;
1086 dis.rcItem.left = dis32->rcItem.left;
1087 dis.rcItem.top = dis32->rcItem.top;
1088 dis.rcItem.right = dis32->rcItem.right;
1089 dis.rcItem.bottom = dis32->rcItem.bottom;
1090 lParam = MapLS( &dis );
1091 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1095 case WM_MEASUREITEM:
1097 MEASUREITEMSTRUCT *mis32 = (MEASUREITEMSTRUCT *)lParam;
1098 MEASUREITEMSTRUCT16 mis;
1099 mis.CtlType = mis32->CtlType;
1100 mis.CtlID = mis32->CtlID;
1101 mis.itemID = mis32->itemID;
1102 mis.itemWidth = mis32->itemWidth;
1103 mis.itemHeight = mis32->itemHeight;
1104 mis.itemData = mis32->itemData;
1105 lParam = MapLS( &mis );
1106 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1108 mis32->itemWidth = mis.itemWidth;
1109 mis32->itemHeight = mis.itemHeight;
1114 COPYDATASTRUCT *cds32 = (COPYDATASTRUCT *)lParam;
1115 COPYDATASTRUCT16 cds;
1117 cds.dwData = cds32->dwData;
1118 cds.cbData = cds32->cbData;
1119 cds.lpData = MapLS( cds32->lpData );
1120 lParam = MapLS( &cds );
1121 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1123 UnMapLS( cds.lpData );
1129 MSG *msg32 = (MSG *)lParam;
1132 msg16.hwnd = HWND_16( msg32->hwnd );
1133 msg16.message = msg32->message;
1134 msg16.wParam = msg32->wParam;
1135 msg16.lParam = msg32->lParam;
1136 msg16.time = msg32->time;
1137 msg16.pt.x = msg32->pt.x;
1138 msg16.pt.y = msg32->pt.y;
1139 lParam = MapLS( &msg16 );
1140 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1144 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1148 MDINEXTMENU *next = (MDINEXTMENU *)lParam;
1149 ret = callback( HWND_16(hwnd), msg, wParam, (LPARAM)next->hmenuIn, result, arg );
1150 next->hmenuNext = HMENU_32( LOWORD(*result) );
1151 next->hwndNext = WIN_Handle32( HIWORD(*result) );
1156 case WM_ASKCBFORMATNAME:
1157 wParam = min( wParam, 0xff80 ); /* Must be < 64K */
1161 case WM_WININICHANGE:
1162 case WM_DEVMODECHANGE:
1163 lParam = MapLS( (void *)lParam );
1164 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1171 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ),
1176 ret = callback( HWND_16(hwnd), msg, wParam, MAKELPARAM( HIWORD(wParam), (HWND16)lParam ),
1179 case WM_CTLCOLORMSGBOX:
1180 case WM_CTLCOLOREDIT:
1181 case WM_CTLCOLORLISTBOX:
1182 case WM_CTLCOLORBTN:
1183 case WM_CTLCOLORDLG:
1184 case WM_CTLCOLORSCROLLBAR:
1185 case WM_CTLCOLORSTATIC:
1186 ret = callback( HWND_16(hwnd), WM_CTLCOLOR, wParam,
1187 MAKELPARAM( (HWND16)lParam, msg - WM_CTLCOLORMSGBOX ), result, arg );
1190 if(HIWORD(wParam) & MF_POPUP)
1193 if ((HIWORD(wParam) != 0xffff) || lParam)
1195 if ((hmenu = GetSubMenu( (HMENU)lParam, LOWORD(wParam) )))
1197 ret = callback( HWND_16(hwnd), msg, HMENU_16(hmenu),
1198 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1205 ret = callback( HWND_16(hwnd), msg, wParam,
1206 MAKELPARAM( HIWORD(wParam), (HMENU16)lParam ), result, arg );
1208 case WM_PARENTNOTIFY:
1209 if ((LOWORD(wParam) == WM_CREATE) || (LOWORD(wParam) == WM_DESTROY))
1210 ret = callback( HWND_16(hwnd), msg, wParam,
1211 MAKELPARAM( (HWND16)lParam, HIWORD(wParam) ), result, arg );
1213 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1215 case WM_ACTIVATEAPP:
1216 ret = callback( HWND_16(hwnd), msg, wParam, HTASK_16( lParam ), result, arg );
1219 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON ))
1220 ret = callback( HWND_16(hwnd), WM_PAINTICON, 1, lParam, result, arg );
1222 ret = callback( HWND_16(hwnd), WM_PAINT, wParam, lParam, result, arg );
1225 if (IsIconic( hwnd ) && GetClassLongPtrW( hwnd, GCLP_HICON )) msg = WM_ICONERASEBKGND;
1226 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1228 case WM_DDE_INITIATE:
1229 case WM_DDE_TERMINATE:
1230 case WM_DDE_UNADVISE:
1231 case WM_DDE_REQUEST:
1232 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam), lParam, result, arg );
1241 UnpackDDElParam( msg, lParam, &lo32, &hi );
1242 if (lo32 && !(lo16 = convert_handle_32_to_16(lo32, GMEM_DDESHARE))) break;
1243 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1244 MAKELPARAM(lo16, hi), result, arg );
1246 break; /* FIXME don't know how to free allocated memory (handle) !! */
1253 UnpackDDElParam( msg, lParam, &lo, &hi );
1255 if (GlobalGetAtomNameA((ATOM)hi, buf, sizeof(buf)) > 0) flag |= 1;
1256 if (GlobalSize((HANDLE)hi) != 0) flag |= 2;
1262 MESSAGE("DDE_ACK: neither atom nor handle!!!\n");
1267 break; /* atom, nothing to do */
1269 MESSAGE("DDE_ACK: %lx both atom and handle... choosing handle\n", hi);
1272 hi = convert_handle_32_to_16(hi, GMEM_DDESHARE);
1275 ret = callback( HWND_16(hwnd), msg, HWND_16(wParam),
1276 MAKELPARAM(lo, hi), result, arg );
1278 break; /* FIXME don't know how to free allocated memory (handle) !! */
1279 case WM_DDE_EXECUTE:
1280 lParam = convert_handle_32_to_16(lParam, GMEM_DDESHARE);
1281 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1282 break; /* FIXME don't know how to free allocated memory (handle) !! */
1284 ret = callback( HWND_16(hwnd), SBM_SETRANGE16, 0, MAKELPARAM(wParam, lParam), result, arg );
1287 ret = callback( HWND_16(hwnd), SBM_GETRANGE16, wParam, lParam, result, arg );
1288 *(LPINT)wParam = LOWORD(*result);
1289 *(LPINT)lParam = HIWORD(*result);
1296 ret = callback( HWND_16(hwnd), msg + BM_GETCHECK16 - BM_GETCHECK, wParam, lParam, result, arg );
1304 case EM_SCROLLCARET:
1307 case EM_GETLINECOUNT:
1319 case EM_LINEFROMCHAR:
1320 case EM_SETTABSTOPS:
1321 case EM_SETPASSWORDCHAR:
1322 case EM_EMPTYUNDOBUFFER:
1323 case EM_GETFIRSTVISIBLELINE:
1324 case EM_SETREADONLY:
1325 case EM_SETWORDBREAKPROC:
1326 case EM_GETWORDBREAKPROC:
1327 case EM_GETPASSWORDCHAR:
1328 ret = callback( HWND_16(hwnd), msg + EM_GETSEL16 - EM_GETSEL, wParam, lParam, result, arg );
1331 ret = callback( HWND_16(hwnd), EM_SETSEL16, 0, MAKELPARAM( wParam, lParam ), result, arg );
1335 case LB_DELETESTRING:
1336 case LB_GETANCHORINDEX:
1337 case LB_GETCARETINDEX:
1340 case LB_GETHORIZONTALEXTENT:
1341 case LB_GETITEMDATA:
1342 case LB_GETITEMHEIGHT:
1344 case LB_GETSELCOUNT:
1346 case LB_GETTOPINDEX:
1347 case LB_RESETCONTENT:
1348 case LB_SELITEMRANGE:
1349 case LB_SELITEMRANGEEX:
1350 case LB_SETANCHORINDEX:
1351 case LB_SETCARETINDEX:
1352 case LB_SETCOLUMNWIDTH:
1354 case LB_SETHORIZONTALEXTENT:
1355 case LB_SETITEMDATA:
1356 case LB_SETITEMHEIGHT:
1358 case LB_SETTOPINDEX:
1359 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1363 case LB_FINDSTRINGEXACT:
1364 case LB_INSERTSTRING:
1365 case LB_SELECTSTRING:
1369 lParam = MapLS( (LPSTR)lParam );
1370 ret = callback( HWND_16(hwnd), msg + LB_ADDSTRING16 - LB_ADDSTRING, wParam, lParam, result, arg );
1373 case LB_GETSELITEMS:
1375 INT *items32 = (INT *)lParam;
1376 INT16 *items, buffer[512];
1379 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1380 if (!(items = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1381 lParam = MapLS( items );
1382 ret = callback( HWND_16(hwnd), LB_GETSELITEMS16, wParam, lParam, result, arg );
1384 for (i = 0; i < wParam; i++) items32[i] = items[i];
1385 free_buffer( buffer, items );
1388 case LB_SETTABSTOPS:
1391 INT *stops32 = (INT *)lParam;
1392 INT16 *stops, buffer[512];
1395 wParam = min( wParam, 0x7f80 ); /* Must be < 64K */
1396 if (!(stops = get_buffer( buffer, sizeof(buffer), wParam * sizeof(INT16) ))) break;
1397 for (i = 0; i < wParam; i++) stops[i] = stops32[i];
1398 lParam = MapLS( stops );
1399 ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1401 free_buffer( buffer, stops );
1403 else ret = callback( HWND_16(hwnd), LB_SETTABSTOPS16, wParam, lParam, result, arg );
1405 case CB_DELETESTRING:
1407 case CB_GETLBTEXTLEN:
1409 case CB_RESETCONTENT:
1413 case CB_SHOWDROPDOWN:
1414 case CB_SETITEMDATA:
1415 case CB_SETITEMHEIGHT:
1416 case CB_GETITEMHEIGHT:
1417 case CB_SETEXTENDEDUI:
1418 case CB_GETEXTENDEDUI:
1419 case CB_GETDROPPEDSTATE:
1420 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1423 ret = callback( HWND_16(hwnd), CB_GETEDITSEL16, wParam, lParam, result, arg );
1424 if (wParam) *((PUINT)(wParam)) = LOWORD(*result);
1425 if (lParam) *((PUINT)(lParam)) = HIWORD(*result); /* FIXME: substract 1? */
1429 case CB_FINDSTRINGEXACT:
1430 case CB_INSERTSTRING:
1431 case CB_SELECTSTRING:
1434 lParam = MapLS( (LPSTR)lParam );
1435 ret = callback( HWND_16(hwnd), msg + CB_GETEDITSEL16 - CB_GETEDITSEL, wParam, lParam, result, arg );
1438 case LB_GETITEMRECT:
1439 case CB_GETDROPPEDCONTROLRECT:
1441 RECT *r32 = (RECT *)lParam;
1443 lParam = MapLS( &rect );
1444 ret = callback( HWND_16(hwnd),
1445 (msg == LB_GETITEMRECT) ? LB_GETITEMRECT16 : CB_GETDROPPEDCONTROLRECT16,
1446 wParam, lParam, result, arg );
1448 RECT16to32( &rect, r32 );
1451 case WM_PAINTCLIPBOARD:
1452 case WM_SIZECLIPBOARD:
1453 FIXME_(msg)( "message %04x needs translation\n", msg );
1455 /* the following messages should not be sent to 16-bit apps */
1458 case WM_CAPTURECHANGED:
1459 case WM_STYLECHANGING:
1460 case WM_STYLECHANGED:
1463 ret = callback( HWND_16(hwnd), msg, wParam, lParam, result, arg );
1470 /***********************************************************************
1471 * SendMessage (USER.111)
1473 LRESULT WINAPI SendMessage16( HWND16 hwnd16, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1476 HWND hwnd = WIN_Handle32( hwnd16 );
1478 if (hwnd != HWND_BROADCAST && WIN_IsCurrentThread(hwnd))
1480 /* call 16-bit window proc directly */
1483 /* first the WH_CALLWNDPROC hook */
1484 if (HOOK_IsHooked( WH_CALLWNDPROC ))
1485 WINPROC_CallProc16To32A( cwp_hook_callback, hwnd16, msg, wparam, lparam, &result, NULL );
1487 if (!(winproc = (WNDPROC16)GetWindowLong16( hwnd16, GWLP_WNDPROC ))) return 0;
1489 SPY_EnterMessage( SPY_SENDMESSAGE16, hwnd, msg, wparam, lparam );
1490 result = CallWindowProc16( winproc, hwnd16, msg, wparam, lparam );
1491 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg, result, wparam, lparam );
1493 else /* map to 32-bit unicode for inter-thread/process message */
1495 WINPROC_CallProc16To32A( send_message_callback, hwnd16, msg, wparam, lparam, &result, NULL );
1501 /***********************************************************************
1502 * PostMessage (USER.110)
1504 BOOL16 WINAPI PostMessage16( HWND16 hwnd, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1507 return WINPROC_CallProc16To32A( post_message_callback, hwnd, msg, wparam, lparam, &unused, NULL );
1511 /***********************************************************************
1512 * PostAppMessage (USER.116)
1514 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
1517 DWORD_PTR tid = HTASK_32( hTask );
1519 if (!tid) return FALSE;
1520 return WINPROC_CallProc16To32A( post_thread_message_callback, 0, msg, wparam, lparam,
1521 &unused, (void *)tid );
1525 /**********************************************************************
1526 * CallWindowProc (USER.122)
1528 LRESULT WINAPI CallWindowProc16( WNDPROC16 func, HWND16 hwnd, UINT16 msg,
1529 WPARAM16 wParam, LPARAM lParam )
1531 int index = winproc_to_index( func );
1534 if (!func) return 0;
1536 if (index == -1 || index >= MAX_WINPROCS32)
1537 call_window_proc16( hwnd, msg, wParam, lParam, &result, func );
1540 WNDPROC proc = (WNDPROC)func;
1541 if (thunk_array && thunk_array[index].proc) proc = thunk_array[index].proc;
1542 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1548 /**********************************************************************
1549 * __wine_call_wndproc (USER.1010)
1551 LRESULT WINAPI __wine_call_wndproc( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam, WNDPROC proc )
1554 WINPROC_CallProc16To32A( call_window_proc_callback, hwnd, msg, wParam, lParam, &result, proc );
1559 /***********************************************************************
1560 * InSendMessage (USER.192)
1562 BOOL16 WINAPI InSendMessage16(void)
1564 return InSendMessage();
1568 /***********************************************************************
1569 * ReplyMessage (USER.115)
1571 void WINAPI ReplyMessage16( LRESULT result )
1573 ReplyMessage( result );
1577 /***********************************************************************
1578 * PeekMessage32 (USER.819)
1580 BOOL16 WINAPI PeekMessage32_16( MSG32_16 *msg16, HWND16 hwnd16,
1581 UINT16 first, UINT16 last, UINT16 flags,
1582 BOOL16 wHaveParamHigh )
1586 HWND hwnd = WIN_Handle32( hwnd16 );
1588 if(USER16_AlertableWait)
1589 MsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, MWMO_ALERTABLE );
1590 if (!PeekMessageA( &msg, hwnd, first, last, flags )) return FALSE;
1592 msg16->msg.time = msg.time;
1593 msg16->msg.pt.x = (INT16)msg.pt.x;
1594 msg16->msg.pt.y = (INT16)msg.pt.y;
1595 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1596 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1597 &unused, &msg16->msg );
1602 /***********************************************************************
1603 * DefWindowProc (USER.107)
1605 LRESULT WINAPI DefWindowProc16( HWND16 hwnd16, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1608 HWND hwnd = WIN_Handle32( hwnd16 );
1610 SPY_EnterMessage( SPY_DEFWNDPROC16, hwnd, msg, wParam, lParam );
1616 CREATESTRUCT16 *cs16 = MapSL(lParam);
1619 cs32.lpCreateParams = ULongToPtr(cs16->lpCreateParams);
1620 cs32.hInstance = HINSTANCE_32(cs16->hInstance);
1621 cs32.hMenu = HMENU_32(cs16->hMenu);
1622 cs32.hwndParent = WIN_Handle32(cs16->hwndParent);
1627 cs32.style = cs16->style;
1628 cs32.dwExStyle = cs16->dwExStyle;
1629 cs32.lpszName = MapSL(cs16->lpszName);
1630 cs32.lpszClass = MapSL(cs16->lpszClass);
1631 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)&cs32 );
1637 RECT16 *rect16 = MapSL(lParam);
1640 rect32.left = rect16->left;
1641 rect32.top = rect16->top;
1642 rect32.right = rect16->right;
1643 rect32.bottom = rect16->bottom;
1645 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)&rect32 );
1647 rect16->left = rect32.left;
1648 rect16->top = rect32.top;
1649 rect16->right = rect32.right;
1650 rect16->bottom = rect32.bottom;
1654 case WM_WINDOWPOSCHANGING:
1655 case WM_WINDOWPOSCHANGED:
1657 WINDOWPOS16 *pos16 = MapSL(lParam);
1660 pos32.hwnd = WIN_Handle32(pos16->hwnd);
1661 pos32.hwndInsertAfter = WIN_Handle32(pos16->hwndInsertAfter);
1664 pos32.cx = pos16->cx;
1665 pos32.cy = pos16->cy;
1666 pos32.flags = pos16->flags;
1668 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)&pos32 );
1670 pos16->hwnd = HWND_16(pos32.hwnd);
1671 pos16->hwndInsertAfter = HWND_16(pos32.hwndInsertAfter);
1674 pos16->cx = pos32.cx;
1675 pos16->cy = pos32.cy;
1676 pos16->flags = pos32.flags;
1682 result = DefWindowProcA( hwnd, msg, wParam, (LPARAM)MapSL(lParam) );
1686 result = DefWindowProcA( hwnd, msg, wParam, lParam );
1690 SPY_ExitMessage( SPY_RESULT_DEFWND16, hwnd, msg, result, wParam, lParam );
1695 /***********************************************************************
1696 * DefDlgProc (USER.308)
1698 LRESULT WINAPI DefDlgProc16( HWND16 hwnd, UINT16 msg, WPARAM16 wParam, LPARAM lParam )
1701 WINPROC_CallProc16To32A( defdlg_proc_callback, hwnd, msg, wParam, lParam, &result, 0 );
1706 /***********************************************************************
1707 * PeekMessage (USER.109)
1709 BOOL16 WINAPI PeekMessage16( MSG16 *msg, HWND16 hwnd,
1710 UINT16 first, UINT16 last, UINT16 flags )
1712 return PeekMessage32_16( (MSG32_16 *)msg, hwnd, first, last, flags, FALSE );
1716 /***********************************************************************
1717 * GetMessage32 (USER.820)
1719 BOOL16 WINAPI GetMessage32_16( MSG32_16 *msg16, HWND16 hwnd16, UINT16 first,
1720 UINT16 last, BOOL16 wHaveParamHigh )
1724 HWND hwnd = WIN_Handle32( hwnd16 );
1726 if(USER16_AlertableWait)
1727 MsgWaitForMultipleObjectsEx( 0, NULL, INFINITE, 0, MWMO_ALERTABLE );
1728 GetMessageA( &msg, hwnd, first, last );
1729 msg16->msg.time = msg.time;
1730 msg16->msg.pt.x = (INT16)msg.pt.x;
1731 msg16->msg.pt.y = (INT16)msg.pt.y;
1732 if (wHaveParamHigh) msg16->wParamHigh = HIWORD(msg.wParam);
1733 WINPROC_CallProc32ATo16( get_message_callback, msg.hwnd, msg.message, msg.wParam, msg.lParam,
1734 &unused, &msg16->msg );
1736 TRACE( "message %04x, hwnd %p, filter(%04x - %04x)\n",
1737 msg16->msg.message, hwnd, first, last );
1739 return msg16->msg.message != WM_QUIT;
1743 /***********************************************************************
1744 * GetMessage (USER.108)
1746 BOOL16 WINAPI GetMessage16( MSG16 *msg, HWND16 hwnd, UINT16 first, UINT16 last )
1748 return GetMessage32_16( (MSG32_16 *)msg, hwnd, first, last, FALSE );
1752 /***********************************************************************
1753 * TranslateMessage32 (USER.821)
1755 BOOL16 WINAPI TranslateMessage32_16( const MSG32_16 *msg, BOOL16 wHaveParamHigh )
1759 msg32.hwnd = WIN_Handle32( msg->msg.hwnd );
1760 msg32.message = msg->msg.message;
1761 msg32.wParam = MAKEWPARAM( msg->msg.wParam, wHaveParamHigh ? msg->wParamHigh : 0 );
1762 msg32.lParam = msg->msg.lParam;
1763 return TranslateMessage( &msg32 );
1767 /***********************************************************************
1768 * TranslateMessage (USER.113)
1770 BOOL16 WINAPI TranslateMessage16( const MSG16 *msg )
1772 return TranslateMessage32_16( (const MSG32_16 *)msg, FALSE );
1776 /***********************************************************************
1777 * DispatchMessage (USER.114)
1779 LONG WINAPI DispatchMessage16( const MSG16* msg )
1784 HWND hwnd = WIN_Handle32( msg->hwnd );
1786 /* Process timer messages */
1787 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
1790 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
1791 msg->message, msg->wParam, GetTickCount() );
1794 if (!(wndPtr = WIN_GetPtr( hwnd )))
1796 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1799 if (wndPtr == WND_OTHER_PROCESS || wndPtr == WND_DESKTOP)
1801 if (IsWindow( hwnd )) SetLastError( ERROR_MESSAGE_SYNC_ONLY );
1802 else SetLastError( ERROR_INVALID_WINDOW_HANDLE );
1805 winproc = WINPROC_GetProc16( wndPtr->winproc, wndPtr->flags & WIN_ISUNICODE );
1806 WIN_ReleasePtr( wndPtr );
1808 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, hwnd, msg->message, msg->wParam, msg->lParam );
1809 retval = CallWindowProc16( winproc, msg->hwnd, msg->message, msg->wParam, msg->lParam );
1810 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg->message, retval, msg->wParam, msg->lParam );
1816 /***********************************************************************
1817 * DispatchMessage32 (USER.822)
1819 LONG WINAPI DispatchMessage32_16( const MSG32_16 *msg16, BOOL16 wHaveParamHigh )
1821 if (wHaveParamHigh == FALSE)
1822 return DispatchMessage16( &msg16->msg );
1827 msg.hwnd = WIN_Handle32( msg16->msg.hwnd );
1828 msg.message = msg16->msg.message;
1829 msg.wParam = MAKEWPARAM( msg16->msg.wParam, msg16->wParamHigh );
1830 msg.lParam = msg16->msg.lParam;
1831 msg.time = msg16->msg.time;
1832 msg.pt.x = msg16->msg.pt.x;
1833 msg.pt.y = msg16->msg.pt.y;
1834 return DispatchMessageA( &msg );
1839 /***********************************************************************
1840 * IsDialogMessage (USER.90)
1842 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, MSG16 *msg16 )
1847 msg.hwnd = WIN_Handle32(msg16->hwnd);
1848 hwndDlg32 = WIN_Handle32(hwndDlg);
1850 switch(msg16->message)
1855 msg.message = msg16->message;
1856 msg.wParam = msg16->wParam;
1857 msg.lParam = msg16->lParam;
1858 return IsDialogMessageA( hwndDlg32, &msg );
1861 if ((hwndDlg32 != msg.hwnd) && !IsChild( hwndDlg32, msg.hwnd )) return FALSE;
1862 TranslateMessage16( msg16 );
1863 DispatchMessage16( msg16 );
1868 /***********************************************************************
1869 * MsgWaitForMultipleObjects (USER.640)
1871 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD count, CONST HANDLE *handles,
1872 BOOL wait_all, DWORD timeout, DWORD mask )
1874 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
1875 wait_all ? MWMO_WAITALL : 0 );
1879 /**********************************************************************
1880 * SetDoubleClickTime (USER.20)
1882 void WINAPI SetDoubleClickTime16( UINT16 interval )
1884 SetDoubleClickTime( interval );
1888 /**********************************************************************
1889 * GetDoubleClickTime (USER.21)
1891 UINT16 WINAPI GetDoubleClickTime16(void)
1893 return GetDoubleClickTime();
1897 /***********************************************************************
1898 * PostQuitMessage (USER.6)
1900 void WINAPI PostQuitMessage16( INT16 exitCode )
1902 PostQuitMessage( exitCode );
1906 /**********************************************************************
1907 * GetKeyState (USER.106)
1909 INT16 WINAPI GetKeyState16(INT16 vkey)
1911 return GetKeyState(vkey);
1915 /**********************************************************************
1916 * GetKeyboardState (USER.222)
1918 BOOL WINAPI GetKeyboardState16( LPBYTE state )
1920 return GetKeyboardState( state );
1924 /**********************************************************************
1925 * SetKeyboardState (USER.223)
1927 BOOL WINAPI SetKeyboardState16( LPBYTE state )
1929 return SetKeyboardState( state );
1933 /***********************************************************************
1934 * SetMessageQueue (USER.266)
1936 BOOL16 WINAPI SetMessageQueue16( INT16 size )
1938 return SetMessageQueue( size );
1942 /***********************************************************************
1943 * UserYield (USER.332)
1945 void WINAPI UserYield16(void)
1948 PeekMessageW( &msg, 0, 0, 0, PM_REMOVE | PM_QS_SENDMESSAGE );
1952 /***********************************************************************
1953 * GetQueueStatus (USER.334)
1955 DWORD WINAPI GetQueueStatus16( UINT16 flags )
1957 return GetQueueStatus( flags );
1961 /***********************************************************************
1962 * GetInputState (USER.335)
1964 BOOL16 WINAPI GetInputState16(void)
1966 return GetInputState();
1970 /**********************************************************************
1971 * TranslateAccelerator (USER.178)
1973 INT16 WINAPI TranslateAccelerator16( HWND16 hwnd, HACCEL16 hAccel, LPMSG16 msg )
1978 msg32.message = msg->message;
1979 /* msg32.hwnd not used */
1980 msg32.wParam = msg->wParam;
1981 msg32.lParam = msg->lParam;
1982 return TranslateAcceleratorW( WIN_Handle32(hwnd), HACCEL_32(hAccel), &msg32 );
1986 /**********************************************************************
1987 * TranslateMDISysAccel (USER.451)
1989 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
1991 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
1994 msg32.hwnd = WIN_Handle32(msg->hwnd);
1995 msg32.message = msg->message;
1996 msg32.wParam = msg->wParam;
1997 msg32.lParam = msg->lParam;
1998 /* MDICLIENTINFO is still the same for win32 and win16 ... */
1999 return TranslateMDISysAccel( WIN_Handle32(hwndClient), &msg32 );
2005 /***********************************************************************
2008 static LRESULT button_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2010 static const UINT msg16_offset = BM_GETCHECK16 - BM_GETCHECK;
2019 return wow_handlers32.button_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2021 return wow_handlers32.button_proc( hwnd, msg, wParam, lParam, unicode );
2026 /***********************************************************************
2029 static LRESULT combo_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2031 static const UINT msg16_offset = CB_GETEDITSEL16 - CB_GETEDITSEL;
2035 case CB_INSERTSTRING16:
2036 case CB_SELECTSTRING16:
2037 case CB_FINDSTRING16:
2038 case CB_FINDSTRINGEXACT16:
2039 wParam = (INT)(INT16)wParam;
2041 case CB_ADDSTRING16:
2043 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2044 if ((style & CBS_HASSTRINGS) || !(style & (CBS_OWNERDRAWFIXED | CBS_OWNERDRAWVARIABLE)))
2045 lParam = (LPARAM)MapSL(lParam);
2046 msg -= msg16_offset;
2049 case CB_SETITEMHEIGHT16:
2050 case CB_GETITEMHEIGHT16:
2051 case CB_SETCURSEL16:
2052 case CB_GETLBTEXTLEN16:
2053 case CB_GETITEMDATA16:
2054 case CB_SETITEMDATA16:
2055 wParam = (INT)(INT16)wParam; /* signed integer */
2056 msg -= msg16_offset;
2058 case CB_GETDROPPEDCONTROLRECT16:
2059 lParam = (LPARAM)MapSL(lParam);
2063 RECT16 *r16 = (RECT16 *)lParam;
2064 wow_handlers32.combo_proc( hwnd, CB_GETDROPPEDCONTROLRECT, wParam, (LPARAM)&r, FALSE );
2067 r16->right = r.right;
2068 r16->bottom = r.bottom;
2072 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
2073 lParam = (LPARAM)MapSL(lParam);
2074 msg -= msg16_offset;
2076 case CB_GETLBTEXT16:
2077 wParam = (INT)(INT16)wParam;
2078 lParam = (LPARAM)MapSL(lParam);
2079 msg -= msg16_offset;
2081 case CB_GETEDITSEL16:
2082 wParam = lParam = 0; /* just in case */
2083 msg -= msg16_offset;
2085 case CB_LIMITTEXT16:
2086 case CB_SETEDITSEL16:
2087 case CB_DELETESTRING16:
2088 case CB_RESETCONTENT16:
2089 case CB_GETDROPPEDSTATE16:
2090 case CB_SHOWDROPDOWN16:
2092 case CB_GETCURSEL16:
2093 case CB_SETEXTENDEDUI16:
2094 case CB_GETEXTENDEDUI16:
2095 msg -= msg16_offset;
2098 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, unicode );
2100 return wow_handlers32.combo_proc( hwnd, msg, wParam, lParam, FALSE );
2104 #define GWW_HANDLE16 sizeof(void*)
2106 static void edit_lock_buffer( HWND hwnd )
2108 STACK16FRAME* stack16 = MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved));
2109 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2114 if (!hloc16) return;
2115 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2117 oldDS = stack16->ds;
2118 stack16->ds = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2119 size = LocalSize16(hloc16);
2120 if (LocalReAlloc( hloc32, size, LMEM_MOVEABLE ))
2122 char *text = MapSL( LocalLock16( hloc16 ));
2123 char *dest = LocalLock( hloc32 );
2124 memcpy( dest, text, size );
2125 LocalUnlock( hloc32 );
2126 LocalUnlock16( hloc16 );
2128 stack16->ds = oldDS;
2132 static void edit_unlock_buffer( HWND hwnd )
2134 STACK16FRAME* stack16 = MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved));
2135 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2140 if (!hloc16) return;
2141 if (!(hloc32 = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return;
2142 size = LocalSize( hloc32 );
2144 oldDS = stack16->ds;
2145 stack16->ds = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2146 if (LocalReAlloc16( hloc16, size, LMEM_MOVEABLE ))
2148 char *text = LocalLock( hloc32 );
2149 char *dest = MapSL( LocalLock16( hloc16 ));
2150 memcpy( dest, text, size );
2151 LocalUnlock( hloc32 );
2152 LocalUnlock16( hloc16 );
2154 stack16->ds = oldDS;
2157 static HLOCAL16 edit_get_handle( HWND hwnd )
2162 STACK16FRAME* stack16;
2164 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2166 if (hloc16) return hloc16;
2168 if (!(hloc = (HLOCAL)wow_handlers32.edit_proc( hwnd, EM_GETHANDLE, 0, 0, FALSE ))) return 0;
2169 alloc_size = LocalSize( hloc );
2171 stack16 = MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved));
2172 oldDS = stack16->ds;
2173 stack16->ds = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2175 if (!LocalHeapSize16())
2177 if (!LocalInit16(stack16->ds, 0, GlobalSize16(stack16->ds)))
2179 ERR("could not initialize local heap\n");
2184 if (!(hloc16 = LocalAlloc16(LMEM_MOVEABLE | LMEM_ZEROINIT, alloc_size)))
2186 ERR("could not allocate new 16 bit buffer\n");
2190 if (!(textA = MapSL(LocalLock16( hloc16))))
2192 ERR("could not lock new 16 bit buffer\n");
2193 LocalFree16(hloc16);
2197 memcpy( textA, LocalLock( hloc ), alloc_size );
2198 LocalUnlock( hloc );
2199 LocalUnlock16( hloc16 );
2200 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2203 stack16->ds = oldDS;
2207 static void edit_set_handle( HWND hwnd, HLOCAL16 hloc16 )
2209 STACK16FRAME* stack16 = MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved));
2210 HINSTANCE16 hInstance = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2211 HANDLE16 oldDS = stack16->ds;
2216 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) return;
2217 if (!hloc16) return;
2219 stack16->ds = hInstance;
2220 count = LocalSize16(hloc16);
2221 text = MapSL(LocalLock16(hloc16));
2222 if ((hloc32 = LocalAlloc(LMEM_MOVEABLE, count)))
2224 memcpy( LocalLock(hloc32), text, count );
2225 LocalUnlock(hloc32);
2226 LocalUnlock16(hloc16);
2227 SetWindowWord( hwnd, GWW_HANDLE16, hloc16 );
2229 stack16->ds = oldDS;
2231 if (hloc32) wow_handlers32.edit_proc( hwnd, EM_SETHANDLE, (WPARAM)hloc32, 0, FALSE );
2234 static void edit_destroy_handle( HWND hwnd )
2236 HLOCAL16 hloc16 = GetWindowWord( hwnd, GWW_HANDLE16 );
2239 STACK16FRAME* stack16 = MapSL(PtrToUlong(NtCurrentTeb()->WOW32Reserved));
2240 HANDLE16 oldDS = stack16->ds;
2242 stack16->ds = GetWindowLongPtrW( hwnd, GWLP_HINSTANCE );
2243 while (LocalUnlock16(hloc16)) ;
2244 LocalFree16(hloc16);
2245 stack16->ds = oldDS;
2246 SetWindowWord( hwnd, GWW_HANDLE16, 0 );
2250 /*********************************************************************
2253 static LRESULT edit_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2255 static const UINT msg16_offset = EM_GETSEL16 - EM_GETSEL;
2258 edit_lock_buffer( hwnd );
2262 case EM_SCROLLCARET16:
2263 case EM_GETMODIFY16:
2264 case EM_SETMODIFY16:
2265 case EM_GETLINECOUNT16:
2267 case EM_LINELENGTH16:
2268 case EM_LIMITTEXT16:
2272 case EM_LINEFROMCHAR16:
2273 case EM_SETPASSWORDCHAR16:
2274 case EM_EMPTYUNDOBUFFER16:
2275 case EM_SETREADONLY16:
2276 case EM_GETPASSWORDCHAR16:
2277 /* these messages missing from specs */
2282 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2285 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, 0, 0, FALSE );
2287 case EM_REPLACESEL16:
2289 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)MapSL(lParam), FALSE );
2291 case EM_LINESCROLL16:
2292 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, (INT)(SHORT)HIWORD(lParam),
2293 (INT)(SHORT)LOWORD(lParam), FALSE );
2295 case EM_LINEINDEX16:
2296 if ((INT16)wParam == -1) wParam = (WPARAM)-1;
2297 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2300 if ((short)LOWORD(lParam) == -1)
2307 wParam = LOWORD(lParam);
2308 lParam = HIWORD(lParam);
2310 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2316 RECT16 *r16 = MapSL(lParam);
2317 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2318 r16->left = rect.left;
2319 r16->top = rect.top;
2320 r16->right = rect.right;
2321 r16->bottom = rect.bottom;
2325 case EM_SETRECTNP16:
2329 RECT16 *r16 = MapSL(lParam);
2330 rect.left = r16->left;
2331 rect.top = r16->top;
2332 rect.right = r16->right;
2333 rect.bottom = r16->bottom;
2334 wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, (LPARAM)&rect, FALSE );
2337 case EM_SETHANDLE16:
2338 edit_set_handle( hwnd, (HLOCAL16)wParam );
2340 case EM_GETHANDLE16:
2341 result = edit_get_handle( hwnd );
2343 case EM_SETTABSTOPS16:
2345 INT16 *tabs16 = MapSL(lParam);
2346 INT i, count = wParam, *tabs = NULL;
2349 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, count * sizeof(*tabs) ))) return 0;
2350 for (i = 0; i < count; i++) tabs[i] = tabs16[i];
2352 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, count, (LPARAM)tabs, FALSE );
2353 HeapFree( GetProcessHeap(), 0, tabs );
2356 case EM_GETFIRSTVISIBLELINE16:
2357 if (!(GetWindowLongW( hwnd, GWL_STYLE ) & ES_MULTILINE)) break;
2358 result = wow_handlers32.edit_proc( hwnd, msg - msg16_offset, wParam, lParam, FALSE );
2360 case EM_SETWORDBREAKPROC16:
2362 struct word_break_thunk *thunk = add_word_break_thunk( (EDITWORDBREAKPROC16)lParam );
2363 result = wow_handlers32.edit_proc( hwnd, EM_SETWORDBREAKPROC, wParam, (LPARAM)thunk, FALSE );
2366 case EM_GETWORDBREAKPROC16:
2367 result = wow_handlers32.edit_proc( hwnd, EM_GETWORDBREAKPROC, wParam, lParam, FALSE );
2368 result = (LRESULT)get_word_break_thunk( (EDITWORDBREAKPROCA)result );
2371 edit_destroy_handle( hwnd );
2372 return wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode ); /* no unlock on destroy */
2375 if (LOWORD(wParam) == EM_GETTHUMB16 || LOWORD(wParam) == EM_LINESCROLL16) wParam -= msg16_offset;
2376 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2379 result = wow_handlers32.edit_proc( hwnd, msg, wParam, lParam, unicode );
2382 edit_unlock_buffer( hwnd );
2387 /***********************************************************************
2390 static LRESULT listbox_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2392 static const UINT msg16_offset = LB_ADDSTRING16 - LB_ADDSTRING;
2397 case LB_RESETCONTENT16:
2398 case LB_DELETESTRING16:
2399 case LB_GETITEMDATA16:
2400 case LB_SETITEMDATA16:
2402 case LB_GETTEXTLEN16:
2403 case LB_GETCURSEL16:
2404 case LB_GETTOPINDEX16:
2405 case LB_GETITEMHEIGHT16:
2406 case LB_SETCARETINDEX16:
2407 case LB_GETCARETINDEX16:
2408 case LB_SETTOPINDEX16:
2409 case LB_SETCOLUMNWIDTH16:
2410 case LB_GETSELCOUNT16:
2411 case LB_SELITEMRANGE16:
2412 case LB_SELITEMRANGEEX16:
2413 case LB_GETHORIZONTALEXTENT16:
2414 case LB_SETHORIZONTALEXTENT16:
2415 case LB_GETANCHORINDEX16:
2418 msg -= msg16_offset;
2422 case LB_SETCURSEL16:
2423 case LB_SETANCHORINDEX16:
2424 wParam = (INT)(INT16)wParam;
2425 msg -= msg16_offset;
2427 case LB_INSERTSTRING16:
2428 case LB_FINDSTRING16:
2429 case LB_FINDSTRINGEXACT16:
2430 case LB_SELECTSTRING16:
2431 wParam = (INT)(INT16)wParam;
2433 case LB_ADDSTRING16:
2436 DWORD style = GetWindowLongW( hwnd, GWL_STYLE );
2437 if ((style & LBS_HASSTRINGS) || !(style & (LBS_OWNERDRAWFIXED | LBS_OWNERDRAWVARIABLE)))
2438 lParam = (LPARAM)MapSL(lParam);
2439 msg -= msg16_offset;
2443 lParam = (LPARAM)MapSL(lParam);
2444 msg -= msg16_offset;
2446 case LB_SETITEMHEIGHT16:
2447 lParam = LOWORD(lParam);
2448 msg -= msg16_offset;
2450 case LB_GETITEMRECT16:
2453 RECT16 *r16 = MapSL(lParam);
2454 ret = wow_handlers32.listbox_proc( hwnd, LB_GETITEMRECT, (INT16)wParam, (LPARAM)&rect, FALSE );
2455 r16->left = rect.left;
2456 r16->top = rect.top;
2457 r16->right = rect.right;
2458 r16->bottom = rect.bottom;
2461 case LB_GETSELITEMS16:
2463 INT16 *array16 = MapSL( lParam );
2464 INT i, count = (INT16)wParam, *array;
2465 if (!(array = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*array) ))) return LB_ERRSPACE;
2466 ret = wow_handlers32.listbox_proc( hwnd, LB_GETSELITEMS, count, (LPARAM)array, FALSE );
2467 for (i = 0; i < ret; i++) array16[i] = array[i];
2468 HeapFree( GetProcessHeap(), 0, array );
2472 /* according to Win16 docs, DDL_DRIVES should make DDL_EXCLUSIVE
2473 * be set automatically (this is different in Win32) */
2474 if (wParam & DDL_DRIVES) wParam |= DDL_EXCLUSIVE;
2475 lParam = (LPARAM)MapSL(lParam);
2476 msg -= msg16_offset;
2478 case LB_SETTABSTOPS16:
2480 INT i, count, *tabs = NULL;
2481 INT16 *tabs16 = MapSL( lParam );
2483 if ((count = (INT16)wParam) > 0)
2485 if (!(tabs = HeapAlloc( GetProcessHeap(), 0, wParam * sizeof(*tabs) ))) return LB_ERRSPACE;
2486 for (i = 0; i < count; i++) tabs[i] = tabs16[i] << 1; /* FIXME */
2488 ret = wow_handlers32.listbox_proc( hwnd, LB_SETTABSTOPS, count, (LPARAM)tabs, FALSE );
2489 HeapFree( GetProcessHeap(), 0, tabs );
2493 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, unicode );
2495 return wow_handlers32.listbox_proc( hwnd, msg, wParam, lParam, FALSE );
2499 /***********************************************************************
2502 static LRESULT mdiclient_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2504 if (msg == WM_CREATE)
2506 LPCREATESTRUCTA cs = (LPCREATESTRUCTA)lParam;
2510 if (!(win = WIN_GetPtr( hwnd ))) return 0;
2511 is_win32 = (win == WND_OTHER_PROCESS || win == WND_DESKTOP || (win->flags & WIN_ISWIN32));
2512 WIN_ReleasePtr( win );
2514 /* Translation layer doesn't know what's in the cs->lpCreateParams
2515 * so we have to keep track of what environment we're in. */
2518 void *orig = cs->lpCreateParams;
2520 CLIENTCREATESTRUCT ccs;
2521 CLIENTCREATESTRUCT16 *ccs16 = MapSL( PtrToUlong( orig ));
2523 ccs.hWindowMenu = HMENU_32(ccs16->hWindowMenu);
2524 ccs.idFirstChild = ccs16->idFirstChild;
2525 cs->lpCreateParams = &ccs;
2526 ret = wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2527 cs->lpCreateParams = orig;
2531 return wow_handlers32.mdiclient_proc( hwnd, msg, wParam, lParam, unicode );
2535 /***********************************************************************
2538 static LRESULT scrollbar_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2540 static const UINT msg16_offset = SBM_SETPOS16 - SBM_SETPOS;
2546 case SBM_ENABLE_ARROWS16:
2547 msg -= msg16_offset;
2549 case SBM_SETRANGE16:
2550 msg = wParam ? SBM_SETRANGEREDRAW : SBM_SETRANGE;
2551 wParam = LOWORD(lParam);
2552 lParam = HIWORD(lParam);
2554 case SBM_GETRANGE16:
2557 wow_handlers32.scrollbar_proc( hwnd, SBM_GETRANGE, (WPARAM)&min, (LPARAM)&max, FALSE );
2558 return MAKELRESULT(min, max);
2561 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, unicode );
2563 return wow_handlers32.scrollbar_proc( hwnd, msg, wParam, lParam, FALSE );
2567 /***********************************************************************
2570 static LRESULT static_proc16( HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam, BOOL unicode )
2575 wParam = (WPARAM)HICON_32( (HICON16)wParam );
2576 return wow_handlers32.static_proc( hwnd, STM_SETICON, wParam, lParam, FALSE );
2578 return HICON_16( wow_handlers32.static_proc( hwnd, STM_GETICON, wParam, lParam, FALSE ));
2580 return wow_handlers32.static_proc( hwnd, msg, wParam, lParam, unicode );
2585 /***********************************************************************
2588 HWND create_window16( CREATESTRUCTW *cs, LPCWSTR className, HINSTANCE instance, UINT flags )
2590 /* map to module handle */
2591 if (instance && !((ULONG_PTR)instance >> 16))
2592 instance = HINSTANCE_32( GetExePtr( HINSTANCE_16(instance) ));
2594 return wow_handlers32.create_window( cs, className, instance, flags );
2598 void register_wow_handlers(void)
2600 static const struct wow_handlers16 handlers16 =
2610 call_window_proc_Ato16,
2611 call_dialog_proc_Ato16
2614 UserRegisterWowHandlers( &handlers16, &wow_handlers32 );