Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Prevent listview column resizing & mouse cursor

6 views
Skip to first unread message

Tim Rude

unread,
Aug 27, 2004, 9:33:27 AM8/27/04
to
I use the following subclassing code (declares omitted here for brevity) to
prevent all column resizing in a listview. This works fine.

However, the mouse cursor still changes to the double-arrow resize cursor
when the mouse is over a column divider in the listview header.

How can I prevent the cursor change as well?

=== BEGIN CODE ===

Function WindowProc(ByVal hWnd As Long, ByVal uMsg As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long

Dim nmh As NMHDR

If uMsg = WM_NOTIFY Then

Call MoveMemory(nmh, ByVal lParam, Len(nmh))

Select Case nmh.code
Case HDN_BEGINTRACK, HDN_DIVIDERDBLCLICK
WindowProc = 1
Exit Function
End Select

End If

WindowProc = CallWindowProc(lpPrevWndProc, hWnd, uMsg, wParam, lParam)

End Function

=== END CODE ===

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]

Rob

unread,
Aug 27, 2004, 1:45:58 PM8/27/04
to
Subclass the header WM_SETCURSOR message. If the cursor is over a divider
for which you want to disallow resizing then change the cursor to an arrow
(SetCursor) and return 1.

"Tim Rude" <tim...@NOSPAM.hotmail.com> wrote in message
news:O1eyxpDj...@TK2MSFTNGP15.phx.gbl...

Tim Rude

unread,
Aug 27, 2004, 10:45:42 PM8/27/04
to
I'll try that. Thanks.

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]

"Rob" <none> wrote in message news:u6feb2F...@TK2MSFTNGP11.phx.gbl...

Tim Rude

unread,
Aug 27, 2004, 11:20:53 PM8/27/04
to
OK, here's the deal. I can get the hwnd of the ListView control itself but I
can't see where it exposes the hwnd of its header.

I fired up Spy++ and if I just watch the messages for the ListView's own
hwnd (the one exposed by the .hwnd property), there is no message fired when
I move over the header dividers and the cursor changes. It only gets
notification messages when a mouse button is depressed.

Spy++ shows a child window under the main ListView window named
'msvb_lib_header'. This is the window that gets the WM_SETCURSOR message.
But I don't know how to find the hwnd of this child window in VB to subclass
it and look for the WM_SETCURSOR message.

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]

"Tim Rude" <tim...@NOSPAM.hotmail.com> wrote in message
news:#zIfekKj...@TK2MSFTNGP10.phx.gbl...

Rob

unread,
Aug 28, 2004, 4:02:35 AM8/28/04
to
hWndHeader = SendMessage(hWndListView, LVM_GETHEADER, ByVal 0&, ByVal 0&)

Regards,
Rob

"Tim Rude" <tim...@NOSPAM.hotmail.com> wrote in message

news:u7ZgI4Kj...@TK2MSFTNGP11.phx.gbl...

Tim Rude

unread,
Aug 28, 2004, 11:12:59 PM8/28/04
to
Aw man. That's too slick!

I was coming up with the EnumChildWindows/EnumChildProc callback to locate
the header hwnd. But I sure like your method a whole lot better.

BTW, since I'm preventing resizing of _all_ columns, subclassing the header
is as simple as returning 1 for any WM_SETCURSOR message. The cursor stays
as the standard pointer just like I wanted.

It seems kind of clunky to have to subclass both the listview and the header
to do all of this though. I wonder if there's a way to prevent column
resizing by subclassing only the header.

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]

"Rob" <none> wrote in message news:egJNLVNj...@TK2MSFTNGP11.phx.gbl...

Rob

unread,
Aug 29, 2004, 7:48:17 PM8/29/04
to
> is as simple as returning 1 for any WM_SETCURSOR message. The cursor stays
> as the standard pointer just like I wanted.

I would be cautious about using this method. This will work fine if the
pointer is moving from a header, which displays an arrow pointer anyway, to
the divider but won't work if the pointer is moving from something which
doesn't show an arrow to a divider.

> It seems kind of clunky to have to subclass both the listview and the
header
> to do all of this though. I wonder if there's a way to prevent column
> resizing by subclassing only the header.

