Re: ToolTipText and the ListView control in VB6



Yes, actually I am worried about a user performing that (or a similar)
sequence of actions. In the bigger picture, it's a significant issue for
us.

I greatly appreciate your further breaking down what's really happening and
why it isn't performing as I would have expected. I haven't done much with
subclassing, but I figured out how to do it after some trial and error using
a third party subclassing tool from DesaWare. (This control is well over
ten years old, because it is targetted for VB4 and VB5, and even includes
16-bit versions of stuff for VB3!)

Here's how it all ended up, not including showing the actual subclass
control setup.

'******************************************************************************
'* Module: lvIRR_MouseMove
'* Description: Process MouseMove event. This is used for updating the
'* ListView's tooltip.
'* Author: Mickey Ferguson
'******************************************************************************
'* Modification History:
'******************************************************************************
Private Sub lvIRR_MouseMove(Button As Integer, Shift As Integer, x As
Single, _
y As Single)
Dim objListItem As ListItem

If gbProcess_lvIRR_MouseMoveEvent Then
With lvIRR
Set objListItem = .HitTest(x, y)
If Not objListItem Is Nothing Then
'Prevent flicker by testing for change
If .ToolTipText <> objListItem.Key Then
'Set the new tooltip
.ToolTipText = objListItem.Key
End If
Else
.ToolTipText = ""
End If
End With
End If
End Sub

'******************************************************************************
'* Function: Winhook_lvIRR_MouseProc
'* Description: This function intercepts the lvIRR mouse messages so that
'* we can update the ListView's ToolTipText, but we need to
use
'* this subclassing control to prevent the ToolTipText from
'* appearing when the mouse is over the header. (The problem
is
'* that the ToolTipText is displayed for the ListView whenever
'* the mouse is over any part of the control, including the
'* header, but the MouseMove event is not triggered when the
'* mouse is over the header.)
'* Author: Mickey Ferguson
'******************************************************************************
'* Modification History:
'******************************************************************************
Private Sub WinHook_lvIRR_MouseProc(wnd As stdole.OLE_HANDLE, _
msg As stdole.OLE_HANDLE, _
x As Long, y As Long, hitcode As Long, _
peek As Integer, nodef As Integer)
Dim rectLV As RECT

gbProcess_lvIRR_MouseMoveEvent = False

If (lvIRR.ListItems.Count > 0) Then
'' Determine height of a list item. If y - LV's Top <= that height,
'' the mouse must be in the header area.
Call GetWindowRect(lvIRR.hWnd, rectLV)

'' Height is presented in twips, but the y and Top values come in
pixels.
'' Also, the y coordinate for this event is a *screen* coordinate, not
'' relative to the current window/control.
If (y - rectLV.Top > lvIRR.ListItems(1).Height / gnTwipsPerPixelY) Then
gbProcess_lvIRR_MouseMoveEvent = True
End If
End If

If (Not gbProcess_lvIRR_MouseMoveEvent) Then
lvIRR.ToolTipText = ""
End If

End Sub

"MikeD" <nobody@xxxxxxxxxxx> wrote in message
news:uVjI9MogHHA.4552@xxxxxxxxxxxxxxxxxxxxxxx

"Mickey Ferguson" <MFerguson@xxxxxxxxxxxx> wrote in message
news:%23AerDcggHHA.4552@xxxxxxxxxxxxxxxxxxxxxxx
That's a much cleaner way of determining which item the mouse is over and
updating the ToolTipText. (I wasn't aware of the HitTest event - nice.)
But it still doesn't solve the underlying problem: When the mouse is
over the column headers, the ToolTipText displays. It shouldn't (or
should be cleared). I need to know when the mouse is over the headers,
but I don't get notified.

Try this scenario. Create such a ListView control, add a few rows, and
then use your code below. Move the mouse over the third row, then move
the mouse horizontally so the third row is the last row the mouse is over
before it is no longer over the control at all. Then swing your mouse
higher than the ListView (without ever touching it), and then decend down
so that the mouse is over the header. The ToolTipText will appear, with
it presenting the data from the third row. The MouseMove event never
fires. So the general problem is that the MouseMove event *should* fire
when the mouse is on the header, but it doesn't. Only when the mouse
moves down to the real data does the MouseMove event get fired.

And you're worried about a using performing that exact sequence of actions
to reproduce this?

Anyway, a ListView and column headers are actually 2 separate controls..
The column headers are a Header control. The ListView is just capable of
automatically creating a Header control, but being a separate control, it
has its own messages and events (API-wise). The ListView as wrapped in the
Common Controls OCX simply doesn't expose messages/notifications for the
Header control as events. You can, however, subclass the Header control.
You shouldn't have a problem then detecting when the mouse is moved over
it.


.


Loading