• Welcome to Valhalla Legends Archive.
 

More SendMessage issues.

Started by Tazo, February 03, 2007, 09:14 AM

Previous topic - Next topic

Tazo

Once again I'm trying to simulate a mouse click to an inactice window... here's what I have so far:


Private Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" (ByVal hWnd1 As Long, ByVal hWnd2 As Long, ByVal lpsz1 As String, ByVal lpsz2 As String) As Long
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

Private Const WM_LBUTTONDOWN = &H201
Private Const WM_LBUTTONUP = &H202
Private Const WM_PARENTNOTIFY = &H210
Private Const WM_MOUSEACTIVATE = &H21
Private Const HTCLIENT = 1


Private hWndParent As Long
Private hWndChild As Long


Private Sub cmdClickSub_Click()

    Dim lngResult As Long

    lngResult = SendMessage(hWndParent, WM_PARENTNOTIFY, WM_LBUTTONDOWN, MAKELPARAM(466, 301))
       
        Debug.Print "Result: " & lResult
   
    'lngResult = SendMessage(hWndParent, WM_PARENTNOTIFY, WM_LBUTTONUP, MAKELPARAM(466, 301))
    'in Winspector it doesn't show a WM_LBUTTONUP being sent after the WM_LBUTTONDOWN so i'll
    'hold off on that

    lngResult = SendMessage(hWndChild, WM_MOUSEACTIVATE, hWndParent, MAKELPARAM(HTCLIENT, 513))

        Debug.Print "Result: " & lResult

End Sub

Private Sub Form_Load()

    hWndParent = FindWindow("IEFrame", "Fiji - Windows Internet Explorer")
   
    Debug.Print "Parent:    0x" & Hex(hWndParent)

    hWndChild = FindWindowEx(hWndParent, 0&, "TabWindowClass", vbNullString)

    Debug.Print "Child:     0x" & Hex(hWndChild)
   
End Sub

'pulled off the internet, not my code
Public Function MAKELPARAM(wLow As Long, wHigh As Long) As Long
    MAKELPARAM = MAKELONG(wLow, wHigh)
End Function
Public Function MAKELONG(wLow As Long, wHigh As Long) As Long
    MAKELONG = LOWORD(wLow) Or (&H10000 * LOWORD(wHigh))
End Function
Function LOWORD(ByVal dw As Long) As Integer
    If dw And &H8000& Then
        LOWORD = dw Or &HFFFF0000
    Else
        LOWORD = dw And &HFFFF&
    End If
End Function


SendMessage isn't returning anything in the cmdClickSub_click event.
The hWnds match what I see in Winspector.
Can someone point me in the right direction? thanks.

Grok

#1
What do you mean by "isn't returning anything"?
Your Debug.Print is displaying the contents of lngResult, which will definitely have a value, even if that is 0.
So, is it returning 0?

Quote
Return Value
If an application processes this message, it should return zero.

With some after thought, I think you could use some error handling.  It will help you determine what's going on.  My general VB6 error handling is this:


Private Sub cmdClickSub_Click()
   
    On Error Goto cmdClickSub_ClickErr
    'do stuff that might possibly generate an error (pretty much anything)
    'your code goes here
   
cmdClickSub_ClickExit:
    Exit Sub
   
cmdClickSub_ClickErr:
    Select Case Err.Number
    Case 5                  'some handled case or cases
        'followed by the code to handle that case, such as:
        Resume Next
    Case Else
        Debug.Print "ERROR: " & Err.Number & "->" & Err.Description
    End Select
    Resume
   
End Sub


Fix up your code so you are properly alerted to errors and try again.

Tazo

#2
Quote from: Grok on February 03, 2007, 04:29 PM
What do you mean by "isn't returning anything"?
Your Debug.Print is displaying the contents of lngResult, which will definitely have a value, even if that is 0.
So, is it returning 0?

Quote
Return Value
If an application processes this message, it should return zero.

With some after thought, I think you could use some error handling.  It will help you determine what's going on.  My general VB6 error handling is this:


