Catching the menu open and close events in Symbian C++
Article Metadata
Tested with
Devices(s): Nokia 6220 Classic
Compatibility
Platform(s): S60 3rd Edition
Platform Security
Signing Required: Self-Signed
Article
Keywords: MEikMenuObserver, MEikMenuObserver::SetEmphasis()
Created: aknyman
(02 Oct 2008)
Last edited: hamishwillee
(14 Jun 2012)
Contents |
Overview
This code snippet shows how to catch the menu open and close events in CAknAppUi-derived classes. These events can be caught by overriding the SetEmphasis() method from MEikMenuObserver. This functionality is needed, for example, when a game must be in pause mode while a game menu is activated.
This snippet can be self-signed.
MMP file
The following libraries are required:
LIBRARY avkon.lib //Avkon resources
Header file
#ifndef __TESTAAPPUI_H__
#define __TESTAAPPUI_H__
// INCLUDES
#include <aknappui.h>
// FORWARD DECLARATIONS
class CTestAAppView;
//class CGameEngine;
// CLASS DECLARATION
/**
* CTestAAppUi application UI class.
*/
class CTestAAppUi : public CAknAppUi
{
//...
private: // from MEikMenuObserver
void SetEmphasis(CCoeControl* aMenuWindow,TBool aEmphasis);
//...
//Pauses the application if menu is activated
void SetUiPauseState(TBool aEmphasis);
private:
// Data
//The application view
CTestAAppView* iAppView;
//The pointer to the game engine
//CGameEngine* iEngine;
};
#endif //__TESTAAPPUI_H__
Source file
#include "TestAAppUi.h"
#include "TestAAppView.h"
//...
// From MEikMenuObserver. Menu emphasising or de-emphasising function.
void CTestAAppUi::SetEmphasis(CCoeControl* /*aMenuWindow*/, TBool aEmphasis)
{
if(iAppView)
{
SetUiPauseState(aEmphasis);
}
}
void CTestAAppUi::SetUiPauseState(TBool aEmphasis)
{
//pause game if menu is activated
if(aEmphasis /*&& !iEngine->IsStopped()*/)
{
//this debug line works only in the emulator
//iEikonEnv->InfoMsg(_L("stop"));
//iEngine->StopGame();
}
else
{
//this debug line works only in the emulator
//iEikonEnv->InfoMsg(_L("start"));
//iEngine->StartGame();
}
}
Postconditions
The menu open and close events has been caught and the pause state has been toggled accordingly.


(no comments yet)