Solved

opening files in their native application

Posted on 2004-08-12
4
230 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…

737 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