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

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