Solved

How to call printer properties dialog

Posted on 2000-03-16
12
889 Views
Last Modified: 2010-04-04
well, I need to show printer properties dialog directly from a button.

So, I can't use PrinterSetupDialog that brings me a form. I need to go directly to the window that configures the printer, like HP's or Epsons configuration dialog.

Thanks, Isac
0
Comment
Question by:billbass
  • 5
  • 3
  • 3
  • +1
12 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 2626816
listening..
0
 

Author Comment

by:billbass
ID: 2629526
ok... I am waiting
0
 

Author Comment

by:billbass
ID: 2636710
Edited text of question.
0
 

Author Comment

by:billbass
ID: 2636711
Adjusted points from 50 to 150
0
 
LVL 4

Expert Comment

by:DMN
ID: 2639873
After 2 hours of reading documents and coding i wrote the unit below. Call PrinterPropertiesDialog(True) to make modal window, PrinterPropertiesDialog(False) to make none modal. This will produce Properties dialog for printer, currently selected in Delphi (See Printer function, printers unit). You can change this printer using Printer.PrinterIndex and Printer.Printers properties of printer object.

This code works nice for me under Win98. I didn't test it with other OS versions.

Alexander.
////////////////////////////////////////////////////////////////////////////////

unit prndlg;

interface


function PrinterPropertiesDialog(Modal:boolean):boolean;

implementation
uses Windows, Forms, Printers;

function PrinterPropertiesDialog(Modal:boolean):boolean;
const
  PRINTACTION_PROPERTIES=1;
type
  pfSHInvokePrinterCommand = function(
    hwnd:THandle; uAction:UINT; lpBuf1:pchar; lpBuf2:pchar; fModal:BOOL
  ):BOOL; stdcall;
var
  Device, Driver, Port: array[0..79] of char;
  Instance,DeviceMode:THandle;
  SHInvokePrinterCommand:pfSHInvokePrinterCommand;
  FreeInstance:boolean;
begin
  Result := False;
  Printer.GetPrinter(Device, Driver, Port, DeviceMode);
  FreeInstance := False;
  Instance:=GetModuleHandle('shell32.dll');
  if Instance=0 then
    begin
      FreeInstance := True;
      Instance:=LoadLibrary('shell32.dll');
    end;
  try
    SHInvokePrinterCommand := GetProcAddress(Instance,'SHInvokePrinterCommandA');
     if Assigned(SHInvokePrinterCommand) then
      Result := SHInvokePrinterCommand(Application.Handle,PRINTACTION_PROPERTIES,Device,nil,Modal)
  finally
    if FreeInstance then
      FreeLibrary(Instance);
  end;
end;

end.

////////////////////////////////////////////////////////////////////////////////

0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2642513
Listening
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Expert Comment

by:inthe
ID: 2642625
nice answer :-)
0
 

Author Comment

by:billbass
ID: 2648675
DMN,

Sorry, but this is not what I want... I want to show the window that let me able to configure the paper size, the print mode, and so...

It is not the "Printer Properties" window.

Can you help me again?
0
 
LVL 4

Expert Comment

by:DMN
ID: 2649060
That was EXACTLY dialog you can see selecting PROPERTIES menu item in your printers folder... :(
0
 
LVL 4

Expert Comment

by:DMN
ID: 2649067
Take a look at DocumentProperies and AdvancedDocumentProperties.

They declared in winspool.pas.

May be this can helps?...
0
 
LVL 17

Accepted Solution

by:
inthe earned 150 total points
ID: 2649495
something like this also works:


uses printers, winspool;
 
{$R *.DFM}
 
procedure TForm1.Button1Click(Sender: TObject);
var
  hPrinter: THandle;
  Device : array[0..255] of char;
  Driver : array[0..255] of char;
  Port  : array[0..255] of char;
  hDeviceMode: THandle;
begin
  Printer.PrinterIndex := combobox1.itemindex;
  Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
  if WinSpool.OpenPrinter(@Device, hPrinter, nil) then
  try
    PrinterProperties( Handle, hPrinter );
  finally
    WinSpool.ClosePrinter( hPrinter );
  end;
end;
 
procedure TForm1.FormCreate(Sender: TObject);
begin
  combobox1.items:= printer.printers;
  combobox1.itemindex := 0;
end;
 
0
 

Author Comment

by:billbass
ID: 2650072
thanks! =)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now