home *** CD-ROM | disk | FTP | other *** search
- /*
- INTWPOS.C -- Uses GetSetInternalWindowPos to adjust window
- positions on the desktop
-
- From Chapter 6 of "Undocumented Windows" (Addison-Wesley 1992)
- by Andrew Schulman, Dave Maxey and Matt Pietrek
-
- Build using: WINIOBC INTWPOS (for Borland C++ v3.00)
- WINIOMS INTWPOS (for Microsoft C/SDK)
- */
-
- #include <windows.h>
- #include <stdlib.h>
- #include <string.h>
- #include "winio.h"
-
- /* undocumented functions */
- extern WORD FAR PASCAL GetInternalWindowPos(HWND hwnd,
- LPRECT lprectWnd, LPPOINT lppointIcon);
- extern BOOL FAR PASCAL SetInternalWindowPos(HWND hwnd,
- WORD wStatus, LPRECT lprectWnd,
- LPPOINT lppointIcon);
-
- char *szWndStatus[] =
- { "0 - hidden", "1 - normal/restored", "2 - minimized",
- "3 - maximized", "4 - restore inactive", "5 - show",
- "6 - minimize", "7 - minimize inactive",
- "8 - show inactive", "9 - restore"};
-
- #include "checkord.c"
-
- int main()
- {
- char achInput[80];
- WORD wStatus;
- HWND hwnd;
- RECT rectWindow;
- POINT pointIcon;
- char *szStr;
- char *szTok;
- int iWrk[4];
- int i;
-
- // Name/ordinal checks
- if (! (CheckOrdName("GetInternalWindowPos", "USER", 460) &&
- CheckOrdName("SetInternalWindowPos", "USER", 461)))
- return 0;
-
- winio_about("INTWPOS"
- "\nUses Get/SetInternalWindowPos to adjust window positions"
- "\non the desktop"
- "\n\nFrom Chapter 6 of"
- "\n\"Undocumented Windows\" (Addison-Wesley, 1992)"
- "\nby Andrew Schulman, David Maxey and Matt Pietrek"
- );
-
- for (;;)
- {
- // Prompt for window to look at
- puts("Enter the window title of a window");
- gets(achInput);
-
- // Get its handle
- if ((hwnd = FindWindow(NULL, (LPSTR) &achInput)) == 0)
- {
- printf("Couldn't locate <%s>....\n", achInput);
- continue;
- }
-
- // Get current minimized, maximized, and normal
- // position data, and current status
- wStatus = GetInternalWindowPos(hwnd,
- (LPRECT) &rectWindow, (LPPOINT) &pointIcon);
- printf("Window is currently %s.\n", szWndStatus[wStatus]);
- printf("Window co-ordinates are %d, %d, %d, %d,\n",
- rectWindow.left, rectWindow.top,
- rectWindow.right, rectWindow.bottom);
- printf("Icon position is %d, %d.\n\n",
- pointIcon.x, pointIcon.y);
-
- // Prompt for new normal window coordinates
- puts("Enter new window coordinates");
- puts("or <CR> to leave unchanged:");
- szStr = gets(achInput);
- if (! *szStr)
- goto lIconPos;
- i = 0;
- while ((i < 4) && (szTok = strtok(szStr, ", \t")))
- {
- iWrk[i++] = atoi(szTok);
- szStr = NULL;
- }
- while (i < 4) iWrk[i++] = 0;
- memcpy(&rectWindow, &iWrk, sizeof(RECT));
-
- lIconPos:
- // Prompt for top left coordinates of minimized icon position
- puts("Enter new icon coordinates");
- puts("or <CR> to leave unchanged:");
- szStr = gets(achInput);
- if (! *szStr)
- goto lWinStatus;
- i = 0;
- while ((i < 2) && (szTok = strtok(szStr, " ")))
- {
- iWrk[i++] = atoi(szTok);
- szStr = NULL;
- }
- while (i < 2) iWrk[i++] = 0;
-
- pointIcon.x = iWrk[0];
- pointIcon.y = iWrk[1];
-
- lWinStatus:
- // Prompt for new window status
- puts("Enter new window status");
- printf("%s\t%s\t%s\n%s\t%s\t%s\n%s\t%s\n%s\t%s\n"
- "or <CR> to leave unchanged:\n", szWndStatus[0],
- szWndStatus[1], szWndStatus[2], szWndStatus[3],
- szWndStatus[4], szWndStatus[5], szWndStatus[6],
- szWndStatus[7], szWndStatus[8], szWndStatus[9]);
- szStr = gets(achInput);
- if (! *szStr)
- goto lSetIWPos;
- wStatus = atoi(szStr);
-
- lSetIWPos:
- // and update window position and status data
- SetInternalWindowPos(hwnd, wStatus,
- (LPRECT) &rectWindow, (LPPOINT) &pointIcon);
- puts("SetInternalWindowPos executed.\n");
- }
-
- printf("Program terminated");
- return 0;
- }
-
-