动态创建ListBox:
//#define ID_SCD_TEXTURE 320
//CListBox *m_lbxImageSet;
//CRect rect;
rect.left = 0;
rect.top = 160;
rect.right = 150;
rect.bottom = 330;
m_lbxImageSet = new CListBox;
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER |
LBS_STANDARD |WS_HSCROLL | WS_VSCROLL ;
m_lbxImageSet->Create(dwStyle, rect,this,ID_LBX_IMSET);
这时创建的是标准ListBox,具有自动排序功能,如果不希望排序就不能使用 LBS_STANDARD风格
可改为:
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER |
LBS_EXTENDEDSEL |WS_HSCROLL | WS_VSCROLL ;
或:
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER |
LBS_STANDARD & (!LBS_SORT) |WS_HSCROLL | WS_VSCROLL ;
但这时又有新问题了,添加的ON_LBN_SELCHANGE(或ON_CBN_SELCHANGE)消息函数不能响应,经实验发现问题还是出在dwStyle上,要添加LBS_NOTIFY 风格 ,当用户单击或双击鼠标时通知父窗口。改动如下:
DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_TABSTOP | WS_BORDER |
LBS_STANDARD & (!LBS_SORT) | LBS_NOTIFY |WS_HSCROLL | WS_VSCROLL ;