Creating stylus pop-up menu

Construct the menu using the method NewL() in the class CAknStylusPopUpMenu .

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.

      void CMyAppView::HandlePointerEventL
    ( const TPointerEvent& aPointerEvent )
    {
    if ( aPointerEvent.iType == TPointerEvent::EButton1Down )
        {
        if ( !iMenu )
            {
            iMenu = CAknStylusPopUpMenu::NewL( 
                    iMenuObserver, 
                    aPointerEvent.iParentPosition, 
                    NULL );
            TInt resourceReaderId = 0;
            resourceReaderId = R_MYAPP_STYLUS_MENU;
            TResourceReader reader;
            iCoeEnv->CreateResourceReaderLC( 
                    reader, resourceReaderId );
            iMenu->ConstructFromResourceL( reader );
            CleanupStack::PopAndDestroy(); // reader
            }
        iMenu->SetPosition( aPointerEvent.iParentPosition );
        iMenu->ShowMenu();
        }
    // Forward event to base class too.
    CCoeControl::HandlePointerEventL( aPointerEvent );
    }

RESOURCE STYLUS_POPUP_MENU r_myapp_stylus_menu
    {
    items =
        {
        STYLUS_POPUP_MENU_ITEM 
            {
            txt = "Stylus Popup Menu Item 1"; 
            command = EMyAppMenuItemCmd1;
            },
        STYLUS_POPUP_MENU_ITEM 
            {
            txt = "Stylus Popup Menu Item 2"; 
            command = EMyAppMenuItemCmd2; 
            },
        STYLUS_POPUP_MENU_ITEM 
            { 
            txt = "Stylus Popup Menu Item 3"; 
            command = EMyAppMenuItemCmd3; 
            }
        };
    }