Call API functions in VB6.0 to create and use logical Fonts

Source: Internet
Author: User
Tags textout
Create and use logical fonts By Calling API functions in VB6.0 Author: Wang shoubing Release Date: 2001/05/15
 
Abstr:
When developing various management systems using Visual FoxPro, Power Builder, and other development tools, we need to print a variety of reports. When designing reports, we sometimes encounter the following problems: reports have too many vertical data columns, and common wide-line printers (such as LQ-1600K series) cannot print all columns on the same page using the widest paper;

Body:  


Call API functions in VB6.0 to create and use logical Fonts

When developing various management systems using Visual FoxPro, Power Builder, and other development tools, we need to print a variety of reports. When designing reports, we sometimes encounter the following problems: reports have too many vertical data columns, and common wide-line printers (such as LQ-1600K series) cannot print all columns on the same page using the widest paper; if you set the printer to print horizontally, although the paper length is set to be large and can be printed horizontally on several consecutive pages, such reports are not beautiful on the one hand, and on the other hand continuous paper is easy to separate, so that the report can be divided into several pages on the same page, it is not suitable for printing the payroll that is distributed to employees. From the STAR-AR3240 printer in the DOS environment can print 24x12 Dot Matrix Chinese characters to be inspired, print the report with a variable ratio of the font print, the report page can be flexibly controlled to print all data columns on one page. For example, if you want to print the payroll that is distributed to employees, when there are many projects, you need to print them in a horizontal font.
Because Windows uses the TrueType font, it can be smoothly and infinitely changed. However, Chinese characters with less than 1 aspect ratio are not standard Chinese characters, but they are not in the Windows system font, however, Windows provides a wide range of APIS (application interfaces) to call createfont () to create ideal logical fonts. Using these fonts to print reports can meet our needs.
To call an API function, select the corresponding function, declare it first, and then call it. Createfont () in Windows is defined as follows:
Bool createfont (// create logical font. If the font is successful, true is returned. Otherwise, false is returned.
Int nheight, // The character height of the created font
Int nwidth, // average font character width
Int nescapement, // The angle between the output direction and the horizontal direction to the right,
In 0.1 degrees
Int norientation, // character and baseline angle, in 0.1 degrees
Int nweight, // The depth of the Character Color
Byte bitalic, // italic attribute mark (0: normal font, non-0: italic)
Byte bunderline, // underline attribute mark (0: No underline, non-0: underlined)
Byte cstrikeout, // mark of the strikethrough attribute (0: No strikethrough, not 0: Yes)
Byte ncharset, // Character Set Identifier 0: ANSI character set, 1: System Default Character Set
Byte noutprecision, // output precision
Byte nclipprecision, // shear precision
Byte nquality, // Output Quality
Byte npitchandfamily, // Character Spacing
Lpctstr lpszfacename // name of the TrueType font of the existing system
)
To display and print user-created fonts, you need to call several other API functions: textout (), SelectObject (), and deleteobject (). Their definitions are as follows:
Bool textout (// outputs a string to the output device in the selected font
HDC, // handle of the character output device
Int nxstart, // start position of the x-axis
Int nystart, // y -- start position of the Axis
Lptstr lpstring, // The first address of the string to be output
Int cbstring // number of output characters
); // Return true if the output is successful; otherwise, return false.
Hgdiobj SelectObject (// set the object (font) for the specified character device)
HDC, // handle of the output device
Hgdiobj // handle of the object
);
Bool deleteobject (// delete a specified logical object
Hgdiobj hobject // handle of the object
); // Return true if the deletion is successful; otherwise, return false.
In order to save space, this program only completes the creation of fonts, display on the screen, and simple string printing examples, and gradually expands its functions to generate a flexible RePort Printing program, to meet the requirements of printing ultra-wide reports with horizontal compression fonts.
One of the following two comparison charts shows the font compression effect when the program is running:

  

Figure 1. Normal carcass
  
Figure 2. horizontal compression
The source code of the program is as follows:

'Create three ComboBox controls on the window body, named char_type, char_size, and char_vhp respectively;
Create three commandbutton controls named pai_prn, pai_pre, and pai_quit
'Create four label controls and one shape control. The shape control is defined as a rectangle (rectangle)

Option explicit
Private declare function createfont lib "GDI32" alias "createfonta" (byval h as long, byval w as long, byval e as long, byval o as long, byval w as long, byval I as long, byval U as long, byval s as long, byval C as long, byval OP as long, byval CP as long, byval Q As long, byval PAF as long, byval F as string) as long
Private declare function textout lib "GDI32" alias "textouta" (byval HDC as long, byval X as long, byval y as long, byval lpstring as string, byval ncount as long) as long
Private declare function SelectObject lib "GDI32" (byval HDC as long, byval hobject as long) as long
Private declare function deleteobject lib "GDI32" (byval hobject as long) as long
'Declare the API function to be called

Private cur_y as integer
Private prnstr as string 'string to be output
Private hsize as long 'horizontal length of the logical font
Private vsize as double
Private hfont as long

Private sub performance_pre_click ()
Form1.cls' clear the display output area
Hsize = clng (char_size.text)
Vsize = cdbl (Val (left (char_vhp.text, Len (char_vhp.text)-1)/100)
'Get the configured Aspect Ratio
Hfont = createfont (CINT (hsize * 22/17), CINT (hsize * vsize * 2/3), 0, 0, 0, 0, 0, 0,128, 0, 0, 0, 0, 0, char_type.text)
'Create a logical font and adjust it to the unit corresponding to the standard size according to the character device property.
Call SelectObject (form1.hdc, hfont) 'sets the font for the form
Form1.currenty= 600
Print prnstr 'output string on the display
End sub

Private sub performance_prn_click ()
Call textout (printer. HDC, 0, 0, prnstr, lenb (prnstr ))
'Send a string to the printer
Printer. enddoc
End sub

Private sub pai_quit_click ()
Call deleteobject (hfont) 'to delete the created font object
End
End sub

Private sub form_load ()
Prnstr = "the font vertical and horizontal folds show the print demonstration effect! "
Char_type.additem ("") 'adds common options for each ComboBox control
Char_type.additem (" _ gb2312 ")
Char_type.additem (" ")
Char_type.additem (" _ gb2312 ")
Char_type.additem (" ")

Char_size.additem ("9 ")
Char_size.additem ("10 ")
Char_size.additem ("11 ")
Char_size.additem ("12 ")
Char_size.additem ("14 ")
Char_size.additem ("16 ")
Char_size.additem ("18 ")
Char_size.additem ("20 ")

Char_vhp.additem ("100% ")
Char_vhp.additem ("80% ")
Char_vhp.additem ("60% ")
Char_vhp.additem ("40% ")
Char_vhp.additem ("20% ")
End sub
(Running environment: pⅱ 400 Lenovo, Windows98, VB6.0)

Author member name: wangsb

Description: Wang shoubing (Email: wangshoubing@sina.com), computer center of Taihe Hospital (442000), Shiyan City, Hubei Province, male. He graduated from Hubei Institute of Technology computer and Application in July 1994, in August of the same year, he was assigned to Taihe Hospital in Shiyan City, Hubei Province (with approximately 1500 employees and 1200 beds). He has been mainly engaged in local area network maintenance in hospitals, he is also engaged in application software development. He mainly developed the Salary Management System of Taihe Hospital in Shiyan city, the fund-raising settlement system for employees in Taihe Hospital in Shiyan City, and the out-of-hospital outpatient Charging System in Taihe Hospital in Shiyan city, five papers were published in e-product maintenance and production, medical equipment, medical equipment information, and other magazines.

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.