From: JanAdam on
I will try your code Matthias (as well as the others). There are parts in
there I do not understand. If I can get through it quick, then of course I
will use it. However, I have to understand it first. Subclassing is new to me
so it may take too long for the main project.
But, regardless, thank you so much for your help.

--
JanAdam


"Matthias Immhoff" wrote:

> JanAdam schrieb:
> > Gentlemen, thank you all.
> > Way back, I was quite comfortable with linear programming. Doing other
> > things, I missed OOP development and have been recently trying to get some
> > feel for it by doing a bit of VBA, just for the fun of it. After carefully
> > reading your messages and trying to understand the code you kindly provided,
> > I am likely to follow Mike's suggestion and have somebody doing it. I will
>
> I already did it for you, what's the problem.
>
From: Karl E. Peterson on
JanAdam wrote:
> I will try your code Matthias (as well as the others). There are parts in
> there I do not understand. If I can get through it quick, then of course I
> will use it. However, I have to understand it first. Subclassing is new to me
> so it may take too long for the main project.

This is probably the best place in the world to ask about the specifics of code like
that. And that code Matthias offered is indeed extremely intimidating! This is
stepping outside the realm that VB was designed for. Fun stuff, but not rookie
material. :-)

There is another option, though. One I don't recommend too often anymore, because I
defintely prefer the native approach and try to avoid external dependencies if I
can. But you could use the old MsgHook control to snag the messages for you. It's
available here:

http://vb.mvps.org/tools/MsgHook

Install that, create a new project that includes this control, and put one on your
form. Then add code like this:

Option Explicit

Private Const WM_MOUSEWHEEL As Long = &H20A

Private Sub Command1_Click()
Unload Me
End Sub

Private Sub Form_Load()
With Msghook1
.HwndHook = Me.hWnd
.Message(WM_MOUSEWHEEL) = True
End With
End Sub

Private Sub Msghook1_Message(ByVal msg As Long, ByVal wp As Long, ByVal lp As
Long, result As Long)
Select Case msg
Case WM_MOUSEWHEEL
If wp < 0 Then
Debug.Print "Wheel rolled backwards!", wp, Timer
Else
Debug.Print "Wheel rolled forwards!", wp, Timer
End If
Case Else
' This shouldn't happen, unless you
' hook other messages too.
End Select
End Sub

The WM_MOUSEWHEEL message is always sent to the parent window if the window under
the cursor doesn't respond. You can see this in action by putting a command button
on the form, and rolling the wheel over it -- you'll get the notifications in the
Immediate window no matter where the cursor is.

More details on the wp and lp parameters in that Message event may be found here:

http://msdn2.microsoft.com/en-us/library/ms645617(VS.85).aspx

Again, ask here if any of that doesn't make sense. (I'm pretty sure a lot of it
won't. That's okay!) On the same page where you can download MsgHook, notice that
I also have links to other sample programs that use it for a variety of interesting
tasks.
--
..NET: It's About Trust!
http://vfred.mvps.org


From: Matthias Immhoff on
All you have to do is put that control on your form, and with every
mousewheel you get a MouseWheel message telling you if the wheel goes up
or down.
You do not have to understand the code of the usercontrol to get the
notification you want.

I would not use the subclassing code that Karl presented because it's
not crash-safe. And that will drive a newbie wild.


