Executing the Print shell command, will result in the file being sent to the default printer. For some file types, like .TXT, a hosting application (Notepad, by default) will open the file first, for some the file would simply be printed (Word Docuemnt - .DOC). Some file types do not have an associated print command application.
File - Right Click - Print. Who will print?
If your want to programmatically print files from Delphi code, using the associated shell application, you need to first make sure that there is an application associated with the shell's print command for a given file type.uses registry;
// get the application (+command line usage) assiciated with
// the Shell PRINT command for a given file
GetShellPrintAssociatedCommand(const fileName: string): string;
var
extension : string;
extDescriptor : string;
begin
result := '';
extension := ExtractFileExt(fileName) ;
with TRegistry.Create do
try
RootKey := HKEY_CLASSES_ROOT;
if OpenKeyReadOnly(extension) then
begin
extDescriptor := ReadString('') ;
CloseKey;
end;
if extDescriptor <> '' then
begin
if OpenKeyReadOnly(extDescriptor + '\Shell\Print\Command') then
begin
result:= ReadString('') ;
end
end;
finally
Free;
end;
end;
Delphi tips navigator:
» Reposition Inherited Control Back to Its Original Position - Revert To Inherited in Delphi IDE
« File Size - Get the Size of a File in Bytes using Delphi


