Namespaces
Variants
Actions

How to get the current screen orientation using Symbian C++

Jump to: navigation, search
Article Metadata

Tested with
Devices(s): Nokia E90

Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition

Platform Security
Signing Required: Self-Signed
Capabilities: None

Article
Keywords: CAknAppUiBase::Orientation(), TAppUiOrientation, CCoeEnv.
Created: vasant21 (17 Oct 2008)
Last edited: hamishwillee (30 May 2013)

Overview

This article shows how to get the current screen orientation using Symbian C++

Using screen dimensions

Below is a reliable way to query the screen dimensions, and hence determine orientation, using Symbian C++.

CWsScreenDevice* screenDevice = CEikonEnv::Static()->ScreenDevice();
const TSize& screenSize = screenDevice->SizeInPixels();
 
if (screenSize.iWidth > screenSize.iHeight)
{
// LayoutLandscape;
}
else
{
// LayoutPortrait;
}


Using CAknAppUiBase::Orientation()

This snippet below shows how to get current orientation by using CAknAppUiBase::Orientation().

Warning.png
Warning: Note that the value returned is simply the value that the app itself defines using SetOrientation() - and will return EAppUiOrientationUnspecified if not set.

You cannot call CAknAppUiBase::Orientation() directly in a class which is not derived directly or indirectly from CAknAppUiBase or if you do not have access to AppUi instance, then you can also fetch the information using CCoeEnv.

This snippet can be self-signed and we assume that we already have a working GUI based application.


The following capabilities and libraries are required:

CAPABILITY  None
LIBRARY avkon.lib

Source:

#include <aknappui.h>
 
CCoeEnv* env = CCoeEnv::Static();
if( env )
{
CAknAppUiBase* appUiBase = REINTERPRET_CAST( CAknAppUiBase*, env->AppUi() );
if( appUiBase )
{
/*
* Possible values for TAppUiOrientation are :
* EAppUiOrientationUnspecified,
* EAppUiOrientationPortrait,
* EAppUiOrientationLandscape,
* EAppUiOrientationAutomatic
**/

CAknAppUiBase::TAppUiOrientation orientation = appUiBase->Orientation();
}
}
This page was last modified on 30 May 2013, at 05:54.
124 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved