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
29 #include "wine/winbase16.h"
30 #include "wine/winuser16.h"
35 #include "wine/debug.h"
36 #include "wine/server.h"
38 WINE_DEFAULT_DEBUG_CHANNEL(msg);
41 /***********************************************************************
42 * QUEUE_CreateMsgQueue
44 * Creates a message queue. Doesn't link it into queue list!
46 static HQUEUE16 QUEUE_CreateMsgQueue(void)
50 MESSAGEQUEUE * msgQueue;
52 TRACE_(msg)("(): Creating message queue...\n");
54 if (!(hQueue = GlobalAlloc16( GMEM_FIXED | GMEM_ZEROINIT,
55 sizeof(MESSAGEQUEUE) )))
58 msgQueue = (MESSAGEQUEUE *) GlobalLock16( hQueue );
62 SERVER_START_REQ( get_msg_queue )
64 wine_server_call_err( req );
65 handle = reply->handle;
70 ERR_(msg)("Cannot get thread queue");
71 GlobalFree16( hQueue );
74 msgQueue->server_queue = handle;
75 msgQueue->self = hQueue;
80 /***********************************************************************
83 * Get the current thread queue, creating it if required.
84 * QUEUE_Unlock is not needed since the queue can only be deleted by
85 * the current thread anyway.
87 MESSAGEQUEUE *QUEUE_Current(void)
89 HQUEUE16 hQueue = NtCurrentTeb()->queue;
93 if (!(hQueue = QUEUE_CreateMsgQueue())) return NULL;
94 SetThreadQueue16( 0, hQueue );
97 return GlobalLock16( hQueue );
102 /***********************************************************************
103 * QUEUE_DeleteMsgQueue
105 * Delete a message queue.
107 void QUEUE_DeleteMsgQueue(void)
109 HQUEUE16 hQueue = NtCurrentTeb()->queue;
110 MESSAGEQUEUE * msgQueue;
112 if (!hQueue) return; /* thread doesn't have a queue */
114 TRACE("(): Deleting message queue %04x\n", hQueue);
116 if (!(msgQueue = GlobalLock16( hQueue )))
118 ERR("invalid thread queue\n");
122 SetThreadQueue16( 0, 0 );
123 CloseHandle( msgQueue->server_queue );
124 GlobalFree16( hQueue );
128 /***********************************************************************
129 * InitThreadInput (USER.409)
131 HQUEUE16 WINAPI InitThreadInput16( WORD unknown, WORD flags )
133 MESSAGEQUEUE *queue = QUEUE_Current();
134 return queue ? queue->self : 0;
137 /***********************************************************************
138 * GetQueueStatus (USER32.@)
140 DWORD WINAPI GetQueueStatus( UINT flags )
144 /* check for pending X events */
145 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
146 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
148 SERVER_START_REQ( get_queue_status )
151 wine_server_call( req );
152 ret = MAKELONG( reply->changed_bits & flags, reply->wake_bits & flags );
159 /***********************************************************************
160 * GetInputState (USER32.@)
162 BOOL WINAPI GetInputState(void)
166 /* check for pending X events */
167 if (USER_Driver.pMsgWaitForMultipleObjectsEx)
168 USER_Driver.pMsgWaitForMultipleObjectsEx( 0, NULL, 0, 0, 0 );
170 SERVER_START_REQ( get_queue_status )
173 wine_server_call( req );
174 ret = reply->wake_bits & (QS_KEY | QS_MOUSEBUTTON);
180 /***********************************************************************
181 * GetMessagePos (USER.119)
182 * GetMessagePos (USER32.@)
184 * The GetMessagePos() function returns a long value representing a
185 * cursor position, in screen coordinates, when the last message
186 * retrieved by the GetMessage() function occurs. The x-coordinate is
187 * in the low-order word of the return value, the y-coordinate is in
188 * the high-order word. The application can use the MAKEPOINT()
189 * macro to obtain a POINT structure from the return value.
191 * For the current cursor position, use GetCursorPos().
195 * Cursor position of last message on success, zero on failure.
202 DWORD WINAPI GetMessagePos(void)
206 if (!(queue = QUEUE_Current())) return 0;
207 return queue->GetMessagePosVal;
211 /***********************************************************************
212 * GetMessageTime (USER.120)
213 * GetMessageTime (USER32.@)
215 * GetMessageTime() returns the message time for the last message
216 * retrieved by the function. The time is measured in milliseconds with
217 * the same offset as GetTickCount().
219 * Since the tick count wraps, this is only useful for moderately short
220 * relative time comparisons.
224 * Time of last message on success, zero on failure.
231 LONG WINAPI GetMessageTime(void)
235 if (!(queue = QUEUE_Current())) return 0;
236 return queue->GetMessageTimeVal;
240 /***********************************************************************
241 * GetMessageExtraInfo (USER.288)
242 * GetMessageExtraInfo (USER32.@)
244 LPARAM WINAPI GetMessageExtraInfo(void)
248 if (!(queue = QUEUE_Current())) return 0;
249 return queue->GetMessageExtraInfoVal;
253 /***********************************************************************
254 * SetMessageExtraInfo (USER32.@)
256 LPARAM WINAPI SetMessageExtraInfo(LPARAM lParam)
261 if (!(queue = QUEUE_Current())) return 0;
262 old_value = queue->GetMessageExtraInfoVal;
263 queue->GetMessageExtraInfoVal = lParam;