13. 得到单击的listctrl的行列号
添加listctrl控件的NM_CLICK消息相应函数
void CTest6Dlg::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// 方法一:
/*
DWORD dwPos = GetMessagePos();
CPoint point( LOWORD(dwPos), HIWORD(dwPos) );
m_list.ScreenToClient(&point);
LVHITTESTINFO lvinfo;
lvinfo.pt = point;
lvinfo.flags = LVHT_ABOVE;
int nItem = m_list.SubItemHitTest(&lvinfo);
if(nItem != -1)
{
CString strtemp;
strtemp.Format("单击的是第%d行第%d列", lvinfo.iItem, lvinfo.iSubItem);
AfxMessageBox(strtemp);
}
*/
// 方法二:
/*
NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;
if(pNMListView->iItem != -1)
{
CString strtemp;
strtemp.Format("单击的是第%d行第%d列",
pNMListView->iItem, pNMListView->iSubItem);
AfxMessageBox(strtemp);
}
*/
*pResult = 0;
}
初始化
BOOL CTestDlg::::OnInitDialog()
{
.......
// TODO: Add extra initialization here
//设置标题栏
m_cResult.InsertColumn(0,"IP Address",LVCFMT_CENTER,100,-1);
m_cResult.InsertColumn(1,"Port Numbers",LVCFMT_CENTER,100,-1);
m_cResult.InsertColumn(2,"Port Status",LVCFMT_CENTER,100,-1);
m_cResult.InsertColumn(3,"Port Style",LVCFMT_CENTER,100,-1);
m_cResult.InsertColumn(4,"Remarks",LVCFMT_CENTER,80,-1);
//设置列表控件的风格
SetListCtrlStyle(&m_cResult);
m_cResult.SetBkColor(RGB(100,100,255));
}
void CTestDlg::SetListCtrlStyle(CListCtrl *pLstCtrl)
{
DWORD dwStyle = GetWindowLong(pLstCtrl->m_hWnd,GWL_STYLE);
dwStyle &=~(LVS_TYPEMASK);
dwStyle &=~(LVS_EDITLABELS);
SetWindowLong(pLstCtrl->m_hWnd,GWL_STYLE,dwStyle|LVS_REPORT|LVS_NOLABELWRAP|LVS_SHOWSELALWAYS);
DWORD styles = LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES;ListView_SetExtendedListViewStyleEx(pLstCtrl->m_hWnd,styles,styles);
}
插入数据
int nRow = m_cResult.InsertItem(0, "11");//插入行
m_cResult.SetItemText(nRow, 1, "jacky");//设置数据
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请
点击举报。