Jump to content

Cannot move by windowhandle (AutoitX)


Recommended Posts

I'm using AutoItX as COM object in Csharp.

string handle = oAutoIt.WinGetHandle("Untitled - Notepad","");

oAutoIt.WinMove(handle,"",0,0,640,480);

I can't get this to work.

Does anyone know what I am doing wrong?

It works perfectly if I use WinMove() function with "Untitled - Notepad" instead of passing the handle.

Thanks.

Link to comment
Share on other sites

WinMove accepts the Title of the window only. Not a handle.

This is in VB.NET 2005:

Imports AutoItX3Lib

Public Class Form1
    Dim oAutoit As AutoItX3

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        oAutoit = New AutoItX3

        oAutoit.WinMove("Untitled - Notepad", "", 0, 0, 640, 480)
    End Sub
End Class
Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

WinMove accepts the Title of the window only. Not a handle.

I am going to have multiple windows with the same Title. That's why I wanted to use the handle.

Is there a solution for this?

BTW I found in the documentation that every function that accepts a title, can also be used by providing the handle to the window. So it seems that WinMove is an exception to this rule?

edit: the documentation is at the bottom of this page: http://hiddensoft.com/autoit3/docs/intro/windowsadvanced.htm

Edited by Area751
Link to comment
Share on other sites

I think it might be an exception for the COMObject itself.

If you do the following:

Dim Handle As String

        oAutoIT = New AutoItX3

        Handle = oAutoIT.WinGetHandle("Untitled - Notepad")
        Debug.WriteLine(oAutoIT.WinMove(Handle, "", 0, 0, 480, 600))

0 is written to the debug window.

Return Value

Success: Returns 1.

Failure: Returns 0 if window is not found.

0 is indicating that the window was not found.

Now what you could do is just do a straight call to MoveWindow in user32.dll

Public Declare Auto Function MoveWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal X As Int32, ByVal Y As Int32, ByVal nWidth As Int32, _

ByVal nHeight As Int32, ByVal bRepaint As Boolean) As Boolean

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

Here is some sample code of what I was talking about in VB.NET 2005:

Full Code:

Private Declare Function MoveWindow Lib "user32.dll" (ByVal hWnd As IntPtr, ByVal X As Int32, ByVal Y As Int32, ByVal nWidth As Int32, ByVal nHeight As Int32, ByVal bRepaint As Boolean) As Boolean
    Private Declare Auto Function FindWindow Lib "user32.dll" (ByVal lpClassName As String, ByVal lpWindowName As String) As IntPtr

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim Handle As IntPtr

        Handle = FindWindow(Nothing, "Untitled - Notepad")

        MoveWindow(Handle, 0, 0, 480, 600, True)
    End Sub

Plus this is a cleaner way than having DLLs with your app...

Edited by DarkMatter

[sub]Quantum mechanics: The dreams stuff is made of[/sub]

Link to comment
Share on other sites

Mybe the AutoIt-Code would work, if you used

Dim Handle As Long

*GERMAN* [note: you are not allowed to remove author / modified info from my UDFs]My UDFs:[_SetImageBinaryToCtrl] [_TaskDialog] [AutoItObject] [Animated GIF (GDI+)] [ClipPut for Image] [FreeImage] [GDI32 UDFs] [GDIPlus Progressbar] [Hotkey-Selector] [Multiline Inputbox] [MySQL without ODBC] [RichEdit UDFs] [SpeechAPI Example] [WinHTTP]UDFs included in AutoIt: FTP_Ex (as FTPEx), _WinAPI_SetLayeredWindowAttributes

Link to comment
Share on other sites

  • Moderators

I am going to have multiple windows with the same Title. That's why I wanted to use the handle.

Is there a solution for this?

BTW I found in the documentation that every function that accepts a title, can also be used by providing the handle to the window. So it seems that WinMove is an exception to this rule?

edit: the documentation is at the bottom of this page: http://hiddensoft.com/autoit3/docs/intro/windowsadvanced.htm

You are looking at the online documentation for AutoIt itself, not the AutoItX.

Since autoit itself handles variant data types, I'd suggest maybe making one yourself with MoveWindow and overloading the function(s) to accept strings/hwnds...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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...