Welcome, Sit down, and make yourself comfortable.
Published on January 17, 2008 By RomanDA In DesktopX

Hey all,

I'm sure most of you think i have given up on DX. Its been months since I posted anything on DX scripting, or creation. Just been working my butt of out-of-town for most of the past 4 months.
Actually I'm sitting in a hotel room right now.  Anyway, I was looking at something the other day and wondered how many little SIMPLE tricks are hidden in DX. I was talking to miksama the other day and he pointed sent me some cool things.

I wanted to share some things that not everyone might know about, or even use. If you know one of these and have been using it forever, goodie, show us something you think we dont know about. I want this it be an ongoing article with lots of user input.

These will require that you know at lease some basics of scripting in DX. If you don't you might want to do a simple Google search for DesktopX Tutorials, I hear SOMEONE spent a great deal of time on some.

Lets get this started with a few 1 liners.

PING:
You want to ping a web site and get the resulting time to site.

x = system.Ping("www.wincustomize.com")
object.text = x & " ms"

WALLPAPER:
Want to change your wallpaper?
This is the quick way to do it.

Option:
0 = use default wallpaper
1 = Center wallpaper
2 = Tile wallpaper
3 = Stretch wallpaper

'Examples:

System.SetWallpaper "C:\temp\wall1.bmp", 1
'Sets the wallpaper to the bmp above and the 1 makes it centered.

System.SetWallpaper Object.Directory & "wall1.jpg", 2
'Sets the wallpaper to wall1 in the directory where the dx object was created, and the 2 tiles it.

System.SetWallpaper "", 0 
'This will restore the original wallpaper.

CLIPBOARD:
Say you want to dump something from DX to the windows clipboard?
Its 1 line of code easy.
I believe this works only with TEXT, not images, but i could be wrong.

System.Clipboard = Object.text

VOLUME/MUTE:
Ok, want a fast way to set your volume to 10? or 90? or mute it completely?

system.Volume = 10
system.Volume = 90

'or mute it
system.mute

READ A FILE
Want to dump the contents of a file to a text string?
Only param=1 is currently supported.

txtLog = System.SimpleRead("C:\temp\file2read.txt", 1)

WRITE TO A FILE
Ok, this is simple, dump the contents of a string into a file.
Only param=1 is currently supported.

txtstring = "This is the text string, could have anything in here" & vbnewline & "even on a second line"
System.SimpleWrite "C:\temp\output.txt", txtstring, 1

These are just a few simple SYSTEM tricks. What do you have up your DX sleeve?


Comments (Page 1)
2 Pages1 2 
on Jan 17, 2008
Sorry Zu, had problems making this stuff work. Have a forum post that i gave up on. man.. need to get the CODE block to work right, this is a pain in the..
on Jan 17, 2008
Gah! I posted on the other one.

Repost:

I've been using object.comments to quickly store information on the fly without having to use persiststorage or localstorage.

I use it mostly for launching shortcuts especially when the target is dynamic and changes frequently. You get a path from user input, e.g. "c:\", you store it in, and launch it from object.comments.

Code: vbscript
  1. Object.comments = "c:\"
  2. 'Called when L-click is released
  3. Function Object_OnLButtonUp(x, y, dragged)
  4. If not dragged then
  5. On Error Resume Next
  6. Set Sh = CreateObject("WScript.Shell")
  7. Sh.Run (Chr(34)& object.comments & Chr(34))
  8. Set Sh = Nothing
  9. End If
  10. End Function


Excellent tips you've highlighted, by the way.   
on Jan 17, 2008
Man, sometimes these pages drive me nuts.. tried to make a simple edit, and it totally messes up the page.. oh well.. think its fixed now.

BTW, code doesnt work here.. in articles, its a pain.
on Jan 17, 2008
sVIZ, thats cool.. never even looked at .comments very cool idea, simple way to store "hidden" data too.. have to try it out.
on Jan 17, 2008
Have been using the object comments for a built in drag and drop help function. Then either build a help file using the dictionary object or a multi-dimensional array. Eg. drag the question mark over the object & help pops up display the comments.

My most favorite one recently is the ctrl+space code suggestions. Still haven't got all the properties items down pat.
on Jan 18, 2008
Very nice and very, very, very useful tips.
Thank you David
on Jan 18, 2008
Cool, thanks..
on Jan 19, 2008
A really cool idea  
on Jan 19, 2008
Mostly I have a single, transparent, non-activatable object at 0,0 that contains the script. Everything else is a non-contained child of this. Life got a great deal simpler when all the script could be located in one place.

