【お知らせ】この部分は英語原文のみでの提供となります。何卒ご了承ください。
2.2.4.32.16 OriginObject::GetEventHandler
Contents
Description
Get the event handler class name if present
Syntax
string GetEventHandler( BOOL bCheckValid = false, BOOL bDeafult = FALSE )
Parameters
- bCheckValid
- [input] TRUE will check to see if class name represents a compiled Origin C class that is registered with the OC_REGISTERED keyword
- bDeafult
- [input] TRUE will return an internal deafult name, of no name has been set using SetEventHandler
Return
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.
Examples
EX1
- this example shows how to use SetEventHandler and GetEventHandler to show a menu after right-click on a rectangle in a graph, so please make sure the active graph layer has a rectangle named "Rect"
#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); } } } }
Remark
See Also
Project::FindClass
Header to Include
origin.h