我现在的打印起始页以及打印总页数都保存在ini文件中,打印的时候读取文件,并在QRCompositeReport中设置。但是用户说,有时候的设置不起作用。
另外,对于一台电脑装了多台打印机,那么我怎么能获取第一次设置的打印机,并保存有关信息,以后打印的时候就不需要再去设置默认打印机呢?
谢谢大家了。特别急……
分不够可以再加
另外,对于一台电脑装了多台打印机,那么我怎么能获取第一次设置的打印机,并保存有关信息,以后打印的时候就不需要再去设置默认打印机呢?
谢谢大家了。特别急……
分不够可以再加
现在我想再添加一块,专门设置打印机的信息,然后将信息保存到ini文件中,打印的时候再读,决定用哪台打印机打印(主要是为解决一台电脑装多个打印机的问题,不用每次都选择默认打印机)。
---------------------------------------------------------------------------
没别的办法,还是单部调试,看是否确实读Ini文件了
怎么能获取第一次设置的打印机,并保存有关信息,以后打印的时候就不需要再去设置默认打印机
---------------------------------------------------------------------------
delphi设置默认打印机:uses printers;procedure SetDefaultPrinter(const printerindex:integer);
Var
FHandle : THandle;
HPrt : THandle;
PrtInfo5: PPrinterInfo5;
FDevice: array[0..79] of char;
FDriver: array[0..79] of char;
FPort: array[0..79] of char;begin {printerindex为选中打印机的索引,如果使用打印机名称,则此句可忽略}
Printer.PrinterIndex := printerindex; Printer.GetPrinter (FDevice, FDriver, FPort, FHandle);
OpenPrinter(FDevice, HPrt, nil);
if HPrt = 0 then
raise(Exception.Create('不能打开打印机'));
try
PrtInfo5 := GetPrinterInfo5(HPrt);
PrtInfo5.Attributes := PrtInfo5.Attributes +
PRINTER_ATTRIBUTE_DEFAULT;
SetPrinter(HPrt,5,PrtInfo5,PRINTER_CONTROL_SET_STATUS);
FreeMem(PrtInfo5);
finally
ClosePrinter(HPrt);
end;end;
var
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;