About Printer

After I changed the default printer, I want to use new printer in everywhere as microsoft word97.
lufAsked:
Who is Participating?
 
intheConnect With a Mentor Commented:
oh other question was about something else..

here is how to get  a list of printers and change the windows default one

you can get the list of printer like this:

uses printers;

var PRINTLIST:TSTRINGLIST;
    index:integer;
begin
   PrintList:=Tstringlist.create;
   PrintList.AddStrings(Printer.Printers);//assign all the printers to a stringlist;
   For index:=0 to Printlist.Count-1 do //iterate thru that list looking for a specfic printer
   begin
     if uppercase(Printlist.Strings[index])='HP LASERJET 600' then
begin
       Printer.PrinterIndex:=index;
        exit;  
     end;
end;
   showmessage('Printer not found'); end;



you can change the default window one like so:


 
var
  Device : array[0..255] of char;
  Driver : array[0..255] of char;
  Port  : array[0..255] of char;
  hDeviceMode: THandle;
begin
  Printer.PrinterIndex := ....;  { select a printer from list to make default}
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  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 ));



Regards Barry

0
 
intheCommented:
hi,
you mean you want to change windows default printer..someone asked this a couple o days ago & it hasnt been answered yet.
0
 
lufAuthor Commented:
Thank you very much! The user of my program can set printer, then all of reports use the new printer, but when he close the program, the default printer of windows has not infection.
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
rwilson032697Commented:
Listening
0
 
lufAuthor Commented:
I means other Application haven't been infected when it use printer.
0
 
intheCommented:
then you would just use the first method to change the printer using printers.printerindex:

uses printers;

var PRINTLIST:TSTRINGLIST;
    index:integer;
begin
   PrintList:=Tstringlist.create;
   PrintList.AddStrings(Printer.Printers);//assign all the printers to a stringlist;
   For index:=0 to Printlist.Count-1 do //iterate thru that list looking for a specfic printer
   begin
     if uppercase(Printlist.Strings[index])='HP LASERJET 600' then
begin
       Printer.PrinterIndex:=index;
        exit;    
     end;
end;
   showmessage('Printer not found'); end;



then it will print to the printer you want but wont change the default printer of windows.


on reading your question im confused
you said:
"I want to use new printer in everywhere as microsoft word97"
    then you say:
"I means other Application haven't been infected when it use printer"

on application close just set the printer back to the one who was default first..
0
 
lufAuthor Commented:
Dear Inthe,
I means is as follows:
I set my default printer in main form, and it is not the default of Windows. when report was printed in other form, the report use my default printer. But after I close my App, the default printer of Window has not changed.  
0
 
intheCommented:
you just have to use the printers.printerindex to select which one to print to,this wont affect the default printer of windows ..
0
 
lufAuthor Commented:
Thank you. But the way have not affect other Quick Report in my App.
0
 
intheCommented:
the quickreport has its own printer unit which you can use to set up printer with.
um..i stole this code from another question:

procedure ChangePaperSize(PaperSize, Comp, Alt: integer);
var
  ADevice, ADriver, APort: array[0..255] of char;
  DeviceMode: THandle;
  M: PDevMode;
  s: string;
begin
  // Força use of Printer due to VCL bug. Do not remove
  S := Printer.Printers[Printer.PrinterIndex];
  // Get current data
  Printer.GetPrinter(ADevice, ADriver, APort, DeviceMode);
  M := GlobalLock(DeviceMode);
  try
    if M <> nil then
    begin
      // Change paper size
      M^.dmFields := DM_PAPERSIZE;
      if PaperSize = DMPAPER_USER then
        M^.dmFields := M^.dmFields or DM_PAPERLENGTH or DM_PAPERWIDTH;
      M^.dmPaperLength := Alt;
      M^.dmPaperWidth := Comp;
      M^.dmPaperSize := PaperSize;//
      // Update
      Printer.SetPrinter(ADevice, ADriver, APort, DeviceMode);
    end;
  finally
    GlobalUnlock(DeviceMode);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ChangePaperSize(DMPAPER_LETTER, 0, 0);
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
  ChangePaperSize(DMPAPER_USER, StrToInt(EdComp.Text), StrToInt(EdAlt.Text));
end;



notice the getprinter() and setprinter() api calls , maybe these are what you need to affect quickreport.
i dont understand why printerindex isnt doing it.
 
0
All Courses

From novice to tech pro — start learning today.