2009-04-03 06:56 745人阅读 评论(0) 收藏 举报
网上关于在CListCtrl控件里面点击直接修改值的东西比较少,其实是个很简单的东西,知识不太容易想到!在这里将代码写下!
void CAdminDialog::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
Invalidate();
HWND hWnd1 = ::GetDlgItem(m_hWnd,IDC_LIST1);
LPNMITEMACTIVATE temp = (LPNMITEMACTIVATE) pNMHDR;
RECT rect;
//get the row number
nItem = temp->iItem;
//get the column number
nSubItem = temp->iSubItem;
if(nSubItem == 0 || nSubItem == -1 || nItem == -1)
return ;
//Retrieve the text of the selected subItem from the list
str1 = GetItemText(hWnd1,nItem ,nSubItem);
RECT rect1,rect2;
// this macro is used to retrieve the Rectanle of the selected SubItem
ListView_GetSubItemRect(hWnd1,temp->iItem,temp->iSubItem,LVIR_BOUNDS,&rect);
//Get the Rectange of the listControl
::GetWindowRect(temp->hdr.hwndFrom,&rect1);
//Get the Rectange of the Dialog
::GetWindowRect(m_hWnd,&rect2);
int x=rect1.left-rect2.left;
int y=rect1.top-rect2.top;
if(nItem != -1)
::SetWindowPos(::GetDlgItem(m_hWnd,IDC_EDIT1),HWND_TOP,rect.left + x,rect.top + y,rect.right-rect.left,rect.bottom-rect.top,NULL);
//GetDlgItem(IDC_EDIT1)->SetWindowText(str1);//°ÑEditµÄ¿Ø¼þÖµÉèΪCListCtrlÀïÃæµÄÖµ
m_List.SetItemText(nItem,nSubItem,"");//½«CListCtrlÀïÃæµÃÖµÉèÖóɲ»¿É¼ûµÄ
::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_SHOW);
::SetFocus(::GetDlgItem(m_hWnd,IDC_EDIT1));
//Draw a Rectangle around the SubItem
::Rectangle(::GetDC(temp->hdr.hwndFrom),rect.left + x,rect.top,rect.right,rect.bottom);
GetDlgItem(IDC_EDIT1)->GetWindowText(str1);//µÃµ½Ð޸ĺóµÄÖµ£¬ÒÔ·½±ãÈ·¶¨Ð޸ĺ󽫴ËÖµÖ±½Óдµ½CListCtrlÉÏ
//Set the listItem text in the EditBox
//::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),str1);
*pResult = 0;
}
CString CAdminDialog::GetItemText(HWND hWnd, int nItem, int nSubItem) const
{
LVITEM lvi;
memset(&lvi, 0, sizeof(LVITEM));
lvi.iSubItem = nSubItem;
CString str;
int nLen = 128;
int nRes;
do
{
nLen *= 2;
lvi.cchTextMax = nLen;
lvi.pszText = str.GetBufferSetLength(nLen);
nRes = (int)::SendMessage(hWnd, LVM_GETITEMTEXT, (WPARAM)nItem,
(LPARAM)&lvi);
} while (nRes == nLen-1);
str.ReleaseBuffer();
return str;
}
void CAdminDialog::OnChange()
{
// TODO: Add your control notification handler code here
//::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),str1);
GetDlgItem(IDC_EDIT1)->GetWindowText(str1);//µÃµ½EditÀïÃæµÄÄÚÈÝ
m_List.SetItemText(nItem,nSubItem,str1);//½«EditÀïÃæµÄֵдµ½CListCtrl¿Ø¼þÀïÃæÈ¥
//delete GetDlgItem(IDC_EDIT1);
GetDlgItem(IDC_EDIT1)->SetWindowText("");//Òª½«EditµÄÎı¾ÉèÖóɿգ¬²»È»ÔÙ´ÎÏÔʾEditµÄʱºò»áÒ²ÏÔʾÉÏ´ÎÐ޸ĵÄÖµ
GetDlgItem(IDC_EDIT1)->ShowWindow(SW_HIDE);//ÒªÒþ²Ø£¬²»ÒªÉ¾³ý£¬ÒòΪɾ³ýÒÑÓÐÔٴε¥»÷µÄʱºò¾Í»á³ö´í
}
分享到:
相关推荐
visual c++改变CListCtrl控件中滚动条的颜色
包含19个CListCtrl控件相关代码,可以实现控件的各类编辑与操作方式,可以为你提供借鉴!
VC 界面clistctrl控件的重绘 适合初学者
CListCtrl控件使用方法总结
VC++ CListCtrl 控件 行高 编辑通过
实现CListCtrl控件的Item项拖拽效果,本源码对应的博客链接为:http://blog.csdn.net/d704791892/article/details/22600075
listCtrl控件可编辑,即双击单元格,可填入相应内容
VC_CListCtrl使用方法,我是在MFC的对话框模式下使用CListCtrl控件的,其实不管在SDK或文档/视图模式下,VC控件的使用都差不多,下面来好好的写写CListCtrl控件的使用笔记。
CListCtrl控件的简单使用,和登录过程实现
此工程演示了如何在列表框控件中添加复选框,并实现了全选按钮操作,相信很多应用软件中都会需要,对于初学者有很大的帮助
Visual C++ 6.0 编写。 1。控件CListCtrl的用法示例。包括他的四种风格:图标、小图标、列表、详细资料的示例程序。是学习ClistCtrl控件的绝对好资料。 2。右键菜单,在CListCtrl中演示右键菜单功能。
摘要:VC/C++源码,控件相关,CListCtrl vc设置CListCtrl控件背景为渐变色,看上去更漂亮的CListCtrl控件了,每一格的行背景色都是渐变彩色的,颜色不满意的话,可自己调,源码文件分享给大家。
非常好用的扩展风格的Clistctrl控件,VC6.0和VS2005实例,附可重用类库
VC 扩展型CListCtrl列表控件,支持双击鼠标实现编辑主项(Item),也可以编辑子项(SubItem),并尽量符合CListCtrl的操作习惯,目前好像很多控件都有这功能的,应该加入这个实用的功能。
本文简单介绍下VC列表控件的点击事件。博客地址:http://blog.csdn.net/bingdianlanxin,有问题欢迎留言!
本资源讲述如何在VC++的CListCtrl控件中多选择项的删除
VC 轻松实现鼠标拖动控件边框改变其大小 根本不需要响应什么LButtonDown之类的
从网上下载的一个CTreeCtrl和CListCtrl结合的控件,刚开始,该控件不具备draging功能,经我改良后,具备了。该控件使用dll封装,调用十分容易。值得推广,也欢迎交流。这个控件类似于VC6.0调试时下面出现的那个Watch...