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

  1. /*
  2.  *  ScreenToClient
  3.  *  scntocli.c,
  4.  *
  5.  *  This program demonstrates the use of the function ScreenToClient.
  6.  *  It converts the screen coordinates of the point into equivalent client
  7.  *  coordinates. The new coordinates replace the existing point. 
  8.  *
  9.  */
  10.  
  11. #include "windows.h"
  12. #include <stdio.h>
  13.  
  14. /* Procedure called when the application is loaded for the first time */
  15. BOOL WinInit( hInstance )
  16. HANDLE hInstance;
  17. {
  18.     WNDCLASS   wcClass;
  19.  
  20.     /* registering the parent window class */
  21.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  22.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  23.     wcClass.lpszMenuName   = (LPSTR)NULL;
  24.     wcClass.lpszClassName  = (LPSTR)"Scntocli";
  25.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  26.     wcClass.hInstance      = hInstance;
  27.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  28.     wcClass.lpfnWndProc    = DefWindowProc;
  29.     wcClass.cbClsExtra     = 0;
  30.     wcClass.cbWndExtra     = 0;
  31.  
  32.     RegisterClass( (LPWNDCLASS)&wcClass );
  33.     return TRUE;        /* Initialization succeeded */
  34. }
  35.  
  36.  
  37. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  38. HANDLE hInstance, hPrevInstance;
  39. LPSTR lpszCmdLine;
  40. int cmdShow;
  41. {
  42.     HWND   hWnd;                /* Handle to the parent window    */
  43.     POINT  ptCurrentPoint;      /* POINT data type                */
  44.     char   szBuffer[60];        /* string buffer for output       */
  45.  
  46.     WinInit (hInstance);
  47.  
  48.     hWnd = CreateWindow((LPSTR)"Scntocli",
  49.                         (LPSTR)"Screen/Client Coordinates",
  50.                         WS_OVERLAPPEDWINDOW,
  51.                         50,                /* x         */
  52.                         50,                /* y         */
  53.                         600,               /* width     */
  54.                         250,               /* height    */
  55.                         (HWND)NULL,        /* no parent */
  56.                         (HMENU)NULL,       /* use class menu */
  57.                         (HANDLE)hInstance, /* handle to window instance */
  58.                         (LPSTR)NULL        /* no params to pass on */
  59.                        );
  60.  
  61.     /* Make window visible according to the way the app is activated */
  62.     ShowWindow( hWnd, cmdShow );
  63.     UpdateWindow( hWnd );
  64.  
  65.     /* Initializing the point to some screen coordinate and display the
  66.      * value in a message box
  67.      */
  68.     ptCurrentPoint.x = 234;
  69.     ptCurrentPoint.y = 150;
  70.     sprintf (szBuffer, "The screen coordinates of the point is %d and %d",
  71.              ptCurrentPoint.x, ptCurrentPoint.y);
  72.     MessageBox (hWnd, (LPSTR)szBuffer, (LPSTR)"Screen", MB_OK);
  73.  
  74.     /* convert the point to client coordinate and display the new value
  75.      * in a message box
  76.      */
  77.     ScreenToClient (hWnd, (POINT FAR *) &ptCurrentPoint);
  78.     sprintf (szBuffer, "The client coordinates of the point is %d and %d",
  79.              ptCurrentPoint.x, ptCurrentPoint.y);
  80.     MessageBox (hWnd, (LPSTR)szBuffer, (LPSTR)"Client", MB_OK);
  81.  
  82.     return 0;
  83. }
  84.