L_TwainGetDeviceEventData

#include "lttwn.h"

L_LTTWN_API L_INT L_TwainGetDeviceEventData(hSession, pDeviceEvent)

HTWAINSESSION hSession;

/* handle to an existing TWAIN session */

pTW_DEVICEEVENT pDeviceEvent;

/* pointer to a structure */

Gets information for a specific device event.

Parameter

Description

hSession

Handle to an existing TWAIN session. This handle is obtained by calling the L_TwainInitSession function.

pDeviceEvent

Pointer to a TW_DEVICEEVENT structure that references the required device event capability. This structure must be allocated and will be filled with data corresponding to the required capability to get.

Returns

SUCCESS

The function was successful.

< 1

An error occurred. Refer to Return Codes.

Comments

This function should be called inside LTWAINDEVICEEVENTCALLBACK callback to get the device event information.

To get the status for each device event, call L_TwainSetDeviceEventCallback function.

To get the CAP_DEVICEEVENT capability values, call L_TwainGetDeviceEventCapability function.

To set the CAP_DEVICEEVENT capability values, call L_TwainSetDeviceEventCapability function.

To rest the CAP_DEVICEEVENT capability value to the default, call L_TwainResetDeviceEventCapability function.

For information about TW_DEVICEEVENT, refer to the TWAIN 1.9 specification from the site "http://www.twain.org/".

Required DLLs and Libraries

LTTWN

For a listing of the exact DLLs and Libraries needed, based on the toolkit version, refer to Files To Be Included With Your Application.

See Also

Functions:

L_TwainSetDeviceEventCallback, L_TwainSetDeviceEventCapability, L_TwainGetDeviceEventCapability, L_TwainResetDeviceEventCapability, LTWAINDEVICEEVENTCALLBACK

Topics:

Getting and Setting Capabilities

 

TWAIN Functionality: Capability Functions

Example

float MyFix32ToFloat(TW_FIX32 * ptwFix)
{
   float Floater = 0;
   Floater = (float)ptwFix->Whole + (float)ptwFix->Frac / (float)65536.0;
   return Floater;
}

L_INT EXT_CALLBACK DeviceEventCB(HTWAINSESSION hSession, L_VOID * /*pUserData*/)
{
   TW_DEVICEEVENT twDevice;
   memset(&twDevice, 0, sizeof(TW_DEVICEEVENT));
   L_INT nRet = L_TwainGetDeviceEventData(hSession, &twDevice);
   if (nRet != SUCCESS)
      return nRet;

   L_TCHAR szBuffer[MAX_PATH];
   memset(szBuffer, 0, sizeof(szBuffer));
   wsprintf(szBuffer, TEXT("Event = %d\nEvent Name  =%s\n"), twDevice.Event, twDevice.DeviceName);
   MessageBox(NULL, szBuffer, TEXT("Notice!"), MB_OK);

   if (twDevice.Event == TWDE_CHECKBATTERY)
   {
      wsprintf(szBuffer, TEXT("Battery Minutes = %d\nBattery Percentage = %d\n"), twDevice.BatteryMinutes, twDevice.BatteryPercentage);
      MessageBox(NULL, szBuffer, TEXT("Notice!"), MB_OK);
   }
   else if (twDevice.Event == TWDE_CHECKPOWERSUPPLY)
   {
      wsprintf(szBuffer, TEXT("Power Supply =%d\n"), twDevice.PowerSupply);
      MessageBox(NULL, szBuffer, TEXT("Notice!"), MB_OK);
   }
   else if (twDevice.Event == TWDE_CHECKRESOLUTION)
   {
      wsprintf(szBuffer, TEXT("XResolution = %f\nYResolution = %f\n"), MyFix32ToFloat(&twDevice.XResolution), MyFix32ToFloat(&twDevice.YResolution));
      MessageBox(NULL, szBuffer, TEXT("Notice!"), MB_OK);
   }
   else if (twDevice.Event == TWDE_CHECKFLASH)
   {
      wsprintf(szBuffer, TEXT("FlashUsed2 =%d\n"), twDevice.FlashUsed2);
      MessageBox(NULL, szBuffer, TEXT("Notice!"), MB_OK);
   }
   else if (twDevice.Event == TWDE_CHECKAUTOMATICCAPTURE)
   {
      wsprintf(szBuffer, TEXT("Automatic Capture =%d\nTime Before First Capture =%d\nTime Between Captures = %d\n"), twDevice.AutomaticCapture, twDevice.TimeBeforeFirstCapture, twDevice.TimeBetweenCaptures);
      MessageBox(NULL, szBuffer, TEXT("Notice!"), MB_OK);
   }

   return SUCCESS;
}

 L_INT GetDeviceEventDataExample(HTWAINSESSION hSession)
{
   BITMAPHANDLE MyBtmp;
   memset(&MyBtmp, 0, sizeof(BITMAPHANDLE));

   L_TwainStartCapsNeg(hSession);
   L_TwainSetDeviceEventCallback(hSession, DeviceEventCB, NULL);
   L_TwainEndCapsNeg(hSession);

   L_TwainAcquire(hSession, &MyBtmp, sizeof(BITMAPHANDLE), NULL, LTWAIN_SHOW_USER_INTERFACE, NULL, NULL);
   return SUCCESS;
}