About Printer

After I changed the default printer, I want to use new printer in everywhere as microsoft word97.
lufAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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
intheCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.