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

  1. /*
  2.  * GetWindowOrg
  3.  *
  4.  * This program registers a window and creates it on the screen.  The
  5.  *  program then creates the window, shows the window, and then updates
  6.  *  the window.  The WinMain proceeds to execute the GetWindowOrg function.
  7.  *  Two message boxes are created which display the x and y coordinates
  8.  *  respectively.  The x and y values here are the default values.
  9.  */
  10.  
  11. #include "windows.h"
  12.  
  13. /* Global Variables */
  14. static HANDLE hInst;
  15. static HWND hWnd;
  16.  
  17. /* FORWARD REFERENCES */
  18. long FAR PASCAL WindowProc (HWND, unsigned, WORD, LONG);
  19.  
  20. /* WINMAIN */
  21. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  22. HANDLE hInstance, hPrevInstance;
  23. LPSTR lpszCmdLine;
  24. int cmdShow;
  25. {
  26.   MSG msg;
  27.   HDC hDC;            /* Handle to the Display Context. */
  28.   unsigned int xOrg;  /* X origin.                      */
  29.   unsigned int yOrg;  /* Y origin.                      */
  30.   long ptOrigin;      /* Pointer to the origin.         */
  31.   char szbuf[50];     /* Output buffer.                 */
  32.  
  33.   if (!hPrevInstance)  {
  34.  
  35.      WNDCLASS rClass;
  36.  
  37.      rClass.lpszClassName = (LPSTR)"getwnorg";
  38.      rClass.hInstance      = hInstance;
  39.      rClass.lpfnWndProc   = DefWindowProc;
  40.      rClass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  41.      rClass.hIcon          = LoadIcon(hInstance, IDI_APPLICATION);
  42.      rClass.lpszMenuName  = (LPSTR)NULL;
  43.      rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  44.      rClass.style          = CS_HREDRAW | CS_VREDRAW;
  45.      rClass.cbClsExtra      = 0;
  46.      rClass.cbWndExtra      = 0;
  47.  
  48.      RegisterClass((LPWNDCLASS)&rClass);
  49.  
  50.      }
  51.  
  52.    hInst = hInstance;
  53.  
  54.    hWnd = CreateWindow((LPSTR) "getwnorg",
  55.                (LPSTR) "GetWindowOrg",
  56.                WS_OVERLAPPEDWINDOW,           /* Use overlapped window.   */
  57.                CW_USEDEFAULT,                 /* Use default coordinates. */
  58.                CW_USEDEFAULT,                 /* Use default coordinates. */
  59.                CW_USEDEFAULT,                 /* Use default coordinates. */
  60.                CW_USEDEFAULT,                 /* Use default coordinates. */
  61.                (HWND)NULL,
  62.                (HMENU)NULL,
  63.                (HANDLE)hInstance,
  64.                (LPSTR)NULL
  65.              );
  66.  
  67.    ShowWindow(hWnd, cmdShow);
  68.    UpdateWindow(hWnd);
  69.  
  70.    hDC = GetDC(hWnd);                /* Get the handle to the DC.     */
  71.    ptOrigin = GetWindowOrg(hDC);     /* Get the origin of the window. */
  72.    ReleaseDC(hWnd, hDC);             /* Release the DC.               */
  73.    xOrg = LOWORD(ptOrigin);          /* Isolate the x coordinate.     */
  74.    yOrg = HIWORD(ptOrigin);          /* Isolate the y coordinate.     */
  75.  
  76.       /* Display the X coordinate in a message box. */
  77.  
  78.    sprintf(szbuf,"%s%d","The Original x Origin is ",xOrg);
  79.    MessageBox(GetFocus(), (LPSTR)szbuf, (LPSTR)"GetWindowOrg", MB_OK);
  80.  
  81.       /* Display the Y coordinate in a message box. */
  82.  
  83.    sprintf(szbuf,"%s%d","The Original y Origin is ",yOrg);
  84.    MessageBox(GetFocus(), (LPSTR)szbuf, (LPSTR)"GetWindowOrg", MB_OK);
  85.  
  86.    MessageBox(GetFocus(), (LPSTR)"Setting a New Origin at (5,5)",
  87.               (LPSTR)"SetWindowOrg", MB_OK);
  88.  
  89.       /* Set a new origin and get it too.           */
  90.    SetWindowOrg(hDC, 5, 5);          /* Set new origin of the window. */
  91.    ptOrigin = GetWindowOrg(hDC);     /* Get new origin of the window. */
  92.    xOrg = LOWORD(ptOrigin);          /* Isolate the x coordinate.     */
  93.    yOrg = HIWORD(ptOrigin);          /* Isolate the y coordinate.     */
  94.  
  95.       /* Display the X coordinate in a message box. */
  96.  
  97.    sprintf(szbuf,"%s%d","The New x Origin is ",xOrg);
  98.    MessageBox(GetFocus(), (LPSTR)szbuf, (LPSTR)"GetWindowOrg", MB_OK);
  99.  
  100.       /* Display the Y coordinate in a message box. */
  101.  
  102.    sprintf(szbuf,"%s%d","The New y Origin is ",yOrg);
  103.    MessageBox(GetFocus(), (LPSTR)szbuf, (LPSTR)"GetWindowOrg", MB_OK);
  104.  
  105. } /* WinMain */
  106.