home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR13 / TI_BC1.ZIP / TI1558.ZIP / TI1558.ASC
Text File  |  1993-09-01  |  7KB  |  397 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.   PRODUCT  :  Borland C++                           NUMBER  :  1558
  9.   VERSION  :  3.x
  10.        OS  :  DOS
  11.      DATE  :  September 1, 1993                        PAGE  :  1/6
  12.  
  13.     TITLE  :  Saving/Restoring the mouse state in Turbo Vision
  14.  
  15.  
  16.  
  17.  
  18.   /*
  19.      Problem:
  20.        When I call mouse interrupts in my Turbo Vision
  21.        application, the mouse cursor disappears and the mouse is
  22.        disabled.
  23.  
  24.      Solution:
  25.        Save the mouse state using interrupts 33,15 and 33,16.
  26.        Then call the other mouse interrupts.  After calling the
  27.        other int 33 functions, restore the mouse state with
  28.        int 33,17.
  29.   */
  30.  
  31.   #include <dos.h>
  32.   #include <stdio.h>
  33.  
  34.   #define Uses_MsgBox
  35.   #define Uses_TKeys
  36.   #define Uses_TApplication
  37.   #define Uses_TEvent
  38.   #define Uses_TRect
  39.   #define Uses_TDialog
  40.   #define Uses_TStaticText
  41.   #define Uses_TButton
  42.   #define Uses_TMenuBar
  43.   #define Uses_TSubMenu
  44.   #define Uses_TMenuItem
  45.   #define Uses_TStatusLine
  46.   #define Uses_TStatusItem
  47.   #define Uses_TStatusDef
  48.   #define Uses_TDeskTop
  49.   #include <tv.h>
  50.  
  51.   const cmGetMouseType = 100;
  52.  
  53.   class MouseState
  54.   {
  55.   private:
  56.     // The size of the mouse state buffer.
  57.     //
  58.     static unsigned int statebufsize;
  59.  
  60.     // The buffer which saves state of mouse.
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.  
  73.  
  74.   PRODUCT  :  Borland C++                           NUMBER  :  1558
  75.   VERSION  :  3.x
  76.        OS  :  DOS
  77.      DATE  :  September 1, 1993                        PAGE  :  2/6
  78.  
  79.     TITLE  :  Saving/Restoring the mouse state in Turbo Vision
  80.  
  81.  
  82.  
  83.  
  84.     //
  85.     static char *statebuf;
  86.   public:
  87.     MouseState(void);
  88.     ~MouseState(void);
  89.     void saveMouseState (void);
  90.     void restoreMouseState (void);
  91.   };
  92.  
  93.   char        *MouseState::statebuf = 0;
  94.   unsigned int MouseState::statebufsize = 0;
  95.  
  96.   MouseState::MouseState (void)
  97.   {
  98.     statebufsize = 0;
  99.     statebuf = 0;
  100.   }
  101.  
  102.   MouseState::~MouseState (void)
  103.   {
  104.     /* Make sure that a MouseState does not get destroyed without
  105.        restoring the mouse state first.
  106.     */
  107.     restoreMouseState();
  108.   }
  109.  
  110.   void MouseState::saveMouseState (void)
  111.   {
  112.     // Check if a mouse state is already saved.
  113.     //
  114.     if (statebuf)
  115.     {
  116.       /* There is a previous mouse state saved.  Restore that
  117.          state before we save this one.
  118.       */
  119.       restoreMouseState();
  120.     }
  121.  
  122.     // Get size of mouse state buffer.
  123.     //
  124.     asm {
  125.       mov ax, 15h
  126.       int 33h     // Loads bx with size of buffer in bytes.
  127.  
  128.  
  129.  
  130.  
  131.  
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.   PRODUCT  :  Borland C++                           NUMBER  :  1558
  141.   VERSION  :  3.x
  142.        OS  :  DOS
  143.      DATE  :  September 1, 1993                        PAGE  :  3/6
  144.  
  145.     TITLE  :  Saving/Restoring the mouse state in Turbo Vision
  146.  
  147.  
  148.  
  149.  
  150.     }
  151.     statebufsize = _BX;
  152.     statebuf     = new char[statebufsize];
  153.  
  154.     // Now save mouse state buffer.
  155.     //
  156.     _ES = FP_SEG (statebuf);
  157.     _DX = FP_OFF (statebuf);
  158.     asm {
  159.       mov ax, 16h
  160.       int 33h    // Saves mouse state structure into statebuf.
  161.     }
  162.   }
  163.  
  164.   void MouseState::restoreMouseState (void)
  165.   {
  166.     if (statebuf)
  167.     {
  168.       // Restore mouse state from statebuf.
  169.       //
  170.       _ES = FP_SEG (statebuf);
  171.       _DX = FP_OFF (statebuf);
  172.       asm {
  173.         mov ax, 17h
  174.         int 33h     // Restore mouse state structure from statebuf.
  175.       }
  176.       delete statebuf;
  177.       statebuf = 0;
  178.       statebufsize = 0;
  179.     }
  180.   }
  181.  
  182.   /* This test function calls some mouse interrupts that can cause
  183.      the mouse to become disabled.
  184.   */
  185.   int getMouseType (void)
  186.   {
  187.     /* Returns -1 if no mouse driver is loaded.  Otherwise returns
  188.        the type of mouse installed (serial, bus, etc.).
  189.     */
  190.     unsigned int mouseloaded;
  191.     signed int   mousetype;
  192.  
  193.  
  194.  
  195.  
  196.  
  197.  
  198.  
  199.  
  200.  
  201.  
  202.  
  203.  
  204.  
  205.  
  206.   PRODUCT  :  Borland C++                           NUMBER  :  1558
  207.   VERSION  :  3.x
  208.        OS  :  DOS
  209.      DATE  :  September 1, 1993                        PAGE  :  4/6
  210.  
  211.     TITLE  :  Saving/Restoring the mouse state in Turbo Vision
  212.  
  213.  
  214.  
  215.  
  216.     // Save mouse state.
  217.     //
  218.     MouseState  ms;
  219.     ms.saveMouseState();
  220.  
  221.     // Detect mouse driver.
  222.     //
  223.     asm {
  224.       mov ax, 0
  225.       int 33h     // AX gets 0, if no mouse driver, else FFFF.
  226.     }
  227.     mouseloaded = _AX;
  228.  
  229.     if (mouseloaded)
  230.     {
  231.       // Get type of mouse installed.
  232.       //
  233.       asm {
  234.         mov ax, 24h
  235.         int 33h   // CH gets type of mouse installed.
  236.       }
  237.       mousetype  = _CH;
  238.     }
  239.     else
  240.       mousetype = -1;
  241.  
  242.     // Restore mouse state.
  243.     //
  244.     ms.restoreMouseState();
  245.  
  246.     return mousetype;
  247.   }
  248.  
  249.   const char *mouseType[] = { "Unknown","Bus","Serial",
  250.                               "InPort","PS/2","HP" };
  251.  
  252.   class MouseApp : public TApplication
  253.   {
  254.  
  255.   public:
  256.       MouseApp();
  257.  
  258.       virtual void handleEvent (TEvent& event);
  259.  
  260.  
  261.  
  262.  
  263.  
  264.  
  265.  
  266.  
  267.  
  268.  
  269.  
  270.  
  271.  
  272.   PRODUCT  :  Borland C++                           NUMBER  :  1558
  273.   VERSION  :  3.x
  274.        OS  :  DOS
  275.      DATE  :  September 1, 1993                        PAGE  :  5/6
  276.  
  277.     TITLE  :  Saving/Restoring the mouse state in Turbo Vision
  278.  
  279.  
  280.  
  281.  
  282.       static TMenuBar *initMenuBar (TRect);
  283.       static TStatusLine *initStatusLine (TRect);
  284.   };
  285.  
  286.   MouseApp::MouseApp() :
  287.       TProgInit( &MouseApp::initStatusLine,
  288.                  &MouseApp::initMenuBar,
  289.                  &MouseApp::initDeskTop
  290.                )
  291.   {
  292.   }
  293.  
  294.   void MouseApp::handleEvent (TEvent& event)
  295.   {
  296.     int type;
  297.     char s[50];
  298.  
  299.     TApplication::handleEvent (event);
  300.     if (event.what == evCommand)
  301.     {
  302.       switch (event.message.command)
  303.       {
  304.         case cmGetMouseType:
  305.           type = getMouseType();
  306.           if (type==-1)
  307.             messageBox( "Mouse Not Installed", cmOK );
  308.           else {
  309.             if ((type<0)||(type>5)) type=0;
  310.             sprintf (s, "Mouse type: %s.", mouseType[type] );
  311.             messageBox (s, cmOK);
  312.           }
  313.           clearEvent( event );
  314.           break;
  315.         default:
  316.           break;
  317.       }
  318.     }
  319.   }
  320.  
  321.   TMenuBar *MouseApp::initMenuBar (TRect r)
  322.   {
  323.     r.b.y = r.a.y+1;
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.  
  333.  
  334.  
  335.  
  336.  
  337.  
  338.   PRODUCT  :  Borland C++                           NUMBER  :  1558
  339.   VERSION  :  3.x
  340.        OS  :  DOS
  341.      DATE  :  September 1, 1993                        PAGE  :  6/6
  342.  
  343.     TITLE  :  Saving/Restoring the mouse state in Turbo Vision
  344.  
  345.  
  346.  
  347.  
  348.     return new TMenuBar (r,
  349.       *new TSubMenu ("~T~est Mouse Save", kbAltT) +
  350.       *new TMenuItem ("~G~et Mouse Type", cmGetMouseType, kbAltG)
  351.     );
  352.   }
  353.  
  354.   TStatusLine *MouseApp::initStatusLine (TRect r)
  355.   {
  356.     r.a.y = r.b.y-1;
  357.     return new TStatusLine (r,
  358.       *new TStatusDef (0, 0xFFFF) +
  359.       *new TStatusItem ("~Alt-X~ Exit", kbAltX, cmQuit) +
  360.       *new TStatusItem (0, kbF10, cmMenu)
  361.     );
  362.   }
  363.  
  364.   int main()
  365.   {
  366.     MouseApp testIt;
  367.     testIt.run();
  368.     return 0;
  369.   }
  370.  
  371.  
  372.   DISCLAIMER: You have the right to use this technical information
  373.   subject to the terms of the No-Nonsense License Statement that
  374.   you received with the Borland product to which this information
  375.   pertains.
  376.  
  377.  
  378.  
  379.  
  380.  
  381.  
  382.  
  383.  
  384.  
  385.  
  386.  
  387.  
  388.  
  389.  
  390.  
  391.  
  392.  
  393.  
  394.  
  395.  
  396.  
  397.