Construct the menu using the method CAknStylusPopUpMenu::NewL()in the class .
Note: The last parameter in the constructor is a pointer to the
preview pop-up from which the stylus pop-up menu is launched. If you
are not constructing a pop-up menu for a preview pop-up, set the parameter
as NULL.
To construct the menu from a resource, use the method CAknStylusPopUpMenu::ConstructFromResourceL().
The following example illustrates a stylus pop-up menu opened in the location (not a preview pop-up) where the user taps with the stylus as well as the resource that defines the menu items:
Note: The menu is constructed only once: when HandlePointerEventL runs for the first time. Later the already constructed menu is shown
again.
Creating directly:
// member variable point to the stylus Popup menu
CAknStylusPopUpMenu * iPopupMenu ;
_LIT(KItem1, "Item 1");
_LIT(KItem2, "Item 2");
_LIT(KItem3, "Item 3");
_LIT(KItem4, "Item 4");
enum StylusPopupMenuCommand
{
StylusMenuCommand1 = 0 ,
StylusMenuCommand2,
StylusMenuCommand3,
StylusMenuCommand4
};
// create object , “this” is a object implement the interface
// MEikMenuObserver
iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
// add menu item
iPopupMenu->AddMenuItemL( KItem1 , StylusMenuCommand1 );
iPopupMenu->AddMenuItemL( KItem2 , StylusMenuCommand2 );
iPopupMenu->AddMenuItemL( KItem3 , StylusMenuCommand3 );
iPopupMenu->AddMenuItemL( KItem4 , StylusMenuCommand4 );
Creating through resource file:
RESOURCE STYLUS_POPUP_MENU r_stylus_popup_menu
{
items =
{
STYLUS_POPUP_MENU_ITEM
{
txt = "Menu Item 1";
command = EStylusPopupCommand1; },
STYLUS_POPUP_MENU_ITEM
{
txt = "Menu Item 2";
command = EStylusPopupCommand2; },
STYLUS_POPUP_MENU_ITEM
{
txt = "Menu Item 3";
command = EStylusPopupCommand3;
}
};
}
// create object
iPopupMenu = CAknStylusPopUpMenu::NewL( this , TPoint( 0 , 0 ) );
{
TResourceReader reader;
iCoeEnv->CreateResourceReaderLC(
reader ,
R_STYLUS_POPUP_MENU );
iPopupMenu->ConstructFromResourceL( reader );
// destroy reader
CleanupStack::PopAndDestroy();
}