locked
CListCtrl Hover Effect RRS feed

  • Question

  • How can i change a single row's bkcolor when mouseover it?

    What is the best way to implement it? ( can Ownerdraw work? what's the state then? or should i use Mouseover?)

    I need an example !

    Thanks!

    Monday, August 5, 2013 9:49 PM

Answers

  • The parent of the list control will get a WM_NOTIFY message with a NM_HOVER code when you mouse over an item. You can get the hot item by calling CListCtrl::SubItemHitTest with mouse coordinates from GetCursorPos and ScreenToClient. If the hit result is LVHT_ONITEM you then save the host item's index somewhere and call UpdateItem to update the hot row.

    The parent of the list control will also get NM_CUSTOMDRAW before displaying a row. You can change NMLVCUSTOMDRAW.clrTextBk after comparing dwItemSpec to the saved hot item index. 

    If you use message reflection (See TN062), you can also have the notification handling code in a derived list control class.



    Visual C++ MVP


    Tuesday, August 6, 2013 5:46 PM
  • You can add LVS_EX_TRACKSELECT to the control, this has the side effect of selecting an item after the mouse is over it for a certain amount of time (therefore changing background color).


    Visual C++ MVP

    Monday, August 5, 2013 11:19 PM

All replies

  • You can add LVS_EX_TRACKSELECT to the control, this has the side effect of selecting an item after the mouse is over it for a certain amount of time (therefore changing background color).


    Visual C++ MVP

    Monday, August 5, 2013 11:19 PM
  • thanks Jiang,

    but what i'm looking for is hover only, i don't want it be selected.

    Tuesday, August 6, 2013 1:31 PM
  • The parent of the list control will get a WM_NOTIFY message with a NM_HOVER code when you mouse over an item. You can get the hot item by calling CListCtrl::SubItemHitTest with mouse coordinates from GetCursorPos and ScreenToClient. If the hit result is LVHT_ONITEM you then save the host item's index somewhere and call UpdateItem to update the hot row.

    The parent of the list control will also get NM_CUSTOMDRAW before displaying a row. You can change NMLVCUSTOMDRAW.clrTextBk after comparing dwItemSpec to the saved hot item index. 

    If you use message reflection (See TN062), you can also have the notification handling code in a derived list control class.



    Visual C++ MVP


    Tuesday, August 6, 2013 5:46 PM