在程序中如何设置打印机?在线教程
//先定义局部函数如下:
FUNCTION ulong GetWindowsDirectoryA(ref string wdir, ulong buf) LIBRARY "kernel32.dll"
//内部变量
string is_winpathfile
//编写读取已经安装的打印机清单:
string ls_WindowsDirctory
ulong lu_Buf
boolean lb_PrinterExists
string ls_printer,ls_tmp,ls_printers[]
int li_point
integer li_rtn,li_ArrayUp,li_step
lu_Buf = 144
ls_WindowsDirctory = Space(144)
//得到系统目录
GetWindowsDirectoryA(ls_WindowsDirctory,lu_Buf)
is_winpathfile = ls_WindowsDirctory + "\win.ini"
//判断系统是否安装打印机
li_rtn = RegistryKeys("HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Print\Printers", ls_printers)
IF li_rtn = 1 THEN
li_ArrayUp = UpperBound(ls_printer)
IF li_ArrayUp >= 1 THEN
FOR li_step = 1 TO li_ArrayUp
ddlb_printers.additem ( ls_Printer[li_step] )
lb_PrinterExists = true
NEXT
else
lb_PrinterExists = false
end if
else
lb_PrinterExists = false
end if
IF NOT lb_PrinterExists THEN
messagebox ("提示!","尚未安装打印机!")
ELSE
ls_tmp = profilestring (is_winpathfile,"windows","device","")
ls_tmp = trim (ls_tmp)
li_point = pos (ls_tmp,",",1)
ls_printer = left (ls_tmp,li_point - 1)
IF trim (ls_printer) <> "" AND NOT IsNull (ls_printer) THEN
ddlb_printers.text = trim (ls_printer)
ELSE
ddlb_printers.selectitem (1)
END IF
END IF
//在selectchanged事件中编程:
string ls_printer
ls_printer = profilestring(is_winpathfile,"Devices",trim(this.text (index)),"")
//修改win.ini文件
setprofilestring(is_winpathfile,"windows","device",trim(this.text (index)) + "," +ls_printer)
//修改注册表文件
RegistrySet("HKEY_CURRENT_CONFIG\System\CurrentControlSet\Control\Print\Printers","Default", trim(this.text))