home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 035 / cenvi29.zip / MINITEMP.CMD < prev    next >
OS/2 REXX Batch file  |  1994-06-09  |  4KB  |  115 lines

  1. @echo off
  2. // *******************************************************
  3. // *** MiniTemp.cmd - Temporarily minimize all windows ***
  4. // *** ver.1          until a new window is selected   ***
  5. // *******************************************************
  6.  
  7. ECHO MiniTemp.cmd - This will minimize all windows whenever
  8. ECHO                you hold CTRL-DOWN (control key and the
  9. ECHO                down arrow) until a new window is selected.
  10.  
  11. start "MiniTemp" /N CEnvi.exe %0.cmd
  12. GOTO CENVI_EXIT
  13.  
  14. #define KEY_CHECK_INTERVAL  1000  // approx. milliseconds between check for ctrl-tab
  15. #define ACTIVE_WIN_INTERVAL 300   // wait for a new window to become active
  16.  
  17. #include <WinTools.lib>
  18.  
  19. // hide this window
  20. ShowWindow(Info().WinHandle,SW_HIDE);
  21.  
  22. while ( True ) {
  23.    WaitForKeys(True);
  24.    DosBeep(880,10);
  25.    DesktopWindow = MinimizeAllWindows(MinList,MinCount);
  26.    if ( MinCount ) {
  27.  
  28.       // wait for new window to become active
  29.       while ( (lActiveWindow = GetActiveWindow()) == DesktopWindow )
  30.          suspend(ACTIVE_WIN_INTERVAL);
  31.  
  32.  
  33.       // restore all of the windows
  34.       RestoreAllWindows(MinList,MinCount,lActiveWindow);
  35.  
  36.    }
  37.    WaitForKeys(False);
  38. }
  39.  
  40. MinimizeAllWindows(pMinList,pMinCount)
  41.    // minimize all windows, save whether maximized
  42. {
  43.    pMinCount = 0;
  44.    lEnum = WinBeginEnumWindows(HWND_DESKTOP);
  45.    while ( lChild = WinGetNextWindow(lEnum) ) {
  46.       if ( IsVisible(lChild) && !IsMinimized(lChild) ) {
  47.          pMinList[pMinCount].Handle = lChild;
  48.          if ( pMinList[pMinCount].Maximized = IsMaximized(lChild) ) {
  49.             GetPosition(lChild,pMinList[pMinCount].col,pMinList[pMinCount].row);
  50.          }
  51.          pMinCount++;
  52.       }
  53.    }
  54.    WinEndEnumWindows(lEnum);
  55.    if ( pMinCount < 2 ) {
  56.       pMinCount = 0;
  57.       return NULL;
  58.    }
  59.  
  60.    // the last window is desktop, and so skip this one
  61.    lDesktopWindow = pMinList[--pMinCount].Handle;
  62.    SetActiveWindow(lDesktopWindow);
  63.  
  64.    // minimize all those windows in this list, in reverse order
  65.    for ( lIdx = pMinCount; 0 < lIdx--; ) {
  66.       ShowWindow(pMinList[lIdx].Handle,SW_SHOWMINNOACTIVE);
  67.    }
  68.  
  69.    return lDesktopWindow;
  70. }
  71.  
  72. RestoreAllWindows(pMinList,pMinCount,pActiveWindow)
  73. {
  74.    for ( lIdx = pMinCount; 0 < lIdx--; ) {
  75.       if ( pMinList[lIdx].Maximized ) {
  76.          ShowWindow(pMinList[lIdx].Handle,SW_SHOWMAXNOACTIVE);
  77.          SetPosition(pMinList[lIdx].Handle,pMinList[lIdx].col,pMinList[lIdx].row);
  78.       } else {
  79.          ShowWindow(pMinList[lIdx].Handle,SW_RESTORENOACTIVE);
  80.       }
  81.    }
  82.    SetActiveWindow(pActiveWindow);
  83. }
  84.  
  85. WaitForKeys(pDown) // wait for keys to be held
  86. {
  87.    #define VK_DOWN      0x18
  88.    #define VK_CTRL      0x0A
  89.    // first wait for keys to not all be down before continuing
  90.    if ( pDown ) {
  91.       while ( !KeyPressed(VK_DOWN)  ||  !KeyPressed(VK_CTRL) )
  92.          suspend( KEY_CHECK_INTERVAL );
  93.    } else {
  94.       while ( KeyPressed(VK_DOWN)  &&  KeyPressed(VK_CTRL) )
  95.          suspend( KEY_CHECK_INTERVAL );
  96.    }
  97. }
  98.  
  99. KeyPressed(pKey)  // return boolen TRUE if keypressed now, else FALSE
  100. {
  101.    #define ORD_WIN32SETKEYBOARDSTATETABLE   921
  102.    lTable[255] = '\0';   // initialize 256-byte key table
  103.    DynamicLink("PMWIN",ORD_WIN32SETKEYBOARDSTATETABLE,BIT32,CDECL,
  104.                HWND_DESKTOP,lTable,FALSE);
  105.    return( 0x80 & lTable[pKey] );
  106. }
  107.  
  108. DosBeep(Frequency,Duration)   // play specified Frequency, in Hz, for specified
  109. {                             // duration, in milliseconds
  110.    #define ORD_DOS32BEEP   286
  111.    return DynamicLink("doscalls",ORD_DOS32BEEP,BIT32,CDECL,Frequency,Duration)
  112. }
  113.  
  114. :CENVI_EXIT
  115.