home *** CD-ROM | disk | FTP | other *** search
- EXTPROC CEnvi
- /**************************************************************
- *** Bouncy.cmd - Start a bouncy OS/2 Command Window. This ***
- *** ver.1 demonstrates moving windows, embedding ***
- *** multiple Cmm executables within one file, ***
- *** passing keystrokes, clipboard use, and ***
- *** silliness. ***
- **************************************************************/
-
- #include <PMdll.lib>
-
- // Spawn a copy of the command processor, so that all looks normal
- CmdChildID = spawn(P_NOWAIT,defined(OS2_SHELL) ? OS2_SHELL : "CMD.EXE" );
-
- ForeverBounce(CmdChildID);
-
-
- #define DELAY_BETWEEN_MOVEMENTS 100 // in milliseconds
- #define COL_AVERAGE_MOVE 4 // average column movement
- #define ROW_AVERAGE_MOVE 4 // average row movement
- #define COL_RANDOM_DELTA 2 // allowed change from average move to
- #define ROW_RANDOM_DELTA 2 // randomize the bounces
-
-
- ForeverBounce(ChildProcessID) // bounce forever and ever while CMD runs
- {
- // // INCREASE PRIORITY OF THIS PROCESS
- // #define ORD_DOS32SETPRIORITY 236
- // #define PRTYC_TIMECRITICAL 3 // very high priority
- // DynamicLink("doscalls",ORD_DOS32SETPRIORITY,BIT32,CDECL,
- // 0/*all threads*/,PRTYC_TIMECRITICAL/*idletime*/,
- // 0/*no process change at new level*/,0/*current process*/)
-
- // Get the dimensions of the desktop
- #define HWND_DESKTOP 1
- GetWindowPosition(HWND_DESKTOP,Col,Row,DeskWidth,DeskHeight);
-
- // Get initial position of the Bouncy Window
- GetWindowPosition(Info().WinHandle,Col,Row,Width,Height);
-
- // determine maximum and minimum values for Col and Row
- MinCol = 0;
- MinRow = 0;
- MaxCol = DeskWidth - Width;
- MaxRow = DeskHeight - Height;
-
- // start random direction and delta
- srand();
- ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,rand() & 1);
- RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,rand() & 1);
-
- // Finally, keep bouncing the window around at every interval
- while ( ValidProcessID(ChildProcessID) ) {
-
- // move window to new Row and Col position
- MoveWindow(Info().WinHandle,Col += ColSpeed,Row += RowSpeed);
-
- // check if needs to bounce back to to hitting desktop edge
- if ( ColSpeed < 0 ) {
- if ( Col < MinCol )
- BouncyBeep(),
- ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,TRUE);
- } else {
- if ( MaxCol < Col )
- BouncyBeep(),
- ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,FALSE);
- }
- if ( RowSpeed < 0 ) {
- if ( Row < MinRow )
- BouncyBeep(),
- RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,TRUE);
- } else {
- if ( MaxRow < Row )
- BouncyBeep(),
- RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,FALSE);
- }
-
- suspend(DELAY_BETWEEN_MOVEMENTS);
- }
- }
-
- GetRandomSpeed(average,deviation,positive) // if not positive then negative
- {
- // get a random deviation from average
- deviate = (rand() % (2*deviation + 1)) - deviation;
-
- if ( positive )
- return( average + deviate );
- else
- return( -average - deviate );
- }
-
- GetWindowPosition(hwnd,Col,Row,Width,Height)
- {
- #define SWP_BLOB_SIZE 9 * 4
- BLObSize(swp,SWP_BLOB_SIZE);
- #define ORD_WIN32QUERYWINDOWPOS 837
- if !DynamicLink("PMWIN",ORD_WIN32QUERYWINDOWPOS,BIT32,CDECL,hwnd,swp)
- exit(1);
- Height = BLObGet(swp,4,SWORD32);
- Width = BLObGet(swp,8,SWORD32);
- Row = BLObGet(swp,12,SWORD32);
- Col = BLObGet(swp,16,SWORD32);
- }
-
- MoveWindow(hwnd,col,row)
- {
- #define ORD_WIN32SETWINDOWPOS 875
- #define SWP_MOVE 0x0002
- #define SWP_NOADJUST 0x0040
- PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
- hwnd,0,col,row,0,0,SWP_MOVE | SWP_NOADJUST);
- }
-
- ValidProcessID(id) // return TRUE if this ID is OK
- {
- if ( pList = ProcessList(False) ) {
- for ( li = GetArraySpan(pList); 0 <= li; li-- ) {
- if ( id == pList[li].id )
- return(True);
- }
- }
- return False;
- }
-
- BouncyBeep()
- {
- #define ORD_DOS32BEEP 286
- DynamicLink("doscalls",ORD_DOS32BEEP,BIT32,CDECL,400,5)
- }
-