コード例 #1
0
ファイル: TwainCpp.cpp プロジェクト: ngphloc/agmagic
/*
Should be called from the main message loop of the application. Can always be called,
it will not process the message unless a scan is in progress.
*/
BOOL CTwain::ProcessMessage(MSG msg)
{
	if(SourceEnabled()){

		TW_UINT16  twRC = TWRC_NOTDSEVENT;
		TW_EVENT twEvent;

		memset(&twEvent, 0, sizeof(TW_EVENT));
	//	twEvent.TWMessage = MSG_NULL;

		twEvent.pEvent = (TW_MEMREF)&msg;

		twRC = CallDSMEntry(&m_AppId,&m_Source,DG_CONTROL,DAT_EVENT,MSG_PROCESSEVENT,(TW_MEMREF)&twEvent);

	//	CallTwainProc(&m_AppId,&m_Source,DG_CONTROL,DAT_EVENT,MSG_PROCESSEVENT,(TW_MEMREF)&twEvent);
	//	if(GetRC() != TWRC_NOTDSEVENT)
	//	{
		TranslateMessage(twEvent);
	//	}

		// tell the caller what happened
		return (twRC==TWRC_DSEVENT);           // returns TRUE or FALSE
	}
	return FALSE;
}
コード例 #2
0
int CTwainSourceManager::CloseDSM()
{
	if(DSMOpen != State)
	{
		return 1;
	}

	TW_UINT16 twRC = TWRC_FAILURE;
	char buffer[80];

	memset(buffer, 0, sizeof(buffer));

	// This call performs one important function:
	// - tells the SM which application, appID.id, is requesting SM to close
	// - be sure to test return code, failure indicates SM did not close !!

	twRC = CallDSMEntry(NULL,
		DG_CONTROL,
		DAT_PARENT,
		MSG_CLOSEDSM,
		&WndNotify);

	if (twRC != TWRC_SUCCESS)
	{
 		//wsprintf(buffer,"CloseDSM failure -- twRC = %d\r\n",twRC);
 		//LogMessage(buffer);
	}
	else
	{
		State = DSMLoad;
	}

	// Let the caller know what happened
	return (twRC==TWRC_SUCCESS) ? 1 : -1;
}
コード例 #3
0
ファイル: TwainCpp.cpp プロジェクト: jf4210/src2-test
/*
Should be called from the main message loop of the application. Can always be called,
it will not process the message unless a scan is in progress.
*/
BOOL CTwain::ProcessMessage(MSG msg)
{
	if(SourceEnabled())
	{
#if 1
		TW_UINT16  twRC = TWRC_NOTDSEVENT;
		TW_EVENT twEvent;

		memset(&twEvent, 0, sizeof(TW_EVENT));
		//  twEvent.TWMessage = MSG_NULL;

		twEvent.pEvent = (TW_MEMREF)&msg;

		twRC = CallDSMEntry(&m_AppId,&m_Source,DG_CONTROL,DAT_EVENT,MSG_PROCESSEVENT,(TW_MEMREF)&twEvent);

// 		if (twRC != TWRC_DSEVENT)
// 			return FALSE;

		//  CallTwainProc(&m_AppId,&m_Source,DG_CONTROL,DAT_EVENT,MSG_PROCESSEVENT,(TW_MEMREF)&twEvent);
		//  if(GetRC() != TWRC_NOTDSEVENT)
		//  {

		if (!_bTwainContinue)
		{
			twEvent.TWMessage = MSG_CLOSEDSREQ;
		}

		TranslateMessage(twEvent);
		//  }

		// tell the caller what happened
		return (twRC == TWRC_DSEVENT);           // returns TRUE or FALSE
//		return TRUE;
#else
	TW_EVENT twEvent;
		twEvent.pEvent = (TW_MEMREF)&msg;
		twEvent.TWMessage = MSG_NULL;
	
		CallTwainProc(&m_AppId,&m_Source,DG_CONTROL,DAT_EVENT,MSG_PROCESSEVENT,(TW_MEMREF)&twEvent);
		if(GetRC() != TWRC_NOTDSEVENT)
		{
			TRACE("********** ProcessMessage ************\n");
			TranslateMessage(twEvent);
		}
		return FALSE;
#endif

	}
	else
	{
//		TRACE("********** ProcessMessage SourceEnabled = false ************\n");
	}
	return FALSE;
}
コード例 #4
0
int CTwainSourceManager::PromptSelectSource( CTwainScanistor** ppScanistor )
{
	if((State != DSMOpen || OpenDSM() != 1) || !ppScanistor)
	{
		return -1;
	}

	TW_UINT16 twRC = TWRC_FAILURE;
	TW_IDENTITY NewDSIdentity;

	memset(&NewDSIdentity, 0, sizeof(TW_IDENTITY));

	twRC = CallDSMEntry(NULL,
		DG_CONTROL,
		DAT_IDENTITY,
		MSG_GETDEFAULT,
		(TW_MEMREF)&NewDSIdentity);

	twRC = CallDSMEntry(NULL,
		DG_CONTROL,
		DAT_IDENTITY,
		MSG_USERSELECT,
		(TW_MEMREF)&NewDSIdentity);

	switch (twRC)
	{
	case TWRC_SUCCESS:
		*ppScanistor = new CTwainScanistor(this, NewDSIdentity);
		break;
	case TWRC_CANCEL:
		break;
	case TWRC_FAILURE:	        
	default:
		break;
	}
	
	return (twRC == TWRC_SUCCESS) ? 1 : -1;
}
コード例 #5
0
int CTwainSourceManager::OpenDSM()
{
	if(DSMOpen == State)
	{
		return 1;
	}

	if(State != DSMLoad || Load() != 1)
	{
		return -1;
	}

	TW_UINT16 twRC = CallDSMEntry(NULL,
		DG_CONTROL,
		DAT_PARENT,
		MSG_OPENDSM,
		(TW_MEMREF)&WndNotify);

	switch (twRC)
	{
	case TWRC_SUCCESS:
		// Needed for house keeping.  Do single open and do not
		// close SM which is not already open ....
		State = DSMOpen;
		/*if (MessageLevel() >= ML_FULL)
		{
			ShowRC_CC(hWnd, 0, 0, 0, 
				"Source Manager was Opened successfully", 
				"TWAIN Information");
		}*/
		break;

	case TWRC_FAILURE:
		//LogMessage("OpenDSM failure\r\n");
	default:
		// Trouble opening the SM, inform the user
		//TWDSMOpen = FALSE;
		//if (MessageLevel() >= ML_ERROR)                
		//{
		//	ShowRC_CC(hWnd, 1, twRC, 0,	//Source Manager
		//		"",
		//		"DG_CONTROL/DAT_PARENT/MSG_OPENDSM");
		//}
		break;
	}

	return (State == DSMOpen) ? 1 : -1;
}
コード例 #6
0
ファイル: Captest.c プロジェクト: yedaoq/YedaoqCodeSpace
/*
* Function: TWAutofeed -- 
* Author: TWAIN Working Group
* Input:
*		hWnd - handle to window
* Output:
*		TW_INT16
* Comments:
*		Checks if the autofeed option on the FILE menu is
* checked and if so begins a capability negotiation.  If the ADF is already
* enabled, (check this) the return value is ??? otherwise the application
* negotiates with the source to enable the capability
*
* If the ADF at the source cannot be enabled, the application should post an 
* error and not allow a transfer (ie: the Source's UI to come up).
*/
TW_INT16 TWAutofeed(HWND hWnd)
{
	TW_CAPABILITY   cap;
	pTW_ONEVALUE    pval = NULL;
	TW_INT16        status = TWRC_SUCCESS;
	char            Details[128];

	memset(&cap, 0, sizeof(TW_CAPABILITY));
	memset(Details, 0, sizeof(char[128]));

	ASSERT(hWnd);

	AutoFeedBOOL = FALSE;
	strcpy(Details, "");

	/*
	* If Automatic Feeding > CAP_AUTOFEED On is checked
	*/
	if (!(GetMenuState (GetMenu (hWnd), TW_APP_AUTOFEED, MF_BYCOMMAND) & MF_CHECKED))
	{
		return (status);
	}

	cap.Cap = CAP_FEEDERENABLED;
	cap.ConType = TWON_ONEVALUE;

	status = CallDSMEntry(&appID,
					&dsID,
					DG_CONTROL, 
					DAT_CAPABILITY, 
					MSG_GET,
					(TW_MEMREF)&cap);

	if (status != TWRC_SUCCESS)
	{
		status = TWRC_FAILURE;
		lstrcpy(Details, "CAP_FEEDERENABLED");
		GlobalFree(cap.hContainer);
	}
	else
	{   
		pval = (pTW_ONEVALUE)GlobalLock(cap.hContainer);
		if (pval->Item == TRUE)
		{   
			/*
			* Feeder is enabled no need to negotiate
			*/
			GlobalUnlock(cap.hContainer);
			GlobalFree((HANDLE)cap.hContainer); 
		}
		else     
		{
			/*
			* Negotiate with the source
			* Try to turn on CAP_FEEDERENABLED
			*/
			pval->ItemType = TWTY_BOOL;
			pval->Item = TRUE;
			GlobalUnlock(cap.hContainer);

			status = CallDSMEntry(&appID,
							&dsID,
							DG_CONTROL, 
							DAT_CAPABILITY, 
							MSG_SET,
							(TW_MEMREF)&cap);

			/*
			* free here because the GET call will allocate a new container
			*/
			GlobalFree(cap.hContainer);

			if (status == TWRC_SUCCESS)
			{   
				/*
				* Verify that CAP_FEEDERENABLED is now TRUE
				*/
				status = CallDSMEntry(&appID,
								&dsID,
								DG_CONTROL, 
								DAT_CAPABILITY, 
								MSG_GET,
								(TW_MEMREF)&cap);

				if (status == TWRC_SUCCESS)
				{
					pval = (pTW_ONEVALUE)GlobalLock(cap.hContainer);
					if (pval->Item != TRUE) 
					{
						/*
						* Verification failed -- CAP_FEEDERENABLED is FALSE even after successful set to TRUE
						*/
						status = TWRC_FAILURE;
						strcpy(Details, "CAP_FEEDERENABLED");
					}
					GlobalUnlock(cap.hContainer);
					GlobalFree((HANDLE)cap.hContainer);    
				}
				else
				{
					status = TWRC_FAILURE;                  
					strcpy(Details, "CAP_FEEDERENABLED");                   
				}               
			}
			else
			{    
				/*
				* MSG_SET of CAP_FEEDERENABLED to TRUE did not succeed
				*/
				strcpy(Details, "CAP_FEEDERENABLED");
				status = TWRC_FAILURE;
			}
		}

		if (status == TWRC_SUCCESS)
		{
			/*
			* CAP_AUTOFEED
			*/
			cap.Cap = CAP_AUTOFEED;
			cap.ConType = TWON_ONEVALUE;

			status = CallDSMEntry(&appID,
							&dsID,
							DG_CONTROL, 
							DAT_CAPABILITY, 
							MSG_GET,
							(TW_MEMREF)&cap);

			if (status != TWRC_SUCCESS)
			{
				/*
				* MSG_GET on CAP_AUTOFEED did not succeed
				*/
				status = TWRC_FAILURE;
				strcpy(Details, "CAP_AUTOFEED");            
			}

			/*
			* MSG_GET on CAP_AUTOFEED returned success
			*/
			pval = (pTW_ONEVALUE)GlobalLock(cap.hContainer);
			if (pval->Item == TRUE)
			{
				/*
				* CAP_AUTOFEED is on
				*/
				GlobalUnlock(cap.hContainer);
				GlobalFree((HANDLE)cap.hContainer);         
			}
			else
			{
				/*
				* Try to set CAP_AUTOFEED to TRUE
				*/
				pval->ItemType = TWTY_BOOL;
				pval->Item = TRUE;
				GlobalUnlock(cap.hContainer);

				status = CallDSMEntry(&appID,
									&dsID,
									DG_CONTROL, 
									DAT_CAPABILITY, 
									MSG_SET,
									(TW_MEMREF)&cap);

				GlobalFree((HANDLE)cap.hContainer);     

				if (status == TWRC_SUCCESS)
				{   
					/*
					* Verify that CAP_AUTOFEED is on
					*/
					status = CallDSMEntry(&appID,
									&dsID,
									DG_CONTROL, 
									DAT_CAPABILITY, 
									MSG_GET,
									(TW_MEMREF)&cap);

					if (status == TWRC_SUCCESS)
					{
						pval = (pTW_ONEVALUE)GlobalLock(cap.hContainer);
						if (pval->Item != TRUE)
						{
							status = TWRC_FAILURE;
							strcpy(Details, "CAP_AUTOFEED");            
							/*
							* CAP_AUTOFEED returns FALSE even after succesful set to TRUE
							*/
						}
						GlobalUnlock(cap.hContainer);
						GlobalFree((HANDLE)cap.hContainer); 
					}
					else
					{
						status = TWRC_FAILURE;
						strcpy(Details, "CAP_AUTOFEED");            
					}
				}
				else
				{
					/*
					* MSG_SET of CAP_AUTOFEED to TRUE did not succeed
					*/
					status = TWRC_FAILURE;
					strcpy(Details, "CAP_AUTOFEED");
				}
			}   
		}   
	}   

	/*
	* Set Local Autofeed Variable on/off        
	*/
	if (status == TWRC_SUCCESS)
	{
		AutoFeedBOOL = TRUE;
	}
	else
	{
		AutoFeedBOOL = FALSE;
		if (MessageLevel() >= ML_ERROR)
		{
			ShowRC_CC(hWnd, 0, 0, 0, Details, "CAP_AUTOFEED ERROR");
		}
	}
	return status;
}