求助:向高手请教关于修改打印机设置的问题,着急呀 ( 积分: 100 )

  • 主题发起人 主题发起人 ww10326
  • 开始时间 开始时间
W

ww10326

Unregistered / Unconfirmed
GUEST, unregistred user!
procedure Tfrmrep_base.ToolButton2Click(Sender: TObject);
var
aDevice,aDriver,aPort:array[0..255] of char;
DeviceHandle:Thandle;
DevMode:PDeviceMode
begin
if printer.printers.count>0 then
begin
// printer:=Tprinter.Create;
printer.Refresh;
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 begin
DevMode:=GlobalLock(DeviceHandle);
with DevMode^ do
begin
dmFields:=dmFields or DM_PAPERSIZE or DM_FORMNAME;
dmPaperSize:=DMPAPER_A3;
// dmPaperLength:=2097;
// dmPaperWidth:=4200;

end;
end;//else
if not DeviceHandle=0 then
GlobalUnlock(DeviceHandle);
Printer.PrinterIndex := Printer.PrinterIndex;
end
else
begin
application.messagebox('dd',mb_ok);
end;
上面程序执行完以后打印机默认还是A4纸,没起作用,哪位帮忙看看问题出在哪里?
 
procedure Tfrmrep_base.ToolButton2Click(Sender: TObject);
var
aDevice,aDriver,aPort:array[0..255] of char;
DeviceHandle:Thandle;
DevMode:PDeviceMode
begin
if printer.printers.count>0 then
begin
// printer:=Tprinter.Create;
printer.Refresh;
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 begin
DevMode:=GlobalLock(DeviceHandle);
with DevMode^ do
begin
dmFields:=dmFields or DM_PAPERSIZE or DM_FORMNAME;
dmPaperSize:=DMPAPER_A3;
// dmPaperLength:=2097;
// dmPaperWidth:=4200;

end;
end;//else
if not DeviceHandle=0 then
GlobalUnlock(DeviceHandle);
Printer.PrinterIndex := Printer.PrinterIndex;
end
else
begin
application.messagebox('dd',mb_ok);
end;
上面程序执行完以后打印机默认还是A4纸,没起作用,哪位帮忙看看问题出在哪里?
 
你用的XP或2000的系统就是这样的,你可以在打印机窗口中击右键选择服务器选项
 
看看这个行不行。。。。
type
TForm1 = class(TForm)
Button1: TButton;
Image1: TImage;
Image2: TImage;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

{$R *.dfm}

procedure PrintPaperSize(Width,Length:integer);
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);
if hDMode <> 0 then
begin
pDMode := GlobalLock(hDMode);
if pDMode <> nil then
begin
pDMode^.dmPaperSize:=256;
pDMode^.dmPaperLength:=Length ;
pDMode^.dmPaperWidth:=Width;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERSIZE;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERLENGTH;
pDMode^.dmFields:=pDMode^.dmFields or DM_PAPERWIDTH;
ResetDC(Printer.Handle,pDMode^);
GlobalUnlock(hDMode);
end;
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
MyPrint:TPrinter;
Rect1:TRect;
begin
with Image1 do
begin
Canvas.TextOut(0,0,'第一个打印测试程序');
Canvas.MoveTo(0,20);
Canvas.LineTo(1200,300);
end;
with Rect1 do
begin
Left:=0;
Top:=0;
Right:=Image1.Width;
Bottom:=Image1.Height;
end;
Image2.Canvas.Draw(0,0,Image1.Picture.Graphic);
MyPrint:=TPrinter.Create;
PrintPaperSize(30,30);
with MyPrint do
begin
BeginDoc;
Canvas.StretchDraw(Canvas.ClipRect,Image2.Picture.Graphic);
Canvas.Draw(0,0,Image2.Picture.Graphic);
EndDoc;
end;
FreeAndNil(MyPrint);
end;

end.
 
后退
顶部