It's possible but it's a bit more work because the most useful messages like
HDN_TRACK are sent to the header's parent window.

Essentially you subclass the WM_LBUTTONDOWN message. Use the HDM_HITTEST
message to determine which header your clicking on (if any). If you're on a
header Check that the HHT_ONDIVIDER or HHT_ONDIVOPEN flags are set. If they
are set then you're clicking on a divider so return 0 to prevent the header
from doing anything.

Air code (Header WndProc)

Dim hdhtiHotItem As HDHITTESTINFO
Dim iHotIndex As Long

Select Case uMsg
Case WM_LBUTTONDOWN
iHotIndex = SendMessage(m_hWnd, HDM_HITTEST, ByVal 0, hdhtiHotItem)
If (iHotIndex >= 0) Then
If (hdhtiHotItem.flags And (HHT_ONDIVIDER Or HHT_ONDIVOPEN)) Then
Exit Function 'Return 0
End If
End If
End Select


Reagrds
Rob

Tim Rude

unread,
Aug 29, 2004, 11:49:45 PM8/29/04
to
Rob,

I've done a bit of testing regarding your cautionary warning, and you're
right. I overlaid a borderless textbox over a portion of the subclassed
listview header. The I-beam cursor from the textbox stays as an I-beam over
the listbox header if you move the mouse cursor from the textbox directly to
the listbox header. (But only if it's a borderless textbox - if it's got a
border, the border flips the cursor back to an arrow as it goes by). Good
catch!

However, in this app I know that there will never be a borderless textbox
over the listview and I'm pretty sure the odds are slim to none that anyone
will ever experience any cursor 'weirdness', or notice it if they do. In any
case, even if they do it's better than having the resize cursor show up when
resizing isn't allowed. I'm satisfied.

And as for the subclassing, your air-code didn't quite work right (locked me
up good) but that's ok. I'll just subclass both the LV and the header and be
fine with that. Thanks for your help!

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]

"Rob" <none> wrote in message news:uZjsQKi...@TK2MSFTNGP11.phx.gbl...

Rob

unread,
Aug 30, 2004, 1:01:44 AM8/30/04
to
> And as for the subclassing, your air-code didn't quite work right (locked
me
> up good) but that's ok. I'll just subclass both the LV and the header and
be
> fine with that. Thanks for your help!

Oops, I forgot to set the coordinates to actually hittest. This
definately works

Dim hdhtiHotItem As HDHITTESTINFO
Dim iHotIndex As Long

Select Case uMsg
Case WM_LBUTTONDOWN

hdhtiHotItem.pt.x = LoWord(lParam)
hdhtiHotItem.pt.y = HiWord(lParam)


iHotIndex = SendMessage(m_hWnd, HDM_HITTEST, ByVal 0, hdhtiHotItem)
If (iHotIndex >= 0) Then
If (hdhtiHotItem.flags And (HHT_ONDIVIDER Or HHT_ONDIVOPEN)) Then
Exit Function

Tim Rude

unread,
Aug 31, 2004, 12:19:12 AM8/31/04
to
Yep, it works now. :)

Do you think either method is inherently more reliable than the other for
preventing column resizing (i.e. subclassing LV for notifications vs.
subclassing LV-Header for WM_LBUTTONDOWN messages)?

I do like getting it all done with one subclassing, just wondering if there
are any gotcha's.

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]

"Rob" <none> wrote in message news:OX0FZ5k...@tk2msftngp13.phx.gbl...

Rob

unread,
Aug 31, 2004, 1:24:10 PM8/31/04
to
Just a thought. You'll also have to subclass WM_LBUTTONDBLCLK in the same
way to stop automatic column resizing.

Changing the case test to the following should do the trick

Case WM_LBUTTONDOWN, WM_LBUTTONDBLCLK


Tim Rude

unread,
Aug 31, 2004, 10:44:19 PM8/31/04
to
Right again!

--
Tim Rude

tim...@NOSPAM.hotmail.com
(remove NOSPAM. for correct email address)

[Please reply via the newsgroup so all can benefit]

"Rob" <none> wrote in message news:eDWB283j...@TK2MSFTNGP12.phx.gbl...

0 new messages