Replaces every pixel using the current fill settings.
#include "LtPnt.h"
L_LTPNT_API L_INT L_PntFillColorReplace(pPaint, UserDC, crColor)
Pointer to a paint handle.
Handle to a device context, such as a screen, to use as a display surface. This parameter can also be NULL. The mapping mode of the device context must be MM_TEXT.
The COLORREF value that specifies the color to be replaced.
Value | Meaning |
---|---|
SUCCESS | The function was successful. |
< 1 | An error occurred. Refer to Return Codes. |
The filling procedure will be carried out using the current fill properties. To determine the current fill properties, call L_PntGetProperty. To set or change the current fill properties, call L_PntSetProperty. For more information on the fill properties, refer to the PAINTFILL structure.
Within the PAINTFILL structure, upper and lower tolerance values can be set for the color specified in crColor. For example, if the color passed to this function has an RGB value of 40, 40 , 200, and the lower tolerance and upper tolerance set in the PAINTFILL structure are 10, 10, 10, and 5, 5, 5, respectively, then this function will replace colors from 30, 30, 190 to 45, 45, 205.
If the UserDC is not NULL, the user should set the DC boundaries before calling this function, by calling L_PntSetDCExtents.
The images below show an example of the results of calling L_PntFillColorReplace.
L_INT PntFillColorReplaceExample(HWND hWnd)
{
L_INT nRet;
pPAINTHANDLE pPaint ;
HDC hDC ;
PAINTSHAPE shape ;
PAINTFILL fill ;
RECT rcShape ;
RECT rcDCExtents ;
/* Initiate the Paint toolkit */
nRet = L_PntInit ( &pPaint );
if ( SUCCESS != nRet )
{
return nRet;
}
/* Get device context to draw on */
hDC = GetDC ( hWnd ) ;
/* Set the required shape properties */
shape.nSize = sizeof ( PAINTSHAPE ) ;
shape.dwMask = PSF_BORDERWIDTH |
PSF_BORDERCOLOR |
PSF_BACKGROUNDCOLOR;
shape.nBorderWidth = 10 ;
shape.crBorderColor = RGB ( 255, 0, 0 ) ;
shape.crBackgroundColor = RGB ( 255, 0, 0 ) ;
/* Set the new shape properties */
nRet = L_PntSetProperty ( pPaint, PAINT_GROUP_SHAPE, &shape ) ;
if(nRet != SUCCESS)
return nRet;
/* Set the coordinates with respect to the DC dimensions */
SetRect ( &rcShape, 10, 10, 60, 60 ) ;
/* Get the destination DC dimensions */
GetClientRect ( hWnd, &rcDCExtents ) ;
/* Set the toolkit user DC extents */
nRet = L_PntSetDCExtents ( pPaint, &rcDCExtents ) ;
if(nRet != SUCCESS)
return nRet;
/* Use the current shape properties to draw an ellipse to the DC (hDC) */
nRet = L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ;
if(nRet != SUCCESS)
return nRet;
SetRect ( &rcShape, 100, 10, 150, 60 ) ;
nRet = L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ;
if(nRet != SUCCESS)
return nRet;
SetRect ( &rcShape, 60, 60, 95, 95 ) ;
nRet = L_PntDrawShapeRectangle ( pPaint, hDC, &rcShape ) ;
if(nRet != SUCCESS)
return nRet;
SetRect ( &rcShape, 10, 100, 60, 150 ) ;
nRet = L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ;
if(nRet != SUCCESS)
return nRet;
SetRect ( &rcShape, 100, 100, 150, 150 ) ;
nRet = L_PntDrawShapeEllipse ( pPaint, hDC, &rcShape ) ;
if(nRet != SUCCESS)
return nRet;
/* Set the required fill properties */
fill.nSize = sizeof ( PAINTFILL ) ;
fill.dwMask = PFF_STYLE ;
fill.nStyle = PAINT_FILL_STYLE_GRADIENT ;
/* Set the new fill properties */
nRet = L_PntSetProperty ( pPaint, PAINT_GROUP_FILL, &fill ) ;
if(nRet != SUCCESS)
return nRet;
/* Fill the target area */
nRet = L_PntFillColorReplace ( pPaint, hDC, RGB ( 255, 0, 0 ) ) ;
if(nRet != SUCCESS)
return nRet;
/* Release the device context */
ReleaseDC ( hWnd, hDC ) ;
/* Free the paint tools handle */
L_PntFree ( pPaint ) ;
return SUCCESS ;
}