Change printer settings by code
I want to change printer settings by code.
Actually it is not a problem but it is a problem when I use Fast Report.
With this code I changed the printer tray which the printer must be used:
But when I have a Report and show a preview and then go to the print button, then I see that printer tray (=bin) is set to the default value and not to the value I set by my code (So Fast Report seems to overrule everytime my settings).
Does somebody know how I can change by code the printer settings and when I do a preview Fast Report gives the printer settings of me?
Actually it is not a problem but it is a problem when I use Fast Report.
With this code I changed the printer tray which the printer must be used:
Procedure SelectPrinterBin( bin: Word);
var
 Device, Driver, Port: array[0..80] of Char;
 DevMode: THandle;
 pDevmode: PDeviceMode;
begin
 // Get printer device name etc.
 Printer.GetPrinter(Device, Driver, Port, DevMode);
 // force reload of DEVMODE
 Printer.SetPrinter(Device, Driver, Port, 0);
 // get DEVMODE handle
 Printer.GetPrinter(Device, Driver, Port, DevMode);
 If Devmode <> 0 Then Begin
  // lock it to get pointer to DEVMODE record
  pDevMode := GlobalLock( Devmode );
  If pDevmode <> Nil Then
  try
   With pDevmode^ Do Begin
    // modify paper size
    dmDefaultsource := bin;
    // tell printer driver that dmDefaultsource field contains
    // data it needs to inspect.
    dmFields := dmFields or DM_DEFAULTSOURCE;
   End;
  finally
   // unlock devmode handle.
   GlobalUnlock( Devmode );
  end;
 End; { If }
end;
But when I have a Report and show a preview and then go to the print button, then I see that printer tray (=bin) is set to the default value and not to the value I set by my code (So Fast Report seems to overrule everytime my settings).
Does somebody know how I can change by code the printer settings and when I do a preview Fast Report gives the printer settings of me?
Comments
Prn.PropertiesDlg shows the changed tray
Showreport ==> Print ==> Properties ==> show NOT the changed tray.
So according to me it seems to be a bug.
Please help me!
Could you already solve this problem?
I have almost the same one.
I'd like to print the first 2 copies on paper that come from the first tray and the 3rd copy on paper comes from the 2nd tray.
But I don't know how to change tray from code.
Thanks!
I solved this problem like this.
First put this oncreate of the form.
cboprinters.Items.Assign(Printer.printers); (cboprinter is a combpbox)
then Put this code to the OnChange of cbo printers:
Frxreport1.PrintOptions.Printer :=cboprinters.Text;
thats alll
Yes, and this is changing the printer, isn't it? It works for me too, I can change the printer, but i'd like to change the PRINTER'S BIN!
If i see well, the frxPrinter.Pas' SetPrintParams function is changing the bin, but it isn't works...
Code: (ABin is the parameter of the procedure)
...
if FBin <> -1 then
ABin := FBin;
FMode.dmDefaultSource := ABin;
...
FDC := ResetDC(FDC, FMode^);
...
The win32 developers reference says:
dmDefaultSource Reserved; must be zero.
???
Thanks for helping!
Thanks!
Thanks!