GetFloaterHandle example for Delphi
The following is an alternative way of coding the PasteFloater 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.
procedure TForm1.PasteFloater2Click(Sender: TObject);
var
{Declare the variable for the Combine operation. }
MyOp: Integer;
{Declare the variable for the saved region. }
SavedRgn: L_HRGN;
{Declare the variables for the client area coordinates. }
LCRgnX, LCRgnY , LCRgnWidth, LCRgnHeight: Integer;
{Declare the variables for the bitmap coordinates. }
LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight: Integer;
begin
{Exit this routine if there is no region. }
If Lead1.HasRgn = False Then Exit;
{Save the region that is in the floater. }
SavedRgn := Lead1.GetFloaterHandle();
{Get the floater into another bitmap }
Lead2.Bitmap := Lead1.Floater;
{Get the floater's client coordinates into local variables. }
LCRgnX := Lead1.FloaterDstLeft;
LCRgnY := Lead1.FloaterDstTop;
LCRgnWidth := Lead1.FloaterDstWidth;
LCRgnHeight := Lead1.FloaterDstHeight;
{Translate the client coordinates to bitmap coordinates. }
LBRgnX := Round((LCRgnX - Lead1.DstLeft) / ZoomFactorX + Lead1.SrcLeft);
LBRgnY := Round((LCRgnY - Lead1.DstTop) / ZoomFactorY + Lead1.SrcTop);
LBRgnWidth := Lead1.FloaterWidth;
LBRgnHeight := Lead1.FloaterHeight;
{Delete the floater. }
Lead1.FloaterVisible := False;
Lead1.Floater := 0;
{Set the saved region to use as a mask for the Combine method. }
Lead1.SetRgnHandle(SavedRgn, LBRgnX, LBRgnY, L_RGN_SET);
{Use the Combine method to paste the Lead2 bitmap into the Lead1 bitmap. }
MyOp := CB_OP_ADD or CB_DST_0; {Operation flags for a simple paste. }
Lead1.Combine(LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight, Lead2.Bitmap, 0, 0, MyOp);
{Repaint the part of the client area that has changed. }
Lead1.RepaintRect(LCRgnX, LCRgnY, LCRgnWidth, LCRgnHeight, False);
{Free the region. }
Lead1.FreeRgn;
{Delete the region handle. }
Lead1.DeleteRgnHandle(SavedRgn);
end;