VB using the API Implementation Font Common dialog box example

Source: Internet
Author: User
Tags call back integer
dialog box Private Const lf_facesize = 32
Private Const cf_printerfonts = &h2
Private Const cf_screenfonts = &h1
Private Const Cf_both = (cf_screenfonts Or cf_printerfonts)
Private Const cf_effects = &H100&
Private Const cf_forcefontexist = &h10000
Private Const cf_inittologfontstruct = &H40&
Private Const cf_limitsize = &H2000&
Private Const Regular_fonttype = &h400

' CharSet Constants

Private Const ansi_charset = 0
Private Const arabic_charset = 178
Private Const Baltic_charset = 186
Private Const Chinesebig5_charset = 136
Private Const default_charset = 1
Private Const Easteurope_charset = 238
Private Const Gb2312_charset = 134
Private Const Greek_charset = 161
Private Const Hangeul_charset = 129
Private Const Hebrew_charset = 177
Private Const Johab_charset = 130
Private Const Mac_charset = 77
Private Const Oem_charset = 255
Private Const Russian_charset = 204
Private Const shiftjis_charset = 128
Private Const Symbol_charset = 2
Private Const Thai_charset = 222
Private Const Turkish_charset = 162

Private Type LogFont


Lfheight as Long
Lfwidth as Long
Lfescapement as Long
Lforientation as Long
Lfweight as Long
Lfitalic as Byte
Lfunderline as Byte
Lfstrikeout as Byte
lfCharSet as Byte
Lfoutprecision as Byte
Lfclipprecision as Byte
Lfquality as Byte
Lfpitchandfamily as Byte
Lffacename as String * 31
End Type
Private Type Choosefont
lStructSize as Long
hWndOwner as Long ' caller ' s window handle
HDC as Long ' printer Dc/ic or NULL
lpLogFont as Long ' ptr. to a logfont struct
Ipointsize as Long ' * size in points of selected font
Flags as Long ' enum. Type flags
Rgbcolors as Long ' returned text color
Lcustdata as Long ' data passed to hook FN.
Lpfnhook as Long ' ptr. To hook function
Lptemplatename as String ' custom template name
HInstance as Long ' instance handle of. EXE that
' Contains Cust. Dlg. Template
Lpszstyle as String ' return to the style field here
' must be lf_facesize or bigger
nFontType as Integer ' same value reported to the Enumfonts
' Call back with the extra fonttype_
' bits added
Missing_alignment as Integer
Nsizemin as Long ' minimum pt size allowed &
Nsizemax as Long ' max PT size allowed if
' Cf_limitsize is used
End Type

Private Declare Function choosefont Lib "Comdlg32.dll" Alias "Choosefonta" _
(ByRef Pchoosefont as Choosefont) As Long
Private Sub Command1_Click ()
Dim CF as Choosefont, Lfont as LogFont
Dim FontName as String, ret as Long
Cf.flags = Cf_both or cf_effects or cf_forcefontexist or cf_inittologfontstruct or cf_limitsize
Cf.lplogfont = VarPtr (Lfont)
Cf.lstructsize = LenB (CF)
' cf.lstructsize = Len (cf) ' size of structure
Cf.hwndowner = Form1.hwnd ' window Form1 is opening this dialog box
CF.HDC = Printer.hdc ' device context of default Printer (using VB ' s mechanism)
cf.rgbcolors = RGB (0, 0, 0) ' Black
Cf.nfonttype = Regular_fonttype ' REGULAR font type i.e. not bold or anything
Cf.nsizemin = Ten ' minimum point size
Cf.nsizemax = maximum point size
ret = choosefont (CF) ' brings up the font dialog
IF ret <> 0 Then ' success
FontName = StrConv (Lfont.lffacename, Vbunicode, &h804) ' Retrieve Chinese font name in 中文版 version os
FontName = left$ (FontName, INSTR (1, FontName, vbNullChar)-1)
' Assign the font properties to Text1
With Text1.font
. Charset = Lfont.lfcharset ' Assign Charset to font
. Name = FontName
. Size = CF.IPOINTSIZE/10 ' Assign point size
Text1.Text =. Name & ":" &. Charset & ":" &. Size ' Display data in chosen Font
End With
End If
End Sub





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.