列表框用法CAknSingleGraphicStyleListBox控件的用法

本文介绍如何在 Symbian 平台上使用 CAknSingleGraphicStyleListBox 创建带有图标和文本项的列表框,包括创建、配置、添加图标及文本列表等步骤。

CAknSingleGraphicStyleListBox


1.在头文件中定义:
    //列表框
    CAknSingleGraphicStyleListBox * iListBox;
    CDesCArrayFlat* iListBoxArray;

2.在.cpp文件ConstructL()中
    //创建列表
    iListBox = new (ELeave) CAknSingleGraphicStyleListBox(); //创建列表对象指针
    iListBox->SetContainerWindowL(*this);//设置容器窗口
    iListBox->ConstructL(this, EAknListBoxSelectionList);
    iListBox->SetExtent(TPoint(0, 0), TSize(aRect.Size().iWidth,
            aRect.Size().iHeight));
    //启动列表的滚动条
    iListBox->CreateScrollBarFrameL(ETrue);
    //关闭了水平的滚动条,垂直的滚动条设置为自动
    iListBox->ScrollBarFrame()->SetScrollBarVisibilityL(
            CEikScrollBarFrame::EOff, CEikScrollBarFrame::EAuto);

    //添加图标列表   
    CArrayPtr<CGulIcon>* icons = new (ELeave) CAknIconArray(2);
    CleanupStack::PushL(icons);
    _LIT(KBitmapPath,"//resource//apps//CallSecretary.mbm");
    TFileName bitmapFile(KBitmapPath);
    User::LeaveIfError(CompleteWithAppPath(bitmapFile));
    //选中
    icons ->AppendL(CEikonEnv::Static()->CreateIconL(bitmapFile,
            EMbmCallsecretaryTick001, EMbmCallsecretaryTick001_mask));
    //未选中
    icons ->AppendL(CEikonEnv::Static()->CreateIconL(bitmapFile,
            EMbmCallsecretaryNull, EMbmCallsecretaryNull_mask));
    CleanupStack::Pop();
    iListBox->ItemDrawer()->ColumnData()->SetIconArray(icons);

    //添加项目列表
    iListBoxArray = new (ELeave) CDesCArrayFlat(10);
    CTextListBoxModel* model = iListBox->Model();
    model->SetItemTextArray(iListBoxArray);
    model->SetOwnershipType(ELbmOwnsItemArray);



3.在析构函数中释放
    MEM_FREE(iListBox);
   
4.CountComponentControls()中
return 1;

5.ComponentControl()中
    switch (aIndex)
        {
        case 0:
            {
            return iListBox;
            }
        default:
            return NULL;
        }


6.OfferKeyEventL()中

    TKeyResponse ret(EKeyWasNotConsumed);
    if (iListBox)
        {
        ret = iListBox->OfferKeyEventL(aKeyEvent, aType);
        return ret;
        }
    return ret;

7.初始化记录
    //清空列表选项
    iListBoxArray->Reset();


    TBuf<32> sTmpBuf;
    sTmpBuf.Append(_L("0/t wangshenghu"));
    iListBoxArray->AppendL(sTmpBuf);
   
       
    if (0 <= nCur)
        iListBox->SetCurrentItemIndex(nCur);
    iListBox->HandleItemAdditionL();
    iListBox->DrawDeferred();

评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值