Sign in to follow this  
Followers 0
vladedoty

problems moving windows to coordinates

9 posts in this topic

sometimes my window move and sometimes they don't.

was wondering if there was a more concrete way for an array of windows to move to their destination

i've tried winmove which works sometimes, and _WinAPI_SetWindowPos which i'm not sure if i'm using correctly

here is my code

#include <array.au3>
#include <WinAPI.au3>
Func StartProcess($titleN)
    Opt("WinWaitDelay", 100)
    Opt("WinTitleMatchMode", 2)
    Opt("WinDetectHiddenText", 1)
    Opt("MouseCoordMode", 0)
    Global $titWin
    Global $handleWin
If $Num == "1" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
    ElseIf $botNum == "2" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
    ElseIf $botNum == "3" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
    ElseIf $botNum == "4" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
        $positionx[3] = ControlGetText($mainGUI, "", $x4Txt)
        $positiony[3] = ControlGetText($mainGUI, "", $y4Txt)
    ElseIf $botNum == "5" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
        $positionx[3] = ControlGetText($mainGUI, "", $x4Txt)
        $positiony[3] = ControlGetText($mainGUI, "", $y4Txt)
        $positionx[4] = ControlGetText($mainGUI, "", $x5Txt)
        $positiony[4] = ControlGetText($mainGUI, "", $y5Txt)
    Else
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positionx[3] = ControlGetText($mainGUI, "", $x4Txt)
        $positionx[4] = ControlGetText($mainGUI, "", $x5Txt)
        $positionx[5] = ControlGetText($mainGUI, "", $x6Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
        $positiony[3] = ControlGetText($mainGUI, "", $y4Txt)
        $positiony[4] = ControlGetText($mainGUI, "", $y5Txt)
        $positiony[5] = ControlGetText($mainGUI, "", $y6Txt)
    EndIf

For $a = 0 To ($Num - 1)
        Do
            Sleep(100)
        Until WinExists($titleN[$a], "")
        If WinExists($titleN[$a], "") Then
            WinWait($titleN[$a], "")
            If Not WinActive($titleN[$a], "") Then WinActivate("$", "")
            WinWaitActive($titleN[$a], "")
            ;$titWin[0] = WinGetTitle("$", "")
            $titWin = WinGetTitle($titleN[$a], "")
            $handleWin = WinGetHandle($titleN[$a], "")
            _WinAPI_SetWindowPos($handleWin, $HWND_BOTTOM, $positionx[$a], $positiony[$a], 802, 574, $SWP_NOZORDER)
            ;WinMove($titWin, "", $positionx[$a], $positiony[$a])
endif
next

endfunc()

Share this post


Link to post
Share on other sites



sometimes my window move and sometimes they don't.

was wondering if there was a more concrete way for an array of windows to move to their destination

i've tried winmove which works sometimes, and _WinAPI_SetWindowPos which i'm not sure if i'm using correctly

here is my code

#include <array.au3>
#include <WinAPI.au3>
Func StartProcess($titleN)
    Opt("WinWaitDelay", 100)
    Opt("WinTitleMatchMode", 2)
    Opt("WinDetectHiddenText", 1)
    Opt("MouseCoordMode", 0)
    Global $titWin
    Global $handleWin
If $Num == "1" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
    ElseIf $botNum == "2" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
    ElseIf $botNum == "3" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
    ElseIf $botNum == "4" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
        $positionx[3] = ControlGetText($mainGUI, "", $x4Txt)
        $positiony[3] = ControlGetText($mainGUI, "", $y4Txt)
    ElseIf $botNum == "5" Then
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
        $positionx[3] = ControlGetText($mainGUI, "", $x4Txt)
        $positiony[3] = ControlGetText($mainGUI, "", $y4Txt)
        $positionx[4] = ControlGetText($mainGUI, "", $x5Txt)
        $positiony[4] = ControlGetText($mainGUI, "", $y5Txt)
    Else
        $positionx[0] = ControlGetText($mainGUI, "", $x1Txt)
        $positionx[1] = ControlGetText($mainGUI, "", $x2Txt)
        $positionx[2] = ControlGetText($mainGUI, "", $x3Txt)
        $positionx[3] = ControlGetText($mainGUI, "", $x4Txt)
        $positionx[4] = ControlGetText($mainGUI, "", $x5Txt)
        $positionx[5] = ControlGetText($mainGUI, "", $x6Txt)
        $positiony[0] = ControlGetText($mainGUI, "", $y1Txt)
        $positiony[1] = ControlGetText($mainGUI, "", $y2Txt)
        $positiony[2] = ControlGetText($mainGUI, "", $y3Txt)
        $positiony[3] = ControlGetText($mainGUI, "", $y4Txt)
        $positiony[4] = ControlGetText($mainGUI, "", $y5Txt)
        $positiony[5] = ControlGetText($mainGUI, "", $y6Txt)
    EndIf

For $a = 0 To ($Num - 1)
        Do
            Sleep(100)
        Until WinExists($titleN[$a], "")
        If WinExists($titleN[$a], "") Then
            WinWait($titleN[$a], "")
            If Not WinActive($titleN[$a], "") Then WinActivate("$", "")
            WinWaitActive($titleN[$a], "")
            ;$titWin[0] = WinGetTitle("$", "")
            $titWin = WinGetTitle($titleN[$a], "")
            $handleWin = WinGetHandle($titleN[$a], "")
            _WinAPI_SetWindowPos($handleWin, $HWND_BOTTOM, $positionx[$a], $positiony[$a], 802, 574, $SWP_NOZORDER)
            ;WinMove($titWin, "", $positionx[$a], $positiony[$a])
endif
next

endfunc()

Now the WinMove doesn;t work properly

I'm lost

Share this post


Link to post
Share on other sites

Provide a short demo that can actually be run. You seem to expect others to code a complete test script to try using your functions, undefined global variables and all...

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Provide a short demo that can actually be run. You seem to expect others to code a complete test script to try using your functions, undefined global variables and all...

:)

