home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / XMOUSE.CMD < prev   
OS/2 REXX Batch file  |  1995-04-07  |  3KB  |  92 lines

  1. @echo OFF
  2. REM ***********************************************************
  3. REM *** XMouse.cmd - Set the active window to always be the ***
  4. REM *** ver.1        one under the mouse, as in XWindows    ***
  5. REM ***********************************************************
  6.  
  7. ECHO XMouse - Set the window under the mouse as the active
  8. ECHO          window, unless the ctrl-key is pressed or
  9. ECHO          any mouse buttons are pressed, which will
  10. ECHO          temporarily de-activate XMOUSE
  11.  
  12. Start "XMouse" /N /B /WIN /MIN CEnvi2 %0.cmd %1 %2 %3 %4
  13. CEnvi2 suspend(10000); // give time to read the message
  14. GOTO CENVI_EXIT
  15.  
  16.  
  17. #include <WinTools.lib>
  18.  
  19. #define SUSPEND_TIME    333   // milliseconds between checks
  20.  
  21. // give earlier message time to display, and make myself invisible
  22. ShowWindow(Info().WinHandle,SW_HIDE);
  23. suspend(10000);
  24.  
  25. for( ; ; ) {
  26.  
  27.    suspend(SUSPEND_TIME);
  28.  
  29.    // get position of active window
  30.    if ( !(ActiveHwnd = GetActiveWindow()) ) {
  31.       WinPos.left = WinPos.right =
  32.       WinPos.top = WinPos.bottom = -1000;
  33.    } else {
  34.       GetWindowRect(ActiveHwnd,WinPos);
  35.    }
  36.  
  37.    // get position of pointer
  38.    Ptr = PointerPosition();
  39.  
  40.    // if pointer is not in currently active window then set new active
  41.    #define VK_CTRL      0x0A
  42.    #define VK_BUTTON1   0x01
  43.    #define VK_BUTTON2   0x02
  44.    #define VK_BUTTON3   0x03
  45.    if ( ( Ptr.col < WinPos.left  ||  WinPos.right < Ptr.col
  46.        || Ptr.row < WinPos.bottom  ||  WinPos.top < Ptr.row )
  47.      && !KeyPressed(VK_CTRL) && !KeyPressed(VK_BUTTON1)
  48.      && !KeyPressed(VK_BUTTON2) && !KeyPressed(VK_BUTTON3) ) {
  49.  
  50.       // go down z-order list of windows to find the first one
  51.       // containing this pointer, then make it active
  52.       lEnum = WinBeginEnumWindows(HWND_DESKTOP);
  53.       while ( lChild = WinGetNextWindow(lEnum) ) {
  54.          if ( IsVisible(lChild) ) {
  55.             GetWindowRect(lChild,WinPos);
  56.             if ( WinPos.left <= Ptr.col  &&  Ptr.col <= WinPos.right
  57.               && WinPos.bottom <= Ptr.row  &&  Ptr.row <= WinPos.top ) {
  58.                // don't accept this window if it is last in z-order (i.e., desktop)
  59.                if ( WinGetNextWindow(lEnum) )
  60.                   SetActiveWindow(lChild);
  61.                break;
  62.             }
  63.          }
  64.       }
  65.       WinEndEnumWindows(lEnum);
  66.    }
  67. }
  68.  
  69.  
  70.  
  71. PointerPosition() // return current cursor position in screen coordinates
  72. {                 // structure elements returned are .col and .row
  73.    #define ORD_WIN32QUERYPOINTERPOS 823
  74.    BLObSize(pointer,4 * 2);
  75.    DynamicLink("PMWIN",ORD_WIN32QUERYPOINTERPOS,BIT32,CDECL,
  76.                HWND_DESKTOP,pointer);
  77.    position.col = BLObGet(pointer,0,SWORD16);
  78.    position.row = BLObGet(pointer,4,SWORD16);
  79.    return(position);
  80. }
  81.  
  82. KeyPressed(pKey)  // return boolen TRUE if keypressed now, else FALSE
  83. {
  84.    #define ORD_WIN32SETKEYBOARDSTATETABLE   921
  85.    _table[255] = '\0';   // initialize 256-byte key table
  86.    DynamicLink("PMWIN",ORD_WIN32SETKEYBOARDSTATETABLE,BIT32,CDECL,
  87.                HWND_DESKTOP,_table,FALSE);
  88.    return( 0x80 & _table[pKey] );
  89. }
  90.  
  91. :CENVI_EXIT
  92.