MiniGUI的mListView研究

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

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


一、  描述

MiniGUI的mListView研究_第1张图片

MiniGUI的mListView研究_第2张图片

二、  建立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

    {

        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

    {

        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

            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

        {

            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);


你可能感兴趣的:(coding,MiniGUI)