Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

delphitask (Programmer)
20 Mar 10 11:58
Could anyone please tell me why print using Shellexecute does not bring up the PrintDialog. This is the command used.
Shellexecute(0, 'Print', pchar(Filename), '', nil, SW_SHOW);
It prints directly to the default printer. We Need to print pdf ,doc,html,xls files and need to give user ability to choose printer.
 
Glenn9999 (Programmer)
20 Mar 10 20:36
Because using ShellExecute sends the action to the program, whose sole responsibility as delegated through Windows Explorer is to print the document, so it does that.  And to eliminate the question of where it goes, the default printer is chosen.

It seems you need to seek different means to accomplish this.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy"

delphitask (Programmer)
21 Mar 10 5:50
Read about Shellexecute with the Printto option(instead of print) . I tried it- but nothing gets printed. Any help from those of you who have tried . This is what I used to select a printer of my choice. Any suggestions would be helpful

procedure DocPrinting(DocName: string);
var
  Device: array[0..255] of Char;
  Driver: array[0..255] of Char;
  Port: array[0..255] of Char;
  S: string;
  hDeviceMode: THandle;
  PrintDialog: TPrintDialog;
begin
  PrintDialog:=TPrintDialog.create(nil);
  If PrintDialog.Execute  then
  begin
    Printer.PrinterIndex := Printer.Printers[Printer.PrinterIndex];

    Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
    S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
    ShellExecute(0, 'print', PChar(DocName), S, nil, SW_HIDE);
  end;
end;
Glenn9999 (Programmer)
21 Mar 10 12:07
What you posted basically works except for a couple of problem issues.

CODE

procedure DocPrinting(DocName: string);
  var
    Device: array[0..255] of Char;
    Driver: array[0..255] of Char;
    Port: array[0..255] of Char;
    S: string;
    hDeviceMode: THandle;
    PrintDialog: TPrintDialog;
  begin
    PrintDialog := TPrintDialog.Create(nil);
    try
      If PrintDialog.Execute then
        begin
          Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
          S := Format('"%s" "%s" "%s"', [Device, Driver, Port]);
          ShellExecute(0, 'printto', PChar(DocName), PChar(S), nil, SW_HIDE);
        end;
    finally
      PrintDialog.Free;
    end;
  end;

For what you might notice, the "printto" command within Windows Explorer might not be supported for the document(s) you are trying to print (ShellExecute is a Windows Explorer shell function) - "printto" is not standard and doesn't appear in the MSDN documentation for ShellExecute (http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx - though it could probably just be old).  This means if any app supports it, it's probably a vendor extension.  If what was posted above doesn't work, check the registry of the computer you are on to see if a printto command is defined.

It also probably is pretty prudent to ask what OS and Delphi you are trying this with.

I'm waiting for the white paper entitled "Finding Employment in the Era of Occupational Irrelevancy"

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close