Question:
- How can I set a context menu to a tree item or listview item?
- How can I create a menu button?
- How can I show a shortcutmenu with a certain content depending on the clicked item?
Answer:There is no built-in menubutton control and no popupmenu control in OpenDCL.
But you can workaround that with a static or dynamic shortcutmenu based on a loaded menu.
The attached project demonstrates solutions for all questions above. In every case a popupmenu is needed to be shown by the AutoLISP menucmd-function.
(defun c:showmenu ()
(MENUCMD "P0=MENUBUTTON.MENUBUTTON")
(MENUCMD "P0=*")
(princ)
); c:showmenu
The macro of each menu item either calls an event for the dialog or another command.
The menu button changes the current method after selecting a menubutton item.
The select button of this sample invokes a progress of reading all listview items to create a shortcut menu of them.
This sample shows how to handle with a dynamic shortcutmenu.
Many thanks to Barry Ralphs (http://sourceforge.net/projects/opendcl/forums/forum/658811/topic/1868759?message=4621323) and James Buzbee (http://www.theswamp.org/index.php?topic=25896.msg311909#msg311909) for their samples.
Note: all the contents of the archive must be placed in a AutoCAD support path. Should work for all AutoCAD releases from R16.0 up to 18.1!
Fred
Hello, in the Rev 1.1 of this FAQ I want apply what I have learned when I studied the changes from Owen of my scrollbar sample (http://www.opendcl.com/forum/index.php?topic=994.0). Owen put the modified code to the new OpenDCL sample in the folder "C:\Program Files\OpenDCL Studio\<LANGUAGE>\Samples".
What is different? The pb_task_OnClicked event handler was replaced by two commands. The commands will be assigned regarding the latest selected method. Have a look into the code and watch out for the (dcl_Control_SetProperty menubutton_form_pb_task "Clicked" ...)-lines.
Have fun with it.
Fred