Resizing windows with AutoIt

How to resize windows using the AutoIt scripting language.

5798 views
d

By. Jacob

Edited: 2019-09-11 16:17

In AutoIt, we use the same function to resize windows, as we do to move windows. When resizing windows with AutoIt, there are at least a few functions that are useful to know about. The WinWait, WinActivate and the WinMove functions.

The WinWait function will first wait for the window to appear, after which we can do whatever else we want with it.

$hWnd = WinWait("[CLASS:SpotifyMainWindow]", "", 10)

Note that we also created a window handle ($hWnd) in the script, this allows us to easily work with the window later, without having to repeat the title of the window throughout the script. The added benefit of doing this, is that if the application is updated by the creators, and the title changes, you will only have to change it one place in your script.

Before we can move a window, we will also need to activate it, this can be done using the WinActivate function, and the handle we created ealier.

WinActivate($hWnd)

And now, finally we may resize and move the window using WinMove.

$hWnd = WinWait("[CLASS:SpotifyMainWindow]", "", 10)
WinActivate($hWnd)
WinMove("[CLASS:SpotifyMainWindow]", "", 0, 0, 200, 200)

Avoiding that the window moves when resizing

Because we are using the same function to resize windows, that we also use to move windows, we may want to avoid moving the window. Using the Default keyword in place of the x and y coordinates, will effectively resize the window without moving it from its original position.

WinMove("[CLASS:SpotifyMainWindow]", "", Default, Default, 200, 200)

Tell us what you think:

  1. How to declare and work with variables in AutoIt, as well as some background information.
  2. Everything you need to know about working with minimized windows.
  3. How to set the request headers when performing HTTP requests.
  4. This Tutorial will focus on post requests in AutoIt, using the Winhttprequest.5.1 object.
  5. How to use while, for, and do until loops, and how to loop through arrays and object in AutoIt.

More in: AutoIt Tutorials