windows 是如何识别连接的打印机并识别出其品牌和型号的? windows 是如何识别连接的打印机并识别出其品牌和型号的?用代码如何实现? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 驱动啊,windows已经做好了直接取就行了,可以参考下打印对话框的VCL源码。 获取当前打印机的名称、驱动程序、打印端口信息:以下是来自Borland公司的完整例子。请注意其中两条判断语句,这说明有时候仅仅凭getprinters并不能保证信息的正确,还需要WIN.INI的帮助。uses printers;{$IFNDEF WIN32}const MAX_PATH = 144;{ENDIF}procedure TForm1.Button1Click(Sender : TObject);var pDevice : pChar; pDriver : pChar; pPort : pChar; hDMode : THandle;begin if PrintDialog1.Execute then begin GetMem(pDevice,cchDeviceName); GetMem(pDriver,MAX_PATH); GetMem(pPort,MAX_PATH); Printer.GetPrinter(pDevice,pDriver,pPort,hDMode); if lStrLen(pDriver) = 0 then begin GetProfileString('Devices',pDevice,'',pDriver,MAX_PATH); pDriver[pos(',',pDriver) - 1] := #0; end; if lStrLen(pPort) = 0 then begin GetProfileString('Devices',pDevice,'',pPort,MAX_PATH); lStrCpy(pPort,@pPort[lStrLen(pPort) + 2]); end; FreeMem(pDevice,cchDeviceName); FreeMem(pDriver,MAX_PATH); FreeMem(pPort,MAX_PATH); end;end; 在Windows的Win.ini文件中有下面的一些配置信息:[Windows]load = run =NullPort = Nonedevice = HPLaserJetIII,HPPCL5MS,LPT1............. 其中Windows节的device键中指明了当前系统中默认打印机的信息。可以通过WindowsAPI函数GetProfileString获取该信息。函数GetProfileString的原形如下: DWORDGetProfileString( LPCTSTRlpAppName, //指定节名的字符串 LPCTSTRlpKeyName, //指定键名的字符串 LPCTSTRlpDefault, //没有找到键名时返回的字符串 LPTSTRlpReturnedString, //在键名找到时返回的字符串 DWORDnSize //lpReturnedString的字节数 ); 查看表中记录有没有增多 窗体释放的问题 急急急!!!关于datetimepicker的小问题。请指点,谢谢! 因项目需要,学习delphi,各位以后多指点!另求实例下载网址 在组件中如何获得颜色?(有一点问题的,看下文)! 帮我提点建议 关于adoconnection对象的问题 如何让delphi编的程序在最小化时像网络蚂蚁一样只在右下脚的系统托盘显示? 怎样预览A3纸的报表? 各位大哥,请帮帮忙!!! 如何让hook拦截到的按键消息区分大小写? 数据采集源码,低价转让,代理采集数据!!
以下是来自Borland公司的完整例子。请注意其中两条判断语句,这说明有时候仅仅凭getprinters并不能保证信息的正确,还需要WIN.INI的帮助。
uses printers;
{$IFNDEF WIN32}
const MAX_PATH = 144;
{ENDIF}
procedure TForm1.Button1Click(Sender : TObject);
var
pDevice : pChar;
pDriver : pChar;
pPort : pChar;
hDMode : THandle;
begin
if PrintDialog1.Execute then begin
GetMem(pDevice,cchDeviceName);
GetMem(pDriver,MAX_PATH);
GetMem(pPort,MAX_PATH);
Printer.GetPrinter(pDevice,pDriver,pPort,hDMode);
if lStrLen(pDriver) = 0 then begin
GetProfileString('Devices',pDevice,'',pDriver,MAX_PATH);
pDriver[pos(',',pDriver) - 1] := #0;
end;
if lStrLen(pPort) = 0 then begin
GetProfileString('Devices',pDevice,'',pPort,MAX_PATH);
lStrCpy(pPort,@pPort[lStrLen(pPort) + 2]);
end;
FreeMem(pDevice,cchDeviceName);
FreeMem(pDriver,MAX_PATH);
FreeMem(pPort,MAX_PATH);
end;
end;
[Windows]
load =
run =
NullPort = None
device = HPLaserJetIII,HPPCL5MS,LPT1
.............
其中Windows节的device键中指明了当前系统中默认打印机的信息。可以通过WindowsAPI函数GetProfileString获取该信息。函数GetProfileString的原形如下:
DWORDGetProfileString(
LPCTSTRlpAppName, //指定节名的字符串
LPCTSTRlpKeyName, //指定键名的字符串
LPCTSTRlpDefault, //没有找到键名时返回的字符串
LPTSTRlpReturnedString, //在键名找到时返回的字符串
DWORDnSize //lpReturnedString的字节数
);