ImageVerifierCode 换一换
格式:DOC , 页数:35 ,大小:207.50KB ,
资源ID:7983321      下载积分:10 金币
验证码下载
登录下载
邮箱/手机:
图形码:
验证码: 获取验证码
温馨提示:
支付成功后,系统会自动生成账号(用户名为邮箱或者手机号,密码是验证码),方便下次登录下载和查询订单;
特别说明:
请自助下载,系统不会自动发送文件的哦; 如果您已付费,想二次下载,请登录后访问:我的下载记录
支付方式: 支付宝    微信支付   
验证码:   换一换

开通VIP
 

温馨提示:由于个人手机设置不同,如果发现不能下载,请复制以下地址【https://www.zixin.com.cn/docdown/7983321.html】到电脑端继续下载(重复下载【60天内】不扣币)。

已注册用户请登录:
账号:
密码:
验证码:   换一换
  忘记密码?
三方登录: 微信登录   QQ登录  

开通VIP折扣优惠下载文档

            查看会员权益                  [ 下载后找不到文档?]

填表反馈(24小时):  下载求助     关注领币    退款申请

开具发票请登录PC端进行申请。


权利声明

1、咨信平台为文档C2C交易模式,即用户上传的文档直接被用户下载,收益归上传人(含作者)所有;本站仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。所展示的作品文档包括内容和图片全部来源于网络用户和作者上传投稿,我们不确定上传用户享有完全著作权,根据《信息网络传播权保护条例》,如果侵犯了您的版权、权益或隐私,请联系我们,核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
2、文档的总页数、文档格式和文档大小以系统显示为准(内容中显示的页数不一定正确),网站客服只以系统显示的页数、文件格式、文档大小作为仲裁依据,个别因单元格分列造成显示页码不一将协商解决,平台无法对文档的真实性、完整性、权威性、准确性、专业性及其观点立场做任何保证或承诺,下载前须认真查看,确认无误后再购买,务必慎重购买;若有违法违纪将进行移交司法处理,若涉侵权平台将进行基本处罚并下架。
3、本站所有内容均由用户上传,付费前请自行鉴别,如您付费,意味着您已接受本站规则且自行承担风险,本站不进行额外附加服务,虚拟产品一经售出概不退款(未进行购买下载可退充值款),文档一经付费(服务费)、不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
4、如你看到网页展示的文档有www.zixin.com.cn水印,是因预览和防盗链等技术需要对页面进行转换压缩成图而已,我们并不对上传的文档进行任何编辑或修改,文档下载后都不会有水印标识(原文档上传前个别存留的除外),下载后原文更清晰;试题试卷类文档,如果标题没有明确说明有答案则都视为没有答案,请知晓;PPT和DOC文档可被视为“模板”,允许上传人保留章节、目录结构的情况下删减部份的内容;PDF文档不管是原文档转换或图片扫描而得,本站不作要求视为允许,下载前可先查看【教您几个在下载文档中可以更好的避免被坑】。
5、本文档所展示的图片、画像、字体、音乐的版权可能需版权方额外授权,请谨慎使用;网站提供的党政主题相关内容(国旗、国徽、党徽--等)目的在于配合国家政策宣传,仅限个人学习分享使用,禁止用于任何广告和商用目的。
6、文档遇到问题,请及时联系平台进行协调解决,联系【微信客服】、【QQ客服】,若有其他问题请点击或扫码反馈【服务填表】;文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“【版权申诉】”,意见反馈和侵权处理邮箱:1219186828@qq.com;也可以拔打客服电话:4009-655-100;投诉/维权电话:18658249818。

注意事项

本文(ListCtrl控件使用方法及经验大全.doc)为本站上传会员【仙人****88】主动上传,咨信网仅是提供信息存储空间和展示预览,仅对用户上传内容的表现方式做保护处理,对上载内容不做任何修改或编辑。 若此文所含内容侵犯了您的版权或隐私,请立即通知咨信网(发送邮件至1219186828@qq.com、拔打电话4009-655-100或【 微信客服】、【 QQ客服】),核实后会尽快下架及时删除,并可随时和客服了解处理情况,尊重保护知识产权我们共同努力。
温馨提示:如果因为网速或其他原因下载失败请重新下载,重复下载【60天内】不扣币。 服务填表

ListCtrl控件使用方法及经验大全.doc