Also, I periodically copy the script into a txt file - not only can this be handy in dire emergencies (when dx explodes for no apparent reason), it is also extremely useful, maybe months later, when making something else to be able to quickly reference all your old scripts and graft parts into your latest project.
on Jan 20, 2008
As well as allow me to remind you about a few useful functions that I already tested:

1. Object Margins

desktopx.object("some object").states("").setmargins left, top, right, bottom, stretch_X, stretch_Y
desktopx.object("some object").states("Mouse away").setmargins left, top, right, bottom, stretch_X, stretch_Y

2. Object Shadow (Glow)

desktopx.object("some object").states("").setshadow enabled, sharpness, darkness, offset X, offset Y, rgb(r,g,
desktopx.object("some object").states("Mouse away").setshadow enabled, sharpness, darkness, offset X, offset Y, rgb(r,g,

3. Object Font

desktopx.object("some object").states("").settont fontname, fontsize, bold, italic, underline, strikeout, charset
desktopx.object("some object").states("Mouse away").settont fontname, fontsize, bold, italic, underline, strikeout, charset

4. The easy way to download any file through internet

system.DownloadFile(URL, localPath, True)
on Jan 21, 2008
Awesome all!! these are great.

I think that if you are looking for windows INFO from your system that WMI is THE place to go. I am working on an update for my DROP INFO program that will have a lot more info.

Love it!! Keep 'em coming!
on Jan 22, 2008
Nice Tips!  
on Jan 22, 2008
Not really a dx tip, more a purely scripting thing...

I've been using loops alot more lately. In the following example I use a loop to incrementally reduce the number of letters in a text object so that it fits in a given width. Also contains an example of object.parentname to...yep, get the name of an object's parent.

Code: vbscript
  1. n = 0'add before the loop
  2. 'then inside your loop add the following lines
  3. n = n + 1
  4. if n > 100 then exit do'where 100 is a number that you think should be plenty ;)
  5. 'it could be 1000


p.s. you have to be quite careful when using loops to ensure that you don't create an endless loop that never exits. If you are unsure just add something like the following when testing your loop...

Code: vbscript
  1. n = 0'add before the loop
  2. 'then inside your loop add the following lines
  3. n = n + 1
  4. if n > 100 then exit do'where 100 is a number that you think should be plenty ;)
  5. 'it could be 1000


Remove this precautionary code when you're sure your loop is working as intended
on Jan 22, 2008
Not really a dx tip, more a purely scripting thing...

I've been using loops alot more lately. In the following example I use a loop to incrementally reduce the number of letters in a text object so that it fits in a given width. Also contains an example of object.parentname to...yep, get the name of an object's parent.

Code: vbscript
  1. t = object.text'assign the object's text to a variable
  2. Do'start of loop
  3. bTooLong = False'set the checking boolean
  4. If object.width > desktopx.Object(object.parentname).width Then
  5. bTooLong = True'reset boolean which will force the loop
  6. t = left(t,len(t)-1)'remove a character from end of text
  7. object.text = t & "..."'apply new text to the object, add dots for missing characters
  8. End If
  9. Loop While bTooLong'return to beginning of loop to recheck widths


p.s. you have to be quite careful when using loops to ensure that you don't create an endless loop that never exits. You can always increment a variable inside the loop, and exit the loop using "exit do" if the variable goes over, say, 1000

*edit* ignore the previous post - had some problems with the code tags etc (ironically enough)
on Jan 23, 2008
This is pretty cool.. i wish i spotted this one earlier.

Say you want the widget/gadget to load a file from the directory its running from.

Well.. if your in BUILDER mode, the widgets executable folder is where DX Builder is running from, not where the widget's exe will end up. SO this could help when testing the program in builder mode, ie:

DesktopX.HostTypeReturns the host that is currently running the object. Return values are:
1 – DesktopX Client
2 – DesktopX Builder
3 – Widget runtime
4 – DesktopX PRO application
0 – Unknown

It could be used like this:
if DesktopX.HostType = 3 then
ExFolder = desktopx.ExecutableDirectory
else
ExFolder = "C:\temp\testfile.ini"
end if
2 Pages1 2