GetFloaterHandle example for Visual Basic

The following is an alternative way of coding the PasteFloaterBtn button's click procedure in Outlining, Dragging, and Pasting a Region. This alternative uses the GetFloaterHandle and SetRgnHandle methods to specify the mask for the paste. It also shows how to use the HasRgn, FloaterWidth, and FloaterHeight properties.

Private Sub PasteFloaterBtn_Click()
    'Declare the variable for the Combine operation.
    Dim MyOp As Long
    'Declare the variable for the saved region.
    Dim SavedRgn As Long
    'Declare the variables for the client area coordinates.
    Dim LCRgnX, LCRgnY, LCRgnWidth, LCRgnHeight
    'Declare the variables for the bitmap coordinates.
    Dim LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight
    'Declare the RasterProcess object
    Dim RasterProc As New LEADRasterProcess
    
    'Exit this routine if there is no region.
    If LEADRasterView1.Raster.HasRgn = False Then Exit Sub
    'Save the region that is in the floater.
    SavedRgn = LEADRasterView1.GetFloaterHandle
    'Get the floater into another bitmap
    LEADRasterView2.ScaleMode = LEADRasterView1.ScaleMode
    LEADRasterView2.Raster.RefBitmap = False
    LEADRasterView2.Raster.Bitmap = LEADRasterView1.Floater
    'Get the floater's client coordinates into local variables.
    LCRgnX = LEADRasterView1.FloaterDstLeft
    LCRgnY = LEADRasterView1.FloaterDstTop
    LCRgnWidth = LEADRasterView1.FloaterDstWidth
    LCRgnHeight = LEADRasterView1.FloaterDstHeight
    'Translate the client coordinates to bitmap coordinates.
    LBRgnX = ((LCRgnX - LEADRasterView1.DstLeft) / ZoomFactorX) + LEADRasterView1.SrcLeft
    LBRgnY = ((LCRgnY - LEADRasterView1.DstTop) / ZoomFactorY) + LEADRasterView1.SrcTop
    LBRgnWidth = LEADRasterView1.FloaterWidth
    LBRgnHeight = LEADRasterView1.FloaterHeight
    'Delete the floater.
    LEADRasterView1.FloaterVisible = False
    LEADRasterView1.Floater = 0
    'Set the saved region to use as a mask for the Combine method.
    LEADRasterView1.Raster.SetRgnHandle SavedRgn, LBRgnX, LBRgnY, L_RGN_SET
    'Use the Combine method to paste the LEADRasterView2 bitmap into the LEADRasterView1 bitmap.
    MyOp = CB_OP_ADD + CB_DST_0 'Operation flags for a simple paste.
    RasterProc.Combine LEADRasterView1.Raster, _
                       LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight, _
                       LEADRasterView2.Raster, _
                       0, 0, MyOp
    'Repaint the part of the client area that has changed.
    LEADRasterView1.RepaintRect LCRgnX, LCRgnY, LCRgnWidth, LCRgnHeight, False
    'Free the region.
    LEADRasterView1.Raster.FreeRgn
    'Delete the region handle.
    LEADRasterView1.Raster.DeleteRgnHandle SavedRgn
End Sub