Jump to content

Resize and move window example not working for me, don't know how to change parameters....


xuzo
 Share

Recommended Posts

I have read the help files, and tried the example, but nothing is happening, I see some code 0,0,0,0 and changed settings, but the window does nothing.

How can I change the parameters for window size and position, where in the code and how?

 

#include <MsgBoxConstants.au3>
#include <WinAPI.au3>
#include <WindowsConstants.au3>

Example()

Func Example()
    ; Assign a Local variable the handle of the NotePad window
    Local $hWnd = WinGetHandle("[CLASS:Notepad]")

    ; If the window does not exists, display a message and return False.
    If @error Then
        MsgBox($MB_SYSTEMMODAL, "", "Notepad window not found.")
        Return False
    EndIf

    ; Assign a Local variable the style of the Notepad window.
    Local $iStyle = _WinAPI_GetWindowLong($hWnd, $GWL_STYLE)

    ; Remove from the window style the MAXIMIZEBOX, MINIMIZEBOX and SIZEBOX styles.
    $iStyle = BitXOR($iStyle, $WS_MAXIMIZEBOX, $WS_MINIMIZEBOX, $WS_SIZEBOX)

    ; Set the style of the window.
    _WinAPI_SetWindowLong($hWnd, $GWL_STYLE, $iStyle)

    ; Apply the style
    _WinAPI_SetWindowPos($hWnd, $HWND_TOP, 0, 0, 0, 0, BitOR($SWP_FRAMECHANGED, $SWP_NOMOVE, $SWP_NOSIZE))
EndFunc   ;==>Example

Thanks

Link to comment
Share on other sites

Hi!

This code works perfectly for me, but all it does is removing Notepad window's maximize and minimize buttons, as well as not allowing the window to be resized.

If you want to change a window position and size, you could try using WinMove() function. If you want to get the current window position and size, then use WinGetPos().

Edited by Jefrey
sorry, it's WinMove(), not WinPos()

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

What I am trying to do is this:

 

1. Open a notepad window (it will open on the size it was manually set last time the program ran)

2. Resize the window to 100px. wide  by 100px. high

3. Move the window 100px. on Y axis and move it to 100px. on X axis

Basically, I want to automate grabbing the window by hand and setting it's size with the mouse.

 

Link to comment
Share on other sites

The code in first post seems to be fine. But don't use $SWP_NOMOVE or $SWP_NOSIZE flags in _WinAPI_SetWindowPos if you want to move or resize the window.

Link to comment
Share on other sites

If you want to rely on AutoIt native functions (easier to understand), then here's your code:

Run("notepad.exe")
WinWait("[CLASS:Notepad]")
WinMove("[CLASS:Notepad]", "", 100, 100, 100, 100, 100)

The first line runs Notepad.

The second line waits until Notepad window shows up.

The third line moves Notepad window to 100px in x axis and 100px in y axis, as well as resize it to 100px of width and 100px of height, on a speed of 100, as you said you want to simulate the mouse action (slowest - the minimum is 1 - fastest - and if you just ignore this argument it will move instantly). 

WinMove ( "title", "text", x, y [, width [, height [, speed]]] )

Here's the documentation for that function: https://www.autoitscript.com/autoit3/docs/functions/WinMove.htm 

My stuff

Spoiler

My UDFs  _AuThread multithreading emulation for AutoIt · _ExtInputBox an inputbox with multiple inputs and more features · forceUTF8 fix strings encoding without knowing its original charset · JSONgen JSON generator · _TCPServer UDF multi-client and multi-task (run on background) event-based TCP server easy to do · _TCPClient_UDF multi-server and multi-task (runs on background) event-based TCP client easy to do · ParseURL and ParseStr functions ported from PHP · _CmdLine UDF easily parse command line parameters, keys or flags · AutoPHP Create documents (bills, incomes) from HTML by sending variables/arrays from AutoIt to PHP · (Un)Serialize Convert arrays and data into a storable string (PHP compatible) · RTTL Plays and exports to MP3 Nokia-format monophonic ringtones (for very old cellphones) · I18n library Simple and easy to use localization library · Scripting.Dictionary OOP and OOP-like approach · Buffer/stack limit arrays to N items by removing the last one once the limit is reached · NGBioAPI UDF to work with Nitgen fingerprint readers · Serial/Licensing system require license key based on unique machine ID from your users · HTTP a simple WinHTTP library that allows GET, POST and file uploads · Thread true AutoIt threads (under-dev) · RC4 RC4 encryption compatible with PHP and JS ·  storage.au3 localStorage and sessionStorage for AutoIt Classes _WKHtmlToX uses wkhtmlto* to convert HTML files and webpages into PDF or images (jpg, bmp, gif, png...) Snippets _Word_DocFindReplaceByLongText replace strings using Word UDF with strings longer than 255 characters (MSWord limit) rangeparser parser for printing-like pages interval (e.g.: "1,2,3-5") EnvParser parse strings/paths with environment variables and get full path GUICtrlStaticMarquee static text scrolling Random stuff Super Mario beep sound your ears will hurt

 

Link to comment
Share on other sites

  • 2 years later...

Im having an issue that soon after i move the screen go back to the same position.

I created a infinite while loop after i call the function that moves the screen to check if it was because the script was not running anymore but it is not.

Soon after i resize and position to 0,0 the screen comes back

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

×
×
  • Create New...