home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / graphics / crrecrin.c < prev    next >
C/C++ Source or Header  |  1988-08-10  |  4KB  |  147 lines

  1. /*
  2.  *  Function Name:   CreateRectRgnIndirect
  3.  *  Program Name:    crrectin.c
  4.  *  SDK Version:         2.03
  5.  *  Runtime Version:     2.03
  6.  *  Microsoft C Version: 5.0
  7.  *
  8.  *  Description:
  9.  *   The program below will create a rectangular region and then invert
  10.  *   it to make it visible on the screen.
  11.  */
  12.  
  13. #include "windows.h"
  14.  
  15. long    FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  16.  
  17. /***********************************************************************/
  18.  
  19. void CALL_CreateRectRgnIndirect(hWnd, hDC)
  20. HWND hWnd;
  21. HDC hDC;
  22. {
  23.   HRGN hNewRgn;
  24.   RECT ClientRect;
  25.  
  26.   GetClientRect( hWnd, (LPRECT) & ClientRect );   /* get client area */
  27.   ClientRect.right /= 2;             /*  half client area  */
  28. /* create new region   */
  29.   hNewRgn = CreateRectRgnIndirect((LPRECT) & ClientRect);
  30.  
  31.   if (hNewRgn == NULL)                   /* Check for error */
  32.   {
  33.     MessageBox(hWnd, (LPSTR)"CreateRectRgn failed.", (LPSTR)"ERROR", MB_ICONHAND);
  34.     return;
  35.   }
  36.   InvertRgn(hDC, hNewRgn);
  37.   DeleteObject( hNewRgn );
  38.  
  39.   return;
  40. }
  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)"CreateRectRgnIndirect";
  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.   HMENU hMenu;
  80.  
  81.   if (!hPrevInstance)
  82.   {
  83. /* Call initialization procedure if this is the first instance */
  84.     if (!WinInit( hInstance ))
  85.       return FALSE;
  86.   }
  87.  
  88.   hWnd = CreateWindow((LPSTR)"CreateRectRgnIndirect",
  89.       (LPSTR)"CreateRectRgnIndirect()",
  90.       WS_OVERLAPPEDWINDOW,
  91.       CW_USEDEFAULT,
  92.       CW_USEDEFAULT,
  93.       CW_USEDEFAULT,
  94.       CW_USEDEFAULT,
  95.       (HWND)NULL,        /* no parent */
  96.   (HMENU)NULL,       /* use class menu */
  97.   (HANDLE)hInstance, /* handle to window instance */
  98.   (LPSTR)NULL        /* no params to pass on */
  99.   );
  100.  
  101. /* Make window visible according to the way the app is activated */
  102.   ShowWindow( hWnd, cmdShow );
  103.   UpdateWindow( hWnd );
  104.  
  105. /* Polling messages from event queue */
  106.   while (GetMessage((LPMSG) & msg, NULL, 0, 0))
  107.   {
  108.     TranslateMessage((LPMSG) & msg);
  109.     DispatchMessage((LPMSG) & msg);
  110.   }
  111.  
  112.   return (int)msg.wParam;
  113. }
  114.  
  115.  
  116. /* Procedures which make up the window class. */
  117. long    FAR PASCAL WndProc( hWnd, message, wParam, lParam )
  118. HWND hWnd;
  119. unsigned    message;
  120. WORD wParam;
  121. LONG lParam;
  122. {
  123.   PAINTSTRUCT ps;
  124.  
  125.   switch (message)
  126.   {
  127.  
  128.   case WM_PAINT:
  129.     BeginPaint( hWnd, (LPPAINTSTRUCT) & ps );
  130.     CALL_CreateRectRgnIndirect(hWnd, ps.hdc);
  131.     ValidateRect(hWnd, (LPRECT) NULL);
  132.     EndPaint( hWnd, (LPPAINTSTRUCT) & ps );
  133.     break;
  134.  
  135.   case WM_DESTROY:
  136.     PostQuitMessage( 0 );
  137.     break;
  138.  
  139.   default:
  140.     return DefWindowProc( hWnd, message, wParam, lParam );
  141.     break;
  142.   }
  143.   return(0L);
  144. }
  145.  
  146.  
  147.