home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d0xx / d087 / movewindow.lha / MoveWindow / MoveWindow.c next >
Encoding:
C/C++ Source or Header  |  1987-07-08  |  4.9 KB  |  169 lines

  1.  
  2. /*
  3.     This little utility was written by the German Softcracking Group 9
  4.     and intentionally left in the PUBLIC DOMAIN.
  5.  
  6.    Feel free to copy the program and this Lattice-C source file, but
  7.    keep the name of the autor in it.
  8.  
  9.                      G.S.G. 9 (Cewy)  10-May-87
  10.  
  11.    If you'll do any changes (fix bugs or else) leave the new source
  12.    (Lattice only !) at the BBS-BOX called 'Barrel-Burst-Box' and a
  13.    message to me 'CEWY'. I'll check the box each week!
  14.  
  15.    Phone : (Germany) 06151/ 595240    (300 8N1 or 1200 8N1)
  16.  
  17. */
  18.  
  19. /* executable (batch) file :
  20.   .key name
  21.   .def name MoveWindow
  22.   stack 30000
  23.   lc -v <name>
  24.   BLink FROM LIB:c.o+<name>.o TO <name> LIBRARY LIB:lc.lib+LIB:amiga.lib NODEBUG
  25. */
  26.  
  27. /* -------------------------- include section ------------------------ */
  28.  
  29. #include <stdio.h>
  30. #include <intuition/intuition.h>
  31.  
  32. /* -------------------------- define section ------------------------- */
  33.  
  34. #define DEFAULT_NAME "AmigaDOS"
  35.  
  36. /* -------------------- global variable section ---------------------- */
  37.  
  38. struct   IntuitionBase  *IntuitionBase = NULL; 
  39.  
  40. struct   Window         *MyWindow;
  41. struct   NewWindow      MyWindowStruct = {
  42.              0,0,1,1,1,1,0,0,
  43.              NULL, NULL, NULL, NULL, NULL,0,0,0,0,WBENCHSCREEN
  44. };
  45.  
  46. /* ---------------------- local function section --------------------- */
  47. /* DESCRIPTION :
  48.       print the usage of the program, so the user knows how to handle it.
  49.    BUGS :
  50.       none.
  51.    COMMENT :
  52.       uses puts instead of printf, cause puts is much shorter.
  53. */
  54. void Usage()
  55. {
  56.    puts ("Usage: MoveWindow NewXpos [NewYpos [NewXSize [NewYSize [WindowTitle]]]]");
  57.    puts ("written by G.S.G. 9 in May '87");
  58.    exit (20);
  59. }
  60.  
  61. /* ----------------------- main program section ----------------------- */
  62. /* DESCRIPTION :
  63.       Find the WorkbenchScreen and search requested window by it's Title.
  64.       If the window was found : Size and drag the window with care!
  65.    BUGS :
  66.       sometimes the borders of the windows get hurt.
  67.    COMMENT :
  68.       none.
  69. */
  70.  
  71. main (argc,argv)
  72. int argc;
  73. char *argv[];
  74. {
  75.    SHORT         Xpos, Ypos, Xwide, Ywide;
  76.    int           DeltaPosX, DeltaPosY, DeltaSizeX, DeltaSizeY;
  77.    struct Screen *WBenchPtr;
  78.    struct Window *Wind;
  79.    UBYTE         *WindName;
  80.  
  81.    /* check the number of arguments */
  82.    if (argc <2 || argc >6 || *argv[1] == '?') Usage ();
  83.  
  84.    /* open the intuition for OpenWindow */
  85.    if (!(IntuitionBase = (struct IntuitionBase *) OpenLibrary
  86.          ("intuition.library",0))) exit (100);
  87.  
  88.    /* open a New Window */
  89.    if (!(MyWindow = (struct Window *) OpenWindow (&MyWindowStruct))) exit (200);
  90.  
  91.    /* Now we got a pointer to the WorkbenchScreen */
  92.    WBenchPtr = MyWindow -> WScreen;
  93.  
  94.    /* we don't need this window any longer, so close it */
  95.    CloseWindow (MyWindow);
  96.  
  97.    /* if a title is given by the user, use it */
  98.    if (argc <6)
  99.       WindName = DEFAULT_NAME;
  100.    else
  101.       WindName = argv[--argc];  /* decrement argc for later use */
  102.  
  103.    /* get a pointer the the first window on the WBScreen */
  104.    Wind = WBenchPtr->FirstWindow;
  105.  
  106.    /* search the list of windows on the WBScreen for the one to be found */
  107.    while (Wind && (strcmp (WindName,Wind->Title)))
  108.       Wind = Wind->NextWindow;
  109.  
  110.    /* if the window isn't there, Wind will point to NULL (=FALSE) */
  111.  
  112.    if (Wind) {
  113.       Ywide = Wind->Height;         /* get the previous values */
  114.       Xwide = Wind->Width;
  115.       Ypos  = Wind->TopEdge;
  116.   /*  Xpos  = Wind->LeftEdge;    this one is changed each time */
  117.  
  118.       /* change current settings */
  119.       switch (argc) {
  120.          case 5: Ywide = (SHORT) atoi (argv[4]); /* remember that each */
  121.          case 4: Xwide = (SHORT) atoi (argv[3]); /* case lower will be */
  122.          case 3: Ypos  = (SHORT) atoi (argv[2]); /* executed !         */
  123.          case 2: Xpos  = (SHORT) atoi (argv[1]);
  124.       }
  125.  
  126.       /* if the user does too big things, we don't care.
  127.          I won't get the ScreenLimits (640,256 or 704,276 (mine) or ....)
  128.          for checking boundaries */
  129.        /* This should be changed, anybody out there knows how? <CB> */    
  130.     
  131.  
  132.       DeltaSizeY = Ywide - Wind->Height;     /* calculate Delta Values */
  133.       DeltaSizeX = Xwide - Wind->Width;
  134.       DeltaPosX  = Xpos  - Wind->LeftEdge;
  135.       DeltaPosY  = Ypos  - Wind->TopEdge;
  136.  
  137.       /* it's a different thing to drag a big window down and
  138.          size it before or after draging! */
  139.  
  140.       if (DeltaSizeY < 0) {
  141.          SizeWindow (Wind, 0, DeltaSizeY);
  142.          MoveWindow (Wind, 0, DeltaPosY);
  143.       } else {
  144.          MoveWindow (Wind, 0, DeltaPosY);
  145.          SizeWindow (Wind, 0, DeltaSizeY);
  146.       }
  147.  
  148.       if (DeltaSizeX < 0) {
  149.          SizeWindow (Wind, DeltaSizeX, 0);
  150.          MoveWindow (Wind, DeltaPosX,  0);
  151.       } else {
  152.          MoveWindow (Wind, DeltaPosX,  0);
  153.          SizeWindow (Wind, DeltaSizeX, 0);
  154.       }
  155.  
  156.    } else {
  157.  
  158.       /* let the user know that he typed something wrong */
  159.       puts ("Sorry, didn't found that window\n");
  160.    }
  161.  
  162.    /* close the opened library */
  163.    CloseLibrary (IntuitionBase);
  164.  
  165.    /* say 'well done' the the system */
  166.    return (0);
  167. }
  168.  
  169.