Guidance
指路人
g.yi.org
Software / Reginald / Examples / twain.rex

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
/*
GUIBEGIN
WINDOW , 0, 0, 400, 200, POPUP|CAPTION|SYSMENU|MINBOX|MAXBOX|THICK, , Twain Demo
	FONT 8, 400, MS Shell Dlg
	MENU
DEND

MENU
	HEADING &Twain
		ITEM Ac&quire..., AcquireTwain
		ITEM &Select Source..., PickTwainSource
	<
DEND
GUIEND
*/

OPTIONS "C_CALL LABELCHECK"
NUMERIC DIGITS 10
LIBRARY rexxgui
DO
	FUNCDEF("BeginPaint","32u,void,void stor","user32")
	FUNCDEF("EndPaint","32,void,void","user32")

	CATCH FAILURE
		CONDITION("M")
		RETURN
END

/* We want SYNTAX raised for REXX GUI and TWAIN functions. */
guierr = "SYNTAX"
guiheading = 1
twainerr = "SYNTAX"
twainheading = 1

/* No DIB yet gotten */
dib = 0

DO
	/* Call GuiWindowDefaults() and indicate we want TWAIN support enabled. You
	 * likely would pass other values too if you want extended support, such as
	 * your own icon, cursor, HTML support, etc. NOTE: GuiWindowDefaults() must
	 * be called BEFORE any windows are open, or any TWAIN functions are called.
	 */
	guiwindowdefaults(, , , , "TWAIN")

	/* Make sure none of our subroutine names conflict with the above registered functions. */
	RXFUNCQUERY()

	/* Initialize TWAIN support. */
	twaininit(1 /* USA */, "Twain Demo", 1)

	guicreatewindow('NORMAL')

	/* Open the Twain Data Source manager. Tell it to report
	 * TWAIN events to our above window.
	 */
	twainopendsm(guiwindow)

	/* We trap SYNTAX just in case any initialization above fails. */
	CATCH SYNTAX
		CONDITION('M')
		
		/* Close the TWAIN Data Source manager if it was open. NOTE:
		 * This is safe to call even if not open.
		 */
		twainclosedsm()

		/* End the script. */
		RETURN
END

again:
DO FOREVER

	guigetmsg()

	IF EXISTS('GuiObject') == 0 THEN DO
		IF EXISTS('GuiSignal') THEN DO
		END
	END
	ELSE DO
		IF EXISTS('GuiSignal') == 0 THEN DROP (guiobject)
		ELSE SELECT guiobject

			/* Was it some Twain event? If so, then GuiObject == 'TWAIN'. NOTE: This
			 * implies that you should never create a child window layout with an
			 * object name of 'TWAIN' if you're using twain support.
			 */
			WHEN 'TWAIN' THEN DO

				/* Is another image (bitmap) ready for us to retrieve from the TWAIN
				 * data source?
				 */
				IF guisignal == "XFER" THEN DO

					/* Fill in our "BitmapInfo" stem variable with information about
					 * the image. This isn't a required step. It's just something
					 * that you can do if you want a little more information about
					 * the image before you do the TwainGetImage() below.
					 */
					twaingetimageinfo("BitmapInfo")
					
					/* Fetch the image, and call our subroutine "HandleBitmap" to do
					 * something with it. Alternately, we could call TwainAck() to
					 * skip this image, or TwainCancel() to cancel the transfer of
					 * all remaining images.
					 */
					twaingetimage("HandleBitmap")

					/* Force the window to be redrawn */
					guirefresh(, 1)
				END

			END /* TWAIN */
			
			OTHERWISE
		END
	END

	CATCH SYNTAX
		CONDITION('M')
		SIGNAL again

	CATCH HALT
	FINALLY
		guidestroywindow()
END
RETURN

/* ==================== TwainAcquire() ==================
 * The event handler for the "Twain -> Acquire..." menu
 * item. Reginald calls this when the user selects that
 * item.
 */

acquiretwain:
	/* Free any DIB we got before. It's OK to call this even if
	 * we didn't get a DIB
	 */
	twainfreedib(dib)

	/* Start an Acquire operation. GuiGetMsg() will return as
	 * each image is ready for us to TwainGetImage(). NOTE:
	 * TwainAcquire() will open whatever data source the user
	 * selected via TwainSelectSource() and then close it when
	 * we're done with the Acquire operation. We accept only
	 * 1 image.
	 */
	twainacquire(1)
	RETURN

/* ==================== TwainSource() ==================
 * The event handler for the "Twain -> Select source..."
 * menu item. Reginald calls this when the user selects
 * that item.
 */

picktwainsource:
	/* Present a dialog box listing the names of all the
	 * available TWAIN data sources on this computer, and
	 * let the user pick one. NOTE: If an error or cancel,
	 * SYNTAX is raised.
	 */
	twainselectsource()
	RETURN

/* ==================== HandleBitmap() ==================
 * Called by TwainGetImage() to pass us the handle to some
 * bitmap of the next acquired image. Here we do whatever
 * we want with the bitmap (ie, save it to disk, display
 * it in a window, etc). Then we return one of the following:
 *
 * 1 =	Free the bitmap.
 * 0 =	Don't free the bitmap (ie, we will take responsibility
 *		for it).
 * No return = Free the bitmap and cancel the acquire operation.
 */

handlebitmap:
	/* Get a Device Independent Bitmap (DIB) from the passed handle */
	dib = twaincreatedib(ARG(1))

	/* Let RXTWAIN free the handle now */
	RETURN 1


/* ==================== WM_PAINT() =====================
 * The PAINT event handler for my window. Reginald calls
 * this whenever the window needs to be redrawn.
 */

wm_paint:
	/* Erase the background and get a device context */
	hdc = beginpaint(guiwindow, ps)

	/* Draw the bitmap */
	twaindrawdib(dib, hdc)

	/* End paint */
	endpaint(guiwindow, ps)

	/* Don't let REXX GUI handle this */
	RETURN ""
掌柜推荐
 
 
¥288.00 ·
 
 
¥908.00 ·
 
 
¥289.00 ·
 
 
¥1,280.00 ·
 
 
¥1,360.00 ·
 
 
¥890.00 ·
© Sun 2024-11-24  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0 Last modified:2010-07-16 20:45:19