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

  1. /*
  2.  *   InvalidateRgn
  3.  *
  4.  *   This program demonstrates the use of the InvalidateRgn function.
  5.  *   InvalidateRgn marks the given region for painting during the next
  6.  *   "paint session." The next paint session starts after the next WM_PAINT
  7.  *   message is received by the window. InvalidateRgn is called from WinMain
  8.  *   in this sample application. UpdateWindow is called directly after
  9.  *   InvalidateRgn to send a WM_PAINT message.
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long    FAR PASCAL HelloWndProc (HWND, unsigned, WORD, LONG);
  15.  
  16. int     PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  17. HANDLE hInstance, hPrevInstance;
  18. LPSTR lpszCmdLine;
  19. int    cmdShow;
  20.   {
  21.   MSG   msg;
  22.   HWND  hWnd;
  23.   HMENU hMenu;
  24.   HRGN hRegion;
  25.   HDC  hDC;
  26.   RECT ClearRect;
  27.  
  28.   if (!hPrevInstance)
  29.     {
  30.     WNDCLASS   HelloClass;
  31.  
  32.     HelloClass.hCursor        = LoadCursor (NULL, IDC_ARROW);
  33.     HelloClass.hIcon          = LoadIcon (hInstance, NULL);
  34.     HelloClass.lpszMenuName   = (LPSTR)NULL;
  35.     HelloClass.lpszClassName  = (LPSTR)"Sample Application";
  36.     HelloClass.hbrBackground  = (HBRUSH)GetStockObject (WHITE_BRUSH);
  37.     HelloClass.hInstance      = hInstance;
  38.     HelloClass.style          = CS_HREDRAW | CS_VREDRAW;
  39.     HelloClass.lpfnWndProc    = HelloWndProc;
  40.  
  41.     if (!RegisterClass ( (LPWNDCLASS)&HelloClass))
  42.       return FALSE;
  43.     }
  44.  
  45.   hWnd = CreateWindow ( (LPSTR)"Sample Application", (LPSTR)"Sample Application",
  46.       WS_OVERLAPPEDWINDOW,
  47.       CW_USEDEFAULT, 0,
  48.       CW_USEDEFAULT, 0,
  49.       NULL, NULL, hInstance, NULL);
  50.  
  51.   ShowWindow (hWnd, cmdShow);
  52.   UpdateWindow (hWnd);
  53.  
  54.   hDC = GetDC (hWnd);
  55.   hRegion = CreateEllipticRgn (5, 5, 220, 110);
  56.  
  57.   GetClientRect (hWnd, (LPRECT) & ClearRect);
  58.   InvertRect (hDC, (LPRECT) & ClearRect);
  59.  
  60.   MessageBox (GetFocus (), (LPSTR)"Call InvalidateRgn",
  61.       (LPSTR)"I am about to...", MB_OK);
  62.  
  63.   InvalidateRgn (hWnd, hRegion, TRUE);   /*  mark the region for painting    */
  64. /*  TRUE parameter says erase first */
  65.   UpdateWindow (hWnd);  /* force a paint */
  66.  
  67.   ReleaseDC (hWnd, hDC);
  68.  
  69.   while (GetMessage ( (LPMSG) & msg, NULL, 0, 0))
  70.     {
  71.     TranslateMessage ( (LPMSG) & msg);
  72.     DispatchMessage ( (LPMSG) & msg);
  73.     }
  74.   return (int)msg.wParam;
  75.   }
  76.  
  77.  
  78. /* Procedures which make up the window class. */
  79. long    FAR PASCAL HelloWndProc (hWnd, message, wParam, lParam)
  80. HWND     hWnd;
  81. unsigned message;
  82. WORD     wParam;
  83. LONG     lParam;
  84.   {
  85.   switch (message)
  86.     {
  87.     case WM_DESTROY:
  88.       PostQuitMessage (0);
  89.       break;
  90.  
  91.     default:
  92.       return DefWindowProc (hWnd, message, wParam, lParam);
  93.       break;
  94.     }
  95.   return (0L);
  96.   }
  97.