首页 > 开发 > 综合 > 正文

VB中获取指定打印机的各种纸张类型及大小

2024-07-21 02:25:11
字体:
来源:转载
供稿:网友

商业源码热门下载www.html.org.cn

  放入一个msflexgrid,名称为fgd1,列数为4'option explicit
private const dc_maxextent = 5
private const dc_minextent = 4
private const dc_papernames = 16
private const dc_papers = 2
private const dc_papersize = 3
private declare function devicecapabilities lib "winspool.drv" alias "devicecapabilitiesa" (byval lpdevicename as string, byval lpport as string, byval iindex as long, lpoutput as any, lpdevmode as any) as long
private type points
        x  as long
        y  as long
end type
private sub form_load()
dim i as longwith fgd1
    .clear
   
    .formatstring = "^纸张编号|^纸张名称|^纸张长度|^纸张宽度"
    for i = 0 to .cols - 1
        .colwidth(i) = 1700
    next i
    .allowuserresizing = flexresizecolumns
    .left = 0
    .width = me.scalewidth
end withgetpaperinfoend subprivate sub getpaperinfo()
dim i as long, ret as long
dim length as integer, width as integer
dim paperno() as integer, papername() as string, papersize() as points'支持最大打印纸:
ret = devicecapabilities(打印机名称, "lpt1", dc_maxextent, byval 0&, byval 0&)
length = ret / 65536
width = ret - length * 65536
'lblmaxlength.caption = length
'lblmaxwidth.caption = width'支持最小打印纸:
ret = devicecapabilities(打印机名称, "lpt1", dc_minextent, byval 0&, byval 0&)
length = ret / 65536
width = ret - length * 65536
'支持纸张种类数
ret = devicecapabilities(打印机名称, "lpt1", dc_papers, byval 0&, byval 0&)'纸张编号
redim paperno(1 to ret) as integer
call devicecapabilities(打印机名称, "lpt1", dc_papers, paperno(1), byval 0&)'纸张名称
dim arrpagename() as byte
dim allnames as string
dim lstart as long, lend as long
redim papername(1 to ret) as string
redim arrpagename(1 to ret * 64) as byte
call devicecapabilities(打印机名称, "lpt1", dc_papernames, arrpagename(1), byval 0&)
allnames = strconv(arrpagename, vbunicode)
'loop through the string and search for the names of the papers
i = 1
do
    lend = instr(lstart + 1, allnames, chr$(0), vbbinarycompare)
    if (lend > 0) and (lend - lstart - 1 > 0) then
        papername(i) = mid$(allnames, lstart + 1, lend - lstart - 1)
        i = i + 1
    end if
    lstart = lend
loop until lend = 0'纸张尺寸redim papersize(1 to ret) as points
call devicecapabilities(form2.combo1.text, "lpt1", dc_papersize, papersize(1), byval 0&)'显示在表格中
for i = 1 to ret
    fgd1.additem paperno(i) & vbtab & papername(i) & vbtab & papersize(i).y & vbtab & papersize(i).x
next i'移除第一个空行
fgd1.row = 1
fgd1.removeitem 1
end subprivate sub form_resize()
with fgd1
    .left = 0
    .width = me.scalewidth
    .height = me.scaleheight
    .top = 0
end withend sub
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表