home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_03_05 / 3n05054b < prev    next >
Text File  |  1992-03-10  |  2KB  |  62 lines

  1. Listing 2
  2.  
  3. /*****************************************************/
  4. /* fpumsg.c                                          */
  5. /* -- Module to implement PeekMessage() with a check */
  6. /*    of the FPU's status word.                      */
  7. /*****************************************************/
  8.  
  9. #include <windows.h>
  10. #include "fpumsg.h"
  11.  
  12. BOOL
  13. FPeekMessageLpfn(LPMSG lpmsg, HWND hwnd,
  14.   WORD wMsgFilterMin, WORD wMsgFilterMax,
  15.   WORD wRemoveMsg, LPFN_NOTIFY lpfnNotify)
  16. /*****************************************************/
  17. /* -- PeekMessage() wrapper.                         */
  18. /* -- Get a message from the queue.                  */
  19. /* -- Check the FPU's status first, and if we have   */
  20. /*    racked up exceptions, call lpfnNotify.         */
  21. /* -- Makes sure all exceptions are masked after the */
  22. /*    call to PeekMessage(), so win87em won't UAE us */
  23. /*    if we do generate an exception.                */
  24. /* -- lpmsg         : Store message here.            */
  25. /* -- hwnd          : Get message for this window,   */
  26. /*                    NULL for all windows.          */
  27. /* -- wMsgFilterMin : Least message.                 */
  28. /* -- wMsgFilterMax : Greatest message.              */
  29. /* -- wRemoveMsg    : PeekMessage() flags.           */
  30. /* -- lpfnNotify    : Callback in case of FPU        */
  31. /*                    exception.                     */
  32. /*****************************************************/
  33.     {
  34.     BOOL    fGotMessage;
  35.     WORD    wStatus, wControl;
  36.  
  37.     /* Get the status of the FPU. */
  38.     _asm fstsw   wStatus;
  39.     _asm wait;
  40.  
  41.     /* Get rid of any exceptions. */
  42.     _asm fclex;
  43.  
  44.     /* Did an exception occured? */
  45.     if (wStatus & 0x003f)
  46.         Notify(wStatus, lpfnNotify);
  47.  
  48.     /* Get a message. */
  49.     fGotMessage = PeekMessage(lpmsg, hwnd,
  50.       wMsgFilterMin, wMsgFilterMax, wRemoveMsg);
  51.  
  52.     /* Mask all exceptions to prevent win87em from */
  53.     /* blowing us away. */
  54.     _asm fstcw   wControl;
  55.     _asm wait;
  56.     wControl |= 0x003f;
  57.     _asm fldcw   wControl
  58.  
  59.     return fGotMessage;
  60.     }
  61.  
  62.