DesktopX Tips and Tricks

By on January 17, 2008 8:44:16 PM from WinCustomize Forums WinCustomize Forums

RomanDA

Join Date 12/2003
+147

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?

20 Replies
Search this post
Subscription Options


Reason for Karma (Optional)
Successfully updated karma reason!
January 17, 2008 9:14:32 PM from WinCustomize Forums WinCustomize Forums
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..
Reason for Karma (Optional)
Successfully updated karma reason!
January 17, 2008 9:23:46 PM from WinCustomize Forums WinCustomize Forums
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.   
Reason for Karma (Optional)
Successfully updated karma reason!
January 17, 2008 9:32:40 PM from WinCustomize Forums WinCustomize Forums
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.
Reason for Karma (Optional)
Successfully updated karma reason!
Sign Up or Login and this ad disappears!
There are many great features available to you once you register. Sign Up for a free account and browse the forums without ads.
January 17, 2008 9:41:14 PM from WinCustomize Forums WinCustomize Forums
sVIZ, thats cool.. never even looked at .comments very cool idea, simple way to store "hidden" data too.. have to try it out.
Reason for Karma (Optional)
Successfully updated karma reason!
January 17, 2008 11:45:09 PM from WinCustomize Forums WinCustomize Forums
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.
Reason for Karma (Optional)
Successfully updated karma reason!
January 18, 2008 5:59:05 AM from WinCustomize Forums WinCustomize Forums
Very nice and very, very, very useful tips.
Thank you David
Reason for Karma (Optional)
Successfully updated karma reason!
January 18, 2008 11:23:24 PM from WinCustomize Forums WinCustomize Forums
Cool, thanks..
Reason for Karma (Optional)
Successfully updated karma reason!
January 19, 2008 10:03:33 AM from WinCustomize Forums WinCustomize Forums
A really cool idea  
Reason for Karma (Optional)
Successfully updated karma reason!
January 19, 2008 11:06:26 PM from WinCustomize Forums WinCustomize Forums
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.
Reason for Karma (Optional)
Successfully updated karma reason!
January 20, 2008 6:26:40 PM from WinCustomize Forums WinCustomize Forums
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)
Reason for Karma (Optional)
Successfully updated karma reason!
January 21, 2008 8:12:06 AM from WinCustomize Forums WinCustomize Forums
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!
Reason for Karma (Optional)
Successfully updated karma reason!
January 22, 2008 5:44:03 AM from WinCustomize Forums WinCustomize Forums
Nice Tips!  
Reason for Karma (Optional)
Successfully updated karma reason!
January 22, 2008 6:34:14 AM from WinCustomize Forums WinCustomize Forums
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
Reason for Karma (Optional)
Successfully updated karma reason!
January 22, 2008 6:36:23 AM from WinCustomize Forums WinCustomize Forums
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)
Reason for Karma (Optional)
Successfully updated karma reason!
January 23, 2008 8:35:03 PM from WinCustomize Forums WinCustomize Forums
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
Reason for Karma (Optional)
Successfully updated karma reason!
January 23, 2008 11:34:16 PM from WinCustomize Forums WinCustomize Forums
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.
Reason for Karma (Optional)
Successfully updated karma reason!
January 24, 2008 6:35:10 AM from WinCustomize Forums WinCustomize Forums
im getting old bud.. i need to organize all my little code snippets somewhere.. hmmm might have an idea on that too.
Reason for Karma (Optional)
Successfully updated karma reason!
March 9, 2008 7:16:35 PM from WinCustomize Forums WinCustomize Forums
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"
Reason for Karma (Optional)
Successfully updated karma reason!
March 9, 2008 7:44:43 PM from WinCustomize Forums WinCustomize Forums
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.
Reason for Karma (Optional)
Successfully updated karma reason!
March 9, 2008 11:34:29 PM from WinCustomize Forums WinCustomize Forums
Ditto
Reason for Karma (Optional)
Successfully updated karma reason!
Stardock Forums v1.0.0.0    #108431  walnut1   Server Load Time: 00:00:00.0000172   Page Render Time:

Home | About | Privacy | Upload Guidelines | Terms of Service | Help
WinCustomize © 2014 Stardock Corporation. All Rights Reserved.