Welcome To The Home Of The Visual FoxPro Experts  
home. signup. forum. archives. search. google. articles. downloads. faq. members. weblogs. file info. rss. print.
THUMBNAILS, ANYONE? (PART 1 OF 2)

When my first article Teach The Fox Hunt Pictures Better in this website was published, Tom Holt of UK, one of the first registrants here wished if he could incorporate into his VFP app some kind of management for multiple page type of graphic files and the option to print all or several pages of the same. Obviously the REPORT FORM command of VFP cannot handle that so we are going to address that issue in this article making Tom’s concerns some sort of a case study.

In return, the sample 5-paged TIFF that goes with this article is courtesy of Mr. Holt. I just removed some pertinent information from the file to protect the interest of Mr. Holt and his employer. Thanks, Tom, and sorry for this delayed reply to your request. I hope it’s not really too late. Just like everyone else, I have my own deadlines to beat so I know you understand. Okay, let’s go down to the core of the business.

Multi-Page Graphic Files
There are quite a number of graphic file formats out there. Some of them support “image pages” - that is, multiple images in one single file, like pages in a photo album. On the other hand, JPGs and BMPs are just examples of files that are limited to a single page. We will deal with single page files on the next part of this series.

The Tools
Once again, the Kodak Imaging Active-X toolkit can be used to achieve our goal. These are the Admin, Edit and Thumbnail controls (Figure 1). Admin is a non-visual control which is used to get most parameter definitions from the user. These parameters influence other Kodak image controls. Thumbnail control displays image files in thumbnail form and it supports IF, DCX, AWD, XIF and WIF. Kodak Image Edit control is used for editing and printing of the image. Its other basic uses were featured in my first article.



Printing the Thumbs
In printing multi-page graphic files, you call the Admin's ShowPrintDialog method to prompt the user to define printing parameters which is somewhat equivalent to VFP's Report Form (MyReport) To Printer Prompt NoConsole command. You can query the default values or any changes made by the user through the following Admin properties:
1. PrintStartPage = starting page number
2. PrintEndPage = ending page number
3. PrintOutputFormat = can be one of the three: 0. Pixel to pixel, 1. Actual size and 2. Fit to page.



Pass these values to Image Edit's PrintImage method to print the file or its selected pages. If you don't, PrintImage will print all pages using the image actual size format. I just feel funny why ShowPrintDialog returns an OLÉ error should the user decide to abort the printing procedure before it starts and it takes no action when the user selects the Print button. Moreso, It doesn't return any value to determine which button (Print or Cancel) the user has selected! To add fire to the injury, if you set the Admin's CancelError property to .F., no error will occur even if the user cancels the printing and you are left without any clue which button the user has pressed. So never ever set CancelError to .F. because this property is our only way for a workaround together with VFP's ON ERROR. That's why I declared a SET PROCEDURE TO ERRHNDLR ADDITIVE in the Init event of our sample form (Figure 2) to manage OLÉ error 1429, in case the user cancels the print.



In the Click method of the btnPrint control (please refer to the sample form for more info), I wrote the following code:
LOCAL lcErrHandler,lnStartPage,lnEndpage,lnPrintOutPutFormat
PUBLIC glCancelledByUser lcErrHandler = ON('Error')
ON ERROR DO OnError WITH ERROR()
WITH THISFORM.Admin
	.ShowPrintDialog
	lnStartPage = .PrintStartPage
	lnEndpage = .PrintEndPage
	lnPrintOutPutFormat = .PrintOutputFormat
ENDWITH ON ERROR &lcErrHandler
IF !glCancelledByUser
	THISFORM.Viewer.PrintImage(lnStartPage,lnEndpage,lnPrintOutPutFormat)
ENDIF

RELEASE glCancelledByUser

glCancelledByUser is a boolean type variable declared as public that serves as our flag if the user chooses Cancel button on the print dialog. If you have a pre-set error handler, it is saved to lcErrHandler variable. The OnError procedure, contained within ERRHNDLR.PRG, is the real procedure that takes care of the error should it occurs.
*** START - ERRHNDLER.PRG ***
PROCEDURE OnError
	LPARAMETERS lnError
	IF lnError = 1429 && Error triggered by ole
		glCancelledByUser = .T.
	ENDIF
	RETURN
	*** END - ERRHNDLR.PRG ***
ENDPROC

Fox And Theories

You may include the code to handle the 1429 error in your own error handler so that you don't need to indicate an additional procedure.
So far, the PrintImage method that captures starting and ending pages among others, works well in ME and older Windows versions. Win2K on the other hand, has a printing option where you can be able to skip pages -- like in MS-Word (Figure 3). You can specify, for example, "2,4-6,8" to print pages 2,4,5,6 and 8. PrintImage surely cannot accommodate this feature now. Let's hope the future version of Kodak Image Edit control will support this cool option and with it, will also include the fix for its buggy scrollbars.



Before I Retreat Graciously Towards My Foxhole…
Tom, I hope you are satisfied with our solution and may you're not the only one who finds another light for the day. As I promise, next article will involve single page graphic files in thumbnails. We will attempt to use pure native objects of VFP, so stay tuned.

Download code
Click here to download the code that is discussed in this article. The download is a zipfile. Its size is 227.417 bytes.

ABOUT THE AUTHOR: DALE DEDOROY

Dale Dedoroy Dale is a poor boy who finds joy in programming. He is currently the I.T. Officer of C.W. Mosser Environment Corporation.

FEEDBACK

Marcos Martinez @ 12/17/2013 3:42:07 PM
Hi Dale, how are you? u can send me both files, thumbs.zip and thumbs2.zip to mkmartinez@hotmail.com ? Thks!

issam mansour @ 6/28/2014 3:17:59 PM
Hi Sir,
t try to download the both files, but i have any error. if you please can send them to my email IssamMansour@hotmail.com.

Regards

Thank you.



Your Name: 
Your Feedback: 

Spam Protection:
Enter the code shown: