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
27 #include "wine/winbase16.h"
28 #include "wine/winuser16.h"
33 #include "wine/debug.h"
34 #include "wine/server.h"
36 WINE_DEFAULT_DEBUG_CHANNEL(msg
);
39 /***********************************************************************
40 * QUEUE_CreateMsgQueue
42 * Creates a message queue. Doesn't link it into queue list!
44 static HQUEUE16
QUEUE_CreateMsgQueue(void)
48 MESSAGEQUEUE
* msgQueue
;
50 TRACE_(msg
)("(): Creating message queue...\n");
52 if (!(hQueue
= GlobalAlloc16( GMEM_FIXED
| GMEM_ZEROINIT
,
53 sizeof(MESSAGEQUEUE
) )))
56 msgQueue
= (MESSAGEQUEUE
*) GlobalLock16( hQueue
);
60 SERVER_START_REQ( get_msg_queue
)
62 wine_server_call_err( req
);
63 handle
= reply
->handle
;
68 ERR_(msg
)("Cannot get thread queue");
69 GlobalFree16( hQueue
);
72 msgQueue
->server_queue
= handle
;
73 msgQueue
->self
= hQueue
;
78 /***********************************************************************
81 * Get the current thread queue, creating it if required.
82 * QUEUE_Unlock is not needed since the queue can only be deleted by
83 * the current thread anyway.
85 MESSAGEQUEUE
*QUEUE_Current(void)
87 HQUEUE16 hQueue
= NtCurrentTeb()->queue
;
91 if (!(hQueue
= QUEUE_CreateMsgQueue())) return NULL
;
92 SetThreadQueue16( 0, hQueue
);
95 return GlobalLock16( hQueue
);
100 /***********************************************************************
101 * QUEUE_DeleteMsgQueue
103 * Delete a message queue.
105 void QUEUE_DeleteMsgQueue(void)
107 HQUEUE16 hQueue
= NtCurrentTeb()->queue
;
108 MESSAGEQUEUE
* msgQueue
;
110 if (!hQueue
) return; /* thread doesn't have a queue */
112 TRACE("(): Deleting message queue %04x\n", hQueue
);
114 if (!(msgQueue
= GlobalLock16( hQueue
)))
116 ERR("invalid thread queue\n");
120 SetThreadQueue16( 0, 0 );
121 CloseHandle( msgQueue
->server_queue
);
122 GlobalFree16( hQueue
);
126 /***********************************************************************
127 * InitThreadInput (USER.409)
129 HQUEUE16 WINAPI
InitThreadInput16( WORD unknown
, WORD flags
)
131 MESSAGEQUEUE
*queue
= QUEUE_Current();
132 return queue
? queue
->self
: 0;
135 /***********************************************************************
136 * GetQueueStatus (USER32.@)
138 DWORD WINAPI
GetQueueStatus( UINT flags
)
142 /* check for pending X events */
143 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
144 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
146 SERVER_START_REQ( get_queue_status
)
149 wine_server_call( req
);
150 ret
= MAKELONG( reply
->changed_bits
& flags
, reply
->wake_bits
& flags
);
157 /***********************************************************************
158 * GetInputState (USER32.@)
160 BOOL WINAPI
GetInputState(void)
164 /* check for pending X events */
165 if (USER_Driver
.pMsgWaitForMultipleObjectsEx
)
166 USER_Driver
.pMsgWaitForMultipleObjectsEx( 0, NULL
, 0, 0, 0 );
168 SERVER_START_REQ( get_queue_status
)
171 wine_server_call( req
);
172 ret
= reply
->wake_bits
& (QS_KEY
| QS_MOUSEBUTTON
);
178 /***********************************************************************
179 * GetMessagePos (USER.119)
180 * GetMessagePos (USER32.@)
182 * The GetMessagePos() function returns a long value representing a
183 * cursor position, in screen coordinates, when the last message
184 * retrieved by the GetMessage() function occurs. The x-coordinate is
185 * in the low-order word of the return value, the y-coordinate is in
186 * the high-order word. The application can use the MAKEPOINT()
187 * macro to obtain a POINT structure from the return value.
189 * For the current cursor position, use GetCursorPos().
193 * Cursor position of last message on success, zero on failure.
200 DWORD WINAPI
GetMessagePos(void)
204 if (!(queue
= QUEUE_Current())) return 0;
205 return queue
->GetMessagePosVal
;
209 /***********************************************************************
210 * GetMessageTime (USER.120)
211 * GetMessageTime (USER32.@)
213 * GetMessageTime() returns the message time for the last message
214 * retrieved by the function. The time is measured in milliseconds with
215 * the same offset as GetTickCount().
217 * Since the tick count wraps, this is only useful for moderately short
218 * relative time comparisons.
222 * Time of last message on success, zero on failure.
229 LONG WINAPI
GetMessageTime(void)
233 if (!(queue
= QUEUE_Current())) return 0;
234 return queue
->GetMessageTimeVal
;
238 /***********************************************************************
239 * GetMessageExtraInfo (USER.288)
240 * GetMessageExtraInfo (USER32.@)
242 LPARAM WINAPI
GetMessageExtraInfo(void)
246 if (!(queue
= QUEUE_Current())) return 0;
247 return queue
->GetMessageExtraInfoVal
;
251 /***********************************************************************
252 * SetMessageExtraInfo (USER32.@)
254 LPARAM WINAPI
SetMessageExtraInfo(LPARAM lParam
)
259 if (!(queue
= QUEUE_Current())) return 0;
260 old_value
= queue
->GetMessageExtraInfoVal
;
261 queue
->GetMessageExtraInfoVal
= lParam
;