tags:

views:

199

answers:

1

How can I create a directory in C and assign an icon to the folder all with in my program?

The point of this is all doing this in one program without any other dependencies. Is this possible?

+2  A: 

CreateDirectory itself does not support creating an association between a directory and an icon. A directory can have an icon associated with it by instructing the shell to do so.

One way of doing this would be to specify the path to the icon in a desktop.ini file within the target directory.

I'm not sure if this still works because the last time I did it was in Windows 9x but I have seen a few desktop.ini files in Vista so I assume it is still supported to some extent

[Shell]
Icon=<path to icon>

NB: This may still work only because the support is provided for backwards-compatibility with earkier versions of Explorer. It's possible there is another less legacy way of doing this now that I am not aware of

Crippledsmurf
But I can not do this in one program?
I'm not sure that I understand your question, but it is possible to do this in a single prgram by creating the desktop.ini file with the icon specification after you have creted the directory
Crippledsmurf
All in the source code of one program
Yes, this can all be done in one program. Doing so would involve calling CreateDirectory to create the directory and then writing the relevent data in an INI file using either INI file helper functios or just regular IO functions such as WriteFile
Crippledsmurf
Oh I didn't see the "no other dependencies" bit. There is probably a function for creating a directory in the C standard library, there are also functions for writing data to files, but if you don't want a dependency on either of these then things get a lot more complex
Crippledsmurf