Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 01-17-2001, 11:33 PM
rod rod is offline
Junior Member
 
Join Date: Jan 2001
Posts: 2
Default Changing printers in-code

I change printers by changing printer.printerindex.
The printer changes succesfully, but the printer page details are that of the default printer.

The second printer has to have a shorter page length.

I cant seem to declare a second printer object
( printer2 : tprinter)

But it MUST be possible to change ones printer incode.

If I bring up the printer dialog(after changing printers), the new printer shows the incorrect settings as well.

But in windows printer settings it is correct.
Reply With Quote
  #2  
Old 01-18-2001, 01:47 PM
MrBaseball34 MrBaseball34 is offline
Senior Member
 
Join Date: Jan 2001
Posts: 7,260
Default RE: Changing printers in-code

I just make the second printer the default like this:

uses ...Printers;
procedure SetDefaultPrinter(sPrinterName:String; var DefaultPrinterName:String; var PrinterName: String);

// This is private in Printers unti and we needed to use
// it here
constructor TPrinterDevice.Create(ADriver, ADevice, APort: PChar);
begin
inherited Create;
Driver := ADriver;
Device := ADevice;
Port := APort;
end;

function TPrinterDevice.IsEqual(ADriver, ADevice, APort: PChar): Boolean;
begin
Result := (Device = ADevice) and ((Port = '') or (Port = APort));
end;

(*
************************************************** *****************
Name: SetDefaultPrinter
Purpose: Set the Default Printer.
Assumptions: None
Effects:
Sets the Default Printer to the printer
passed in sPrintername. Sets the var parameters
DefualtPrinterName and PrinterName to the correct values
for use in later calls.

Inputs: sPrinterName, var DefaultPrinterName, var PrinterName
Returns: None
************************************************** *****************
*)
procedure SetDefaultPrinter(sPrinterName:String; var DefaultPrinterName:String; var PrinterName: String);
var
i: Integer;
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
hDeviceMode: THandle;
begin
DefaultPrinterName := Printer.Printers[Printer.PrinterIndex];
Printer.PrinterIndex := -1;
with Printer.Printers do
begin
for I := 0 to Count-1 do
begin
if TPrinterDevice(Objects[I]).Device = sPrinterName then
begin
Printer.PrinterIndex := Printer.Printers.IndexOf(sPrinterName);
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
PrinterName := Printer.Printers[i];
StrCat(Device, ',');
StrCat(Device, Driver );
StrCat(Device, ',');
StrCat(Device, Port );
WriteProfileString( 'windows', 'device', Device );
StrCopy(Device, 'windows' );
SendMessage(HWND_BROADCAST, WM_WININICHANGE, 0, longint(@Device));
end;
end;
end;
end;
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 11:08 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2018, vBulletin Solutions, Inc.