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

  1. /*
  2.  *
  3.  *  GetAspectRatioFilter
  4.  *  
  5.  *  This program demonstrates the use of the function GetAspectRatioFilter.
  6.  *  This function retrieves the setting for the current aspect-ratio filter.
  7.  *
  8.  */
  9.  
  10. #include "windows.h"
  11. #include <stdio.h>
  12.  
  13. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  14.  
  15. static char    szAppName [] = "GARF";
  16. static char    szFuncName [] = "GetAspectRatioFilter";
  17.  
  18. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  19. HANDLE    hInstance;
  20. HANDLE    hPrevInstance;
  21. LPSTR     lpszCmdLine;
  22. int       cmdShow;
  23.   {
  24.   WNDCLASS  rClass;
  25.   HWND      hWnd;
  26.   MSG       msg;
  27.  
  28.   if (!hPrevInstance)
  29.     {
  30.     rClass.style         = CS_HREDRAW | CS_VREDRAW;
  31.     rClass.lpfnWndProc   = WndProc;
  32.     rClass.cbClsExtra    = 0;
  33.     rClass.cbWndExtra    = 0;
  34.     rClass.hInstance     = hInstance;
  35.     rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  36.     rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  37.     rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  38.     rClass.lpszMenuName  = (LPSTR)NULL;
  39.     rClass.lpszClassName = szAppName;
  40.  
  41.     if (!RegisterClass (&rClass))
  42.       return FALSE;
  43.     }
  44.  
  45. hWnd = CreateWindow (szAppName,          /* window class name       */
  46.                     szFuncName,          /* window caption          */
  47.                     WS_OVERLAPPEDWINDOW, /* window style            */
  48.                     CW_USEDEFAULT,       /* initial x position      */
  49.                     0,                   /* initial y position      */
  50.                     CW_USEDEFAULT,       /* initial x size          */
  51.                     0,                   /* initial y size          */
  52.                     NULL,                /* parent window handle    */
  53.                     NULL,                /* window menu handle      */
  54.                     hInstance,           /* program instance handle */
  55.                     NULL);               /* create parameters       */
  56.  
  57.   ShowWindow (hWnd, cmdShow);
  58.   UpdateWindow (hWnd);
  59.  
  60.   while (GetMessage (&msg, NULL, 0, 0))
  61.     {
  62.     TranslateMessage (&msg);
  63.     DispatchMessage (&msg);
  64.     }
  65.   return (msg.wParam);
  66.   }
  67.  
  68. long    FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  69. HWND     hWnd;
  70. unsigned iMessage;
  71. WORD     wParam;
  72. LONG     lParam;
  73.   {
  74.   HDC   hDC;
  75.   HMENU hMenu;
  76.   DWORD dwAspectRatio;
  77.   char    szBuffer[80];
  78.  
  79.   switch (iMessage)
  80.     {
  81.     case WM_CREATE:
  82.       hMenu = CreateMenu ();
  83.       ChangeMenu (hMenu, NULL, (LPSTR)"Aspect Ratio", 1000, MF_APPEND);
  84.       SetMenu (hWnd, hMenu);
  85.       break;
  86.  
  87.     case WM_COMMAND:
  88.       if (wParam == 1000)
  89.         {
  90.         hDC = GetDC (hWnd);
  91.         SetMapperFlags (hDC, (DWORD)0);
  92.         dwAspectRatio = GetAspectRatioFilter (hDC);
  93.         sprintf (szBuffer, "%s%hu%s%hu\0",
  94.             "Aspect ratio of filter zero is: x = ", HIWORD (dwAspectRatio),
  95.             " y = ", LOWORD (dwAspectRatio));
  96.         MessageBox (GetFocus (), (LPSTR)szBuffer, (LPSTR)szFuncName, MB_OK);
  97.  
  98.         SetMapperFlags (hDC, (DWORD)1);
  99.         dwAspectRatio = GetAspectRatioFilter (hDC);
  100.         sprintf (szBuffer, "%s%hu%s%hu\0",
  101.             "Aspect ratio of filter one is: x = ", HIWORD (dwAspectRatio),
  102.             " y = ", LOWORD (dwAspectRatio));
  103.         MessageBox (GetFocus (), (LPSTR)szBuffer, (LPSTR)szFuncName, MB_OK);
  104.  
  105.         ReleaseDC (hWnd, hDC);
  106.         }
  107.       break;
  108.  
  109.     case WM_DESTROY:
  110.       PostQuitMessage (0);
  111.       break;
  112.  
  113.     default:
  114.       return DefWindowProc (hWnd, iMessage, wParam, lParam);
  115.     }
  116.   return (0L);
  117.   }
  118.