×
Namespaces

Variants
Actions

通过UID判断某个程序是否在前台运行

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
User:Davey 2 在 20 Dec 2007 创建
最后由 hamishwillee 在 15 Dec 2011 编辑

适用版本:

S60 2nd Edition, S60 3rd Edition


具体方案:


通过以下代码可以判断一个UID为KUidMyAppUid的程序是否运行在前台,若是返回ETrue,若否则返回EFalse。

TBool MyApplication::IsTaskInForegroundL()
{
RWsSession& wsSession = CEikonEnv::Static()->WsSession();
CArrayFixFlat<TInt>* wgIds = new (ELeave) CArrayFixFlat<TInt>(2);
CleanupStack::PushL(wgIds);
wsSession.WindowGroupList(0, wgIds);
TInt WgId = (*wgIds)[0];
CleanupStack::PopAndDestroy(); // wgIds

CApaWindowGroupName* wgn = CApaWindowGroupName::NewLC(wsSession, WgId);
TUid uid = wgn->AppUid();
CleanupStack::PopAndDestroy();

if (uid == KUidMyAppUid) // Put UID of your application.
return ETrue;
else
return EFalse;
}

This page was last modified on 15 December 2011, at 09:38.
153 page views in the last 30 days.
×