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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/winuser16.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
31 DWORD USER16_AlertableWait
= 0;
33 /***********************************************************************
34 * SendMessage (USER.111)
36 LRESULT WINAPI
SendMessage16( HWND16 hwnd16
, UINT16 msg
, WPARAM16 wparam
, LPARAM lparam
)
41 HWND hwnd
= WIN_Handle32( hwnd16
);
43 if (hwnd
!= HWND_BROADCAST
&& WIN_IsCurrentThread(hwnd
))
45 /* call 16-bit window proc directly */
48 /* first the WH_CALLWNDPROC hook */
49 if (HOOK_IsHooked( WH_CALLWNDPROC
))
51 LPARAM lparam32
= lparam
;
53 if (WINPROC_MapMsg16To32A( hwnd
, msg
, wparam
, &msg32
, &wparam32
, &lparam32
) != -1)
59 cwp
.wParam
= wparam32
;
60 cwp
.lParam
= lparam32
;
61 HOOK_CallHooks( WH_CALLWNDPROC
, HC_ACTION
, 1, (LPARAM
)&cwp
, FALSE
);
62 WINPROC_UnmapMsg16To32A( hwnd
, msg32
, wparam32
, lparam32
, 0 );
63 /* FIXME: should reflect changes back into the message we send */
67 if (!(winproc
= (WNDPROC16
)GetWindowLong16( hwnd16
, GWLP_WNDPROC
))) return 0;
69 SPY_EnterMessage( SPY_SENDMESSAGE16
, hwnd
, msg
, wparam
, lparam
);
70 result
= CallWindowProc16( (WNDPROC16
)winproc
, hwnd16
, msg
, wparam
, lparam
);
71 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
, result
, wparam
, lparam
);
73 else /* map to 32-bit unicode for inter-thread/process message */
75 if (WINPROC_MapMsg16To32W( hwnd
, msg
, wparam
, &msg32
, &wparam32
, &lparam
) == -1)
77 result
= WINPROC_UnmapMsg16To32W( hwnd
, msg32
, wparam32
, lparam
,
78 SendMessageW( hwnd
, msg32
, wparam32
, lparam
) );
84 /***********************************************************************
85 * PostMessage (USER.110)
87 BOOL16 WINAPI
PostMessage16( HWND16 hwnd16
, UINT16 msg
, WPARAM16 wparam
, LPARAM lparam
)
91 HWND hwnd
= WIN_Handle32( hwnd16
);
93 switch (WINPROC_MapMsg16To32W( hwnd
, msg
, wparam
, &msg32
, &wparam32
, &lparam
))
96 return PostMessageW( hwnd
, msg32
, wparam32
, lparam
);
98 ERR( "16-bit message 0x%04x contains pointer, cannot post\n", msg
);
106 /***********************************************************************
107 * PostAppMessage (USER.116)
109 BOOL16 WINAPI
PostAppMessage16( HTASK16 hTask
, UINT16 msg
, WPARAM16 wparam
, LPARAM lparam
)
113 DWORD tid
= HTASK_32( hTask
);
114 if (!tid
) return FALSE
;
116 switch (WINPROC_MapMsg16To32W( 0, msg
, wparam
, &msg32
, &wparam32
, &lparam
))
119 return PostThreadMessageW( tid
, msg32
, wparam32
, lparam
);
121 ERR( "16-bit message %x contains pointer, cannot post\n", msg
);
129 /***********************************************************************
130 * InSendMessage (USER.192)
132 BOOL16 WINAPI
InSendMessage16(void)
134 return InSendMessage();
138 /***********************************************************************
139 * ReplyMessage (USER.115)
141 void WINAPI
ReplyMessage16( LRESULT result
)
143 ReplyMessage( result
);
147 /***********************************************************************
148 * PeekMessage32 (USER.819)
150 BOOL16 WINAPI
PeekMessage32_16( MSG32_16
*msg16
, HWND16 hwnd16
,
151 UINT16 first
, UINT16 last
, UINT16 flags
,
152 BOOL16 wHaveParamHigh
)
155 HWND hwnd
= WIN_Handle32( hwnd16
);
157 if(USER16_AlertableWait
)
158 MsgWaitForMultipleObjectsEx( 0, NULL
, 1, 0, MWMO_ALERTABLE
);
159 if (!PeekMessageW( &msg
, hwnd
, first
, last
, flags
)) return FALSE
;
161 msg16
->msg
.hwnd
= HWND_16( msg
.hwnd
);
162 msg16
->msg
.lParam
= msg
.lParam
;
163 msg16
->msg
.time
= msg
.time
;
164 msg16
->msg
.pt
.x
= (INT16
)msg
.pt
.x
;
165 msg16
->msg
.pt
.y
= (INT16
)msg
.pt
.y
;
166 if (wHaveParamHigh
) msg16
->wParamHigh
= HIWORD(msg
.wParam
);
168 return (WINPROC_MapMsg32WTo16( msg
.hwnd
, msg
.message
, msg
.wParam
,
169 &msg16
->msg
.message
, &msg16
->msg
.wParam
,
170 &msg16
->msg
.lParam
) != -1);
174 /***********************************************************************
175 * PeekMessage (USER.109)
177 BOOL16 WINAPI
PeekMessage16( MSG16
*msg
, HWND16 hwnd
,
178 UINT16 first
, UINT16 last
, UINT16 flags
)
180 return PeekMessage32_16( (MSG32_16
*)msg
, hwnd
, first
, last
, flags
, FALSE
);
184 /***********************************************************************
185 * GetMessage32 (USER.820)
187 BOOL16 WINAPI
GetMessage32_16( MSG32_16
*msg16
, HWND16 hwnd16
, UINT16 first
,
188 UINT16 last
, BOOL16 wHaveParamHigh
)
191 HWND hwnd
= WIN_Handle32( hwnd16
);
195 if(USER16_AlertableWait
)
196 MsgWaitForMultipleObjectsEx( 0, NULL
, INFINITE
, 0, MWMO_ALERTABLE
);
197 GetMessageW( &msg
, hwnd
, first
, last
);
198 msg16
->msg
.hwnd
= HWND_16( msg
.hwnd
);
199 msg16
->msg
.lParam
= msg
.lParam
;
200 msg16
->msg
.time
= msg
.time
;
201 msg16
->msg
.pt
.x
= (INT16
)msg
.pt
.x
;
202 msg16
->msg
.pt
.y
= (INT16
)msg
.pt
.y
;
203 if (wHaveParamHigh
) msg16
->wParamHigh
= HIWORD(msg
.wParam
);
205 while (WINPROC_MapMsg32WTo16( msg
.hwnd
, msg
.message
, msg
.wParam
,
206 &msg16
->msg
.message
, &msg16
->msg
.wParam
,
207 &msg16
->msg
.lParam
) == -1);
209 TRACE( "message %04x, hwnd %p, filter(%04x - %04x)\n",
210 msg16
->msg
.message
, hwnd
, first
, last
);
212 return msg16
->msg
.message
!= WM_QUIT
;
216 /***********************************************************************
217 * GetMessage (USER.108)
219 BOOL16 WINAPI
GetMessage16( MSG16
*msg
, HWND16 hwnd
, UINT16 first
, UINT16 last
)
221 return GetMessage32_16( (MSG32_16
*)msg
, hwnd
, first
, last
, FALSE
);
225 /***********************************************************************
226 * TranslateMessage32 (USER.821)
228 BOOL16 WINAPI
TranslateMessage32_16( const MSG32_16
*msg
, BOOL16 wHaveParamHigh
)
232 msg32
.hwnd
= WIN_Handle32( msg
->msg
.hwnd
);
233 msg32
.message
= msg
->msg
.message
;
234 msg32
.wParam
= MAKEWPARAM( msg
->msg
.wParam
, wHaveParamHigh
? msg
->wParamHigh
: 0 );
235 msg32
.lParam
= msg
->msg
.lParam
;
236 return TranslateMessage( &msg32
);
240 /***********************************************************************
241 * TranslateMessage (USER.113)
243 BOOL16 WINAPI
TranslateMessage16( const MSG16
*msg
)
245 return TranslateMessage32_16( (MSG32_16
*)msg
, FALSE
);
249 /***********************************************************************
250 * DispatchMessage (USER.114)
252 LONG WINAPI
DispatchMessage16( const MSG16
* msg
)
257 HWND hwnd
= WIN_Handle32( msg
->hwnd
);
259 /* Process timer messages */
260 if ((msg
->message
== WM_TIMER
) || (msg
->message
== WM_SYSTIMER
))
263 return CallWindowProc16( (WNDPROC16
)msg
->lParam
, msg
->hwnd
,
264 msg
->message
, msg
->wParam
, GetTickCount() );
267 if (!(wndPtr
= WIN_GetPtr( hwnd
)))
269 if (msg
->hwnd
) SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
272 if (wndPtr
== WND_OTHER_PROCESS
)
274 if (IsWindow( hwnd
))
275 ERR( "cannot dispatch msg to other process window %p\n", hwnd
);
276 SetLastError( ERROR_INVALID_WINDOW_HANDLE
);
279 winproc
= (WNDPROC16
)wndPtr
->winproc
;
280 WIN_ReleasePtr( wndPtr
);
282 SPY_EnterMessage( SPY_DISPATCHMESSAGE16
, hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
283 retval
= CallWindowProc16( winproc
, msg
->hwnd
, msg
->message
, msg
->wParam
, msg
->lParam
);
284 SPY_ExitMessage( SPY_RESULT_OK16
, hwnd
, msg
->message
, retval
, msg
->wParam
, msg
->lParam
);
290 /***********************************************************************
291 * DispatchMessage32 (USER.822)
293 LONG WINAPI
DispatchMessage32_16( const MSG32_16
*msg16
, BOOL16 wHaveParamHigh
)
295 if (wHaveParamHigh
== FALSE
)
296 return DispatchMessage16( &msg16
->msg
);
301 msg
.hwnd
= WIN_Handle32( msg16
->msg
.hwnd
);
302 msg
.message
= msg16
->msg
.message
;
303 msg
.wParam
= MAKEWPARAM( msg16
->msg
.wParam
, msg16
->wParamHigh
);
304 msg
.lParam
= msg16
->msg
.lParam
;
305 msg
.time
= msg16
->msg
.time
;
306 msg
.pt
.x
= msg16
->msg
.pt
.x
;
307 msg
.pt
.y
= msg16
->msg
.pt
.y
;
308 return DispatchMessageA( &msg
);
313 /***********************************************************************
314 * IsDialogMessage (USER.90)
316 BOOL16 WINAPI
IsDialogMessage16( HWND16 hwndDlg
, MSG16
*msg16
)
321 msg
.hwnd
= WIN_Handle32(msg16
->hwnd
);
322 hwndDlg32
= WIN_Handle32(hwndDlg
);
324 switch(msg16
->message
)
329 msg
.lParam
= msg16
->lParam
;
330 WINPROC_MapMsg16To32W( msg
.hwnd
, msg16
->message
, msg16
->wParam
,
331 &msg
.message
, &msg
.wParam
, &msg
.lParam
);
332 /* these messages don't need an unmap */
333 return IsDialogMessageW( hwndDlg32
, &msg
);
336 if ((hwndDlg32
!= msg
.hwnd
) && !IsChild( hwndDlg32
, msg
.hwnd
)) return FALSE
;
337 TranslateMessage16( msg16
);
338 DispatchMessage16( msg16
);
343 /***********************************************************************
344 * MsgWaitForMultipleObjects (USER.640)
346 DWORD WINAPI
MsgWaitForMultipleObjects16( DWORD count
, CONST HANDLE
*handles
,
347 BOOL wait_all
, DWORD timeout
, DWORD mask
)
349 return MsgWaitForMultipleObjectsEx( count
, handles
, timeout
, mask
,
350 wait_all
? MWMO_WAITALL
: 0 );
354 /**********************************************************************
355 * SetDoubleClickTime (USER.20)
357 void WINAPI
SetDoubleClickTime16( UINT16 interval
)
359 SetDoubleClickTime( interval
);
363 /**********************************************************************
364 * GetDoubleClickTime (USER.21)
366 UINT16 WINAPI
GetDoubleClickTime16(void)
368 return GetDoubleClickTime();
372 /***********************************************************************
373 * PostQuitMessage (USER.6)
375 void WINAPI
PostQuitMessage16( INT16 exitCode
)
377 PostQuitMessage( exitCode
);
381 /**********************************************************************
382 * GetKeyState (USER.106)
384 INT16 WINAPI
GetKeyState16(INT16 vkey
)
386 return GetKeyState(vkey
);
390 /**********************************************************************
391 * GetKeyboardState (USER.222)
393 BOOL WINAPI
GetKeyboardState16( LPBYTE state
)
395 return GetKeyboardState( state
);
399 /**********************************************************************
400 * SetKeyboardState (USER.223)
402 BOOL WINAPI
SetKeyboardState16( LPBYTE state
)
404 return SetKeyboardState( state
);
408 /***********************************************************************
409 * SetMessageQueue (USER.266)
411 BOOL16 WINAPI
SetMessageQueue16( INT16 size
)
413 return SetMessageQueue( size
);
417 /***********************************************************************
418 * GetQueueStatus (USER.334)
420 DWORD WINAPI
GetQueueStatus16( UINT16 flags
)
422 return GetQueueStatus( flags
);
426 /***********************************************************************
427 * GetInputState (USER.335)
429 BOOL16 WINAPI
GetInputState16(void)
431 return GetInputState();
435 /**********************************************************************
436 * TranslateAccelerator (USER.178)
438 INT16 WINAPI
TranslateAccelerator16( HWND16 hwnd
, HACCEL16 hAccel
, LPMSG16 msg
)
443 msg32
.message
= msg
->message
;
444 /* msg32.hwnd not used */
445 msg32
.wParam
= msg
->wParam
;
446 msg32
.lParam
= msg
->lParam
;
447 return TranslateAcceleratorW( WIN_Handle32(hwnd
), HACCEL_32(hAccel
), &msg32
);
451 /**********************************************************************
452 * TranslateMDISysAccel (USER.451)
454 BOOL16 WINAPI
TranslateMDISysAccel16( HWND16 hwndClient
, LPMSG16 msg
)
456 if (msg
->message
== WM_KEYDOWN
|| msg
->message
== WM_SYSKEYDOWN
)
459 msg32
.hwnd
= WIN_Handle32(msg
->hwnd
);
460 msg32
.message
= msg
->message
;
461 msg32
.wParam
= msg
->wParam
;
462 msg32
.lParam
= msg
->lParam
;
463 /* MDICLIENTINFO is still the same for win32 and win16 ... */
464 return TranslateMDISysAccel( WIN_Handle32(hwndClient
), &msg32
);