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

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