The following example uses a rectangle to update a clipping region and then draws a rectangle that demonstrates the updated clipping region.
C++
VOID Example_SetClip4(HDC hdc)
{
Graphics graphics(hdc);
// Create a Rect object.
Rect clipRect(100, 50, 200, 100);
// Set the clipping region with hRegion.
graphics.SetClip(clipRect);
// Fill a rectangle to demonstrate the clipping region.
graphics.FillRectangle(&SolidBrush(Color(255, 0, 0, 0)), 0, 0, 500, 500);
}
PowerBASIC
SUB GDIP_SetClipRect (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pBrush AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Create a SolidBrush
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 0, 0, 255), pBrush)
' // Set the clipping region to its exclusion.
hStatus = GdipSetClipRect(pGraphics, 100, 50, 200, 200, %CombineModeReplace)
' // Fill a rectangle to demonstrate the clipping region.
hStatus = GdipFillRectangle(pGraphics, pBrush, 0, 0, 400, 340)
' // Cleanup
IF pBrush THEN GdipDeleteBrush(pBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetClipRect.png)
The following example sets a clipping region and updates the clipping region. It then draws rectangles to demonstrate the effective clipping region.
SUB GDIP_SetClipRect2 (BYVAL hdc AS DWORD)
LOCAL hStatus AS LONG
LOCAL pGraphics AS DWORD
LOCAL pBrush AS DWORD
LOCAL pBlackPen AS DWORD
LOCAL pRedPen AS DWORD
hStatus = GdipCreateFromHDC(hdc, pGraphics)
' // Set the clipping region.
hStatus = GdipSetClipRect(pGraphics, 0.5!, 0.5!, 200.5!, 200.5!, %CombineModeReplace)
' // Update the clipping region to the portion of the rectangle that
' // intersects with the current clipping region.
hStatus = GdipSetClipRect(pGraphics, 100.5!, 100.5!, 200.5!, 200.5!, %CombineModeIntersect)
' // Fill a rectangle to demonstrate the effective clipping region.
hStatus = GdipCreateSolidFill(GDIP_ARGB(255, 0, 0, 255), pBrush)
hStatus = GdipFillRectangle(pGraphics, pBrush, 0, 0, 500, 500)
' // Reset the clipping region to infinite.
hStatus = GdipResetClip(pGraphics)
' // Draw clipRect and intersectRect.
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1, %UnitWorld, pBlackPen)
hStatus = GdipCreatePen1(GDIP_ARGB(255, 0, 0, 0), 1, %UnitWorld, pRedPen)
hStatus = GdipDrawRectangle(pGraphics, pBlackPen, 0.5!, 0.5!, 200.5!, 200.5!)
hStatus = GdipDrawRectangle(pGraphics, pRedPen, 100.5!, 100.5!, 200.5!, 200.5!)
' // Cleanup
IF pBlackPen THEN GdipDeletePen(pBlackPen)
IF pRedPen THEN GdipDeletePen(pRedPen)
IF pBrush THEN GdipDeleteBrush(pBrush)
IF pGraphics THEN GdipDeleteGraphics(pGraphics)
END SUB
(http://www.jose.it-berater.org/captures/GdipSetClipRect2.png)