?
Solved

opening files in their native application

Posted on 2004-08-12
4
Medium Priority
?
233 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 200 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

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

719 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