BIM Coordinator Program (INT) April 22, 2024
Find the next step in your career as a Graphisoft Certified BIM Coordinator!
Archicad C++ API
About Archicad add-on development using the C++ API.

Add context menu to a DG control?

Anonymous
Not applicable
How can I add a context menu to a DG control, to a LeftText for example?
1 REPLY 1
Anonymous
Not applicable
I found it:
void AddMenuItem (DG::Menu& menu, int id, std::string text)
{
	DG::CommandDescriptor* commandDescriptor =
		new DG::CommandDescriptor (DG::Command (id), text.c_str ());
	menu.AddMenuItem (DG::MenuSimpleItem (commandDescriptor));
}

void MyPalette::ItemContextMenuRequested (
	const DG::ItemContextMenuEvent& ev, bool* needHelp, bool* processed)
{
	*processed = true;
	DG::Menu* menu = new DG::Menu ("");

	AddMenuItem (*menu, 1, "Apple");
	AddMenuItem (*menu, 2, "Pear");
	AddMenuItem (*menu, 3, "Dog");

	DG::CommandEvent& commandEvent = *DG::ContextMenu ("", menu).Display (ev.GetPosition ());
	if (&commandEvent != 0)
	{
		std::stringstream stream;
		stream << "Clicked ";
		stream << commandEvent.GetCommand ().GetCommandId ();
		DGAlert (DG_INFORMATION, "Apple", stream.str ().c_str (), NULL, "OK", NULL, NULL);
	}
}
My problem now is when to call the destructors.
Learn and get certified!