flat assembler
Message board for the users of flat assembler.

Index > IDE Development > Handling user preferences

Author
Thread Post new topic Reply to topic
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 26 Jan 2006, 18:27
Larger projects, like Fresh, have a lot of preference settings available to user. An application is supposed to load them on startup, save them on exit, and allow user to change them on runtime.

Usually, Windows application uses registry or .INI file for storing its preferences. User can access them by various dialog boxes.

Usually it is enough to write some code that will load and store all this options one by one. However, for larger applications there should be more sophisticated method. I'm thinking about implementing simple system that will help menaging user settings. It should:

1. Load all preferences from INI file or registry when application starts:
Code:
stdcall LoadPreferences    

That should be everything that has to be called on startup.

2. Provide routines that will prepare controls in options dialog box:
Code:
stdcall PrefToWnd, [hwnd],[pPref]    

Where pPref is a pointer to preference structure, and hwnd is a control handle. This function will have to be smart enough to send proper message to a control, for example WM_SETTEXT to editbox, BM_SETCHECK to checkbox.

3. Provide functions that read data from controls when dialog is closed, and store it back in preference structure:
Code:
stdcall WndToPref, [hwnd],[pPref]    

Similar to function above, but works in different direction.

4. Provide access to preferences:
Code:
stdcall GetPref, [pPref]    

This call should return valid value of given preference, for example pointer to a string or boolean value.

5. Store all preferences when program exists:
Code:
stdcall SavePreferences    


Above I mentioned "pPref". It is a pointer to TPreference structure:

Code:
struct TPreference
  iType    dd ?   ; PREF_TEXT (edit box, PREF_FLAG (checkbox), 
                  ; PREF_OPTION (radio button)
  value    dd ?   ; pointer to a string, flag or number of option, 
                  ; depending on iType
  pszName  dd ?   ; preference name
  pszGroup dd ?   ; INI file group or registry key
ends    


There could be static array of TPreference structures that would hold all pref that given application needs.

That's my first draft of this system. Did you ever made anything similar? What do you think of it? How it could be improved? Any comments will be appreciated.

regards,
Mateusz
Post 26 Jan 2006, 18:27
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 26 Jan 2006, 20:09
Please don't go into registry... I hate those apps which i must install and uninstall, just some useless mess. One .INI in program main directory is sufficent. YOu aren't going to do multi-user interface Wink
Post 26 Jan 2006, 20:09
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 26 Jan 2006, 21:18
No I don't want to (at least for Fresh), but it will be easy to extend library so that it will support registry too.
Post 26 Jan 2006, 21:18
View user's profile Send private message Visit poster's website Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 26 Jan 2006, 22:40
vid wrote:
Please don't go into registry... I hate those apps which i must install and uninstall, just some useless mess. One .INI in program main directory is sufficent. YOu aren't going to do multi-user interface Wink

But wouldn't that (storing in the main application dir) require administrator privileges (required to write to c:\program files). Since I work professionally as a sysadmin, that's just asking for bad karma. And since WindowsNT is multi-user (abielt not in the *nix sense), wouldn't it be better to support it from scratch, rather than trying to hack it in later...

Wouldn't it be better to store the *.ini in say: $APPDATA\.app_name\settings.ini

($APPDATA points to the local user directory for storing local settings in files, instead of using the registry. Assuming W2K/XP+)
Post 26 Jan 2006, 22:40
View user's profile Send private message Visit poster's website Reply with quote
RedGhost



Joined: 18 May 2005
Posts: 443
Location: BC, Canada
RedGhost 27 Jan 2006, 02:07
vid wrote:
Please don't go into registry... I hate those apps which i must install and uninstall, just some useless mess. One .INI in program main directory is sufficent. YOu aren't going to do multi-user interface Wink


yeah why don't the application uninstallers properly remove the data from the registry, they never do and you have to use a registry cleaner :\

_________________
redghost.ca
Post 27 Jan 2006, 02:07
View user's profile Send private message AIM Address MSN Messenger Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2465
Location: Bucharest, Romania
Borsuc 28 Jan 2006, 10:48
.ini is much easier to edit manually, and once you know where Fresh is, you can already find the .ini file.. Not so with Registry (I hate all the mess in my Registry!)
Post 28 Jan 2006, 10:48
View user's profile Send private message Reply with quote
decard



Joined: 11 Sep 2003
Posts: 1092
Location: Poland
decard 29 Jan 2006, 14:59
OK, but what about whole idea? what do you think?
Post 29 Jan 2006, 14:59
View user's profile Send private message Visit poster's website Reply with quote
Reverend



Joined: 24 Aug 2004
Posts: 408
Location: Poland
Reverend 29 Jan 2006, 15:16
I think it can be nicely done via xml. I once thought about writing some xml-parsing code, but have lack of time recently. Even though my imagination of this:
Code:
<preference>
  <id>"1"</id>
  <name>"Set button's caption to 'Exit'"</name>
  <action>"WM_SETTEXT"</action>
  <wparam type="string" value="Exit" />
  <lparam type="integer" value="0" />
</preference>    
Any preference can be matched by id or by name.
Post 29 Jan 2006, 15:16
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.