Learning DX Step-By-Step - #6
User Input / Save / Retrieve
Wednesday, April 11, 2007 by RomanDA | Discussion: DesktopX Tutorials
#6 - User Input / Save / Retrieve
A series by RomanDA
Listing of other DX Tutorials:
In this lesson we will cover how to gather information from a user via a popup dialog box, and to how to store and retrieve this data from the registry.
As in the previous tutorial, the goal here is for you to learn how to create an object, add code to it, and be able to edit that code to make changes to the way the object/widget behaves. The code is provided for you to copy/paste, but it would work best if you type in the code, to see how DX "Auto-fills" the info as you type. Its really the best way to see how DX works.
In order to use these Tutorials you will need to purchase DesktopX for $14.95 from Stardock.
Lets get started.
|STEP 1 - What are we doing here?|
Why do we want to get
input from a user?
Well that's all depends on the gadget/widget you are creating. For a Weather widget you need to get the City code or Zip code to use. If you have a "to-do list" widget, you would want to get the item they want to add into the list. There are a lot of reasons you need to gather input from the user.
Why store the data in the
|STEP 2 - Lets Get Started- Make a TEXT object.|
As in the previous
tutorials, I think you should know enough by now so that i can move past
the every-single-step process.
Create a TEXT object.
ADD the following at the bottom of the existing script items (Object_OnScriptEnter/Object_OnScriptExit)
Lets break the above apart.
The way this will work is very simple.
The original Text object shows:
Click to Add Text
When you click on the object you will see a dialog box like below:
The next Object will now look like:Click to Add Text
2nd Line of Text
You can keep adding more and more lines to the object.
This was simply
to show you how to get "input" from the user.
|STEP 3 - STORING User Entered Data|
Using the same style entry
box above we want to store a single piece of data into the registry.
To add this to the registry, we need to create a link into the Registry by using the WScript.Shell, we open a link.
Then we use the .REGWRITE command to send info to a particular part of the registry.
In this case we are going to use the "KEY" you see listed below. You could use just about anything.
The HKCU = HKEY_Current_User - you could use HKLM - for Local Machine. I prefer to use the Current User because this way each person could have their own settings on the machine.
As for the rest of the key, that is open to your desire, for now we want to use \Stardock\DesktopX\Widget\Tutorial6\SavedInfo
This can be done right in the previous code like this:
This Just adds the value of X into the KEY "Saved Info".
It would not look like what our text.object looks like now. So if you want it to match the widget's info with what you are storing in the registry just change the RegWrite line and replace the X with object.text
If we click on the widget, and add the "2nd Line of Text" to it, then we look in the registry we see the following in the KEY:
If you continue to add things, you will see this change, over and over.
|STEP 4 - Retrieving the Data From the Registry|
So, we stored the data into
the Registry, and into the actual object (kind of dumb to do it in both,
but it helps us see what's being stored).
Now we want to pull that data into another object. So lets make a new TEXT object, put in the text "Click to Restore" (you can save a LOT of time by "right-clicking" on the existing object and hitting "CLONE". This makes a duplicate object with all the same code already in place!)
We want to add a very simple script to this object.
You will notice about 80% of this is the same. What is different is:
You could make a lot of modifications to this one, but it has a great
base to build from.
There are a lot of usages for these items. Anytime you want to get
user info, or store/retrieve data from the registry you now know what to
Keep in mind that you can read in ANY "KEY" from the registry, so
you could easily modify this to pull in the data in the key for say...
Who the "Registered Owner" of the pc is
There are lots of things you could pull from the reg. and update as well. SO PLEASE PLEASE PLEASE Take care when you write to the registry.
Check back as I add new Step-By-Step Tutorials on how to make this a link to a folder, web-site, or just about anything you want!
I hope you have enjoyed this step into DX, and look forward to the next installment.
Reply #2 Thursday, May 3, 2007 7:58 AM
Please login to comment and/or vote for this skin.
Welcome Guest! Please take the time to register with us.
There are many great features available to you once you register, including:
- Richer content, access to many features that are disabled for guests like commenting on the forums and downloading skins.
- Access to a great community, with a massive database of many, many areas of interest.
- Access to contests & subscription offers like exclusive emails.
- It's simple, and FREE!
Reply #1 Wednesday, April 11, 2007 9:54 PM
Agree with you on the autofill.
When you type it in people look at the information in the tooltip or scroll through the list. Stardock has put a great deal of information at your fingertips there.