GetFloaterHandle example for C++ Builder
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.
void __fastcall TForm1::PasteFloater2Click(TObject *Sender)
{
/*Declare the variable for the Combine operation. */
int MyOp;
/*Declare the variable for the saved region. */
L_HRGN SavedRgn;
/*Declare the variables for the client area coordinates. */
int LCRgnX, LCRgnY , LCRgnWidth, LCRgnHeight;
/*Declare the variables for the bitmap coordinates. */
int LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight;
/*Exit this routine if there is no region. */
if(Lead1->HasRgn == False)
return;
/*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 = (LCRgnX - Lead1->DstLeft) / ZoomFactorX + Lead1->SrcLeft;
LBRgnY = (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 | 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);
}