如何设置一个ListCtrl每行(Item)的宽度? CListCtrl::SetColumnWidth只能设置列的宽度,我查了CListCtrl的成员函数,好像没有设置行的宽度的函数,本人才疏学浅,麻烦指点一下好吗? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void CWordListView::OnInitialUpdate() { CListCtrl& theCtrl = GetListCtrl(); long style=theCtrl.GetStyle(); style|=LVS_REPORT; ::SetWindowLong(theCtrl.m_hWnd,GWL_STYLE,style); theCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES); theCtrl.SetBkColor(RGB(207,226,248)); theCtrl.SetTextBkColor(RGB(207,226,248)); theCtrl.SetTextColor(RGB(0,0,255)); theCtrl.InsertColumn(0,_T("单词序号"),LVCFMT_LEFT,80); theCtrl.InsertColumn(1,_T("英语单词"),LVCFMT_LEFT,150); theCtrl.InsertColumn(2,_T("解释"),LVCFMT_LEFT,120); theCtrl.InsertColumn(3,_T("同义词"),LVCFMT_LEFT,100);} void CWordListView::OnInitialUpdate() { CListView::OnInitialUpdate(); CListCtrl& theCtrl = GetListCtrl(); long style=theCtrl.GetStyle(); style|=LVS_REPORT; ::SetWindowLong(theCtrl.m_hWnd,GWL_STYLE,style); theCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES); theCtrl.SetBkColor(RGB(207,226,248)); theCtrl.SetTextBkColor(RGB(207,226,248)); theCtrl.SetTextColor(RGB(0,0,255)); theCtrl.InsertColumn(0,_T("单词序号"),LVCFMT_LEFT,80); theCtrl.InsertColumn(1,_T("英语单词"),LVCFMT_LEFT,150); theCtrl.InsertColumn(2,_T("解释"),LVCFMT_LEFT,120); theCtrl.InsertColumn(3,_T("同义词"),LVCFMT_LEFT,100);} 在创建的时候使用insertcolumn()的最后一个参数制定列的宽度就行了 zsq202(棋棋)的问题描述的好象不大对,我估计你是问怎么设置行高吧?大概说来要设置行高是个很麻烦的问题,没有直接可用的函数,需要你自己写一个列表类,在其中自绘列表内容。大概要用到WM_MEASUREITEM这个消息,关于这个消息可以看http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/htm/cerefWM_MEASUREITEM.asp下面是MSDN给出的一个自绘列表简短例子http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listboxes/usinglistboxes.asp你只要将这句“lpmis->itemHeight = 20; ”的20在你自己写的重载类里设置的变量即可,然后在类里写个函数改变这个变量。这里有个自绘列表的例子http://www.vckbase.com/code/listcode.asp?mclsid=3&sclsid=323&page=2列表控件(视图)源代码:supergrid 详细信息 < 列表控件(视图) >可以参考一下,但这里面没有封装改变高度的函数,我自己的另一个例子封装大概函数有用的函数如下:void CGfxListCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct){ if (pCategoryManager) lpMeasureItemStruct->itemHeight = iItemHeightCategory;//17;iItemHeightCategory 是这个类的一个变量 else lpMeasureItemStruct->itemHeight = iItemHeight + iAutoPreviewHeight;//16;}void CGfxListCtrl::SetItemHeight(const int iHeight, const bool bCategory){ if (bCategory) iItemHeightCategory = iHeight;//iItemHeightCategory 是这个类的一个变量 else iItemHeight = iHeight; if (GetSafeHwnd()) { CRect rc; GetWindowRect( &rc ); WINDOWPOS wp; wp.hwnd = m_hWnd; wp.cx = rc.Width(); wp.cy = rc.Height(); wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER; SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp); }}如果还有什么问题可以给我发短消息! 是的,是我描述不够准确,我是想要设置每行的高度,昨晚我想了一想,用了一个比较简单的方法基本达到了目的,就是为ListCtrl创建一个ImageList,随便做一个16*16或24*24(别的也可以,视你每行的高度而定),这样行的高度就变了。感谢各位了!! 当然这样投机取巧的方法也还是行的通的的,但如果到时你的LISTCTRL要用IMAGELIST了那你就没辙了,所以最好还是写个重载类的好,这样的类很多代码网站都有的,功能也很全的 网络协议分析 ListBox如何置顶? 求解树节点刷新后不显示的问题? 在Vc下如何能做出漂亮的界面 请问如何把对话框CDialog内嵌到CWnd中 各位:QQ中多人聊天的原理是什么?等待讨论 为何在播放动画的时候,占用内存,但几乎不占用CPU?欢迎大家讨论!!! 急!急!有没有网络远程监控程序!分多多! 请帮忙,再线等待,高分赠送 哪有petzold的那本经典windows程序设计的中文电子版下? 怎么检测其它进程是否在运行? 谁有“对象的艺术” ( the art of objects) 这本书啊?
{
CListCtrl& theCtrl = GetListCtrl();
long style=theCtrl.GetStyle();
style|=LVS_REPORT;
::SetWindowLong(theCtrl.m_hWnd,GWL_STYLE,style);
theCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES);
theCtrl.SetBkColor(RGB(207,226,248));
theCtrl.SetTextBkColor(RGB(207,226,248));
theCtrl.SetTextColor(RGB(0,0,255));
theCtrl.InsertColumn(0,_T("单词序号"),LVCFMT_LEFT,80);
theCtrl.InsertColumn(1,_T("英语单词"),LVCFMT_LEFT,150);
theCtrl.InsertColumn(2,_T("解释"),LVCFMT_LEFT,120);
theCtrl.InsertColumn(3,_T("同义词"),LVCFMT_LEFT,100);
}
{
CListView::OnInitialUpdate();
CListCtrl& theCtrl = GetListCtrl();
long style=theCtrl.GetStyle();
style|=LVS_REPORT;
::SetWindowLong(theCtrl.m_hWnd,GWL_STYLE,style);
theCtrl.SetExtendedStyle(LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES);
theCtrl.SetBkColor(RGB(207,226,248));
theCtrl.SetTextBkColor(RGB(207,226,248));
theCtrl.SetTextColor(RGB(0,0,255));
theCtrl.InsertColumn(0,_T("单词序号"),LVCFMT_LEFT,80);
theCtrl.InsertColumn(1,_T("英语单词"),LVCFMT_LEFT,150);
theCtrl.InsertColumn(2,_T("解释"),LVCFMT_LEFT,120);
theCtrl.InsertColumn(3,_T("同义词"),LVCFMT_LEFT,100);
}
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wceui40/htm/cerefWM_MEASUREITEM.asp
下面是MSDN给出的一个自绘列表简短例子
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/commctls/listboxes/usinglistboxes.asp
你只要将这句“lpmis->itemHeight = 20; ”的20在你自己写的重载类里设置的变量即可,然后在类里写个函数改变这个变量。
这里有个自绘列表的例子http://www.vckbase.com/code/listcode.asp?mclsid=3&sclsid=323&page=2
列表控件(视图)源代码:supergrid 详细信息 < 列表控件(视图) >
可以参考一下,但这里面没有封装改变高度的函数,我自己的另一个例子封装大概函数有用的函数如下:
void CGfxListCtrl::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct)
{
if (pCategoryManager) lpMeasureItemStruct->itemHeight = iItemHeightCategory;//17;iItemHeightCategory 是这个类的一个变量
else lpMeasureItemStruct->itemHeight = iItemHeight + iAutoPreviewHeight;//16;
}void CGfxListCtrl::SetItemHeight(const int iHeight, const bool bCategory)
{
if (bCategory) iItemHeightCategory = iHeight;//iItemHeightCategory 是这个类的一个变量
else iItemHeight = iHeight; if (GetSafeHwnd())
{
CRect rc;
GetWindowRect( &rc );
WINDOWPOS wp;
wp.hwnd = m_hWnd;
wp.cx = rc.Width();
wp.cy = rc.Height();
wp.flags = SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOOWNERZORDER | SWP_NOZORDER;
SendMessage(WM_WINDOWPOSCHANGED, 0, (LPARAM)&wp);
}
}
如果还有什么问题可以给我发短消息!
感谢各位了!!