在delphi中如何判断有没有默认的 打印机?

lpf78 2001-11-19 02:55:11
各位:
在delphi中如何判断本机有没有安装默认的 打印机?
多谢!!!!1
...全文
110 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
thygw 2001-11-19
  • 打赏
  • 举报
回复
if printer.Printers.Count=0 then
application.MessageBox();
cobi 2001-11-19
  • 打赏
  • 举报
回复
ADevice, ADriver, APort:array [0..255] of Char;
DeviceHandle:THandle;
DevMode:PDeviceMode;//TDeviceMode指针
begin
{首先获取TPrinter的DeviceMode结构的句柄}
PrinterGetPrinter(ADevice, ADriver, APort, DeviceHandle);
{如果句柄是0, 表示打印机没有装载}
if DeviceHandle=0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPritner(ADevice, ADriver, APort, DeviceHandle);
end;
{如果DeviceHandle还是0, 表示有错误发生。否则,就调用}
{GlobalLock来获取TDeviceMode结构的指针}
if DeviceHandle=0 then
Raise Exception.Create('Could Not Initialize TDeviceMode structure')
else
DevMode:=GlobalLock(DeviceHandle);
{下面是设置纸张大小}
with DevMode^ do
begin
dmFields:=dmFields or DM_PAPERSIZE;
dmPaperSize:=DMPADER_LETTER;//LETTER,8-1/2
{如果纸张大小由dmPaperWidth和dmPaperLength设置,则dmPaperSize的值可以设为0}
//dmFields:=dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH;
//dmPaperLength:=somelength;
//dmPaperWidth:=somewidth;
end;
if not DeviceHandle=0 then
GlobalUnlock(DeviceHandle);
end;
关于TDeviceMode的详细情况参阅Win32 Programmer's Reference的DEVMODE主题

5,392

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