This is a discussion on File Types within the Windows Programming forums, part of the Platform Specific Boards category; Originally Posted by Codeplug MSDN: Introduction to File Associations MSDN: Registry Originally Posted by Codeplug The first link describes what ...
Ok, I'm sorry, I still don't really understand what to do. Does it actually say what values to add on that page? I found a link off of that page, but it wasn't actually the page. Anyway, I've been trying for a while now, to no avail. Here's what I found, although I must be doing something wrong because it isn't working: http://msdn2.microsoft.com/en-us/lib...70(VS.85).aspx and http://msdn2.microsoft.com/en-us/lib...75(VS.85).aspx. Can anyone explain this to me simply? I'm rather slow.
Use the tree-view on the left and look at some of the surrounding documentation. I would also inspect existing entries in your registry for examples - like how .txt maps to notepad.exe etc..
I associated one of the file types with my application not from the regristry, but form a folder - Tools->Folder Options->File Types. I then looked at the registry to see what it had done, did the exact same thing with another file I want to associate but this time I copied the stuff in the registry, changing only the things that needed to be changed, such as the name. Of course, the first one worked but the second one did not. Here's what I've tried:
Under HKEY_CURRENT_USER\Software\Microsoft\Windows\Curre ntVersion\Explorer\FileExts\.mona:
Gosh, this is a pain. Any suggestions?Code:(Default) = (value not set) Progid = mona_auto_file OpenWith List (Default) = (value not set) a = Program Name.exe b = NOTEPAD.EXE MRUlist = ab OpenWithProgids (Default) = (value not set) ft000001 = (zero-length binary value) //This is a REG_BINARY type mona_auto_file= (zero-length binary value) //This is a REG_BINARY TYPE File Type Description= (zero-length binary value) //This is a REG_BINARY type
Well, I already tried that codeplug and it didn't really help...
To set a default value in the registry, specify the name "" for the name argument.Code:HKEY_CLASSES_ROOT: -> File extension (including prefix .) -> Default value, set to a new value - this will be your key name. -> Your key name you specified in the default value. -> shell -> Name of your command -> command -> Default value: Set to command to execute. %1 means the filename. So "%SystemRoot%\system32\NOTEPAD.EXE %1" opens notepad and passes the textfile you're trying to open as an argument.
Check out .txt in the registry to see how notepad does it.
*sigh* I still can't get it to work! I did exactly as Elysia said, and that still didn't work. I must be doing something wrong. I've looked at the .txt part, but it doesn't look anything like Elysia's. The file still doesn't open with my program.
Here's what I did:
Code:HKEY_CLASSES_ROOT: -> .mona -> Default value = File Archive -> File Archive -> shell -> open -> command -> Default value = "C:\My Program.exe %1"
Last edited by mikeman118; 12-21-2007 at 05:54 PM. Reason: Added more info
I finally got it to work! Elysia, thanks for getting me in the right direction, but it seems your code didn't work. I got rid of the "Your key name you specified in the default value." key, and changed the value of "C:\My Program.exe %1" to "C:\My Program.exe" "%1" (I saw that on MSDN). Thanks again, codeplug and Elysia - you're the only ones who helped. Now if you guys aren't sick of me yet, I have just one more question. How would I specify the icon to display from the new file type? It's in my program.
NVM, I think I found it. Thanks again!
Last edited by mikeman118; 12-21-2007 at 06:06 PM.
On second thought, maybe I haven't. This is what I tried:
However, that doesn't seem to do anything. This isn't too important to me, so if you guys are too tired of answering my questions you don't have too.Code:->.cboarddefault = C++->C++default = C++ Application->DefaultIcondefault = C:\Program.exe, 1
[EDIT]I got this info from here.[/EDIT]
[EDIT2]Ah, yes. Once again, I solved my own problem! I feel happy. It turned out that the resource value I gave to my icon in my .rc file was the number of the icon. So I changed it from "1" to "106", and the fixed it. Hopefully that's my last question about the registry![/EDIT2]
Last edited by mikeman118; 12-21-2007 at 06:36 PM.
Perhaps you shouldn't use such an unambiguous name for your filetype... Better you set it to something such as "YourAppNameFile" so it doesn't conflict with any other keys in the registry.Code:default = C++ ->C++
Yeah I know- I used different names in my app - those names would be silly! I just didn't feel like putting the real names.
Right. Then all is well!
Will this ever end? Ok, I have one last question. I have updated the icon for my file, but it doesn't appear to be working. I was looking through the documentation and found the SHUpdateImage( function which is apparently necessary to make the icons show up. When looking at it, I found that I have to use two other functions in combination with it (what is with the stupid win api? If they are going to make you call three different functions for one, can't they put it into 1 function?!)! So I tried that:
However, I recieve compiler error C2352:Code:LPSTR lps = "C:\\My Program.exe"; int index; UINT value; SHFILEINFO sh; SHGetFileInfo(lp, 0, &sh, sizeof(SHFILEINFO), SHGFI_SYSICONINDEX); IExtractIcon::GetIconLocation(GIL_DEFAULTICON, lps, sizeof(LPSTR), &index, &value); SHUpdateImage(lps, index, value, sh.iIcon);
I looked up what that error meant, but I have no idea how to fix it... does anyone else? I'm sure I made some other mistake anyway, so if anyone sees anything please point it out.Code:error C2352: 'IExtractIconA::GetIconLocation' : illegal call of non-static member function
BTW Elysia that's not my real program name.
This is COM... it's not a namespace - it's a class, so you have to create an instance of it first. Though you actually have to query for the interface and then extract the icon.
COM is messy and confusing for newbies. You might want to stay away from it and it some other way...
Yeah, I tried making an instance of it, but it gives me this error:
I don't particularly want to get into COM... I just want to associate a file extension!Code:error C2259: 'IExtractIconA' : cannot instantiate abstract class
That's because it's COM - you can't create them directly. You have to use CoCreateInstance.
And even so, you're supposed to find the folder or file you want to get an icon from and query for the interface, so it's not easy.
Better read up on how COM works or avoid it altogether.