This example accepts four values from the user to specify the left start, top start, width and height of the area to be scanned in inches. Values are passed via SetScanCapability, which would scan the area specified without displaying the TWAIN UI.
void CNewscanDlg::OnLayout()
{
#define CAP_SCAN_IMAGE_LAYOUT 106
#define CAP_SCAN_IMAGE_HEIGHT 3
#define CAP_SCAN_IMAGE_WIDTH 4
VARIANT vScanWidth, vScanHeight;
// Open scanner for capability check.
ImgScan1.OpenScanner();
// Determine what width and height the scanner can support.
vScanWidth = ImgScan1.GetScanCapability(CAP_SCAN_IMAGE_WIDTH);
if(V_VT(&vScanWidth) == VT_ERROR)
{
AfxMessageBox ("Unable to get maximum width");
}
vScanHeight = ImgScan1.GetScanCapability(CAP_SCAN_IMAGE_HEIGHT);
if(V_VT(&vScanHeight) == VT_ERROR)
{
AfxMessageBox("Unable to get maximum height");
}
// The user enters width and height values in a dialog box.
VARIANT sngLayout[4];
V_VT(&sngLayout[0]) = VT_R4; // left start
V_VT(&sngLayout[1]) = VT_R4; // top start
V_VT(&sngLayout[2]) = VT_R4; // width
V_VT(&sngLayout[3]) = VT_R4; // height
V_R4(&sngLayout[0]) = 10; // left start
V_R4(&sngLayout[1]) = 20; // top start
V_R4(&sngLayout[2]) = 400; // width
V_R4(&sngLayout[3]) = 410; // height
COleSafeArray sa;
sa.CreateOneDim(VT_R4,4,&sngLayout);
// Validate values the user entered before trying to set them.
if (V_R4(&sngLayout[0]) + V_R4(&sngLayout[2]) > V_I4(&vScanWidth))
AfxMessageBox ("Too Wide");
if (V_R4(&sngLayout[1]) + V_R4(&sngLayout[3]) > V_I4(&vScanHeight))
AfxMessageBox("Too Long");
ImgScan1.SetScanCapability (CAP_SCAN_IMAGE_LAYOUT, sa);
}