2 * Message queues related functions
4 * Copyright 1993, 1994 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
22 #include "wine/port.h"
32 #include "wine/winbase16.h"
33 #include "wine/winuser16.h"
38 #include "wine/debug.h"
39 #include "wine/server.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(msg);
44 /***********************************************************************
45 * QUEUE_CreateMsgQueue
47 * Creates a message queue. Doesn't link it into queue list!
49 static HQUEUE16 QUEUE_CreateMsgQueue(void)
53 MESSAGEQUEUE * msgQueue;
55 TRACE_(msg)("(): Creating message queue...\n");
57 if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
58 sizeof(MESSAGEQUEUE) )))
61 msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
65 SERVER_START_REQ( get_msg_queue )
67 wine_server_call_err( req );
68 handle = reply->handle;
73 ERR_(msg)("Cannot get thread queue\n");
74 GlobalFree16( hQueue );
77 msgQueue->server_queue = handle;
78 msgQueue->self = hQueue;
83 /***********************************************************************
86 * Get the current thread queue, creating it if required.
87 * QUEUE_Unlock is not needed since the queue can only be deleted by
88 * the current thread anyway.
90 MESSAGEQUEUE *QUEUE_Current(void)
92 HQUEUE16 hQueue = NtCurrentTeb()->queue;
96 if (!(hQueue = QUEUE_CreateMsgQueue())) return NULL;
97 SetThreadQueue16( 0, hQueue );
100 return GlobalLock16( hQueue );
105 /***********************************************************************
106 * QUEUE_DeleteMsgQueue
108 * Delete a message queue.
110 void QUEUE_DeleteMsgQueue(void)
112 HQUEUE16 hQueue = NtCurrentTeb()->queue;
113 MESSAGEQUEUE * msgQueue;
115 if (!hQueue) return; /* thread doesn't have a queue */
117 TRACE("(): Deleting message queue %04x\n", hQueue);
119 if (!(msgQueue = GlobalLock16( hQueue )))
121 ERR("invalid thread queue\n");
125 SetThreadQueue16( 0, 0 );
126 CloseHandle( msgQueue->server_queue );
127 GlobalFree16( hQueue );
131 /***********************************************************************
132 * InitThreadInput (USER.409)
134 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
136 MESSAGEQUEUE *queue = QUEUE_Current();
137 return queue ? queue->self : 0;
140 /***********************************************************************
141 * GetQueueStatus (USER32.@)
143 DWORD WINAPI GetQueueStatus( UINT flags )
147 /* check for pending X events */
148 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
149 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
151 SERVER_START_REQ( get_queue_status )
154 wine_server_call( req );
155 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
162 /***********************************************************************
163 * GetInputState (USER32.@)
165 BOOL WINAPI GetInputState(void)
169 /* check for pending X events */
170 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
171 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
173 SERVER_START_REQ( get_queue_status )
176 wine_server_call( req );
177 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
183 /***********************************************************************
184 * GetMessagePos (USER.119)
185 * GetMessagePos (USER32.@)
187 * The GetMessagePos() function returns a long value representing a
188 * cursor position, in screen coordinates, when the last message
189 * retrieved by the GetMessage() function occurs. The x-coordinate is
190 * in the low-order word of the return value, the y-coordinate is in
191 * the high-order word. The application can use the MAKEPOINT()
192 * macro to obtain a POINT structure from the return value.
194 * For the current cursor position, use GetCursorPos().
198 * Cursor position of last message on success, zero on failure.
205 DWORD WINAPI GetMessagePos(void)
209 if (!(queue = QUEUE_Current())) return 0;
210 return queue->GetMessagePosVal;
214 /***********************************************************************
215 * GetMessageTime (USER.120)
216 * GetMessageTime (USER32.@)
218 * GetMessageTime() returns the message time for the last message
219 * retrieved by the function. The time is measured in milliseconds with
220 * the same offset as GetTickCount().
222 * Since the tick count wraps, this is only useful for moderately short
223 * relative time comparisons.
227 * Time of last message on success, zero on failure.
234 LONG WINAPI GetMessageTime(void)
238 if (!(queue = QUEUE_Current())) return 0;
239 return queue->GetMessageTimeVal;
243 /***********************************************************************
244 * GetMessageExtraInfo (USER.288)
245 * GetMessageExtraInfo (USER32.@)
247 LPARAM WINAPI GetMessageExtraInfo(void)
251 if (!(queue = QUEUE_Current())) return 0;
252 return queue->GetMessageExtraInfoVal;
256 /***********************************************************************
257 * SetMessageExtraInfo (USER32.@)
259 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
264 if (!(queue = QUEUE_Current())) return 0;
265 old_value = queue->GetMessageExtraInfoVal;
266 queue->GetMessageExtraInfoVal = lParam;