Results 1 to 12 of 12

Thread: Subclassing ... MouseScroll ... Someone Please READ | Project Samples Avail!

  1. #1

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51

    Subclassing ... MouseScroll ... Someone Please READ | Project Samples Avail!

    Hey All ... (I'm going mad here .. ) ... I've been trying to get this to work for the last 4 hours but I don't know a whole lot about subclassing so here is my situation ..


    I've made a usercontrol (I pass a form name to the control and it paints the form into a PictureBox, and scrollbars in the usercontrol allow the user to scroll about) ... but I want the user to be able to scroll the form with a wheel mouse, so earlier on I searched the forums and came up with two different peices of cone, one which is very basic other highly complex with all sorts of error detection / os detection ect ... in anycase the WM_MOUSESCROLL message isn't being fired as far as I can't tell. (I am debug.printing all the messages being sent to the specified function) ... I see it being called when I move the mouse from control area control area / mouse clicking ect ...

    I've tried using this in a seperate project (just a scrollbar and the form) and it works just fine. So because I used SetParent() to paint the form into a picturebox cause a problem somehow ? ...

    Any Ideas / Suggestions would be appriciated.
    Last edited by Tcalp; Feb 4th, 2003 at 09:43 AM.
    ~T

  2. #2

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    anyone ?
    ~T

  3. #3
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    http://msdn.microsoft.com/library/de...MOUSEWHEEL.asp

    It works

    VB Code:
    1. Private Const WM_MOUSEWHEEL As Long = &H20A

  4. #4

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    sorry .. I am using WM_MOUSEWHEEL, and i have gotten it to work in a test project .. it just won't work in my app ..
    (module I'm using for mouse scroll)

    VB Code:
    1. Option Explicit
    2. Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    3. Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    4. Const GWL_WNDPROC = (-4)
    5. 'These are the messages
    6. Const WM_MOUSEWHEEL = &H20A
    7. Global WndProcOld As Long
    8.  
    9. Public Function WindProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    10. 'checks the messages
    11.     Debug.Print "wMsg Is : " & wMsg
    12.     Debug.Print "Mwheel  : " & WM_MOUSEWHEEL
    13.     If wMsg = WM_MOUSEWHEEL Then
    14.         If wParam < 0 Then
    15.             'If Form1.VScroll1.Value <> Form1.VScroll1.Max Then Form1.VScroll1.Value = Form1.VScroll1.Value + 1
    16.             Form1.FormScroll.vs_Change
    17.         Else
    18.            
    19.             'If Form1.VScroll1.Value <> Form1.VScroll1.Min Then Form1.VScroll1.Value = Form1.VScroll1.Value - 1
    20.             Form1.FormScroll.vs_Change
    21.         End If
    22.     End If
    23.     WindProc = CallWindowProc(WndProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    24. End Function
    25.  
    26. Sub SubClassWnd(hwnd As Long)
    27.     WndProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WindProc)
    28. End Sub
    29.  
    30. Sub UnSubclassWnd(hwnd As Long)
    31.     SetWindowLong hwnd, GWL_WNDPROC, WndProcOld&
    32.     WndProcOld& = 0
    33. End Sub


    Where Form is Subclassed:
    VB Code:
    1. Public Sub Form_Draw(MyForm As Form)
    2.  
    3. Set PForm = MyForm
    4. Dim xx As Long
    5.  
    6. xx = GetWindowLong(MyForm.hwnd, GWL_STYLE)
    7. SetWindowLong MyForm.hwnd, GWL_STYLE, (xx Or WS_CHILD)
    8. xx = SetParent(MyForm.hwnd, Image1.hwnd)
    9.     'Mouse scrolling
    10.     SubClassWnd MyForm.hwnd
    11. Image1.top = 0
    12. Image1.left = 0
    13. MyForm.Move 0, 0
    14. MyForm.Show
    15. Image1.Height = MyForm.Height
    16. Image1.Width = MyForm.Width
    17.  
    18.     Debug.Print MyForm.Height
    19.     Debug.Print UserControl.Height
    20.     If MyForm.Height <= UserControl.Height Then
    21.         vs.Enabled = False
    22.     Else
    23.         vs.Enabled = True
    24.         vs.Min = 0
    25.         vs.Max = (MyForm.Height - vs.Height) / 4
    26.         vs.Value = 0
    27.     End If
    28.    
    29.     If MyForm.Width <= UserControl.Width Then
    30.         hs.Enabled = False
    31.     Else
    32.         hs.Enabled = True
    33.         hs.Min = 0
    34.         hs.Max = (Image1.Width - hs.Width) / 4
    35.         hs.Value = 0
    36.     End If
    37. End Sub
    ~T

  5. #5

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    and sorry Image1 is a Picturebox not an image control :P
    ~T

  6. #6
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    You got the latest drivers for your mouse?

  7. #7

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    hummm .. I've said serveral times that I've gotten it working (in a new project) ... it does not work in my main app


    Picture having a usercontrol with a picturebox and two scrollbars (VS and HS) ...
    (Scrollform control is say on Form1 ... I call ...
    VB Code:
    1. ScrollForm.Form_Draw Form3
    which calls the above procedure ...

    That procedure uses SetParent() to place the form inside of the picturebox (so that Form3 more or less becomes part of Form1, not really sure how to explain it - the title of the main form won't loose focus, although I'm not sure that Form3 can actually gain focus anymore *shrug*)

    Here is a screen to give you a better idea .. Form3 is the one that displays all the information...
    Attached Images Attached Images  
    ~T

  8. #8
    Frenzied Member axion_sa's Avatar
    Join Date
    Jan 2002
    Location
    Joburg, RSA
    Posts
    1,724
    I see what you mean. With a similar project (I think), the mouse wheel message is picked up once, and not at all until re-subclassed. Strange

  9. #9

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    In a New Project ...

    1 Form
    1 Vertical Scrollbar
    No Custom Usercontrol
    No Use Of SetParent() (as there is only one form)

    Works Fine ...

    Using it in my main app shown in the screenshot above, it doesn't work .. No mouse wheel events are sent .. I'm not sure if it's because the form can't get proper focus or what but it's really annoying and bothering me to no end. *Tears hair out*
    ~T

  10. #10

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    Quick Sample Project (with setparent)
    Attached Files Attached Files
    ~T

  11. #11

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    Quick Sample Project (without setparent)
    *works
    Attached Files Attached Files
    ~T

  12. #12

    Thread Starter
    Member
    Join Date
    Mar 2002
    Location
    Canada
    Posts
    51
    *bump

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width