CListBox
-
Hi I have created a list box using CListBox class. I want to give the hover effect on the list box item. like combo box. Please anyone can help me how to do that. Thanks
-
No, but here is the rough idea. 1. Create a new class derived from CListBox -> CHoverListBox. 2. Make it owner drawn (a window style). 3. Override DrawItem() and possibly OnMeasureItem(). You will need DrawItem since you will be changing the visual appearance of the control while hovering. 4. Add a message handler for WM_MOUSEMOVE, and in this handler figure out which item the cursor is over. Cooridnates of the mouse is supplied in screen coords, so you should convert them to client coords using CListBox::ScreenToClient(). Then use CListBox::GetItemRect() to find the hovered item. Set a flag for this item, and then call Invalidate(FALSE) to force a repaint. 5. Implement DrawItem() to look at the flag set, and paint the items accordingly. 6. Now you have a reusable class. 7. Write an article about what you did and post it on this site. Tip: Do not use CListBox::SetItemData() to set the flag, because the space is likely to be needed by the users of your control. Use a separate integer in your class instead.