将当前程序的优先级调高
1. 定位当前程序,并将当前程序的优先级调高 SetOrdinalPosition
01.TInt prio = 1001; //设置一个较高的值
02.CEikonEnv::Static()->RootWin().SetOrdinalPosition(0, prio); //将当前程序的窗口组设计一个高的优先
级,并置为同级最前
2.将当前程序的窗口组设置为最前, 可与HandleForegroundEventL 配合使用,使当前程序使终处于最前(条件是优先
级要有足够高,否则的话还是会被优先级更高的程序抢占)
01.RWsSession ws = CEikonEnv::Static()->WsSession();
02.TApaTaskList tlist(ws);
03.TApaTask task = tlist.FindApp(KUidMyApp); //KUidMyApp 是指要调高优先级的程序的ID
02.task.BringToForeground();
3.模拟一个按键消息,并发向指定窗口组 SendEventToWindowGroup
01.RWsSession sess = CCoeEnv::Static() -> WsSession();
02.TWsEvent event;
03.TInt id = sess.FindWindowGroupIdentifier( 0, _L("*Phone?") ); //取得电话程序的窗口组
04.event.SetType(EEventKey);
05.event.SetTimeNow();
06.event.Key()->iCode = EKeyDownArrow; //模拟一个向下的箭头按键
07.event.Key()->iModifiers = 0;
08.event.Key()->iRepeats = 0;
09.event.Key()->iScanCode = EStdKeyNull;
10.sess.SendEventToWindowGroup( id, event); 将模拟的按键消息发给窗口组