1、 本文全面介绍了如何编辑List Control里面的任何子项 介绍 内容有点多,译出来也没多大意思,大致就是说一个VC程序员会常常碰到List Control,List Control有很多方法可以显示数据,可List Control里默认的没有编辑功能,故在此智短文里,那个牛叉的人教你怎么实现这个功能。这篇文章是基于VC MFC滴,用别的功具的娃们当然也可以看看,呵呵,不多说,先实现图上ok exit两个按钮: void CMultipleColumnsDlg::OK() { CDialog::EndDialog (0); // Add this line

2、} void CMultipleColumnsDlg::OnExit() { CDialog::EndDialog (0); // Add this line } 接下来添加一个ListCtrl控件,记得把ListCtrl的style设置成Report,这个是为了实现我们要多行显示的功能 然后增加一个文本框Edit Box去掉它的Border style属性 增加一个InsertItems() 成员函数,用来写入ListControl的显示内容 void CMultipleColumnsDlg::InsertItems() { HWND hWnd = ::

3、GetDlgItem(m_hWnd, IDC_LIST1); // Set the LVCOLUMN structure with the required // column information LVCOLUMN list; list.mask = LVCF_TEXT |LVCF_WIDTH| LVCF_FMT |LVCF_SUBITEM; list.fmt = LVCFMT_LEFT; list.cx = 50; list.pszText = "S.No"; list.iSubIt

4、em = 0; //Inserts the column ::SendMessage(hWnd,LVM_INSERTCOLUMN, (WPARAM)0,(WPARAM)&list); list.cx = 100; list.pszText = "Name"; list.iSubItem = 1; ::SendMessage(hWnd ,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list); list.cx = 100; list.pszTe

5、xt = "Address"; list.iSubItem = 2; ::SendMessage(hWnd ,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list); list.cx = 100; list.pszText = "Country"; list.iSubItem = 2; ::SendMessage(hWnd ,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list); // Inserts first R

6、ow with four columns . SetCell(hWnd,"1",0,0); SetCell(hWnd,"Prabhakar",0,1); SetCell(hWnd,"Hyderabad",0,2); SetCell(hWnd,"India",0,3); // Inserts second Row with four columns . SetCell(hWnd,"2",1,0); SetCell(hWnd,"Uday",1,1); SetCell(hWnd,"Chennai",1,2);

7、 SetCell(hWnd,"India",1,3); } 自定义的SetCell( ) 函数,用来实现插入数据用的 void CMultipleColumnsDlg::SetCell(HWND hWnd1, CString value, int nRow, int nCol) { TCHAR szString [256]; wsprintf(szString,value ,0); //Fill the LVITEM structure with the //values given as parameters.

8、 LVITEM lvItem; lvItem.mask = LVIF_TEXT; lvItem.iItem = nRow; lvItem.pszText = szString; lvItem.iSubItem = nCol; if(nCol >0) //set the value of listItem ::SendMessage(hWnd1,LVM_SETITEM, (WPARAM)0,(WPARAM)&lvItem); else //Inse

9、rt the value into List ListView_InsertItem(hWnd1,&lvItem); } //通过行和列得到项目里面的数据 CString CMultipleColumnsDlg::GetItemText( HWND hWnd, int nItem, int nSubItem) const { LVITEM lvi; memset(&lvi, 0, sizeof(LVITEM)); lvi.iSubItem = nSubItem; CString str; int nLen

10、 128; int nRes; do { nLen *= 2; lvi.cchTextMax = nLen; lvi.pszText = str.GetBufferSetLength(nLen); nRes = (int)::SendMessage(hWnd, LVM_GETITEMTEXT, (WPARAM)nItem, (LPARAM)&lvi); str.ReleaseBuffer(); return str;

11、 } //为窗口类添加两个成员变量: int nItem, nSubItem; 用Class wizard 添加 NM_CLICK 响应 ,当用户点击任何位置时,就会对应出现一个Edit Box,并可以修改数据 void CMultipleColumnsDlg::OnClickList( NMHDR* pNMHDR, LRESULT* pResult) { Invalidate(); HWND hWnd1 = ::GetDlgItem (m_hWnd,IDC_LIST1); LPNMITEMACTIVATE temp = (LPNMI

12、TEMACTIVATE) 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

13、CString str = 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 listContr

14、ol ::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

15、x,rect.top+4, rect.right-rect.left - 3, rect.bottom-rect.top -1,NULL); ::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

16、left,rect.top-1,rect.right,rect.bottom); //Set the listItem text in the EditBox ::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),str); *pResult = 0; } To handle the ENTER key we need to write the virtual function OnOk (响应ENTER键) afx_msg void OnOK(); In MultipleColumnsDlg.cpp write

17、the following code. // This function handles the ENTER key void CMultipleColumnsDlg::OnOK() { CWnd* pwndCtrl = GetFocus(); // get the control ID which is // presently having the focus int ctrl_ID = pwndCtrl->GetDlgCtrlID(); CString str; switch (ctrl_ID) {

