How to retrieve a list of currently running tasks?
#include <apgtask.h> // link against apgrfx.lib
TApaTask taskInForeground = tasklist.FindByPos( 0 );
// Window Group ID of the foreground task
TInt WindowGroupIdentifier = taskInForeground.WgId();
// Thread ID of the foreground task
TThreadId ThreadIdentifier = taskInForeground.ThreadId();
The first task in TApaTaskList is the one in foreground (the associated window group has ordinal position 0).
TApaTask contains some information about the task. For example, the thread identifier (ThreadId()) and window group identifier (WgId()).
Furthermore, there are useful methods such as EndTask() that requests the task to close normally, and KillTask() that directly terminates the task. SendToBackground() and BringToForeground() can be used for controlling the application's position in the task list.