admin管理员组文章数量:1567541
2024年6月27日发(作者:)
自动调整ListCtrl的列的宽度
void CSortListCtrl::AutoSizeColumns(int col /*=-1*/,BOOL bFitWidth/*=F
ALSE*/)
{
// Call this after your list control is filled
if(!GetHeaderCtrl())return;
ShowWindow(SW_HIDE);//避免闪烁
SetRedraw(FALSE);
if(!bFitWidth)//如果不自动调整最后一列宽度,使得总列宽等于控件宽度,
InsertColumn(GetColumnCount(),"");
int mincol = col < 0 ? 0 : col;
int maxcol = col < 0 ? GetColumnCount()-1 : col;
for (col = mincol; col <= maxcol; col++) {
SetColumnWidth(col,LVSCW_AUTOSIZE);
int wc1 = GetColumnWidth(col);
SetColumnWidth(col,LVSCW_AUTOSIZE_USEHEADER);
int wc2 = GetColumnWidth(col);
int iFrom=GetTopIndex();
int nCountPerpage=GetCountPerPage();
if(nCountPerpage<=0)
nCountPerpage=GetItemCount();
int iTo=iFrom+nCountPerpage;
int nImgWidth=0;
int iIndent=0;
LVITEM li;
=LVIF_IMAGE|LVIF_INDENT;
IMAGEINFO ImageInfo;
for(int iItem=iFrom;iItem =iItem; GetItem(&li); iIndent=max(t,iIndent); if(!=-1){ CImageList* pImageList=GetImageList(LVSIL_SMALL); if(pImageList->GetSafeHandle()){ pImageList->GetImageInfo(,&ImageInfo); nImgWidth=max(nImgWidth, ); } } } int wc = max(20,max(wc1,wc2)); if(col==0) wc+=nImgWidth*(iIndent+1); else wc+=nImgWidth; SetColumnWidth(col,wc); } if(!bFitWidth) DeleteColumn(GetColumnCount()-1); SetRedraw(TRUE); ShowWindow(SW_SHOW); }
版权声明:本文标题:自动调整ListCtrl的列的宽度 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://www.elefans.com/xitong/1719487391a781276.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论