18、 //if the control is the EditBox case IDC_EDIT1: //get the text from the EditBox GetDlgItemText(IDC_EDIT1,str); //set the value in the listContorl with the //specified Item & SubItem values SetCell(::GetDlgItem (m_hWnd,IDC_LIST1),

19、 str,nItem,nSubItem); ::SendDlgItemMessage(m_hWnd,IDC_EDIT1, WM_KILLFOCUS,0,0); ::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1), SW_HIDE); break; default: break; } } 最后一步在OnInitDialog 中设置List Control的样式 ListView_

20、SetExtendedListViewStyle(::GetDlgItem (m_hWnd,IDC_LIST1),LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); InsertItems(); ::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_HIDE); Introduction Almost every one of us who are programming in VC++ , will come across the List control. There

21、are many cases where there is a need to represent data in List Control in multiple columns. By default it is not possible to modify the data in the List control itself. In this small article I am putting a simple way to edit any value in any column in a Report style List control. The logic here is s

22、imple, whenever user clicks on an sub-item which he wants to modify at that place I am displaying a edit box and allowing to modify the value. Once modified and by clicking the ENTER key, the updated value is set in the List control. Here I am assuming the user is familiar with VC++ and using Class

23、Wizard Implementation steps: 1. Using MFC AppWizard, create a Dialog Based application. Give the application name as MultipleColumns. By default the wizard adds OK and Cancel buttons to the Dialog, Remove these two buttons. 2. Now Add a List-Control and in properties change the style to Report,

24、 this style is necessary if we want multiple columns 3. Add two buttons to the Dialog and name them as OK and Exit 4. Add one Edit box and in the properties remove the Border style 5. Using the Class Wizard add the message handlers for the OK and Exit Buttons. Add the following code to those f

25、unctions Collapse Copy Code void CMultipleColumnsDlg::OK() { CDialog::EndDialog (0); // Add this line } Collapse Copy Code void CMultipleColumnsDlg::OnExit() { CDialog::EndDialog (0); // Add this line } 6. Add a function called InsertItems() to the CMulipleColumnsDlg cl

26、ass. Collapse Copy Code void InsertItems(); In the function handler add the following code Collapse Copy Code // This function inserts the default values // into the listControl void CMultipleColumnsDlg::InsertItems() { HWND hWnd = ::GetDlgItem(m_hWnd, IDC_LIST1); // Set t

27、he LVCOLUMN structure with the required // column information LVCOLUMN list; list.mask = LVCF_TEXT |LVCF_WIDTH| LVCF_FMT |LVCF_SUBITEM; list.fmt = LVCFMT_LEFT; list.cx = 50; list.pszText = "S.No"; list.iSubItem = 0; //Inserts the column

28、 ::SendMessage(hWnd,LVM_INSERTCOLUMN, (WPARAM)0,(WPARAM)&list); list.cx = 100; list.pszText = "Name"; list.iSubItem = 1; ::SendMessage(hWnd ,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list); list.cx = 100; list.pszText = "Address"; list.iSub

29、Item = 2; ::SendMessage(hWnd ,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list); list.cx = 100; list.pszText = "Country"; list.iSubItem = 2; ::SendMessage(hWnd ,LVM_INSERTCOLUMN, (WPARAM)1,(WPARAM)&list); // Inserts first Row with four columns .

30、 SetCell(hWnd,"1",0,0); SetCell(hWnd,"Prabhakar",0,1); SetCell(hWnd,"Hyderabad",0,2); SetCell(hWnd,"India",0,3); // Inserts second Row with four columns . SetCell(hWnd,"2",1,0); SetCell(hWnd,"Uday",1,1); SetCell(hWnd,"Chennai",1,2); SetCell(hWnd,"India

31、",1,3); // Inserts third Row with four columns . SetCell(hWnd,"3",2,0); SetCell(hWnd,"Saradhi",2,1); SetCell(hWnd,"Bangolore",2,2); SetCell(hWnd,"India",2,3); // Inserts fourth Row with four columns . SetCell(hWnd,"4",3,0); SetCell(hWnd,"Surya",3,1);

32、 SetCell(hWnd,"Calcutta",3,2); SetCell(hWnd,"India",3,3); } 7. Add another function called SetCell( ) to the CMultipleColumnsDlg class Collapse Copy Code void SetCell(HWND hWnd1, CString value, int nRow, int nCol); In the function handler add the following code Collapse Copy Code

33、// This function set the text in the specified // SubItem depending on the Row and Column values void CMultipleColumnsDlg::SetCell(HWND hWnd1, CString value, int nRow, int nCol) { TCHAR szString [256]; wsprintf(szString,value ,0); //Fill the LVITEM structure wi

34、th the //values given as parameters. LVITEM lvItem; lvItem.mask = LVIF_TEXT; lvItem.iItem = nRow; lvItem.pszText = szString; lvItem.iSubItem = nCol; if(nCol >0) //set the value of listItem ::SendMessage(hWnd1,LVM_SETITEM, (WPA

