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
 All Forums
 Origin Forum for Programming
 Forum for Origin C
 GetNBox event hander as method

Note: You must be registered in order to post a reply.
To register, click here. Registration is FREE!

Screensize:
UserName:
Password:
Anti-Spam Code:
Format Mode:
Format: BoldItalicizedUnderlineStrikethrough Align LeftCenteredAlign Right Horizontal Rule Insert HyperlinkUpload FileInsert Image Insert CodeInsert QuoteInsert List
   
Message:

* HTML is OFF
* Forum Code is ON
Smilies
Smile [:)] Big Smile [:D] Cool [8D] Blush [:I]
Tongue [:P] Evil [):] Wink [;)] Clown [:o)]
Black Eye [B)] Eight Ball [8] Frown [:(] Shy [8)]
Shocked [:0] Angry [:(!] Dead [xx(] Sleepy [|)]
Kisses [:X] Approve [^] Disapprove [V] Question [?]

 
Check here to subscribe to this topic.
   

T O P I C    R E V I E W
additive Posted - 04/03/2009 : 12:51:11 PM
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();
}
2   L A T E S T    R E P L I E S    (Newest First)
additive Posted - 06/23/2009 : 11:37:16 AM
Hi Sophy,
that's a great idea! Thank you very much!

Michael
Sophy Posted - 06/05/2009 : 05:38:20 AM
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;
}

The Origin Forum © 2020 Originlab Corporation Go To Top Of Page
Snitz Forums 2000