DesktopX Tips and Tricks

Thursday, January 17, 2008 by RomanDA | Discussion: 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?

RomanDA
Reply #1 Thursday, January 17, 2008 9:14 PM
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..
sViz
Reply #2 Thursday, January 17, 2008 9:23 PM
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.   
RomanDA
Reply #3 Thursday, January 17, 2008 9:32 PM
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.
RomanDA
Reply #4 Thursday, January 17, 2008 9:41 PM
sVIZ, thats cool.. never even looked at .comments very cool idea, simple way to store "hidden" data too.. have to try it out.
SirSmiley
Reply #5 Thursday, January 17, 2008 11:45 PM
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.
danioc
Reply #6 Friday, January 18, 2008 5:59 AM
Very nice and very, very, very useful tips.
Thank you David
Richard Mohler
Reply #7 Friday, January 18, 2008 11:23 PM
Cool, thanks..
Quentin94
Reply #8 Saturday, January 19, 2008 10:03 AM
A really cool idea  
Tiggz
Reply #9 Saturday, January 19, 2008 11:06 PM
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.
Vad_M
Reply #10 Sunday, January 20, 2008 6:26 PM
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)
RomanDA
Reply #11 Monday, January 21, 2008 8:12 AM
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!
Julynessi
Reply #12 Tuesday, January 22, 2008 5:44 AM
Nice Tips!  
Tiggz
Reply #13 Tuesday, January 22, 2008 6:34 AM
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
Tiggz
Reply #14 Tuesday, January 22, 2008 6:36 AM
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)
RomanDA
Reply #15 Wednesday, January 23, 2008 8:35 PM
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
SirSmiley
Reply #16 Wednesday, January 23, 2008 11:34 PM
umm... I believe you did somewhere (unless I stole it from Vad or Tiggz?) because that's what I used with the iReflector. Except for the If Statement which seems obvious now.
RomanDA
Reply #17 Thursday, January 24, 2008 6:35 AM
im getting old bud.. i need to organize all my little code snippets somewhere.. hmmm might have an idea on that too.
SirSmiley
Reply #18 Sunday, March 09, 2008 7:16 PM
In popup or right click menus add an "&" symbol before a letter.
When the menu is called selecting that letter will execute the resulting menu item.
Code: vbscript
  1. mainmenu.AppendMenu 0, 1, "&item1"
  2. mainmenu.AppendMenu 0, 2, "i&tem2"
  3. mainmenu.AppendMenu 0, 3, "it&em3"
zakai1369
Reply #19 Sunday, March 09, 2008 7:44 PM
Haven't gotten into DX yet but I'd like to in the near future. So just marking this to be able to find it easily.
BigDogBigFeet
Reply #20 Sunday, March 09, 2008 11:34 PM
Ditto

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!

Articles Filters

Category:
View:
Search:
Apply



walnut3