|
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.
|
|
|
|
|
Thanks Mr.Miller, I'll try your way.
There are still many things eternal !!
|
|
|
|
|
I'd like to setup the extension so that if its clicked on via IE, the document will automatically open (much like a Microsoft Word Document within an HTML page).
Any ideas?
Thank-you for a wonderful class.
Jim
QTExtender - The OFFICIAL addon for QuoteTracker.
|
|
|
|
|
This mght require some kind of MIME association, but I have not investigated that. Perhaps you can find something similar in the registry for types that DO work within IE.
|
|
|
|
|
Please forgive a beginner's very basic question. I have included the files cgfiltyp.cpp and .h in my project and set registry keys to recognise my app from the extension. But when - in my app - I try to get from the command line (from m_lpCmdLine) the full pathname of the file on which I have double-clicked, it comes back in the form
"C:\MYFOL~1\MYFIL~1.XXX"
as opposed to C:\MyFolder\MyFile.xxx
As far as I can see, the registry keys are set as in your demo, with the exception of CLSID. Any assistance gratefully appreciated!!
Brian
|
|
|
|
|
These are the 'short' file names.
Your system might be set up to convert long file names to short ones automatically.
Please read some more in the MSDN (April 2004) here :
Files and I/0 Technical Articles : Making Room for Long Filenames
|
|
|
|
|
I had a similar problem. What makes a difference seems to be how the text is quoted in the registry. This worked for me:
Shell\Open\Command key: The default value must look like this in regedit:
"C:\folder 1\folder 2\My App Name.exe" "%1"
Aldo
|
|
|
|
|
Thank you for this. I've been struggling to try to do this on my own for a bit, but couldn't figure out how to do it.
The next logical step is of course reading the command line parameters in the application, which can be done using WinApp::ParseCommandLine().
The third step, (at least in my case), is making the application smart enough not to launch a new instance if one is already running (and make the running one open the file). That is, a single instance of the application should be able to have multiple documents open. If someone double clicks on a file in explorer, the currently running instance should open the file instead of launching another instance -- kind of like Word or Exel.
I'm completely baffled on this one, as I'm not even sure where to start looking. I imagine I will launch a new instance which will somehow have to message the existing instance with the filename, and then exit immediately. But so far, all of my
Google searches have not found me anything that might be useful. If anyone could at least point me somewhere to start looking it would be greatly appreciated.
|
|
|
|
|
I had solved this problem before (some day I might post the class) by creating a memory mapped file by the first instance to run. In the memory mapped file I stored the window handle of the main window of the first instance and other information important to me (such as Process ID, primary thread ID) and you could also leave room to pass in a file path. Then once you wrote to the memory mapped file from the second instance (placing the full file path into the memory mapped fie) then you can set an event or post a user-defined message (or registered windows message) to the main window of the first instance that would indicate it should process. Thismessage would meant to read the filename out of the memory mapped file. In this way, the second instance could communciate the file path to the first instance and then gracefully exit, leaving only once instance running.
Look here at CodeProject for some single instance code that uses memory mapped files, and you could modify the data structure in the memory mapped file.
|
|
|
|
|
only a small note
when exe file is in long path like "c:\test, no. 1\...\test.exe"
shell will fail to extract the icon (in win 9.x platforms), and hence explorer will show unkown icon associated with file types regitered, all because of ","
in the path..
i guess the solution is to have the path written in short form like "c:\test~1\.."
thats all
|
|
|
|
|
I don't recall if having the file path in double quotes within the registry helped either.
Like:
"<filepath>",<iconid>
|
|
|
|