Textbox mousewheel hook

The place for threads about TimoSoft EditControls.
Post Reply
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Textbox mousewheel hook

Post by Mex »

Hi!

I hope you have good advice. :)

Let me explain my problem

I have a form and usercontrol on it. Usercontrol contains PictureBox as container and 1 to N TextBoxes(your control, multiline enabled).
TexBoxes do not have scrollbars and height is set automatically (see the picture). Usecontrol is basically a "grid". If needed, scrollbar is added to form
and user can scroll the grid. Parent form is subclassed to catch mousewheel and if cursor is over the control, user can scroll grid with wheel.

When textbox on the grid has focus wheel action is not "catched". What is the best method to catch mousewheel actions also, when textbox has focus?
Must I hook all textboxes indivually too?

Regards
Meelis
Attachments
control.png
(71.56 KiB) Not downloaded yet
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Textbox mousewheel hook

Post by Mex »

I think I figured it but don't know if this is a correct way.

I hook textbox and on WM_MOUSEWHEEL call PostMessage GetParent(GetParent(Lwnd)), Lmsg, wParam, lParam


Regards
Meelis
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: Textbox mousewheel hook

Post by TiKu »

Hi,

In my opinion posting the message to the parent window isn't a good idea.
First, posted messages do not get handled synchronously. They are appended to the message queue, so bazillions of other messages might get handled before. SendMessage would be better, because it bypasses the message queue. But I've not tested it, so other problems might arise.
Second, it should be enough to return 1 without forwarding the message anywhere:

Code: Select all

Function WndProc(...) As Long
  Select Case LMsg
    Case WM_MOUSEWHEEL
      ' tell Windows, that we did NOT handle the message
      WndProc = 1
      ' do NOT call CallWindowProc here, so that the text box won't handle the message
      Exit Function
    Case Else
      ' handle other messages
  End Select
  ' let the control itself handle the message
  WndProc = CallWindowProc(...)
End Function
According to MSDN, returning a value other than 0 means that the WM_MOUSEWHEEL message has not been handled. The window manager therefore will send it to the parent window and see whether it handles this message.

Please let me know whether this works. I'm interested in it.

/Edit: Ah, you also asked whether subclassing really is necessary. I'm afraid it is, as long as I don't implement a feature to suppress mouse wheel handling.

Regards
TiKu
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Textbox mousewheel hook

Post by Mex »

Thnx for the answer.

Returning 1 does not work :(
Only solution working is PostMessage. Tested also SendMessage and its not working.

Meelis
User avatar
TiKu
Administrator
Administrator
Posts: 832
Joined: 28 Sep 2004, 21:10
Location: Unterföhring
Contact:

Re: Textbox mousewheel hook

Post by TiKu »

Hmm, maybe the direct parent of the control does return 0 on WM_MOUSEWHEEL, so that it does not get sent to the grid control. You need the PictureBox as container in order to get scrollbars, right?
However, it's interesting that SendMessage does not work.
Crunching for Fab36_Folding-Division at Folding@Home. Join Fab36/Fab30! - Folding@Home and BOINC
Boycott DRM! Boycott HDCP!
User avatar
Mex
Captain
Posts: 130
Joined: 24 Sep 2009, 19:47

Re: Textbox mousewheel hook

Post by Mex »

OK, SendMessage is working but... when i send WM_WHEEL to top parent form, wParam is changed and I get wrong rotation.
After SendMessage and in parent form rotation = wParam / 65536, it's always 20 instead of -120 and 120
Currently I'm using SendNotifyMessage and then parent form is receiving params as expected.

Any ideas why wParam is changing using SendMessage?


Meelis
Post Reply