ON_CBN_SELCHANGE The selection in the list box of a combo box is about to be changed as a result of the user either clicking in the list box or changing the selection by using the arrow keys. When processing this message, the text in the edit control of the combo box can only be retrieved via GetLBText or another similar function. GetWindowText cannot be used.
移动时选中的第几项应该是无法获得的,只有点击左键选中后,就可以通过API获得了
用customdraw.
再WM_DRAWITEM里边,调用基类的方法来画,但是可以判定是不是选中状态我猜想能行。。hoho
看看msdn.
为什么不知道啊?drawitem参数里边带item号吧?!
{
// TODO: Add your specialized code here and/or call the base class
if(WM_CTLCOLORLISTBOX == message)
{
HWND hListBox = (HWND)lParam;
CListBox* pListBox = (CListBox*)FromHandle(hListBox);
ASSERT(pListBox);
int nCount = pListBox->GetCount(); if(CB_ERR != nCount)
{
CPoint pt;
GetCursorPos(&pt);
pListBox->ScreenToClient(&pt);
CRect rc;
for(int i=0; i<nCount; i++)
{
pListBox->GetItemRect(i, &rc);
if(rc.PtInRect(pt))
{
CString str;
str.Format(_T("nIndex = %d"), i);
AfxGetMainWnd()->SetWindowText(str);
break;
}
}
}
}
return CComboBox::WindowProc(message, wParam, lParam);
}
重写CComboBox类,在WindowProc中加上上面的代码,在主对话框的标题上会显示当前鼠标在下拉ListBox中的哪一个item上。