建立一对话框,加入列表控件,设置其变量为 m_ListView
BOOL CMy0000000000000Dlg::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 // TODO: Add extra initialization here m_ListView.SetExtendedStyle(LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES); int nItem = 0; m_ListView.InsertColumn(nItem++, "学号", LVCFMT_LEFT, 50); m_ListView.InsertColumn(nItem++, "姓名", LVCFMT_LEFT, 60); m_ListView.InsertColumn(nItem++, "姓别", LVCFMT_LEFT, 50); m_ListView.InsertColumn(nItem++, "专业", LVCFMT_LEFT, 70); m_ListView.InsertColumn(nItem++, "年级", LVCFMT_LEFT, 70); m_ListView.InsertColumn(nItem++, "班级", LVCFMT_LEFT, 70); for(int i=0; i<5; i++) { CString csTemp; csTemp.Format("学号%i", i); nItem = m_ListView.InsertItem(0xFFFFFF, csTemp); csTemp.Format("姓名%i", i); int nSub = 1; m_ListView.SetItem(nItem, nSub++, 1, csTemp, NULL, 0, 0, 0); csTemp.Format("男"); m_ListView.SetItem(nItem, nSub++, 1, csTemp, NULL, 0, 0, 0); csTemp.Format("专业%i", i); m_ListView.SetItem(nItem, nSub++, 1, csTemp, NULL, 0, 0, 0); csTemp.Format("年级%i", i); m_ListView.SetItem(nItem, nSub++, 1, csTemp, NULL, 0, 0, 0); csTemp.Format("班级%i", i); m_ListView.SetItem(nItem, nSub++, 1, csTemp, NULL, 0, 0, 0); } return TRUE; // return TRUE unless you set the focus to a control }
..................
对列表控件加入双击事件。 void CMy0000000000000Dlg::OnDblclkList1(NMHDR* pNMHDR, LRESULT* pResult) { // TODO: Add your control notification handler code here CString IP; int i=m_ListView.GetSelectionMark(); //将选择的项号赋予i if(i==-1) //i=-1表示没有选项 {
MessageBox("请选择IP!","没有选择项...",MB_OK|MB_ICONSTOP); return ; } else { IP=m_ListView.GetItemText(i,0); //0为要取值的列号 ::MessageBox(NULL,IP,"文件内容",0); } *pResult = 0; }
|