⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 focuseventappui.cpp

📁 用来学习 焦点 的 的例子,可以 好好看看焦点在 symbian中很重要,
💻 CPP
字号:
/*
* ==============================================================================
*  Name        : focuseventappui.cpp
*  Part of     : Focus event example
*  Interface   :
*  Description :
*  Version     :
*
*  Copyright (c) 2004 - 2006 Nokia Corporation.
*  This material, including documentation and any related
*  computer programs, is protected by copyright controlled by
*  Nokia Corporation.
* ==============================================================================
*/

// INCLUDE FILES
#include <avkon.hrh>
#include <aknnotewrappers.h>
#include <stringloader.h>
#include <FocusEvent.rsg>

#include "FocusEvent.pan"
#include "FocusEventAppUi.h"
#include "FocusEventAppView.h"
#include "capturingkeys.h"

// ============================ MEMBER FUNCTIONS ===============================

// -----------------------------------------------------------------------------
// CFocusEventAppUi::CFocusEventAppUi()
// C++ default constructor can NOT contain any code, that might leave.
// -----------------------------------------------------------------------------
//
CFocusEventAppUi::CFocusEventAppUi()
    {
    // No implementation required
    }

// -----------------------------------------------------------------------------
// CFocusEventAppUi::ConstructL()
// Symbian 2nd phase constructor can leave.
// -----------------------------------------------------------------------------
//
void CFocusEventAppUi::ConstructL()
    {
    BaseConstructL( EAknEnableSkin );

    iAppView = CFocusEventAppView::NewL( ClientRect() );
    AddToStackL( iAppView );
    
    SetKeyBlockMode( ENoKeyBlock );
    
    iEikonEnv->WsSession().SetKeyboardRepeatRate(
        TTimeIntervalMicroSeconds32(10000), 
        TTimeIntervalMicroSeconds32(10000));
    }


// -----------------------------------------------------------------------------
// CFocusEventAppUi::~CFocusEventAppUi()
// Destructor.
// -----------------------------------------------------------------------------
//
CFocusEventAppUi::~CFocusEventAppUi()
    {
    if ( iAppView )
        {
        iEikonEnv->RemoveFromStack( iAppView );
        delete iAppView;
        iAppView = NULL;
        }
    }

// -----------------------------------------------------------------------------
// CFocusEventAppUi::HandleCommandL()
// Takes care of key event handling.
// -----------------------------------------------------------------------------
//
void CFocusEventAppUi::HandleCommandL( TInt aCommand )
    {
    switch ( aCommand )
        {
    case EEikCmdExit:  
    case EAknSoftkeyExit:
        Exit();
        break;
        
    case EAknSoftkeyClear:
        iAppView->ClearTextOnScreen();
        break;

    default:
        Panic(EFocusEventBasicUi);
        break;
        }
    }

// -----------------------------------------------------------------------------
// CFocusEventAppUi::HandleForegroundEventL()
// Displays message every time focus is gained or lost.
// -----------------------------------------------------------------------------
//
void CFocusEventAppUi::HandleForegroundEventL( TBool aForeground )
    {
    if ( !aForeground ) // Focus lost
        {
        // Load a string from the resource file.
        HBufC* lostFocusMessage = StringLoader::LoadLC
                                  ( R_FOCU_LOST_FOCUS_TEXT );
#ifdef __WINS__
        User::InfoPrint( *lostFocusMessage );
#endif /* __WINS__ */
        iAppView->Print( *lostFocusMessage );
        iAppView->PrintNewLineL();
        // Pop HBuf from CleanupStack and destroy it.
        CleanupStack::PopAndDestroy( lostFocusMessage );
        
        iCaptureKey = CKeyCapturer::NewLC( *iAppView );
        
        }
        
    else // Focus gaind
        {
        if ( iCaptureKey )
            {
            CleanupStack::PopAndDestroy( iCaptureKey );
            }        
        
        // Load a string from the resource file.
        HBufC* gainedFocusMessage = StringLoader::LoadLC
                                    ( R_FOCU_GAINED_FOCUS_TEXT );
#ifdef __WINS__
        User::InfoPrint( *gainedFocusMessage );
#endif /* __WINS__ */
        iAppView->Print( *gainedFocusMessage );
        iAppView->PrintNewLineL();
        // Pop HBuf from CleanupStack and Destroy it.
        CleanupStack::PopAndDestroy( gainedFocusMessage );
        }

    CAknAppUi::HandleForegroundEventL( aForeground );
    }
    
// -----------------------------------------------------------------------------
// CFocusEventAppUi::BringToForeground()
// Bring UI to foreground
// -----------------------------------------------------------------------------
//
void CFocusEventAppUi::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();
}

// End of File

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -