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

  1. /*
  2.  *
  3.  *  Functions demonstrated in this program: FloodFill
  4.  *  Compiler version: C 5.1
  5.  *
  6.  *  This program demonstrates the use of FloodFill function.
  7.  *  This function fills an area of the suface with the current
  8.  *  brush. The area is assumed to be bounded by the given 
  9.  *  rgbColor. The function begins at the point specified by
  10.  *  the logical coordinates X, Y and continues in all directions
  11.  *  to the color boundary.
  12.  *
  13.  */
  14.  
  15. #include <windows.h>
  16.  
  17. static HANDLE hInst;
  18. static char szFileName[] = "floodfil";
  19. static char szFuncName[] = "FloodFill";
  20.  
  21. long FAR PASCAL WindowProc (HANDLE, unsigned, WORD, LONG);
  22.  
  23. /**************************************************************************/
  24.  
  25. int PASCAL WinMain  (hInstance, hPrevInstance, lpszCmdLine, cmdShow)
  26. HANDLE hInstance, hPrevInstance;
  27. LPSTR  lpszCmdLine;
  28. int    cmdShow;
  29.   {
  30.   MSG  msg;
  31.  
  32.   WindowInit (hInstance, hPrevInstance, cmdShow);
  33.   while (GetMessage ( (LPMSG)&msg, NULL, 0, 0))
  34.     {
  35.     TranslateMessage ( (LPMSG)&msg);
  36.     DispatchMessage ( (LPMSG)&msg);
  37.     }
  38.   exit (msg.wParam);
  39.   }
  40. /**************************************************************************/
  41.  
  42. BOOL WindowInit (hInstance, hPrevInstance, cmdShow)
  43. HANDLE hInstance, hPrevInstance;
  44. int cmdShow;
  45.   {
  46.   HWND  hWnd;
  47.  
  48.   if (!hPrevInstance)
  49.      {
  50.      WNDCLASS rClass;
  51.  
  52.      rClass.style         = CS_HREDRAW | CS_VREDRAW;
  53.      rClass.lpfnWndProc   = WindowProc;
  54.      rClass.cbClsExtra    = 0;
  55.      rClass.cbWndExtra    = 0;
  56.      rClass.hInstance     = hInstance;
  57.      rClass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  58.      rClass.hIcon         = LoadIcon (hInstance, IDI_APPLICATION);
  59.      rClass.hbrBackground = GetStockObject (WHITE_BRUSH);
  60.      rClass.lpszMenuName  = (LPSTR) NULL;
  61.      rClass.lpszClassName = (LPSTR) szFileName;
  62.    
  63.      if (!RegisterClass ( ( LPWNDCLASS) &rClass))
  64.        return FALSE;
  65.      }
  66.  
  67.   hInst = hInstance;
  68.  
  69.   hWnd = CreateWindow ( (LPSTR) szFileName, (LPSTR) szFuncName,
  70.                       WS_OVERLAPPEDWINDOW,
  71.                       CW_USEDEFAULT, CW_USEDEFAULT,
  72.                       CW_USEDEFAULT, CW_USEDEFAULT,
  73.                       (HWND) NULL, (HMENU) NULL,
  74.                       (HANDLE) hInstance, (LPSTR) NULL);
  75.  
  76.   ShowWindow (hWnd, cmdShow);
  77.   UpdateWindow (hWnd);
  78.  
  79.   return TRUE;
  80.   }
  81. /**************************************************************************/
  82.  
  83. long FAR PASCAL WindowProc (hWnd, message, wParam, lParam)
  84. HWND        hWnd;
  85. unsigned    message;
  86. WORD        wParam;
  87. LONG        lParam;
  88.   {
  89.   PAINTSTRUCT ps;
  90.  
  91.   switch (message)
  92.     {
  93.     case WM_PAINT:
  94.       BeginPaint (hWnd, (LPPAINTSTRUCT)&ps);
  95.       FunctionDemonstrated (hWnd, (PAINTSTRUCT *)&ps);
  96.       EndPaint (hWnd, (LPPAINTSTRUCT)&ps);
  97.       break;
  98.  
  99.     case WM_DESTROY:
  100.       PostQuitMessage (0);
  101.       break;
  102.  
  103.     default:
  104.       return (DefWindowProc (hWnd, message, wParam, lParam));
  105.       break;
  106.     }
  107.   return (0L);
  108.   }
  109.  
  110. /*************************************************************************/
  111. /*              FUNCTION DEMONSTRATED HERE - LOOK HERE                   */
  112. /*************************************************************************/
  113.  
  114. FunctionDemonstrated (hWnd, pps)
  115. HWND hWnd;
  116. PAINTSTRUCT *pps;
  117.   {
  118.   HDC hDC = pps->hdc;
  119.   HPEN hPen;
  120.   HPEN hMyPen;
  121.   HBRUSH hBrush;
  122.   HBRUSH hMyBrush;
  123.   BOOL bFilled;
  124.  
  125. /*  Creating a rectangle to fill */
  126.   hMyPen = CreatePen (0, 1, RGB (0, 0, 255));
  127.   hPen = SelectObject (hDC, hMyPen);
  128.   Rectangle (hDC, 0, 0, 500, 200);
  129.   hMyPen = SelectObject (hDC, hPen);
  130.   DeleteObject (hMyPen);
  131.  
  132. /* Getting a brush to do the filling */
  133.   hMyBrush = GetStockObject (GRAY_BRUSH);
  134.   hBrush = SelectObject (hDC, hMyBrush);
  135.  
  136.   FloodFill (hDC, 52, 48, RGB (0, 0, 255));
  137.  
  138.   hMyBrush = SelectObject (hDC, hBrush);
  139.  
  140.   return TRUE;
  141.   }
  142.