Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3348978
  • 博文数量: 1450
  • 博客积分: 11163
  • 博客等级: 上将
  • 技术积分: 11101
  • 用 户 组: 普通用户
  • 注册时间: 2005-07-25 14:40
文章分类

全部博文(1450)

文章存档

2017年(5)

2014年(2)

2013年(3)

2012年(35)

2011年(39)

2010年(88)

2009年(395)

2008年(382)

2007年(241)

2006年(246)

2005年(14)

分类: C/C++

2009-07-09 10:41:01

第一步, 
#include
#include "AppUi.h"

class CAknSingleNumberStyleListBox;
class CDesC16Array;

class CCallAppAppContainer : public CCoeControl, MCoeControlObserver
{
......
public:
TKeyResponse OfferKeyEventL(const TKeyEvent& aKeyEvent,                                                            TEventCode aType)
public:  
virtual void HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType);

private:
CAknSingleNumberStyleListBox *iListBox;
CDesC16Array *iItems;

};

第二步, 在控件构造函数中生成对象,并设置基本参数

void CContainer::ConstructL(const TRect& aRect)
{
    CreateWindowL();

     //生成对象
  iListBox = new( ELeave ) CAknSingleNumberStyleListBox();
iListBox->SetContainerWindowL( *this );
     iListBox->SetObserver(this);
iListBox->ConstructL( this, 
EAknListBoxSelectionList | EAknListBoxLoopScrolling );
   
//设置滚动条
    iListBox->CreateScrollBarFrameL(ETrue);
iListBox->ScrollBarFrame()
->SetScrollBarVisibilityL( 
CEikScrollBarFrame::EOff,CEikScrollBarFrame::EAuto );

  // Get the item list
     // listbox 中的数据项的数组
  iItems = static_cast
              (iListBox->Model()->ItemTextArray());

    SetRect(aRect);
    ActivateL();
}

void CCallAppAppContainer::HandleControlEventL(CCoeControl* aControl,TCoeEvent aEventType)
{
}

第三步,在适当的位置,添加数据项。

iItems->AppendL( _T("TTTTTT") );

TInt count = iItems->Count();
iListBox->HandleItemAdditionL();
iListBox->SetCurrentItemIndexAndDraw( count - 1 );

第四步,控制用户按键

TKeyResponse Container::OfferKeyEventL(const TKeyEvent& aKeyEvent,                                                            TEventCode aType)
{   
    if ( aType != EEventKey )
    {
     return EKeyWasNotConsumed;
    }
    switch ( aKeyEvent.iCode )
    {
    // Up & Down arrow key's event transfer to list box
    case EKeyUpArrow:
    case EKeyDownArrow:
        if ( iListBox )
        {
         return iListBox->OfferKeyEventL( aKeyEvent, aType );
        }
        break;
case EKeyLeftArrow:
case EKeyRightArrow:
return EKeyWasConsumed;
break;
case EKeyDelete:
case EKeyBackspace:
return EKeyWasConsumed;
break;
    default:
        break;
    }

    return EKeyWasNotConsumed;   
}

阅读(462) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~