Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

How to call printer properties dialog

Posted on 2000-03-16
12
918 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
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Delphi XE10, MySQL Query 4 164
Delphi 2 68
SUM 2 INTEGER ARRAYS INTO 1 10 108
Moving (cutting/pasting) controls in a TTabbedNotebook... 7 42
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

792 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