Realize the output of the form in VFP (i.)

Source: Internet
Author: User

Say in front

VB, Delphi for the form object encapsulates the PrintForm method, allowing users to easily convert form to BMP. This is a good feature, in the actual development process is often the demand, such as the statistical chart as a picture to save ...

Unfortunately, however, Visual FoxPro (including the upcoming 7.0) does not encapsulate this functionality for us. This problem must be plagued with a lot of fox friends, including me. Although we know that using the Win API can solve the problem, the actual programming is not easy?

I'm glad to get the "obj2bmp" tool written by George Tasker and get all the original code. George Tasker provides us with a Visual FoxPro version of the Capture tool, but I don't think the tool is practical-it's not always possible to call a tool in our application to complete the printfrom work, which is neither professional nor attractive. So I made a simple two-time development using the source code provided by George Tasker, encapsulating some of the functionality, hoping that this great tool would be more suitable for developers to use.

The original code copyright belongs to George Tasker, this article and two development of copyright belongs to the BOE Data Network Studio. The software is free software and you can use it at will, but we are not liable for any adverse consequences.

All of the following discussions are in pixels!!!

Using the Obj2bmp tool

Let's take a look at how to use George tasker to provide us with obj2bmp tools!

Compile project becomes Obj2bmp.app

Using the Obj2bmp.app tool

Create a new form, set the Alwaysontop property of the form to. T, or set the Alwaysonbottom property to. T, and run the form.

Type the following command in the command window and execute:

Oobjpicker=.null.
Do Obj2bmp.app with Oobjpicker

The following figure:

The right side of the form is the grab tool, note that the Drop-down list box below it lists two objects: Grab and select Object (the Caption property of the destination form). "Grab" refers to the form on the left, and "select Object" is itself. Because we selected the Grab form in the Drop-down list box, the list box lists all the visual controls in the Grab: form, OLEControl, Command, you can select the name of the control you want to snap, press the "Capture" button, You will get a picture of the current shape of the control.

For the quality of the screen you can also control, Bit Color quality is the best.

The use of the Formprint class is detailed

From the developer's point of view "obj2bmp" tool, seems to be very practical, so I have a simple encapsulation of the source code.

Required Support Files

    1. Class files: obj2bmp.vcx, OBJ2BMP.VCT

    2. Header file referenced by class: Rgb_256.h

    3. API Library: FOXTOOLS.FLL

    4. Other API libraries, I think this is not a problem for Windows 32-bit systems

A description of the FOXTOOLS.FLL. FOXTOOLS.FLL is the Visual FoxPro API Library, which is stored by default in the home () directory. When a Formprint class instance is established (the Init event) detects whether the FOXTOOLS.FLL reference has been made, and if not, executes the following command:

Set Library to (home () + "FOXTOOLS.FLL") Addi

Make sure you have this file in the home () directory, and if you want to place the foxtools.fll somewhere else, please modify the above statement.

The foxtools.fll of the reference is to get the handle of the form, and in Visual FoxPro 7, each form has a handle property, so you don't have to bother foxtools.fll.

User interface for Formprint classes

    1. cFileName property: Picture output directory and name.

    2. Makebitmap (Pnhwnd, PNBPP, Pntop, Pnleft, Pnheight, Pnwidth) method: Achieve picture output.

A description of the cFileName property. Set this property before using the Makebitmap method to specify the name of the picture file and the output path. Such as:

Obj.cfilename= "C:\BMP\abc.bmp" saves the picture file in the C:\BMP directory, and the file name is abc.bmp.

If the target file already exists when the Makebitmap method is executed, the program overwrites it without notice, and if the file cannot be established (possibly the directory does not exist, the path is invalid, the existing file cannot be overwritten) when the Makebitmap method is executed ... , the program will reset the name of the picture file and save the directory, the new file name and directory is so determined:

SYS (5) +sys (2003) + "\" +left (SYS (2015), 8) + ". bmp"

If you do not set the cFileName property beforehand, leave it with the default value. Null. or set cFileName to. Null. Value, the program will also use the SYS (5) +sys (2003) + "\" +left (SYS (2015), 8) + ". bmp" To determine the name of the picture and the Save directory.

Each time the picture is generated, the cFileName property is automatically set to. Null. Value.

A description of the Makebitmap (Pnhwnd, PNBPP, Pntop, Pnleft, Pnheight, Pnwidth) methods.

All six parameters can be omitted, but I recommend that you do not omit the first two arguments when calling.

The--pnhwnd represents the handle of the form being output. If the PrintForm is instantiated after its parent object is output form, passing 0 means printing the current form, and if you want to print another form, use the following code to get its handle and pass it as a pnhwnd:

_WhToHwnd (_WFINDTITL (ccaption)) && ccaption represents the Caption attribute of the output form.

--PNBPP represents the quality of the output picture. There are three choices: 4,8,24, the larger the number the better the quality.

Output the entire form

Create a new form (instance one) and add a control. Don't forget to add the PrintForm class to the form as a child object of the form. As shown in figure:

A. The simplest application, add the following code to the "click" Event of the "Output" button:

? ThisForm.printform1.makebitmap (0,24)
* Display: F:\OBJ2BMP\_0CU0FYF. Bmp. Indicates the name and location of the surface file.

B. Specify the output destination, add the following code to the "click" event in the output button:

Thisform.printform1.cfilename= "C:\ABC. BMP "
? ThisForm.printform1.makebitmap (0,24)
* Display: C:\ABC. Bmp. Indicates the name and location of the surface file.

Thisform.printform1.cfilename= "Z:\ABC. BMP "
? ThisForm.printform1.makebitmap (0,24)
* Display: F:\OBJ2BMP\_0CU0FYT. Bmp. Because the z disk does not exist, the picture file cannot be established, using the default directory and file name instead.

C. Output other forms.

Create a new form (instance II), add controls, and run.

In the "click" Event of the output button of the instance one form, add the following code to run:

ThisForm.printform1.makebitmap (_WhToHwnd (_WFINDTITL ("Instance II")), 24
* "Instance two" is the Caption property value of the form that was created later.

As shown in figure:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.