Published on October 6, 2005 By ExodusCrow In DesktopX
I'm trying to figure out controller scripts for DX and I'm running in to a problem. I can't get DX to recognize anything but right clicks on my widget. I've tried this code to test it out. It only produces a message box when I right click, not when I left-click or double click on the widget.

Sub Object_OnScriptEnter
desktopx.RegisterController Object.Name
End Sub

Function OnControl(lType, lCode)
msgbox (lType & " " & lCode)
End function


Also, the documentation states that I can create a custon right click menu for my widget.

For instance you can replace the right click or systray widget menu by returning true to 1 / 1 notification and provide your own menu as described in the preceding chapter.


How do I return true? and where would I place the code for the new menu?

Thanks in advance for the help.

Confused,
ExodusCrow

Comments
on Oct 07, 2005
Okay, I tried it, and here's how it seemsk to work (you may have already figured it out):

The control messages are only sent for right-clicks on the widget, and for both right and left clicks on the widget's system tray icon. The type and code arguments seem to be as advertised.

As for your question about a custom right-click menu, here's an example:

Note: This one is set up to just handle the right click on the object, but you could use the same contents for the OnControl notification, as long as you made sure it was for the event you wanted.


Function Object_OnRButtonUp(x,y,dragged)
If Not dragged Then
Dim menu
Set menu = DesktopX.CreatePopupMenu
menu.AppendMenu 0, 1, "Options 1"
menu.AppendMenu 0, 2, "Options 2"
menu.AppendMenu 0, 99, "DesktopX"
Dim rtn
rtn = menu.TrackPopupMenu(0, System.CursorX, System.CursorY)
Select Case rtn
Case 1
'Do something
Case 2
'Do something else
End Select
Set menu = nothing
End If
If rtn <> 99 Then
Object_OnRButtonUp=True ' Here's where we return True so DesktopX won't respond further
End If
End Function

This is covered in the documentation under "Scriptable Popup Menus".
on Oct 07, 2005
Btw, sorry about the lack of formatting in the example, but it gets lost in the post.
on Oct 07, 2005
Now it makes sense. I didn’t realize the control script was working on events from the system tray. I'll give the code you wrote a try when I get home. Thanks for the response.
on Oct 07, 2005
hm... the controller script isn't just for system tray... https://www.stardock.com/products/desktopx/documentation/scripting/controllers.html
on Oct 07, 2005
thomassen, how do you get it to recognize the other events?
on Oct 08, 2005
you know what.... when I read the post I went on to do a quick test. without much luck really. I couldn't even get it to respond to the tray icon. However, I know I've used this function before. I'll look into it over this weekend.
on Nov 28, 2005
to dredge up a topic, do controller scripts work only on widgets? im trying to get the right click menu to not appear on objects so i can use the OnRbuttonup commands on objects without the menu appearing.