|
Hi,
do we need admin rights to set this registry values??
In my case the function RegCreateKeyEx() called in SetRegistryValue() returns
allways an error ERROR_ACCESS_DENIED?
Tnanks for help and sharing your work
bosfan
|
|
|
|
|
thanks for your good article
i want to know how can i get the path of a file selected in windows explorer.
i work with visual studio 2010
in fact i want load files in my application when the user clicks on that.
like image viewer or notepad.
thanks again
|
|
|
|
|
it's great i really need it
thanks again
|
|
|
|
|
Hi, this works great for me on xp but the same code fails to add anyhting to the registry in windows 7. I have the correct access rights etc. Any Ideas?
|
|
|
|
|
Hi,
The methods works perfectly. But it will set the icon as the application icon, because we are passing the default index as "0". But don't wan to set the application icon to file, i want the different icon as file icon. How to identify the icons index from the exe and set.
Please help me..
----------------------------
KRISHNA KUMAR T M
|
|
|
|
|
Could you tell me why this solution doesn't work for me? When I click on my document icon in Windows Explorer, it is opened with the older version of the program. I don't have HKCU\Software\Microsoft\Windows\Current Version\Explorer\FileExts\.txt\UserChoice in my registry. I use Windows XP.
Icons do change though, after I added SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
Thanks.
|
|
|
|
|
If the user has specified another default application (via the 'Always Open With' dialog), this code does not work. In this case you need to delete the key stored under HKCU\Software\Microsoft\Windows\Current Version\Explorer\FileExts\.txt\UserChoice
|
|
|
|
|
I have tried to open file, using CStdioFile::Open with options CFile::modeRead | CFile::shareDenyNone, but gives an error.
The message error is strange "No error occurred"
What could be?
Tks
|
|
|
|
|
Ok - this may be irrelevant but does anyone know how to do a similar thing inside a Delphi project? I am a newbie and trying to make my Delphi application automatically recognise file types as its own on Windows explorer.
http://theprecociousone.spaces.live.com/
|
|
|
|
|
Great article, I have done what you suggested and I can get my application to receive the file name when the user clicks on the file and my application is NOT running.
However, when my application is running and the user clicks on a file, my application does not receive any notification that a file open command was issued ?
Any ideas ?
|
|
|
|
|
Did you find out? I am interested if you have the answer!
|
|
|
|
|
Usefull stuff, Blake! Here is a simple C# version, to be adapted to your needs (check extension pre-conditions etc):
<br />
using Microsoft.Win32;<br />
<br />
public static void Associate(string extension, string progID, string description, string icon, string application)<br />
{<br />
Registry.ClassesRoot.CreateSubKey(extension).SetValue("", progID);<br />
if (progID!=null && progID.Length>0)<br />
using (RegistryKey key = Registry.ClassesRoot.CreateSubKey(progID))<br />
{<br />
if (description!=null)<br />
key.SetValue("", description);<br />
if (icon!=null)<br />
key.CreateSubKey("DefaultIcon").SetValue("", ToShortPathName(icon));<br />
if (application!=null)<br />
key.CreateSubKey(@"Shell\Open\Command").SetValue("", ToShortPathName(application) + " \"%1\"");<br />
}<br />
}<br />
<br />
public static bool IsAssociated(string extension)<br />
{<br />
return (Registry.ClassesRoot.OpenSubKey(extension, false)!=null);<br />
}<br />
<br />
[DllImport("Kernel32.dll")]<br />
private static extern uint GetShortPathName(string lpszLongPath, [Out] StringBuilder lpszShortPath, uint cchBuffer);<br />
<br />
private static string ToShortPathName(string longName)<br />
{<br />
StringBuilder s = new StringBuilder(1000);<br />
uint iSize = (uint) s.Capacity;<br />
uint iRet = GetShortPathName(longName, s, iSize);<br />
return s.ToString();<br />
}<br />
Call pattern:
<br />
if (!IsAssociated(".ext"))<br />
Associate(".ext", "ClassID.ProgID", "ext File", "YourIcon.ico", "YourApplication.exe");<br />
|
|
|
|
|
Hi
I have a question about the call pattern:
if (!IsAssociated(".ext"))
Associate(".ext", "ClassID.ProgID", "ext File", "YourIcon.ico", "YourApplication.exe");
From where do I get the value ClassID.ProgID? What is that?
Thank you,
Dominik
|
|
|
|
|
ClassID.ProgID is the identifier of an ActiveX/COM component (see spec).
I'm not sure, but it seems that an application must be registered as COM to make this kind of file association possible (?)
|
|
|
|
|
I had, like others in this thread, the "long files names" problem.
If the executable file was in a long path, the launched document is passed as argument in 8.3 format to the program.
It was, as others said, caused by the lake of quotes arround the executable file name.
Just in case, for others, it works by replacing :
// just pass file path in quotes on command line
csTempText = szProgPath;
csTempText += " \"%1\"";
by
csTempText.Format("\"%s\" %s",szProgPath,"\"%1\"");
Wich adds quotes arround the executable path.
By this way, if the executable file is in long file name path or not, windows will pass the good long file name of the document in m_lpCmdLine
|
|
|
|
|
OK, every thing is fine. but can you help me finding a way to check the association?
i have to check the association for an extention first with my app. if it is associated with some other app, i have to prompt user and then register it with app if wanted.
Thanx,
Ahmed: a dreaming soul.
|
|
|
|
|
thanks for the great discussion.
i have a beginner's question: what determines the icon index sent to SetDocumentDefaultIcon()?
i understand that the application's icon is 0, but that's about it.
if you know of a tutorial describing how to set these icon-document/application associations, i'd appreciate it.
thanks,
ed
|
|
|
|
|
It is EXACTLY the order they are located in the resources.
You have to carefully order the ICON statments in the RC file if you want the icons to have a particular index.
So, when the index is set to 0, it is typically because the desired icon is the first one, or in some cases, the only one in the EXE file.
If you wanted the third icon in the EXE file's resources to be the applcication icon, then use an index of 2, for exmaple.
|
|
|
|
|
This was a very useful information for my running project. Thanks a lot..
Regards
Sreekanth Muralidharan,
Corporate Systems Consultant [Embedded Systems],
INDIA
|
|
|
|
|
I noticed that after a file type was registered. One-clike on the files with the spec type direct to our program as predicted. But if the file type was associated by another program before we take the change. The file's icon will not refresh to the one we specified automatically in the Explorer. Is there any way to tell windows do that for us?
Best Regards,
Michael Leung
|
|
|
|
|
use SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, 0, 0);
Pierre
|
|
|
|
|
thx, its working,
best regards
|
|
|
|
|
Thank you very much, this worked great
|
|
|
|
|
How can we pass all the selected files to a running application ??
When I use open command, each file opens a new App. window.
ie. I'd like to write a program like WinMedia Player. We Right-Click --> "Add to Now Playing List" : all the selected files are added to only ONE App. window.
Please help me out this problem, I desperately need it.
Thanks so much !!
A true luv is obviously eternal !!
|
|
|
|
|
If you completely control the program then what you do is actualy run another copy of the program. The second copy of the program passes the file to the first copy of the program and then exits. You can use WM_COPYDATA or else a memory mapped file to pass the data or some other means of interprocess communication. You also pass a flag on the command line to the program so you can disntinguish that the intention is to pass the file from the second program to the first program. This way, if the user actually starts your program with his own command and passes a file, you DO get a second copy running the second file, as the user would expect. You can't force a program to accept more than one file if it was not originaly designed to do so. I think there might be a sample of passing a file from one instance of a program to another on this website.
|
|
|
|