home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / region / getwnrct.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-08-11  |  2.6 KB  |  88 lines

  1. /*
  2.  *
  3.  * GetWindowRect
  4.  *
  5.  * This program registers a window and creates it on the screen.  The
  6.  *  program then creates the window, shows the window, and then updates
  7.  *  the window.  The WinMain proceeds to execute the GetWindowRect function.
  8.  *  If the function call is successful, message boxes are created which
  9.  *  display the rectangle coordinates.
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. /* Global Variables */
  16. static HANDLE hInst;
  17. static HWND hWnd;
  18.  
  19. /* FORWARD REFERENCES */
  20. long FAR PASCAL WindowProc (HWND, unsigned, WORD, LONG);
  21.  
  22. /* WINMAIN */
  23. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  24. HANDLE hInstance, hPrevInstance;
  25. LPSTR lpszCmdLine;
  26. int cmdShow;
  27. {
  28.   MSG msg;
  29.   RECT *rect;             /* Pointer to Window Rectangle. */
  30.   char szbuf[31];         /* Buffer for Message Box.        */
  31.  
  32.   if (!hPrevInstance)  {
  33.  
  34.      WNDCLASS rClass;
  35.  
  36.      rClass.lpszClassName = (LPSTR)"getwnrct";
  37.      rClass.hInstance      = hInstance;
  38.      rClass.lpfnWndProc   = DefWindowProc;
  39.      rClass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  40.      rClass.hIcon            = LoadIcon(NULL, IDI_APPLICATION);
  41.      rClass.lpszMenuName  = (LPSTR)NULL;
  42.      rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  43.      rClass.style            = CS_HREDRAW | CS_VREDRAW;
  44.      rClass.cbClsExtra      = 0;
  45.      rClass.cbWndExtra      = 0;
  46.  
  47.      RegisterClass((LPWNDCLASS)&rClass);
  48.  
  49.      }
  50.    else
  51.       ;
  52.  
  53.    hInst = hInstance;
  54.  
  55.    hWnd = CreateWindow((LPSTR) "getwnrct",
  56.                (LPSTR) "GetWindowRect",
  57.                WS_OVERLAPPEDWINDOW,           /* Use overlapped window.   */
  58.                CW_USEDEFAULT,                 /* Use default coordinates. */
  59.                CW_USEDEFAULT,                 /* Use default coordinates. */
  60.                CW_USEDEFAULT,                 /* Use default coordinates. */
  61.                CW_USEDEFAULT,                 /* Use default coordinates. */
  62.                (HWND)NULL,
  63.                (HMENU)NULL,
  64.                (HANDLE)hInstance,
  65.                (LPSTR)NULL
  66.              );
  67.  
  68.    ShowWindow(hWnd, cmdShow);
  69.  
  70.    UpdateWindow(hWnd);
  71.  
  72.    GetWindowRect(hWnd, (LPRECT)rect);  /* Get the Window Rectangle.    */
  73.  
  74.    /* Report the top left and the bottom right of the window rectangle */
  75.    /* in separate message boxes.                                             */
  76.  
  77.    sprintf(szbuf,"%s%d%s%d%s","The top left is (", rect->top,
  78.        ",", rect->left, ").");
  79.    MessageBox(NULL, (LPSTR)szbuf, (LPSTR)"GetWindowRect", MB_OK);
  80.  
  81.    sprintf(szbuf,"%s%d%s%d%s","The bottom right is (", rect->bottom,
  82.        ",", rect->right, ").");
  83.    MessageBox(NULL, (LPSTR)szbuf, (LPSTR)"GetWindowRect", MB_OK);
  84.  
  85. } /* WinMain */
  86.  
  87. /* WINDOWPROC */
  88.