?
Solved

How to call printer properties dialog

Posted on 2000-03-16
12
Medium Priority
?
969 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
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!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
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…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses
Course of the Month12 days, 13 hours left to enroll

777 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