Jump to content

Displaying Coordinates from WinGetPos()


etidd
 Share

Go to solution Solved by Gianni,

Recommended Posts

Hi all,

First time posting here. I will make a handful of these questions here as I walk through my first AutoIt scripts.

I am attempting to read the contents of the array after running WinGetPos().

Run("C:\Windows\explorer.exe /n, /e, C:\Users\Username\Music\")
WinWaitActive("[ACTIVE]")
Send("^n")
WinWaitActive("[ACTIVE]")
Local $windowSize = WinGetPos("[ACTIVE]")
$coordinateMessage = "X: " + $windowSize[0] + ", Y: " + $windowSize[1] + ", width: " + $windowSize[2] + ", height: " + $windowSize[3]
MsgBox(0, "Current Window Coordinates", $coordinateMessage)
; MouseClickDrag("left", )

The message box does not preserve the string inside of $coordinateMessage.

It simply says the message box title and an integer. The last one only said "1946" and nothing else.

Perhaps I have used MsgBox() incorrectly.

 

Thanks in advance for any suggestions. Hopefully this is super easy for somebody to figure out my newbie mistake. 😜

Edited by etidd
Link to comment
Share on other sites

18 minutes ago, Gianni said:

use the "&" for strings concatenation not "+"

Yes.

@etidd : ... and you can use underscore  _  for multiline concatenation. Example :

Local $sMainStr
Local $sStr1 = "Happy ", $sStr2 = "New ", $sStr3 = "Year"

; & for concatenation (one line) :
$sMainStr = $sStr1 & $sStr2 & $sStr3
ConsoleWrite($sMainStr & @CRLF)

; & _ for multiline concatenation :
$sMainStr = $sStr1 & _
            $sStr2 & _
            $sStr3
ConsoleWrite($sMainStr & @CRLF)

 

Musashi-C64.png

"In the beginning the Universe was created. This has made a lot of people very angry and been widely regarded as a bad move."

Link to comment
Share on other sites

... and this line

Run("C:\Windows\explorer.exe /n, /e, " & @UserProfileDir & "\Music\")

instead

Run("C:\Windows\explorer.exe /n, /e, C:\Users\Username\Music\")

 

and in line WinWaitActive("[ACTIVE]")

what window are you waiting for ?  :think:

I know that I know nothing

Link to comment
Share on other sites

Great replies, all.

I learned a lot including the use of underscores for multiline concatenation.

The reason the message was originally producing an integer was because the + signs were causing an addition operation of each index in the array.

Edited by etidd
Link to comment
Share on other sites

19 hours ago, etidd said:

I am attempting to read the contents of the array after running WinGetPos().

If you're just wanting to see what the array contains as part of your development process while you're writing or debugging a script, have a look at the _ArrayDisplay UDF (user-defined function).

For example:

#include <Array.au3>

Local $windowSize = WinGetPos("[ACTIVE]")
_ArrayDisplay($windowSize, "Current Window Coordinates")

By the way,

WinWaitActive("[ACTIVE]")

really doesn't do anything since you're asking AutoIt to wait for the currently active window to become active. So there's nothing to wait for. It's like saying 'wait until 1 equals 1.' It's always immediately true and therefore is meaningless.

If you want it to actually wait for a specific window to become active, you need to specify what window by passing either the Title and Text of the window, the window handle, or else using the advanced method for identifying the window.

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