上一篇 | 下一篇

CListCtrl 使用演示的例子

发布: 2008-6-26 14:30 | 作者: admin | 来源: | 查看: 16次

下载本文所附源代码

BOOL CLCDemoDlg::OnInitDialog()

{

CDialog::OnInitDialog();

// Add "About..." menu item to system menu.

// IDM_ABOUTBOX must be in the system command range.

ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);

ASSERT(IDM_ABOUTBOX < 0xF000);

CMenu* pSysMenu = GetSystemMenu(FALSE);

if (pSysMenu != NULL)

{

CString strAboutMenu;

strAboutMenu.LoadString(IDS_ABOUTBOX);

if (!strAboutMenu.IsEmpty())

{

pSysMenu->AppendMenu(MF_SEPARATOR);

pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);

}

}

// Set the icon for this dialog. The framework does this automatically

// when the application's main window is not a dialog

SetIcon(m_hIcon, TRUE); // Set big icon

SetIcon(m_hIcon, FALSE); // Set small icon

m_imagelist.Create(16,16,TRUE,2,2);

m_imagelist.Add(AfxGetApp()->LoadIcon(IDI_ICON2));

m_list.SetImageList(&m_imagelist,LVSIL_SMALL);

m_font.CreateFont(16, 0,0,0,FW_NORMAL, 0,0,0,

DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,

DEFAULT_QUAL99vY, DEFAULT_P99vCH | FF_DONTCARE, "Arial");

m_list.SetFont(&m_font);

/*-----------------------------------------------------------*/

m_list.SetExtendedStyle(LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES);

m_list.SetBkColor(RGB(247,247,255));

m_list.SetTextColor(RGB(0,0,255));

m_list.SetTextBkColor(RGB(247,247,255));

m_list.InsertColumn(0, "学号", LVCFMT_LEFT, 110);

m_list.InsertColumn(1, "姓名", LVCFMT_LEFT, 130);

m_list.InsertColumn(2, "成绩", LVCFMT_LEFT, 47);

m_list.InsertItem(0,"2002112105");

m_list.SetItemText(0,1,"程红秀");

m_list.SetItemText(0,2,"96");

m_list.InsertItem(1,"2002112126");

m_list.SetItemText(1,1,"符中辉");

m_list.SetItemText(1,2,"85");

m_list.InsertItem(2,"2002112125");

m_list.SetItemText(2,1,"王斌年");

m_list.SetItemText(2,2,"95");

m_list.InsertItem(3,"2002112103");

m_list.SetItemText(3,1,"袁浩");

m_list.SetItemText(3,2,"92");

return TRUE; // return TRUE unless you set the focus to a control

}

void CLCDemoDlg::OnClickList(NMHDR* pNMHDR, LRESULT* pResult)

{

POS99vION pos = m_list.GetFirstSelectedItemPosition();

m_nIndex = m_list.GetNextSelectedItem(pos); // 得到项目索引

*pResult = 0;

}

字号: | 推荐给好友

41/41234>

评分:0

我来说两句