hbrasch
asked on
Change Printer/ Get new Information
hi out there...
i´ve got a problem. I got 2 SONY
UP-D2500 Printer. One on LPT1 one
one LPT2. The printer on LPT2 is
prepared for printing sticker, the
other one for postcards also defined as standard printer. Now i want
to change the printeroutput
with Tprinter.printerindex. No problem
but when i´ll try to get the dimensions
of the printer (Tprinter.pagewidth and
pageheight) delphi gives me the
dimenstion of the default printer. naughty naughty delphi... the other way,
wenn I define the sticker printer as
default, and i want to print postcards... i´ll only retriev the stickerheight and width ... no chance
for me at the moment.
what i want is the print on the postcards printer, retriev the postcards printer dimensions and when i want to print on the sticker printer, i´ll want to retriev the sticker size !
please help,
Heinz
i´ve got a problem. I got 2 SONY
UP-D2500 Printer. One on LPT1 one
one LPT2. The printer on LPT2 is
prepared for printing sticker, the
other one for postcards also defined as standard printer. Now i want
to change the printeroutput
with Tprinter.printerindex. No problem
but when i´ll try to get the dimensions
of the printer (Tprinter.pagewidth and
pageheight) delphi gives me the
dimenstion of the default printer. naughty naughty delphi... the other way,
wenn I define the sticker printer as
default, and i want to print postcards... i´ll only retriev the stickerheight and width ... no chance
for me at the moment.
what i want is the print on the postcards printer, retriev the postcards printer dimensions and when i want to print on the sticker printer, i´ll want to retriev the sticker size !
please help,
Heinz
Why not post this question to Borland ?!!
Try to call TPrinter.Refresh after setting the printerindex
Heinz
I don;t have exactly the same setup as you but there are 2 printers attached to my machine and the following code DOES correctly return the page width and height data from each of them.
PROCEDURE TForm1.Button1Click(Sender : TObject);
VAR
n : INTEGER;
begin
ListBox1.Items.Assign(Prin ter.Printe rs);
FOR n := 0 TO (ListBox1.Items.Count - 1)
DO
BEGIN
Printer.PrinterIndex := n;
ListBox1.Items[n] := ListBox1.Items[n] + ' [' + IntToStr(Printer.PageWidth ) + 'x' + IntToStr(Printer.PageHeigh t) + ']';
END;
end;
This will at least prove that Delphi is aware of both your printers. As to why it's getting the dimensions wrong on your system then it could be Windows trying to do something 'clever'.
The Neil
I don;t have exactly the same setup as you but there are 2 printers attached to my machine and the following code DOES correctly return the page width and height data from each of them.
PROCEDURE TForm1.Button1Click(Sender
VAR
n : INTEGER;
begin
ListBox1.Items.Assign(Prin
FOR n := 0 TO (ListBox1.Items.Count - 1)
DO
BEGIN
Printer.PrinterIndex := n;
ListBox1.Items[n] := ListBox1.Items[n] + ' [' + IntToStr(Printer.PageWidth
END;
end;
This will at least prove that Delphi is aware of both your printers. As to why it's getting the dimensions wrong on your system then it could be Windows trying to do something 'clever'.
The Neil
ASKER
To PeterLarsen:
I´ll do too.
To BrunoHe:
Didn´t work ! I´ll tried allready!
To TheNeil:
noep, that didn´t work... both printer
got the same dimension.
Step by step i think that´s because
both printer are using the same
driver....
thanks
Heinz
I´ll do too.
To BrunoHe:
Didn´t work ! I´ll tried allready!
To TheNeil:
noep, that didn´t work... both printer
got the same dimension.
Step by step i think that´s because
both printer are using the same
driver....
thanks
Heinz
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Hi, something simular was given once by Raymond
unit PrinterDevices1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Printers;
const
DM_ORIENTATION = 1;
DM_PAPERSIZE = 2;
DM_PAPERLENGTH = 4;
DM_PAPERWIDTH = 8;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
PrinterSetupDialog1: TPrinterSetupDialog;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender : TObject);var
ADevice, ADriver, APort: array [0..255] of char;
ADeviceMode: THandle;
DevMode: PDevMode;
begin
with Printer do
begin
GetPrinter(ADevice,ADriver ,APort,ADe viceMode);
DevMode := GlobalLock(ADeviceMode);
if not Assigned(DevMode) then showMessage('can't find printer')
else
begin
with DevMode^ do
begin
memo1.lines.add('Source ' + IntToStr(dmDefaultSource)) ; // check
the constants
memo1.lines.add('Orientati on ' + IntToStr(dmOrientation)); // check
the constants
memo1.lines.add('Papersize ' + IntToStr(dmPaperSize)); // check the
constants
end;
end;
// etc.
// HAVE A LOOK INTO WINDOWS.PAS FOR MANY MORE CHOICES !!!
GlobalUnlock(ADeviceMode);
end;
end;
{ Here's the TDevMode structure with all the things you can change like
this:
_devicemodeA = packed record
dmDeviceName: array[0..CCHDEVICENAME - 1] of AnsiChar;
dmSpecVersion: Word;
dmDriverVersion: Word;
dmSize: Word;
dmDriverExtra: Word;
dmFields: DWORD;
dmOrientation: SHORT;
dmPaperSize: SHORT;
dmPaperLength: SHORT;
dmPaperWidth: SHORT;
dmScale: SHORT;
dmCopies: SHORT;
dmDefaultSource: SHORT;
dmPrintQuality: SHORT;
dmColor: SHORT;
dmDuplex: SHORT;
dmYResolution: SHORT;
dmTTOption: SHORT;
dmCollate: SHORT;
dmFormName: array[0..CCHFORMNAME - 1] of AnsiChar;
dmLogPixels: Word;
dmBitsPerPel: DWORD;
dmPelsWidth: DWORD;
dmPelsHeight: DWORD;
dmDisplayFlags: DWORD;
dmDisplayFrequency: DWORD;
dmICMMethod: DWORD;
dmICMIntent: DWORD;
dmMediaType: DWORD;
dmDitherType: DWORD;
dmICCManufacturer: DWORD;
dmICCModel: DWORD;
dmPanningWidth: DWORD;
dmPanningHeight: DWORD;
end; }
procedure TForm1.Button3Click(Sender : TObject);
begin
printersetupdialog1.Execut e;
end;
end.
To Change Printer with Printer.PrinterIndex should work
but you could also use
SetPrinter(ADevice,ADriver ,APort,ADe viceMode);
Good Luck
Indi
unit PrinterDevices1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs, StdCtrls, Printers;
const
DM_ORIENTATION = 1;
DM_PAPERSIZE = 2;
DM_PAPERLENGTH = 4;
DM_PAPERWIDTH = 8;
type
TForm1 = class(TForm)
Button1: TButton;
Memo1: TMemo;
Button2: TButton;
PrinterSetupDialog1: TPrinterSetupDialog;
Button3: TButton;
procedure Button2Click(Sender: TObject);
procedure Button3Click(Sender: TObject);
private
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.Button2Click(Sender
ADevice, ADriver, APort: array [0..255] of char;
ADeviceMode: THandle;
DevMode: PDevMode;
begin
with Printer do
begin
GetPrinter(ADevice,ADriver
DevMode := GlobalLock(ADeviceMode);
if not Assigned(DevMode) then showMessage('can't find printer')
else
begin
with DevMode^ do
begin
memo1.lines.add('Source ' + IntToStr(dmDefaultSource))
the constants
memo1.lines.add('Orientati
the constants
memo1.lines.add('Papersize
constants
end;
end;
// etc.
// HAVE A LOOK INTO WINDOWS.PAS FOR MANY MORE CHOICES !!!
GlobalUnlock(ADeviceMode);
end;
end;
{ Here's the TDevMode structure with all the things you can change like
this:
_devicemodeA = packed record
dmDeviceName: array[0..CCHDEVICENAME - 1] of AnsiChar;
dmSpecVersion: Word;
dmDriverVersion: Word;
dmSize: Word;
dmDriverExtra: Word;
dmFields: DWORD;
dmOrientation: SHORT;
dmPaperSize: SHORT;
dmPaperLength: SHORT;
dmPaperWidth: SHORT;
dmScale: SHORT;
dmCopies: SHORT;
dmDefaultSource: SHORT;
dmPrintQuality: SHORT;
dmColor: SHORT;
dmDuplex: SHORT;
dmYResolution: SHORT;
dmTTOption: SHORT;
dmCollate: SHORT;
dmFormName: array[0..CCHFORMNAME - 1] of AnsiChar;
dmLogPixels: Word;
dmBitsPerPel: DWORD;
dmPelsWidth: DWORD;
dmPelsHeight: DWORD;
dmDisplayFlags: DWORD;
dmDisplayFrequency: DWORD;
dmICMMethod: DWORD;
dmICMIntent: DWORD;
dmMediaType: DWORD;
dmDitherType: DWORD;
dmICCManufacturer: DWORD;
dmICCModel: DWORD;
dmPanningWidth: DWORD;
dmPanningHeight: DWORD;
end; }
procedure TForm1.Button3Click(Sender
begin
printersetupdialog1.Execut
end;
end.
To Change Printer with Printer.PrinterIndex should work
but you could also use
SetPrinter(ADevice,ADriver
Good Luck
Indi
Oops...
Sorry
i killed CONST dmDefaultSource, when cutting the source
Button3Click was just for testing
cheers
Indi
Sorry
i killed CONST dmDefaultSource, when cutting the source
Button3Click was just for testing
cheers
Indi
Oh oh...
forgot button1, too
procedure TForm1.Button1Click(Sender : TObject);
var
ADevice, ADriver, APort: array [0..255] of char;
ADeviceMode: THandle;
DevMode: PDevMode;
begin with Printer do begin
GetPrinter(ADevice,ADriver ,APort,ADe viceMode);
SetPrinter(ADevice,ADriver ,APort,0);
GetPrinter(ADevice,ADriver ,APort,ADe viceMode);
DevMode := GlobalLock(ADeviceMode);
if not Assigned(DevMode) then ShowMessage('Can''t set printer.')
else begin
with DevMode^ do begin
{Put any other settings you want here}
dmDefaultSource := DMBIN_UPPER;
{these codes are listed in "Windows.pas"}
end;
GlobalUnlock(ADeviceMode);
SetPrinter(ADevice,ADriver ,APort,ADe viceMode);
end;
end;
Printer.BeginDoc;
Printer.Canvas.TextOut(50, 50,'This page is printing from the UPPER PAPER TRAY.');
with DevMode^ do begin
{Put any other settings you want here}
dmDefaultSource := DMBIN_LOWER;
{these codes are listed in "Windows.pas"}
end;
Printer.NewPageDC(DevMode) ;
Printer.Canvas.TextOut(50, 50,'This page is printing from the LOWER PAPER TRAY.');
Printer.EndDoc;
end;
....
Sorry, have some problems formatting the ExEx page, too
forgot button1, too
procedure TForm1.Button1Click(Sender
var
ADevice, ADriver, APort: array [0..255] of char;
ADeviceMode: THandle;
DevMode: PDevMode;
begin with Printer do begin
GetPrinter(ADevice,ADriver
SetPrinter(ADevice,ADriver
GetPrinter(ADevice,ADriver
DevMode := GlobalLock(ADeviceMode);
if not Assigned(DevMode) then ShowMessage('Can''t set printer.')
else begin
with DevMode^ do begin
{Put any other settings you want here}
dmDefaultSource := DMBIN_UPPER;
{these codes are listed in "Windows.pas"}
end;
GlobalUnlock(ADeviceMode);
SetPrinter(ADevice,ADriver
end;
end;
Printer.BeginDoc;
Printer.Canvas.TextOut(50,
with DevMode^ do begin
{Put any other settings you want here}
dmDefaultSource := DMBIN_LOWER;
{these codes are listed in "Windows.pas"}
end;
Printer.NewPageDC(DevMode)
Printer.Canvas.TextOut(50,
Printer.EndDoc;
end;
....
Sorry, have some problems formatting the ExEx page, too
Heinz,
you could try a little dirty
duplicate the printers.pas unit to myprinters.pas and change
the printer unit
just a thought...
Indi
you could try a little dirty
duplicate the printers.pas unit to myprinters.pas and change
the printer unit
just a thought...
Indi
ASKER
yes, i´ll tried this many times before... but now, magically it works
fine... now i access the printers
over the name in the printerlist and
all properties will work..
procedure tform.print;
var adevicemode : thandle;
begin
adevicemode:=0;
printer.setprinter(pchar(P rintername ),
#0,#0,adevicemode);
end;
thanx, Heinz
fine... now i access the printers
over the name in the printerlist and
all properties will work..
procedure tform.print;
var adevicemode : thandle;
begin
adevicemode:=0;
printer.setprinter(pchar(P
#0,#0,adevicemode);
end;
thanx, Heinz
schön für dich, Heinz