DX Tutorial #3: Let's Create a Right-Click Menu

RomanDA's DX Tutorial Series

Wednesday, May 24, 2006 by RomanDA | Discussion: DesktopX Tutorials

RomanDA's DesktopX Tutorials:
My goal is to make a set of tutorials for DesktopX.  If you have ideas on what you would like to see, please email me at [email protected]

Lets make a RIGHT-CLICK menu
Would you like to have a right-click menu that isn't the "standard" one
that DX supplies when you export a widget?

Ok, Read on...

 

The code for this isn't really all that hard.

( danilloOc's new player)

 
'--- Function to handle the RIGHT-Click

Function Object_OnRButtonUpEx(obj,x,y,dragged)
  If Not dragged Then            
'-- Do not do anything if someone is dragging the widget
    Object_OnRButtonUpEx = True
    Call CreateSectionMenu()     
'-- Call the Function that Shows the Menu
  End If
End Function

'--- Right Click Menu Creation Function -------

Sub CreateSectionMenu()
     Set mainmenu = nothing
     Set mainmenu = DesktopX.CreatePopupMenu    
'-- Create Main Menu
     mainmenu.AppendMenu 0, 1, "About Player"    '-- First item in the menu
     mainmenu.AppendMenu 0, 2, "Properties"     
'-- Second item in the menu
     mainmenu.AppendMenu 0, 3, "Exit"           
'-- Third item in the menu (this can continue)
     result = mainmenu.TrackPopupMenu(0, System.CursorX, System.CursorY) '-- Save the results of mouse movements
     Call ExecuteSectionMenu(result,snum)       
'-- Run the Function that handles the menu function called
End Sub

'-- Function to handle the results of the right-click menu action

Sub ExecuteSectionMenu(result,snum)
     Select Case result                       
'-- Look thru the results to see what was selected
          Case 1                              
'-- Look in the function above 0, 1, "About" - this is the 1
               desktopx.Object("About_Window").Visible = True
'-- show your custom ABOUT window
          Case 2                              
'-- Look in the function above 0, 2, "Prop.." - this is the 2
               widget.OpenProperties          
'-- Open the Properties for the widget
          Case 3                              
'-- Look in the function above 0, 3, "Exit.." - this is the 3
               widget.Close                   
'-- Close the Widget
          ' Case 4
     End Select
     Set mainmenu = nothing                   
'-- clear the menu
End Sub

There are a lot of things that can be done with this, things like SUB menus, etc.  Maybe I will look into that at a later date.  Its just a simple example

This script needs to be attached to any object that you want to have the right-menu active.
This code is part mine, mostly VAD_M's who is quickly becoming the GOD of DX scripts!

Enjoy,
RomanDA
AKA: David A. Roman
http://romanda.wincustomize.com
http://www.romanda.org
[email protected]
TheGuyPC
Reply #1 Friday, May 26, 2006 2:05 AM
I am sure I am not the only one who appreciates your efforts.

I hope that the others who gain from your knowledge will post their gratitude.

Personally, I think tutorials as good as these should either be "stickied" or, have their own link all together.

One concern I have is, can a person use "your" script without permission? In my mind, art is art. Knowledge is an art within itself. Without your knowledge, there is no script. I may be over-complicating the issue, but I thought it worth asking.


A clearly defined "newbie" link for DX language would only benefit this community. Your tutorial skips ahead of where I am.


Either way, what you have done by posting your tutorials is as close to unselfish as it gets. I look forward to using the printed version of your wisdom in the future! I will gladly share my efforts as you have. Good 4 U!
CerebroJD
Reply #2 Friday, May 26, 2006 4:37 AM
The "DX Language", so-to-speak, is just VBscript, for which there are many tutorials around the internet for. Take a look over at w3schools for a really good start!
RomanDA
Reply #3 Friday, May 26, 2006 7:00 AM
By posting the code here I am essentially giving everyone the rights to use the code, if I didn’t do that the tutorials would be useless.
danioc
Reply #4 Friday, May 26, 2006 10:16 AM
RomanDA, thanks a lot for the tutorials and for helping me with the player scripts, I couldn't make it without your help my friend.
Please keep doing the tutorials
TheGuyPC
Reply #5 Friday, May 26, 2006 3:45 PM
Thanks CerebroJD! That link is great!

By posting the code here I am essentially giving everyone the rights to use the code, if I didn’t do that the tutorials would be useless.


^^That's what I figured. Still, I thought it was worth asking.^^

Thanks all!

PC
sViz
Reply #6 Thursday, June 1, 2006 4:07 PM
Thanks for these tutorials RomanDA! I don't think alot of people realize how many newbies start out really excited to use DX and then end up struggling and discouraged because they have little knowledge of scripting. I know I had alot of dynamic ideas for cool widgets and then spend most of the time frustrated with the scripting. So, keep up the good work!
c242
Reply #7 Friday, June 2, 2006 12:13 AM
Roman : First I really enjoy what You do here.

But a question as that isn't in the official tutorials also : Is it possible to assign an icon to the menu entries ? I couldn't figure that one out.
RomanDA
Reply #8 Friday, June 2, 2006 6:32 AM
That i dont know.. illl check in a few days when im back "on-line"
ZubaZ
Reply #9 Friday, June 2, 2006 8:30 AM
David, I just re-read these tuts and am amazed.

If any Stardockians are following this thread, may I suggest that these tutorials be included or linked in the on-line documentation for DX in the tutorials section (with permissions and props of course): https://www.stardock.com/products/desktopx/documentation/index.html




Posted via WinCustomize Browser/Stardock Central
Cindersis
Reply #10 Tuesday, January 9, 2007 3:23 AM
thank you for all of the wonderful tutorials.One day In the future I will show my own objects on wincostomize it will be thanks to Your tutorials
Sprinkle
RomanDA
Reply #11 Tuesday, January 9, 2007 5:30 AM
Ms. SprinkleSB,

Im very glad they have been of help to you. I look forward to seeing your objects.
Fairyy~
Reply #12 Tuesday, January 9, 2007 6:19 AM
By posting the code here I am essentially giving everyone the rights to use the code, if I didn’t do that the tutorials would be useless.


I appreciate your sharing your codes, people like myself that have no knowledge of vb script wouldn't be able to make a thing. Looking forward to more of your Tutorials.
Thankyou.
tawoods
Reply #13 Tuesday, January 9, 2007 6:32 AM
Thanks David for the time and effort you put into this.

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!



web-wc01