home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: WPS_PM / WPS_PM.zip / resizer.zip / resizer.c < prev    next >
Text File  |  2000-09-16  |  3KB  |  98 lines

  1. /* Window Resizer - by Darrell Spice, Jr.     September 16, 2000
  2. || finds the window passed and change it's size
  3. || http://home.houston.rr.com/spiceware/
  4. */
  5.  
  6. #define INCL_WINFRAMEMGR
  7. #define INCL_WINWINDOWMGR
  8. #define INCL_WINMESSAGEMGR
  9. #define INCL_WINSYS
  10. #include <os2.h>
  11. #include <string.h>
  12. #include <stdlib.h>
  13.  
  14. int main(int argc,char *argv[])
  15. {
  16.     /* handles for Anchor Block, Window, Enumoration, and Mesage Queue */
  17.     HAB hab;
  18.     HWND hwnd;
  19.     HENUM henum;
  20.     HMQ hmq;
  21.  
  22.     /* window title and search for title */
  23.     char title[MAXNAMEL + 1];
  24.     char searchfor[MAXNAMEL + 1];
  25.  
  26.     /* screen and window dimensions */
  27.     int screenx;
  28.     int screeny;
  29.     int windowx;
  30.     int windowy;
  31.  
  32.     /* window size rectangle */
  33.     RECTL rcl;
  34.  
  35.     /* window size multiplier */
  36.     int multiplier;
  37.  
  38.     /* set default window and size */
  39.     strcpy(searchfor, "Entrepreneur");
  40.     multiplier = 2;
  41.  
  42.     /* get passed parameters, change to defaults if invalid */
  43.     if (argc > 1) strcpy(searchfor, argv[1]);
  44.     if (argc > 2) multiplier = atoi(argv[2]);
  45.     if (strlen(searchfor) == 0) strcpy(searchfor, "Entrepreneur");
  46.     if (multiplier < 1) multiplier = 2;
  47.  
  48.     /* get Anchor Block and create Message Queue */
  49.     hab = WinInitialize(0);
  50.     if (!(hmq = WinCreateMsgQueue (hab, 0))) return(1);
  51.  
  52.     /* get screen dimensions - used to center resized window */
  53.     screenx = WinQuerySysValue(HWND_DESKTOP, SV_CXSCREEN);
  54.     screeny = WinQuerySysValue(HWND_DESKTOP, SV_CYSCREEN);
  55.  
  56.     /* ask for list of windows */
  57.     henum = WinBeginEnumWindows(HWND_DESKTOP);
  58.     while((hwnd = WinGetNextWindow(henum)) != NULLHANDLE)
  59.     {
  60.         WinQueryWindowText(hwnd, strlen(searchfor)+1, title);
  61.         if (strcmp(title, searchfor)==0)
  62.         {
  63.             /* get frame window size */
  64.             WinQueryWindowRect (hwnd, &rcl);
  65.  
  66.             /* calculate client window size */
  67.             WinCalcFrameRect(hwnd, &rcl, TRUE);
  68.  
  69.             /* calculate new client window size */
  70.             rcl.xRight = (rcl.xRight - rcl.xLeft) * multiplier;
  71.             rcl.yTop = (rcl.yTop - rcl.yBottom) * multiplier;
  72.             rcl.xLeft = 0;
  73.             rcl.yBottom = 0;
  74.  
  75.             /* calculate new frame window size */
  76.             WinCalcFrameRect(hwnd, &rcl, FALSE);
  77.  
  78.             /* send window position & size change request */
  79.             windowx = rcl.xRight - rcl.xLeft;
  80.             windowy = rcl.yTop - rcl.yBottom;
  81.             WinSetWindowPos(hwnd, NULLHANDLE,
  82.                      (screenx - windowx)/2,
  83.                      (screeny - windowy )/2,
  84.                      windowx ,
  85.                      windowy ,
  86.                      SWP_SIZE|SWP_MOVE|SWP_ACTIVATE|SWP_SHOW);
  87.         }
  88.     }
  89.  
  90.     /* clean up */
  91.     WinEndEnumWindows(henum);
  92.     WinDestroyMsgQueue(hmq);
  93.     WinTerminate(hab);
  94.     return 0;
  95. }
  96.  
  97.  
  98.