Accusoft.TwainPro9.ActiveX
Handling Events with the TwainPRO COM Object

The TwainPRO sample demonstrates how to handle events with the TwainPRO COM object.

The Event handler prototypes are located in TwainPro9Events.h in the private section of the CTwainPRO class. The Event handler parameters contain a DWORD instance pointer and a DWORD object ID followed by the same parameter list as the corresponding ActiveX event.

The following tutorial demonstrates adding a PostScan event to the TwainPRO sample.

1. Add the Event Handler Prototype to TwnPRODlg.h

C++ Example
Copy Code
// This code demonstrates how to use the static keyword when defining the event handler
class CTwnPRODlg : public CDialog
{
static HRESULT PostScan(void* instancePtr, DWORD objID, VARIANT_BOOL Cancel);

2. After Creating the Objects in TwnPRODlg.cpp, Set the PostScan Event to the Function Name PostScan

C++ Example
Copy Code
// This code demonstrates how to create a TwainPRO object
ppCTwainPRO = new CTwainPRO(this, 1);
pTwainPRO = ppCTwainPRO->pTwainPRO;
// Set the application window handle to TwainPRO.
// This property was added specifically for creating
// TwainPRO in-proc and the control will not work
// unless this property is set with the application's
// window handle.
pTwainPRO->PuthParentWnd(HandleToLong(m_hWnd));
// Set up the PostScan event handler
ppCTwainPRO->SetPostScanEvent(PostScan);

3. Implement the Event Handler

The first line in the event handler typecasts the instance pointer to a CTwnPRODlg class pointer in order to gain access to the objects on the dialog.

The Object ID is the object ID that is passed as the second parameter when a new TwainPRO object is created. If there are multiple TwainPRO objects, use the Object ID to determine which object generated the event.

C++ Example
Copy Code
// This code demonstrates how to implement an event handler
HRESULT CTwnPRODlg::PostScan
(
void* instancePtr,
DWORD ObjID,
VARIANT_BOOL Cancel
)
{
CTwnPRODlg *p = (CTwnPRODlg *) instancePtr;
char buf[_MAX_PATH];
p->GetDlgItemText(IDC_FILENAME, buf, _MAX_PATH);
p->pTwainPRO->SaveFile(buf);
return S_OK;
}
See Also

 

 


©2017. Accusoft Corporation. All Rights Reserved.

Send Feedback