MouseHover effect on ListBox
-
Hi I ahve created a Listbox using myclass which is derived from Clistbox. I want to set the Mouseover effect on the listbox, I mean whenever my mouse moves from one index to other it should be hilighted. Can anybode please help me.. Please send me some sample code if possible.. Thanks
-
Hi I ahve created a Listbox using myclass which is derived from Clistbox. I want to set the Mouseover effect on the listbox, I mean whenever my mouse moves from one index to other it should be hilighted. Can anybode please help me.. Please send me some sample code if possible.. Thanks
As far as i know CListBox doesn't provide you with this feature. You can however try implement it yourself , you would probably need to use an owner drawn list box for this by adding the LBS_OWNERDRAWFIXED style, handle the WM_MOUSEMOVE message, use TrackMouseEvent[^], the ItemFromPoint[^] method. p.s: CListCtrl however does have an extended style called LVS_EX_TRACKSELECT that probably does what you want, if possible you might try to use CListCtrl instead of CListBox.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
-
As far as i know CListBox doesn't provide you with this feature. You can however try implement it yourself , you would probably need to use an owner drawn list box for this by adding the LBS_OWNERDRAWFIXED style, handle the WM_MOUSEMOVE message, use TrackMouseEvent[^], the ItemFromPoint[^] method. p.s: CListCtrl however does have an extended style called LVS_EX_TRACKSELECT that probably does what you want, if possible you might try to use CListCtrl instead of CListBox.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <
I am trying with the below function, but every time its drawing the 1st item only.. basically the GetItemRect() needs the index value as the first parameter, can u please tell how to get the index value of the list box when mouse is moving from one item to other. my code is like this : void CTxListControl::OnMouseHover(UINT nFlags, CPoint point) { CDC* pDC = GetWindowDC(); CRect rect; GetItemRect(0,rect); rect.OffsetRect( -rect.left, -rect.top); CBrush brush( RGB(0, 0, 255)); pDC->FillRect(rect, &brush); }
-
I am trying with the below function, but every time its drawing the 1st item only.. basically the GetItemRect() needs the index value as the first parameter, can u please tell how to get the index value of the list box when mouse is moving from one item to other. my code is like this : void CTxListControl::OnMouseHover(UINT nFlags, CPoint point) { CDC* pDC = GetWindowDC(); CRect rect; GetItemRect(0,rect); rect.OffsetRect( -rect.left, -rect.top); CBrush brush( RGB(0, 0, 255)); pDC->FillRect(rect, &brush); }
See ItemFromPoint[^], as i already wrote.
> The problem with computers is that they do what you tell them to do and not what you want them to do. < > "It doesn't work, fix it" does not qualify as a bug report. < > Amazing what new features none of the programmers working on the project ever heard of you can learn about when reading what the marketing guys wrote about it. <