hDocCleanRgn example for Visual Basic

Private Declare Function CreateRectRgn Lib "gdi32" (ByVal X1 As Long, ByVal Y1 As Long, ByVal X2 As Long, ByVal Y2 As Long) As Long
Private Declare Function DeleteObject Lib "gdi32" (ByVal hObject As Long) As Long
Private Declare Function CombineRgn Lib "gdi32" (ByVal hDestRgn As Long, ByVal hSrcRgn1 As Long, ByVal hSrcRgn2 As Long, ByVal nCombineMode As Long) As Long
Public hRgnAll As Long
Private Const RGN_OR = 2

'Declare the RasterProcess object WithEvents
Public WithEvents RasterProc As LEADRasterProcess

'Create the RasterProcess object and UnlockSupport
Private Sub Form_Load()
'.....
    Set RasterProc = CreateObject("LEADRasterProcess.LEADRasterProcess. ")
    LEADRasterView1.Raster.UnlockSupport L_SUPPORT_DOCUMENT, "TestKey"
'.....
End Sub

Private Sub Command62_Click()
'HolePunch Remove
'This example updates a windows region with all removed hole punches
'For the example, a windows region is updated and then converted to a LEAD region
'but in practice it would easier and faster to just update a LEAD region
'The HOLEPUNCH_USE_DPI flag instructs the API to determine the size of the hole punches
'based on the image DPI
'The image is modified
'The HolePunch Event is used to display information about each hole punch removed

Dim nRet As Integer
RasterProc.EnableDocCleanEvents = True
nRet = RasterProc.HolePunchRemove(LEADRasterView1.Raster, _
                                  HOLEPUNCH_SINGLE_REGION Or HOLEPUNCH_USE_DPI Or HOLEPUNCH_USE_COUNT Or HOLEPUNCH_USE_LOCATION, _
                                  2, 4, 0, 0, 0, 0, HOLEPUNCH_LEFT)

If (nRet = 0) Then
    LEADRasterView1.Raster.FreeRgn
    LEADRasterView1.Raster.SetRgnHandle RasterProc.hDocCleanRgn, 0, 0, L_RGN_SET
    RasterProc.hDocCleanRgn = 0 'no longer need rgn
    LEADRasterView1.RgnFrameType = RGNFRAME_COLOR
End If
End Sub

Private Sub RasterProc_HolePunchRemove(ByVal hRgn As Long, ByVal fBoundingRectLeft As Single, ByVal fBoundingRectTop As Single, ByVal fBoundingRectWidth As Single, ByVal fBoundingRectHeight As Single, ByVal iHoleIndex As Long, ByVal iHoleTotalCount As Long, ByVal iWhiteCount As Long, ByVal iBlackCount As Long)
Debug.Print "HolePunch at [Left,Top,Width,Height]" & CStr(fBoundingRectLeft) & "," & CStr(fBoundingRectTop) _
            & "," & CStr(fBoundingRectWidth) & "," & CStr(fBoundingRectHeight) _
            & " HoleIndex=" & CStr(iHoleIndex) & " TotalCount=" & CStr(iHoleTotalCount) _
            & " WhiteCount=" & CStr(iWhiteCount) & " BlackCount=" & CStr(iBlackCount)
End Sub