Home › Forums › TWAIN Classic › Direct Acquire without UI
- This topic has 1 reply, 2 voices, and was last updated 10 years, 10 months ago by spike.
- AuthorPosts
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;
}
}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.- AuthorPosts