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

  1. /*
  2.  *  Function Name:   EqualRgn
  3.  *  Program Name:    eqrgn.c
  4.  *
  5.  *  Description:
  6.  *   This function will compare the coordinates of two regions.  If
  7.  *   both regions are the same size and in the same place, a nonzero
  8.  *   value will return.  Otherwise a zero is returned.
  9.  *
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. long FAR PASCAL WndProc(HWND, unsigned, WORD, LONG);
  15.  
  16. /***********************************************************************/
  17.  
  18. void CALL_EqualRgn(hWnd, hDC)
  19. HWND hWnd;
  20. HDC hDC;
  21. {
  22.   HRGN hRgn1, hRgn2;
  23.   BOOL bEqual;
  24.  
  25.   MessageBox(hWnd, "Creating two rectangular regions at \
  26. (30,30)-(90,90)...", "EqualRgn", MB_OK);
  27.  
  28.   hRgn1 = CreateRectRgn(30, 30, 90, 90);
  29.   hRgn2 = CreateRectRgn(30, 30, 90, 90);
  30.   InvertRgn(hDC, hRgn1);                        /* make region visible  */
  31.  
  32.   bEqual = EqualRgn(hRgn1, hRgn2);        /* compare regions       */
  33.  
  34.   if (bEqual)
  35.     TextOut (hDC, 10, 10, (LPSTR)"Regions are equal", 17);
  36.   else
  37.     TextOut (hDC, 10, 10, (LPSTR)"Regions are not equal", 21);
  38.  
  39.   DeleteObject( hRgn1 );
  40.   DeleteObject( hRgn2 );
  41.  
  42.   return;
  43. }
  44.  
  45. /**************************************************************************/
  46.  
  47. /* Procedure called when the application is loaded for the first time */
  48. BOOL WinInit( hInstance )
  49. HANDLE hInstance;
  50. {
  51.     WNDCLASS   wcClass;
  52.  
  53.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  54.     wcClass.lpfnWndProc    = WndProc;
  55.     wcClass.cbClsExtra     =0;
  56.     wcClass.cbWndExtra     =0;
  57.     wcClass.hInstance      = hInstance;
  58.     wcClass.hIcon          = LoadIcon( hInstance,NULL );
  59.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  60.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  61.     wcClass.lpszMenuName   = (LPSTR)NULL;
  62.     wcClass.lpszClassName  = (LPSTR)"EqualRgn";
  63.  
  64.     if (!RegisterClass( (LPWNDCLASS)&wcClass ) )
  65.         /* Initialization failed.
  66.          * Windows will automatically deallocate all allocated memory.
  67.          */
  68.         return FALSE;
  69.  
  70.     return TRUE;        /* Initialization succeeded */
  71. }
  72.  
  73.  
  74. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  75. HANDLE hInstance, hPrevInstance;
  76. LPSTR lpszCmdLine;
  77. int cmdShow;
  78. {
  79.     MSG   msg;
  80.     HWND  hWnd;
  81.  
  82.     if (!hPrevInstance)
  83.         {
  84.         /* Call initialization procedure if this is the first instance */
  85.         if (!WinInit( hInstance ))
  86.             return FALSE;
  87.         }
  88.  
  89.     hWnd = CreateWindow((LPSTR)"EqualRgn",
  90.                         (LPSTR)"EqualRgn()",
  91.                         WS_OVERLAPPEDWINDOW,
  92.                         CW_USEDEFAULT,
  93.                         CW_USEDEFAULT,
  94.                         CW_USEDEFAULT,
  95.                         CW_USEDEFAULT,
  96.                         (HWND)NULL,        /* no parent */
  97.                         (HMENU)NULL,       /* use class menu */
  98.                         (HANDLE)hInstance, /* handle to window instance */
  99.                         (LPSTR)NULL        /* no params to pass on */
  100.                         );
  101.  
  102.     /* Make window visible according to the way the app is activated */
  103.     ShowWindow( hWnd, cmdShow );
  104.     UpdateWindow( hWnd );
  105.  
  106.     /* Polling messages from event queue */
  107.     while (GetMessage((LPMSG)&msg, NULL, 0, 0))
  108.         {
  109.         TranslateMessage((LPMSG)&msg);
  110.         DispatchMessage((LPMSG)&msg);
  111.         }
  112.  
  113.     return (int)msg.wParam;
  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_EqualRgn(hWnd, ps.hdc);
  131.         EndPaint( hWnd, (LPPAINTSTRUCT)&ps );
  132.         break;
  133.  
  134.     case WM_DESTROY:
  135.         PostQuitMessage( 0 );
  136.         break;
  137.  
  138.     default:
  139.         return DefWindowProc( hWnd, message, wParam, lParam );
  140.         break;
  141.     }
  142.     return(0L);
  143. }
  144.