《MFC ListControl控件用法.docx》由会员分享,可在线阅读,更多相关《MFC ListControl控件用法.docx(14页珍藏版)》请在优知文库上搜索。
1、IvColumn.pszText=JrFWName*);ttJlfl亮名)m_Storeltems.lnsertColumn(0,&lvC。IUmn);/MiD列,索引为0IvColumn.mask=1.VCF_FMT1.VCF,TEXT1.VCF_V/IDTH;IvCoIumnJmt=1.VCFMT1.EFT;IvCoIumnxx三100;IvColumn.pszText三.T(,Profession*);m_Storeltems.lnsertColumn(1.&lvColumn);IvColumn.mask=1.VCF_FMT1.VCF.TEXT1.VCF_WIDTH;IvCoIumnJm
2、t=1.VCFMT.1.EFT:IvCoIumnxx三80;IvColumn.pszText三.T(wFavSportn);m_Storeltems.lnsertColumn(2.&lvColumn);IvColumn.mask=1.VCF,FMT1.VCF_TEXT1.VCFjIDTH;IvCoIumnJmt=1.VCFMT_1.EFT;IvCoIumnxx三75;IvColumn.pszText=JrrHObby);m-Sloreltems.lnsenColumn(31&lvColumn);m_Storeltems.SetltemText(nltem,2t-T(HandBall,);m_S
3、toreltems.SetltemText(nltem.3.-T(Beach,);lvltm,mask=1.VIF,TEXT;lvltem.Htem三1;IvItemJSubUem三0;Ivltem.pszText三-T(RogerA.Miller);nltem三m_Storeltems.lnsertltem(&lvhem);m-Storltms.SetltemText(nltem.1._T(MFootballer);m-Storltms.SetltmText(nltem.2l-T(uTnnis);mStoreltems.SHllemTet(nltemt3lT(Toachirg);lvltem
4、.mask三1.VIF_TEXT;lvttem.Utem三2;IvhemJSubItem三0;Ivltem.pszText三.TCMarie-JuIieW.Gross);nltem三mStorellemsJnsertltem(lvltem);mStoreltems.SetltemText(nltemf1,.Tf*Studnt);m.Sloreltems.Sem_Storeltems.SetExtendedSty1e(1.VS_EX_FU1.1.ROWSE1.ECT);这禅盘中的时IMt是一行了,否。会是一格假如襄,多行选中的,Je可以用下面的代码,intnlndex:do(nlndex三m-S
5、toreltems.GetNextltem(-111.VN1.SE1.ECTED);m_Sloreltems.Deleteltem(nlndex);while(nlndex!三-1);这里IMQ一点Blt的,以下代码可供K(自CSDN),VOidCMy1.istView:AutoAdjustCoIumnWidthO(CHeaderCtrrpHeaderCtrl=m-p1.lstCtrl-GetHeaderCtr1();mp1.islCtrlSctRcGetltemCount();力婆栩RHRfor(inti0;IVnCoIUmnCOUnt;1*)(m_p1.istCtrl-SetColumnW
6、idth(i,1.VSCW_AUTOSIZE);intnColumnWidth=m-p1.istCtrkGetColumnWidth(i);IvColumn.mask三1.VCF_FMT1.VCF_TEXT1.VCFJVIDTH1.VCFJMAGE;IvColumn.fmt三1.VCFMT_1.EFT1.VCFMTJMAGE;IvCoIumnxx=120;IvColumn.pszText=-TFullNaEe)IvCoIumnJImage三O;m_Storeltems.lnsertColumn(OtAIvCoIumn);IvColumn.mask三1.VCF_FMT1.VCF_TEXT1.VC
7、F_V/IDTH;IvColumn.fmt三1.VCFM1.1.EFT:IvColumn.cx=100;IvColumn.pszText=T(wProfessk)n;m-Storeltems.lnserlColumn(1lAIvCoIumn);IvColumn.maskb1.VCF_FMT1.VCF_TEXT1.VCFjwIDTH1.VCFJMAGE;IvColumn.fmt=1.VCFMT_1.EFT1.VCFMTJMAGE;IvCoIumnJImage三1;IvCoIumnxx三80;IvColumn.pszText=_T(FavSport);m-SloreltemsJnseHColumn
8、(21AIvCoIumn);IvColumn.mask三三1.VCF_FMT1.VCF_TEXT1.VCF_V,DTH;IvColumn.fmt=1.VCFMT_1.EFT:IvColumn.cx三75;IvColumn.pszText=_TCHobby);m_Sloreltems.lnse11Column(3,&lvColumn);voidCDepartmentStoreDlg:SetViewType(DWORDdwViewType)DWORDdwCurTyp;HWNDhWnd;hWrdthmStoreitems;GetSafeHwndO;dwCurType三:GetWindow1.ong(
9、hWnd.GV/1._STY1.E);dwCurType&=-1.VS,TYPEMASK;dwViewType:=dwCurType;:SetWindow1.ong(hWnd,GW1.STY1.E,dwViewType);体上承加1.argc、Smalk1.ist、DcuiHsISjbutton,添加标点击,务的响应盘敷,如下.voidCDepartmentstoreDlgziOnBnCIicked1.argeO(/TODO:在Igto控件建知处程声代码SctViewTypcdVSICON);voidCDepartmentStoreDlg:OnBnClickedSmall()(/Todo:at
10、*tatt件知科if(GctViewTypeO!=1.VSSMA1.1.ICON)SetviewType(1.VS-SMA1.1.ICON);voidCDepartmentstoreDlgziOnBnCIickedDetaiK)/TODO:件H8Mt碍if(GctVicwTypeO!三1.VSREPORT)SetViewType(1.VS_REPORT);voidCDepartmentStoreDlg:OnBnClicked1.ist()/TODO:在此添加控件建知HaUF代码lf(GetViewTypeO!三1.VS_1.IST)SetViewType(1.VS.UST);体上的NeWMm按
11、IB用的体如下,用来添加皴,玲穹体制类,井的控件厚加相应如.Departmentstore-NewItem添加2个地图贵,H在为ID:IDB1.argingWeightz162Height:32,ID:IDBSmalllngWclght:80Height:16初妁化融敷代码,m_Storeltems.SetView(1.VS_REPORT):1.vcolumnIVCOlUmn;IvColumn.mask=1.VCF_FMT1.VCF_TEXT1.VCF_WIDTH;IvCoIumnJmt=1.VCFMTCENTER;IvCoIumnxx三60;IvColumn.pszText三_T(wltem
12、9,t);this-m_Storeltems.lnsertColumn0.&lvColumn);IvColumn.mask=1.VCF_FMT1.VCF.TEXTI1.VCF_V/IDTH;IvCoIumnJmt三1.VCFMT1.EFT;IvCoIumnxx三100;IvColumn.pszText三-T(wCategoryw);this-m_Storeltems.lnsertColumn(1,&lvColumn);IvColumn,mask=1.VCF_FMT1.VCF,TEXT1.VCF_WIDTH;IvCoIumnJmt=1.VCFMT1.EFT;IvCoIumnxx=160;IvCo
13、lumn.pszText三.T(11temName);this-m_Storeltems.lnsertColumn(2.&lvColumn);IvColumn.mask=1.VCF_FMT1.VCF,TEXT1.VCF_V/IDTH;IvCoIumnJmt=1.VCFMT_1.EFT;IvCoIumnxx=80;IvColumn.pszText三Jrc*S*);this-m-Storeltems.lnsertColumn(3.&lvColumn);IvColumn.mask三1.VCF_FMT1.VCF_TEXT1.VCFjWTH;IvCoIumnJmt=1.VCFMT_RIGHT;IvCoIumnxx三60;IvColumn.pszText三JrrUnItPrice);this-m_Storeltems.lnsertColumn(4,SIvCoIumn);IvColumn.mask=1