X
xhqing
Unregistered / Unconfirmed
GUEST, unregistred user!
我想用代码动态实现设置成A3纸张打印,quickReport 的quickrep1组件的页面属性就设置到了,就是系统打印机的纸张属性没有设置到,我分别尝试用了以下三个WindowsAPI调用都无济于事,请您帮忙,万分感谢:(QuickReport的版本为3.09+Delphi7,不知QuickReport 4.06有没有类似问题)
quickrep1.Page.Length:=297;
quickrep1.Page.Width :=420;
quickrep1.Page.Orientation:=poPortrait;
qrlabel2.Caption:='纸张规格: '+inttostr(round(quickrep1.Page.Width))+' × '+inttostr(round(quickrep1.Page.Length));
implementation
Procedure SetPage(pagewidth,pageheight:real);
var
Device : array[0..cchDeviceName-1] of Char;
Driver : array[0..(MAX_PATH-1)] of Char;
Port : array[0..32]of Char;
hDMode : THandle;
pDMode : PDevMode;
begin
Printer.GetPrinter(Device,Driver,Port,hDMode);
// 获取打印机DevMode 结构的句柄值,存放在hDMode 中
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
// 获取指向打印机DevMode 结构的指针
if pDMode <> nil then
begin
pDMode^.dmPaperSize := 256;
// 如果要将当前打印机纸张变为自定义 dmPaperSize 必须设置成256
pDMode^.dmPaperLength := round(pageheight*10);
pDMode^.dmPaperWidth := round(pagewidth*10);
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE;
pDMode^.dmFields :=pDMode^.dmFields or DM_PAPERLENGTH;
pDMode^.dmFields :=pDMode^.dmFields or DM_PAPERWIDTH;
//以上三条语句是对相应的dmFields 成员进行置位。
ResetDC(Printer.Handle,pDMode^);
// 设置打印机设备环境句柄的值
GlobalUnlock(hDMode);
end;
end;
end;
procedure PreparePrinter;
var
aDevice: array[0..CCHDEVICENAME-1] of Char;
aDriver: array[0..MAX_PATH-1] of Char;
aPort: array[0..31] of Char;
hDevMode: THandle;
pDevMode: PDeviceMode;
begin
// 获取打印机DeviceMode的句柄
Printer.GetPrinter(aDevice, aDriver, aPort, hDevMode);
if hDevMode <> 0 then
begin
// 获取指向DeviceMode的指针
pDevMode := GlobalLock(hDevMode);
if pDevMode <> nil then
begin
pDevMode^.dmPaperSize := DMPAPER_USER;
pDevMode^.dmPaperLength := 2970;
pDevMode^.dmPaperWidth := 4200;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERSIZE;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERLENGTH;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERWIDTH;
ResetDC(Printer.Handle, pDevMode^);
GlobalUnlock(hDevMode);
end;
end;
end;
procedure myset;
var
ADevice, ADriver, APort: array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin
//初始化打印机
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;
if DeviceHandle = 0 then
Raise Exception.Create('不能初始化打印机!')
else
DevMode := GlobalLock(DeviceHandle);
if DeviceHandle <> 0 then
begin
with DevMode^ do
begin
dmFields := dmFields or DM_ORIENTATION;
//在下面这里设置打印方向
dmOrientation := DMORIENT_LANDSCAPE;
//DMORIENT_PORTRAIT
dmPaperSize := DMPAPER_A3;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
GlobalUnLock(DeviceHandle);
end;
end;
end;
{$R *.dfm}
quickrep1.Page.Length:=297;
quickrep1.Page.Width :=420;
quickrep1.Page.Orientation:=poPortrait;
qrlabel2.Caption:='纸张规格: '+inttostr(round(quickrep1.Page.Width))+' × '+inttostr(round(quickrep1.Page.Length));
implementation
Procedure SetPage(pagewidth,pageheight:real);
var
Device : array[0..cchDeviceName-1] of Char;
Driver : array[0..(MAX_PATH-1)] of Char;
Port : array[0..32]of Char;
hDMode : THandle;
pDMode : PDevMode;
begin
Printer.GetPrinter(Device,Driver,Port,hDMode);
// 获取打印机DevMode 结构的句柄值,存放在hDMode 中
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
// 获取指向打印机DevMode 结构的指针
if pDMode <> nil then
begin
pDMode^.dmPaperSize := 256;
// 如果要将当前打印机纸张变为自定义 dmPaperSize 必须设置成256
pDMode^.dmPaperLength := round(pageheight*10);
pDMode^.dmPaperWidth := round(pagewidth*10);
pDMode^.dmFields := pDMode^.dmFields or DM_PAPERSIZE;
pDMode^.dmFields :=pDMode^.dmFields or DM_PAPERLENGTH;
pDMode^.dmFields :=pDMode^.dmFields or DM_PAPERWIDTH;
//以上三条语句是对相应的dmFields 成员进行置位。
ResetDC(Printer.Handle,pDMode^);
// 设置打印机设备环境句柄的值
GlobalUnlock(hDMode);
end;
end;
end;
procedure PreparePrinter;
var
aDevice: array[0..CCHDEVICENAME-1] of Char;
aDriver: array[0..MAX_PATH-1] of Char;
aPort: array[0..31] of Char;
hDevMode: THandle;
pDevMode: PDeviceMode;
begin
// 获取打印机DeviceMode的句柄
Printer.GetPrinter(aDevice, aDriver, aPort, hDevMode);
if hDevMode <> 0 then
begin
// 获取指向DeviceMode的指针
pDevMode := GlobalLock(hDevMode);
if pDevMode <> nil then
begin
pDevMode^.dmPaperSize := DMPAPER_USER;
pDevMode^.dmPaperLength := 2970;
pDevMode^.dmPaperWidth := 4200;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERSIZE;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERLENGTH;
pDevMode^.dmFields := pDevMode^.dmFields or DM_PAPERWIDTH;
ResetDC(Printer.Handle, pDevMode^);
GlobalUnlock(hDevMode);
end;
end;
end;
procedure myset;
var
ADevice, ADriver, APort: array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin
//初始化打印机
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
if DeviceHandle = 0 then
begin
Printer.PrinterIndex := Printer.PrinterIndex;
Printer.GetPrinter(ADevice, ADriver, APort, DeviceHandle);
end;
if DeviceHandle = 0 then
Raise Exception.Create('不能初始化打印机!')
else
DevMode := GlobalLock(DeviceHandle);
if DeviceHandle <> 0 then
begin
with DevMode^ do
begin
dmFields := dmFields or DM_ORIENTATION;
//在下面这里设置打印方向
dmOrientation := DMORIENT_LANDSCAPE;
//DMORIENT_PORTRAIT
dmPaperSize := DMPAPER_A3;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
GlobalUnLock(DeviceHandle);
end;
end;
end;
{$R *.dfm}