home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / setwin.zip / SETWIN.C < prev    next >
Text File  |  1994-02-20  |  6KB  |  154 lines

  1. /*****************************************************************************
  2.     TITLE:      SetWin.C
  3.     AUTHOR:     Michael Thompson (Graduate Software)
  4.     CIS ID:     76500,2037
  5.     DATE:       02-20-1994
  6.     VERSION:    1.1
  7.     
  8.     One of the major deficiencies in OS/2's windowed command prompts has 
  9.     been the lack of commands to allow the window to be sized and moved 
  10.     from the command line, or batch procedures.  This program overcomes
  11.     this restriction, albeit, in a kludgy sort of way.  
  12.     
  13.     The main kludge in this program is caused by the fact that I could not
  14.     find a way to write a VIO program which has access to the necessary 
  15.     Win functions to perform the desired sizing and moving functions.
  16.     For this, it seems one needs a message queue, and the use of a
  17.     message queue is only valid when the program is linked as PM.  A PM 
  18.     program tells the command processor to minimize itself after the
  19.     program starts, so it is not acceptable as the solution.  The way
  20.     I got around the problem was to have two programs, a VIO program
  21.     which determines the PID of the windowed command prompt, and a PM
  22.     program, which is detached by the VIO program, to perform the Win
  23.     functions to move and size.  If anyone can think of a better way
  24.     to get around this apparent problem, please feel free to do so, or
  25.     e-mail me with your idea.
  26.     
  27.     I release this program into the public domain in the hope that this 
  28.     functionality eventually makes its way into IBM's command processor.
  29.     
  30.     ----  Maybe this will eventually make it onto Hobbes CD-ROM!!  ----
  31.     ----  That would be an honor.                                  ----        
  32.  
  33.     Other enhancements to consider:
  34.         Selection of windowed session font
  35.         Screen print of windowed session
  36.         
  37.         
  38.     REVISIONS:    
  39.     
  40.     Version 1.0   02-19-94
  41.     
  42.         Initial release.
  43.     
  44.     Version 1.1   02-20-94
  45.     
  46.         Removed SLEEP from SetWin.C.
  47.         Added ability to combine multiple actions.
  48.         Added ACTIVATE DEACTIVATE TOP BOTTOM SLEEP to actions.
  49.         Removed MOVESIZE action.
  50.         Added example usage to Read.ME.
  51.         
  52. *****************************************************************************/
  53.  
  54. #define INCL_DOS
  55. #define INCL_WIN
  56.  
  57. #include <os2.h>
  58. #include <stdio.h>
  59. #include <stdlib.h>
  60. #include <string.h>
  61.  
  62. int main(void)
  63.     {
  64.     CHAR CommandLine[512];
  65.     HSWITCH SwitchHandle;
  66.     SWCNTRL SwitchData;
  67.     PPIB ProcessInfo;
  68.     PTIB ThreadInfo;
  69.     CHAR *Arguments;
  70.     PID ParentPID;
  71.     
  72.     /**********************************************************
  73.         Get the process id for the parent process to this
  74.         program.  If this program is run from the command
  75.         line, then the parent PID will be that of CMD.EXE.
  76.     **********************************************************/
  77.         DosGetInfoBlocks(&ThreadInfo,&ProcessInfo);
  78.         ParentPID=ProcessInfo->pib_ulppid;
  79.  
  80.     /**********************************************************
  81.         Get the pointer to the command line and skip the 
  82.         executable name at the start.  The arguments to
  83.         this program will be passed "as is" to the SetWinPM
  84.         program.
  85.     **********************************************************/
  86.         Arguments=ProcessInfo->pib_pchcmd;
  87.         Arguments+=strlen(Arguments)+1;
  88.         while(*Arguments==' ')
  89.             Arguments++;
  90.  
  91.     /**********************************************************
  92.         Display help if no options were specified.
  93.     **********************************************************/
  94.         if(*Arguments==0) {
  95.             printf("\n");
  96.             printf("Syntax:  SETWIN action [params]\n\n");
  97.             printf("Valid Actions:\n\n");
  98.             printf("    MINIMIZE\n");
  99.             printf("    MAXIMIZE\n");
  100.             printf("    RESTORE\n");
  101.             printf("    HIDE\n");
  102.             printf("    SHOW\n");
  103.             printf("    MOVE x y\n");
  104.             printf("    SIZE w h\n");
  105.             printf("    FLASHON\n");
  106.             printf("    FLASHOFF\n");
  107.             printf("    ACTIVATE\n");
  108.             printf("    DEACTIVATE\n");
  109.             printf("    TOP\n");
  110.             printf("    BOTTOM\n");
  111.             printf("    SLEEP ms\n");
  112.             printf("\n");
  113.             return 0;
  114.         }
  115.         
  116.     /**********************************************************
  117.         Locate the parent's PID in the switch list.  This
  118.         program will terminate if there is no entry in the 
  119.         switch list for the parent process.
  120.     **********************************************************/
  121.         SwitchHandle=WinQuerySwitchHandle(NULLHANDLE,ParentPID);
  122.         if(SwitchHandle==NULLHANDLE) {
  123.             printf("No switch list entry for the parent process.\n");
  124.             return 0;
  125.         }
  126.         
  127.     /**********************************************************
  128.         Determine the window handle associated with the 
  129.         parent process.  This program will terminate if 
  130.         there is no window associated with the parent 
  131.         process.
  132.     **********************************************************/
  133.         WinQuerySwitchEntry(SwitchHandle,&SwitchData);
  134.         if(SwitchData.hwnd==NULLHANDLE) {
  135.             printf("No window associated with the parent process.\n");
  136.             return 0;
  137.         }
  138.         
  139.     /**********************************************************
  140.         Build the command line for the SetWinPM program.
  141.         The first parameter passed is the window handle.
  142.         The remaining parameters are the arguments passed
  143.         to this program.  The SetWinPM program is detached
  144.         so that window size changes don't get reset on
  145.         return from the PM program.  The "2>NUL" causes
  146.         stderr to be rerouted, which keeps the PID number
  147.         from being displayed for the detached process.
  148.     **********************************************************/
  149.         sprintf(CommandLine,"DETACH SetWinPM %p %s 2>NUL",SwitchData.hwnd,Arguments);
  150.         system(CommandLine);
  151.         return 0;
  152.     }
  153.  
  154.