DTWAIN Notifications Using a Window Handle
The only message that is sent to a window when a DTWAIN event occurs is equivalent to the return value of DTWAIN_GetRegisteredMsg. This message number will not conflict with any message numbers that your application or any other application may be using. All DTWAIN specific messages use this message number and this number only. The message number is set by DTWAIN when the DTWAIN_SysInitialize function is called.
Once you have determined that the message has been sent by DTWAIN, you will need to know exactly what DTWAIN is informing your application of. To get the notification, the notification code is always passed as the 'WPARAM' value of the DTWAIN message. The current Source is always sent as the LPARAM value.
Retrieving messages sent to a window differ depending on the language that you use for application development. C and C++ programmers can handle message retrieval easily, since messaging is intrinsic to a program written in those languages. Visual Basic programmers that use version 4.0 and below will have to use one of the 'message blaster' type VBX's or OCX's that are available, since VB 4.0 and below had no way of capturing user-defined messages
Regardless of the language, you must be familiar with how your language allows message processing. If your language does not provide a facility to capture messages, you can still use DTWAIN to a great extent, but you will not be able to 'fine-tune' the application in as far as checking for the progress of an acquisition, allow users to stop a multi-page acquisition, etc.
The following is a small skeleton example of how to use the notifications. The example is in 'C', however almost all Windows programming languages has the facility to process window messages:
Example: #include <windows.h> #include "dtwain.h"
HWND hDTwainWnd; LONG DTwainMsg; ... ... DTwainMsg = DTWAIN_GetRegisteredMsg( ); DTWAIN_EnableMsgNotify( TRUE ); ... DTWAIN_StartTwainSession( hDTwainWnd, NULL); ...
/* Here is the window procedure for the DTWAIN message window hDTwainWnd */ LONG MyProc( HWND hWnd, UINT nMsg, WORD wParam, LONG lParam)
... if ( nMsg == DTwainMsg) if ( wParam == DTWAIN_TN_ACQUIRESTARTED ) DTWAIN Started an image acquisition else if ( wParam == DTWAIN_TN_ACQUIRECANCELLED) Acquisition Cancelled ... /* Possibly more tests for other notifications */ ... /* STOP! LOOK! LISTEN! IMPORTANT! */ return 1; /* Must always return 1 for unprocessed notifications*/ /* end of if */ else /* This is NOT a DTWAIN message /*This is a 'normal' window message */
...
Note that in the above example, DTWAIN_GetRegisteredMsg returns the message that is always sent to your message window if the message was generated by DTWAIN. Also DTWAIN_EnableMsgNotify is set to TRUE to invoke processing DTWAIN messages.
DTWAIN message processing requires that your window procedure return the value of TRUE for unprocessed DTWAIN messages. This is very important and should not be overlooked!! |