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

  1. /*
  2.  *  Function Name:   CreateEllipticRgnIndirect
  3.  *
  4.  *  Description:
  5.  *   The program below creates an elliptical region that will be displayed
  6.  *   by inverting the region.
  7.  */
  8.  
  9. #include "windows.h"
  10.  
  11. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  12.  
  13. /***********************************************************************/
  14.  
  15. void CALL_CreateEllipticRgnIndirect (hWnd, hDC)
  16. HWND hWnd;
  17. HDC hDC;
  18.   {
  19.   RECT ClientRect;
  20.   HRGN hNewRgn;
  21.  
  22.   GetClientRect (hWnd, (LPRECT) & ClientRect);   /* get client area  */
  23.  
  24.   ClientRect.right /= 2;
  25. /* create new region   */
  26.   hNewRgn = CreateEllipticRgnIndirect ( (LPRECT) & ClientRect);
  27.  
  28.   if (hNewRgn == NULL)                   /* Check for error */
  29.     {
  30.     MessageBeep (0);
  31.     return;
  32.     }
  33.   InvertRgn (hDC, hNewRgn);
  34.   DeleteObject (hNewRgn);
  35.   return;
  36.   }
  37.  
  38. /**************************************************************************/
  39.  
  40. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  41. HANDLE    hInstance, hPrevInstance;
  42. LPSTR     lpszCmdLine;
  43. int       cmdShow;
  44.   {
  45.   MSG   msg;
  46.   HWND  hWnd;
  47.  
  48.   if (!hPrevInstance)
  49.     {
  50.     WNDCLASS   wcClass;
  51.  
  52.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  53.     wcClass.lpfnWndProc    = WndProc;
  54.     wcClass.cbClsExtra     = 0;
  55.     wcClass.cbWndExtra     = 0;
  56.     wcClass.hInstance      = hInstance;
  57.     wcClass.hIcon          = LoadIcon (hInstance, NULL);
  58.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  59.     wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  60.     wcClass.lpszMenuName   = (LPSTR)NULL;
  61.     wcClass.lpszClassName  = (LPSTR)"CreateEllipticRgnIndirect";
  62.  
  63.     if (!RegisterClass ( (LPWNDCLASS) & wcClass))
  64.       return FALSE;
  65.     }
  66.  
  67.   hWnd = CreateWindow ( (LPSTR)"CreateEllipticRgnIndirect",
  68.                       (LPSTR)"CreateEllipticRgnIndirect ()",
  69.                       WS_OVERLAPPEDWINDOW,
  70.                       CW_USEDEFAULT,
  71.                       CW_USEDEFAULT,
  72.                       CW_USEDEFAULT,
  73.                       CW_USEDEFAULT,
  74.                       (HWND)NULL,        /* no parent */
  75.                       (HMENU)NULL,       /* use class menu */
  76.                       (HANDLE)hInstance, /* handle to window instance */
  77.                       (LPSTR)NULL);      /* no params to pass on */
  78.  
  79.  
  80.   ShowWindow (hWnd, cmdShow);
  81.   UpdateWindow (hWnd);
  82.  
  83.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  84.     {
  85.     TranslateMessage ( (LPMSG) & msg);
  86.     DispatchMessage ( (LPMSG) & msg);
  87.     }
  88.   return (int)msg.wParam;
  89.   }
  90.  
  91. /* Procedures which make up the window class. */
  92. long    FAR PASCAL WndProc (hWnd, message, wParam, lParam)
  93. HWND     hWnd;
  94. unsigned message;
  95. WORD     wParam;
  96. LONG     lParam;
  97.   {
  98.   PAINTSTRUCT ps;
  99.  
  100.   switch (message)
  101.     {
  102.     case WM_PAINT:
  103.       BeginPaint (hWnd, (LPPAINTSTRUCT) & ps);
  104.       CALL_CreateEllipticRgnIndirect (hWnd, ps.hdc);
  105.       ValidateRect (hWnd, (LPRECT) NULL);
  106.       EndPaint (hWnd, (LPPAINTSTRUCT) & ps);
  107.       break;
  108.  
  109.     case WM_DESTROY:
  110.       PostQuitMessage (0);
  111.       break;
  112.  
  113.     default:
  114.       return DefWindowProc (hWnd, message, wParam, lParam);
  115.       break;
  116.     }
  117.   return (0L);
  118.   }
  119.