Accessing the toolbar from applications or application views

To access the current toolbar (CAknToolbar, defined in akntoolbar.h) in applications, use the methods CAknAppUi::CurrentPopupToolbar() or CEikAppUiFactory::CurrentPopupToolbar() in the case of a floating toolbar. For a fixed toolbar, use CAknAppUi::CurrentFixedToolbar() or CEikAppUiFactory::CurrentFixedToolbar(). The methods return a pointer to either the application toolbar or a view-specific toolbar (if defined).

To access the application toolbar directly from applications, you can also call CAknAppUi::PopupToolbar() and CEikAppUiFactory::PopupToolbar(). To access the view-specific toolbar as a client, call CAknView::Toolbar(). These calls do not transfer the ownership of the toolbar, so the framework takes care of the toolbar destruction.

The example below shows how to access the toolbar in the application AppUi class. (You can also use CEikAppUiFactory methods.)

void CMyAppUi::DoSomethingToToolbar()
    {
    
    // Current fixed toolbar (if view has no fixed toolbar, returns application toolbar)
    CAknToolbar* fixedToolbar = CurrentFixedToolbar();
    
    // Current popup toolbar (if view has no popup toolbar, returns application toolbar)
    CAknToolbar* popupToolbar = CurrentPopupToolbar();
    
    // Application toolbar
    CAknToolbar* appToolbar = PopupToolbar();

    …

    }

The example below shows how to access a view specific toolbar in the application view class.

void CMyView::DoSomethingToToolbar()
    {
    
    // View toolbar
    CAknToolbar* toolbar = Toolbar();
    
    …

    }