home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / cenvi23.zip / WINSET.CMD < prev    next >
OS/2 REXX Batch file  |  1995-03-28  |  5KB  |  171 lines

  1. EXTPROC CEnvi2
  2. /*********************************************************
  3.  *** WinSet.cmd - CEnvi2 program to position, maximize, ***
  4.  *** ver.4        or hide a window, etc...             ***
  5.  *********************************************************/
  6.  
  7. #include <PMdll.lib>
  8. #include <WinTools.lib>
  9. #include <WinMsg.lib>
  10.  
  11. #define  NO_ERROR          0     // return code from most successful DosCalls
  12.  
  13. // Initialize an array of Commands, their functions, and how many extra
  14. // arguments they require
  15. commands = { { "MIN",      "MyMinimizeWindow",     "0" },
  16.              { "MAX",      "MyMaximizeWindow",     "0" },
  17.              { "RESTORE",  "MyRestoreWindow",      "0" },
  18.              { "HIDE",     "MyHideWindow",         "0" },
  19.              { "SHOW",     "MyShowWindow",         "0" },
  20.              { "ACTIVE",   "MyActivateWindow",     "0" },
  21.              { "INACTIVE", "MyInactivateWindow",   "0" },
  22.              { "CLOSE",    "MyClose",              "0" },
  23.              { "SIZE",     "MySizeWindow",         "2" },
  24.              { "MOVE",     "MyMoveWindow",         "2" },
  25.              { "BIGGEST",  "MakeBiggestWindow",    "0" } };
  26.  
  27. main(argc,argv)
  28. {
  29.    if ( argc < 3  ||  !strcmp(argv[1],"/?")  ||  !strcmpi(argv[1],"help") ) {
  30.       Instructions();
  31.    } else {
  32.       if ( !strcmp(argv[1],"@") )
  33.          lHwnd = Info().WinHandle;
  34.       else
  35.          lHwnd = GetHwnd(argv[1]);
  36.       if ( lHwnd ) {
  37.          if ( argc == 4  &&  !stricmp(argv[2],"TITLE") ) {
  38.             SetWindowTitle(lHwnd,argv[3]);
  39.          } else {
  40.             // find the command in list of commands we know
  41.             for ( i = GetArraySpan(commands); 0 <= i; i-- ) {
  42.                command = commands[i];
  43.                if ( !stricmp(argv[2],commands[i][0]) )
  44.                   break;
  45.             }
  46.             if ( i < 0  ||  argc != 3 + (ArgCount = atoi(command[2])) ) {
  47.                Instructions();
  48.             } else {
  49.                // send command to window
  50.                function(command[1],lHwnd,
  51.                         argv[3],argv[4],argv[5],argv[6],argv[7]);
  52.             }
  53.          }
  54.       }
  55.    }
  56. }
  57.  
  58. Instructions()
  59. {
  60.    puts("\a")
  61.    puts(`WinSet - Tell a window where to go`)
  62.    puts(``)
  63.    puts(`SYNTAX: WinSet Title MIN`)
  64.    puts(`        WinSet Title MAX`)
  65.    puts(`        WinSet Title HIDE`)
  66.    puts(`        WinSet Title SHOW`)
  67.    puts(`        WinSet Title RESTORE`)
  68.    puts(`        WinSet Title BIGGEST`)
  69.    puts(`        WinSet Title ACTIVE`)
  70.    puts(`        WinSet Title INACTIVE`)
  71.    puts(`        WinSet Title CLOSE`)
  72.    puts(`        WinSet Title SIZE Width Height`)
  73.    puts(`        WinSet Title MOVE [r]Column [t]Row`)
  74.    puts(`        WinSet Title TITLE NewTitle`)
  75.    puts(``)
  76.    puts(`   Where: Title - All or partial name of a Window.`)
  77.    puts(`          If title is @ (at) then window is this window.`)
  78.    puts(`          r - preceding Column with r relative to right edges`)
  79.    puts(`          t - preceding Row with t relative to top edges`)
  80.    puts(``)
  81.    puts(`EXAMPLE: WinSet "OS/2 Window" MOVE 300 200`)
  82.    puts(`         WinSet "Drive C" TITLE "Boot Drive"`)
  83.    puts(`         WinSet E.EXE move r10 t0`)
  84.    puts(`         WinSet @ ACTIVE`)
  85.    puts(``)
  86. }
  87.  
  88. MyMinimizeWindow(pHwnd)
  89. {
  90.    ShowWindow(pHwnd,SW_MINIMIZE);
  91. }
  92.  
  93. MyMaximizeWindow(pHwnd)
  94. {
  95.    ShowWindow(pHwnd,SW_SHOWMAXNOACTIVE);
  96. }
  97.  
  98. MyHideWindow(pHwnd)
  99. {
  100.    ShowWindow(pHwnd,SW_HIDE);
  101. }
  102.  
  103. MyShowWindow(pHwnd)
  104. {
  105.    ShowWindow(pHwnd,SW_SHOWNOACTIVATE);
  106. }
  107.  
  108. MyRestoreWindow(pHwnd)
  109. {
  110.    ShowWindow(pHwnd,SW_RESTORENOACTIVE);
  111. }
  112.  
  113. MySizeWindow(pHwnd,pWidth,pHeight)
  114. {
  115.    SetSize(pHwnd,atoi(pWidth),atoi(pHeight));
  116. }
  117.  
  118. MyMoveWindow(pHwnd,pColumn,pRow)
  119. {
  120.    GetScreenSize(ScreenWidth,ScreenHeight);
  121.    GetSize(pHwnd,lWidth,lHeight);
  122.    if ( 'r' == tolower(pColumn[0]) ) {
  123.       // move relative to right edges
  124.       lColumn = ScreenWidth - atoi(pColumn+1) - lWidth;
  125.    } else
  126.       lColumn = atoi(pColumn);
  127.    if ( 't' == tolower(pRow[0]) ) {
  128.       // move relative to top edges
  129.       lRow = ScreenHeight - atoi(pRow+1) - lHeight;
  130.    } else
  131.       lRow = atoi(pRow);
  132.    SetPosition(pHwnd,lColumn,lRow);
  133. }
  134.  
  135. MyActivateWindow(pHwnd)
  136. {
  137.    SetActiveWindow(pHwnd);
  138. }
  139.  
  140. MyInactivateWindow(pHwnd)
  141. {
  142.    SetWindowPos(pHwnd,0,0,0,0,0,SWP_DEACTIVATE);
  143. }
  144.  
  145. MyClose(pHwnd)
  146. {
  147.    #define WM_CLOSE  0x0029
  148.    #define WM_QUIT   0x002a
  149.    WinPostMsg(pHwnd,WM_CLOSE,0,0,False);
  150.    return(TRUE);
  151. }
  152.  
  153. MakeBiggestWindow(pHwnd)
  154. {
  155.    ShowWindow(pHwnd,SW_SHOWMAXNOACTIVE);
  156.    // get maximized size, then restore but at maximum size
  157.    GetWindowRect(pHwnd,rect);
  158.    ShowWindow(pHwnd,SW_RESTORENOACTIVE);
  159.    SetWindowRect(pHwnd,rect);
  160. }
  161.  
  162. GetHwnd(pWinSpec)
  163. {
  164.    // Try to find window handle, look for exact match first and then
  165.    // partial match if exact not found.  Return 0 if problem.
  166.    if ( !(lHwnd = GetWindowHandle(pWinSpec,True)) )
  167.       lHwnd = GetWindowHandle(pWinSpec);
  168.    return lHwnd;
  169. }
  170.  
  171.