home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PsL Monthly 1994 February
/
psl_9403.zip
/
psl_9403
/
DOS
/
UT_SYSTM
/
CENVI2.ZIP
/
BOUNCY.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1993-10-29
|
6KB
|
167 lines
EXTPROC CEnvi
/**************************************************************
*** Bouncy.cmd - Start a bouncy OS/2 Command Window. This ***
*** demonstrates moving windows, embedding ***
*** multiple Cmm executables within one file, ***
*** passing keystrokes, clipboard use, and ***
*** silliness. ***
**************************************************************/
#include <KeyPush.lib>
#include <ClipBrd.lib>
#include <PMdll.lib>
BouncyWindowName = "Bouncy OS/2 Window";
main(argc,argv)
{
// Start a different command session
system("start \"%s\" /F /WIN /K mode 80,25",BouncyWindowName);
// Send Keystrokes to that session for smallest font
KeyStroke(VK_ALT);
KeyStroke('f');
KeyStroke(VK_HOME);
KeyStroke(VK_ENTER);
// Tell window to clear screen by sending that command from the clipboard
PutClipboardData("cls\r",4,CF_TEXT);
KeyStroke(VK_ALT);
KeyStroke('p');
// Start the resident portion of this program, telling it the
// Window handle to control
system("start \"Bouncy Boss\" /N /B /WIN /MIN CEnvi #include '%s,,,/*RESIDENT*/' Forever(%d)",
argv[0],GetWindowHandle(BouncyWindowName));
}
GetWindowHandle(WindowName)
{
// build list of all window titles
SwitchList = WinQuerySwitchList(PMInfo().hab);
for ( i = GetArraySpan(SwitchList); 0 <= i; i-- ) {
if ( 0 == WinQuerySwitchEntry(SwitchList[i],SwEntry) ) {
if ( !strcmp(WindowName,SwEntry.title) )
return(SwEntry.hwnd);
}
}
// if made it here then window not found, so exit
exit(1);
}
/*Resident*/
/***********************************************************
*** Code below this section becomes resident and hidden ***
***********************************************************/
#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
Forever(WindowHandle) // while Bouncy window is valid, move the window around
{
// Hide this resident window
HideWindow(Info().WinHandle);
// // 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(WindowHandle,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 ( WinIsWindow(WindowHandle) ) {
// move window to new Row and Col position
MoveWindow(WindowHandle,Col += ColSpeed,Row += RowSpeed);
// check if needs to bounce back to to hitting desktop edge
if ( ColSpeed < 0 ) {
if ( Col < MinCol )
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,TRUE);
} else {
if ( MaxCol < Col )
ColSpeed = GetRandomSpeed(COL_AVERAGE_MOVE,COL_RANDOM_DELTA,FALSE);
}
if ( RowSpeed < 0 ) {
if ( Row < MinRow )
RowSpeed = GetRandomSpeed(ROW_AVERAGE_MOVE,ROW_RANDOM_DELTA,TRUE);
} else {
if ( MaxRow < Row )
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 );
}
WinIsWindow(hwnd) // return TRUE if this is still a valid window
{
#define ORD_WIN32ISWINDOW 772
return PMDynamicLink("PMWIN",ORD_WIN32ISWINDOW,BIT32,CDECL,PMInfo().hab,hwnd)
}
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);
}
HideWindow(hwnd)
{
#define ORD_WIN32SETWINDOWPOS 875
#define SWP_HIDE 0x0010
PMDynamicLink("PMWIN",ORD_WIN32SETWINDOWPOS,BIT32,CDECL,
hwnd,0,0,0,0,0,SWP_HIDE);
}