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

  1. /*
  2.  *   InvertRgn
  3.  *
  4.  *   This program demonstrates the use of the InvertRgn function. InvertRgn
  5.  *   inverts the pixels in the given region. InvertRgn is called from
  6.  *   WinMain in this sample application.
  7.  */
  8.  
  9. #include "windows.h"
  10.  
  11. long    FAR PASCAL HelloWndProc (HWND, unsigned, WORD, LONG);
  12.  
  13. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  14. HANDLE hInstance, hPrevInstance;
  15. LPSTR lpszCmdLine;
  16. int    cmdShow;
  17.   {
  18.   MSG   msg;
  19.   HWND  hWnd;
  20.   HMENU hMenu;
  21.   HRGN hRegion;
  22.   HDC  hDC;
  23.  
  24.   if (!hPrevInstance)
  25.     {
  26.     WNDCLASS   HelloClass;
  27.  
  28.     HelloClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  29.     HelloClass.hIcon          = LoadIcon (hInstance, NULL);
  30.     HelloClass.lpszMenuName   = (LPSTR)NULL;
  31.     HelloClass.lpszClassName  = (LPSTR)"Sample Application";
  32.     HelloClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  33.     HelloClass.hInstance      = hInstance;
  34.     HelloClass.style          = CS_HREDRAW | CS_VREDRAW;
  35.     HelloClass.lpfnWndProc    = HelloWndProc;
  36.  
  37.     if (!RegisterClass ( (LPWNDCLASS)&HelloClass))
  38.       return FALSE;
  39.     }
  40.  
  41.   hWnd = CreateWindow ( (LPSTR)"Sample Application", (LPSTR)"InvertRgn Application",
  42.       WS_OVERLAPPEDWINDOW,
  43.       CW_USEDEFAULT, 0,
  44.       CW_USEDEFAULT, 0,
  45.       NULL, NULL, hInstance, NULL);
  46.  
  47.   ShowWindow (hWnd, cmdShow);
  48.   UpdateWindow (hWnd);
  49.  
  50.   hDC = GetDC (hWnd);
  51.   hRegion = CreateEllipticRgn (5, 5, 220, 100);
  52.  
  53. /*******    invert the region "hRegion"    *******/
  54.   if (!InvertRgn (hDC, hRegion))
  55.     MessageBox (GetFocus (), (LPSTR)"InvertRgn failed",
  56.         (LPSTR)" ", MB_OK);
  57.   ReleaseDC (hWnd, hDC);
  58.  
  59.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  60.     {
  61.     TranslateMessage ( (LPMSG) & msg);
  62.     DispatchMessage ( (LPMSG) & msg);
  63.     }
  64.   return (int)msg.wParam;
  65.   }
  66.  
  67. /* Procedures which make up the window class. */
  68. long    FAR PASCAL HelloWndProc (hWnd, message, wParam, lParam)
  69. HWND     hWnd;
  70. unsigned message;
  71. WORD     wParam;
  72. LONG     lParam;
  73.   {
  74.   switch (message)
  75.     {
  76.     case WM_DESTROY:
  77.       PostQuitMessage (0);
  78.       break;
  79.  
  80.     default:
  81.       return DefWindowProc (hWnd, message, wParam, lParam);
  82.       break;
  83.     }
  84.   return (0L);
  85.   }
  86.