Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Registry question - associating files and changing default file icons

Author
Message
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 3rd Dec 2007 14:57 Edited at: 3rd Dec 2007 14:57
I'm working on a model viewer and manipulator right now, and because I can't do anything halfway I'm trying to do this properly.

I need to be able to associate files with my program and change the default file icons. Don't worry, this will be up to the user to do. I'll be using the default DBP registry commands.



I've tried searching but I've not found any direct answers, and I don't want to experiment on my registry. I don't know if it matters, but it's certainly possible that .x and .dbo files aren't associated to anything on the user's computers. When making the associations and changes will it work the same way?

So basically, what registry changes are necessary to:
1. Associate files (.x and .dbo) with an EXE?
2. Change file's default icons (.x and .dbo again).


Come see the WIP!

Attachments

Login to view attachments
dark coder
21
Years of Service
User Offline
Joined: 6th Oct 2002
Location: Japan
Posted: 3rd Dec 2007 15:12
Unless I'm mistaken you need to create an entry under HKEY_CLASSES_ROOT\.x or .dbo\OpenWithList\Exe Path.exe However, I'm pretty sure the DBP registry commands use the 'HKEY_LOCAL_MACHINE' as the root directory, though I haven't experimented very much with this so you might be able to go up one.

Scraggle
Moderator
20
Years of Service
User Offline
Joined: 10th Jul 2003
Location: Yorkshire
Posted: 3rd Dec 2007 15:16
So, I presume you no longer need the model viewer that you asked me to make for you?



hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 3rd Dec 2007 15:16
Hopefully you can convert this to DBP code. This is the Delphi code that CodeSurge uses to associate your files with the registry:


The SCHangeNotify thingy is a WinAPI call that you'll need to call. It's in the shell32.dll library. SHCNE_ASSOCCHANGED=134217728 and SHCNF_IDLIST=0.

Hopefully that helps you some. That last command there may not be necessary, but the changes might not take effect unless you restart the computer. It basically notifies Windows about the changes you made to the icon, etc.

CodeSurge
Version 1.0 finally released! Code your DBP projects in style. (And save the kittens!)
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 3rd Dec 2007 15:44 Edited at: 5th Dec 2007 11:00
@Scraggle -
Damn, I just saw your e-mail I sent you one. The past couple of days my monitor has been out so I haven't been able to work on Geisha House, so I made a couple editors and viewers.

@hyrichter -
Thank you, that's perfect. It looks very straightforward, shouldn't be any problem to implement it.

Quote: "SHCNE_ASSOCCHANGED=134217728 and SHCNF_IDLIST=0"

I take it that I pass these values to SCHangeNotify every time? Is SHCNE_ASSOCCHANGED a Delphi constant?


Come see the WIP!

Attachments

Login to view attachments
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 3rd Dec 2007 15:55 Edited at: 5th Dec 2007 11:03
Okay, here's my approximation to DBP so far...



Does this look like I'm setting the right values with the DBP code?


Come see the WIP!

Attachments

Login to view attachments
hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 3rd Dec 2007 16:02
Quote: "I take it that I pass these values to SCHangeNotify every time? Is SHCNE_ASSOCCHANGED a Delphi constant?"

Yes, you need to pass those values to the SHChangeNotify each time you do a file association. Those constants are technically Win32 API constants, but they're also included with Delphi.

Your DBP code looks OK so far, but don't blame me if you screw up your registry.

CodeSurge
Version 1.0 finally released! Code your DBP projects in style. (And save the kittens!)
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 3rd Dec 2007 16:49 Edited at: 5th Dec 2007 11:01
Awesome. I have one lingering doubt before I implement this...

Should
Quote: "RootKey$="HKEY_CLASSES_ROOT""

be
Quote: "RootKey$="HKEY_CLASSES_ROOT""

instead? Or does it not matter? It seems that this constant should have a slash, but my search efforts didn't help me. I suppose I don't know enough of the right terminology to conduct proper search.


Come see the WIP!

Attachments

Login to view attachments
hyrichter
20
Years of Service
User Offline
Joined: 15th Feb 2004
Location: Arizona
Posted: 3rd Dec 2007 18:25
I don't really know on that, but I have a feeling you should use it with the '\'. If it doesn't work, it's really not that hard to open up regedit and delete any odd entries you make.

CodeSurge
Version 1.0 finally released! Code your DBP projects in style. (And save the kittens!)
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 3rd Dec 2007 18:45 Edited at: 3rd Dec 2007 18:50
You will need the backslash - nothing will happen without it as you can't create anything at the top level of the registry.

