MiniGUI的mListView研究

清理硬盘时发现有几篇2011年整理的博客躺在那里,删了怪可惜的,发上来保存一下~~

年代久远,已经过时,仅作参考用途~~~


一、  描述



二、  建立ListView

static BOOL Listview1_onCreate (mWidget* self, DWORD dwAddData)

{

int i;

NCS_LISTV_CLMINFO   lstv_clminfo;

    NCS_LISTV_ITEMINFO  lstv_iteminfo;

    HITEM hItem = 0;

    mListView * lstvObj = (mListView *)self;

    NCS_CB_LISTV_CMPCLM lstvcmp = cmp_callback;

 

    if(!lstvObj)

        return FALSE;

 

    //_c(lstvObj)->setAutoSortItem(lstvObj, TRUE);

    _c(lstvObj)->freeze(lstvObj, TRUE);

 

    for(i=0; i<COL_NR; i++)

    {

        lstv_clminfo.index = i;

        lstv_clminfo.text = caption[i];

        lstv_clminfo.width = 120;

        lstv_clminfo.pfnCmp = NULL;

        lstv_clminfo.flags = NCSF_LSTCLM_CENTERALIGN | NCSF_LSTHDR_CENTERALIGN;

        _c(lstvObj)->addColumn(lstvObj, &lstv_clminfo);

    }

 

    lstv_iteminfo.height = 25;

    lstv_iteminfo.flags = 0;

    lstv_iteminfo.foldIcon = 0;

    lstv_iteminfo.unfoldIcon = 0;

    lstv_iteminfo.parent = 0;

    for(i=0; i<USER_NR; i++)

    {

        lstv_iteminfo.index = i;

        hItem = addItem(lstvObj, &lstv_iteminfo);

    }

 

    _c(lstvObj)->sort(lstvObj, lstvcmp, 1, NCSID_LSTCLM_LOSORTED);

    _c(lstvObj)->freeze(lstvObj, FALSE);

 

         return TRUE;

}

三、  查询ListView

static BOOL listview1_on_sledit1_editchanged (mListView *self, mSlEdit* sender, int id, DWORD param)

{

    HITEM hItem = 0;

    char *strBuff = (char *)malloc(100*sizeof(char));

    int i = 0, n = _c(sender)->getContent(sender, strBuff, 100, 0, 100);    //输入的字符数

    NCS_LISTV_ITEMINFO  lstv_iteminfo;

    NCS_CB_LISTV_CMPCLM lstvcmp = cmp_callback;

 

    if(!_c(self)->removeAll(self))

        return FALSE;

 

    lstv_iteminfo.height = 25;

    lstv_iteminfo.flags = 0;

    lstv_iteminfo.foldIcon = 0;

    lstv_iteminfo.unfoldIcon = 0;

    lstv_iteminfo.parent = 0;

 

    if(n)

    {

        for(i=0; i<USER_NR; i++)

            if(!strncmp(user[i].name, strBuff, n))

            {

                printf("%s\n", user[i].name);

                lstv_iteminfo.index = i;

                hItem = addItem(self, &lstv_iteminfo);

            }

        hItem = _c(self)->getItem(self, 0);

        _c(self)->hilight(self, hItem);

    }

    else

    {

        lstv_iteminfo.height = 25;

        lstv_iteminfo.flags = 0;

        lstv_iteminfo.foldIcon = 0;

        lstv_iteminfo.unfoldIcon = 0;

        lstv_iteminfo.parent = 0;

        for(i=0; i<USER_NR; i++)

        {

            lstv_iteminfo.index = i;

            hItem = addItem(self, &lstv_iteminfo);

        }

    }

 

    _c(self)->sort(self, lstvcmp, 1, NCSID_LSTCLM_LOSORTED);

         return TRUE; /* allow the event to go next */

}

 

四、ListView排序

//排序的回调函数

int cmp_callback(HITEM hItem1, HITEM hItem2, NCS_LSTCLM_SORTDATA *sortData)

{

    const char * str1, * str2;

    sortData->column = 1;

    sortData->losorted = NCSID_LSTCLM_LOSORTED;

    mListView * col = (mListView *)sortData->obj;

    str1 = _c(col)->getText(col, hItem1);

    str2 = _c(col)->getText(col, hItem2);

    return strcmp(str1, str2);

}

 

_c(self)->sort(self, lstvcmp, 1, NCSID_LSTCLM_LOSORTED);


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值