首 页 | 新 闻 | Symbian | Android| Windows Mobile | J2ME | 下载中心 | 游戏策划招聘与求职 | 购书指南 | 视频教程
您现在的位置: 开发视界 >> Symbian英文资料 >> User Interface >> 正文
Moving an application to foreground / to background
作者:佚名    文章来源:不详    更新时间:2006-5-7 11:19:44

This article will show you how you can control the behaviour of your application so that it knows when it gains or looses the screen focus and how to control it.

Being notified of the focus change

The Series 60 framework will notify an application when it gains or looses the screen focus through a call to CAknAppUi::HandleForegroundEventL(TBool aForeground). The aForeground parameter equals ETrue when your app gains the screen focus, and EFalse when it looses it.

If you need to do some specific stuff, you should override this function (and call the base class implementation). Here is an example for an application that don’t want to loose the focus:


void CMyAppUi::HandleForegroundEventL(TBool aForeground)
{
 // Call Base class method
 CAknAppUi::HandleForegroundEventL(aForeground);

 if(aForeground)
 {
     // We have gained the focus
     ...
 }
 else
 {
     // We have lost the focus
     ...
 }
}

Changing the focus

You can also request to change the focus of your application. The commands are TApaTask::SendToBackground() and TApaTask::BringToForeground().

Here is how you can use them (from the AppUi):


void CMyAppUi::BringToForeground()
{
 // Construct en empty TApaTask object
 // giving it a reference to the Window Server session
 TApaTask task(iEikonEnv->WsSession( ));
               
 // Initialise the object with the window group id of
 // our application (so that it represent our app)
 task.SetWgId(CEikonEnv::Static()->RootWin().Identifier());

 // Request window server to bring our application
 // to foreground
 task.BringToForeground();
}

I never tested the following code, but you may be able to control the focus of other applications by using:


 // Bring the application "theApp" to background
 TApaTaskList tasklist(iCoeEnv->WsSession());
 TApaTask     task(tasklist.FindApp(_L("theApp")));
 task.SendToBackground();  // or BringToForeground()


Don’t forget to link against apgrfx.lib
相关文章:
Observer Pattern in Symbian application
Change the application language at runtime for Series 60 3rd Ed.
How to detect if an application is launched by user or the startup list
Tips & code samples for Sony Ericsson’s UIQ 3 based phones
Enable Skin support in your Symbian OS applications
My experiences making a Task Manager
How to let a DLL know which application uses it
Tracking down memory leaks
 

站点地图 | 加入收藏 | 联系站长 | 广告服务 |
QQ:280529124  Tel:0592-8271361 辽ICP备05021703号