CListCtrl::SetColumnWidth只能设置列的宽度,我查了CListCtrl的成员函数,好像没有设置行的宽度的函数,本人才疏学浅,麻烦指点一下好吗?

解决方案 »

  1.   

    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);
    }
      

  2.   

    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);
    }
      

  3.   

    在创建的时候使用insertcolumn()的最后一个参数制定列的宽度就行了
      

  4.   

    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);
    }
    }
    如果还有什么问题可以给我发短消息!
      

  5.   

    是的,是我描述不够准确,我是想要设置每行的高度,昨晚我想了一想,用了一个比较简单的方法基本达到了目的,就是为ListCtrl创建一个ImageList,随便做一个16*16或24*24(别的也可以,视你每行的高度而定),这样行的高度就变了。
    感谢各位了!!
      

  6.   

    当然这样投机取巧的方法也还是行的通的的,但如果到时你的LISTCTRL要用IMAGELIST了那你就没辙了,所以最好还是写个重载类的好,这样的类很多代码网站都有的,功能也很全的