通过程序设置打印机

  易飞的报表打印方向(横向和纵向)是取自默认打印机的设置,所以你会发现如果系统中没有默认打印机的话易飞是无法设计报表的。有客户反映有的报表格式比较固定(横向),由于操作繁琐故没有必要每次都把纸张的方向从纵向设置为横向。

  我们可以在设计报表ReportViewer元件对这些报表作业时把打印机临时设为横向,待退出处理后再恢复回来。实现代码如下:

Code
public
FChange: Boolean;
。。。。。。
procedure TfrmReportViewer.FormShow(Sender: TObject);
var

ADevice, ADriver, APort:
array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin

//^_^ 20080911 ADD BY ==start 设置为横向
FChangeProperty :
=
False;

If FReportID
= 'COPR01'
THEN
Begin
{

方法一:用的时候把弹出窗体去掉,直接确认即可
ShellExecute(0, 'OPEN', PChar('D:\Conductor70\C_Dsbin\HP_A4_H.reg'), nil, nil, SW_SHOWNORMAL);
WinExec(PChar('D:\Conductor70\C_Dsbin\HP_A4_H.reg'), 1);
}
//
方法二:
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;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
GlobalUnLock(DeviceHandle);
end
;
end
;
FormatChange;
RepaintArea(
0
, ToolBar.Height, VScrollBar.Left, HScrollBar.Top);

FChangeProperty :
=
True;
End;
//^_^ 20080911 ADD BY ==end


inherited;

end
;


procedure TfrmReportViewer.FormClose(Sender: TObject;var
Action: TCloseAction);
var

ADevice, ADriver, APort:
array[0..255] of Char;
DeviceHandle: THandle;
DevMode: PDeviceMode;
begin

//^_^ 20080911 ADD BY ==start 设置为纵向
If FChange THEN
Begin
//
方法一:用时候去掉确认窗
//ShellExecute(0, 'OPEN', PChar('D:\Conductor70\C_Dsbin\HP_A4_L.reg'), nil, nil
, SW_SHOWNORMAL);

//
方法二:
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_PORTRAIT;
Printer.SetPrinter(ADevice, ADriver, APort, DeviceHandle);
GlobalUnLock(DeviceHandle);
end
;
end
;

End;
//^_^ 20080911 ADD BY ==end


WriteTransferDataIni([
is
_ShowSetting]);
Disconnect;
// if ((FReportSource= rs_Leader)or(FReportSource= rs_VarLeader))then

if (FReportSource= rs_Leader) then
Action:
= caFree
else Action:=
caHide;
end;
posted @ 2008-09-11 10:44  威尼斯的夏天  阅读(689)  评论(0编辑  收藏  举报