Bring application to foreground with a keypress

本文介绍了一种方法,使应用程序能够在后台捕获按键事件,并通过按下特定按键(如'#'键)将应用程序从后台切换到前台。这种方法涉及设置应用程序为系统级应用、永久捕获指定按键、调整应用优先级等步骤。

 

Bring application to foreground with a keypress

From Forum Nokia Wiki

Inorder to capture the keys while you application under background you've to override CCoeAppUi::HandleWsEventL to your AppUi. With the use of RWindowGroup::CaptureKeyUpAndDowns() you can capture the keys from an application. Below is some sample code which will show you basically how to do it, you may found some additional bit of code which you may use.

 

The mmp file

CAPABILITY    

SwEvent

 

The header file

/**
  * To store the handle to the captured key.
  */

TInt iHashKeyHandle;

The cpp file

// -----------------------------------------------------------------------------


// CMyAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CMyAppUi:: ConstructL ()
    {
    BaseConstructL() ;
 
    // ...
 
    // set application as system application so that it will
    // not be closed by system events
     CEikonEnv:: Static () - > SetSystem( ETrue ) ;
 
    // capture hash '#' key permanently
    iHashKeyHandle = CEikonEnv:: Static () - > RootWin() .CaptureKeyUpAndDowns ( EStdKeyHash, 0, 0) ;
 
    // set application priority to foreground priority even if it goes to background
    CEikonEnv:: Static () - > WsSession() .ComputeMode ( RWsSession:: EPriorityControlDisabled ) ;
 
    // Make the application a high priority application
    CEikonEnv:: Static () - > RootWin() .EnableReceiptOfFocus ( ETrue ) ;
    CEikonEnv:: Static () - > RootWin() .SetOrdinalPosition ( 0, ECoeWinPriorityAlwaysAtFront) ;
    }
 
// -----------------------------------------------------------------------------
// CMyAppUi::~CMyAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CMyAppUi:: ~CMyAppUi()
    {
    // Release the hanlde to the captured key.
    CEikonEnv:: Static () - > RootWin() .CancelCaptureKeyUpAndDowns ( iHashKeyHandle) ;
 
    // ...
    }
 
// -----------------------------------------------------------------------------
// CMyAppUi::HandleForegroundEventL(TBool aForeground)
// Handles changes in keyboard focus when the application is brought to the
// foreground, or put into the background.
// -----------------------------------------------------------------------------
//
void CMyAppUi:: HandleForegroundEventL ( TBool aForeground)
    {
    // Make the application a high priority application
    if ( aForeground)
        {
        CEikonEnv:: Static () - > RootWin() .SetOrdinalPosition ( 0, ECoeWinPriorityAlwaysAtFront) ;
        }
    }
 
// -----------------------------------------------------------------------------
// CMyAppUi::HandleWsEventL (const TWsEvent &aEvent, CCoeControl *aDestination)
// Handles events sent to the application by the window server.
// -----------------------------------------------------------------------------
//
void CMyAppUi:: HandleWsEventL ( const TWsEvent & aEvent, CCoeControl * aDestination)
    {
    if ( aEvent.Type () == EEventKey ||
        aEvent.Type () == EEventKeyUp ||
        aEvent.Type () == EEventKeyDown ||
        aEvent.Type () == EEventKeyRepeat)
        {
        // This is for switching back to Application when Hash key is pressed
        if ( EStdKeyHash == aEvent.Key () - > iScanCode && EEventKey == aEvent.Type ())
            {
            TApaTask task( iEikonEnv- > WsSession()) ;
            task.SetWgId ( CEikonEnv:: Static () - > RootWin() .Identifier ()) ;
            task.BringToForeground () ;
 
            return ;
            }
        }
 
        CAknAppUi:: HandleWsEventL ( aEvent, aDestination) ;
    }

 

 

多源动态最优潮流的分布鲁棒优化方法(IEEE118节点)(Matlab代码实现)内容概要:本文介绍了基于Matlab代码实现的多源动态最优潮流的分布鲁棒优化方法,适用于IEEE118节点电力系统。该方法结合两阶段鲁棒模型与确定性模型,旨在应对电力系统中多源输入(如可再生能源)的不确定性,提升系统运行的安全性与经济性。文中详细阐述了分布鲁棒优化的建模思路,包括不确定性集合的构建、目标函数的设计以及约束条件的处理,并通过Matlab编程实现算法求解,提供了完整的仿真流程与结果分析。此外,文档还列举了大量相关电力系统优化研究案例,涵盖微电网调度、电动汽车集群并网、需求响应、储能配置等多个方向,展示了其在实际工程中的广泛应用价值。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事能源系统优化工作的工程师。; 使用场景及目标:①用于研究高比例可再生能源接入背景下电力系统的动态最优潮流问题;②支撑科研工作中对分布鲁棒优化模型的复现与改进;③为电力系统调度、规划及运行决策提供理论支持与仿真工具。; 阅读建议:建议读者结合提供的Matlab代码与IEEE118节点系统参数进行实操演练,深入理解分布鲁棒优化的建模逻辑与求解过程,同时可参考文中提及的其他优化案例拓展研究思路。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值