Karl E. Peterson schrieb:
> JanAdam wrote:
>> I will try your code Matthias (as well as the others). There are parts in
>> there I do not understand. If I can get through it quick, then of course I
>> will use it. However, I have to understand it first. Subclassing is new to me
>> so it may take too long for the main project.
>
> This is probably the best place in the world to ask about the specifics of code like
> that. And that code Matthias offered is indeed extremely intimidating! This is
> stepping outside the realm that VB was designed for. Fun stuff, but not rookie
> material. :-)
>
> There is another option, though. One I don't recommend too often anymore, because I
> defintely prefer the native approach and try to avoid external dependencies if I
> can. But you could use the old MsgHook control to snag the messages for you. It's
> available here:
>
> http://vb.mvps.org/tools/MsgHook
>
> Install that, create a new project that includes this control, and put one on your
> form. Then add code like this:
>
> Option Explicit
>
> Private Const WM_MOUSEWHEEL As Long = &H20A
>
> Private Sub Command1_Click()
> Unload Me
> End Sub
>
> Private Sub Form_Load()
> With Msghook1
> .HwndHook = Me.hWnd
> .Message(WM_MOUSEWHEEL) = True
> End With
> End Sub
>
> Private Sub Msghook1_Message(ByVal msg As Long, ByVal wp As Long, ByVal lp As
> Long, result As Long)
> Select Case msg
> Case WM_MOUSEWHEEL
> If wp < 0 Then
> Debug.Print "Wheel rolled backwards!", wp, Timer
> Else
> Debug.Print "Wheel rolled forwards!", wp, Timer
> End If
> Case Else
> ' This shouldn't happen, unless you
> ' hook other messages too.
> End Select
> End Sub
>
> The WM_MOUSEWHEEL message is always sent to the parent window if the window under
> the cursor doesn't respond. You can see this in action by putting a command button
> on the form, and rolling the wheel over it -- you'll get the notifications in the
> Immediate window no matter where the cursor is.
>
> More details on the wp and lp parameters in that Message event may be found here:
>
> http://msdn2.microsoft.com/en-us/library/ms645617(VS.85).aspx
>
> Again, ask here if any of that doesn't make sense. (I'm pretty sure a lot of it
> won't. That's okay!) On the same page where you can download MsgHook, notice that
> I also have links to other sample programs that use it for a variety of interesting
> tasks.
From: JanAdam on

Thanks Karl, this seems to be within my abilities. I think I understand it
the idea and will try it shortly. That is when I can get to the mvp site. For
whatever reason my IP server is somewhat slow and erratic today.
--
JanAdam


"Karl E. Peterson" wrote:

> JanAdam wrote:
> > I will try your code Matthias (as well as the others). There are parts in
> > there I do not understand. If I can get through it quick, then of course I
> > will use it. However, I have to understand it first. Subclassing is new to me
> > so it may take too long for the main project.
>
> This is probably the best place in the world to ask about the specifics of code like
> that. And that code Matthias offered is indeed extremely intimidating! This is
> stepping outside the realm that VB was designed for. Fun stuff, but not rookie
> material. :-)
>
> There is another option, though. One I don't recommend too often anymore, because I
> defintely prefer the native approach and try to avoid external dependencies if I
> can. But you could use the old MsgHook control to snag the messages for you. It's
> available here:
>
> http://vb.mvps.org/tools/MsgHook
>
> Install that, create a new project that includes this control, and put one on your
> form. Then add code like this:
>
> Option Explicit
>
> Private Const WM_MOUSEWHEEL As Long = &H20A
>
> Private Sub Command1_Click()
> Unload Me
> End Sub
>
> Private Sub Form_Load()
> With Msghook1
> .HwndHook = Me.hWnd
> .Message(WM_MOUSEWHEEL) = True
> End With
> End Sub
>
> Private Sub Msghook1_Message(ByVal msg As Long, ByVal wp As Long, ByVal lp As
> Long, result As Long)
> Select Case msg
> Case WM_MOUSEWHEEL
> If wp < 0 Then
> Debug.Print "Wheel rolled backwards!", wp, Timer
> Else
> Debug.Print "Wheel rolled forwards!", wp, Timer
> End If
> Case Else
> ' This shouldn't happen, unless you
> ' hook other messages too.
> End Select
> End Sub
>
> The WM_MOUSEWHEEL message is always sent to the parent window if the window under
> the cursor doesn't respond. You can see this in action by putting a command button
> on the form, and rolling the wheel over it -- you'll get the notifications in the
> Immediate window no matter where the cursor is.
>
> More details on the wp and lp parameters in that Message event may be found here:
>
> http://msdn2.microsoft.com/en-us/library/ms645617(VS.85).aspx
>
> Again, ask here if any of that doesn't make sense. (I'm pretty sure a lot of it
> won't. That's okay!) On the same page where you can download MsgHook, notice that
> I also have links to other sample programs that use it for a variety of interesting
> tasks.
> --
> ..NET: It's About Trust!
> http://vfred.mvps.org
>
>
>
From: Karl E. Peterson on
Matthias Immhoff wrote:
> You do not have to understand the code of the usercontrol to get the
> notification you want.

Well, I gotta hand it to you! That's one of the better understatements I think I've
heard here before. I tried the code you posted, and am definitely impressed. Is
that your work? Has it been published?

I'm not convinced, though, that someone who isn't very familiar with VB could do
what I did to make your post functional. There's a fair bit of assumed knowledge
there.
--
..NET: It's About Trust!
http://vfred.mvps.org