ListCtrl控件笔记

ExtendedStyle

 

m_list.SetExtendedStyle(m_list.GetExtendedStyle()|LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|);

 

InsertColumn插入列,实际就是加个列头

InsertItem加入一行,实际是加一行的第一列元素,可以设置很多属性,最重要的有个lparam

SetItemText设置一行中其它元素的值

 

单击列头排序

int CALLBACK CmpFunc(LPARAM lParam0, LPARAM lParam1, LPARAM lParam)
{
    CListCtrl *pList = (CListCtrl*)lParam;
    LVCOLUMN stCol;
    LVFINDINFO stFindInfo;
    int iFindItem;
    CString str0;
    CString str1;

    stFindInfo.flags = LVFI_PARAM;
    stFindInfo.lParam = lParam0;

    /* 根据参数lParam找到要排的行 */

    iFindItem = pList->FindItem(&stFindInfo);

    /* 获取要排的元素 */
    str0 = pList->GetItemText(iFindItem, g_curSelCol);

    stFindInfo.flags = LVFI_PARAM;
    stFindInfo.lParam = lParam1;
    iFindItem = pList->FindItem(&stFindInfo);
    str1 = pList->GetItemText(iFindItem, g_curSelCol);

 

    /* 根据列选择排序算法 */

    if (g_curSelCol == 0)
    {
        return iSortDir*strcmp(str0, str1);
    }
    else
    {
        return iSortDir*(atoi(str0) - atoi(str1));
    }


}

 

void ListView_SetHeaderSortImage(HWND listView, int columnIndex, BOOL isAscending)
{
    HWND header = ListView_GetHeader(listView);

    int columnCount = Header_GetItemCount(header);
    for (int i = 0; i<columnCount; i++)
    {
        HDITEM hi = {0};

        //I only need to retrieve the format if i'm on
        //windows xp. If not, then i need to retrieve
        //the bitmap also.
        hi.mask = HDI_FORMAT;

        Header_GetItem(header, i, &hi);

        //Set sort image to this column
        if(i == columnIndex)
        {
            //Windows xp has a easier way to show the sort order
            //in the header: i just have to set a flag and windows
            //will do the drawing. No windows xp, no easy way.
            hi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
            hi.fmt |= isAscending ? HDF_SORTUP : HDF_SORTDOWN;
        }
        //Remove sort image (if exists)
        //from other columns.
        else
        {
            hi.fmt &= ~(HDF_SORTDOWN|HDF_SORTUP);
        }

        Header_SetItem(header, i, &hi);
    }
}

 

void CAboutDlg::OnColumnclickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
     NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
     // TODO: Add your control notification handler code here

    /* 获取要排序的列编号 */

    g_curSelCol = pNMListView->iSubItem;

    /* 排序 */
    m_list.SortItems(CmpFunc, (DWORD_PTR)&m_list);

 

    ListView_SetHeaderSortImage(m_list.GetSafeHwnd(), g_curSelCol, iSortDir>0?TRUE:FALSE);

    iSortDir *= -1;

}

 

关于排序的箭头显示

http://www.winapizone.net/tutorials/winapi/listview/columnsortimage.php

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值