home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 144.lha / VScreen_Src / wSize.c < prev    next >
Encoding:
C/C++ Source or Header  |  1986-11-21  |  3.7 KB  |  120 lines

  1. #include <exec/types.h>
  2. #include <intuition/intuitionbase.h>
  3. #include <intuition/screens.h>
  4. #include <proto/intuition.h>
  5. #include <proto/exec.h>
  6. #define INTUITION_REV   0L
  7. extern struct IntuitionBase *IntuitionBase;
  8. extern struct IntuitionBase *OpenLibrary();
  9. static void ShowUsage()
  10. {
  11.    printf("Usage:  WSIZE dx dy [window [screen [IGNOREMAX]]\n");
  12.    exit(10L);
  13. --MORE--(92%)}
  14. static void GetInt(i,s)
  15. long *i;
  16. char *s;
  17. {
  18.    if (sscanf(s,"%ld",i) != 1) ShowUsage();
  19. }
  20. static struct Screen *FindScreen(ScreenName)
  21. char *ScreenName;
  22. {
  23.    struct Screen *theScreen;
  24.    if (ScreenName && ScreenName[0])
  25.    {
  26.       theScreen = IntuitionBase->FirstScreen;
  27.       while (theScreen && (theScreen->Title == NULL ||
  28.              stricmp(theScreen->Title,ScreenName) != 0))
  29.                 theScreen = theScreen->NextScreen;
  30.    } else {
  31.       theScreen = IntuitionBase->ActiveScreen;
  32. --MORE--(93%)   }
  33.    if (theScreen == NULL)
  34.    {
  35.       Permit();
  36.       printf("Can't find screen '%s'\n",ScreenName);
  37.       exit(10L);
  38.    }
  39.    return(theScreen);
  40. }
  41. static struct Window *FindWindow(WindowName,theScreen)
  42. char *WindowName;
  43. struct Screen *theScreen;
  44. {
  45.    struct Window *theWindow;
  46.    if (WindowName && WindowName[0])
  47.    {
  48.       theWindow = theScreen->FirstWindow;
  49.       while (theWindow && (theWindow->Title == NULL ||
  50.              stricmp(theWindow->Title,WindowName) != 0))
  51. --MORE--(94%)                theWindow = theWindow->NextWindow;
  52.    } else {
  53.       theWindow = IntuitionBase->ActiveWindow;
  54.    }
  55.    if (theWindow == NULL)
  56.    {
  57.       Permit();
  58.       printf("Can't find window '%s' on screen '%s'\n",
  59.          WindowName,theScreen->Title);
  60.       exit(10L);
  61.    }
  62.    Permit();
  63.    return(theWindow);
  64. }
  65. void main(argc,argv)
  66. int argc;
  67. char *argv[];
  68. {
  69.    char *WindowName = NULL;
  70.    char *ScreenName = NULL;
  71. --MORE--(95%)   long dx,dy;
  72.    struct Window *theWindow;
  73.    struct Screen *theScreen;
  74.    long UseMax = TRUE;
  75.    if (argc < 3 || argc > 6) ShowUsage();
  76.    GetInt(&dx,argv[1]);
  77.    GetInt(&dy,argv[2]);
  78.    if (argc > 3 && argv[3] && argv[3][0] != '\0') WindowName = argv[3];
  79.    if (argc > 4 && argv[4] && argv[4][0] != '\0') ScreenName = argv[4];
  80.    if (argc > 5) UseMax = FALSE;
  81.    
  82.    IntuitionBase = OpenLibrary("intuition.library",INTUITION_REV);
  83.    if (IntuitionBase)
  84.    {
  85.       Forbid();
  86.       theScreen = FindScreen(ScreenName);
  87.       theWindow = FindWindow(WindowName,theScreen);
  88.       Permit();
  89.       if (theWindow->LeftEdge + theWindow->Width + dx > theScreen->Width)
  90.          dx = theScreen->Width - theWindow->LeftEdge - theWindow->Width;
  91.       if (theWindow->Width + dx < theWindow->MinWidth)
  92. --MORE--(97%)         dx = theWindow->MinWidth - theWindow->Width;
  93.       if (theWindow->Width + dx > theWindow->MaxWidth && UseMax)
  94.          dx = theWindow->MaxWidth - theWindow->Width;
  95.       if (theWindow->TopEdge + theWindow->Height + dy > theScreen->Height)
  96.          dy = theScreen->Height - theWindow->TopEdge - theWindow->Height;
  97.       if (theWindow->Height + dy < theWindow->MinHeight)
  98.          dy = theWindow->MinHeight - theWindow->Height;
  99.       if (theWindow->Height + dy > theWindow->MaxHeight && UseMax)
  100.          dy = theWindow->MaxHeight - theWindow->Height;
  101.       printf("\nWindow '%s' on Screen '%s'\n",
  102.          theWindow->Title,theWindow->WScreen->Title);
  103.       printf("   Old size:  (%d,%d)\n",theWindow->Width,theWindow->Height);
  104.       if (dx || dy)
  105.       {
  106.          printf("   New size:  (%d,%d)\n   Changed:   (%d,%d)\n\n",
  107.             theWindow->Width+dx,theWindow->Height+dy,dx,dy);
  108.          SizeWindow(theWindow,dx,dy);
  109.       }
  110.       CloseLibrary(IntuitionBase);
  111.    }
  112. }
  113. --MORE--(99%)SHAR_EOF
  114. if test 3542 -ne "`wc -c wSize.c`"
  115. then
  116. echo shar: error transmitting wSize.c '(should have been 3542 characters)'
  117. fi
  118. #       End of shell archive
  119. exit 0
  120. End of article 181 (of 181)--what next? [npq]