Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

ShellExecute and Printing

1,368 views
Skip to first unread message

A Nixon

unread,
Sep 23, 2006, 10:17:04 PM9/23/06
to
Hi all,

I am using ShellExecute to print some files.

It works ok, but if I select the printer from my application before
printing, the default printer is used instead.

Using *.doc files, I am assuming Word is selecting the default printer when
it activates to print the file.

Any work arounds?

TIA

Tony


Peter Below (TeamB)

unread,
Sep 24, 2006, 6:18:55 AM9/24/06
to
A Nixon wrote:

Many (but not all) applications support the "printto" action in
addition to "print". "printto" allows you to specify the printer to use
as one of the parameters you hand to ShellExecute.

The Win32.hlp has this to say about printto:

<quote>
HKEY_CLASSES_ROOT
wrifile = Write Document
shell
open
command = C:\Progra~1\Access~1\WORDPAD.EXE %1
print
command = C:\Progra~1\Access~1\WORDPAD.EXE /p "%1"
printto
command =
C:\Progra~1\Access~1\WORDPAD.EXE /pt "%1" "%2" "%3" "%4"

In the preceding commands, the %1 parameter is the filename, %2 is the
printer name, %3 is the driver name, and %4 is the port name. In
Windows 95, you can ignore the %3 and %4 parameters (the printer name
is unique in Windows 95).
</quote>

So you need to pass some parameters in addition to the document name to
ShellExecute for the printto action.

var
Device : array[0..255] of char;
Driver : array[0..255] of char;
Port : array[0..255] of char;
S: String;
hDeviceMode: THandle;
begin
Printer.PrinterIndex := -1; // select a printer
Printer.GetPrinter(Device, Driver, Port, hDeviceMode);
S:= Format('"%s" "%s" "%s"',[Device, Driver, Port]);
ShellExecute( handle, 'printto', PChar(documentname), Pchar(S), Nil,
SW_HIDE );

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com
http://www.prolix.be

0 new messages