Following GetTasksL()-function illustrates how to get all running GUI application and their information. Note that if you are running this inside a application that is not implementing standard application framework, you have the replace the RWsSession handling.
If you are interested on finding other than GUI tasks, you could utilize the process finding example code better.
void GetTasksL(void)
{
RWsSession& wsSession = CEikonEnv::Static()->WsSession();
CApaWindowGroupName* wgName=CApaWindowGroupName::NewL(wsSession);
CleanupStack::PushL(wgName);
CArrayFixFlat<TInt>* WindowGroupIds = new(ELeave)CArrayFixFlat<TInt>(1);
CleanupStack::PushL(WindowGroupIds);
User::LeaveIfError(wsSession.WindowGroupList(0,WindowGroupIds));
const TInt count = WindowGroupIds->Count();
for (TInt ii=0; ii<count; ii++)
{
TInt wgId = WindowGroupIds->At(ii);
wgName->ConstructFromWgIdL(wgId);
//wgName->Caption()
//wgName->AppUid().Name()
//wgName->Hidden()
//wgName->IsSystem()
//wgName->IsBusy()
//wgName->AppUid()
}
CleanupStack::PopAndDestroy(2);//WindowGroupIds, wgName
}
Then if you are interested to find just one specific task, and you know the application UID you could also use the code shown in the following example function:
void DoSomethingWithTaskL(TUid aUid)
{
RWsSession& wsSession = CEikonEnv::Static()->WsSession();
TApaTaskList taskList( wsSession );
TApaTask task = taskList.FindApp(aUid);
if( task.Exists() )
{
task.EndTask();
//task.KillTask();
//task.SendSystemEvent(EApaSystemEventShutdown);
//task.BringToForeground();
//task.SendToBackground();
//RThread th;
//if (t.Open(task.ThreadId())==KErrNone)
//{
// th.Kill(0);
// th.Close();
//}
}
}
The DoSomethingWithTaskL() example function shows different approaches you could use for closing GUI application from other processes, note that in S60 3rd Edition some of the ways might require some capabilities. Also the nicest way is always to ask nicely, thus the EndTask() should nearly always be used, it basically sends the exit command to the application, so the application to be closed can handle its data saving etc. when exiting.
// Constant the UID of the application that we are trying to find.
const TUid KMyAppUid = {0x10009e9f};
// Gets a reference to a window server session
TApaTaskList taskList(CCoeEnv::Static()->WsSession());
// Create TApaTask instance
TApaTask task = taskList.FindApp(KMyAppUid);
if (task.Exists())
{
// Do Something
}
The following libraries need to be added in the MMP configuration file. apgrfx.lib, ws32.lib
No related wiki articles found