Now a blog about my Android adventure
Seriously, this easy work and you could go all the way.
Published on August 9, 2005 By CerebroJD In DesktopX Tutorials

Welcome to Part 2 of the basics of DesktopX

by CerebroJD

Time for part two, assuming you read through and understood part one of the series.


Now we know basicly how to adjust some of an objects attributes. Width isnt the only thing that you can change though! Through various end attributes you can change position, color, transparency, rotation, etc. So far, what we've used is just a static value for the attribute value, though, and it doesnt have to be that way. We're gonna learn two things really quick here, timers and dynamic changes. First off, the timer. What we're going to do is take out that stuff we had on line 3 of the script, so that the first sub is empty again. Now, we must "initialize the timer". Sounds cool, but really isnt that big of a deal. Just gotta put in a bit saying what you're doing, then what the ID of the timer is, and how often it triggers. The math for how often it triggers is wierd... 1000 = 1 second. Therefor, intitializing a timer called 42 to trigger every second looks something like this:

Object.SetTimer 42, 1000

So now we've got this timer going...and it'll just keep firing away, with nothing actually happening, unless you put in a new sub with info on what to do when it triggers. In order to do that, we're going to add in a new sub. Its easy to get a sub to react to a timer, because instead of having it react to Object_OnScriptEnter, we just have it react to Object_OnTimer* with * being the number ID of your timer you made. For me, that code is this:

Sub Object_OnTimer42

End Sub

Working within this sub is just as easy as the other one, so we're gonna toss a tiny bit of dynamic content in there, just to make things interesting. Remember how we were setting the image width to a fixed number before? This time, we're going to set the width to equal its existing width, plus 10. If we put that into the the sub that is triggered by the timer, everytime it is fired, the width will increase by 10 pixels. Our final sub code for this will be this:

Sub Object_OnTimer42
DesktopX.Object("Test").Width = DesktopX.Object("Test").Width + 10
End Sub

Close your editor, and hit apply. Your object will begin growing slowly getting wider every second. Now, read this really fast, because it'll be too wide for your screen for very long. What we're gonna do now is take that line out again, otherwise it'll get too big! So take it out, (gonna do something different this time, so dont quit the editor yet!), hit File->Save and Apply. That way we dont have to be going in and out of the script editor so much! Immediate feedback is always handy.

To fully get the use of out of DX, you're not going to always be playing around with widths and heights... you're going to want to actually process data that's being moved around. We're gonna try some working with numbers next. Close out of the editor and look under the States tab, and change the radio button from Image to Text, then go back into the script editor via the General tab. We're going to start manipulating some of the numbers that we have. We've already done a bit of it, in the last example, but you can do all sorts of math using the VBScript that DX uses. Really, DX's power comes from two things: Its ablility to process and show data in a simple way, and its ability to display it using nearly any graphics format.

Really, everything you need from here on out is all in either the DesktopX documentation as well as in the section on VBScript over at www.w3schools.com, but I'm gonna run through a really neat little tutorial that will show you just a tiny bit of what dynamic DX scripting can do.


Goal of the object: To create a miniature representation of a monitor to graphically indicate mouse position. Gonna make this thing SUPER simple... 2 graphics... the rest is script. The images I used are one 6px by 6px blue box. Thats the "Screen" and will stetch and skew without any sort of distortion. The "Mouse" is a 1px by 1px white image.

Note: We're making this script within the "Screen" object, so work on it instead of "Mouse". Be sure you set the Screen object as the parent object of the Mouse one, with Mouse's properties window (Summary tab). First thing we're going to do is make a timer, naming it 42 (since thats the answer to Life, the Universe and Everything), and set it to go off every 1/10th of a second, so 100. (Note! Comment your work.... its very important if you wish others to learn from it)

'Called when the script is executed
Sub Object_OnScriptEnter
Object.SetTimer 42, 100 'Sets a timer that fires every 1/10th of a second
End Sub

Logical, makes sense, and leads to the next step, which is to grab some system info and do some math. First, we'll start our sub, then get the info.

'Goes to work when the timer triggers
Sub Object_OnTimer42
DesktopX.Object("Screen").Width = System.VScreenWidth/10 'Object's width equals width of screen divided by 10
DesktopX.Object("Screen").Height = System.VScreenHeight/10 'Object's height equals height of screen divided by 10

Now to position the "Mouse" on the "Screen" using a bit of data retrival and a bit of math, just like before.

DesktopX.Object("Mouse").Left = System.CursorX/10 'Self-explanatory
DesktopX.Object("Mouse").Top = System.CursorY/10 'Self-explanatory
End Sub

Finally, the last sub, the OnScriptExit one, that wraps it all together, and in this case, kills the timer.

'Called when the script is terminated
Sub Object_OnScriptExit
Object.KillTimer 42 'Does the killing
End Sub

Here's an interesting little bit of information for you, actually. This wont work correctly on my system just like this. My dual monitor setup hinders my use of the entire area, because although the VSscreenWidth will return a positive value of 3200 in this case, the stuff on the left monitor is measured in the negative pixel values. Therefore, to force this object to show the correct position for me, I have to add VScreen.Width/2 to the total to bump it over the right amount. Most of you WILL NOT have this problem, but its an easy fix in case you do have that.

My completed object's script in a screenshot: Click to view Image


Should I make more? What should I do them on?


Comments
on Aug 09, 2005
Great articles. As for what next, I could really use some resources on WMI. Even if you didn't want to get into it yourself, you might know of something more than we do. I am sloughing through MSDN, and they are nothing if not verbose...
on Aug 09, 2005
Ok, that'll be interesting, since I dont use them at all yet... time for some learning!
on Aug 09, 2005
Verry cool. Keep it up! more please.
on Aug 09, 2005
I would love for someone to figure out how to get foobar2000 to play nicely with DesktopX. It can be done with Samurize, so I would think it could be done with DesktopX as well.

