欢迎光临
我们一直在努力

在场景中输出横向或纵向压缩的中文字符-.NET教程,评论及其它

建站超值云服务器,限时71元/月

private const lf_facesize = 32

private const fw_normal = 400

private const fw_bold = 700

private const ff_dontcare = 0

private const default_quality = 0

private const default_pitch = 0

private const default_charset = 1

private const dt_calcrect = &h400

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(lf_facesize) as byte

end type

private type rect

left as long

top as long

right as long

bottom as long

end type

private declare function createfontindirect lib "gdi32" alias "createfontindirecta" (lplogfont as logfont) as long

private declare function deleteobject lib "gdi32" (byval hobject as long) as long

private declare function drawtext lib "user32" alias "drawtexta" (byval hdc as long, byval lpstr as string, byval ncount as long, lprect as rect, byval wformat as long) as long

private declare function selectobject lib "gdi32" (byval hdc as long, byval hobject as long) as long

private declare function offsetrect lib "user32" (lprect as rect, byval x as long, byval y as long) as long

private sub printtext(byval hdc as long, byval mystr as string, myfont as stdfont, optional byval fontwidth as integer = 30, optional byval fontheight as integer = 15, optional byval fontbold as boolean = false, optional byval fontitlaic as boolean = false, optional byval fontunderline as boolean = false, optional byval fontstrikethrough as boolean = false)

dim tlf as logfont

dim hfnt as long

dim hfntold as long

dim tr as rect

dim sfont as string

dim ichar as integer

dim temp() as byte

convert an ole stdfont to a logfont structure:

with tlf

sfont = myfont.name

temp = strconv(sfont, vbfromunicode)

for ichar = 1 to len(sfont)

.lffacename(ichar – 1) = temp(ichar – 1)

next ichar

based on the win32sdk documentation:

.lfitalic = myfont.italic

lfweight = iif(myfont.bold, fw_bold, fw_normal)

.lfwidth = fontwidth

.lfheight = fontheight

.lfunderline = fontunderline

.lfstrikeout = fontstrikethrough

.lfcharset = myfont.charset

end with

hfnt = createfontindirect(tlf) convert the logfont into a font handle

test the font out:

hfntold = selectobject(hdc, hfnt)

drawtext hdc, mystr, -1, tr, dt_calcrect

offsetrect tr, 32, 32

drawtext hdc, mystr, -1, tr, 0&

selectobject hdc, hfntold

remember to delete the font when finished

deleteobject hfnt

end sub

private sub command1_click()

me.cls

dim myfont as new stdfont

myfont.name = "arial"

printtext me.hdc, "扁扁的几个字", myfont, 50, 20

end sub

private sub command2_click()

dim myfont as new stdfont

myfont.name = "arial"

printtext me.hdc, "修长的几个字", myfont, 10, 200, true, true, false, false

end sub

赞(0)
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com 特别注意:本站所有转载文章言论不代表本站观点! 本站所提供的图片等素材,版权归原作者所有,如需使用,请与原作者联系。未经允许不得转载:IDC资讯中心 » 在场景中输出横向或纵向压缩的中文字符-.NET教程,评论及其它
分享到: 更多 (0)