GetEventHandler
Get the event handler class name if present
string GetEventHandler( BOOL bCheckValid = false, BOOL bDeafult = FALSE )
If bCheckValid = [input] false, simply return the class name or empty string if no event handler was installed.
If bCheckValid = [input] true, then only return the class name if it is valid.
EX1
#include <Origin.h> #include <control.h> #include <..\OriginLab\OriginEvents.h> // The following code installs an Event Handler class called MyEvent into a rectangle named "Rect" in active graph layer // MyEvent is a class to trap right-click on GraphObject // You can create your own class and install it into origin object that require customized event handling. // Make sure your class is based on OriginEventsBase. class OC_REGISTERED MyEvent : public OriginEventsBase { public: //show a test menu virtual bool OnContextMenu(int x, int y, DWORD dwControl = 0) { Menu muMenu; muMenu.Add(_L("test menu"), 1, MF_STRING); int nSelCmd; muMenu.TrackPopupMenu(0, x, y, GetWindow(), &nSelCmd); return true; } virtual bool SetObj(OriginObject& obj) //obj with the Event Handler { m_Object = obj; if( m_Object ) return true; return false; } protected: GraphObject m_Object; }; //set an Event Handler to the Rect object. //then you can right on the rect to see the test menu void OriginObject_SetEventHandler_Ex1() { GraphLayer lay = Project.ActiveLayer(); //get the Rect object on the graph GraphObject goMe; if(lay) goMe = lay.GraphObjects("Rect"); if(goMe) goMe.SetEventHandler("MyEvent"); //event class name } //Get the event handler class name //run this function to show the test menu void OriginObject_GetEventHandler_Ex1() { GraphLayer lay = Project.ActiveLayer(); //get the Rect object on the graph GraphObject goMe; if(lay) goMe = lay.GraphObjects("Rect"); if(goMe) { //use the event handler class name to get the event class to show test menu string strClassName = goMe.GetEventHandler(true); if(!strClassName.IsEmpty()) { MyEvent& event = (MyEvent&)Project.FindClass(strClassName); if(event) { out_str("Found handler, invoking context menu"); int x = 500; int y = 500; event.OnContextMenu(x, y); } } } }
OriginObject::SetEventHandler
Project::FindClass
origin.h