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

  1. /*
  2.  *  Function Name:   DPtoLP
  3.  *
  4.  *  Description:
  5.  *   This program will take the client area in MM_TEXT mode (device
  6.  *   coordinates), store the client area size in a POINT data structure,
  7.  *   change the map mode to MM_LOENGLISH, then convert the points to
  8.  *   MM_LOENGLISH (logical coordinates).  The size of the client area
  9.  *   is then displayed for both map modes.
  10.  */
  11.  
  12. #include "windows.h"
  13. #include "stdio.h"
  14.  
  15. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  16.  
  17. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  18. HANDLE      hInstance, hPrevInstance;
  19. LPSTR       lpszCmdLine;
  20. int         cmdShow;
  21.   {
  22.   MSG         msg;
  23.   HWND         hWnd;
  24.   WNDCLASS   wcClass;
  25.  
  26.   if (!hPrevInstance)
  27.     {
  28.     wcClass.style       = CS_HREDRAW | CS_VREDRAW;
  29.     wcClass.lpfnWndProc    = WndProc;
  30.     wcClass.cbClsExtra       = 0;
  31.     wcClass.cbWndExtra       = 0;
  32.     wcClass.hInstance       = hInstance;
  33.     wcClass.hIcon          = LoadIcon (hInstance, NULL);
  34.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  35.     wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  36.     wcClass.lpszMenuName   = NULL;
  37.     wcClass.lpszClassName  = "DPtoLP";
  38.  
  39.     if (!RegisterClass ( (LPWNDCLASS) & wcClass))
  40.       return FALSE;
  41.     }
  42.  
  43.   hWnd = CreateWindow ("DPtoLP",
  44.                       "DPtoLP ()",
  45.                       WS_OVERLAPPEDWINDOW,
  46.                       CW_USEDEFAULT,
  47.                       CW_USEDEFAULT,
  48.                       CW_USEDEFAULT,
  49.                       CW_USEDEFAULT,
  50.                       NULL,
  51.                       NULL,
  52.                       hInstance,
  53.                       NULL);
  54.  
  55.   ShowWindow (hWnd, cmdShow);
  56.   UpdateWindow (hWnd);
  57.   while (GetMessage (&msg, NULL, 0, 0))
  58.     {
  59.     TranslateMessage (&msg);
  60.     DispatchMessage (&msg);
  61.     }
  62.   return msg.wParam;
  63.   }
  64.  
  65.  
  66. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  67. HWND      hWnd;
  68. unsigned  message;
  69. WORD      wParam;
  70. LONG      lParam;
  71.   {
  72.   PAINTSTRUCT ps;
  73.   RECT          ClientRect;
  74.   POINT       Points[1];
  75.   char        szString1[80], szString2[80];
  76.   int         nLength[2];
  77.  
  78.   switch (message)
  79.     {
  80.     case WM_PAINT:
  81.       BeginPaint (hWnd, &ps);
  82.       GetClientRect (hWnd, &ClientRect);
  83.       Points[0].x = ClientRect.right;
  84.       Points[0].y = ClientRect.bottom;
  85.       SetMapMode (ps.hdc, MM_LOENGLISH);
  86.       if (!DPtoLP (ps.hdc, Points, 1))
  87.         {
  88.         MessageBeep (0);
  89.     break;
  90.         }
  91.       SetMapMode (ps.hdc, MM_TEXT);
  92.       nLength[0] = sprintf (szString1,
  93.           "Client area in MM_LOENGLISH mode: x=%d   y=%d",
  94.           Points[0].x,
  95.           Points[0].y);
  96.       nLength[1] = sprintf (szString2,
  97.           "Client area in MM_TEXT mode (pixels): x=%d   y=%d",
  98.           ClientRect.right,
  99.           ClientRect.bottom);
  100.       TextOut (ps.hdc, 10, 10, szString1, nLength[0]);
  101.       TextOut (ps.hdc, 30, 30, szString2, nLength[1]);
  102.       ValidateRect (hWnd, NULL);
  103.       EndPaint (hWnd, &ps);
  104.       break;
  105.  
  106.     case WM_DESTROY:
  107.       PostQuitMessage (0);
  108.       break;
  109.  
  110.     default:
  111.       return DefWindowProc (hWnd, message, wParam, lParam);
  112.     }
  113.   return (0L);
  114.   }
  115.