ListCtrl设置可写

<textarea cols="50" rows="15" name="code" class="cpp">// MyListCtrl.cpp : 实现文件 // #include "stdafx.h" #include "EditListCtrl.h" #include "MyListCtrl.h" // CMyListCtrl IMPLEMENT_DYNAMIC(CMyListCtrl, CListCtrl) CMyListCtrl::CMyListCtrl() { } CMyListCtrl::~CMyListCtrl() { } BEGIN_MESSAGE_MAP(CMyListCtrl, CListCtrl) ON_WM_LBUTTONDOWN() ON_NOTIFY_REFLECT(LVN_ENDLABELEDIT, &amp;CMyListCtrl::OnLvnEndlabeledit) END_MESSAGE_MAP() // CMyListCtrl 消息处理程序 void CMyListCtrl::PreSubclassWindow() { // TODO: 在此添加专用代码和/或调用基类 CListCtrl::PreSubclassWindow(); ModifyStyle(0, LVS_EDITLABELS); } void CMyListCtrl::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: 在此添加消息处理程序代码和/或调用默认值 LVHITTESTINFO lvhit; lvhit.pt = point; int item = SubItemHitTest(&amp;lvhit); //if (over a item/subitem) if (item != -1 &amp;&amp; (lvhit.flags &amp; LVHT_ONITEM)) { //CListCtrl::OnLButtonDown(nFlags, point); EditLabel(lvhit.iItem); } } void CMyListCtrl::OnLvnEndlabeledit(NMHDR *pNMHDR, LRESULT *pResult) { NMLVDISPINFO *pDispInfo = reinterpret_cast&lt;NMLVDISPINFO*&gt;(pNMHDR); // TODO: 在此添加控件通知处理程序代码 LV_ITEM *plvItem = &amp;pDispInfo-&gt;item; if (plvItem-&gt;pszText != NULL ) { SetItemText(plvItem-&gt;iItem, plvItem-&gt;iItem, plvItem-&gt;pszText); } //VERIFY(m_edtItemEdit.UnsubclassWindow()!=NULL); *pResult = 0; } </textarea>

首先用ModifyStyle(0, LVS_EDITLABELS);设置为可写

然后在OnLButtonDown里面调用EditLabel(lvhit.iItem);

EditLabel(lvhit.iItem);会发送WM_LABLEEDIT消息

最后编辑完成后会发送LVN_ENDLABELEDIT

这个消息是一个反射消息,只要在消息响应函数中改变内容即可

 

你可能感兴趣的:(null)