Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

How to create semi-transparent windows using Symbian C++

From Wiki
Jump to: navigation, search
Article Metadata
Code ExampleCompatibilityArticle
Keywords: CControlOnTopCtrl
Created: chenziteng (27 Sep 2009)
Last edited: hamishwillee (17 Sep 2012)

Contents

Overview

This article describes how to create semi-transparent windows on devices support display mode EColor16MA.

Pre-conditions

The device must support display mode EColor16MA, the display mode can be checked the following code

if(CCoeEnv::Static()->ScreenDevice()->DisplayMode()==EColor16MA)
{
// EColor16MA is supported
}


Solution

The solution is from the "Semi-Transparent Windows" series of articles by william.edwards (the UIQ developer website has been closed but you can open the cached pages after Googling the keywords "Semi-Transparent Windows #1" and "Semi-Transparent Windows #2").

void CControlOnTopCtrl::ConstructL(const TRect& aRect, RWindowGroup* aWindowGroup)
{
TRect rc(aRect);
TInt w = rc.Width();
TInt h = rc.Height();
 
CreateWindowL(aWindowGroup);
for (TInt i = 0; i < 2; i++)
{
w /= 2;
h /= 2;
}
 
SetUniqueHandle(EMyCueControl);
 
TRect rc_new(w, h, w+15, h+15);
SetRect(rc_new);
// begin by chen, code from William's post
// we need to set the display mode to ensure that it has an
// alpha-component specified. However, the system may instead return
// another display mode. We don't have to pay much attention, as the
// call to SetTransparencyAlphaChannel will check wether the Window
// Server and the window's display mode support this kind of
// transparency
Window().SetRequiredDisplayMode(EColor16MA);
TRgb backgroundColour = KRgbWhite; // for example
if(KErrNone == Window().SetTransparencyAlphaChannel())
{
// we now have a semi-transparent window,
// so we have to not clear the window region in an
// opaque colour before drawing it each time;
// 0 alpha is completely transparent,
// 255 alpha is completely opaque
backgroundColour.SetAlpha(0);
}
Window().SetBackgroundColor(backgroundColour);
// end by chen
ActivateL();
}

The code has been verified on S60 5th Edition emulator and a device that support EColor16MA, see the emulator screenshots (a transparent window with a red dot):

Semi-transparent03.PNG Semi-transparent04.PNG

The full example can be download: HelloWorld(Semi-transparent).zip

Version Hint

Windows Phone: [[Category:Windows Phone]]
[[Category:Windows Phone 7.5]]
[[Category:Windows Phone 8]]

Nokia Asha: [[Category:Nokia Asha]]
[[Category:Nokia Asha Platform 1.0]]

Series 40: [[Category:Series 40]]
[[Category:Series 40 1st Edition]] [[Category:Series 40 2nd Edition]]
[[Category:Series 40 3rd Edition (initial release)]] [[Category:Series 40 3rd Edition FP1]] [[Category:Series 40 3rd Edition FP2]]
[[Category:Series 40 5th Edition (initial release)]] [[Category:Series 40 5th Edition FP1]]
[[Category:Series 40 6th Edition (initial release)]] [[Category:Series 40 6th Edition FP1]] [[Category:Series 40 Developer Platform 1.0]] [[Category:Series 40 Developer Platform 1.1]] [[Category:Series 40 Developer Platform 2.0]]

Symbian: [[Category:Symbian]]
[[Category:S60 1st Edition]] [[Category:S60 2nd Edition (initial release)]] [[Category:S60 2nd Edition FP1]] [[Category:S60 2nd Edition FP2]] [[Category:S60 2nd Edition FP3]]
[[Category:S60 3rd Edition (initial release)]] [[Category:S60 3rd Edition FP1]] [[Category:S60 3rd Edition FP2]]
[[Category:S60 5th Edition]]
[[Category:Symbian^3]] [[Category:Symbian Anna]] [[Category:Nokia Belle]]

This page was last modified on 17 September 2012, at 07:27.
87 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.

×