DTWAIN Application Loop Example
Implementing the TWAIN message loop in a DTWAIN application is a very simple process. The DTWAIN version of the TWAIN message loop is simplified to the following construct: (Also see MFC Example)
#include <windows.h> #include "dtwain.h" ... MSG msg; ... // Initialize DTWAIN DTWAIN_SysInitialize( ); ... // Let DTWAIN know that the application will adjust the main loop DTWAIN_SetTwainMode(DTWAIN_MODELESS); ... while (GetMessage(&msg, NULL, 0, 0)) { if ( !DTWAIN_IsTwainMsg( &msg )) { TranslateMessage(&msg); DispatchMessage(&msg); } }
...
Except for the DTWAIN_SysInitialize call, the only change to the traditional message loop are the calls to DTWAIN_SetTwainMode and DTWAIN_IsTwainMsg. The DTWAIN_SetTwainMode with the DTWAIN_MODELESS value tells DTWAIN that the application will be responsible in letting TWAIN process the messages. The DTWAIN_SetTwainMode should be called before the main application loop starts.
The DTWAIN_IsTwainMsg is the 'TWAIN Message processor'. If DTWAIN_IsTwainMsg returns FALSE, the normal TranslateMessage and DispatchMessage Windows API functions called. Otherwise, the message is not processed by the application. The DTWAIN_IsTwainMsg is a very powerful function. Not only does it determine whether the message is actually a TWAIN message, but also processes the message correctly. Note that there is no switch or if-then statements that you would have to normally do if you were to process the TWAIN messages yourself without DTWAIN. |