Implementing TWAIN Application Loop with MFC

Top  Previous  Next

If you are using MFC and C++, the CWinApp::PreTranslateMessage function has to be overridden as follows for DTWAIN to function properly:

 

// Class declaration for CMyApp

class CMyApp : public CWinApp

{

...

     // Definition of overriden PreTranslateMessage( )

    BOOL PreTranslateMessage(MSG &msg);

...

};

//------------------------------------------------------------------------------------

// The InitInstance of the application should have the following

BOOL CMyApp::InitInstance( )

{

  ...

  DTWAIN_SysInitialize( );

  DTWAIN_SetTwainMode(DTWAIN_MODELESS);

 ...

}

//----------------------------------------------------------------------------------

// Implementation of overridden PreTranslateMessage( )

BOOL  CMyApp::PreTranslateMessage(MSG *msg)

{

   // Check if not TWAIN message

  if ( !DTWAIN_IsTwainMsg( msg ))

     // Do normal processing and return

        return CWinApp::PreTranslateMessage(msg);

 

   return TRUE;

}