×
Namespaces

Variants
Actions

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

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia E90
CompatibilityPlatform 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.pngWarning: 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.
97 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×