The Origin Forum
File Exchange
Try Origin for Free
The Origin Forum
Home | Profile | Register | Active Topics | Members | Search | FAQ | Send File to Tech support
Username:
Password:
Save Password
Forgot your Password? | Admin Options

 All Forums
 Origin Forum for Programming
 Forum for Origin C
 GetNBox event hander as method
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic

additive

Germany
109 Posts

Posted - 04/03/2009 :  12:51:11 PM  Show Profile  Edit Topic  Reply with Quote  View user's IP address  Delete Topic
Hi,

working with GetNBox macros, I added an event handler using

GETN_OPTION_EVENT_EX(ButtonEvent)


This works fine as long as ButtonEvent is a static function. Since my project is more complex, I've inserted the GetNBox macro into an own class and would like ButtonEvent() to have access to class methods and proporties:


bool CGetNBox::ButtonEvent(...)


But this would require that GETN_OPTION_EVENT_EX macro would accept a method pointer. Unfortunately I wasn't able to get this done.
Do you have any advice?

Thanks,
Michael



#include <Origin.h>
#include "GetNBoxEvent.h"

void CGetNBox::CGetNBox()
{
}

void CGetNBox::CreateToolBoxDialog()
{
	GETN_BOX(tr) 	
	GETN_BUTTON_GROUP(TestButton, "Fire event", 2, "Press button") GETN_OPTION_EVENT_EX(ButtonEvent) 	
	if( GetNBox(tr, "Test Dialog", NULL, NULL ) )
	{	   	
	}     
}

bool ButtonEvent(TreeNode& myTree, int nRow, int nCol, TreeNode& trNode, DWORD dwCntrl, int nType, WndContainer& theDlg)
{
    if(ONODETYPE_PUSHBUTTON_GROUP == nType && nRow >= 0  && !(dwCntrl & GETNEVENT_ON_INIT) )
	{
		printf("Butten pressed.\n");
	}
	return true; 
}

void TestDialog()
{
	CGetNBox sampleDialog;
	sampleDialog.CreateToolBoxDialog();
}

Sophy

China
Posts

Posted - 06/05/2009 :  05:38:20 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
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;
}

Edited by - Sophy on 06/05/2009 06:02:51 AM
Go to Top of Page

additive

Germany
109 Posts

Posted - 06/23/2009 :  11:37:16 AM  Show Profile  Edit Reply  Reply with Quote  View user's IP address  Delete Reply
Hi Sophy,
that's a great idea! Thank you very much!

Michael
Go to Top of Page
  Previous Topic Topic Next Topic Lock Topic Edit Topic Delete Topic New Topic Reply to Topic
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000