source: trunk/src/user32/oslibmsg.cpp@ 8953

Last change on this file since 8953 was 8953, checked in by sandervl, 23 years ago

Signal post message event semaphore in PostMessageA/W & PostThreadMessage

File size: 25.0 KB
Line 
1/* $Id: oslibmsg.cpp,v 1.60 2002-08-01 16:04:19 sandervl Exp $ */
2/*
3 * Window message translation functions for OS/2
4 *
5 *
6 * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
7 *
8 *
9 * Project Odin Software License can be found in LICENSE.TXT
10 *
11 * TODO: Some messages that are sent to the frame window are directly passed on to the client
12 * -> Get/PeekMessage never gets them as we return a dummy message for non-client windows
13 * (i.e. menu WM_COMMAND messages)
14 *
15 * TODO: Filter translation isn't correct! (for posted messages or messages that don't have
16 * a PM version.
17 *
18 */
19#define INCL_WIN
20#define INCL_PM
21#define INCL_DOSPROCESS
22#include <os2wrap.h>
23#include <odinwrap.h>
24#include <string.h>
25#include <misc.h>
26#include "oslibmsg.h"
27#include <winconst.h>
28#include <win32api.h>
29#include <winuser32.h>
30#include "oslibutil.h"
31#include "timer.h"
32#include <thread.h>
33#include <wprocess.h>
34#include "pmwindow.h"
35#include "oslibwin.h"
36#include <win\hook.h>
37#include <winscan.h>
38#include <winkeyboard.h>
39
40#define DBG_LOCALLOG DBG_oslibmsg
41#include "dbglocal.h"
42
43
44ODINDEBUGCHANNEL(USER32-OSLIBMSG)
45
46
47
48typedef BOOL (EXPENTRY FNTRANS)(MSG *, QMSG *);
49typedef FNTRANS *PFNTRANS;
50
51typedef struct
52{
53 ULONG msgOS2;
54 ULONG msgWin32;
55// PFNTRANS toOS2;
56// PFNTRANS toWIN32;
57} MSGTRANSTAB, *PMSGTRANSTAB;
58
59//NOTE: Must be ordered by win32 message id!!
60MSGTRANSTAB MsgTransTab[] = {
61 WM_NULL, WINWM_NULL,
62 WM_CREATE, WINWM_CREATE,
63 WM_DESTROY, WINWM_DESTROY,
64 WM_MOVE, WINWM_MOVE, //TODO: Sent directly
65 WM_SIZE, WINWM_SIZE, //TODO: Sent directly
66 WM_ACTIVATE, WINWM_ACTIVATE,
67 WM_SETFOCUS, WINWM_SETFOCUS,
68 WM_SETFOCUS, WINWM_KILLFOCUS,
69 WM_ENABLE, WINWM_ENABLE,
70 WM_PAINT, WINWM_PAINT,
71 WM_CLOSE, WINWM_CLOSE,
72 WM_QUIT, WINWM_QUIT,
73 WM_SHOW, WINWM_SHOWWINDOW,
74
75 WM_HITTEST, WINWM_NCHITTEST,
76
77 //todo: not always right if mouse msg turns out to be for the client window
78 WM_MOUSEMOVE, WINWM_NCMOUSEMOVE,
79 WM_BUTTON1DOWN, WINWM_NCLBUTTONDOWN,
80 WM_BUTTON1UP, WINWM_NCLBUTTONUP,
81 WM_BUTTON1DBLCLK, WINWM_NCLBUTTONDBLCLK,
82 WM_BUTTON2DOWN, WINWM_NCRBUTTONDOWN,
83 WM_BUTTON2UP, WINWM_NCRBUTTONUP,
84 WM_BUTTON2DBLCLK, WINWM_NCRBUTTONDBLCLK,
85 WM_BUTTON3DOWN, WINWM_NCMBUTTONDOWN,
86 WM_BUTTON3UP, WINWM_NCMBUTTONUP,
87 WM_BUTTON3DBLCLK, WINWM_NCMBUTTONDBLCLK,
88
89 //TODO: Needs better translation!
90 WM_CHAR, WINWM_KEYDOWN, //WM_KEYFIRST
91 WM_CHAR, WINWM_KEYUP,
92 WM_CHAR, WINWM_CHAR,
93 WM_CHAR, WINWM_DEADCHAR,
94 WM_CHAR, WINWM_SYSKEYDOWN,
95 WM_CHAR, WINWM_SYSKEYUP,
96 WM_CHAR, WINWM_SYSCHAR,
97 WM_CHAR, WINWM_SYSDEADCHAR,
98 WM_CHAR, WINWM_KEYLAST,
99
100 //
101 WM_TIMER, WINWM_TIMER,
102
103 //
104 //todo: not always right if mouse msg turns out to be for the nonclient window
105 WM_MOUSEMOVE, WINWM_MOUSEMOVE, //WM_MOUSEFIRST
106 WM_BUTTON1DOWN, WINWM_LBUTTONDOWN,
107 WM_BUTTON1UP, WINWM_LBUTTONUP,
108 WM_BUTTON1DBLCLK, WINWM_LBUTTONDBLCLK,
109 WM_BUTTON2DOWN, WINWM_RBUTTONDOWN,
110 WM_BUTTON2UP, WINWM_RBUTTONUP,
111 WM_BUTTON2DBLCLK, WINWM_RBUTTONDBLCLK,
112 WM_BUTTON3DOWN, WINWM_MBUTTONDOWN,
113 WM_BUTTON3UP, WINWM_MBUTTONUP,
114 WM_BUTTON3DBLCLK, WINWM_MBUTTONDBLCLK,
115 WM_BUTTON3DBLCLK, WINWM_MOUSEWHEEL, //WM_MOUSELAST
116 999999999, 999999999,
117};
118#define MAX_MSGTRANSTAB (sizeof(MsgTransTab)/sizeof(MsgTransTab[0]))
119
120//******************************************************************************
121//******************************************************************************
122void WinToOS2MsgTranslate(MSG *winMsg, QMSG *os2Msg, BOOL isUnicode)
123{
124 dprintf(("WinToOS2MsgTranslate not implemented"));
125// memcpy(os2Msg, winMsg, sizeof(MSG));
126// os2Msg->hwnd = Win32ToOS2Handle(winMsg->hwnd);
127// os2Msg->reserved = 0;
128}
129//******************************************************************************
130//TODO: NOT COMPLETE nor 100% CORRECT!!!
131//If both the minimum & maximum message are unknown, the result can be wrong (max > min)!
132//******************************************************************************
133ULONG TranslateWinMsg(ULONG msg, BOOL fMinFilter, BOOL fExactMatch = FALSE)
134{
135 if(msg == 0)
136 return 0;
137
138 if(msg >= WINWM_USER)
139 return msg + WIN32APP_POSTMSG;
140
141 for(int i=0;i<MAX_MSGTRANSTAB;i++)
142 {
143 if(fExactMatch) {
144 if(MsgTransTab[i].msgWin32 == msg)
145 return MsgTransTab[i].msgWin32;
146 }
147 else {
148 if(fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
149 return MsgTransTab[i].msgOS2;
150 }
151 else
152 if(!fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
153 if(MsgTransTab[i].msgWin32 == msg)
154 return MsgTransTab[i].msgOS2;
155 else return MsgTransTab[i-1].msgOS2;
156 }
157 }
158 }
159
160 //not found, get everything
161 dprintf2(("WARNING: TranslateWinMsg: message %x not found", msg));
162 return 0;
163}
164//******************************************************************************
165//******************************************************************************
166void OSLibWinPostQuitMessage(ULONG nExitCode)
167{
168 APIRET rc;
169
170 //NOTE: mp2 must always be zero or else we won't be able to distinguish
171 // between the WM_QUIT sent by us and the one sent by the window list!!
172 rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, MPFROMLONG(nExitCode), 0);
173 dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc));
174}
175//******************************************************************************
176//******************************************************************************
177LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
178{
179 TEB *teb;
180 QMSG os2msg;
181 LONG rc;
182
183 teb = GetThreadTEB();
184 if(teb == NULL) {
185 DebugInt3();
186 return FALSE;
187 }
188
189 //TODO: What to do if app changed msg? (translate)
190 // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
191
192 if(!memcmp(msg, &teb->o.odin.winmsg, sizeof(MSG)) || msg->hwnd == 0) {
193 memcpy(&os2msg, &teb->o.odin.os2msg, sizeof(QMSG));
194 teb->o.odin.os2msg.time = -1;
195 teb->o.odin.winmsg.time = -1;
196 if(msg->hwnd) {
197 teb->o.odin.nrOfMsgs = 1;
198 teb->o.odin.msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg
199 memcpy(&teb->o.odin.msg, msg, sizeof(MSG));
200 }
201 if(os2msg.hwnd || os2msg.msg == WM_QUIT) {
202 memset(&teb->o.odin.os2msg, 0, sizeof(teb->o.odin.os2msg));
203 memset(&teb->o.odin.winmsg, 0, sizeof(teb->o.odin.winmsg));
204 return (LONG)WinDispatchMsg(teb->o.odin.hab, &os2msg);
205 }
206 //SvL: Don't dispatch messages sent by PostThreadMessage (correct??)
207 // Or WM_TIMER msgs with no window handle or timer proc
208 return 0;
209
210 }
211 else {//is this allowed?
212// dprintf(("WARNING: OSLibWinDispatchMsg: called with own message!"));
213 return SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam);
214 }
215}
216//******************************************************************************
217//******************************************************************************
218BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
219 BOOL isUnicode)
220{
221 BOOL rc, eaten;
222 TEB *teb;
223 QMSG os2msg;
224 HWND hwndOS2 = 0;
225 ULONG filtermin, filtermax;
226
227 if(hwnd) {
228 hwndOS2 = Win32ToOS2Handle(hwnd);
229 if(hwndOS2 == NULL) {
230 memset(pMsg, 0, sizeof(MSG));
231 dprintf(("GetMsg: window %x NOT FOUND!", hwnd));
232 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
233 return TRUE;
234 }
235 }
236
237 teb = GetThreadTEB();
238 if(teb == NULL) {
239 DebugInt3();
240 return TRUE;
241 }
242
243 if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
244 {
245 dprintf(("Return queued WM_CHAR message hwnd=%x msg=%d wParam=%x lParam=%x", teb->o.odin.msgWCHAR.hwnd, teb->o.odin.msgWCHAR.message, teb->o.odin.msgWCHAR.wParam, teb->o.odin.msgWCHAR.lParam));
246 if(uMsgFilterMin) {
247 if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
248 goto continuegetmsg;
249 }
250 if(uMsgFilterMax) {
251 if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
252 goto continuegetmsg;
253 }
254 teb->o.odin.fTranslated = FALSE;
255 memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
256 teb->o.odin.os2msg.msg = 0;
257 teb->o.odin.os2msg.hwnd = 0;
258
259 // @@@PH verify this
260 // if this is a keyup or keydown message, we've got to
261 // call the keyboard hook here
262 // send keyboard messages to the registered hooks
263 switch (pMsg->message)
264 {
265 case WINWM_KEYDOWN:
266 case WINWM_KEYUP:
267 case WINWM_SYSKEYDOWN:
268 case WINWM_SYSKEYUP:
269 // only supposed to be called upon WM_KEYDOWN
270 // and WM_KEYUP according to docs.
271 if(ProcessKbdHook(pMsg, TRUE))
272 goto continuegetmsg;
273 break;
274 }
275
276 return (pMsg->message != WINWM_QUIT);
277 }
278
279continuegetmsg:
280 if(hwnd) {
281 filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
282 filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
283 if(filtermin > filtermax) {
284 ULONG tmp = filtermin;
285 filtermin = filtermax;
286 filtermax = filtermin;
287 }
288 do {
289 WinWaitMsg(teb->o.odin.hab, filtermin, filtermax);
290 rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode);
291 }
292 while(rc == FALSE);
293
294 return (pMsg->message != WINWM_QUIT);
295 }
296 else
297 {
298 filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
299 filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
300 if(filtermin > filtermax) {
301 ULONG tmp = filtermin;
302 filtermin = filtermax;
303 filtermax = filtermin;
304 }
305 do {
306 eaten = FALSE;
307 rc = WinGetMsg(teb->o.odin.hab, &os2msg, 0, filtermin, filtermax);
308 if (os2msg.msg == WM_TIMER)
309 eaten = TIMER_HandleTimer(&os2msg);
310 if (os2msg.msg == WM_QUIT && ((ULONG)os2msg.mp2 != 0) ) {
311 // Don't return FALSE when the window list sends us
312 // a WM_QUIT message, improper killing can lead to
313 // application crashes.
314 // In the WM_QUIT handler in pmwindow we send a WM_CLOSE
315 // in this case. When the app calls PostQuitMessage (mp2 == 0),
316 // then we handle it the normal way
317 rc = 1;
318 }
319 }
320 while (eaten);
321 }
322 if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, MSG_REMOVE) == FALSE) {
323 //dispatch untranslated message immediately
324 WinDispatchMsg(teb->o.odin.hab, &os2msg);
325 //and get the next one
326 return OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode);
327 }
328
329 memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
330 memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
331
332 // send keyboard messages to the registered hooks
333 switch (pMsg->message)
334 {
335 case WINWM_KEYDOWN:
336 case WINWM_KEYUP:
337 case WINWM_SYSKEYDOWN:
338 case WINWM_SYSKEYUP:
339 // only supposed to be called upon WM_KEYDOWN
340 // and WM_KEYUP according to docs.
341 if(ProcessKbdHook(pMsg, TRUE))
342 goto continuegetmsg;
343 break;
344 }
345 return rc;
346}
347
348
349//******************************************************************************
350//PeekMessage retrieves only messages associated with the window identified by the
351//hwnd parameter or any of its children as specified by the IsChild function, and within
352//the range of message values given by the uMsgFilterMin and uMsgFilterMax
353//parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that
354//belongs to the current thread making the call. (PeekMessage does not retrieve
355//messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only
356//returns messages with a hwnd value of NULL, as posted by the PostAppMessage
357//function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all
358//available messages (no range filtering is performed).
359//TODO: Not working as specified right now!
360//******************************************************************************
361BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
362 DWORD fRemove, BOOL isUnicode)
363{
364 BOOL rc, eaten;
365 TEB *teb;
366 QMSG os2msg;
367 HWND hwndOS2 = 0;
368
369 if(uMsgFilterMin > uMsgFilterMax) {
370 //TODO: is this correct behaviour?
371 dprintf(("!ERROR!: invalid message filter range!!!"));
372 SetLastError(ERROR_INVALID_PARAMETER_W);
373 return FALSE;
374 }
375 if(hwnd && hwnd != -1) {
376 hwndOS2 = Win32ToOS2Handle(hwnd);
377 if(hwndOS2 == NULL) {
378 dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
379 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
380 return FALSE;
381 }
382 }
383
384 teb = GetThreadTEB();
385 if(teb == NULL) {
386 DebugInt3();
387 return FALSE;
388 }
389
390 if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
391 {
392 dprintf(("Return queued WM_CHAR message hwnd=%x msg=%d wParam=%x lParam=%x", teb->o.odin.msgWCHAR.hwnd, teb->o.odin.msgWCHAR.message, teb->o.odin.msgWCHAR.wParam, teb->o.odin.msgWCHAR.lParam));
393 if(uMsgFilterMin) {
394 if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
395 goto continuepeekmsg;
396 }
397 if(uMsgFilterMax) {
398 if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
399 goto continuepeekmsg;
400 }
401
402 if(fRemove & PM_REMOVE_W) {
403 teb->o.odin.fTranslated = FALSE;
404 teb->o.odin.os2msg.msg = 0;
405 teb->o.odin.os2msg.hwnd = 0;
406 }
407 memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
408
409 // @@@PH verify this
410 // if this is a keyup or keydown message, we've got to
411 // call the keyboard hook here
412 // send keyboard messages to the registered hooks
413 if(fRemove & PM_REMOVE_W) {
414 switch (pMsg->message)
415 {
416 case WINWM_KEYDOWN:
417 case WINWM_KEYUP:
418 case WINWM_SYSKEYDOWN:
419 case WINWM_SYSKEYUP:
420 // only supposed to be called upon WM_KEYDOWN
421 // and WM_KEYUP according to docs.
422 if(ProcessKbdHook(pMsg, fRemove))
423 goto continuepeekmsg;
424 break;
425 }
426 }
427
428 return TRUE;
429 }
430
431continuepeekmsg:
432 if(uMsgFilterMin && uMsgFilterMax)
433 { //we can't use the PM message filter (since the message nrs aren't similar), so we must
434 //filter each message seperately
435 //to do so, we will translate each win32 message in the filter range and call WinPeekMsg
436 ULONG ulPMFilter;
437
438 for(int i=0;i<uMsgFilterMax-uMsgFilterMin+1;i++) {
439 rc = 0;
440
441 ulPMFilter = TranslateWinMsg(uMsgFilterMin+i, TRUE, TRUE);
442 if(ulPMFilter) {
443 do {
444 eaten = FALSE;
445
446 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, ulPMFilter, ulPMFilter,
447 (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
448
449 if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
450 eaten = TIMER_HandleTimer(&os2msg);
451 }
452 }
453 while (eaten && rc);
454 }
455 if(rc) {
456 break;
457 }
458 }
459 }
460 else {
461 do {
462 eaten = FALSE;
463
464 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, 0, 0, (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
465
466 if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
467 eaten = TIMER_HandleTimer(&os2msg);
468 }
469 }
470 while (eaten && rc);
471 }
472 if(rc == FALSE) {
473 return FALSE;
474 }
475
476 // @@@PH
477 // warning - OS2ToWinMsgTranslate might insert additional messages
478 // into the queue
479 if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE)
480 {
481 //unused PM message; dispatch immediately and grab next one
482 dprintf2(("OSLibWinPeekMsg: Untranslated message; dispatched immediately"));
483 if(!(fRemove & PM_REMOVE_W)) {
484 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
485 TranslateWinMsg(uMsgFilterMax, FALSE), PM_REMOVE);
486 }
487 WinDispatchMsg(teb->o.odin.hab, &os2msg);
488 return OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, fRemove, isUnicode);
489 }
490 //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
491 if(fRemove & PM_REMOVE_W) {
492 memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
493 memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
494 }
495
496 // send keyboard messages to the registered hooks
497 if(fRemove & PM_REMOVE_W) {
498 switch (pMsg->message)
499 {
500 case WINWM_KEYDOWN:
501 case WINWM_KEYUP:
502 case WINWM_SYSKEYDOWN:
503 case WINWM_SYSKEYUP:
504 // only supposed to be called upon WM_KEYDOWN
505 // and WM_KEYUP according to docs.
506 if(ProcessKbdHook(pMsg, fRemove))
507 goto continuepeekmsg;
508 break;
509 }
510 }
511
512 return rc;
513}
514//******************************************************************************
515//******************************************************************************
516ULONG OSLibWinQueryMsgTime()
517{
518 return WinQueryMsgTime(GetThreadHAB());
519}
520//******************************************************************************
521//******************************************************************************
522BOOL OSLibWinWaitMessage()
523{
524 return WinWaitMsg(GetThreadHAB(), 0, 0);
525}
526//******************************************************************************
527//TODO: QS_HOTKEY
528//******************************************************************************
529ULONG OSLibWinQueryQueueStatus()
530{
531 ULONG statusOS2, statusWin32 = 0;
532
533 statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
534
535 if(statusOS2 & QS_KEY)
536 statusWin32 |= QS_KEY_W;
537 if(statusOS2 & QS_MOUSEBUTTON)
538 statusWin32 |= QS_MOUSEBUTTON_W;
539 if(statusOS2 & QS_MOUSEMOVE)
540 statusWin32 |= QS_MOUSEMOVE_W;
541 if(statusOS2 & QS_TIMER)
542 statusWin32 |= QS_TIMER_W;
543 if(statusOS2 & QS_PAINT)
544 statusWin32 |= QS_PAINT_W;
545 if(statusOS2 & QS_POSTMSG)
546 statusWin32 |= QS_POSTMESSAGE_W;
547 if(statusOS2 & QS_SENDMSG)
548 statusWin32 |= QS_SENDMESSAGE_W;
549
550 return statusWin32;
551}
552//******************************************************************************
553//******************************************************************************
554BOOL OSLibWinInSendMessage()
555{
556 return WinInSendMsg(GetThreadHAB());
557}
558//******************************************************************************
559//******************************************************************************
560DWORD OSLibWinGetMessagePos()
561{
562 APIRET rc;
563 POINTL ptl;
564
565 rc = WinQueryMsgPos(GetThreadHAB(), &ptl);
566 if(!rc) {
567 return 0;
568 }
569 //convert to windows coordinates
570 return MAKEULONG(ptl.x,mapScreenY(ptl.y));
571}
572//******************************************************************************
573//******************************************************************************
574LONG OSLibWinGetMessageTime()
575{
576 return (LONG)WinQueryMsgTime(GetThreadHAB());
577}
578//******************************************************************************
579//******************************************************************************
580BOOL OSLibWinReplyMessage(ULONG result)
581{
582 return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
583}
584//******************************************************************************
585//******************************************************************************
586ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
587{
588 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
589
590 if(NULL == packet)
591 {
592 dprintf(("user32::oslibmsg::OSLibSendMessage - allocated packet structure is NULL"));
593
594 // PH: we cannot provide a correct returncode :(
595 DebugInt3();
596 return 0;
597 }
598
599 packet->wParam = wParam;
600 packet->lParam = lParam;
601
602 return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
603}
604//******************************************************************************
605//******************************************************************************
606ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend)
607{
608 return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam,
609 (fSend) ? BMSG_SEND : BMSG_POST);
610}
611//******************************************************************************
612//******************************************************************************
613BOOL OSLibPostMessage(HWND hwndWin32, HWND hwndOS2, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
614{
615 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
616 BOOL ret;
617
618 if (NULL == packet)
619 {
620 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL"));
621
622 // PH: we can provide a correct returncode
623 DebugInt3();
624 return FALSE;
625 }
626 TEB *teb = GetTEBFromThreadId(GetWindowThreadProcessId(hwndWin32, NULL));
627
628 packet->wParam = wParam;
629 packet->lParam = lParam;
630 ret = WinPostMsg(hwndOS2, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
631
632 if(teb && (teb->o.odin.dwWakeMask & QS_POSTMESSAGE_W)) {
633 //thread is blocked in MsgWaitForMultipleObjects waiting for
634 //posted messages
635 dprintf(("PostMessage: Wake up thread %x which is blocked in MsgWaitForMultipleObjects", teb->o.odin.threadId));
636 SetEvent(teb->o.odin.hPostMsgEvent);
637 }
638 return ret;
639}
640//******************************************************************************
641//Direct posting of messages that must remain invisible to the win32 app
642//******************************************************************************
643BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
644{
645 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
646}
647//******************************************************************************
648//******************************************************************************
649BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
650{
651 TEB *teb = GetTEBFromThreadId(threadid);
652 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
653 BOOL ret;
654
655 if(NULL == packet)
656 {
657 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL"));
658
659 DebugInt3();
660 // PH: we can provide a correct returncode
661 return FALSE;
662 }
663
664 if(teb == NULL) {
665 dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid));
666 return FALSE;
667 }
668 dprintf(("PostThreadMessageA %x %x %x %x -> hmq %x", threadid, msg, wParam, lParam, teb->o.odin.hmq));
669 packet->wParam = wParam;
670 packet->lParam = lParam;
671
672 ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg,
673 (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
674 (MPARAM)packet);
675
676 if(ret == FALSE)
677 {
678 SetLastError(ERROR_INVALID_PARAMETER_W);
679 return FALSE;
680 }
681
682 if(teb->o.odin.dwWakeMask & QS_POSTMESSAGE_W) {
683 //thread is blocked in MsgWaitForMultipleObjects waiting for
684 //posted messages
685 dprintf(("PostMessage: Wake up thread %x which is blocked in MsgWaitForMultipleObjects", teb->o.odin.threadId));
686 SetEvent(teb->o.odin.hPostMsgEvent);
687 }
688
689 SetLastError(ERROR_SUCCESS_W);
690 return TRUE;
691}
692//******************************************************************************
693//******************************************************************************
694DWORD GetThreadMessageExtraInfo()
695{
696 TEB *teb;
697
698 teb = GetThreadTEB();
699 if(teb)
700 {
701 return teb->o.odin.dwMsgExtraInfo;
702 }
703 dprintf(("GetThreadMessageExtraInfo: teb == NULL!!"));
704 return 0;
705}
706//******************************************************************************
707//******************************************************************************
708DWORD SetThreadMessageExtraInfo(DWORD lParam)
709{
710 TEB *teb;
711
712 teb = GetThreadTEB();
713 if(teb)
714 {
715 teb->o.odin.dwMsgExtraInfo = lParam;
716 }
717 else dprintf(("SetThreadMessageExtraInfo: teb == NULL!!"));
718 return 0;
719}
720//******************************************************************************
721//******************************************************************************
Note: See TracBrowser for help on using the repository browser.