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

Last change on this file since 7310 was 7223, checked in by sandervl, 24 years ago

* empty log message *

File size: 20.9 KB
Line 
1/* $Id: oslibmsg.cpp,v 1.49 2001-10-26 17:48:21 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
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 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}
326
327
328//******************************************************************************
329//PeekMessage retrieves only messages associated with the window identified by the
330//hwnd parameter or any of its children as specified by the IsChild function, and within
331//the range of message values given by the uMsgFilterMin and uMsgFilterMax
332//parameters. If hwnd is NULL, PeekMessage retrieves messages for any window that
333//belongs to the current thread making the call. (PeekMessage does not retrieve
334//messages for windows that belong to other threads.) If hwnd is -1, PeekMessage only
335//returns messages with a hwnd value of NULL, as posted by the PostAppMessage
336//function. If uMsgFilterMin and uMsgFilterMax are both zero, PeekMessage returns all
337//available messages (no range filtering is performed).
338//TODO: Not working as specified right now!
339//******************************************************************************
340BOOL OSLibWinPeekMsg(LPMSG pMsg, HWND hwnd, UINT uMsgFilterMin, UINT uMsgFilterMax,
341 DWORD fRemove, BOOL isUnicode)
342{
343 BOOL rc, eaten;
344 TEB *teb;
345 QMSG os2msg;
346 HWND hwndOS2 = 0;
347
348 if(hwnd && hwnd != -1) {
349 hwndOS2 = Win32ToOS2Handle(hwnd);
350 if(hwndOS2 == NULL) {
351 dprintf(("PeekMsg: window %x NOT FOUND!", hwnd));
352 SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
353 return FALSE;
354 }
355 }
356
357 teb = GetThreadTEB();
358 if(teb == NULL) {
359 DebugInt3();
360 return FALSE;
361 }
362
363 if(teb->o.odin.fTranslated && (!hwnd || hwnd == teb->o.odin.msgWCHAR.hwnd)) {
364 if(uMsgFilterMin) {
365 if(teb->o.odin.msgWCHAR.message < uMsgFilterMin)
366 goto continuepeekmsg;
367 }
368 if(uMsgFilterMax) {
369 if(teb->o.odin.msgWCHAR.message > uMsgFilterMax)
370 goto continuepeekmsg;
371 }
372
373 if(fRemove & PM_REMOVE_W) {
374 teb->o.odin.fTranslated = FALSE;
375 teb->o.odin.os2msg.msg = 0;
376 teb->o.odin.os2msg.hwnd = 0;
377 }
378 memcpy(pMsg, &teb->o.odin.msgWCHAR, sizeof(MSG));
379
380 // @@@PH verify this
381 // if this is a keyup or keydown message, we've got to
382 // call the keyboard hook here
383 // send keyboard messages to the registered hooks
384 switch (pMsg->message)
385 {
386 case WINWM_KEYDOWN:
387 case WINWM_KEYUP:
388 case WINWM_SYSKEYDOWN:
389 case WINWM_SYSKEYUP:
390 // only supposed to be called upon WM_KEYDOWN
391 // and WM_KEYUP according to docs.
392 if(ProcessKbdHook(pMsg, fRemove))
393 goto continuepeekmsg;
394 break;
395 }
396
397 return TRUE;
398 }
399
400continuepeekmsg:
401 do {
402 eaten = FALSE;
403 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
404 TranslateWinMsg(uMsgFilterMax, FALSE), (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
405
406 if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
407 eaten = TIMER_HandleTimer(&os2msg);
408 }
409 }
410 while (eaten && rc);
411
412 if(rc == FALSE) {
413 return FALSE;
414 }
415
416 // @@@PH
417 // warning - OS2ToWinMsgTranslate might insert additional messages
418 // into the queue
419 if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE)
420 {
421 //unused PM message; dispatch immediately and grab next one
422 dprintf2(("OSLibWinPeekMsg: Untranslated message; dispatched immediately"));
423 if(!(fRemove & PM_REMOVE_W)) {
424 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
425 TranslateWinMsg(uMsgFilterMax, FALSE), PM_REMOVE);
426 }
427 WinDispatchMsg(teb->o.odin.hab, &os2msg);
428 return OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax,
429 fRemove, isUnicode);
430 }
431 //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
432 if(fRemove & PM_REMOVE_W) {
433 memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
434 memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
435 }
436
437 // send keyboard messages to the registered hooks
438 switch (pMsg->message)
439 {
440 case WINWM_KEYDOWN:
441 case WINWM_KEYUP:
442 case WINWM_SYSKEYDOWN:
443 case WINWM_SYSKEYUP:
444 // only supposed to be called upon WM_KEYDOWN
445 // and WM_KEYUP according to docs.
446 if(ProcessKbdHook(pMsg, fRemove))
447 goto continuepeekmsg;
448 break;
449 }
450
451 return rc;
452}
453//******************************************************************************
454//******************************************************************************
455ULONG OSLibWinQueryMsgTime()
456{
457 return WinQueryMsgTime(GetThreadHAB());
458}
459//******************************************************************************
460//******************************************************************************
461BOOL OSLibWinWaitMessage()
462{
463 return WinWaitMsg(GetThreadHAB(), 0, 0);
464}
465//******************************************************************************
466//TODO: QS_HOTKEY
467//******************************************************************************
468ULONG OSLibWinQueryQueueStatus()
469{
470 ULONG statusOS2, statusWin32 = 0;
471
472 statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
473
474 if(statusOS2 & QS_KEY)
475 statusWin32 |= QS_KEY_W;
476 if(statusOS2 & QS_MOUSEBUTTON)
477 statusWin32 |= QS_MOUSEBUTTON_W;
478 if(statusOS2 & QS_MOUSEMOVE)
479 statusWin32 |= QS_MOUSEMOVE_W;
480 if(statusOS2 & QS_TIMER)
481 statusWin32 |= QS_TIMER_W;
482 if(statusOS2 & QS_PAINT)
483 statusWin32 |= QS_PAINT_W;
484 if(statusOS2 & QS_POSTMSG)
485 statusWin32 |= QS_POSTMESSAGE_W;
486 if(statusOS2 & QS_SENDMSG)
487 statusWin32 |= QS_SENDMESSAGE_W;
488
489 return statusWin32;
490}
491//******************************************************************************
492//******************************************************************************
493BOOL OSLibWinInSendMessage()
494{
495 return WinInSendMsg(GetThreadHAB());
496}
497//******************************************************************************
498//******************************************************************************
499DWORD OSLibWinGetMessagePos()
500{
501 APIRET rc;
502 POINTL ptl;
503
504 rc = WinQueryMsgPos(GetThreadHAB(), &ptl);
505 if(!rc) {
506 return 0;
507 }
508 //convert to windows coordinates
509 return MAKEULONG(ptl.x,mapScreenY(ptl.y));
510}
511//******************************************************************************
512//******************************************************************************
513LONG OSLibWinGetMessageTime()
514{
515 return (LONG)WinQueryMsgTime(GetThreadHAB());
516}
517//******************************************************************************
518//******************************************************************************
519BOOL OSLibWinReplyMessage(ULONG result)
520{
521 return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
522}
523//******************************************************************************
524//******************************************************************************
525ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
526{
527 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
528
529 if(NULL == packet)
530 {
531 dprintf(("user32::oslibmsg::OSLibSendMessage - allocated packet structure is NULL, heapmin=%d\n",
532 _sheapmin() ));
533
534 // PH: we cannot provide a correct returncode :(
535 DebugInt3();
536 return 0;
537 }
538
539 packet->wParam = wParam;
540 packet->lParam = lParam;
541
542 return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
543}
544//******************************************************************************
545//******************************************************************************
546ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend)
547{
548 return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam,
549 (fSend) ? BMSG_SEND : BMSG_POST);
550}
551//******************************************************************************
552//******************************************************************************
553BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
554{
555 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
556
557 if (NULL == packet)
558 {
559 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
560 _sheapmin() ));
561
562 // PH: we can provide a correct returncode
563 DebugInt3();
564 return FALSE;
565 }
566 packet->wParam = wParam;
567 packet->lParam = lParam;
568 return WinPostMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
569}
570//******************************************************************************
571//Direct posting of messages that must remain invisible to the win32 app
572//******************************************************************************
573BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
574{
575 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
576}
577//******************************************************************************
578BOOL _System _O32_PostThreadMessage( DWORD, UINT, WPARAM, LPARAM );
579
580inline BOOL O32_PostThreadMessage(DWORD a, UINT b, WPARAM c, LPARAM d)
581{
582 BOOL yyrc;
583 USHORT sel = RestoreOS2FS();
584
585 yyrc = _O32_PostThreadMessage(a, b, c, d);
586 SetFS(sel);
587
588 return yyrc;
589}
590//******************************************************************************
591BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
592{
593 TEB *teb = GetTEBFromThreadId(threadid);
594 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
595 BOOL ret;
596
597 if(NULL == packet)
598 {
599 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
600 _sheapmin() ));
601
602 DebugInt3();
603 // PH: we can provide a correct returncode
604 return FALSE;
605 }
606
607 if(teb == NULL) {
608 dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid));
609 return FALSE;
610 }
611 dprintf(("PostThreadMessageA %x %x %x %x -> hmq %x", threadid, msg, wParam, lParam, teb->o.odin.hmq));
612 packet->wParam = wParam;
613 packet->lParam = lParam;
614
615 ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg,
616 (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
617 (MPARAM)packet);
618
619 if(ret == FALSE)
620 {
621 SetLastError(ERROR_INVALID_PARAMETER_W);
622 return FALSE;
623 }
624 SetLastError(ERROR_SUCCESS_W);
625 return TRUE;
626}
627//******************************************************************************
628//******************************************************************************
629
Note: See TracBrowser for help on using the repository browser.