Sign in to follow this  
Followers 0
zaduma

VB.NET w/Autoit3X thingy.

8 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



If you were to iterate thru all of the controls within the window would you be able to pick the correct control that way?

If so then you can get at its id.

Otherwise Im not aware of any way to get at a control unless you have its id

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites

Fantastic. Thanks.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

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

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

@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

Share this post


Link to post
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
Sign in to follow this  
Followers 0