Jump to content

Check windows size


AutoDEV
 Share

Recommended Posts

This could be a simple way:

AutoItSetOption('WinTitleMatchMode', 2)

HotKeySet('{ESC}', 'Quit') ; Press ESC to exit the script

Local $aPos[4], $aNewPos[4]

Run('notepad.exe')
WinWait('Notepad')

$aPos = WinGetPos('Notepad')

MsgBox(0, '', 'Press OK and then resize the Notepad window' & @CRLF & 'Check what''s happening in the console')

While True
    $aNewPos = WinGetPos('Notepad')
    If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
    EndIf
    Sleep(10)
WEnd

Func Quit()
    Exit
EndFunc

If it's a window created by you, another way is to register WM_SIZING that is sent to a window after its size has changed.

Edited by Andreik

When the words fail... music speaks.

Link to comment
Share on other sites

ok, ihave make this :

AutoItSetOption('WinTitleMatchMode', 2)

HotKeySet('{ESC}', 'Quit') ; Press ESC to exit the script

Local $aPos[4], $aNewPos[4]

Run('notepad.exe')
WinWait('Sans titre - Bloc-notes')

$aPos = WinGetPos('Sans titre - Bloc-notes')
MsgBox(0, '', 'Position = ' & $aPos[0] & '/' & $aPos[1])

