Skojarzenie z aplikacja

0

Mam aplikacje ktora odtwarza pliki mp3, i teraz chce zorbic taki myk, aby po klikniecu na plik muzyczny, zostal on odtworzony w moim programie. Zapewne trzba skorzystac z jakichs zmiennych srodowiskoych, czy tak? ma kttos przyklad takiego programu, lub wie jak to sie robi

0

http://www.dotnet247.com/247reference/msgs/21/109542.aspx

Z http://www.codeproject.com/shell/cgfiletype.asp?df=100&forumid=846&exp=0&select=1589623
using Microsoft.Win32;

// Associate file extension with progID, description, icon and application
public static void Associate(string extension, string progID, string description, string icon, string application)
{
Registry.ClassesRoot.CreateSubKey(extension).SetValue("", progID);
if (progID!=null && progID.Length>0)
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progID))
{
if (description!=null)
key.SetValue("", description);
if (icon!=null)
key.CreateSubKey("DefaultIcon").SetValue("", ToShortPathName(icon));
if (application!=null)
key.CreateSubKey(@"Shell\Open\Command").SetValue("", ToShortPathName(application) + " "%1"");
}
}

// Return true if extension already associated in registry
public static bool IsAssociated(string extension)
{
return (Registry.ClassesRoot.OpenSubKey(extension, false)!=null);
}

[DllImport("Kernel32.dll")]
private static extern uint GetShortPathName(string lpszLongPath, [Out] StringBuilder lpszShortPath, uint cchBuffer);

// Return short path format of a file name
private static string ToShortPathName(string longName)
{
StringBuilder s = new StringBuilder(1000);
uint iSize = (uint) s.Capacity;
uint iRet = GetShortPathName(longName, s, iSize);
return s.ToString();
}

Call pattern:

if (!IsAssociated(".ext"))
Associate(".ext", "ClassID.ProgID", "ext File", "YourIcon.ico", "YourApplication.exe");

1 użytkowników online, w tym zalogowanych: 0, gości: 1