35、RAM)0,(WPARAM)&lvItem); else //Insert the value into List ListView_InsertItem(hWnd1,&lvItem); } 8. Add one more function called GetItemText() to the same Class Collapse Copy Code CString GetItemText(HWND hWnd, int nItem, int nSubItem) const; Inside the function add t

36、he following code Collapse Copy Code //this function will returns the item //text depending on the item and SubItem Index CString CMultipleColumnsDlg::GetItemText( HWND hWnd, int nItem, int nSubItem) const { LVITEM lvi; memset(&lvi, 0, sizeof(LVITEM)); lvi.iSubItem = n

37、SubItem; 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);

38、 str.ReleaseBuffer(); return str; } 9. Also add two member variables to the CMultipleColumnsDlg class which are of type int Collapse Copy Code int nItem, nSubItem; 10. From the Class wizard add NM_CLICK notification to the List control. Inside the function handler write the following c

39、ode Collapse Copy Code //This function Displays an EditBox at the position //where user clicks on a particular SubItem with //Rectangle are equal to the SubItem, thus allows to //modify the value void CMultipleColumnsDlg::OnClickList( NMHDR* pNMHDR, LRESULT* pResult) { Inva

40、lidate(); 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 == -

41、1) return ; //Retrieve the text of the selected subItem //from the list CString str = GetItemText(hWnd1,nItem , nSubItem); RECT rect1,rect2; // this macro is used to retrieve the Rectanle // of the selected SubItem ListView_GetSubItemRect(hWnd

42、1,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;

43、 if(nItem != -1) ::SetWindowPos(::GetDlgItem(m_hWnd,IDC_EDIT1), HWND_TOP,rect.left+x,rect.top+4, rect.right-rect.left - 3, rect.bottom-rect.top -1,NULL); ::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_SHOW); ::SetFocus(::GetDlgItem(m_hWnd,IDC_EDIT1));

44、 //Draw a Rectangle around the SubItem ::Rectangle(::GetDC(temp->hdr.hwndFrom), rect.left,rect.top-1,rect.right,rect.bottom); //Set the listItem text in the EditBox ::SetWindowText(::GetDlgItem(m_hWnd,IDC_EDIT1),str); *pResult = 0; } 11. To handle the ENTER key w

45、e need to write the virtual function OnOk in the MultipleColumnsDlg.h, so add the following as protected member Collapse Copy Code afx_msg void OnOK(); In MultipleColumnsDlg.cpp write the following code. Collapse Copy Code // This function handles the ENTER key void CMultipleColumnsDlg::OnO

46、K() { CWnd* pwndCtrl = GetFocus(); // get the control ID which is // presently having the focus int ctrl_ID = pwndCtrl->GetDlgCtrlID(); CString str; switch (ctrl_ID) { //if the control is the EditBox case IDC_EDIT1: //get the text from th

47、e EditBox GetDlgItemText(IDC_EDIT1,str); //set the value in the listContorl with the //specified Item & SubItem values SetCell(::GetDlgItem (m_hWnd,IDC_LIST1), str,nItem,nSubItem); ::SendDlgItemMessage(m_hWnd,IDC_EDIT1, WM_KI

48、LLFOCUS,0,0); ::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1), SW_HIDE); break; default: break; } } 12. The last step in the implementation is add the following code in side the OnInitDialog function Collapse Copy Code //Set th

49、e style to listControl ListView_SetExtendedListViewStyle(::GetDlgItem (m_hWnd,IDC_LIST1),LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES); InsertItems(); ::ShowWindow(::GetDlgItem(m_hWnd,IDC_EDIT1),SW_HIDE); VC/MFC之ListCtrl控件使用经验总结 以下未经说明,listctrl默认view 风格为report 相关类及处理函数 M

50、FC:CListCtrl类 SDK:以 “ListView_”开头的一些宏。如 ListView_InsertColumn -------------------------------------------------------------------------------- 1. CListCtrl 风格       LVS_ICON: 为每个item显示大图标       LVS_SMALLICON: 为每个item显示小图标       LVS_LIST: 显示一列带有小图标的item       LVS_REPORT: 显示item详细资料       直观的理

移动网页_全站_页脚广告1

关于我们      便捷服务       自信AI       AI导航        抽奖活动

©2010-2025 宁波自信网络信息技术有限公司  版权所有

客服电话:4009-655-100  投诉/维权电话:18658249818

gongan.png浙公网安备33021202000488号   

icp.png浙ICP备2021020529号-1  |  浙B2-20240490  

关注我们 :微信公众号    抖音    微博    LOFTER 

客服