home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / BOUNCY.CMD < prev    next >
OS/2 REXX Batch file  |  1995-01-20  |  5KB  |  141 lines

  1. EXTPROC CEnvi2
  2. /**************************************************************
  3.  *** Bouncy.cmd - Start a bouncy OS/2 Command Window. This  ***
  4.  *** ver.1        demonstrates moving windows, embedding    ***
  5.  ***              multiple Cmm executables within one file, ***
  6.  ***              passing keystrokes, clipboard use, and    ***
  7.  ***              silliness.                                ***
  8.  **************************************************************/
  9.  
  10. #include <PMdll.lib>
  11.  
  12. main()
  13. {
  14.    // Spawn a copy of the command processor, so that all looks normal
  15.    CmdChildID = spawn(P_NOWAIT,defined(OS2_SHELL) ? OS2_SHELL : "CMD.EXE" );
  16.  
  17.    ForeverBounce(CmdChildID);
  18. }
  19.  
  20.  
  21. #define  DELAY_BETWEEN_MOVEMENTS   100 // in milliseconds
  22. #define  COL_AVERAGE_MOVE  4           // average column movement
  23. #define  ROW_AVERAGE_MOVE  4           // average row movement
  24. #define  COL_RANDOM_DELTA  2           // allowed change from average move to
  25. #define  ROW_RANDOM_DELTA  2           // randomize the bounces
  26.  
  27.  
  28. ForeverBounce(ChildProcessID)   // bounce forever and ever while CMD runs
  29. {
  30.    // // INCREASE PRIORITY OF THIS PROCESS
  31.    // #define ORD_DOS32SETPRIORITY     236
  32.    // #define PRTYC_TIMECRITICAL 3     // very high priority
  33.    // DynamicLink("doscalls",ORD_DOS32SETPRIORITY,BIT32,CDECL,
  34.    //             0/*all threads*/,PRTYC_TIMECRITICAL/*idletime*/,
  35.    //             0/*no process change at new level*/,0/*current process*/)
  36.  
  37.    // Get the dimensions of the desktop
  38.    #define HWND_DESKTOP 1
  39.    GetWindowPosition(HWND_DESKTOP,Col,Row,DeskWidth,DeskHeight);
  40.  
  41.    // Get initial position of the Bouncy Window
  42.    GetWindowPosition(Info().WinHandle,Col,Row,Width,Height);
  43.  
  44.    // determine maximum and minimum values for Col and Row
  45.    MinCol = 0;
  46.    MinRow = 0;
  47.    MaxCol = DeskWidth - Width;
  48.    MaxRow = DeskHeight - Height;
  49.  
  50.    // start random direction and delta
  51.    srand();
  52.    ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,rand() & 1);
  53.    RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,rand() & 1);
  54.  
  55.    // Finally, keep bouncing the window around at every interval
  56.    while ( ValidProcessID(ChildProcessID) ) {
  57.  
  58.       // move window to new Row and Col position
  59.       MoveWindow(Info().WinHandle,Col += ColSpeed,Row += RowSpeed);
  60.  
  61.       // check if needs to bounce back to to hitting desktop edge
  62.       if ( ColSpeed < 0 ) {
  63.          if ( Col < MinCol )
  64.             BouncyBeep(),
  65.             ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,TRUE);
  66.       } else {
  67.          if ( MaxCol < Col )
  68.             BouncyBeep(),
  69.             ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,FALSE);
  70.       }
  71.       if ( RowSpeed < 0 ) {
  72.          if ( Row < MinRow )
  73.             BouncyBeep(),
  74.             RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,TRUE);
  75.       } else {
  76.          if ( MaxRow < Row )
  77.             BouncyBeep(),
  78.             RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,FALSE);
  79.       }
  80.  
  81.       suspend(DELAY_BETWEEN_MOVEMENTS);
  82.    }
  83. }
  84.  
  85. GetRandomSpeed(average,deviation,positive) // if not positive then negative
  86. {
  87.    // get a random deviation from average
  88.    deviate = (rand() % (2*deviation + 1)) - deviation;
  89.  
  90.    if ( positive )
  91.       return( average + deviate );
  92.    else
  93.       return( -average - deviate );
  94. }
  95.  
  96. gSWP._fl = UWORD32;
  97. gSWP.Height = SWORD32;
  98. gSWP.Width = SWORD32;
  99. gSWP.Row = SWORD32;
  100. gSWP.Col = SWORD32;
  101. gSWP._Behind = UWORD32;
  102. gSWP._hwnd = UWORD32;
  103. gSWP._res1 = UWORD32;
  104. gSWP._res2 = UWORD32;
  105.  
  106. GetWindowPosition(pHwnd,pCol,pRow,pWidth,pHeight)
  107. {
  108.    #define ORD_WIN32QUERYWINDOWPOS  837
  109.    if !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,pHwnd,gSWP,lSwp)
  110.       exit(1);
  111.    pHeight = lSwp.Height;  pWidth = lSwp.Width;
  112.    pRow = lSwp.Row;        pCol = lSwp.Col;
  113. }
  114.  
  115. MoveWindow(hwnd,col,row)
  116. {
  117.    #define ORD_WIN32SETWINDOWPOS 875
  118.    #define SWP_MOVE              0x0002
  119.    #define SWP_NOADJUST          0x0040
  120.    PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
  121.                  hwnd,0,col,row,0,0,SWP_MOVE | SWP_NOADJUST);
  122. }
  123.  
  124. ValidProcessID(id)   // return TRUE if this ID is OK
  125. {
  126.    if ( pList = ProcessList(False) ) {
  127.       for ( li = GetArraySpan(pList); 0 <= li; li-- ) {
  128.          if ( id == pList[li].id )
  129.             return(True);
  130.       }
  131.    }
  132.    return False;
  133. }
  134.  
  135. BouncyBeep()
  136. {
  137.    #define ORD_DOS32BEEP   286
  138.    DynamicLink("doscalls",ORD_DOS32BEEP,BIT32,CDECL,400,5)
  139. }
  140.  
  141.