假设你所使用的是VS,即MFC库
1、建立一个新的类,并继承自CListBox
2、为这个类添加新的消息处理机制(WM_MOUSEMOVE)
3、把这个类应用于你所需要使用的地方(例如:《MFC Windows程序设计》中第7章的FontView程序),代码如下:
class CPKIListBox : public CListBox
{
public:
DECLARE_MESSAGE_MAP()
afx_msg void OnMouseMove(UINT nFlags, CPoint point);
};
BEGIN_MESSAGE_MAP(CPKIListBox, CListBox)
ON_WM_MOUSEMOVE()
END_MESSAGE_MAP()
void CPKIListBox::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: 在此添加消息处理程序代码和/或调用默认值
BOOL outSide = TRUE;
this->SetCurSel(this->ItemFromPoint(point,outSide));
CListBox::OnMouseMove(nFlags, point);
}