How to get the current screen orientation using Symbian C++
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: 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();
}
}


28 Sep
2009
Application may need to get current orientation. In GUI application you can get it easily by using method CAknAppUiBase::Orientation(). Article describes how to get current orientation of application, which is more useful to beginners.
Current orientation of application is different from orientation of device. Do not confuse with screen orientation of device and current orientation of application. CAknAppUiBase::Orientation() will returns the orientation that you have set using SetOrientationL() in your constructL() method of appui class, not screen orientation of device.