CompletePaste Example VC++

This example copies the area bound by a user-drawn selection rectangle to a new page.

void CImgEdit1Dlg::OnCopyPaste() 
{
    // This would copy the area bounded by a user drawn
    // selection rectangle to a new page
    // Global blnIsRectangle As Boolean
    // The value of blnIsRectangle is set in the
    // SelectionRectDrawn event
    if(!blnIsRectangle)
    {
      AfxMessageBox ("No rectangle drawn", MB_ICONEXCLAMATION);
      return;
    }
    
    // If no parameters specified will copy area bounded
    // by rectangle
    VARIANT evt; V_VT(&evt) = VT_ERROR; // set to default
    ImgEdit1.ClipboardCopy(evt,evt,evt,evt);
    // Create 8 1/2 X 11 black and white 300 dpi image
    VARIANT vRes; V_VT(&vRes) = VT_I4; V_I4(&vRes) = 300;
    VARIANT vPageType; V_VT(&vPageType) = VT_I2; // set to PageType for saveas
    V_I2(&vPageType) = 1; // wiPageTypeBW
    ImgEdit1.DisplayBlankImage(2550, 3300, vRes, vRes, vPageType); 
    
    // Reset blnIsRectangle
    blnIsRectangle = FALSE;
    
    // Paste data to new image, call CompletePaste to commit
    // the paste operation
    ImgEdit1.ClipboardPaste(evt,evt);
    ImgEdit1.CompletePaste();
}