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.

如何创建半透明窗口

From Wiki
Jump to: navigation, search
Article Metadata

代码示例
兼容于
文章
翻译:
chenziteng
最后由 hamishwillee 在 14 Sep 2012 编辑

概述

本文描述了如何在支持EColor16MA显示模式的设备上创建半透明窗口。

前提条件

设备必须支持EColor16MA显示模式。使用以下代码可以检查设备支持的显示模式。

if(CCoeEnv::Static()->ScreenDevice()->DisplayMode()==EColor16MA)
{
// 支持EColor16MA
}

方案

本方案最初由william.edwards在UIQ论坛的"半透明窗口"系列文章中阐明 (UIQ论坛已经关闭,但仍然可以使用Google搜索"Semi-Transparent Windows #1"和"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();
}

该代码已经在S60第五版仿真器和一台支持EColor16MA显示模式的设备上验证通过, 以下是仿真器屏幕截图 (透明窗口上的红点):

Semi-transparent03.PNG Semi-transparent04.PNG

完整的示例程序: HelloWorld(Semi-transparent).zip

This page was last modified on 14 September 2012, at 06:02.
146 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.

×