GetScanCapability Example VC++

This example uses SetScanCapability to specify the Image Type for scanning, without using the scanner's TWAIN dialog box.

void CNewscanDlg::OnCapability() 
{
// User is given the option to select an Image Type for scanning
// of black and white, grayscale or color. The option selected
// is stored in a global variable ScanType.
#define IT_BW  1
#define IT_GRAY8  4
#define IT_RGB 16
#define CAP_SCAN_IMAGE_TYPE 100
#define CAP_SCAN_IMAGE_TYPES_SUPPORTED 1
    VARIANT vScanImgType;
    VARIANT vCap; V_VT(&vCap) = VT_I2;
    // Global Scantype as integer
    // Scanner must be open for Capability check.
    ImgScan1.OpenScanner();
    // See what image types the scanner supports.
    vScanImgType = 
        ImgScan1.GetScanCapability(CAP_SCAN_IMAGE_TYPES_SUPPORTED);
    if(V_VT(&vScanImgType) = VT_ERROR)
        AfxMessageBox ("Unable to get Supported Image Types");
    // Find out if the type the user selected is supported.
    // If so, set the capability to that image type.
    switch (m_iScanType)
        {
    case 1:
        if(V_I4(&vScanImgType) & IT_BW)
                {  
                     V_I2(&vCap)= IT_BW;
                     ImgScan1.SetScanCapability (CAP_SCAN_IMAGE_TYPE,vCap);
                }
        else
           AfxMessageBox ("Black & White image type is not supported by your scanner");
                break;
    case 2:
        if(V_I4(&vScanImgType) & IT_GRAY8)
                {
                     V_I2(&vCap)= IT_GRAY8;
                     ImgScan1.SetScanCapability (CAP_SCAN_IMAGE_TYPE,vCap);
                 }
        else
           AfxMessageBox ("Grayscale image type is not supported by your scanner");
                break;    
    case 3:
        if(V_I4(&vScanImgType) & IT_RGB)
                {
                    V_I2(&vCap)= IT_RGB;
                    ImgScan1.SetScanCapability( CAP_SCAN_IMAGE_TYPE,vCap);
                }
        else
           AfxMessageBox ("Color image type is not supported by your scanner");
        }
}