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

  1. EXTPROC CEnvi
  2. //****************************************************************
  3. //*** TempFldr.cmd - CEnvi script to open a folder and keep it ***
  4. //*** ver.3          open only as long as it is the active     ***
  5. //***                window.                                   ***
  6. //****************************************************************
  7.  
  8. #include <PMdll.lib>
  9. #include <WinTools.lib>
  10. #include <WinMsg.lib>
  11.  
  12. // define how many milliseconds to wait between each check to see
  13. // when the folder no longer has the focus
  14. #define WAIT_BETWEEN_CHECKS  1000
  15.  
  16. // define how long between checks for new window when the
  17. // folder is starting up, and how many times to look for it
  18. #define DELAY_LOOK_FOR_FOLDER 400   // milliseconds
  19. #define LOOK_FOR_FOLDER_COUNT 25
  20.  
  21. // #define the type of view the opened windows should have.
  22. // note that DEFAULT won't work if you set this as the
  23. // default action for a folder.  So remove comment from ONLY
  24. // ONE of the following
  25. #define OPEN_MODE "ICON"
  26. // #define OPEN_MODE "TREE"
  27. // #define OPEN_MODE "DETAILS"
  28. // #define OPEN_MODE "DEFAULT"
  29.  
  30. // Check if ESCAPE key was pressed when this is invoked
  31. #define VK_ESC 0x0F
  32. EscapePressed = KeyPressed(VK_ESC);
  33.  
  34. main(argc,argv)
  35. {
  36.    if ( argc != 2 )
  37.       Instructions();
  38.  
  39.    // Hide this TempFldr window because it's in the way.  If you
  40.    // don't want to bother to hide it then comment-out the
  41.    // following line
  42.    ShowWindow(Info().WinHandle,SW_HIDE);
  43.  
  44.    // build list of existing windows, to find the new one
  45.    WindowList = BuildWindowList();
  46.  
  47.    // Open the folder
  48.    StartFolderObject(argv[1]);
  49.  
  50.    // Get the handle of the new folder
  51.    FolderWindowHandle = GetNewWindowHandle(WindowList);
  52.  
  53.    // Give this new window the active focus
  54.    if ( FolderWindowHandle != GetActiveWindow() )
  55.       SetActiveWindow(FolderWindowHandle);
  56.  
  57.    // If escape was pressed, then just keep standard folder
  58.    // behavior, and so exit now
  59.    if ( EscapePressed )
  60.       exit(EXIT_SUCCESS);
  61.  
  62.    // Wait until this folder no longer has the focus, and
  63.    // then close it
  64.    while ( FolderWindowHandle == GetActiveWindow() )
  65.       suspend(WAIT_BETWEEN_CHECKS);
  66.  
  67.    #define WM_CLOSE  0x0029
  68.    WinPostMsg(FolderWindowHandle,WM_CLOSE,0,0,False);
  69.  
  70.    return(EXIT_SUCCESS);
  71. }
  72.  
  73. Instructions()
  74. {
  75.    printf("\a\n")
  76.    printf("TempFldr - Open a temporary folder\n")
  77.    printf("\n")
  78.    printf("SYNTAX: TempFldr <FolderName>\n");
  79.    printf("\n");
  80.    printf("USAGE: Use TempFldr to open a folder that will\n")
  81.    printf("       automatically close when it no longer\n")
  82.    printf("       has focus. If ESCAPE is pressed while\n")
  83.    printf("       the folder is opened then will open as\n")
  84.    printf("       a regular folder.\n")
  85.    printf("\n")
  86.    printf("       Edit TempFldr.cmd to change settings to\n")
  87.    printf("       your liking. /BIND to make it work faster.\n")
  88.    printf("\n")
  89.    exit(EXIT_FAILURE);
  90. }
  91.  
  92. StartFolderObject(FolderName)
  93. {
  94.    lSetupString = "OPEN=" OPEN_MODE ";"
  95.    if ( !(lObject = WinQueryObject(FolderName)) ) {
  96.       printf("Error: can't find \"%s\"\a\a\n",FolderName);
  97.       exit(EXIT_FAILURE);
  98.    }
  99.    if ( !WinSetObjectData(lObject,lSetupString) ) {
  100.       printf("Error: can't open \"%s\"\a\a\n",FolderName);
  101.       exit(EXIT_FAILURE);
  102.    }
  103. }
  104.  
  105. BuildWindowList() // return array of existing window handles
  106. {
  107.    lCount = 0;
  108.    lEnum = WinBeginEnumWindows(HWND_DESKTOP);
  109.    while ( lChild = WinGetNextWindow(lEnum) )
  110.       lWindowArray[lCount++] = lChild;
  111.    WinEndEnumWindows(lEnum);
  112.    return lWindowArray;
  113. }
  114.  
  115. GetNewWindowHandle(pOldHandles)
  116. {
  117.    lOldHandleCount = 1 + GetArraySpan(pOldHandles);
  118.    for ( i = 0; i < LOOK_FOR_FOLDER_COUNT; i++ ) {
  119.       lEnum = WinBeginEnumWindows(HWND_DESKTOP);
  120.       while ( lChild = WinGetNextWindow(lEnum) ) {
  121.          for ( lOldIdx = 0; lOldIdx < lOldHandleCount; lOldIdx++ ) {
  122.             if ( lChild == pOldHandles[lOldIdx] )
  123.                break;
  124.          }
  125.          if ( lOldIdx == lOldHandleCount
  126.            && lChild != PMInfo().WinHandle ) {
  127.             WinEndEnumWindows(lEnum);
  128.             return(lChild);
  129.          }
  130.       }
  131.       suspend(DELAY_LOOK_FOR_FOLDER);
  132.    }
  133.  
  134.    // didn't find the folder
  135.    printf("\aCould not find folder\a\n");
  136.    exit(EXIT_FAILURE);
  137. }
  138.  
  139. KeyPressed(pKey)  // return boolen TRUE if keypressed now, else FALSE
  140. {
  141.    #define ORD_WIN32SETKEYBOARDSTATETABLE   921
  142.    _table[255] = '\0';   // initialize 256-byte key table
  143.    DynamicLink("PMWIN",ORD_WIN32SETKEYBOARDSTATETABLE,BIT32,CDECL,
  144.                HWND_DESKTOP,_table,FALSE);
  145.    return( 0x80 & _table[pKey] );
  146. }
  147.  
  148.