TWAIN Working Group

Newsletter Signup
Donate
Help keep TWAIN free
  • About TWAIN
    • What’s New?
    • News
    • Events
    • Membership
    • Consider a Donation
    • Contact Us
  • Why TWAIN?
  • Developers
    • Driver Developer
    • Application Developer
    • TWAIN Features
    • Specification & Tools
    • Self Certification Process
  • Support Forums
  • Scanner End-User
  • Find Certified Drivers
    • Facebook
    • LinkedIn
    • Vimeo

Direct Acquire without UI

Forums › TWAIN Classic › Direct Acquire without UI

  • This topic has 1 reply, 2 voices, and was last updated 7 years, 7 months ago by spike.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • June 10, 2013 at 12:38 pm #22852 Reply
    kp121212
    Participant
    • Topics - 1
    • Replies - 0
    • Total Posts - 1

    Hi,

    I’m developping a Twain C++ Wrapper, and I want to be able to acquire in one clic.

    What I have at the moment is you clic “Acquire” button and it open the confirmation window : http://puu.sh/3cvB1.png
    What I want is that the window don’t appears, and that the scanner direct runs and transfer the image.

    Is it possible ?

    Here is my Acquire function :

    int acquire()
    {
    int* truc;
    HWND hwnd = CreateWindow ("STATIC", "", WS_POPUPWINDOW, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, CW_USEDEFAULT, HWND_DESKTOP, 0, g_hinstDLL, 0);
    if (hwnd == 0)
    {
    std::cout << "error hwd create" << std::endl;
    return 0;
    }
    SetWindowPos (hwnd, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOSIZE);
    TW_UINT16 rc;
    int image = 0;

    BLOCK_BEGIN(1)

    rc = (*g_pDSM_Entry) (&g_AppID, 0, DG_CONTROL, DAT_PARENT, MSG_OPENDSM, (TW_MEMREF) &hwnd);

    if (rc != TWRC_SUCCESS)
    {
    std::cout << "error open dsm" << std::endl;
    EXIT_CURRENT_BLOCK
    }
    BLOCK_BEGIN(2)

    TW_IDENTITY srcID;

    ZeroMemory (&srcID, sizeof(srcID));
    rc = (*g_pDSM_Entry) (&g_AppID, 0, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &srcID);

    if(rc == TWRC_FAILURE)
    {
    std::cout << "error get default name" << std::endl;
    EXIT_CURRENT_BLOCK
    }

    rc = (*g_pDSM_Entry) (&g_AppID, 0, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &srcID);

    if(rc != TWRC_SUCCESS)
    {
    std::cout << "error get default name2" << std::endl;
    EXIT_CURRENT_BLOCK
    }
    BLOCK_BEGIN(3)

    TW_USERINTERFACE ui;
    ui.ShowUI = TRUE;
    ui.ModalUI = FALSE;
    ui.hParent = hwnd;

    rc = (*g_pDSM_Entry) (&g_AppID, &srcID, DG_CONTROL, DAT_USERINTERFACE, MSG_ENABLEDS, &ui);

    if (rc != TWRC_SUCCESS)
    {
    std::cout << "error get default name3" << std::endl;
    EXIT_CURRENT_BLOCK
    }

    MSG msg;
    TW_EVENT event;
    TW_PENDINGXFERS pxfers;

    while(GetMessage ((LPMSG) &msg, 0, 0, 0))
    {
    // Each window message must be forwarded to the default data source.

    event.pEvent = (TW_MEMREF) &msg;
    event.TWMessage = MSG_NULL;

    rc = (*g_pDSM_Entry) (&g_AppID, &srcID, DG_CONTROL, DAT_EVENT, MSG_PROCESSEVENT, (TW_MEMREF) &event);

    if (rc == TWRC_NOTDSEVENT)
    {
    TranslateMessage ((LPMSG) &msg);
    DispatchMessage ((LPMSG) &msg);
    continue;
    }

    if (event.TWMessage == MSG_CLOSEDSREQ)
    break;

    if (event.TWMessage == MSG_XFERREADY)
    {

    TW_IMAGEINFO ii;
    rc = (*g_pDSM_Entry) (&g_AppID, &srcID, DG_IMAGE, DAT_IMAGEINFO, MSG_GET, (TW_MEMREF) &ii);

    if (rc == TWRC_FAILURE)
    {

    (*g_pDSM_Entry) (&g_AppID, &srcID, DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, (TW_MEMREF) &pxfers);

    std::cout << "error image info" << std::endl;
    break;
    }

    if (ii.Compression != TWCP_NONE ||
    ii.BitsPerPixel != 8 &&
    ii.BitsPerPixel != 24)
    {

    (*g_pDSM_Entry) (&g_AppID, &srcID, DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, (TW_MEMREF) &pxfers);

    std::cout << "error image compression" << std::endl;
    break;
    }


    TW_UINT32 handle;

    rc = (*g_pDSM_Entry) (&g_AppID, &srcID, DG_IMAGE, DAT_IMAGENATIVEXFER, MSG_GET, (TW_MEMREF) &handle);


    if (rc != TWRC_XFERDONE)
    {
    // Cancel all remaining transfers.

    (*g_pDSM_Entry) (&g_AppID, &srcID, DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, (TW_MEMREF) &pxfers);



    std::cout << "transfer aborted" << std::endl;
    break;
    }



    LPBITMAPINFOHEADER lpbmih;
    lpbmih = (LPBITMAPINFOHEADER) GlobalLock ((HANDLE) handle);
    image = xferDIB8toImage (lpbmih);



    if (image == 0)
    std::cout << "error transfer image" << std::endl;

    GlobalUnlock ((HANDLE) handle);

    GlobalFree ((HANDLE) handle);

    // Cancel all remaining transfers.

    (*g_pDSM_Entry) (&g_AppID, &srcID, DG_CONTROL, DAT_PENDINGXFERS, MSG_RESET, (TW_MEMREF) &pxfers);

    // Convert TWRC_XFERDONE to TWRC_SUCCESS so that appropriate value
    // is returned.

    rc = TWRC_SUCCESS;

    break;
    }
    }
    June 11, 2013 at 7:35 pm #25908 Reply
    spike
    Participant
    • Topics - 10
    • Replies - 139
    • Total Posts - 149

    Start by changing

    ui.ShowUI = TRUE;

    to

    ui.ShowUI = FALSE;

    That tells the scanner driver to enable itself for scanning without its UI.
    Normally, this causes the scanner to immediately start scanning with the current settings…
    Note that the ‘current settings’ will be an unpredictable mixture of TWAIN defaults and whatever your scanner feels like.
    You should plan on setting ICAP_PIXELTYPE and ICAP_XRESOLUTION at a minimum, unless you really don’t care about even those settings.

    Other suggestion: disable the scanner when you are done with the scan job, and close the scanner when you are ‘done scanning’.
    Many applications close the scanner after every scan job, but closing & opening the scanner does take a few seconds with most scanners.

  • Author
    Posts
Viewing 2 posts - 1 through 2 (of 2 total)
Reply To: Direct Acquire without UI
Your information:




Quick Links

Service Providers
TWAIN Support Forums
Membership
Contact Us
Privacy Policy

Newsletter Signup

TWAIN Working Group Family

TWAIN Working Group
TWAIN Direct®
TWAIN Resources
TWAIN Certified Drivers
PDF/raster

  • Facebook
  • GitHub
  • LinkedIn
  • Vimeo

Recent Topics

  • EPSON V600 TWAIN and WIA on Windows 10
  • When and how to use WaitForEvents command ?
  • Problem enumerating list of installed scanners in windows server 2012
  • Failed to create TWAIN progress! Error code is 1260.
  • To get the list of scanners from javascript client side (browser)
  • Quarterly Newsletter
  • TWAIN Working Group Membership
  • Logo Usage
  • TWAIN License
  • Contact Us
Privacy Policy • Privacy Tools • Copyright © 2021 TWAIN Working Group • by iHwy, LLC • Log in

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.