Results 1 to 8 of 8

Thread: [RESOLVED] hmmm MouseMove in webbrowser control

  1. #1

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Resolved [RESOLVED] hmmm MouseMove in webbrowser control

    yo!
    Is there any way to get the mousemove event in the webbrowser control?
    Thanks









    Added green "resolved" checkmark - Hack
    Last edited by Hack; Nov 14th, 2005 at 09:40 AM.
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  2. #2
    Frenzied Member wiz126's Avatar
    Join Date
    Jul 2005
    Location
    Mars,Milky Way... Chit Chat Posts: 5,733
    Posts
    1,080

    Re: hmmm MouseMove in webbrowser control

    well not in a webbrowser control but you could put a timer insted, it will work just as well.
    what are you trying to do?
    1) If your post has been adequately answered please click in your post on "Mark Thread Resolved".
    2) If someone has been useful to you please show your respect by rating their posts.
    3) Please use [highlight="VB"] 'your code goes in here [/highlight] tags when posting code.
    4) Before posting your question, make sure you checked this links:
    MICROSOFT MSDN -- VB FORUMS SEARCH

    5)Support Classic VB - A PETITION TO MICROSOFT

    ___________________________________________________________________________________
    THINGS TO KNOW ABOUT VB: || VB Examples/Demos
    What are Classes?
    || -
    Where to place a sub/function?(global) || Webbrowser control

  3. #3

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: hmmm MouseMove in webbrowser control

    this is my code:

    VB Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, x As Single, y As Single)
    2.         Call GetCursorPos(MousePos)
    3.     If (MousePos.x * 15.0117279124316) >= (Screen.Width - 200) Then
    4.         Timer3.Enabled = True
    5.     End If
    6.     If (MousePos.x * 15.0117279124316) <= 200 Then
    7.         Timer4.Enabled = True
    8.     End If
    9.  
    10. End Sub

    If the mouse x coordinate is to the right of the screen, it activates timer3 ( wich is set to 1500 miliseconds)
    And when the timer has counted to 1500 miliseconds, it checks the mouse position once again, and if the mouseposition is to the left of the screen this time, the webbrowser control goes "back in the history".

    Thats what im trying to do, shortcuts to back and forward in the webbrowser.
    The problem is that the webbrowser is covering most of the screen, so i would like to have the mousemove event there instead...

    Atheist
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  4. #4
    Fanatic Member paralinx's Avatar
    Join Date
    Jun 2005
    Location
    Michigan
    Posts
    987

    Re: hmmm MouseMove in webbrowser control

    Quote Originally Posted by Atheist
    yo!
    Is there any way to get the mousemove event in the webbrowser control?
    Thanks
    why not try something like:

    VB Code:
    1. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    2.     If X >= WebBrowser1.Left And Y <= WebBrowser1.Left + WebBrowser1.Width Then
    3.         WebBrowser1.Navigate "www.google.com"
    4.     End If
    5. End Sub

  5. #5
    Old Member moeur's Avatar
    Join Date
    Nov 2004
    Location
    Wait'n for Free Stuff
    Posts
    2,712

    Re: hmmm MouseMove in webbrowser control

    You can generate a mouse move event using a mouse hook like this
    In a Module
    VB Code:
    1. Option Explicit
    2.  
    3. Private Type POINTAPI
    4.         x As Long
    5.         y As Long
    6. End Type
    7.  
    8. Private Type MOUSEHOOKSTRUCT
    9.         pt As POINTAPI
    10.         hwnd As Long
    11.         wHitTestCode As Long
    12.         dwExtraInfo As Long
    13. End Type
    14.  
    15. Private lpPrevWndProc As Long
    16. Private IsHooked As Boolean
    17.  
    18. Private Const WH_MOUSE = 7
    19. Private Const WM_MOUSEMOVE = &H200
    20.  
    21. Private Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" ( _
    22.     ByVal idHook As Long, _
    23.     ByVal lpfn As Long, _
    24.     ByVal hmod As Long, _
    25.     ByVal dwThreadId As Long _
    26. ) As Long
    27.  
    28. Private Declare Function UnhookWindowsHookEx Lib "user32" ( _
    29.     ByVal hHook As Long _
    30. ) As Long
    31.  
    32. Private Declare Function CallNextHookEx Lib "user32" ( _
    33.     ByVal hHook As Long, _
    34.     ByVal ncode As Long, _
    35.     ByVal wParam As Long, _
    36.     lParam As Any _
    37. ) As Long
    38.  
    39. Public Sub SetMouseHook()
    40.     If Not IsHooked Then
    41.         lpPrevWndProc = SetWindowsHookEx(WH_MOUSE, AddressOf MouseProc, 0, App.ThreadID)
    42.         IsHooked = True
    43.     End If
    44. End Sub
    45.  
    46. Public Sub RemoveMouseHook()
    47.     UnhookWindowsHookEx lpPrevWndProc
    48.     IsHooked = False
    49. End Sub
    50.  
    51. Public Function MouseProc(ByVal uCode As Long, ByVal wParam As Long, lParam As MOUSEHOOKSTRUCT) As Long
    52.     If uCode < 0 Then
    53.         MouseProc = CallNextHookEx(lpPrevWndProc, uCode, wParam, lParam)
    54.     Else
    55.         Select Case wParam
    56.         Case WM_MOUSEMOVE
    57.             'here is your mouse move event
    58.             Debug.Print "Mouse Move: "; lParam.pt.x; lParam.pt.y
    59.         End Select
    60.            
    61.         MouseProc = CallNextHookEx(lpPrevWndProc, uCode, wParam, lParam)
    62.     End If
    63. End Function
    In your Form
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     SetMouseHook
    5. End Sub
    6.  
    7. Private Sub Form_Unload(Cancel As Integer)
    8.     RemoveMouseHook
    9. End Sub

  6. #6
    Fanatic Member TheVader's Avatar
    Join Date
    Oct 2002
    Location
    Rotterdam, the Netherlands
    Posts
    871

    Re: hmmm MouseMove in webbrowser control

    This is probably the easiest way to go.

    Add 'Microsoft HTML Object Library' as a reference.
    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents objDocument As HTMLDocument
    4.  
    5. Private Sub Form_Load()
    6.     WebBrowser1.Navigate2 "http://www.google.com"
    7. End Sub
    8.  
    9. Private Sub objDocument_onmousemove()
    10.     Debug.Print "mouse moved: " & objDocument.parentWindow.event.clientX & "x" & objDocument.parentWindow.event.clientY
    11. End Sub
    12.  
    13. Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    14.     Set objDocument = WebBrowser1.Document
    15. End Sub
    Author for Visual Basic Web Magazine

    My articles on the Web Browser Control:
    Using the Web Browser Control & Using the DHTML Document Object Model

    The examples referenced in the articles can be found here:

  7. #7

    Thread Starter
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: hmmm MouseMove in webbrowser control

    oh thank you Vader!
    And thanks to all the rest of you aswell
    Finally got it working now
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  8. #8
    Hyperactive Member
    Join Date
    Nov 2001
    Posts
    377

    Re: hmmm MouseMove in webbrowser control

    how can i use this code to tell the mouse to go to 175x 94y on the webbrowser then left click?

    Quote Originally Posted by TheVader
    This is probably the easiest way to go.

    Add 'Microsoft HTML Object Library' as a reference.
    VB Code:
    1. Option Explicit
    2.  
    3. Dim WithEvents objDocument As HTMLDocument
    4.  
    5. Private Sub Form_Load()
    6.     WebBrowser1.Navigate2 "http://www.google.com"
    7. End Sub
    8.  
    9. Private Sub objDocument_onmousemove()
    10.     Debug.Print "mouse moved: " & objDocument.parentWindow.event.clientX & "x" & objDocument.parentWindow.event.clientY
    11. End Sub
    12.  
    13. Private Sub WebBrowser1_NavigateComplete2(ByVal pDisp As Object, URL As Variant)
    14.     Set objDocument = WebBrowser1.Document
    15. End Sub

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