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

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

Gracefully handle WM_QUIT message sent by window list

File size: 22.8 KB
Line 
1/* $Id: oslibmsg.cpp,v 1.54 2002-03-28 11:25:59 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)
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(fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
144 return MsgTransTab[i].msgOS2;
145 }
146 else
147 if(!fMinFilter && MsgTransTab[i].msgWin32 >= msg) {
148 if(MsgTransTab[i].msgWin32 == msg)
149 return MsgTransTab[i].msgOS2;
150 else return MsgTransTab[i-1].msgOS2;
151 }
152 }
153
154 //not found, get everything
155 dprintf(("WARNING: TranslateWinMsg: message %x not found", msg));
156 return 0;
157}
158//******************************************************************************
159//******************************************************************************
160void OSLibWinPostQuitMessage(ULONG nExitCode)
161{
162 APIRET rc;
163
164 rc = WinPostQueueMsg(NULLHANDLE, WM_QUIT, MPFROMLONG(nExitCode), 0);
165 dprintf(("WinPostQueueMsg %d returned %d", nExitCode, rc));
166}
167//******************************************************************************
168//******************************************************************************
169LONG OSLibWinDispatchMsg(MSG *msg, BOOL isUnicode)
170{
171 TEB *teb;
172 QMSG os2msg;
173 LONG rc;
174
175 teb = GetThreadTEB();
176 if(teb == NULL) {
177 DebugInt3();
178 return FALSE;
179 }
180
181 //TODO: What to do if app changed msg? (translate)
182 // WinToOS2MsgTranslate(msg, &qmsg, isUnicode);
183
184 if(!memcmp(msg, &teb->o.odin.winmsg, sizeof(MSG)) || msg->hwnd == 0) {
185 memcpy(&os2msg, &teb->o.odin.os2msg, sizeof(QMSG));
186 teb->o.odin.os2msg.time = -1;
187 teb->o.odin.winmsg.time = -1;
188 if(msg->hwnd) {
189 teb->o.odin.nrOfMsgs = 1;
190 teb->o.odin.msgstate++; //odd -> next call to our PM window handler should dispatch the translated msg
191 memcpy(&teb->o.odin.msg, msg, sizeof(MSG));
192 }
193 if(os2msg.hwnd || os2msg.msg == WM_QUIT) {
194 memset(&teb->o.odin.os2msg, 0, sizeof(teb->o.odin.os2msg));
195 memset(&teb->o.odin.winmsg, 0, sizeof(teb->o.odin.winmsg));
196 return (LONG)WinDispatchMsg(teb->o.odin.hab, &os2msg);
197 }
198 //SvL: Don't dispatch messages sent by PostThreadMessage (correct??)
199 // Or WM_TIMER msgs with no window handle or timer proc
200 return 0;
201
202 }
203 else {//is this allowed?
204// dprintf(("WARNING: OSLibWinDispatchMsg: called with own message!"));
205 return SendMessageA(msg->hwnd, msg->message, msg->wParam, msg->lParam);
206 }
207}
208//******************************************************************************
209//******************************************************************************
210
211#ifdef ALTGR_HACK
212static void i_MostUglyAltGrHack(LPMSG pMsg)
213{
214 switch (pMsg->message)
215 {
216 case WINWM_KEYUP:
217 case WINWM_SYSKEYUP:
218 USHORT wWinScan = (pMsg->lParam & 0x00ff0000) >> 16;
219 if (wWinScan == WINSCAN_ALTRIGHT)
220 {
221 KeySetOverlayKeyState(VK_RMENU_W, KEYOVERLAYSTATE_DONTCARE);
222 KeySetOverlayKeyState(VK_MENU_W, KEYOVERLAYSTATE_DONTCARE);
223 }
224 break;
225 }
226}
227#else
228#define i_MostUglyAltGrHack(a)
229#endif
230
231BOOL OSLibWinGetMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
232 BOOL isUnicode)
233{
234 BOOL rc, eaten;
235 TEB *teb;
236 QMSG os2msg;
237 HWND hwndOS2 = 0;
238 ULONG filtermin, filtermax;
239
240 if(hwnd) {
241 hwndOS2 = Win32ToOS2Handle(hwnd);
242 if(hwndOS2 == NULL) {
243 memset(pMsg, 0, sizeof(MSG));
244 dprintf(("GetMsg: window %x NOT FOUND!", hwnd));
245 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
246 return TRUE;
247 }
248 }
249
250 teb = GetThreadTEB();
251 if(teb == NULL) {
252 DebugInt3();
253 return TRUE;
254 }
255
256 if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
257 {
258 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));
259 if(uMsgFilterMin) {
260 if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
261 goto continuegetmsg;
262 }
263 if(uMsgFilterMax) {
264 if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
265 goto continuegetmsg;
266 }
267 teb->o.odin.fTranslated = FALSE;
268 memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
269 teb->o.odin.os2msg.msg = 0;
270 teb->o.odin.os2msg.hwnd = 0;
271
272 // @@@PH verify this
273 // if this is a keyup or keydown message, we've got to
274 // call the keyboard hook here
275 // send keyboard messages to the registered hooks
276 switch (pMsg->message)
277 {
278 case WINWM_KEYDOWN:
279 case WINWM_KEYUP:
280 case WINWM_SYSKEYDOWN:
281 case WINWM_SYSKEYUP:
282 // only supposed to be called upon WM_KEYDOWN
283 // and WM_KEYUP according to docs.
284 if(ProcessKbdHook(pMsg, TRUE))
285 goto continuegetmsg;
286 break;
287 }
288
289 i_MostUglyAltGrHack(pMsg);
290
291 return (pMsg->message != WINWM_QUIT);
292 }
293
294continuegetmsg:
295 if(hwnd) {
296 filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
297 filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
298 if(filtermin > filtermax) {
299 ULONG tmp = filtermin;
300 filtermin = filtermax;
301 filtermax = filtermin;
302 }
303 do {
304 WinWaitMsg(teb->o.odin.hab, filtermin, filtermax);
305 rc = OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, PM_REMOVE_W, isUnicode);
306 }
307 while(rc == FALSE);
308
309 return (pMsg->message != WINWM_QUIT);
310 }
311 else
312 {
313 filtermin = TranslateWinMsg(uMsgFilterMin, TRUE);
314 filtermax = TranslateWinMsg(uMsgFilterMax, FALSE);
315 if(filtermin > filtermax) {
316 ULONG tmp = filtermin;
317 filtermin = filtermax;
318 filtermax = filtermin;
319 }
320 do {
321 eaten = FALSE;
322 rc = WinGetMsg(teb->o.odin.hab, &os2msg, 0, filtermin, filtermax);
323 if (os2msg.msg == WM_TIMER)
324 eaten = TIMER_HandleTimer(&os2msg);
325 if (os2msg.msg == WM_QUIT && ((ULONG)os2msg.mp2 != 0) ) {
326 // Don't return FALSE when the window list sends us
327 // a WM_QUIT message, improper killing can lead to
328 // application crashes.
329 // In the WM_QUIT handler in pmwindow we send a WM_CLOSE
330 // in this case. When the app calls PostQuitMessage (mp2 == 0),
331 // then we handle it the normal way
332 rc = 1;
333 }
334 } while (eaten);
335 }
336 if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, MSG_REMOVE) == FALSE) {
337 //dispatch untranslated message immediately
338 WinDispatchMsg(teb->o.odin.hab, &os2msg);
339 //and get the next one
340 return OSLibWinGetMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, isUnicode);
341 }
342
343 memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
344 memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
345
346 // send keyboard messages to the registered hooks
347 switch (pMsg->message)
348 {
349 case WINWM_KEYDOWN:
350 case WINWM_KEYUP:
351 case WINWM_SYSKEYDOWN:
352 case WINWM_SYSKEYUP:
353 // only supposed to be called upon WM_KEYDOWN
354 // and WM_KEYUP according to docs.
355 if(ProcessKbdHook(pMsg, TRUE))
356 goto continuegetmsg;
357 break;
358 }
359
360 i_MostUglyAltGrHack(pMsg);
361
362 return rc;
363}
364
365
366//******************************************************************************
367//PeekMessage retrieves only messages associated with the window identified by the
368//hwnd parameter or any of its children as specified by the IsChild function, and within
369//the range of message values given by the uMsgFilterMin and uMsgFilterMax
370//parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that
371//belongs to the current thread making the call. (PeekMessage does not retrieve
372//messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only
373//returns messages with a hwnd value of NULL, as posted by the PostAppMessage
374//function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all
375//available messages (no range filtering is performed).
376//TODO: Not working as specified right now!
377//******************************************************************************
378BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
379 DWORD fRemove, BOOL isUnicode)
380{
381 BOOL rc, eaten;
382 TEB *teb;
383 QMSG os2msg;
384 HWND hwndOS2 = 0;
385
386 if(hwnd && hwnd != -1) {
387 hwndOS2 = Win32ToOS2Handle(hwnd);
388 if(hwndOS2 == NULL) {
389 dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
390 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
391 return FALSE;
392 }
393 }
394
395 teb = GetThreadTEB();
396 if(teb == NULL) {
397 DebugInt3();
398 return FALSE;
399 }
400
401 if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd))
402 {
403 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));
404 if(uMsgFilterMin) {
405 if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
406 goto continuepeekmsg;
407 }
408 if(uMsgFilterMax) {
409 if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
410 goto continuepeekmsg;
411 }
412
413 if(fRemove & PM_REMOVE_W) {
414 teb->o.odin.fTranslated = FALSE;
415 teb->o.odin.os2msg.msg = 0;
416 teb->o.odin.os2msg.hwnd = 0;
417 }
418 memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
419
420 // @@@PH verify this
421 // if this is a keyup or keydown message, we've got to
422 // call the keyboard hook here
423 // send keyboard messages to the registered hooks
424 switch (pMsg->message)
425 {
426 case WINWM_KEYDOWN:
427 case WINWM_KEYUP:
428 case WINWM_SYSKEYDOWN:
429 case WINWM_SYSKEYUP:
430 // only supposed to be called upon WM_KEYDOWN
431 // and WM_KEYUP according to docs.
432 if(ProcessKbdHook(pMsg, fRemove))
433 goto continuepeekmsg;
434 break;
435 }
436
437 return TRUE;
438 }
439
440continuepeekmsg:
441 do {
442 eaten = FALSE;
443 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
444 TranslateWinMsg(uMsgFilterMax, FALSE), (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
445
446 if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
447 eaten = TIMER_HandleTimer(&os2msg);
448 }
449 }
450 while (eaten && rc);
451
452 if(rc == FALSE) {
453 return FALSE;
454 }
455
456 // @@@PH
457 // warning - OS2ToWinMsgTranslate might insert additional messages
458 // into the queue
459 if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE)
460 {
461 //unused PM message; dispatch immediately and grab next one
462 dprintf2(("OSLibWinPeekMsg: Untranslated message; dispatched immediately"));
463 if(!(fRemove & PM_REMOVE_W)) {
464 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
465 TranslateWinMsg(uMsgFilterMax, FALSE), PM_REMOVE);
466 }
467 WinDispatchMsg(teb->o.odin.hab, &os2msg);
468 return OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax,
469 fRemove, isUnicode);
470 }
471 //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
472 if(fRemove & PM_REMOVE_W) {
473 memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
474 memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
475 }
476
477 // send keyboard messages to the registered hooks
478 switch (pMsg->message)
479 {
480 case WINWM_KEYDOWN:
481 case WINWM_KEYUP:
482 case WINWM_SYSKEYDOWN:
483 case WINWM_SYSKEYUP:
484 // only supposed to be called upon WM_KEYDOWN
485 // and WM_KEYUP according to docs.
486 if(ProcessKbdHook(pMsg, fRemove))
487 goto continuepeekmsg;
488 break;
489 }
490
491 return rc;
492}
493//******************************************************************************
494//******************************************************************************
495ULONG OSLibWinQueryMsgTime()
496{
497 return WinQueryMsgTime(GetThreadHAB());
498}
499//******************************************************************************
500//******************************************************************************
501BOOL OSLibWinWaitMessage()
502{
503 return WinWaitMsg(GetThreadHAB(), 0, 0);
504}
505//******************************************************************************
506//TODO: QS_HOTKEY
507//******************************************************************************
508ULONG OSLibWinQueryQueueStatus()
509{
510 ULONG statusOS2, statusWin32 = 0;
511
512 statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
513
514 if(statusOS2 & QS_KEY)
515 statusWin32 |= QS_KEY_W;
516 if(statusOS2 & QS_MOUSEBUTTON)
517 statusWin32 |= QS_MOUSEBUTTON_W;
518 if(statusOS2 & QS_MOUSEMOVE)
519 statusWin32 |= QS_MOUSEMOVE_W;
520 if(statusOS2 & QS_TIMER)
521 statusWin32 |= QS_TIMER_W;
522 if(statusOS2 & QS_PAINT)
523 statusWin32 |= QS_PAINT_W;
524 if(statusOS2 & QS_POSTMSG)
525 statusWin32 |= QS_POSTMESSAGE_W;
526 if(statusOS2 & QS_SENDMSG)
527 statusWin32 |= QS_SENDMESSAGE_W;
528
529 return statusWin32;
530}
531//******************************************************************************
532//******************************************************************************
533BOOL OSLibWinInSendMessage()
534{
535 return WinInSendMsg(GetThreadHAB());
536}
537//******************************************************************************
538//******************************************************************************
539DWORD OSLibWinGetMessagePos()
540{
541 APIRET rc;
542 POINTL ptl;
543
544 rc = WinQueryMsgPos(GetThreadHAB(), &ptl);
545 if(!rc) {
546 return 0;
547 }
548 //convert to windows coordinates
549 return MAKEULONG(ptl.x,mapScreenY(ptl.y));
550}
551//******************************************************************************
552//******************************************************************************
553LONG OSLibWinGetMessageTime()
554{
555 return (LONG)WinQueryMsgTime(GetThreadHAB());
556}
557//******************************************************************************
558//******************************************************************************
559BOOL OSLibWinReplyMessage(ULONG result)
560{
561 return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
562}
563//******************************************************************************
564//******************************************************************************
565ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
566{
567 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
568
569 if(NULL == packet)
570 {
571 dprintf(("user32::oslibmsg::OSLibSendMessage - allocated packet structure is NULL, heapmin=%d\n",
572 _sheapmin() ));
573
574 // PH: we cannot provide a correct returncode :(
575 DebugInt3();
576 return 0;
577 }
578
579 packet->wParam = wParam;
580 packet->lParam = lParam;
581
582 return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
583}
584//******************************************************************************
585//******************************************************************************
586ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend)
587{
588 return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam,
589 (fSend) ? BMSG_SEND : BMSG_POST);
590}
591//******************************************************************************
592//******************************************************************************
593BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
594{
595 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
596
597 if (NULL == packet)
598 {
599 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
600 _sheapmin() ));
601
602 // PH: we can provide a correct returncode
603 DebugInt3();
604 return FALSE;
605 }
606 packet->wParam = wParam;
607 packet->lParam = lParam;
608 return WinPostMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
609}
610//******************************************************************************
611//Direct posting of messages that must remain invisible to the win32 app
612//******************************************************************************
613BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
614{
615 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
616}
617//******************************************************************************
618//******************************************************************************
619BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
620{
621 TEB *teb = GetTEBFromThreadId(threadid);
622 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
623 BOOL ret;
624
625 if(NULL == packet)
626 {
627 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
628 _sheapmin() ));
629
630 DebugInt3();
631 // PH: we can provide a correct returncode
632 return FALSE;
633 }
634
635 if(teb == NULL) {
636 dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid));
637 return FALSE;
638 }
639 dprintf(("PostThreadMessageA %x %x %x %x -> hmq %x", threadid, msg, wParam, lParam, teb->o.odin.hmq));
640 packet->wParam = wParam;
641 packet->lParam = lParam;
642
643 ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg,
644 (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
645 (MPARAM)packet);
646
647 if(ret == FALSE)
648 {
649 SetLastError(ERROR_INVALID_PARAMETER_W);
650 return FALSE;
651 }
652 SetLastError(ERROR_SUCCESS_W);
653 return TRUE;
654}
655//******************************************************************************
656//******************************************************************************
657DWORD GetThreadMessageExtraInfo()
658{
659 TEB *teb;
660
661 teb = GetThreadTEB();
662 if(teb)
663 {
664 return teb->o.odin.dwMsgExtraInfo;
665 }
666 dprintf(("GetThreadMessageExtraInfo: teb == NULL!!"));
667 return 0;
668}
669//******************************************************************************
670//******************************************************************************
671DWORD SetThreadMessageExtraInfo(DWORD lParam)
672{
673 TEB *teb;
674
675 teb = GetThreadTEB();
676 if(teb)
677 {
678 teb->o.odin.dwMsgExtraInfo = lParam;
679 }
680 else dprintf(("SetThreadMessageExtraInfo: teb == NULL!!"));
681 return 0;
682}
683//******************************************************************************
684//******************************************************************************
Note: See TracBrowser for help on using the repository browser.