TwainPRO 9 for ActiveX - User Guide > Getting Started > 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.
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); |
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); |
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; } |