[edit]Forget I said that - I didn't read the code properly and though you were building a registry path, not specifying the complete one.

One question though: Doesn't DBPro limit the registry commands so that you can only write to HKEY_LOCAL_MACHINE?

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 4th Dec 2007 02:03 Edited at: 5th Dec 2007 11:01
Man, that was hard. It seems like everything is though

DBP commands won't write to "HKEY_CLASSES_ROOT", only "HKEY_LOCAL_MACHINE". This cost me a lot of time, I couldn't figure out why it wasn't writing anything at all.

Quote: "One question though: Doesn't DBPro limit the registry commands so that you can only write to HKEY_LOCAL_MACHINE?"

I sure wish I'd seen that edit a long time ago

Then I found this handy little thread by MadrMan... http://forum.thegamecreators.com/?m=forum_view&t=74495&b=1. That got me on the right track, but it took some heavy modifications. Each part must be passed to the registry exactly right or it either won't write or won't work, neither of which is very helpful. I was able to determine the exact strings needed by exporting other correct ones that matched the shell/command and DefaultIcon key values.



This is a very clumsy way to do it, I'm going to combine it all into one single .reg file and execute it once. The purpose of this was just to get it working and to share portable code with everyone that might search for this in the future.

For anyone just joining this, this will associate a filetype with your application and change its icon to icon 0 in said application. This is the ugly DBP icon right now, I'll fix that for myself, you're all on your own.

This is how it's used...
Quote: "RegisterFileType("x", appname$())"


Use it wisely and sparingly!


Come see the WIP!

Attachments

Login to view attachments
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 4th Dec 2007 14:58
This is the last bump...

New and improved version, using IanM's datafile plugin.



startRegistry() opens a new .reg file, RegisterFileType() accepts a new parameter, an alternative icon path. When you're all done writing keys for the registry call closeRegistry() and it will make the changes and delete the file.

For sloppy simplicity I use a '1' for the datafile - "OPEN DATAFILE TO WRITE 1". This is because I'm not using the datafile commands anywhere else, so it's safe to assume that 1 will always be open. This will need to be changed to something more dynamic if you're using other files.

In case anyone is wondering why I keep posting it's just so that future searchers will have a complete answer. But, that's pretty much it, so I'm done here.


Come see the WIP!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Dec 2007 18:23
Thanks for pointing out the missing function: FIND FREE DATAFILE - it'll be added to the next release.

One other thing - If you use 'DATAFILE STRING TYPE 1', it will automatically output CRLF's at the end of each line for you.

One more other thing - You can use the REPLACE ALL$ function to replace all backslashes with double-backslashes in your fixString function.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 4th Dec 2007 18:53
Quote: "Thanks for pointing out the missing function"

Thanks for pointing out that I pointed it out, because I actually didn't I just assumed it was a command, your resource finding functions are very comprehensive, but I just used the '1' for simplicity. Good to know, and I look forward to it being added. I'm about to make massive use of your datafile functions for another editor and it will be really handy to have.

Quote: "One other thing - If you use 'DATAFILE STRING TYPE 1', it will automatically output CRLF's at the end of each line for you."

Good to know, thanks.

Quote: "You can use the REPLACE ALL$ function "

Of course it would be that simple Thanks for your help, and especially for your plugins, they really make some things possible that would otherwise be impossible or require massive workarounds.

Would adding improved registry editing functions be a lot of work? The existing ones are fairly useless for applications. The .reg file works but it feels to sloppy.


Come see the WIP!
IanM
Retired Moderator
21
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 4th Dec 2007 19:24
I've avoided adding registry commands so far. The commands provided by Lee are generally Ok for normal use and are relatively secure too. Adding others with global access to the registry could open up all sorts of security holes (disable AV or firewall on startup for example) - what you have done is one of the few reasonable uses I've seen so far.

That's not a 'no'... it's an 'I'll think about it'. It isn't a difficult job by any means.

Utility plugins collection and
http://www.matrix1.demon.co.uk for older plug-ins and example code
Cash Curtis II
19
Years of Service
User Offline
Joined: 8th Apr 2005
Location: Corpus Christi Texas
Posted: 4th Dec 2007 23:50
I suppose that one good thing about DBP Exes is that they're pretty safe, and giving it full access to the registry could have bad results. Changing a file association isn't speed critical at all, so this approach is fine. Any storage values that should be faster I can write to HKEY_LOCAL_MACHINE, so there isn't any real need for more powerful registry commands.


Come see the WIP!

Login to post a reply

Server time is: 2024-05-06 13:10:26
Your offset time is: 2024-05-06 13:10:26