File Types

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 ...

  1. #16
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    Quote Originally Posted by Codeplug View Post
    Quote Originally Posted by Codeplug View Post
    The first link describes what registry entries that needed to be modified/added.
    It's all there.

    gg

  2. #17
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    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.

  3. #18
    Registered User Codeplug's Avatar
    Join Date
    Mar 2003
    Posts
    4,676
    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..

    gg

  4. #19
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    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:
    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
    Gosh, this is a pain. Any suggestions?

    Well, I already tried that codeplug and it didn't really help...

  5. #20
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,789
    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.
    To set a default value in the registry, specify the name "" for the name argument.
    Check out .txt in the registry to see how notepad does it.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  6. #21
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    *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

  7. #22
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    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.

  8. #23
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    On second thought, maybe I haven't. This is what I tried:
    Code:
    ->.cboard
    
    default = C++
    ->C++
    default = C++ Application
    ->DefaultIcon
    default = C:\Program.exe, 1
    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.

    [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.

  9. #24
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,789
    Code:
    default = C++
    
        ->C++
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  10. #25
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    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.

  11. #26
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,789
    Right. Then all is well!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  12. #27
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    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:
    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);
    However, I recieve compiler error C2352:
    Code:
    error C2352: 'IExtractIconA::GetIconLocation' : illegal call of non-static member function
    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.

    BTW Elysia that's not my real program name.

  13. #28
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,789
    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...
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  14. #29
    Registered User mikeman118's Avatar
    Join Date
    Aug 2007
    Posts
    183
    Yeah, I tried making an instance of it, but it gives me this error:
    Code:
     error C2259: 'IExtractIconA' : cannot instantiate abstract class
    I don't particularly want to get into COM... I just want to associate a file extension!

  15. #30
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,789
    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.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 12:44 PM
  2. opening empty file causes access violation
    By trevordunstan in forum C Programming
    Replies: 10
    Last Post: 10-21-2008, 11:19 PM
  3. Formatting a text file...
    By dagorsul in forum C Programming
    Replies: 12
    Last Post: 05-02-2008, 03:53 AM
  4. Possible circular definition with singleton objects
    By techrolla in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2004, 09:46 AM
  5. System
    By drdroid in forum C++ Programming
    Replies: 3
    Last Post: 06-28-2002, 10:12 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21