Solved

opening files in their native application

Posted on 2004-08-12
4
227 Views
Last Modified: 2010-04-05
I have some .rtf documents with my application and I want the user to be able to open them in their native application. Without assuming that to be MSWord or WordPad, how can I do that?
0
Comment
Question by:HorridMan
  • 3
4 Comments
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11789468
The information is here:

E:='rtf';

var
  e,s:string;
  R:tRegistry;
begin
  E:='rtf';  //extension for which we want the association
  R:=TRegistry.Create;
  try
   if R.OpenKey('Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.'+E+'\OpenWithList',false) then begin
      S:=R.ReadString('MRUList');
      S:=R.ReadString(copy(S,1,1));  //looks at first item in list
      R.CloseKey;
    end;
   // S has the program used to execute the association
 finally
  R.Free;
end;
 
 
Now, just execute  S with the argument of the file name. Use shellexecute!
0
 
LVL 7

Expert Comment

by:LRHGuy
ID: 11789635
Here's a shellexecute example...

procedure Go;
var
  RunThis:Std_String;
  S1,S2:array[0..79] of char;
  S3:array[0..255] of char;  
  Dir,Arg:Std_String;        
  hRU:tHandle;              
begin

  RunThis:=S; //put program here
  Dir:='';
  Arg:=filename; //put filename here
  StrPCopy(S1,RunThis);
  StrPCopy(S2,Dir); {Directory to start in}
  StrPCopy(S3,Arg); {args}
  hRU:=ShellExecute(0,nil,S1,S3,S2,Sw_ShowMinNoActive);
end;

0
 
LVL 7

Accepted Solution

by:
LRHGuy earned 50 total points
ID: 11789695
Also, if you don't want to look it up in the registry...this might work...

procedure Open(Param:AnsiString);
begin
  ShellExecute(GetDeskTopWindow
              ,'open'
              ,pChar(Param)
              ,nil
              ,nil
              ,SW_SHOWNORMAL
              );
end;


and do:   Open(filename)  //name of rtf file or whatever
0
 

Author Comment

by:HorridMan
ID: 11790388
ShellExecute looks like the simplest way to do what I want to do.
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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