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

Last change on this file since 7222 was 7212, checked in by phaller, 24 years ago

.

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