home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l430 / 1.ddi / CHAP6.ZIP / INTWPOS.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-10  |  4.4 KB  |  138 lines

  1. /*
  2.     INTWPOS.C -- Uses GetSetInternalWindowPos to adjust window
  3.                  positions on the desktop
  4.  
  5.     From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
  6.     by Andrew Schulman, Dave Maxey and Matt Pietrek
  7.  
  8.     Build using: WINIOBC INTWPOS (for Borland C++ v3.00)
  9.                  WINIOMS INTWPOS (for Microsoft C/SDK)
  10. */
  11.  
  12. #include <windows.h> 
  13. #include <stdlib.h> 
  14. #include <string.h> 
  15. #include "winio.h" 
  16.  
  17. /* undocumented functions */ 
  18. extern WORD FAR PASCAL GetInternalWindowPos(HWND hwnd,
  19.                             LPRECT lprectWnd, LPPOINT lppointIcon);
  20. extern BOOL FAR PASCAL SetInternalWindowPos(HWND hwnd,
  21.                             WORD wStatus, LPRECT lprectWnd,
  22.                             LPPOINT lppointIcon); 
  23.  
  24. char *szWndStatus[] =
  25.     {   "0 - hidden", "1 - normal/restored", "2 - minimized",
  26.         "3 - maximized", "4 - restore inactive", "5 - show",
  27.         "6 - minimize", "7 - minimize inactive",
  28.         "8 - show inactive", "9 - restore"};
  29.  
  30. #include "checkord.c"
  31.  
  32. int main() 
  33.     {
  34.     char achInput[80];
  35.     WORD wStatus;
  36.     HWND hwnd;
  37.     RECT rectWindow;
  38.     POINT pointIcon;
  39.     char *szStr;
  40.     char *szTok;
  41.     int iWrk[4];
  42.     int i;
  43.  
  44.     // Name/ordinal checks
  45.     if (! (CheckOrdName("GetInternalWindowPos", "USER", 460) &&
  46.             CheckOrdName("SetInternalWindowPos", "USER", 461)))
  47.         return 0;
  48.     
  49.     winio_about("INTWPOS"
  50.         "\nUses Get/SetInternalWindowPos to adjust window positions"
  51.         "\non the desktop"
  52.         "\n\nFrom Chapter 6 of"
  53.         "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
  54.         "\nby Andrew Schulman, David Maxey and Matt Pietrek"
  55.         );
  56.     
  57.     for (;;)
  58.         {
  59.         // Prompt for window to look at
  60.         puts("Enter the window title of a window");
  61.         gets(achInput);
  62.         
  63.         // Get its handle
  64.         if ((hwnd = FindWindow(NULL, (LPSTR) &achInput)) == 0)
  65.             {
  66.             printf("Couldn't locate <%s>....\n", achInput);
  67.             continue;
  68.             }
  69.  
  70.         // Get current minimized, maximized, and normal
  71.         // position data, and current status
  72.         wStatus = GetInternalWindowPos(hwnd,
  73.                     (LPRECT) &rectWindow, (LPPOINT) &pointIcon);
  74.         printf("Window is currently %s.\n", szWndStatus[wStatus]);
  75.         printf("Window co-ordinates are %d, %d, %d, %d,\n",
  76.                         rectWindow.left, rectWindow.top,
  77.                         rectWindow.right, rectWindow.bottom);
  78.         printf("Icon position is %d, %d.\n\n",
  79.                         pointIcon.x, pointIcon.y);
  80.  
  81.         // Prompt for new normal window coordinates
  82.         puts("Enter new window coordinates");
  83.         puts("or <CR> to leave unchanged:");
  84.         szStr = gets(achInput);
  85.         if (! *szStr)
  86.             goto lIconPos;
  87.         i = 0;
  88.         while ((i < 4) && (szTok = strtok(szStr, ", \t")))
  89.             {
  90.             iWrk[i++] = atoi(szTok);
  91.             szStr = NULL;
  92.             }
  93.         while (i < 4) iWrk[i++] = 0;
  94.         memcpy(&rectWindow, &iWrk, sizeof(RECT));
  95.         
  96.     lIconPos:
  97.         // Prompt for top left coordinates of minimized icon position
  98.         puts("Enter new icon coordinates");
  99.         puts("or <CR> to leave unchanged:");
  100.         szStr = gets(achInput);
  101.         if (! *szStr)
  102.             goto lWinStatus;
  103.         i = 0;
  104.         while ((i < 2) && (szTok = strtok(szStr, " ")))
  105.             {
  106.             iWrk[i++] = atoi(szTok);
  107.             szStr = NULL;
  108.             }
  109.         while (i < 2) iWrk[i++] = 0;
  110.  
  111.         pointIcon.x = iWrk[0];
  112.         pointIcon.y = iWrk[1];
  113.  
  114.     lWinStatus:
  115.         // Prompt for new window status
  116.         puts("Enter new window status");
  117.         printf("%s\t%s\t%s\n%s\t%s\t%s\n%s\t%s\n%s\t%s\n"
  118.                 "or <CR> to leave unchanged:\n", szWndStatus[0],
  119.                 szWndStatus[1], szWndStatus[2], szWndStatus[3],
  120.                 szWndStatus[4], szWndStatus[5], szWndStatus[6],
  121.                 szWndStatus[7], szWndStatus[8], szWndStatus[9]);
  122.         szStr = gets(achInput);
  123.         if (! *szStr)
  124.             goto lSetIWPos;
  125.         wStatus = atoi(szStr);
  126.         
  127.     lSetIWPos:
  128.         // and update window position and status data
  129.         SetInternalWindowPos(hwnd, wStatus,
  130.                     (LPRECT) &rectWindow, (LPPOINT) &pointIcon);
  131.         puts("SetInternalWindowPos executed.\n");
  132.         }
  133.     
  134.     printf("Program terminated");
  135.     return 0;
  136.     }
  137.  
  138.