While True
    $aNewPos = WinGetPos('Sans titre - Bloc-notes')
    Global $notepad = WinList("Sans titre - Bloc-notes")
    
    If $aNewPos <> 0 Then
      If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
          $aPos = $aNewPos
          Global $windows = WinMove($notepad[1][0], "", 0, 0, 1024, 768)
          ConsoleWrite('Window has been resized (New pos: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
    EndIf
    Sleep(10)
    EndIf
WEnd

MsgBox(0, '', 'Press OK and then resize the Notepad window' & @CRLF & 'Check what''s happening in the console')

While True
    $aNewPos = WinGetPos('Sans titre - Bloc-notes')
    
    If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
        Global $notepad = WinList("Sans titre - Bloc-notes")
        If $aNewPos <> 0 Then
        $aPos = $aNewPos
        Global $windows = WinMove($notepad[1][0], "", 0, 0, 1024, 768
        ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
    EndIf
    Sleep(10)
    EndIf
WEnd

Func Quit()
    Exit
EndFunc

But i think a code is big for check pos and size.

Edited by AutoDEV
Link to comment
Share on other sites

Try this:

AutoItSetOption('WinTitleMatchMode', 2)

Local $aPos[4], $aNewPos[4]

Run('notepad.exe')
WinWait('Notepad')

$aPos = WinGetPos('Notepad')

MsgBox(0, '', 'Press OK and then resize or move the Notepad window' & @CRLF & 'Check what''s happening in the console')

While WinExists('Notepad')
    $aNewPos = WinGetPos('Notepad')
    If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
    EndIf
    If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
    EndIf
    Sleep(10)
WEnd

 

When the words fail... music speaks.

Link to comment
Share on other sites

AutoItSetOption('WinTitleMatchMode', 2)

    Local $aPos[4], $aNewPos[4]

    Run('notepad.exe')
    WinWait('Sans titre - Bloc-notes')

    $aPos = WinGetPos('Sans titre - Bloc-notes')

    MsgBox(0, '', 'Press OK and then resize or move the Notepad window' & @CRLF & 'Check what''s happening in the console')

    While WinExists('Sans titre - Bloc-notes')
        $aNewPos = WinGetPos('Sans titre - Bloc-notes')
        If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
        EndIf
        If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
        EndIf
        Sleep(10)
    WEnd





Func Example2()

    Local $sFilePath = _WinAPI_GetTempFileName(@TempDir)
    Local $hDownload = InetGet("http://mywebsite.com/download/updates.txt", $sFilePath)
    Global $remoteVersion1 = IniReadSection($sFilePath, 'Update')
    
    If Not @error Then

        For $i = 1 To $remoteVersion1[0][0]

            Switch $remoteVersion1[$i][0]

                Case "ProductVersion"
                    Global $rVersion = $remoteVersion1[$i][1]
                
                    MsgBox(0, 'remoteversion', $rVersion)                   
            EndSwitch
        Next
        
            Global $localVersion = FileGetVersion('myprog.exe')
            ConsoleWrite(@AutoItExe)
            MsgBox(0, 'version Local', $localVersion)
                        
            If $rVersion > $localVersion Then 
                MsgBox(0, 'version', 'Update Avaibale')
            EndIf
    EndIf
    
EndFunc

Example2()

 

Link to comment
Share on other sites

OK.

First i start notepad and i check id is changed.

 

Exemple2() check remote version of program and compare with local.

 

But for continue script i need close notepad.
I want check every time pos and size of notepad and not block a script in this loop.

 

How to make plz ?

Edited by AutoDEV
Link to comment
Share on other sites

I still don't get it. What's the point of checking if the position or the size of notepad has changed with the code from Example2()? You can call Example2() anywhere between While and Wend if you want to keep calling this function but I don't see the point. This code makes no sense.

When the words fail... music speaks.

Link to comment
Share on other sites

For a script is not nimportant to know code.

Just while block code, and not continue.
For continue a script i need close notepad.

I have try with exitloop but after my notepad close but code continuous and work

 

Quote
While WinExists('Sans titre - Bloc-notes')
        $aNewPos = WinGetPos('Sans titre - Bloc-notes')
        If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
            ExitLoop 
        EndIf
        If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
            ExitLoop
        EndIf
        Sleep(10)
    WEnd

 

 

Edited by AutoDEV
Link to comment
Share on other sites

I have cretae exemple.

Look, when i add loop while, all is not working

 

I have same problem with my app

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 195, 47, 192, 124, BitOR($WS_SIZEBOX, $WS_SYSMENU))
$Button1 = GUICtrlCreateButton("OK", 16, 8, 75, 25)
$Button2 = GUICtrlCreateButton("CANCEL", 104, 8, 75, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

AutoItSetOption('WinTitleMatchMode', 2)

Local $aPos[4], $aNewPos[4]


$aPos = WinGetPos($Form1)

    While WinExists('Form1')
        $aNewPos = WinGetPos($form1)
        If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
        EndIf
        If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
        EndIf
        Sleep(10)
    WEnd
    

While 
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
            
        Case $Button1
            MsgBox(0, '', 'Button OK is pressed')
            
        Case $Button2
            MsgBox(0, '', 'Button CANCEL is presses')
    EndSwitch
WEnd

 

Edited by AutoDEV
Link to comment
Share on other sites

All I can see it's that you post code that it doesn't even run.

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

Global $aPos[4], $aNewPos[4]

$Form1 = GUICreate("Form1", 195, 100, 192, 150, BitOR($WS_SIZEBOX, $WS_SYSMENU))
$Button1 = GUICtrlCreateButton("OK", 16, 8, 75, 25)
$Button2 = GUICtrlCreateButton("CANCEL", 104, 8, 75, 25)
GUISetState(@SW_SHOW)

While True
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
        Case $Button1
            MsgBox(0, '', 'Button OK is pressed')
        Case $Button2
            MsgBox(0, '', 'Button CANCEL is presses')
    EndSwitch
    $aNewPos = WinGetPos($form1)
    If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
    EndIf
    If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
    EndIf
WEnd

 

When the words fail... music speaks.

Link to comment
Share on other sites

OK it's working

But why this code not working ?

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

Func _checkChangeWindows()

Global $aPos[4], $aNewPos[4]


Global $fenetre = WinList("Sans titre - Bloc-notes")
WinWait('Sans titre - Bloc-notes')

$aPos = WinGetPos('Sans titre - Bloc-notes')
MsgBox(0, '', 'Position = ' & $aPos[0] & '/' & $aPos[1])

While True
    $aNewPos = WinGetPos($fenetre)
    If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
    EndIf
    If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
    EndIf
WEnd

EndFunc

I have add code, for debug all is ok.

But all after this script not working, exemple inpuit not working

Pelase help me.

Edited by AutoDEV
Link to comment
Share on other sites

Because whatever goes between Func and EndFunc is the body of a function and is not run until that function is called by name.

#include <WindowsConstants.au3>
#include <GUIConstants.au3>

_checkChangeWindows()

Func _checkChangeWindows()

    Global $aPos[4], $aNewPos[4]


    Global $fenetre = WinList("Sans titre - Bloc-notes")
    WinWait('Sans titre - Bloc-notes')

    $aPos = WinGetPos('Sans titre - Bloc-notes')
    MsgBox(0, '', 'Position = ' & $aPos[0] & '/' & $aPos[1])

    While True
        $aNewPos = WinGetPos($fenetre)
        If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
        EndIf
        If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
            $aPos = $aNewPos
            ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
        EndIf
    WEnd

EndFunc

 

When the words fail... music speaks.

Link to comment
Share on other sites

I called a function in my script.

My code is :

Func _checkChangeWindows()

AutoItSetOption('WinTitleMatchMode', 2)

Local $aPos[4], $aNewPos[4]



Global $fenetre = WinList("[CLASS:Notepad]")


        WinActivate($fenetre[1][0])
        WinSetState($fenetre[1][0],"",@SW_MINIMIZE)
        WinSetState($fenetre[1][0],"",@SW_RESTORE)
        Global $windows = WinMove($fenetre[1][0], "", 0, 0, 1024, 768)

$aPos = WinGetPos($fenetre[1][0])

MsgBox(0, '', $aPos[0] & '/' & $aPos[1])

While WinExists("[CLASS:Notepad]")
    $aNewPos = WinGetPos("[CLASS:Notepad]")
    If $aPos[0] <> $aNewPos[0] Or $aPos[1] <> $aNewPos[1] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been repositioned (New position: ' & $aPos[0] & 'x' & $aPos[1] & ').' & @CRLF)
    EndIf
    If $aPos[2] <> $aNewPos[2] Or $aPos[3] <> $aNewPos[3] Then
        $aPos = $aNewPos
        ConsoleWrite('Window has been resized (New size: ' & $aPos[2] & 'x' & $aPos[3] & ').' & @CRLF)
    EndIf
    Sleep(10)
WEnd

EndFunc

And again any button in my form working.
 

and script is blocked waiting

Link to comment
Share on other sites

  • 3 weeks later...

hello.

I have short exemple.

$choice = GUICreate("Custom MsgBox", 225, 80)
GUICtrlCreateLabel("Please select a button.", 10, 10)
Local $idYess = GUICtrlCreateButton("YES", 10, 50, 65, 25)
Local $idNoo = GUICtrlCreateButton("NON", 80, 50, 65, 25)
Local $idExitt = GUICtrlCreateButton("EXIT", 150, 50, 65, 25)
GUISetState(@SW_SHOW, $choice)

;While can must run in background
While 1

    Switch GUIGetMsg()
        Case $idYess
            ConsoleWrite("$idYess=" & $idYess & @CRLF)
            ;ExitLoop
            
        Case $idNoo
            ConsoleWrite("$idNoo=" & $idNoo & @CRLF)

    EndSwitch

WEnd 

MsgBox(0, '', "I want show this msgbox")

Please can you tell me how to continue and not stay in loop while ? For whow show a MsgBox

Is very imposrtant, im try hard without success.

It's my last topic, and if i not success i stop my project.

Thank you

Link to comment
Share on other sites

  • Moderators

AutoDEV,

$choice = GUICreate("Custom MsgBox", 225, 80)
GUICtrlCreateLabel("Please select a button.", 10, 10)
Local $idYess = GUICtrlCreateButton("YES", 10, 50, 65, 25)
Local $idNoo = GUICtrlCreateButton("NON", 80, 50, 65, 25)
Local $idExitt = GUICtrlCreateButton("EXIT", 150, 50, 65, 25)
GUISetState(@SW_SHOW, $choice)

;While can must run in background
While 1

    Switch GUIGetMsg()

        Case $idExitt
            ExitLoop ; or just Exit if you want to leave the script without showing the MsgBox

        Case $idYess
            ConsoleWrite("$idYess=" & $idYess & @CRLF)
            ExitLoop

        Case $idNoo
            ConsoleWrite("$idNoo=" & $idNoo & @CRLF)
            ExitLoop

    EndSwitch

WEnd

MsgBox(0, '', "I want show this msgbox")

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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