Implementing a wait loop for Modeless Acquisitions
|
For modeless acquisitions, acquisition functions such as DTWAIN_AcquireNative return immediately when called. This becomes a problem if your application desires to wait until the acquisition session has terminated before moving on. For cases such as this, the application must enter a "wait" or "idle" loop until the acquisitions are done. The following C / C++ code will perform this job:
/* Call an acquisition function */ MSG msg; /* Perform a loop until acquisitions are done */ while ( DTWAIN_IsUIEnabled(Source) ) // Source is acquiring { /* Process all pending messages */ while ( PeekMessage(&msg, NULL, 0, 0, PM_REMOVE) ) { if ( msg.message == WM_QUIT ) return; if ( !DTWAIN_IsTwainMsg(&msg) ) // send message to app, not TWAIN { TranslateMessage(&msg); DispatchMessage(&msg); } } /* Optional throttle to avoid CPU spin */ Sleep(1); }
Remember that this loop is necessary only if:
a) Modeless processing is used and b) You want your application to "wait" until the acquisitions are done.
|