Symbian Special Interest Group

Sig Is symbian special interest Group

« Symbian落户中国How to prevent build-in camera application to be autolaunched »

How to check if an application is in fore/background in UIQ

As we know, S60 has a funtion called IsForeground() in CAknAppUiBase Class. But there's no equivalent in UIQ, so how to do this in UIQ? Here's  a possible solution.

TBool CForegroundAppUi::AppIsForground()
{
 TApaTaskList list( iEikonEnv->WsSession() );
 TApaTask app = list.FindByPos( 0 );
 
 TBool response;
 CApaWindowGroupName* wgName = CApaWindowGroupName::NewLC( iEikonEnv->WsSession(), app.WgId() );
 if ( wgName->AppUid().iUid == 0xe4414862 )   
// 0xe4414862 is the UID of the application
  response = ETrue;
 else
  response = EFalse;
 CleanupStack::PopAndDestroy( wgName );

 return response;
}

You can also use the thread id to do the same thing because TApaTask class has a function called ThreadId(). Give a try.

  • 相关文章:
  • quote 1.chenziteng
  • Why not override the HandleForegroundEventL()?
    ...
    class CForegroundAppUi : public CQikAppUi
    {
    ...

    public:
    TBool AppIsForground();

    private: // from CQikAppUi
    void HandleForegroundEventL(TBool aForeground);

    private:
    TBool iForeground;
    };

    TBool CForegroundAppUi::AppIsForground()
    {
    return iForeground;
    }

    void CForegroundAppUi::HandleForegroundEventL(TBool aForeground)
    {
    iForeground = aForeground;
    }

    or use:

    TBool CForegroundAppUi::AppIsForground()
    {
    return iCoeEnv->WsSession().GetFocusWindowGroup() == iCoeEnv->RootWin().Identifier();
    }
  • 2007-6-20 23:16:22
  • quote 2.Jimmy
  • I think we can't make sure when system will call HandleForegroundEventL(), sometimes this function will be called late.

    The second method is interesting.

    Thank you for your comments.
  • 2007-6-21 9:34:44

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

日历

最新留言

最近发表

Powered By Z-Blog 1.6 Final Build 60816

Copyright 2006-2007 SymbianSIG.com . All Rights Reserved.