周星星 阅读(1762) 评论(1)

#pragma once
#include <atlbase.h>
#include <atlwin.h>

class CTest : public CDialogImpl<CTest>
{
public:
    enum { IDD = IDD_DIALOG1 };

    CTest()
    {
    }
    ~CTest()
    {
    }

    BEGIN_MSG_MAP(CTest)
        MESSAGE_HANDLER(WM_INITDIALOG, OnInitDialog)
        COMMAND_HANDLER(IDOK, BN_CLICKED, OnClickedOK)
        COMMAND_HANDLER(IDCANCEL, BN_CLICKED, OnClickedCancel)
        NOTIFY_HANDLER(IDC_LIST1, LVN_GETDISPINFO, OnLvnGetdispinfoList1)
        NOTIFY_HANDLER(IDC_LIST1, LVN_ITEMCHANGED, OnItemChangedList1)
//        CHAIN_MSG_MAP(CDialogImpl<CTest>)
    END_MSG_MAP()

    LRESULT OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
    {
        HWND hList = ::GetDlgItem(m_hWnd,IDC_LIST1);
        // LVS_OWNERDATA不支持动态切换,当OnInitDialog()被调用时,列表视控件已经建立了
        // ListView_SetExtendedListViewStyle( hList, ListView_GetExtendedListViewStyle(m_hList2)|LVS_OWNERDATA|LVS_REPORT );
       
        // 16H*32W
        HIMAGELIST hImageList = ImageList_LoadBitmap( ::GetModuleHandle(0),MAKEINTRESOURCE(IDB_BITMAP1), 16, 0, 0x00ffffff);
        ListView_SetImageList(hList, hImageList, LVSIL_SMALL);

        LVCOLUMN lvc;
        lvc.mask = LVCF_TEXT|LVCF_WIDTH;
        lvc.pszText = _T("Column1");
        lvc.cx = 100;
        ListView_InsertColumn(hList, 0, &lvc);

        lvc.mask = LVCF_TEXT|LVCF_WIDTH;
        lvc.pszText = _T("Column2");
        lvc.cx = 100;
        ListView_InsertColumn(hList, 1, &lvc);

        ListView_SetItemCount(hList,2);

        return 1;
    }

    LRESULT OnLvnGetdispinfoList1(int idCtrl, LPNMHDR pNMHDR, BOOL& bHandled)
    {
        NMLVDISPINFO* lpdi = reinterpret_cast<NMLVDISPINFO*>(pNMHDR);

        switch( lpdi->item.iItem )
        {
        case 0:
            switch( lpdi->item.iSubItem )
            {
            case 0:
                lpdi->item.pszText = _T("00");
                lpdi->item.iImage = 0;
                lpdi->item.iIndent = 1;
                break;
            case 1:
                lpdi->item.pszText = _T("01");
                break;
            }
            break;
        case 1:
            switch( lpdi->item.iSubItem )
            {
            case 0:
                lpdi->item.pszText = _T("10");
                lpdi->item.iImage = 1;
                lpdi->item.iIndent = 0;
                break;
            case 1:
                lpdi->item.pszText = _T("11");
                break;
            }
            break;
        }
       
        return 0;
    }

    LRESULT OnItemChangedList1(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
    {
        LPNMLISTVIEW pNMListView = reinterpret_cast<LPNMLISTVIEW>(pnmh);

        return 0;
    }

    LRESULT OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        EndDialog(wID);
        return 0;
    }

    LRESULT OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
    {
        EndDialog(wID);
        return 0;
    }
};


评论列表
布袋
re: ListCtrl OwnerData example
为什么现在才发现这篇文章55555555555

发表评论
切换编辑模式