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

  1. /*
  2.  *   InvertRect
  3.  *
  4.  *   This program demonstrates the use of the InvertRect function. The
  5.  *   InvertRect function inverts the contents of the given rectangle.
  6.  *   In this application, two calls are made to InvertRect. The first
  7.  *   inverts the pixels in a rectangle specified by lpRect. The second
  8.  *   call inverts the whole client area.
  9.  */
  10.  
  11. #include "windows.h"
  12.  
  13. long    FAR PASCAL HelloWndProc (HWND, unsigned, WORD, LONG);
  14.  
  15. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  16. HANDLE    hInstance, hPrevInstance;
  17. LPSTR     lpszCmdLine;
  18. int       cmdShow;
  19.   {
  20.   MSG   msg;
  21.   HWND  hWnd;
  22.   HMENU hMenu;
  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.   hMenu = CreateMenu ();
  42.   ChangeMenu (hMenu, NULL, "Invert!", 100, MF_APPEND);
  43.  
  44.   hWnd = CreateWindow ( (LPSTR)"Sample Application", (LPSTR)"InvertRect",
  45.                       WS_OVERLAPPEDWINDOW,
  46.                       CW_USEDEFAULT, 0,
  47.                       CW_USEDEFAULT, 0,
  48.                       NULL, hMenu, hInstance, NULL);
  49.  
  50.   ShowWindow (hWnd, cmdShow);
  51.   UpdateWindow (hWnd);
  52.  
  53.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  54.     {
  55.     TranslateMessage ( (LPMSG) & msg);
  56.     DispatchMessage ( (LPMSG) & msg);
  57.     }
  58.   return (int)msg.wParam;
  59.   }
  60.  
  61. /* Procedures which make up the window class. */
  62. long    FAR PASCAL HelloWndProc (hWnd, message, wParam, lParam)
  63. HWND     hWnd;
  64. unsigned message;
  65. WORD     wParam;
  66. LONG     lParam;
  67.   {
  68.   HDC hDC;
  69.   RECT rRect;
  70.  
  71.   switch (message)
  72.     {
  73.     case WM_COMMAND:
  74.       if (wParam == 100)
  75.         {
  76.         hDC = GetDC (hWnd);
  77.  
  78.         rRect.left = 10; /* fill lpRect with coordinate info for rectangle */
  79.         rRect.top  = 10;
  80.         rRect.right = 150;
  81.         rRect.bottom = 20;
  82.  
  83.         InvertRect (hDC, (LPRECT) &rRect);    /** invert pixels in lpRect **/
  84.         ReleaseDC (hWnd, hDC);
  85.         }
  86.       else
  87.         return DefWindowProc (hWnd, message, wParam, lParam);
  88.       break;
  89.  
  90.     case WM_DESTROY:
  91.       PostQuitMessage (0);
  92.       break;
  93.  
  94.     default:
  95.       return DefWindowProc (hWnd, message, wParam, lParam);
  96.       break;
  97.     }
  98.   return (0L);
  99.   }
  100.