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 Discussion / The wonderful world of file associations

Author
Message
KYP
20
Years of Service
User Offline
Joined: 5th May 2005
Location: 01110000
Posted: 4th Oct 2007 01:30
I've recently been experimenting with saving data in file types created by me ( .bear .awesome etc), and it seems to work fine. I've found a installation program that can associate file types with your program, which would be cool (like, click on a .doc and it opens Macrohard Word, then loads the document).

Here's my question: How do you make DB tell what file was used to open it? Like, if someone opens "myfile.awesome" with your executable, how do you get the executable to automatically open myfile.awesome?

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Oct 2007 03:35 Edited at: 4th Oct 2007 03:37
Hello,

You make the file associations just like you would for any windows program, but in your compiled exe, you need to tell your exe what to do with the file that is being associated with it.

In your source, include something like


at the top.

The cl$() is a command line string input variable. If you have associated a particular extension with your exe, the filename of the file (not the exe) will be returned in cl$(). It's your job to program what your application is supposed to do with that filename. Most likely, a load routine that pulls the information out of the file to use in your app.

Enjoy your day.
KYP
20
Years of Service
User Offline
Joined: 5th May 2005
Location: 01110000
Posted: 4th Oct 2007 18:47 Edited at: 4th Oct 2007 19:42
Thanks! How do I find the directory that the file is in?

Edit: Does the CL$() return the file extension? If not, how would you manually apply the extension in the app?

Latch
18
Years of Service
User Offline
Joined: 23rd Jul 2006
Location:
Posted: 4th Oct 2007 20:53
Quote: "Thanks! How do I find the directory that the file is in?"

I don't know what you mean. Aren't you using an installation program that would store the files where you specifiy?

Quote: "Edit: Does the CL$() return the file extension? If not, how would you manually apply the extension in the app?"


In the case I'm suggesting, cl$() will return the entire path of the myfile.awesome file (ex. d:\game\data\myfile.awesome) if you double click on myfile.awesome. If you have associated the extension .awesome to the exe (let's say the exe is called game.exe) , then game.exe will open, cl$() will have the path and filename because .awesome has been associated to it, then if you have programed your app or game to do something with the filename returned in cl$(), it will do so.

Now, if your installer hasn't associated game.exe with the extension .awesome, then you need to do that manually. If it is a game or app that you are distributing, then you would handle the association through registry keys. But this can be dangerous to the operating system if you don't know what you are doing. Do a search on the internet for Registry keys and file associations and you'll find the relavent information and the proper keys to change. Look up HKEY_CLASSES_ROOT. That should get you started.

Your app can use the built in DBC registry commands or you can create a batch or registry file that you can launch using the EXECUTE FILE command.

Again, a word of caution, messing with the registry can be very bad if you make a mistake!

Enjoy your day.

Login to post a reply

Server time is: 2025-05-31 21:23:03
Your offset time is: 2025-05-31 21:23:03