home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / RNDBCKGR.CMD < prev    next >
OS/2 REXX Batch file  |  1994-10-04  |  3KB  |  97 lines

  1. @echo off
  2. REM ***********************************************************************
  3. REM *** RndBckgr.cmd: Background Randomizer.  Randomize the background  ***
  4. REM *** ver.1         of the desktop.  This runs at low-priority and so ***
  5. REM ***               its timing for new backgrounds is not accurate.   ***
  6. REM ***********************************************************************
  7. start "Background Randomizer" /N /B /WIN /MIN CEnvi2 %0.cmd
  8. GOTO CENVI_EXIT
  9.  
  10. #define  REPEAT_MINUTE_INTERVAL      3  // minutes between changes
  11.  
  12. // Define desktop settings that deviate from the default so that when
  13. // the new desktop image is given it does not change your other
  14. // desktop settings
  15. OtherDesktopSettings = "ICONVIEW=NONFLOWED,MINI;"
  16.  
  17. // Define full filespecs. for where all the random images may be found
  18. ImagesSpecs = { `C:\OS2\BITMAP\*.BMP` ,
  19.                 `C:\OS2\BITMAP\*.BGA` ,
  20.                 `E:\Personal\Images\*.bmp` ,
  21.                 `D:\WIN\*.BMP` };
  22.  
  23.  
  24. // Build an array of ALL files that match the above file specs
  25. FileCount = BuildFileList(FileList);
  26. if ( FileCount < 2 ) {
  27.    printf("\aNot enough files chosen for randomizing.\n");
  28.    printf("Press any key to exit...\n");
  29.    exit(1);
  30. }
  31.  
  32. // Hide this program
  33. system("WinSet \"Background Randomizer\" HIDE");
  34.  
  35. // Make this task run only in the background
  36. // REDUCE PRIORITY OF THIS PROCESS TO IDLETIME
  37. #define ORD_DOS32SETPRIORITY     236
  38. #define PRTYC_IDLETIME     1  // set to idletime priority
  39. DynamicLink("doscalls",ORD_DOS32SETPRIORITY,BIT32,CDECL,
  40.             0/*all threads*/,PRTYC_IDLETIME/*idletime*/,
  41.             0,0/*current process*/)
  42.  
  43. // initialize the random number gererator
  44. srand();
  45.  
  46. // Loop forever, picking new screens
  47. for ( NewChoice = -1; ; suspend(REPEAT_MINUTE_INTERVAL * 60 * 1000) ) {
  48.  
  49.    // choose the next random screen to display
  50.    PreviousChoice = NewChoice;
  51.    do {
  52.       NewChoice = rand() % FileCount;
  53.    } while( PreviousChoice == NewChoice ); // don't want same choice repeated
  54.  
  55.    // get the desktop object
  56.    if ( NULL != (DesktopObject = WinQueryObject("<WP_DESKTOP>")) ) {
  57.  
  58.       // build setup string, and give to dekstop object
  59.       printf("Display \"%s\"\n",FileList[NewChoice]);
  60.       sprintf(SetupString,"BACKGROUND=%s;%s;",FileList[NewChoice],
  61.               OtherDesktopSettings);
  62.       WinSetObjectData(DesktopObject,SetupString);
  63.  
  64.    }
  65.  
  66. }
  67.  
  68.  
  69. BuildFileList(FileList) {
  70.    count = 0;
  71.    for ( Spec = GetArraySpan(ImagesSpecs); 0 <= Spec; Spec-- ) {
  72.       if ( (SubList = Directory(ImagesSpecs[Spec])) ) {
  73.          // add all of the files in SubList onto FileList
  74.          for ( Sub = GetArraySpan(SubList); 0 <= Sub; Sub-- ) {
  75.             FileList[count++] = SubList[Sub].name;
  76.             printf("File choice %d = \"%s\"\n",count,FileList[count-1]);
  77.          }
  78.       }
  79.    }
  80.    return(count);
  81. }
  82.  
  83. WinQueryObject(ObjectID) // called by above code
  84. {
  85.    #define ORD_WINQUERYOBJECT    252
  86.    return DynamicLink("PMWP",ORD_WINQUERYOBJECT,BIT32,CDECL,ObjectID);
  87. }
  88.  
  89. WinSetObjectData(WPObjectHandle,SetupString) // called by above code
  90. {
  91.    #define ORD_WINSETOBJECTDATA  250
  92.    return DynamicLink("PMWP",ORD_WINSETOBJECTDATA,BIT32,CDECL,
  93.                         WPObjectHandle,SetupString)
  94. }
  95.  
  96. :CENVI_EXIT
  97.