GetFloaterHandle example for C++ 5.0 and later

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.

void CTutorDlg::OnPastefloater() 
{
   ILEADRasterProcess *pRasterProc=NULL;

   CoCreateInstance(CLSID_LEADRasterProcess, NULL, CLSCTX_ALL,
                    IID_ILEADRasterProcess, (void**)&pRasterProc);

   // Variable for the Combine operation.
   long MyOp;
   // Variable for the saved region.
   long SavedRgn;
   // Variables for the client area coordinates.
   float LCRgnX, LCRgnY , LCRgnWidth, LCRgnHeight;
   // Variables for the bitmap coordinates.
   float LBRgnX, LBRgnY , LBRgnWidth, LBRgnHeight;
   // Exit this routine if there is no region.
  if(m_LEADRasterView1.GetRaster().GetHasRgn() == FALSE) return;
   // Save the region that is in the floater.
   SavedRgn = m_LEADRasterView1.GetFloaterHandle();
   // Get the floater into another bitmap
   m_LEADRasterView2.SetScaleMode(m_LEADRasterView1.GetScaleMode());
   m_LEADRasterView2.GetRaster().SetBitmap(m_LEADRasterView1.GetFloater());
   // Get the floater's client coordinates into local variables.
   LCRgnX = m_LEADRasterView1.GetFloaterDstLeft();
   LCRgnY = m_LEADRasterView1.GetFloaterDstTop();
   LCRgnWidth = m_LEADRasterView1.GetFloaterDstWidth();
   LCRgnHeight = m_LEADRasterView1.GetFloaterDstHeight();
   // Translate the client coordinates to bitmap coordinates.
   LBRgnX = ((LCRgnX - m_LEADRasterView1.GetDstLeft()) / ZoomFactorX) + m_LEADRasterView1.GetSrcLeft();
   LBRgnY = ((LCRgnY - m_LEADRasterView1.GetDstTop()) / ZoomFactorY) + m_LEADRasterView1.GetSrcTop();
   LBRgnWidth = m_LEADRasterView1.GetFloaterWidth();
   LBRgnHeight = m_LEADRasterView1.GetFloaterHeight();
   // Delete the floater.
   m_LEADRasterView1.SetFloaterVisible(FALSE);
   m_LEADRasterView1.SetFloater(0);
   // Set the saved region to use as a mask for the Combine method.
   m_LEADRasterView1.GetRaster().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.
   pRasterProc->Combine(m_LEADRasterView1.GetRaster(),
                        LBRgnX, LBRgnY, LBRgnWidth, LBRgnHeight, 
                        m_LEADRasterView2.GetRaster(),
                        0.0f, 0.0f, (CombineConstants)MyOp);
   // Repaint the part of the client area that has changed.
   m_LEADRasterView1.RepaintRect(LCRgnX, LCRgnY, LCRgnWidth, LCRgnHeight, FALSE);
   // Free the region.
   m_LEADRasterView1.GetRaster().FreeRgn();
   // Delete the region handle.
   m_LEADRasterView1.GetRaster().DeleteRgnHandle(SavedRgn);
}