home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / vrac / dflt20.zip / MESSAGE.C < prev    next >
C/C++ Source or Header  |  1994-12-14  |  19KB  |  648 lines

  1. /* --------- message.c ---------- */
  2.  
  3. #include "dflat.h"
  4.  
  5. static int px = -1, py = -1;
  6. static int pmx = -1, pmy = -1;
  7. static int mx, my;
  8. static int handshaking = 0;
  9. static BOOL CriticalError;
  10. BOOL AllocTesting = FALSE;
  11. jmp_buf AllocError;
  12. BOOL AltDown = FALSE;
  13.  
  14. /* ---------- event queue ---------- */
  15. static struct events    {
  16.     MESSAGE event;
  17.     int mx;
  18.     int my;
  19. } EventQueue[MAXMESSAGES];
  20.  
  21. /* ---------- message queue --------- */
  22. static struct msgs {
  23.     WINDOW wnd;
  24.     MESSAGE msg;
  25.     PARAM p1;
  26.     PARAM p2;
  27. } MsgQueue[MAXMESSAGES];
  28.  
  29. static int EventQueueOnCtr;
  30. static int EventQueueOffCtr;
  31. static int EventQueueCtr;
  32.  
  33. static int MsgQueueOnCtr;
  34. static int MsgQueueOffCtr;
  35. static int MsgQueueCtr;
  36.  
  37. static int lagdelay = FIRSTDELAY;
  38.  
  39. static void (interrupt far *oldtimer)(void);
  40. static void (interrupt far *oldkeyboard)(void);
  41.  
  42. static int keyportvalue;    /* for watching for key release */
  43.  
  44. WINDOW CaptureMouse;
  45. WINDOW CaptureKeyboard;
  46. static BOOL NoChildCaptureMouse;
  47. static BOOL NoChildCaptureKeyboard;
  48.  
  49. static int doubletimer = -1;
  50. static int delaytimer  = -1;
  51. static int clocktimer  = -1;
  52. char time_string[] = "         ";
  53.  
  54. static WINDOW Cwnd;
  55.  
  56. static void interrupt far newkeyboard(void)
  57. {
  58.     keyportvalue = inp(KEYBOARDPORT);
  59.     oldkeyboard();
  60. }
  61.  
  62. /* ------- timer interrupt service routine ------- */
  63. static void interrupt far newtimer(void)
  64. {
  65.     if (timer_running(doubletimer))
  66.         countdown(doubletimer);
  67.     if (timer_running(delaytimer))
  68.         countdown(delaytimer);
  69.     if (timer_running(clocktimer))
  70.         countdown(clocktimer);
  71.     oldtimer();
  72. }
  73.  
  74. static char ermsg[] = "Error accessing drive x";
  75.  
  76. /* -------- test for critical errors --------- */
  77. int TestCriticalError(void)
  78. {
  79.     int rtn = 0;
  80.     if (CriticalError)    {
  81.         rtn = 1;
  82.         CriticalError = FALSE;
  83.         if (TestErrorMessage(ermsg) == FALSE)
  84.             rtn = 2;
  85.     }
  86.     return rtn;
  87. }
  88.  
  89. /* ------ critical error interrupt service routine ------ */
  90. static void interrupt far newcrit(IREGS ir)
  91. {
  92.     if (!(ir.ax & 0x8000))     {
  93.         ermsg[sizeof(ermsg) - 2] = (ir.ax & 0xff) + 'A';
  94.         CriticalError = TRUE;
  95.     }
  96.     ir.ax = 0;
  97. }
  98.  
  99. static void StopMsg(void)
  100. {
  101.     if (oldtimer != NULL)    {
  102.         setvect(TIMER, oldtimer);
  103.         oldtimer = NULL;
  104.     }
  105.     if (oldkeyboard != NULL)    {
  106.         setvect(KEYBOARDVECT, oldkeyboard);
  107.         oldkeyboard = NULL;
  108.     }
  109.     ClearClipboard();
  110.     ClearDialogBoxes();
  111.     restorecursor();    
  112.     unhidecursor();
  113.     hide_mousecursor();
  114. }
  115.  
  116. /* ------------ initialize the message system --------- */
  117. BOOL init_messages(void)
  118. {
  119.     AllocTesting = TRUE;
  120.     if (setjmp(AllocError) != 0)    {
  121.         StopMsg();
  122.         return FALSE;
  123.     }
  124.     resetmouse();
  125.     set_mousetravel(0, SCREENWIDTH-1, 0, SCREENHEIGHT-1);
  126.     savecursor();
  127.     hidecursor();
  128.     px = py = -1;
  129.     pmx = pmy = -1;
  130.     mx = my = 0;
  131.     CaptureMouse = CaptureKeyboard = NULL;
  132.     NoChildCaptureMouse = FALSE;
  133.     NoChildCaptureKeyboard = FALSE;
  134.     MsgQueueOnCtr = MsgQueueOffCtr = MsgQueueCtr = 0;
  135.     EventQueueOnCtr = EventQueueOffCtr = EventQueueCtr = 0;
  136.     if (oldtimer == NULL)    {
  137.         oldtimer = getvect(TIMER);
  138.         setvect(TIMER, newtimer);
  139.     }
  140.     if (oldkeyboard == NULL)    {
  141.         oldkeyboard = getvect(KEYBOARDVECT);
  142.         setvect(KEYBOARDVECT, newkeyboard);
  143.     }
  144.     setvect(CRIT, newcrit);
  145.     PostMessage(NULL,START,0,0);
  146.     lagdelay = FIRSTDELAY;
  147.     return TRUE;
  148. }
  149.  
  150. /* ----- post an event and parameters to event queue ---- */
  151. static void PostEvent(MESSAGE event, int p1, int p2)
  152. {
  153.     if (EventQueueCtr != MAXMESSAGES)    {
  154.         EventQueue[EventQueueOnCtr].event = event;
  155.         EventQueue[EventQueueOnCtr].mx = p1;
  156.         EventQueue[EventQueueOnCtr].my = p2;
  157.         if (++EventQueueOnCtr == MAXMESSAGES)
  158.             EventQueueOnCtr = 0;
  159.         EventQueueCtr++;
  160.     }
  161. }
  162.  
  163. /* ------ collect mouse, clock, and keyboard events ----- */
  164. static void near collect_events(void)
  165. {
  166.     static int ShiftKeys = 0;
  167.     int sk;
  168.     struct tm *now;
  169.     static BOOL flipflop = FALSE;
  170.     int hr;
  171.  
  172.     /* -------- test for a clock event (one/second) ------- */
  173.     if (timed_out(clocktimer))    {
  174.         /* ----- get the current time ----- */
  175.         time_t t = time(NULL);
  176.         now = localtime(&t);
  177.         hr = now->tm_hour > 12 ?
  178.              now->tm_hour - 12 :
  179.              now->tm_hour;
  180.         if (hr == 0)
  181.             hr = 12;
  182.         sprintf(time_string, "%2d:%02d", hr, now->tm_min);
  183.         strcpy(time_string+5, now->tm_hour > 11 ? "pm " : "am ");
  184.         /* ------- blink the : at one-second intervals ----- */
  185.         if (flipflop)
  186.             *(time_string+2) = ' ';
  187.         flipflop ^= TRUE;
  188.         /* -------- reset the timer -------- */
  189.         set_timer(clocktimer, 1);
  190.         /* -------- post the clock event -------- */
  191.         PostEvent(CLOCKTICK, FP_SEG(time_string), FP_OFF(time_string));
  192.     }
  193.  
  194.     /* --------- keyboard events ---------- */
  195.     if ((sk = getshift()) != ShiftKeys)    {
  196.         ShiftKeys = sk;
  197.         /* ---- the shift status changed ---- */
  198.         PostEvent(SHIFT_CHANGED, sk, 0);
  199.         if (sk & ALTKEY)
  200.             AltDown = TRUE;
  201.     }
  202.  
  203.     /* ---- build keyboard events for key combinations that
  204.         BIOS doesn't report --------- */
  205.     if (sk & ALTKEY)    {
  206.         if (keyportvalue == 14)    {
  207.             AltDown = FALSE;
  208.             waitforkeyboard();
  209.             PostEvent(KEYBOARD, ALT_BS, sk);
  210.         }
  211.         if (keyportvalue == 83)    {
  212.             AltDown = FALSE;
  213.             waitforkeyboard();
  214.             PostEvent(KEYBOARD, ALT_DEL, sk);
  215.         }
  216.     }
  217.     if (sk & CTRLKEY)    {
  218.         AltDown = FALSE;
  219.         if (keyportvalue == 82)    {
  220.             waitforkeyboard();
  221.             PostEvent(KEYBOARD, CTRL_INS, sk);
  222.         }
  223.     }
  224.     /* ----------- test for keystroke ------- */
  225.     if (keyhit())    {
  226.         static int cvt[] = {SHIFT_INS,END,DN,PGDN,BS,'5',
  227.                         FWD,HOME,UP,PGUP};
  228.         int c = getkey();
  229.  
  230.         AltDown = FALSE;
  231.         /* -------- convert numeric pad keys ------- */
  232.         if (sk & (LEFTSHIFT | RIGHTSHIFT))    {
  233.             if (c >= '0' && c <= '9')
  234.                 c = cvt[c-'0'];
  235.             else if (c == '.' || c == DEL)
  236.                 c = SHIFT_DEL;
  237.             else if (c == INS)
  238.                 c = SHIFT_INS;
  239.         }
  240.         if (c != '\r' && (c < ' ' || c > 127))
  241.             clearBIOSbuffer();
  242.         /* ------ post the keyboard event ------ */
  243.         PostEvent(KEYBOARD, c, sk);
  244.     }
  245.  
  246.     /* ------------ test for mouse events --------- */
  247.     if (button_releases())    {
  248.         /* ------- the button was released -------- */
  249.         AltDown = FALSE;
  250.         doubletimer = DOUBLETICKS;
  251.         PostEvent(BUTTON_RELEASED, mx, my);
  252.         disable_timer(delaytimer);
  253.     }
  254.     get_mouseposition(&mx, &my);
  255.     if (mx != px || my != py)  {
  256.         px = mx;
  257.         py = my;
  258.         PostEvent(MOUSE_MOVED, mx, my);
  259.     }
  260.     if (rightbutton())    {
  261.         AltDown = FALSE;
  262.         PostEvent(RIGHT_BUTTON, mx, my);
  263.     }
  264.     if (leftbutton())    {
  265.         AltDown = FALSE;
  266.         if (mx == pmx && my == pmy)    {
  267.             /* ---- same position as last left button ---- */
  268.             if (timer_running(doubletimer))    {
  269.                 /* -- second click before double timeout -- */
  270.                 disable_timer(doubletimer);
  271.                 PostEvent(DOUBLE_CLICK, mx, my);
  272.             }
  273.             else if (!timer_running(delaytimer))    {
  274.                 /* ---- button held down a while ---- */
  275.                 delaytimer = lagdelay;
  276.                 lagdelay = DELAYTICKS;
  277.                 /* ---- post a typematic-like button ---- */
  278.                 PostEvent(LEFT_BUTTON, mx, my);
  279.             }
  280.         }
  281.         else    {
  282.             /* --------- new button press ------- */
  283.             disable_timer(doubletimer);
  284.             delaytimer = FIRSTDELAY;
  285.             lagdelay = DELAYTICKS;
  286.             PostEvent(LEFT_BUTTON, mx, my);
  287.             pmx = mx;
  288.             pmy = my;
  289.         }
  290.     }
  291.     else
  292.         lagdelay = FIRSTDELAY;
  293. }
  294.  
  295. /* ----- post a message and parameters to msg queue ---- */
  296. void PostMessage(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  297. {
  298.     if (MsgQueueCtr != MAXMESSAGES)    {
  299.         MsgQueue[MsgQueueOnCtr].wnd = wnd;
  300.         MsgQueue[MsgQueueOnCtr].msg = msg;
  301.         MsgQueue[MsgQueueOnCtr].p1 = p1;
  302.         MsgQueue[MsgQueueOnCtr].p2 = p2;
  303.         if (++MsgQueueOnCtr == MAXMESSAGES)
  304.             MsgQueueOnCtr = 0;
  305.         MsgQueueCtr++;
  306.     }
  307. }
  308.  
  309. /* --------- send a message to a window ----------- */
  310. int SendMessage(WINDOW wnd, MESSAGE msg, PARAM p1, PARAM p2)
  311. {
  312.     int rtn = TRUE, x, y;
  313.  
  314. #ifdef INCLUDE_LOGGING
  315.     LogMessages(wnd, msg, p1, p2);
  316. #endif
  317.     if (wnd != NULL)
  318.         switch (msg)    {
  319.             case PAINT:
  320.             case BORDER:
  321.                 /* ------- don't send these messages unless the
  322.                     window is visible -------- */
  323.                 if (isVisible(wnd))
  324.                     rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
  325.                 break;
  326.             case RIGHT_BUTTON:
  327.             case LEFT_BUTTON:
  328.             case DOUBLE_CLICK:
  329.             case BUTTON_RELEASED:
  330.                 /* --- don't send these messages unless the
  331.                     window is visible or has captured the mouse -- */
  332.                 if (isVisible(wnd) || wnd == CaptureMouse)
  333.                     rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
  334.                 break;
  335.             case KEYBOARD:
  336.             case SHIFT_CHANGED:
  337.                 /* ------- don't send these messages unless the
  338.                     window is visible or has captured the keyboard -- */
  339.                 if (!(isVisible(wnd) || wnd == CaptureKeyboard))
  340.                     break;
  341.             default:
  342.                 rtn = (*wnd->wndproc)(wnd, msg, p1, p2);
  343.                 break;
  344.         }
  345.     /* ----- window processor returned true or the message was sent
  346.         to no window at all (NULL) ----- */
  347.     if (rtn != FALSE)    {
  348.         /* --------- process messages that a window sends to the
  349.             system itself ---------- */
  350.         switch (msg)    {
  351.             case STOP:
  352.                 StopMsg();
  353.                 break;
  354.             /* ------- clock messages --------- */
  355.             case CAPTURE_CLOCK:
  356.                 if (Cwnd == NULL)
  357.                     set_timer(clocktimer, 0);
  358.                 wnd->PrevClock = Cwnd;
  359.                 Cwnd = wnd;
  360.                 break;
  361.             case RELEASE_CLOCK:
  362.                 Cwnd = wnd->PrevClock;
  363.                 if (Cwnd == NULL)
  364.                     disable_timer(clocktimer);
  365.                 break;
  366.             /* -------- keyboard messages ------- */
  367.             case KEYBOARD_CURSOR:
  368.                 if (wnd == NULL)
  369.                     cursor((int)p1, (int)p2);
  370.                 else if (wnd == inFocus)
  371.                     cursor(GetClientLeft(wnd)+(int)p1,
  372.                                 GetClientTop(wnd)+(int)p2);
  373.                 break;
  374.             case CAPTURE_KEYBOARD:
  375.                 if (p2)
  376.                     ((WINDOW)p2)->PrevKeyboard=CaptureKeyboard;
  377.                 else
  378.                     wnd->PrevKeyboard = CaptureKeyboard;
  379.                 CaptureKeyboard = wnd;
  380.                 NoChildCaptureKeyboard = (int)p1;
  381.                 break;
  382.             case RELEASE_KEYBOARD:
  383.                 if (wnd != NULL)    {
  384.                     if (CaptureKeyboard == wnd || (int)p1)
  385.                         CaptureKeyboard = wnd->PrevKeyboard;
  386.                     else    {
  387.                         WINDOW twnd = CaptureKeyboard;
  388.                         while (twnd != NULL)    {
  389.                             if (twnd->PrevKeyboard == wnd)    {
  390.                                 twnd->PrevKeyboard = wnd->PrevKeyboard;
  391.                                 break;
  392.                             }
  393.                             twnd = twnd->PrevKeyboard;
  394.                         }
  395.                         if (twnd == NULL)
  396.                             CaptureKeyboard = NULL;
  397.                     }
  398.                     wnd->PrevKeyboard = NULL;
  399.                 }
  400.                 else
  401.                     CaptureKeyboard = NULL;
  402.                 NoChildCaptureKeyboard = FALSE;
  403.                 break;
  404.             case CURRENT_KEYBOARD_CURSOR:
  405.                 curr_cursor(&x, &y);
  406.                 *(int*)p1 = x;
  407.                 *(int*)p2 = y;
  408.                 break;
  409.             case SAVE_CURSOR:
  410.                 savecursor();
  411.                 break;
  412.             case RESTORE_CURSOR:
  413.                 restorecursor();
  414.                 break;
  415.             case HIDE_CURSOR:
  416.                 normalcursor();
  417.                 hidecursor();
  418.                 break;
  419.             case SHOW_CURSOR:
  420.                 if (p1)
  421.                     set_cursor_type(0x0106);
  422.                 else
  423.                     set_cursor_type(0x0607);
  424.                 unhidecursor();
  425.                 break;
  426.             case WAITKEYBOARD:
  427.                 waitforkeyboard();
  428.                 break;
  429.             /* -------- mouse messages -------- */
  430.             case RESET_MOUSE:
  431.                 resetmouse();
  432.                 set_mousetravel(0, SCREENWIDTH-1, 0, SCREENHEIGHT-1);
  433.                 break;
  434.             case MOUSE_INSTALLED:
  435.                 rtn = mouse_installed();
  436.                 break;
  437.             case MOUSE_TRAVEL:    {
  438.                 RECT rc;
  439.                 if (!p1)    {
  440.                     rc.lf = rc.tp = 0;
  441.                     rc.rt = SCREENWIDTH-1;
  442.                     rc.bt = SCREENHEIGHT-1;
  443.                 }
  444.                 else 
  445.                     rc = *(RECT *)p1;
  446.                 set_mousetravel(rc.lf, rc.rt, rc.tp, rc.bt);
  447.                 break;
  448.             }
  449.             case SHOW_MOUSE:
  450.                 show_mousecursor();
  451.                 break;
  452.             case HIDE_MOUSE:
  453.                 hide_mousecursor();
  454.                 break;
  455.             case MOUSE_CURSOR:
  456.                 set_mouseposition((int)p1, (int)p2);
  457.                 break;
  458.             case CURRENT_MOUSE_CURSOR:
  459.                 get_mouseposition((int*)p1,(int*)p2);
  460.                 break;
  461.             case WAITMOUSE:
  462.                 waitformouse();
  463.                 break;
  464.             case TESTMOUSE:
  465.                 rtn = mousebuttons();
  466.                 break;
  467.             case CAPTURE_MOUSE:
  468.                 if (p2)
  469.                     ((WINDOW)p2)->PrevMouse = CaptureMouse;
  470.                 else
  471.                     wnd->PrevMouse = CaptureMouse;
  472.                 CaptureMouse = wnd;
  473.                 NoChildCaptureMouse = (int)p1;
  474.                 break;
  475.             case RELEASE_MOUSE:
  476.                 if (wnd != NULL)    {
  477.                     if (CaptureMouse == wnd || (int)p1)
  478.                         CaptureMouse = wnd->PrevMouse;
  479.                     else    {
  480.                         WINDOW twnd = CaptureMouse;
  481.                         while (twnd != NULL)    {
  482.                             if (twnd->PrevMouse == wnd)    {
  483.                                 twnd->PrevMouse = wnd->PrevMouse;
  484.                                 break;
  485.                             }
  486.                             twnd = twnd->PrevMouse;
  487.                         }
  488.                         if (twnd == NULL)
  489.                             CaptureMouse = NULL;
  490.                     }
  491.                     wnd->PrevMouse = NULL;
  492.                 }
  493.                 else
  494.                     CaptureMouse = NULL;
  495.                 NoChildCaptureMouse = FALSE;
  496.                 break;
  497.             default:
  498.                 break;
  499.         }
  500.     }
  501.     return rtn;
  502. }
  503.  
  504. static RECT VisibleRect(WINDOW wnd)
  505. {
  506.     RECT rc = WindowRect(wnd);
  507.     if (!TestAttribute(wnd, NOCLIP))    {
  508.         WINDOW pwnd = GetParent(wnd);
  509.         RECT prc;
  510.         prc = ClientRect(pwnd);
  511.         while (pwnd != NULL)    {
  512.             if (TestAttribute(pwnd, NOCLIP))
  513.                 break;
  514.             rc = subRectangle(rc, prc);
  515.             if (!ValidRect(rc))
  516.                 break;
  517.             if ((pwnd = GetParent(pwnd)) != NULL)
  518.                 prc = ClientRect(pwnd);
  519.         }
  520.     }
  521.     return rc;
  522. }
  523.  
  524. /* ----- find window that mouse coordinates are in --- */
  525. static WINDOW inWindow(WINDOW wnd, int x, int y)
  526. {
  527.     WINDOW Hit = NULL;
  528.     while (wnd != NULL)    {
  529.         if (isVisible(wnd))    {
  530.             WINDOW wnd1;
  531.             RECT rc = VisibleRect(wnd);
  532.             if (InsideRect(x, y, rc))
  533.                 Hit = wnd;
  534.             if ((wnd1 = inWindow(LastWindow(wnd), x, y)) != NULL)
  535.                 Hit = wnd1;
  536.             if (Hit != NULL)
  537.                 break;
  538.         }
  539.         wnd = PrevWindow(wnd);
  540.     }
  541.     return Hit;
  542. }
  543.  
  544. static WINDOW MouseWindow(int x, int y)
  545. {
  546.     /* ------ get the window in which a
  547.                     mouse event occurred ------ */
  548.     WINDOW Mwnd = inWindow(ApplicationWindow, x, y);
  549.     /* ---- process mouse captures ----- */
  550.     if (CaptureMouse != NULL)    {
  551.         if (NoChildCaptureMouse ||
  552.                 Mwnd == NULL     ||
  553.                     !isAncestor(Mwnd, CaptureMouse))
  554.             Mwnd = CaptureMouse;
  555.     }
  556.     return Mwnd;
  557. }
  558.  
  559. void handshake(void)
  560. {
  561.     handshaking++;
  562.     dispatch_message();
  563.     --handshaking;
  564. }
  565.  
  566. /* ---- dispatch messages to the message proc function ---- */
  567. BOOL dispatch_message(void)
  568. {
  569.     WINDOW Mwnd, Kwnd;
  570.     /* -------- collect mouse and keyboard events ------- */
  571.     collect_events();
  572.     /* --------- dequeue and process events -------- */
  573.     while (EventQueueCtr > 0)  {
  574.         struct events ev;
  575.             
  576.         ev = EventQueue[EventQueueOffCtr];
  577.         if (++EventQueueOffCtr == MAXMESSAGES)
  578.             EventQueueOffCtr = 0;
  579.         --EventQueueCtr;
  580.  
  581.         /* ------ get the window in which a
  582.                         keyboard event occurred ------ */
  583.         Kwnd = inFocus;
  584.  
  585.         /* ---- process keyboard captures ----- */
  586.         if (CaptureKeyboard != NULL)
  587.             if (Kwnd == NULL ||
  588.                     NoChildCaptureKeyboard ||
  589.                         !isAncestor(Kwnd, CaptureKeyboard))
  590.                 Kwnd = CaptureKeyboard;
  591.  
  592.         /* -------- send mouse and keyboard messages to the
  593.             window that should get them -------- */
  594.         switch (ev.event)    {
  595.             case SHIFT_CHANGED:
  596.             case KEYBOARD:
  597.                 if (!handshaking)
  598.                     SendMessage(Kwnd, ev.event, ev.mx, ev.my);
  599.                 break;
  600.             case LEFT_BUTTON:
  601.                 if (!handshaking)    {
  602.                     Mwnd = MouseWindow(ev.mx, ev.my);
  603.                     if (!CaptureMouse ||
  604.                             (!NoChildCaptureMouse &&
  605.                                 isAncestor(Mwnd, CaptureMouse)))
  606.                         if (Mwnd != inFocus)
  607.                             SendMessage(Mwnd, SETFOCUS, TRUE, 0);
  608.                     SendMessage(Mwnd, LEFT_BUTTON, ev.mx, ev.my);
  609.                 }
  610.                 break;
  611.             case BUTTON_RELEASED:
  612.             case DOUBLE_CLICK:
  613.             case RIGHT_BUTTON:
  614.                 if (handshaking)
  615.                     break;
  616.             case MOUSE_MOVED:
  617.                 Mwnd = MouseWindow(ev.mx, ev.my);
  618.                 SendMessage(Mwnd, ev.event, ev.mx, ev.my);
  619.                 break;
  620.             case CLOCKTICK:
  621.                 SendMessage(Cwnd, ev.event,
  622.                     (PARAM) MK_FP(ev.mx, ev.my), 0);
  623.                 break;
  624.             default:
  625.                 break;
  626.         }
  627.     }
  628.     /* ------ dequeue and process messages ----- */
  629.     while (MsgQueueCtr > 0)  {
  630.         struct msgs mq;
  631.  
  632.         mq = MsgQueue[MsgQueueOffCtr];
  633.         if (++MsgQueueOffCtr == MAXMESSAGES)
  634.             MsgQueueOffCtr = 0;
  635.         --MsgQueueCtr;
  636.         SendMessage(mq.wnd, mq.msg, mq.p1, mq.p2);
  637.         if (mq.msg == ENDDIALOG)
  638.             return FALSE;
  639.         if (mq.msg == STOP)    {
  640.             PostMessage(NULL, STOP, 0, 0);
  641.             return FALSE;
  642.         }
  643.     }
  644.     return TRUE;
  645. }
  646.  
  647.  
  648.