GetRgnHandle example for C++ Builder
The following code creates a region, saves its handle and adds the saved region beside the current region.
void __fastcall TForm1::Button1Click(TObject *Sender)
{
/*Declare local variables.*/
int OffsetX, OffsetY;
HRGN SavedRegion;
/*Initialize the variables that we will manipulate to simulate mouse coordinates.*/
OffsetX = Lead1->BitmapWidth / 8;
OffsetY = Lead1->BitmapHeight / 6;
/*Create an elliptical region.*/
Lead1->SetRgnEllipse(OffsetX, OffsetY, OffsetX, OffsetY, L_RGN_SET);
/*Save a copy of the region.*/
SavedRegion = (HRGN) Lead1->GetRgnHandle();
/*Offset original Region*/
Lead1->OffsetRgn(OffsetX / 2, OffsetY / 2);
/*Add the saved region to the bitmap, offsetting it so that we can see it.*/
Lead1->SetRgnHandle((L_HRGN)SavedRegion, OffsetX, OffsetY, L_RGN_OR);
/*Delete the saved region.*/
Lead1->DeleteRgnHandle((L_HRGN)SavedRegion);
/*Fill the bitmap region with blue.*/
Lead1->Fill(RGB(0, 0, 255));
/*Free the bitmap region.*/
Lead1->FreeRgn();
/*Repaint the image so that we can see how the image was updated.*/
Lead1->ForceRepaint();
}