views:

57

answers:

1

Hi All,

I am creating a tar file ( from several files), now while saving this tar file i save this file as my particular extension like (.xyz), so i want whenever i save this type file (.xyz extension) from my tool this file should save with a particular ico file format. This is similar like when we save a bmp or jpeg file from mspaint they save with their icon file format.

Thanks

A: 

To associate a icon with your extension you will have to create a registry entry for that and a icon associated with a extension doesn't mean anything unless you associate some program to open it with you, that too you can do in registry e.g

  1. Create an entry for your program's icon name, e.g. HKCU\Software\Classes\myprog.file.xyz

  2. under HKCU\Software\Classes\myprog.file.xyz create enteries for default icon HKCU\Software\Classes\myprog.file.xyz\DefaultIcon

    here you can give path to an icon or to your app and icon will be taken from resource

  3. Create a entry for Open and other commands if you want your extension to open correctly e.g. HKCU\Software\Classes\myprog.file.xyz\Shell\Open\Command and enter path to your program or any other program

    similarly you can add command for view/print etc

  4. Now you have to tell registry that extension .xyz should use info from HKCU\Software\Classes\myprog.file.xyz so create an entry HKCU\Software\Classes.xyz = myprog.file.xyz

Actually if you wish you can directly put 1-3 in HKCU\Software\Classes.xyz, but this redirection is a better way of doing things. because now you can simply assign myprog.file.xyz to many extrnsions e.g. .xxx, .yyy or .zzz etc

Now using python module _winreg (http://docs.python.org/library/_winreg.html) you can create all these enteries programtically. e.g. this script will set xyz to python icon

from _winreg import *

xyzKey = CreateKey(HKEY_CLASSES_ROOT, ".xyz")
SetValue(xyzKey, None, REG_SZ, "MyTest.xyz")
CloseKey(xyzKey)

myTestKey = CreateKey(HKEY_CLASSES_ROOT, "MyTest.xyz")
iconKey= CreateKey(myTestKey, "DefaultIcon")
CloseKey(myTestKey)

SetValue(iconKey, None, REG_SZ, "D:\\Python25\\python.exe")
CloseKey(iconKey)
Anurag Uniyal