Solved

How to call printer properties dialog

Posted on 2000-03-16
12
949 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
[X]
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
  • 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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

724 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