Archive: file extension registration


file extension registration
Hi!

How can a file extention be registered for opening a file with the windows explorer by double clicking?


Hi!

Under HKEY_CLASSES_ROOT key in the registry create the following structure:


.ext = MyApp
MyApp = My Application
|
-- Shell
|
-- open
|
-- command = c:\mydir\my.exe %1


In NSIS script it should look something like this:
WriteRegStr HKCR ".ext" "" "MyApp"
WriteRegStr HKCR "MyApp\Shell\open\command" "" '"C:\MyDir\my.exe" %1'


If you want you can also add a DefaultIcon key:
WriteRegStr HKCR "MyApp\DefaultIcon" "" "C:\MyDir\my.ico"

or
WriteRegStr HKCR "MyApp\DefaultIcon" "" "C:\MyDir\my.exe,1"


KiCHiK

There is another way...here's my function for it.


Function RegExt
Pop $0
StrCmp $0 "" EndNow
StrCpy $1 $0 20 1
WriteRegStr HKCR "$1" "" "$1file"
WriteRegStr HKCR "$1file\DefaultIcon" "" "$INSTDIR\MyIcon.ico"
WriteRegStr HKCR "$1file\Shell\open\command" "" "$INSTDIR\MyApp.exe"
# If your icon is built in to your .exe,
# use "$INSTDIR\MyApp.exe,n" where n is the
# number of the icon in the .exe (start with 0 not 1)
FunctionEnd


To use it:

Push ".blah" ; whatever your file extension is
Call RegExt


Sorry I can't figure out how to get the function to work properly for the uninstall thing but here's what you need to do...replace "blah" with whatever your extension is:


DeleteRegKey HKCR ".blah"
ReadRegStr $0 ".blah" ""
DeleteRegKey HKCR "$0"

refresh filetype-icons in windows explorer...
hi,

I have used this method to register my own icon for my application. works fine. however, if there are already existing files with my filetype, the new icon is not displayed immediately. I need to kill/restart the explorer process or logout/login (which obviuosly does the same).

How can I trigger that the explorer refreshes icons?

Thanks,

mow


It's for VB, but you can easily do this with NSIS too:

http://groups.google.com/groups?q=re...pex.net&rnum=2

To send a timed message you will have to use the latest CVS version or a DLL. With the latest CVS version:

SendMessage ${HWND_BROADCAST} ${WM_SETTINGCHANGE} 0x002A 0 /TIMEOUT=5000

I got the 0x002A from this line in WinUser.h:
#define SPI_SETNONCLIENTMETRICS 0x002A


Hi,

Sending this message is not enough, I suppose.

I've done that, the screen flickers but nothing else happens - the icons don't change!

Then I found a hint to change the default icon size, send the message, restore the original default icon size and send the message again.
The registry entry is:
HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size"
If it does not exist, I use the default windows size 32...

This seems to work, but is there another, an easier way to accomplish it?


mow


I never said the message alone will do, I just noted how to accomplish a certain part of the steps required in the link I have provided.

I do not know of a better way, you'll have to search for it. If you do find one, plesae let us know about it.


rearranging icons!!!!!!
hi!

I have just realized, that sending this message rearranges all the icons on my desktop!!!!!!!!!!!!!!!


how can I prevent this?


please help,


mow


additional info
hi,

I have verified this:

it just happens with windows xp.

any ideas?


thanks,


mow


You are rebuilding the icon cache. That is not nessacarry to make Window display the new icon, usually just a refresh of the Explorer Window works.

There is no easy way to restore the desktop icon locations. It is possible, but it requires a lot of work and you need to write a plugin for it.


refreshing explorer window
hi,

do you mean if I send a refresh to the explorer window, it should do?

how can I do this? does findwindow help me here?


thanks for your help,


mow