Solved

opening files in their native application

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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