本帖最后由 yimenggushang 于 2012-07-31 17:15:06 编辑

解决方案 »

  1.   

    · LBS_EXTENDEDSEL 用户可以通过鼠标和SHIFT键或者其它特殊键组合来选取多个项。  
    · LBS_HASSTRINGS 指定自画列表框中包含的项是由字符串组成的。列表框维护着字符串的内存和指针,应用程序可以使用GetText成员函数来获得特定项的文本。  
    · LBS_MULTICOLUMN 指定一个可以水平滚动的多列列表框。SetColumnWidth成员函数设置列的宽度。  
    · LBS_MULTIPLESEL 当用户单击或双击字符串时,切换字符串的选择状态。可以选择任意数目的字符串。  
    · LBS_NOINTEGRALHEIGHT 列表框的大小与应用程序创建它的时候指定的大小完全相等。通常,Windows会调整列表框的大小,是列表框不会只显示部分项。  
    · LBS_NOREDRAW 当列表框发生变化时不更新显示。这个风格可以通过发送WM_SETREDRAW消息在任何时间改变。  
    · LBS_NOTIFY 当用户单击或双击字符串时,父窗口接收到一个输入消息。  
    · LBS_OWNERDRAWFIXED 列表框的所有者负责画出它的内容,列表框中的各项是等高的。  
    · LBS_OWNERDRAWVARIABLE 列表框的所有者负责画出其内容,列表框中的各项的高度不相同。  
    · LBS_SORT 列表框中的字符串是按照字母表顺序排列的。  
    · LBS_STANDARD 列表框中的字符串是按照字母表顺序排序的,当用户单击或双击字符串时,父窗口接收到一个输入消息。列表框在每条边上都有边界。  
    · LBS_USETABSTOPS 允许列表框在显示字符串的时候识别并扩展制表字符。缺省的制表位置是32个对话框单位。(对话框单位是水平或垂直距离。水平对话框单位等于当前对话框基准宽度单位的四分之一。对话框基准单位是通过当前系统字体的宽度和高度来计算的。Windows的GetDialogBaseUnits函数返回以象素为单位的当前对话框基准单位。)  
    · LBS_WANTKEYBOARDINPUT 不论什么时候,只要用户在列表框具有输入焦点的时候按下了键,列表框就接收到WM_VKEYTOITEM或WM_CHARTOITEM消息。这使得应用程序能够对键盘输入进行特别处理。  
    · LBS_DISABLENOSCROLL 当列表框 
    -------------------------------------------
    都贴上来.
    LBS_HASSTRINGS 你没有指定这个风格吧.
      

  2.   

    void MyListBox::PreSubclassWindow() 
    {
    // TODO: Add your specialized code here and/or call the base class
    ModifyStyle(0,LBS_HASSTRINGS);
    CListBox::PreSubclassWindow();

    不行还是乱码。
      

  3.   


    //MylistBox.cpp文件#include "stdafx.h"
    #include "ListBoxTest.h"
    #include "MyListBox.h"#ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif/////////////////////////////////////////////////////////////////////////////
    // MyListBoxMyListBox::MyListBox()
    {
    }MyListBox::~MyListBox()
    {
    }
    BEGIN_MESSAGE_MAP(MyListBox, CListBox)
    //{{AFX_MSG_MAP(MyListBox)
    ON_WM_PAINT()
    ON_WM_DRAWITEM_REFLECT()
    ON_WM_CTLCOLOR()
    ON_WM_NCMOUSEMOVE()
    ON_WM_MEASUREITEM_REFLECT()
    //}}AFX_MSG_MAP
    END_MESSAGE_MAP()/////////////////////////////////////////////////////////////////////////////
    // MyListBox message handlersvoid MyListBox::OnPaint() 
    {
    CPaintDC dc(this); // device context for painting

    // TODO: Add your message handler code here

    // Do not call CListBox::OnPaint() for painting messages
    } void MyListBox::DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct) 
    {
    // TODO: Add your message handler code here
    ASSERT(lpDrawItemStruct->CtlType == ODT_LISTBOX);  
     LPCTSTR lpszText = (LPCTSTR) lpDrawItemStruct->itemData;  
     ASSERT(lpszText != NULL);  
     CDC dc;  
       
     dc.Attach(lpDrawItemStruct->hDC);  
       
     // Save these value to restore them when done drawing.  
     COLORREF crOldTextColor = dc.GetTextColor();  
     COLORREF crOldBkColor = dc.GetBkColor();  
       
     // If this item is selected, set the background color   
     // and the text color to appropriate values. Also, erase  
     // rect by filling it with the background color.  
     if ((lpDrawItemStruct->itemAction | ODA_SELECT) &&  
      (lpDrawItemStruct->itemState & ODS_SELECTED))  
     {  
      dc.SetTextColor(::GetSysColor(COLOR_HIGHLIGHTTEXT));  
      dc.SetBkColor(::GetSysColor(COLOR_HIGHLIGHT));  
      dc.FillSolidRect(&lpDrawItemStruct->rcItem,   
       ::GetSysColor(COLOR_HIGHLIGHT));  
     }  
     else  
     {  
      if(lpDrawItemStruct->itemID%2)  
       dc.FillSolidRect(&lpDrawItemStruct->rcItem, RGB(128,128,128));  
      else  
       dc.FillSolidRect(&lpDrawItemStruct->rcItem, RGB(255,128,255));  
     }  
       
     // If this item has the focus, draw a red frame around the  
     // item's rect.  
     if ((lpDrawItemStruct->itemAction | ODA_FOCUS) &&  
      (lpDrawItemStruct->itemState & ODS_FOCUS))  
     {  
      CBrush br(RGB(0, 0, 128));  
      dc.FrameRect(&lpDrawItemStruct->rcItem, &br);  
     }  
     lpDrawItemStruct->rcItem.left += 5;  
     // Draw the text.  
     dc.DrawText(  
      lpszText,  
      strlen(lpszText),  
      &lpDrawItemStruct->rcItem,  
      DT_LEFT|DT_SINGLELINE|DT_VCENTER);  
       
     // Reset the background color and the text color back to their  
     // original values.  
     dc.SetTextColor(crOldTextColor);  
     dc.SetBkColor(crOldBkColor);  
       
     dc.Detach();  
    }HBRUSH MyListBox::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) 
    {
    HBRUSH hbr = CListBox::OnCtlColor(pDC, pWnd, nCtlColor);

    // TODO: Change any attributes of the DC here

    // TODO: Return a different brush if the default is not desired
    return hbr;
    }void MyListBox::OnNcMouseMove(UINT nHitTest, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CListBox::OnNcMouseMove(nHitTest, point);
    }void MyListBox::MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct) 
    {
    // TODO: Add your message handler code here
    ASSERT(lpMeasureItemStruct->CtlType == ODT_LISTBOX);  
     LPCTSTR lpszText = (LPCTSTR) lpMeasureItemStruct->itemData;  
     ASSERT(lpszText != NULL);  
     CSize   sz;  
     CDC*    pDC = GetDC();  
       
     sz = pDC->GetTextExtent(lpszText);  
       
     ReleaseDC(pDC);  
       
     lpMeasureItemStruct->itemHeight = 2*sz.cy; 
    }
    void MyListBox::PreSubclassWindow() 
    {
    // TODO: Add your specialized code here and/or call the base class
    ModifyStyle(0,LBS_HASSTRINGS);
    CListBox::PreSubclassWindow();
    }
    //这是双击获得内容的代码
    void CListBoxTestDlg::OnDblclkList1() 
    {
    // TODO: Add your control notification handler code here
    int nindex=m_list.GetCurSel();
    CString str;
    m_list.GetText(nindex,str);
    MessageBox(str);
    }
      

  4.   

    注意:
    必须 :has string
      

  5.   

    vc6上也不行,我用的CString类型的,还用考虑\0吗?
      

  6.   

    是不是unicode的问题?
    试试用DrawTextW输出看看
      

  7.   

    有没有初始化?
    即AddString ?
      

  8.   

    用这个

    const TCHAR* str = ((TCHAR*)GetItemDataPtr(lpDrawItemStruct->itemID));CListBox的GetText是有这个问题的
      

  9.   

    不必:const TCHAR* str = ((TCHAR*)GetItemDataPtr(lpDrawItemStruct->itemID));
    const TCHAR* str = ((TCHAR*)GetItemText(lpDrawItemStruct->itemID));
      

  10.   

    ‘没有 HAS STRING’时用SetItemDataPtr(“Item 1”)先加数据(=AddString)
    然后才能GetItemDataPtr或者 HAS STRING 简单