Solved

opening files in their native application

Posted on 2004-08-12
4
231 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

Industry Leaders: 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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Suggested Courses
Course of the Month7 days, 2 hours left to enroll

623 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