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

  1. EXTPROC CEnvi2
  2. /***************************************************************
  3.  *** Switch - Switch to the specified window/task.  Make any ***
  4.  *** ver.1    slow match on the window name.                 ***
  5.  ***************************************************************/
  6.  
  7. #include <PMdll.lib>
  8.  
  9. main(argc,argv)
  10. {
  11.    if ( 2 != argc  ||  !strcmp(argv[1],"/?")  ||  !stricmp(argv[1],"/help") )
  12.       Instructions();
  13.    else
  14.       // create for input folder or for current dir if no input folder
  15.       SwitchToName(argv[1]);
  16. }
  17.  
  18. SwitchToName(Name)
  19.    // this will create a list of all windows that can be switched to, and try
  20.    // to match any portion of Name with the window title
  21. {
  22.    // create list of switchable windows
  23.    SwitchList = WinQuerySwitchList(Info().hab);
  24.    assert( SwitchList != NULL );
  25.    SwitchCount = 1 + GetArraySpan(SwitchList);
  26.    // check each of those windows for title match to Name, and if so then switch
  27.    for ( ExactMatch = 0; ExactMatch < SwitchCount; ExactMatch++ ) {
  28.       if ( 0 == WinQuerySwitchEntry(SwitchList[ExactMatch],SwEntry) ) {
  29.          if ( !stricmp(Name,SwEntry.title) )
  30.             break;
  31.          // that wasn't exact, so find partial if not one alread
  32.          if ( !defined(Partial)  &&  FindNameInTitle(Name,SwEntry.title) )
  33.             PartialMatch = ExactMatch;
  34.       }
  35.    }
  36.    if ( ExactMatch < SwitchCount )
  37.       WinSwitchToProgram(SwitchList[ExactMatch]);
  38.    else if ( defined(PartialMatch) )
  39.       WinSwitchToProgram(SwitchList[PartialMatch]);
  40.    else
  41.       printf("No window task found to match \"%s\"\n",Name);
  42. }
  43.  
  44. FindNameInTitle(name,title) // if name found anywhere in title, then TRUE, else FALSE
  45. {
  46.    nameLen = strlen(name);
  47.    while( 0 != title[0] ) {
  48.       if ( !strnicmp(name,title++,nameLen) )
  49.          return TRUE;
  50.    }
  51.    return(FALSE);
  52. }
  53.  
  54. Instructions()
  55. {
  56.    printf("\n")
  57.    printf("Switch - Switch to specified task by Title name.  If an exact match\n")
  58.    printf("         is not found then tries for a partial match.\n");
  59.    printf("\n")
  60.    printf("SYNTAX: Switch TitleSpec\n")
  61.    printf("\n")
  62.    printf("Where:  TitleSpec - Full or partial title\n")
  63.    printf("\n")
  64.    printf("Examples: Switch Desktop    - Switch focus to the OS/2 desktop\n")
  65.    printf("          Switch E.EXE      - Switch to running e.exe, if there is one\n")
  66.    printf("\n")
  67. }
  68.  
  69.