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

  1. /*
  2.  *  Function Name:   CreatePolygonRgn
  3.  *
  4.  *  Description:
  5.  *   The program below will create a triangular region and then display it
  6.  *   by inverting the region.
  7.  */
  8.  
  9. #include "windows.h"
  10.  
  11. long    FAR PASCAL WndProc (HWND, unsigned, WORD, LONG);
  12.  
  13. /***********************************************************************/
  14. void CALL_CreatePolygonRgn (hWnd, hDC)
  15. HWND hWnd;
  16. HDC hDC;
  17.   {
  18.   HRGN hNewRgn;
  19.   POINT Points[3];
  20.  
  21.   Points[0].x = 10;
  22.   Points[0].y = 10;
  23.   Points[1].x = 10;
  24.   Points[1].y = 190;                      /* clip area     */
  25.   Points[2].x = 200;
  26.   Points[2].y = 10;
  27.      /*  polygon region created  */
  28.   hNewRgn = CreatePolygonRgn ( (LPPOINT)Points, 3, WINDING);
  29.  
  30.   if (hNewRgn == NULL)                   /* Check for error */
  31.     {
  32.     MessageBeep (0);
  33.     return;
  34.     }
  35.   InvertRgn (hDC, hNewRgn);
  36.   DeleteObject (hNewRgn);
  37.   return;
  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.   HMENU hMenu;
  48.  
  49.   if (!hPrevInstance)
  50.     {
  51.     WNDCLASS   wcClass;
  52.  
  53.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  54.     wcClass.lpfnWndProc    = WndProc;
  55.     wcClass.cbClsExtra     = 0;
  56.     wcClass.cbWndExtra     = 0;
  57.     wcClass.hInstance      = hInstance;
  58.     wcClass.hIcon          = LoadIcon (hInstance, NULL);
  59.     wcClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  60.     wcClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  61.     wcClass.lpszMenuName   = (LPSTR)NULL;
  62.     wcClass.lpszClassName  = (LPSTR)"CreatePolygonRgn";
  63.  
  64.     if (!RegisterClass ( (LPWNDCLASS) & wcClass))
  65.       return FALSE;
  66.     }
  67.  
  68.   hWnd = CreateWindow ( (LPSTR)"CreatePolygonRgn",
  69.                       (LPSTR)"CreatePolygonRgn ()",
  70.                       WS_OVERLAPPEDWINDOW,
  71.                       CW_USEDEFAULT,
  72.                       CW_USEDEFAULT,
  73.                       CW_USEDEFAULT,
  74.                       CW_USEDEFAULT,
  75.                       (HWND)NULL,        /* no parent */
  76.                       (HMENU)NULL,       /* use class menu */
  77.                       (HANDLE)hInstance, /* handle to window instance */
  78.                       (LPSTR)NULL);      /* no params to pass on */
  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_CreatePolygonRgn (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.