Dynamic Web TWAIN  - TWAIN ActiveX/Plug-in, Scanner COM Control
TWAIN ActiveX/Plug-in HTTP Control/SDK

Using Dynamic Web TWAIN in Visual C++ Non-Dialog Based Applications (SDI, MDI)

Topics included in this article that describe how to use Dynamic Web TWAIN in Visual C++ non-dialog based applications are:

  • 1. Adding Dynamic Web TWAIN to a Visual C++ Project
  • 2. Adding Code to the Project
  • 1. Adding Dynamic Web TWAIN to a Visual C++ Project

    1. Start Microsoft Visual C++.
    2. On the File menu, click New to bring up the New dialog box.
    3. In the New dialog box, select MFC AppWizard (exe) project type and input DynamicWebTwainNonDlgApp in the Project Name edit box, as seen in the following figure.
    4. Click OK button.
    5. In the MFC AppWizard - Step 1 dialog box, select Single document application type and click Finish button.
    6. In the New Project Information dialog box, click OK button.
    7. On the Project menu, point to Add To Project, then click Components and Controls.
    8. In the Components and Controls Gallery dialog box , expand the Registered ActiveX Controls folder, select the DynamicWebTwain Class, click Insert.
    9. In the Microsoft Visual C++ dialog box, click OK.
    10. In the Confirm Classes dialog box, click OK.
    11. In the Components and Controls Gallery dialog box, click Close to close the dialog box.
    12. So far, Dynamic Web TWAIN ActiveX Control has been imported into DynamicWebTwainNonDlgApp project, and a wrapper class called CDynamicWebTwain has been generated by Visual C++ IDE, as seen in the following figure:

    2. Adding Code to The Project

    1. On the View menu, click Resource Symbols.  In the Resource Symbols dialog box, click New button. In the New Symbol dialog box, input ID_DYNAMICWEBTWAIN in the Name edit box, click OK. Click Close.
    2. In the DynamicWebTwainNonDlgAppView.h file, add #include "DynamicWebTwain.h" just before the CDynamicWebTwainNonDlgAppView class definition.  
      
      #include "DynamicWebTwain.h"
      class CDynamicWebTwainNonDlgAppView : public CView

    3. Add a member variable m_DynamicWebTwain to the private section of the CDynamicWebTwainNonDlgAppView class definition.
      
      class CDynamicWebTwainNonDlgAppView : public CView
      {
      private: 
      	CDynamicWebTwain m_DynamicWebTwain;

    4. Add DECLARE_EVENTSINK_MAP() after DECLARE_MESSAGE_MAP() in the DynamicWebTwainNonDlgAppView.h.
      
      DECLARE_MESSAGE_MAP()
      
      DECLARE_EVENTSINK_MAP()

    5. Add a WM_CREATE message handler to class CDynamicWebTwainNonDlgAppView. Edit the function as the following:
      
      int CDynamicWebTwainNonDlgAppView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
      {
          if (CView::OnCreate(lpCreateStruct) == -1)
              return -1;
      
          if (m_DynamicWebTwain.Create(NULL,NULL,NULL,CRect(1,1,2,2),this,ID_DYNAMICWEBTWAIN,NULL) == FALSE)
              return -1;
          
          m_DynamicWebTwain.AcquireImage();
      
          return 0;
      }

      m_DynamicWebTwain.Create() is to create the ActiveX control.
      m_DynamicWebTwain.AcquireImage() is to start the image acquiring process. This is for demonstrating the event handler only. In really application, it may be more reasonable to add a menu item to start the acquiring.
    6. Add event sink map after message map in DynamicWebTwainNonDlgAppView.cpp.
      
      END_MESSAGE_MAP()
      
      BEGIN_EVENTSINK_MAP(CDynamicWebTwainNonDlgAppView, CView)
          ON_EVENT(CDynamicWebTwainNonDlgAppView,ID_DYNAMICWEBTWAIN,1,OnPostTransferHandler,VTS_NONE)
      END_EVENTSINK_MAP()

      1 is the Dispatch ID of the OnPostTranfer event. OnPostTransferHandler is a private member function of CDynamicWebTwainNonDlgAppView class to handler the event. VTS_NONE indicates the event passes no arguments.
    7. Add a private member function OnPostTransferHandler to handle the event.
      
      void CDynamicWebTwainNonDlgAppView::OnPostTransferHandler()
      {
          MessageBox("OnPostTransfer event fired.");
      }

     

     

     













    TWAIN ActiveX | TWAIN Plug-in | TWAIN Control | TWAIN SDK | Scanner COM
    Software Configuration Management | Version Control | Source Control
    Copyright © 2009 Dynamsoft Corporation. All Rights Reserved.