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

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

fix

File size: 24.2 KB
Line 
1/* $Id: oslibmsg.cpp,v 1.57 2002-06-15 17:38:23 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 switch (pMsg->message)
414 {
415 case WINWM_KEYDOWN:
416 case WINWM_KEYUP:
417 case WINWM_SYSKEYDOWN:
418 case WINWM_SYSKEYUP:
419 // only supposed to be called upon WM_KEYDOWN
420 // and WM_KEYUP according to docs.
421 if(ProcessKbdHook(pMsg, fRemove))
422 goto continuepeekmsg;
423 break;
424 }
425
426 return TRUE;
427 }
428
429continuepeekmsg:
430 if(uMsgFilterMin && uMsgFilterMax)
431 { //we can't use the PM message filter (since the message nrs aren't similar), so we must
432 //filter each message seperately
433 //to do so, we will translate each win32 message in the filter range and call WinPeekMsg
434 ULONG ulPMFilter;
435
436 for(int i=0;i<uMsgFilterMax-uMsgFilterMin+1;i++) {
437 rc = 0;
438
439 ulPMFilter = TranslateWinMsg(uMsgFilterMin+i, TRUE, TRUE);
440 if(ulPMFilter) {
441 do {
442 eaten = FALSE;
443
444 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, ulPMFilter, ulPMFilter,
445 (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
446
447 if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
448 eaten = TIMER_HandleTimer(&os2msg);
449 }
450 }
451 while (eaten && rc);
452 }
453 if(rc) {
454 break;
455 }
456 }
457 }
458 else {
459 do {
460 eaten = FALSE;
461
462 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, 0, 0, (fRemove & PM_REMOVE_W) ? PM_REMOVE : PM_NOREMOVE);
463
464 if (rc && (fRemove & PM_REMOVE_W) && os2msg.msg == WM_TIMER) {
465 eaten = TIMER_HandleTimer(&os2msg);
466 }
467 }
468 while (eaten && rc);
469 }
470 if(rc == FALSE) {
471 return FALSE;
472 }
473
474 // @@@PH
475 // warning - OS2ToWinMsgTranslate might insert additional messages
476 // into the queue
477 if(OS2ToWinMsgTranslate((PVOID)teb, &os2msg, pMsg, isUnicode, (fRemove & PM_REMOVE_W) ? MSG_REMOVE : MSG_NOREMOVE) == FALSE)
478 {
479 //unused PM message; dispatch immediately and grab next one
480 dprintf2(("OSLibWinPeekMsg: Untranslated message; dispatched immediately"));
481 if(!(fRemove & PM_REMOVE_W)) {
482 rc = WinPeekMsg(teb->o.odin.hab, &os2msg, hwndOS2, TranslateWinMsg(uMsgFilterMin, TRUE),
483 TranslateWinMsg(uMsgFilterMax, FALSE), PM_REMOVE);
484 }
485 WinDispatchMsg(teb->o.odin.hab, &os2msg);
486 return OSLibWinPeekMsg(pMsg, hwnd, uMsgFilterMin, uMsgFilterMax, fRemove, isUnicode);
487 }
488 //TODO: This is not safe! There's no guarantee this message will be dispatched and it might overwrite a previous message
489 if(fRemove & PM_REMOVE_W) {
490 memcpy(&teb->o.odin.os2msg, &os2msg, sizeof(QMSG));
491 memcpy(&teb->o.odin.winmsg, pMsg, sizeof(MSG));
492 }
493
494 // send keyboard messages to the registered hooks
495 switch (pMsg->message)
496 {
497 case WINWM_KEYDOWN:
498 case WINWM_KEYUP:
499 case WINWM_SYSKEYDOWN:
500 case WINWM_SYSKEYUP:
501 // only supposed to be called upon WM_KEYDOWN
502 // and WM_KEYUP according to docs.
503 if(ProcessKbdHook(pMsg, fRemove))
504 goto continuepeekmsg;
505 break;
506 }
507
508 return rc;
509}
510//******************************************************************************
511//******************************************************************************
512ULONG OSLibWinQueryMsgTime()
513{
514 return WinQueryMsgTime(GetThreadHAB());
515}
516//******************************************************************************
517//******************************************************************************
518BOOL OSLibWinWaitMessage()
519{
520 return WinWaitMsg(GetThreadHAB(), 0, 0);
521}
522//******************************************************************************
523//TODO: QS_HOTKEY
524//******************************************************************************
525ULONG OSLibWinQueryQueueStatus()
526{
527 ULONG statusOS2, statusWin32 = 0;
528
529 statusOS2 = WinQueryQueueStatus(HWND_DESKTOP);
530
531 if(statusOS2 & QS_KEY)
532 statusWin32 |= QS_KEY_W;
533 if(statusOS2 & QS_MOUSEBUTTON)
534 statusWin32 |= QS_MOUSEBUTTON_W;
535 if(statusOS2 & QS_MOUSEMOVE)
536 statusWin32 |= QS_MOUSEMOVE_W;
537 if(statusOS2 & QS_TIMER)
538 statusWin32 |= QS_TIMER_W;
539 if(statusOS2 & QS_PAINT)
540 statusWin32 |= QS_PAINT_W;
541 if(statusOS2 & QS_POSTMSG)
542 statusWin32 |= QS_POSTMESSAGE_W;
543 if(statusOS2 & QS_SENDMSG)
544 statusWin32 |= QS_SENDMESSAGE_W;
545
546 return statusWin32;
547}
548//******************************************************************************
549//******************************************************************************
550BOOL OSLibWinInSendMessage()
551{
552 return WinInSendMsg(GetThreadHAB());
553}
554//******************************************************************************
555//******************************************************************************
556DWORD OSLibWinGetMessagePos()
557{
558 APIRET rc;
559 POINTL ptl;
560
561 rc = WinQueryMsgPos(GetThreadHAB(), &ptl);
562 if(!rc) {
563 return 0;
564 }
565 //convert to windows coordinates
566 return MAKEULONG(ptl.x,mapScreenY(ptl.y));
567}
568//******************************************************************************
569//******************************************************************************
570LONG OSLibWinGetMessageTime()
571{
572 return (LONG)WinQueryMsgTime(GetThreadHAB());
573}
574//******************************************************************************
575//******************************************************************************
576BOOL OSLibWinReplyMessage(ULONG result)
577{
578 return (BOOL)WinReplyMsg( NULLHANDLE, NULLHANDLE, HMQ_CURRENT, (MRESULT)result);
579}
580//******************************************************************************
581//******************************************************************************
582ULONG OSLibSendMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
583{
584 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
585
586 if(NULL == packet)
587 {
588 dprintf(("user32::oslibmsg::OSLibSendMessage - allocated packet structure is NULL, heapmin=%d\n",
589 _sheapmin() ));
590
591 // PH: we cannot provide a correct returncode :(
592 DebugInt3();
593 return 0;
594 }
595
596 packet->wParam = wParam;
597 packet->lParam = lParam;
598
599 return (ULONG)WinSendMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
600}
601//******************************************************************************
602//******************************************************************************
603ULONG OSLibWinBroadcastMsg(ULONG msg, ULONG wParam, ULONG lParam, BOOL fSend)
604{
605 return WinBroadcastMsg(HWND_DESKTOP, WIN32APP_POSTMSG+msg, (MPARAM)wParam, (MPARAM)lParam,
606 (fSend) ? BMSG_SEND : BMSG_POST);
607}
608//******************************************************************************
609//******************************************************************************
610BOOL OSLibPostMessage(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam, BOOL fUnicode)
611{
612 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
613
614 if (NULL == packet)
615 {
616 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
617 _sheapmin() ));
618
619 // PH: we can provide a correct returncode
620 DebugInt3();
621 return FALSE;
622 }
623 packet->wParam = wParam;
624 packet->lParam = lParam;
625 return WinPostMsg(hwnd, WIN32APP_POSTMSG+msg, (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA), (MPARAM)packet);
626}
627//******************************************************************************
628//Direct posting of messages that must remain invisible to the win32 app
629//******************************************************************************
630BOOL OSLibPostMessageDirect(HWND hwnd, ULONG msg, ULONG wParam, ULONG lParam)
631{
632 return WinPostMsg(hwnd, msg, (MPARAM)wParam, (MPARAM)lParam);
633}
634//******************************************************************************
635//******************************************************************************
636BOOL OSLibPostThreadMessage(ULONG threadid, UINT msg, WPARAM wParam, LPARAM lParam, BOOL fUnicode)
637{
638 TEB *teb = GetTEBFromThreadId(threadid);
639 POSTMSG_PACKET *packet = (POSTMSG_PACKET *)_smalloc(sizeof(POSTMSG_PACKET));
640 BOOL ret;
641
642 if(NULL == packet)
643 {
644 dprintf(("user32::oslibmsg::OSLibPostMessage - allocated packet structure is NULL, heapmin=%d\n",
645 _sheapmin() ));
646
647 DebugInt3();
648 // PH: we can provide a correct returncode
649 return FALSE;
650 }
651
652 if(teb == NULL) {
653 dprintf(("OSLibPostThreadMessage: thread %x not found!", threadid));
654 return FALSE;
655 }
656 dprintf(("PostThreadMessageA %x %x %x %x -> hmq %x", threadid, msg, wParam, lParam, teb->o.odin.hmq));
657 packet->wParam = wParam;
658 packet->lParam = lParam;
659
660 ret = WinPostQueueMsg((HMQ)teb->o.odin.hmq, WIN32APP_POSTMSG+msg,
661 (MPARAM)((fUnicode) ? WIN32MSG_MAGICW : WIN32MSG_MAGICA),
662 (MPARAM)packet);
663
664 if(ret == FALSE)
665 {
666 SetLastError(ERROR_INVALID_PARAMETER_W);
667 return FALSE;
668 }
669 SetLastError(ERROR_SUCCESS_W);
670 return TRUE;
671}
672//******************************************************************************
673//******************************************************************************
674DWORD GetThreadMessageExtraInfo()
675{
676 TEB *teb;
677
678 teb = GetThreadTEB();
679 if(teb)
680 {
681 return teb->o.odin.dwMsgExtraInfo;
682 }
683 dprintf(("GetThreadMessageExtraInfo: teb == NULL!!"));
684 return 0;
685}
686//******************************************************************************
687//******************************************************************************
688DWORD SetThreadMessageExtraInfo(DWORD lParam)
689{
690 TEB *teb;
691
692 teb = GetThreadTEB();
693 if(teb)
694 {
695 teb->o.odin.dwMsgExtraInfo = lParam;
696 }
697 else dprintf(("SetThreadMessageExtraInfo: teb == NULL!!"));
698 return 0;
699}
700//******************************************************************************
701//******************************************************************************
Note: See TracBrowser for help on using the repository browser.