Private Sub cmdClickSub_Click()
   
    On Error Goto cmdClickSub_ClickErr
    'do stuff that might possibly generate an error (pretty much anything)
    'your code goes here
   
cmdClickSub_ClickExit:
    Exit Sub
   
cmdClickSub_ClickErr:
    Select Case Err.Number
    Case 5                  'some handled case or cases
        'followed by the code to handle that case, such as:
        Resume Next
    Case Else
        Debug.Print "ERROR: " & Err.Number & "->" & Err.Description
    End Select
    Resume
   
End Sub


Fix up your code so you are properly alerted to errors and try again.
Oh wow. I had it printing "lResult" to the debug and it should've been "lngResult".

Well, anyways, I'm getting these results: 0 for the first one, 1 for the second.

A return of 1 would be MA_ACTIVATE = Activates the window, and does not discard the mouse message.

I'm not seeing the button being clicked. Even when the IE window is active it isn't clicking.

Hm. I want it sent while the window isn't active, though.

topaz

Isn't VB6 supposed to report errors when you refer to nonexistent variables?
RLY...?

Barabajagal

Only if Option Explicit is at the top of each Module (form, class, or otherwise). You can enable automatic adding of Option Explicit by going to the Options window in vb6, and checking the "Require Variable Declaration" checkbox.

topaz

That's only the editor. It should be raising errors when you refer to absent variables during runtime
RLY...?

Barabajagal

You don't give VB as a language enough credit. Without Option Explicit, the compiled EXE counts all variables as defined when used. It's an amazing feature, so long as you have flawless typing skills.

topaz

VB6 isn't dynamically typed. Please, delete your account again
RLY...?

Barabajagal

Please learn a bit more about languages before you insult them. I'll delete my account again when I want it deleted again, ty.

topaz

You think it's ok for a language to allow the coder to call variables that don't exist? srsly?


You're just as dumb as I thought you were when you put "I Am Not What I Am - iago from Shakesphere". lol @ phonetically spelling your words like a third grader
RLY...?

Barabajagal

I don't remember misspelling Shakespeare's name so terribly, but if I did, I apologize to Will and his family. It's perfectly fine to use variables that haven't been declared if the language supports it, since the COMPILER adds the declarations in automatically. Except that nowadays, it'd probably be defined as Variant, which isn't so good. but when it was originally written, there was one variable type: Variable. The difference was strings had $ at the end and numbers didn't.

topaz

#11
You are a liar.

http://72.14.253.104/search?q=cache:N4D3n2x0FDUJ:www.bnetweb.net/showthread.php%3Fp%3D674+Shakesphere+RealityRipple

Quote
"I am not what I am" - iago(Shakesphere)


There is no point declaring variables that don't exist if they never end up being used (other in the context where they're misspelled)
RLY...?

Barabajagal

Yes, because I don't remember something, and state that I don't remember it, I must be a liar. How wonderful your logic is. Of course there's no point declaring variables that don't exist. Removal of Option Explicit lets you save time by NOT declaring variables and using them anyway. When converted to assembly and compiled to an EXE, the converter adds the declarations automatically.

l2k-Shadow

However, having compiler automatically declare variables can lead to it declaring the variable to something that it shouldn't be, hence your program will then act like shit. Very bad coding practice.
Quote from: replaced on November 04, 2006, 11:54 AM
I dunno wat it means, someone tell me whats ix86 and pmac?
Can someone send me a working bot source (with bnls support) to my email?  Then help me copy and paste it to my bot? ;D
Já jsem byl určenej abych tady žil,
Dával si ovar, křen a k tomu pivo pil.
Tam by ses povídaj jak prase v žitě měl,
Já nechci před nikym sednout si na prdel.

Já nejsem z USA, já nejsem z USA, já vážně nejsem z USA... a snad se proto na mě nezloběj.

Barabajagal

Yes, it is laziness, but if you follow old coding practices, like naming conventions that include a variable representation symbol like $, %, &, etc... it can make things much better, and actually allows for BETTER readability, because all the variables will be labeled by their type.