Great series BTW.
on Aug 12, 2005
I agree. As we've discusssed, you can get some control by using the foo_winamp_spam plugin or foo_remote and setting DXPlayer to Winamp mode (see here and here), but it's not a perfect solution. Apparently 0.9 may be better in that respect. We shall see.
on Sep 08, 2005
Great job CerebroJD... Yes I think you should do more of the TUT's on scripting.. I think Desktopx is overlooked by many skinners because, To really make any thing exciting and useful it takes scripts to do it. I know that you can do a lot of the same things by using what is built into Desktopx but it takes longer and sometimes it can get really confusing filling in the messages for each object. One of the scripts I think would be useful would be a script that would roll up a object such as a menu, And at the same time fade out the text. also you should be able to have the function button ( roll up, roll down) located on another object. Just a thought.. Keep up the good work...
on Sep 19, 2005
Thks a lot. I'm an oldie who pulls teeth everytime I try to change a pixel's worth on a downloaded theme. With your instructions on scripts I feel I just might be able to get one done sometime in the future. Right now I'm at the stage where I am trying only to:
1. Rename shortcuts (actually I can get the new name in a preset color and size, but it reverts to the old name on mouseover).
2. Rename icons. Can get a new icon by cloning and adding text thru property state but the new name shows up above the icon. The old text of course remains here upon mouseover as well.
3. Import (establish?) a new icon. Several themes I am trying to modify have blank game menus. Some say "add your games here." HA! Have been thru every instruction and forum I can find and haven't found a step- by-step procedure for doing this yet. My game menus are blankedty blank blank.

You asked for suggestions for new tutorials. Mine would be any that helped with the 3 basic chores mentioned above. Mine would even be a tutorial on finding tutorials on above.

Thks again for the tutorial. Wish I could find a few more written as well as yours.

Best wishes,

OldHack
on Sep 23, 2005
One question with the mous position widget. How do you associate the graphics with the script?
on Sep 27, 2005
HighCommand, what do you mean? As it is, it is more like the *scripts* are associated with the *graphics*, since the script is within each object.

Sometime this week, I think I'll put together another tutorial. I like Murex's idea of the roll-up menu and fading text. I'm trying to think of the best way to do that, but I have some good ideas.

OldHack, it sounds like you want to modify a DesktopX theme. The process for doing this can vary from theme to theme, and your best bet is to ask in the comments section of the skin here on WinCustomize. Amazingly enough, I dont use any DX themes... never have. I prefer to just do stuff on my own, creating my own little environment. However, I may be able to help you further if you provide more information.
on Sep 28, 2005
OldHack wrote

Thks a lot. I'm an oldie who pulls teeth everytime I try to change a pixel's worth on a downloaded theme. With your instructions on scripts I feel I just might be able to get one done sometime in the future. Right now I'm at the stage where I am trying only to:
1. Rename shortcuts (actually I can get the new name in a preset color and size, but it reverts to the old name on mouseover).
2. Rename icons. Can get a new icon by cloning and adding text thru property state but the new name shows up above the icon. The old text of course remains here upon mouseover as well.
3. Import (establish?) a new icon. Several themes I am trying to modify have blank game menus. Some say "add your games here." HA! Have been thru every instruction and forum I can find and haven't found a step- by-step procedure for doing this yet. My game menus are blankedty blank blank.

You asked for suggestions for new tutorials. Mine would be any that helped with the 3 basic chores mentioned above. Mine would even be a tutorial on finding tutorials on above.

Thks again for the tutorial. Wish I could find a few more written as well as yours.

Ok in number one you mention scripts.. not sure what to do if you are trying to change the states in a script. But if you are trying to change the text in the properties box You have to change the text and color in each state. Mouse away ( text) mouse over (text)

#2 Same thing here you must change the text for each state..

#3 Usually the text for games are on some kind of menu. if it is text or an icon for a game you do the same thing. to make (new text or add a graphic) make a new object, In the properties box go to states add either text or a graphic. Then go to summary at this point you will need to know the name of the Object (menu) that you want to attach the text or graphic to. Now go to it's properties then summary page look at the object ID that is the name of the object let's just say the name is( Games Menu).. Now go back to your new object. On the summary page where it says "Parent/Owner" put the name of the object there"Game Menu" Ok now that will assign the new object to the menu. Under where is says "Child" change it to yes if it doesn't do it automatically. then give your new object "Text or Graphic " a name where it says object ID. then hit apply

Hope this helps..



CerebroJD Looking forward to seeing the new script.....
on Sep 28, 2005
I could really use some resources on WMI

BakerStreet, the basics of WMI are quite simple. You'll just need the tools to search through your WMI. The first one is wbemtest.exe, found in your system32/wbem/ folder. You can find some information on the Microsoft website here: http://www.microsoft.com/technet/prodtechnol/windowsserver2003/library/ServerHelp/28209472-b3ed-4b96-a6dd-c43ffdd91369.mspx and a simple tutorial here: http://www.computerperformance.co.uk/vbscript/wmi_wbemtest.htm
The next useful tool is Microsofts Scriptomatic, now on version 2.0. It's a REALLY good tool if you want to quickly generate WMI code in several languages (VBScript and JScript!). It can be found here: http://www.microsoft.com/technet/scriptcenter/tools/scripto2.mspx
Hope that helps, happy scripting!
on Sep 28, 2005
Also, Brad wrote a good tutorial a while back using WMI. Find it here: https://www.wincustomize.com/articles.aspx?SID=1&AID=67611&c=1#525386