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

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