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

  1. /*
  2.  *
  3.  * GetViewportOrg
  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 GetViewportOrg function.
  8.  *  Two message boxes are created which display the x and y coordinates
  9.  *  of the viewport origin respectively.
  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.   HDC hDC;            /* Handle to the Display Context. */
  30.   unsigned int xOrg;  /* X coordinate of the origin.    */
  31.   unsigned int yOrg;  /* Y coordinate of the origin.    */
  32.   long ptOrigin;      /* Long pointer to the origin.    */
  33.   char szbuf[19];     /* Output buffer.                 */
  34.  
  35.   if (!hPrevInstance)  {
  36.  
  37.      WNDCLASS rClass;
  38.  
  39.      rClass.lpszClassName = (LPSTR)"getvworg";
  40.      rClass.hInstance      = hInstance;
  41.      rClass.lpfnWndProc   = DefWindowProc;
  42.      rClass.hCursor         = LoadCursor(NULL, IDC_ARROW);
  43.      rClass.hIcon            = LoadIcon(hInstance, IDI_APPLICATION);
  44.      rClass.lpszMenuName  = (LPSTR)NULL;
  45.      rClass.hbrBackground = GetStockObject(WHITE_BRUSH);
  46.      rClass.style            = CS_HREDRAW | CS_VREDRAW;
  47.      rClass.cbClsExtra      = 0;
  48.      rClass.cbWndExtra      = 0;
  49.  
  50.      RegisterClass((LPWNDCLASS)&rClass);
  51.  
  52.      }
  53.    else
  54.       ;
  55.  
  56.    hInst = hInstance;
  57.  
  58.    hWnd = CreateWindow((LPSTR) "getvworg",
  59.                (LPSTR) "GetViewportOrg",
  60.                WS_OVERLAPPEDWINDOW,           /* Use overlapped window.   */
  61.                CW_USEDEFAULT,                 /* Use default coordinates. */
  62.                CW_USEDEFAULT,                 /* Use default coordinates. */
  63.                CW_USEDEFAULT,                 /* Use default coordinates. */
  64.                CW_USEDEFAULT,                 /* Use default coordinates. */
  65.                (HWND)NULL,
  66.                (HMENU)NULL,
  67.                (HANDLE)hInstance,
  68.                (LPSTR)NULL
  69.              );
  70.  
  71.    ShowWindow(hWnd, cmdShow);
  72.  
  73.    UpdateWindow(hWnd);
  74.  
  75.    hDC = GetDC(hWnd);
  76.  
  77.    ptOrigin = GetViewportOrg(hDC);      /* Get the viewport origin.  */
  78.  
  79.    xOrg = LOWORD(ptOrigin);             /* Isolate the X coordinate. */
  80.    yOrg = HIWORD(ptOrigin);             /* Isolate the Y coordinate. */
  81.  
  82.    sprintf(szbuf,                       /* Place the X coordinate in */
  83.            "%s%d",                      /*  the output buffer along  */
  84.            "The x Origin is ",          /*  with some explanatory    */
  85.            xOrg);                       /*  text.                    */
  86.    MessageBox(NULL,                     /* Display the information   */
  87.               (LPSTR)szbuf,             /*  in a message box.        */
  88.               (LPSTR)"GetViewportOrg",
  89.               MB_OK);
  90.  
  91.    sprintf(szbuf,                       /* Place the Y origin in the */
  92.            "%s%d",                      /*  output buffer along with */
  93.            "The y Origin is ",          /*  some text.               */
  94.            yOrg);
  95.    MessageBox(NULL,                     /* Output the information in */
  96.               (LPSTR)szbuf,             /*  another message box.     */
  97.               (LPSTR)"GetViewportOrg",
  98.               MB_OK);
  99.  
  100. } /* WinMain */
  101.