Results 1 to 8 of 8

Thread: [RESOLVED] Postmessage - x,y coordinates wrong (MakeDWord)

  1. #1

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Resolved [RESOLVED] Postmessage - x,y coordinates wrong (MakeDWord)

    (I had another thread dealing with my current problem - but my needs evolved so I think a new thread couldn't hurt - also helping me to reach more people)

    Here's the code I use. PostMessage sends a click on my vb-form, and the Form_MouseDown reacts to it by msgbox'ing the coordinates.

    Code:
    Private Sub Form_MouseDown(Button As Integer, Shift As Integer, X As Single, y As Single)
        MsgBox "x: " & X & " y: " & y
    End Sub
    
    Private Sub Command2_Click()    
            Call PostMessage(Me.hwnd, WM_LBUTTONDOWN, 0&, MakeDWord(200, 200))
            Call PostMessage(Me.hwnd, WM_LBUTTONUP, 0&, 0&)
    End Sub
    When clicking Command2, the Form_MouseDown even *IS* fired, but always white those coords: x: -45600 y:285. No matter what value I send to MakeDWord, I end up with -45600,285.

    Code:
    Private Declare Function PostMessage& Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any)
    
    Function MakeDWord(LoWord As Integer, HiWord As Integer) As Long
        MakeDWord = (HiWord * &H10000) Or (LoWord And &HFFFF&)
    End Function
    ...Am I missing something here?

    Using winspector, I've been spying on the form. Here are the results:

    When manually cliking the form:
    Code:
    WM_LBUTTONDOWN - Mouse coordinates:  325,184
    WM_LBUTTONDOWN - Mouse coordinates:  325,184, Button pressed:  MK_LBUTTON
    WM_LBUTTONUP - wParam:  0x00000001, lParam: 0x00b80145
    WM_LBUTTONUP - wParam:  0x00000000, lParam: 0x00b80145
    when using Command2_Click
    Code:
    WM_LBUTTONDOWN - Mouse coordinates:  -3200, 19
    WM_LBUTTONDOWN - Mouse coordinates:  -3200, 19
    WM_LBUTTONUP - wParam:  0x00000000, lParam: 0x0013f380
    WM_LBUTTONUP - wParam:  0x00000000, lParam: 0x0013f380
    Even tho the 2nd solution shows -3200, 19, the msgbox still shows "-45600,285" - OH, actually I just noticed the msgbox now shows "-48000,285" (I think those numbers changed because I've closed and rerunned my VB app).

    Odd.

    Any feedback VERY welcome.

    (Edit: I did try SendMessage instead, ending up with the same results)
    Last edited by Krass; May 30th, 2007 at 03:20 PM.
    Chris

  2. #2
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Postmessage - x,y coordinates wrong (MakeDWord)

    Pass the lParam argument ByVal

    Call PostMessage(Me.hwnd, WM_LBUTTONDOWN, 0&, Byval MakeDWord(200, 200))

  3. #3

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Postmessage - x,y coordinates wrong (MakeDWord)

    I've spent a total of 10 hours in the last 2 days trying to make this work.

    You solved it all in one line.

    **THANKS**

    (I'm not yet putting that thread as resolved as I might need some futher help on the subject)
    Chris

  4. #4
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: Postmessage - x,y coordinates wrong (MakeDWord)

    I don't completely understand all this ByVal, lparam As Any, MakeDWord stuff...

    The declaration of your PostMessage statement is different than the declaration from the API Viewer which led me to try ByVal.

    Here is the API Viewer declaration

    Private Declare Function PostMessage Lib "user32" Alias "PostMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

    You could use the above with your original statement.

  5. #5

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Postmessage - x,y coordinates wrong (MakeDWord)

    I was trying the postmessage technique in such an easy situation, to get used to it.

    I'm now back to my primary goal... This might go over your knowledge, if not, I'll very gladly receive your help.

    I had an entire empty form, now I covered it up entirely with a webbrowser control. I'll want to simulate click on it... WITH postmessage. No Mouseevent, since I'd want the whole solution to work when the app is even minimzed.

    I've been told to get the webbrowser hwnd that way:

    Code:
    Dim webhwnd as Long
    webhwnd = FindWindowEx(Me.hwnd, 0, "Shell Embedding", vbNullString)
    I then tried:
    Code:
    Call PostMessage(webwhnd, WM_LBUTTONDOWN, 0&, ByVal MakeDWord(Int(Rnd * 7000), Int(Rnd * 7000)))
    I've watched the webbrowser with Winspector, and can see it reacting to me clicking the mouse here and there in the browser, but postmessage doesn't seem to reach the browser as Winspector doesn't show up anything.

    I'll make some further tests... meanwhile, if that's something you already did, I'm open to all the code you might have handy

    Thanks again, pal

    (Edit: I'm used to different webbrowser techniques to click buttons, dropdowns, edit value or extract links and stuff - but in my case, I will need to click at x,y a couple of time)
    Chris

  6. #6

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Postmessage - x,y coordinates wrong (MakeDWord)

    I've worked on it a little... I had a typo somewhere in my code when using the "Internet Explorer_Server" HWND. (my previous post's method for retrieving the hwnd was FALSE - just ask if someone needs the code)

    I've made a huge loop with postmessage inside with random x,y coords, and I can now see Winspector receiving all the clicks I am simulating.

    Also, by looking at the webpage on my form, I can see that the items are actually focussed (I can see the rectangle surrounding images appearing when I randomly click on them).

    They get "focus", but they don't get clicked, as the webbrower isn't browsing/loading any page when clicking those links/picture-links.

    So, I'm near my goal, but it's quite it yet. I'll keep on working on it - but I'm pretty confused as to what I should try, now.

    Any help greatly appreciated.
    Chris

  7. #7

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Postmessage - x,y coordinates wrong (MakeDWord)

    *bump #1*
    Chris

  8. #8

    Thread Starter
    Hyperactive Member Krass's Avatar
    Join Date
    Aug 2000
    Location
    Montreal
    Posts
    489

    Re: Postmessage - x,y coordinates wrong (MakeDWord)

    Just remembered this thread was about a problem of WRONG X,Y coords sent using MakeDWord so I'm marking this thread as resolved.

    If anyone needs help on the subject, post to this thread.

    Thanks
    Chris

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