Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 04-08-2012, 11:38 PM
oggtheclever oggtheclever is offline
Junior Member
 
Join Date: Mar 2012
Posts: 14
Unhappy File Association and the registry

I come to you in desperation as I've been struggling with this problem all weekend. So obsessed with it have I become that I even dreamt about it last night.

My problem is this. For the past couple of months I have been creating my own media player in Delphi and I must admit that it's really coming along very nicely.

This weekend I finally got around to doing some of the options in 'preferences' and one of these was the file associations. The idea, as you expect, is that the user can select various extensions, such as .avi, .mpg, .mp3 etc.. and assign them to my programme so that the next time they double-click on one of these files it's my media player that opens and plays them and not, say, windows media player.

So far so good...

Now it seems no matter what I do, how I change the registry using examples found on various sites, whether I run the programme as an admin or not it doesn't make the slightest difference. I simply cannot change any file association to my media player.

Further imagine my utter frustration when I download media players such as Zoom Player or the DIVX Player and go into their options dialog and find that within a couple of clicks I can assign extensions to them with no problem whatsoever. What is it that they are doing that my media player isn't?

So, to cut a long story short I suppose the real question is this. What registry entries do I need to change (without having to run my app in admin mode as I didn't with Zoom Player etc.) to associate certain filetypes such as .avi with my media player that actually works under Windows 7?

Can I confine myself entirely to HKEY_CURRENT_USER for example?

Many thanks in advance
Reply With Quote
  #2  
Old 04-09-2012, 02:04 PM
oggtheclever oggtheclever is offline
Junior Member
 
Join Date: Mar 2012
Posts: 14
Default Solved

Code:
procedure TForm1.RegisterFileType(ExtName:String);
var
  a: byte;

begin
  a:=0;

  with TRegistry.Create do
  try
    RootKey := HKEY_CLASSES_ROOT;

    DeleteKey('\.avi\');

    if OpenKey('\.avi\', True) then begin
      WriteString('','avifile');
      WriteString('PerceivedType', 'video');
      WriteString('Content Type', 'video/avi');
    end;

    OpenKey('\.avi\OpenWithList\ehshell.exe\', True);

    if OpenKey('\.avi\OpenWithProgIds\', True) then
      WriteBinaryData('avifile', a, 1);

   if OpenKey('\avifile\shell\open\command\', True) then
      WriteString('', '"'+ParamStr(0)+'" "%1"');

    RootKey := HKEY_CURRENT_USER;

    DeleteKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.av​i\');

    if OpenKey('\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.avi\OpenW​ithProgids\', True) then
      WriteBinaryData('avifile', a, 1);

  finally
    Free;
  end;

  SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
end;

Last edited by Norrit; 04-10-2012 at 10:44 AM. Reason: added code-tags
Reply With Quote
Reply

Tags
extensions, filetypes, registry, tregistry

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 07:07 PM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.