Hi, Rarf:
One solution is to add a hiden node to the GETN tree and store the object pointer in it for later use. Here is an example, hope it will be helpful to you.
#include <Origin.h>
#include <GetNBox.h>
#define STR_OBJ "ObjectPtr"
#define STR_OBJ_NAME "TTT"
class TTT
{
public:
TTT(){ m_nID = 12580; }
~TTT(){}
void CreateBox();
void Say(){ showMsg(); }
private:
void showMsg(){out_int("My ID is : ", m_nID);}
int m_nID;
};
void TTT::CreateBox()
{
GETN_BOX(tr);
GETN_BUTTON_GROUP(TestButton, "Fire event", 2, "Press button") GETN_OPTION_EVENT_EX(ButtonEvent)
//Store the current object into tree node
TreeNode trClassObj = tr.AddNode(STR_OBJ_NAME);
int nObj = (int)this;
trClassObj.SetAttribute(STR_OBJ, (DWORD)this);
trClassObj.Show = false; //make invisible
if ( GetNBox(tr, "Call This", "In event handler can access member functions", NULL, NULL) )
{
}
}
bool ButtonEvent(TreeNode& myTree, int nRow, int nCol, TreeNode& trNode, DWORD dwCntrl, int nType, WndContainer& theDlg)
{
out_str("Button Pressed!");
//Try to get the object stored in tree node and call its member function
TreeNode trClassObj = myTree.GetNode(STR_OBJ_NAME);
if ( trClassObj )
{
int dwObj;
if ( trClassObj.GetAttribute(STR_OBJ, dwObj) )
{
TTT* pObj = (TTT*)dwObj;
pObj->Say();
}
}
return true;
}
void test_TTT()
{
//Remember, in OC, if you want to store object pointer in tree node for later use,
//should use new to create object, for OC depend on this to find object when casting data like TTT* obj = (TTT*)dwObj
//so here, you shall never use TTT tt; tt.CreateBox(); to try to do the following thing, or may cause runtime error
TTT* ttt = new TTT();
ttt->CreateBox();
delete ttt;
}