Get rid of the WIN_NEEDS_BEGINPAINT flag, Windows will happily loop
[wine/dcerpc.git] / dlls / user / msg16.c
blobab2e228f67998fe3a341a925971f2e7dea89cd4a
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #include "wine/winuser16.h"
22 #include "wownt32.h"
23 #include "winerror.h"
24 #include "message.h"
25 #include "win.h"
26 #include "winproc.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 )
38 LRESULT result;
39 UINT msg32;
40 WPARAM wparam32;
41 HWND hwnd = WIN_Handle32( hwnd16 );
43 if (hwnd != HWND_BROADCAST && WIN_IsCurrentThread(hwnd))
45 /* call 16-bit window proc directly */
46 WNDPROC16 winproc;
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)
55 CWPSTRUCT cwp;
57 cwp.hwnd = hwnd;
58 cwp.message = msg32;
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)
76 return 0;
77 result = WINPROC_UnmapMsg16To32W( hwnd, msg32, wparam32, lparam,
78 SendMessageW( hwnd, msg32, wparam32, lparam ) );
80 return result;
84 /***********************************************************************
85 * PostMessage (USER.110)
87 BOOL16 WINAPI PostMessage16( HWND16 hwnd16, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
89 WPARAM wparam32;
90 UINT msg32;
91 HWND hwnd = WIN_Handle32( hwnd16 );
93 switch (WINPROC_MapMsg16To32W( hwnd, msg, wparam, &msg32, &wparam32, &lparam ))
95 case 0:
96 return PostMessageW( hwnd, msg32, wparam32, lparam );
97 case 1:
98 ERR( "16-bit message 0x%04x contains pointer, cannot post\n", msg );
99 return FALSE;
100 default:
101 return FALSE;
106 /***********************************************************************
107 * PostAppMessage (USER.116)
109 BOOL16 WINAPI PostAppMessage16( HTASK16 hTask, UINT16 msg, WPARAM16 wparam, LPARAM lparam )
111 WPARAM wparam32;
112 UINT msg32;
113 DWORD tid = HTASK_32( hTask );
114 if (!tid) return FALSE;
116 switch (WINPROC_MapMsg16To32W( 0, msg, wparam, &msg32, &wparam32, &lparam ))
118 case 0:
119 return PostThreadMessageW( tid, msg32, wparam32, lparam );
120 case 1:
121 ERR( "16-bit message %x contains pointer, cannot post\n", msg );
122 return FALSE;
123 default:
124 return FALSE;
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 )
154 MSG msg;
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 )
190 MSG msg;
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 )
230 MSG msg32;
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 )
254 WND * wndPtr;
255 WNDPROC16 winproc;
256 LONG retval;
257 HWND hwnd = WIN_Handle32( msg->hwnd );
259 /* Process timer messages */
260 if ((msg->message == WM_TIMER) || (msg->message == WM_SYSTIMER))
262 if (msg->lParam)
264 /* before calling window proc, verify whether timer is still valid;
265 there's a slim chance that the application kills the timer
266 between GetMessage and DispatchMessage API calls */
267 if (!TIMER_IsTimerValid(hwnd, (UINT) msg->wParam, (WNDPROC)msg->lParam))
268 return 0; /* invalid winproc */
270 return CallWindowProc16( (WNDPROC16)msg->lParam, msg->hwnd,
271 msg->message, msg->wParam, GetTickCount() );
275 if (!(wndPtr = WIN_GetPtr( hwnd )))
277 if (msg->hwnd) SetLastError( ERROR_INVALID_WINDOW_HANDLE );
278 return 0;
280 if (wndPtr == WND_OTHER_PROCESS)
282 if (IsWindow( hwnd ))
283 ERR( "cannot dispatch msg to other process window %p\n", hwnd );
284 SetLastError( ERROR_INVALID_WINDOW_HANDLE );
285 return 0;
287 winproc = (WNDPROC16)wndPtr->winproc;
288 WIN_ReleasePtr( wndPtr );
290 SPY_EnterMessage( SPY_DISPATCHMESSAGE16, hwnd, msg->message, msg->wParam, msg->lParam );
291 retval = CallWindowProc16( winproc, msg->hwnd, msg->message, msg->wParam, msg->lParam );
292 SPY_ExitMessage( SPY_RESULT_OK16, hwnd, msg->message, retval, msg->wParam, msg->lParam );
294 return retval;
298 /***********************************************************************
299 * DispatchMessage32 (USER.822)
301 LONG WINAPI DispatchMessage32_16( const MSG32_16 *msg16, BOOL16 wHaveParamHigh )
303 if (wHaveParamHigh == FALSE)
304 return DispatchMessage16( &msg16->msg );
305 else
307 MSG msg;
309 msg.hwnd = WIN_Handle32( msg16->msg.hwnd );
310 msg.message = msg16->msg.message;
311 msg.wParam = MAKEWPARAM( msg16->msg.wParam, msg16->wParamHigh );
312 msg.lParam = msg16->msg.lParam;
313 msg.time = msg16->msg.time;
314 msg.pt.x = msg16->msg.pt.x;
315 msg.pt.y = msg16->msg.pt.y;
316 return DispatchMessageA( &msg );
321 /***********************************************************************
322 * IsDialogMessage (USER.90)
324 BOOL16 WINAPI IsDialogMessage16( HWND16 hwndDlg, MSG16 *msg16 )
326 MSG msg;
327 HWND hwndDlg32;
329 msg.hwnd = WIN_Handle32(msg16->hwnd);
330 hwndDlg32 = WIN_Handle32(hwndDlg);
332 switch(msg16->message)
334 case WM_KEYDOWN:
335 case WM_CHAR:
336 case WM_SYSCHAR:
337 msg.lParam = msg16->lParam;
338 WINPROC_MapMsg16To32W( msg.hwnd, msg16->message, msg16->wParam,
339 &msg.message, &msg.wParam, &msg.lParam );
340 /* these messages don't need an unmap */
341 return IsDialogMessageW( hwndDlg32, &msg );
344 if ((hwndDlg32 != msg.hwnd) && !IsChild( hwndDlg32, msg.hwnd )) return FALSE;
345 TranslateMessage16( msg16 );
346 DispatchMessage16( msg16 );
347 return TRUE;
351 /***********************************************************************
352 * MsgWaitForMultipleObjects (USER.640)
354 DWORD WINAPI MsgWaitForMultipleObjects16( DWORD count, CONST HANDLE *handles,
355 BOOL wait_all, DWORD timeout, DWORD mask )
357 return MsgWaitForMultipleObjectsEx( count, handles, timeout, mask,
358 wait_all ? MWMO_WAITALL : 0 );
362 /**********************************************************************
363 * SetDoubleClickTime (USER.20)
365 void WINAPI SetDoubleClickTime16( UINT16 interval )
367 SetDoubleClickTime( interval );
371 /**********************************************************************
372 * GetDoubleClickTime (USER.21)
374 UINT16 WINAPI GetDoubleClickTime16(void)
376 return GetDoubleClickTime();
380 /***********************************************************************
381 * PostQuitMessage (USER.6)
383 void WINAPI PostQuitMessage16( INT16 exitCode )
385 PostQuitMessage( exitCode );
389 /**********************************************************************
390 * GetKeyState (USER.106)
392 INT16 WINAPI GetKeyState16(INT16 vkey)
394 return GetKeyState(vkey);
398 /**********************************************************************
399 * GetKeyboardState (USER.222)
401 BOOL WINAPI GetKeyboardState16( LPBYTE state )
403 return GetKeyboardState( state );
407 /**********************************************************************
408 * SetKeyboardState (USER.223)
410 BOOL WINAPI SetKeyboardState16( LPBYTE state )
412 return SetKeyboardState( state );
416 /***********************************************************************
417 * SetMessageQueue (USER.266)
419 BOOL16 WINAPI SetMessageQueue16( INT16 size )
421 return SetMessageQueue( size );
425 /***********************************************************************
426 * GetQueueStatus (USER.334)
428 DWORD WINAPI GetQueueStatus16( UINT16 flags )
430 return GetQueueStatus( flags );
434 /***********************************************************************
435 * GetInputState (USER.335)
437 BOOL16 WINAPI GetInputState16(void)
439 return GetInputState();
443 /**********************************************************************
444 * TranslateAccelerator (USER.178)
446 INT16 WINAPI TranslateAccelerator16( HWND16 hwnd, HACCEL16 hAccel, LPMSG16 msg )
448 MSG msg32;
450 if (!msg) return 0;
451 msg32.message = msg->message;
452 /* msg32.hwnd not used */
453 msg32.wParam = msg->wParam;
454 msg32.lParam = msg->lParam;
455 return TranslateAcceleratorW( WIN_Handle32(hwnd), HACCEL_32(hAccel), &msg32 );
459 /**********************************************************************
460 * TranslateMDISysAccel (USER.451)
462 BOOL16 WINAPI TranslateMDISysAccel16( HWND16 hwndClient, LPMSG16 msg )
464 if (msg->message == WM_KEYDOWN || msg->message == WM_SYSKEYDOWN)
466 MSG msg32;
467 msg32.hwnd = WIN_Handle32(msg->hwnd);
468 msg32.message = msg->message;
469 msg32.wParam = msg->wParam;
470 msg32.lParam = msg->lParam;
471 /* MDICLIENTINFO is still the same for win32 and win16 ... */
472 return TranslateMDISysAccel( WIN_Handle32(hwndClient), &msg32 );
474 return 0;