May 16, 2024, 12:50:24 AM

News:

Own IWBasic 2.x ? -----> Get your free upgrade to 3.x now.........


Saving User Settings

Started by Jim Scott, January 16, 2007, 07:14:12 AM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Jim Scott

It seems that I've seen somewhere on this board a method for saving values within the executable to store values that reflect the user resizing windows, changing sort preferences, etc.  I can't seem to find it now, so I'd appreciate a pointer to the right thread.
Jim Scott

ExMember001

i don't think its a good thing to store this kind of data in the executable (is it possible??)
what i suggest is to use the registry or an ini file to store the user preference.

Ionic Wind Support Team

The registry is your best bet.  Barring that use a text file store in the users documents directory.  To remain compatable with Windows Vista you can't store program settings in the 'program files' directory anymore.  In fact Vista is quite limiting on where your program can write user data to.

Paul.
Ionic Wind Support Team

Jim Scott

Thanks for the reply.  I'll just write a file on the install directory for now.  If I wanted to be Vista compatible, is a safe bet to write to the C://Documents and Settings/All Users directory?

Jim
Jim Scott

Ionic Wind Support Team

That depends on the program.  If you want it to be licensed to just one user you will need to get the current users documents directory.  If your program is meant to be used by all users on a system then the shared documents folder is OK.  This is the correct method of getting those directories:


CONST CSIDL_PERSONAL = 0x05
CONST CSIDL_COMMON_DOCUMENTS = 0x2e
WINDOW dummy
PRINT GetFolderLocation(dummy, CSIDL_PERSONAL)
PRINT GetFolderLocation(dummy, CSIDL_COMMON_DOCUMENTS)
DO:UNTIL INKEY$ <> ""
'-----------------------------------------------------------------
'GetFolderLocation
'Helper sub for getting the path of a system folder from a CSIDL value
'-----------------------------------------------------------------
DECLARE "shell32",SHGetSpecialFolderLocation(HWND:INT,nFolder:INT,LPITEMIDLIST:POINTER),int
DECLARE "shell32",SHGetPathFromIDList(ITEMIDLIST:INT,PATH:STRING),int
DECLARE "ole32",CoTaskMemFree(pidl:int)
SUB GetFolderLocation(win:WINDOW,nFolder:INT),STRING
DEF path:STRING
DEF pidl:INT
DEF ppidl:POINTER
ppidl = pidl
SHGetSpecialFolderLocation(win.hwnd,nFolder,ppidl)
SHGetPathFromIDList(pidl,path)
CoTaskMemFree(pidl)
RETURN path
ENDSUB


Have fun!
Paul.
Ionic Wind Support Team

Jim Scott

Thanks Paul, I'll save user settings in one of these directories.  I was hoping to keep my application completely stand alone by trying to save them within the executable.  This seems like a reasonable exception since the two calls to GefFolderLocation will always return a valid path.

Thanks again, 

Jim
Jim Scott

Ionic Wind Support Team

Yes and the path will be correct for a users language as well.  "My Documents" isn't spelled the same in french, or german ;)
Ionic Wind Support Team

Zen

Jim. I don't think I've seen t done here but I know that Joske from the old IBasic forums made a self modifying executable that stored a string in the resource table. It was prety cool but I think it was a bit complicated to be honest.

Lewis

Ionic Wind Support Team

Lewis,
While writing to your own executables resources is possible it only works on Win 2K and above.  And will definately fail on Vista in user mode.  Not to mention certain virus scanners giving an alarm everytime it is done ;)
Ionic Wind Support Team

Zen

I think the way Joske did it was he had another program to write to the program that called it to modify the string table. Or something along those lines anyway ;) Didnt work for me though, I'll stick with the registry.

Lewis

Jim Scott

I'm not yet comfortable modifying the registry, so I'll stick with writing to a file in a common directory.  But thanks for the ideas Lewis.  May come in handy some other day.

Jim
Jim Scott

Brice Manuel

Thank you for that code, Paul.  If I can figure it out, I will integrate it into my program  ;)

Junner2003

Just a question:

I worked until now with GETENVIROMENT. The problem was that it only worked for the language it was made for because of I had to add "MY DOCUMENTS" and such stuff in the code.

The stuff below posted by Paul is really cool:

QuoteCONST CSIDL_PERSONAL = 0x05
CONST CSIDL_COMMON_DOCUMENTS = 0x2e

How can I access even other system folders such as MY FAVORITES and LOCAL SETTINGS/APPFATA/MICROSOFT/OUTLOOK/ ???
Is there any documentation available?

Junner2003

Ok,
a few I figures out by myself:

0x06 = FAVORITES
0x07 = Start Menu\Programs\Startup
0x08 = Recent
0x09 = SendTo

and so on. I still wish there would be a documentation for programming idiots like me! :)

Ionic Wind Support Team

It's called the Windows SDK and is available at Microsofts site.  Or just paste this into google:  SHGetSpecialFolderLocation

The first link that comes up is the documentation on MSDN.  And there is a link in that documentation to click on which gives all the values you can use.

Paul.
Ionic Wind Support Team

Junner2003

Cool,
thanks a lot, Paul! :)

I just wonder why the CSIDL values at the MSDN site are always 4 digits? Does it matter? I get the FAVORITES folder with booth:

0x06 (following Pauls's example)
0x0006 (the value at the MSDN page below)

Here the link to more values:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp

Ionic Wind Support Team

Ionic Wind Support Team