I have a similar problem. At work in a constraction "for..next" moving of a window sometimes they don't.. It can depends on the program where the script is carried out? Edited by Vlasssov

Share this post


Link to post
Share on other sites

; Run Notepad
Run("notepad.exe")
; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
WinWaitActive("Untitled - Notepad")
winmove("Untitled - Notepad","",0,0)
$n=10
for $i=1 to $n
send("Text"&$i)
;save
MouseClick("left",15,34,1,0)
for $j=1 to 4
Send("{down}")
Next
Send("{Enter}")
WinWaitActive("Open")
winmove("Open","",0,0)
Send("c:\proekt\a\file"&$i&".txt")
Send("{Enter}")

Next

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

; Run Notepad
Run("notepad.exe")
; Wait for the Notepad become active - it is titled "Untitled - Notepad" on English systems
WinWaitActive("Untitled - Notepad")
winmove("Untitled - Notepad","",0,0)
$n=10
for $i=1 to $n
send("Text"&$i)
;save
MouseClick("left",15,34,1,0)
for $j=1 to 4
Send("{down}")
Next
Send("{Enter}")
WinWaitActive("Open")
winmove("Open","",0,0)
Send("c:\proekt\a\file"&$i&".txt")
Send("{Enter}")

Next
You might find something like this more reliable:
Run("notepad.exe")
WinWait("Untitled - Notepad")
$hNotepad = WinGetHandle("Untitled - Notepad")
WinMove($hNotepad, "", 0, 0)
For $i = 1 To 10
    ControlSend($hNotepad, "", "Edit1", "Text" & $i & @CRLF)
    ControlSend($hNotepad, "", "", "!fa") ; Alt-f, a = Save As
    WinWait("Save As")
    $hSaveAs = WinGetHandle("Save As")
    WinMove($hSaveAs, "", 0, 0)
    ControlSend($hSaveAs, "", "Edit1", @ScriptDir & "\file" & $i & ".txt")
    ControlSend($hSaveAs, "", "", "!s") ; Alt-s = Save
    WinWaitClose($hSaveAs)
Next

Note the use of window handles, hotkeys, and ControlSend(). For example, once you save the file, the window title changes and won't match anymore, but the handle still works.

:)

P.S. Of course, if writing text to the files is the object, you don't need Notepad at all:

For $i = 1 To 10
    FileWriteLine(@ScriptDir & "\file" & $i & ".txt", "Text" & $i)
Next

:)

Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

I also thinking what to use controls more favourable, but my code - an example, for the decision of a problem in other program. How I can learn names of elements of the form there? Do you want I shall result the text of the real program? :)

Share this post


Link to post
Share on other sites

I also thinking what to use controls more favourable, but my code - an example, for the decision of a problem in other program. How I can learn names of elements of the form there?

If you installed the full version of AutoIt, there should have been an AutoIt Window Info Tool, AU3Info.exe. That will give you the control ID information.

Do you want I shall result the text of the real program? :)

Don't dismiss the idea too quickly. If there is an application to do whatever it is, then there may not be any good way to directly produce the results. But many things can be done straight from AutoIt and might be more reliable than hacking the GUI\Menu of the application. Depends on the application.

:)


Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post


Link to post
Share on other sites

Thanks for the information! Big thanks for the information! Posted Image

I shall take advantage AU3Info.exe, but I still the beginner in Autoit, therefore for me to use GUI \Menu of the application easier. In difference from "notepad" this program uses non-standard controls.

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  
Followers 0