| Herd Software Development
|=
DaVinci Graphics Library
|==
DaVinci Documentation Home Search Order


Leonardo: The TWAINIsTwainMessage function

GetMessage, or an abstraction of this function, must be used while TWAIN sessions are open to filter messages in the Windows queue similarly to the Windows function IsDialogMessage. This is required because the acquired data is passed to the requesting application as the wParam of a Windows message. This is similiar to the handling of the IsDialogMessage Windows API function.

void FAR PASCAL TWAINIsTwainMessage(
HTWAINACCESS hta,
LPMSG msg,
HWND hWnd);

hta Handle to TWAIN memory created by TWAINInitialize

msg Pointer to the window message (see GetMessage, PeekMessage, TranslateMessage etc.)

hWnd Handle of the window that should receive acquired data passed via the UWM_TWAINIMAGERECEIVED. message.

Windows API:

  MSG msg;

  while (GetMessage(&msg,NULL,0,0))
  {
     if (!TWAINIsTwainMessage(TwainAccessHandle, &msg, hwMain))
	{ TranslateMessage(&msg);
	  DispatchMessage(&msg);
	}
  } 

Borland OWL:

class TDavApp : public TApplication {
public:
    TDavApp(LPSTR AName, HINSTANCE hInstance,
		  HINSTANCE hPrevInstance, LPSTR lpCmd,
		  int nCmdShow)
		: TApplication(AName, hInstance,
			       hPrevInstance, lpCmd, nCmdShow) {};
    virtual void InitMainWindow();
    virtual bool ProcessAppMsg(MSG &msg);
};

/* We need to test whether a Message to be processed is a Message
to the TWAIN interface, else it will not work at all... */
bool TDavApp::ProcessAppMsg(MSG &msg)
{
  TDavWindow *DavWindow = TYPESAFE_DOWNCAST(MainWindow, TDavWindow);

  if (DavWindow &&
      DavWindow->HWindow &&
      DavWindow->TwainAccessHandle &&
      TWAINIsTwainMessage(DavWindow->TwainAccessHandle, &msg, DavWindow->HWindow))
      return TRUE;

  return TApplication::ProcessAppMsg(msg);
}

Borland Delphi:

type
  TDavForm = class(TForm)
    procedure MyAppMessage(var Msg: TMsg; var Handled: Boolean);    procedure MnuOpenClick(Sender: Tobject);
...


  if (TwainAccessHandle<>0) then
     Application.OnMessage:=MyAppMessage;

...
procedure TDavForm.MyAppMessage(var Msg: TMsg; var Handled: Boolean);
begin
   if (TwainAccessHandle<>0) then
      Handled:=TWAINIsTwainMessage(TwainAccessHandle,Msg,Handle);
end;

Remarks

Applications can avoid to implement changes to the message loop by using the Function TWAINGetImage.