Jump to content

VB.NET w/Autoit3X thingy.


zaduma
 Share

Recommended Posts

here is kinda what my code looks like

CODE

dim autoit As New AutoItX3Lib.AutoItX3

dim s as string

public sub dostuff()

s = autoit.ControlGetText("Application", "", ID)

msgbox(s)

end sub

I of course get teh control ID from AutoIt Window Info...

The application will work perfectly if I just have opened it, but everytime I open the application there is a new Control ID for the area I want to get text out of.

So i was wondering if there is a function like "autoit.GetControlFromPixel(x,y)" and I am blind, or what?

P.S. The ClassNameNN changes as well.

Thanks in advance

Edited by zaduma
Link to comment
Share on other sites

Without solving your problem for you (tempting as it is...), remember that every control is also a window. Once that is understood, a tremendous chunk of the Win32 API begins to make sense.

Here is code in regular AutoIt to get a control from a point:

; WindowFromPoint (thanks Larry!)
Func WindowFromPoint()
    Local $point, $cHwnd, $hwnd, $pos, $size
    Local $dll = dllopen("user32.dll")
    $point = MouseGetPos()
    $hwnd = DLLCall($dll, "hwnd", "WindowFromPoint", "int", $point[0], "int", $point[1])
    If $hwnd[0] <> 0 Then
        $pos = WinGetPos($hwnd[0])
        If @error Then Return 0
        $size = WinGetClientSize($hwnd[0])
        If @error Then Return 0
        $pos[0] += (($pos[2] - $size[0]) / 2)
        $pos[1] += (($pos[3] - $size[1]) - (($pos[2] - $size[0]) / 2))
        $cHwnd = DLLCall($dll,"hwnd","RealChildWindowFromPoint","hwnd",$hwnd[0], _
                    "int",$point[0] - $pos[0],"int",$point[1] - $pos[1])
        If $cHwnd[0] <> 0 Then $hwnd[0] = $cHwnd[0]
    EndIf
    DLLClose($dll)
    Return $hwnd[0]
EndFunc

In AutoItX, the MouseGetPos, WinGetPos, and WinGetClientSize functions are split up into X and Y, but you probably already noticed that. Naturally, you can accept X and Y as parameters instead of using the mouse position. The DLLCall is the tricky part, but it can be replaced with a function made with the DLLImport attribute.

PInvoke.net gives the C# signatures (easy enough to translate) for RealChildWindowFromPoint and WindowFromPoint as:

[DllImport("user32.dll")]
 static extern IntPtr RealChildWindowFromPoint(IntPtr hwndParent,
    POINT ptParentClientCoords);

[DllImport("user32.dll")]
 static extern IntPtr WindowFromPoint(POINT Point);

You will also need this (which is already in VB.Net):

<System.Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential)> _
     Public Structure POINT
     Public X As Integer
     Public Y As Integer
  
     Public Sub New(ByVal X As Integer, ByVal Y As Integer)
         Me.X = X
         Me.Y = Y
     End Sub
     End Structure

See MSDN for additional info on those.

Suppose that you are uncomfortable with handles for whatever reason, and wanted to get the control ID; you can feed the handle from the above function into this GetDlgCtrlID, and it will give you the exact same thing the AU3InfoTool will.

[DllImport("user32.dll")]
static extern int GetDlgCtrlID(IntPtr hwndCtl);

The rest should be fairly straightforward, and I think the resulting code should work on any 32-bit system after Win95. Good luck!

Edited by sohfeyr
Link to comment
Share on other sites

Without solving your problem for you (tempting as it is...), remember that every control is also a window. Once that is understood, a tremendous chunk of the Win32 API begins to make sense.

Yeah to bad you didn't help, I wish you would have.

I did not come here because I wanted cryptic messages that may hide the actual code needed, I want a line or segment of code to do the function I wanted, If you can not do this then please do not respond as your input is rather uneccesary.

I needed VB.net with autoitx, nothing else.

Edited by zaduma
Link to comment
Share on other sites

@jvetter: You're welcome! Glad to help.

@zaduma: You're not. I came inches within solving your programming problem. I gave you sliced bread, meat and cheese, and you complain I didn't give you a sandwich. If you need help with laziness, seek the help of a licensed therapist - or perhaps find someone to do it for you. You have all the grace and problem-solving skills of a cinderblock tumbling down a mountain, and will receive no further assistance, or replies, from me.

Link to comment
Share on other sites

  • 1 year later...

@zaduma: You're not. I came inches within solving your programming problem. I gave you sliced bread, meat and cheese, and you complain I didn't give you a sandwich. If you need help with laziness, seek the help of a licensed therapist - or perhaps find someone to do it for you. You have all the grace and problem-solving skills of a cinderblock tumbling down a mountain, and will receive no further assistance, or replies, from me.

Am I allowed to just post a laugh? :P

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...