Jump to content
Sign in to follow this  
Area751

Cannot move by windowhandle (AutoitX)

Recommended Posts

Area751

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.

Share this post


Link to post
Share on other sites
DarkMatter

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]

Share this post


Link to post
Share on other sites
Area751

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

Share this post


Link to post
Share on other sites
DarkMatter

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]

Share this post


Link to post
Share on other sites
DarkMatter

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]

Share this post


Link to post
Share on other sites
ProgAndy

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

Share this post


Link to post
Share on other sites
DarkMatter

Tried it already... Accepts a string not long you will get a type mismatch.


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

Share this post


Link to post
Share on other sites
SmOke_N

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.

Share this post


Link to post
Share on other sites
Area751

Thanks DarkMatter. I solved it by using user32.dll !

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  

×