Solved

How to call printer properties dialog

Posted on 2000-03-16
12
872 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

760 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

19 Experts available now in Live!

Get 1:1 Help Now