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

  1. /*
  2.  *  Function Name:   ExcludeUpdateRgn
  3.  *  Program Name:    exuprg.c
  4.  *  Special Notes:
  5.  *
  6.  *  SDK Version:         2.03
  7.  *  Runtime Version:     2.03
  8.  *  Microsoft C Version: 5.1
  9.  *
  10.  *  Description:
  11.  *   This program invalidates a rectangular region, then calls the
  12.  *   ExcludeUpdateRgn function to protect the invalidated rectangle from
  13.  *   being overlayed by succeeding regions, in this case an
  14.  *   elliptical region. The display will show that the elliptical region
  15.  *   did not overlay the invalidated rectangular region.
  16.  
  17.  *   Windows Version 2.0 function demonstration application
  18.  *
  19.  */
  20.  
  21. #include "windows.h"
  22.  
  23. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  24.  
  25. /***********************************************************************/
  26.  
  27. void CALL_ExcludeUpdateRgn(hWnd, hDC)
  28. HWND hWnd;
  29. HDC hDC;
  30. {
  31.   HRGN hRgn;
  32.   RECT rect;
  33.  
  34.   rect.left=70;               /* region to invalidate  */
  35.   rect.top =70;
  36.   rect.right =200;
  37.   rect.bottom=100;
  38.  
  39.   InvalidateRect(hWnd,(LPRECT)&rect,TRUE);
  40.  
  41.   ExcludeUpdateRgn(hDC, hWnd);          /*  function demonstrated  */
  42.  
  43.   hRgn = CreateEllipticRgn( 50, 50, 400, 150);    /*  new region created  */
  44.   InvertRgn(hDC, hRgn);                           /* invert region to show */
  45.   DeleteObject(hRgn);
  46.  
  47.   return;
  48. }
  49.  
  50. /**************************************************************************/
  51.  
  52. /* Procedure called when the application is loaded for the first time */
  53. BOOL WinInit( hInstance )
  54. HANDLE hInstance;
  55. {
  56.     WNDCLASS   wcClass;
  57.  
  58.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  59.     wcClass.lpfnWndProc    = WndProc;
  60.     wcClass.cbClsExtra     =0;
  61.     wcClass.cbWndExtra     =0;
  62.     wcClass.hInstance      = hInstance;
  63.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  64.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  65.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  66.     wcClass.lpszMenuName   = (LPSTR)NULL;
  67.     wcClass.lpszClassName  = (LPSTR)"ExcludeUpdateRgn";
  68.  
  69.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  70.         /* Initialization failed.
  71.          * Windows will automatically deallocate all allocated memory.
  72.          */
  73.         return FALSE;
  74.  
  75.     return TRUE;        /* Initialization succeeded */
  76. }
  77.  
  78.  
  79. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  80. HANDLE hInstance, hPrevInstance;
  81. LPSTR lpszCmdLine;
  82. int cmdShow;
  83. {
  84.     MSG   msg;
  85.     HWND  hWnd;
  86.  
  87.     if (!hPrevInstance)
  88.         {
  89.         /* Call initialization procedure if this is the first instance */
  90.         if (!WinInit( hInstance ))
  91.             return FALSE;
  92.         }
  93.  
  94.     hWnd = CreateWindow((LPSTR)"ExcludeUpdateRgn",
  95.                         (LPSTR)"ExcludeUpdateRgn()",
  96.                         WS_OVERLAPPEDWINDOW,
  97.                         CW_USEDEFAULT,
  98.                         CW_USEDEFAULT,
  99.                         CW_USEDEFAULT,
  100.                         CW_USEDEFAULT,
  101.                         (HWND)NULL,        /* no parent */
  102.                         (HMENU)NULL,       /* use class menu */
  103.                         (HANDLE)hInstance, /* handle to window instance */
  104.                         (LPSTR)NULL        /* no params to pass on */
  105.                         );
  106.  
  107.     /* Make window visible according to the way the app is activated */
  108.     ShowWindow( hWnd, cmdShow );
  109.     UpdateWindow( hWnd );
  110.  
  111.     /* Polling messages from event queue */
  112.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  113.         {
  114.         TranslateMessage((LPMSG)&msg);
  115.         DispatchMessage((LPMSG)&msg);
  116.         }
  117.  
  118.     return (int)msg.wParam;
  119. }
  120.  
  121. /* Procedures which make up the window class. */
  122. long FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  123. HWND hWnd;
  124. unsigned message;
  125. WORD wParam;
  126. LONG lParam;
  127. {
  128.     PAINTSTRUCT ps;
  129.  
  130.     switch (message)
  131.     {
  132.  
  133.     case WM_PAINT:
  134.         BeginPaint( hWnd, (LPPAINTSTRUCT)&ps );
  135.         CALL_ExcludeUpdateRgn(hWnd, ps.hdc);
  136.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  137.         break;
  138.  
  139.     case WM_DESTROY:
  140.         PostQuitMessage( 0 );
  141.         break;
  142.  
  143.     default:
  144.         return DefWindowProc( hWnd, message, wParam, lParam );
  145.         break;
  146.     }
  147.     return(0L);
  148. }
  149.  
  150. 
  151.