Karl
Tue Feb 06 18:38:18 CST 2007
Hi Mickey --
> To be honest, I'm a little unsure of what's going on in that Private Declare
> Function statement. I've never really used them. What it looks like is that
> your using a function from the user32 library. I've never used anything like
> that before, so I'm a bit lost there.
Yeah, SendMessage is a very powerful tool provided by the Windows API. You "send" a
message to any particular window, and it (hopefully) responds with some information
you want/need.
> I guess what I'm really looking for is an explanation of what SendMessage
> does. The article that you linked didn't go into detail on it. I don't know
> what any of the parameters are and not sure where to find documentation on
> it, and (if my suppositions are correct) any other pre-made functions like it.
Okay, sorry about that. Lots of implied knowledge there. If you want to learn
about that sort of thing, I'd recommend starting slow, with specific examples (like
this, in fact) or at sites like
http://word.mvps.org
> Also, another novice questions here, what significance is the Alias
> "SendMessageA" portion?
Ah, most of the API calls that work with strings in Windows come in both ANSI (A)
and Unicode (W) flavors. VB automatically converts strings to ANSI when passing to
external DLLs, so that's the one we need to use most often.
Sadly, that all said, I just tried my suggestion in Word, and it doesn't work.
Seems the listbox in Word isn't a "real" listbox afterall. It doesn't respond to
the LB_* messages. :-(
Sorry... Karl
> "Karl E. Peterson" wrote:
>
>> Mickey F. <MickeyF@discussions.microsoft.com> wrote:
>>> Is there a way to get Word to return the Index of an item in a ListBox that
>>> you right-clicked over?
>>>
>>> This is for Word 2002.
>>
>> Well, you'll need to obtain its hWnd (GetFocus, maybe?). Once you have that, you
>> can translate mouse position to ListIndex something like this:
>>
>> Private Declare Function SendMessage Lib _
>> "user32" Alias "SendMessageA" (ByVal hWnd As _
>> Long, ByVal wMsg As Long, ByVal wParam As _
>> Long, lParam As Any) As Long
>> Private Const LB_GETITEMHEIGHT = &H1A1
>>
>> Private Sub List1_MouseMove(Button As Integer, _
>> Shift As Integer, X As Single, Y As Single)
>> Dim ItemHeight As Long
>> Dim NewIndex As Long
>> Static OldIndex As Long
>>
>> With List1
>> ItemHeight = SendMessage(.hWnd, _
>> LB_GETITEMHEIGHT, 0, ByVal 0&)
>> ItemHeight = .Parent.ScaleY(ItemHeight, _
>> vbPixels, vbTwips)
>> NewIndex = .TopIndex + (Y \ ItemHeight)
>> If NewIndex <> OldIndex Then
>> If NewIndex < .ListCount Then
>> .ToolTipText = .List(NewIndex)
>> Else
>> .ToolTipText = vbNullString
>> End If
>> OldIndex = NewIndex
>> End If
>> End With
>> End Sub
>>
>> Source:
>>
>> Ask the VB Pro, June 2000
>>
http://vb.mvps.org/articles/ap200006.asp
>>
>> That was originally written for Classic VB, of course, but the same general
>> principles apply. In this case, you're only after the value NewIndex.
>> --
>> ..NET: It's About Trust!
>>
http://vfred.mvps.org
--
.NET: It's About Trust!
http://vfred.mvps.org