Printing the active form from within VFP

      No Comments on Printing the active form from within VFP

I am currently working on an application where one of the requirements is that the user can press a button on the screen and the currently active window will be printed out on the printer. I must note that this UI is a little different in that they wanted a form where only one field was displayed at a time. The user would enter values and they would then *Accept* that value before continuing. I accomplished this by creating a pageframe set with a lot of tabs. In production mode, the tabs will be hidden. When the user accepts a value, I call a method that sets the ActivePage = ActivePage + 1. It works pretty well, or as good as it gets. It sure beats creating hundreds of forms, or hiding and displaying text boxes and lables, or dynamically assigning the control sources and label captions. I think.

Back on the subject of printing the forms. In searching around the web, I found two possible solutions for printing my active forms. One was to use a methodology from a file download on the Foxite.com web page called FoxForm.dll by Eric den Doop. The second was in the September 2004 issue of Foxpro Advisor magazine in the FoxTips by Ceil Silver.

I tried the FoxForm approach and the test form worked right off the bat. Eric included a test form to test it with and it created a BMP of the screen. I created a simple report and imbedded the BMP into the report and I was off to the races. I thought. The test form that Eric has did not include a pageframe on it. The pageframes print fine with the exception that it only prints the first page of the pageframe as the active page, even if the fourth or seventh page is the active page. Drats.

I was filled with dread that I would have to find a very elaborate solution when I reached for my copy of Foxpro Advisor. This had better work or I am going to be set way back. I downloaded the DIBAPI32.DLL file from the Microsoft site and I entered the script as Ceil printed in his article. I used Erics demo form as a test but not until I had entered a pageframe with a couple of pages on it. I ran the test form, selected page four of the pageframe, and then clicked on the button that contained Ceils code. Success! The only problem is that this solution prompts with the printer console. It would be nice if I could get it to send to the printer directly with no prompt but a beggar cannot be a chooser.

What an awesome Fox developer community we have. Thanks to Eric and Ceil for being excellent resources to me and others.

Leave a Reply