Back Button delegate in Windows phone 8

Hello,
I want to implement the back button delegate function but I am stuck at:

bool CCApplication::onBackButton() { bool ff = true; if (m_pDelegate) ff=m_pDelegate->onBackPressed(false); return ff; }
In reply to this Pink Nibor said:

OnEnter:
CCApplication::sharedApplication()->setBackDelegate(this);

OnExit
CCApplication::sharedApplication()->setBackDelegate(null);

But he did not tell where to put these lines. As I am new to cocos2dx I am having trouble figuring it out.
Please someone help me.

I have the same trouble to you, i want to known if you solve it ?
please help me .
thank you,

I was not able to find where to place those lines. But, I found a working solution, it is probably not the best but it works :

I changed the OnBackButtonPressed function to call the keyBackClicked function of the current scene (CCLayer child of CCScene). Since I only use single layer in my scene, it works for me. But I think you can make it work even if you have multiple layers.
@
void CCFrameworkView::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args)

{
/* CCLog(“Came into OnBackButtonPressed”);
int c=CCDirector::sharedDirector()>getRunningScene>getChildrenCount;
char buf ;
_itoa_s;
CCLog;/
CCArray
layers=CCDirector::sharedDirector~~>getRunningScene~~>getChildren;
if {
layers~~>objectAtIndex)>keyBackClicked;
//if m_BackDelegate
>onBackPressed;
// bool ff = CCApplication::sharedApplication.onBackButton;
// args~~>Handled = ff;
args~~>Handled=layers~~>objectAtIndex(0))>m_bRunning;
} else args
>Handled=true;
}@

hey Muhammad Wajahat:
thank you for you reply!
I want to know what’s the “m_bRunning” in you code and if i need to add the variable in every layer ?

Muhammad Wajahat wrote:

I was not able to find where to place those lines. But, I found a working solution, it is probably not the best but it works :
>
I changed the OnBackButtonPressed function to call the keyBackClicked function of the current scene (CCLayer child of CCScene). Since I only use single layer in my scene, it works for me. But I think you can make it work even if you have multiple layers.
@
void CCFrameworkView::OnBackButtonPressed(Object^ sender, BackPressedEventArgs^ args)
>
{
/* CCLog(“Came into OnBackButtonPressed”);
int c=CCDirector::sharedDirector()>getRunningScene>getChildrenCount;
char buf ;
_itoa_s;
CCLog;/
CCArray
layers=CCDirector::sharedDirector~~>getRunningScene~~>getChildren;
if {
layers~~>objectAtIndex)>keyBackClicked;
//if m_BackDelegate
>onBackPressed;
// bool ff = CCApplication::sharedApplication.onBackButton;
// args~~>Handled = ff;
args~~>Handled=layers~~>objectAtIndex(0))>m_bRunning;
} else args
>Handled=true;
}@

Oh that is just a variable of CCLayer class. As I said it is not a good way of doing things, it is kind of a hack. If args->Handled is false after this function call then application closes. And therefore, I set m_bRunning=false, only in the MenuScene (first page)’s keyBackClicked function. By default the m_bRunning for any layer is true as far as I know when it returns.
So I get: Close the app if back button pressed on first page (_scene)
Otherwise only follow the logic in keyBackClicked function.

Remember: The app is closed when the program counter (control) returns from the keyBackClicked function for the menuscene as well.

I got that.
Maybe this is not the best way ,but it can running in my device.
Thank you very much!

It just typo.
Here is my solution and it works for sure!
In class (Helloworld for example) .h: define:
void onEnter();
void onExit();
In class .cpp:
void HelloWorld::onEnter()
{
CCApplication::sharedApplication().setBackDelegate(this);
}

void HelloWorld::onExit()
{
CCApplication::sharedApplication().setBackDelegate(NULL);
}
The typo here is instead of using “.” he used “->” lol

The above function doesnt exist in 2.2.4??!?!