Jump to content

Move windows with mouse inside a loop


Kyan
 Share

Recommended Posts

Hi

its possible to make an gui accept to be changed is position with the typical mouse action inside a loop (For or Do loop)?

ever my script is inside a loop, I cannot change the window's position

thanks in advance :)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Hi,

Can you be more clear, how do you want the GUI to be moved (e.g : caption bar, control). Why especially inside a loop?

Edit : Do you want your GUI to be moved, or an external window?

Br, FireFox.

Edited by FireFox
Link to comment
Share on other sites

Hi,

Can you be more clear, how do you want the GUI to be moved (e.g : caption bar, control). Why especially inside a loop?

Edit : Do you want your GUI to be moved, or an external window?

Br, FireFox.

Hi

from the caption bar (the normal way to move a window with mouse pointer), I create a gui with GuiCreate(), and when I'm executing a DO/FOR/While Loop I cannot move it until the loop ends :s

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

and when I'm executing a DO/FOR/While Loop I cannot move it until the loop ends :s

That's why you have to use the MAIN while and not another one, because AutoIt does not support multi threading.

Instead of this :

While 1
;Main Loop
WEnd

Func _bad()
Do
;my stuff
Until ...
EndFunc

Do :

Global $blDoStuff = False

While 1
If $blDoStuff Then
;my stuff
EndIf
WEnd

Func _Good()
$blDoStuff = True
EndFunc

Br, FireFox.

Link to comment
Share on other sites

That's why you have to use the MAIN while and not another one, because AutoIt does not support multi threading.

Instead of this :

While 1
;Main Loop
WEnd

Func _bad()
Do
;my stuff
Until ...
EndFunc

Do :

Global $blDoStuff = False

While 1
If $blDoStuff Then
;my stuff
EndIf
WEnd

Func _Good()
$blDoStuff = True
EndFunc

Br, FireFox.

I do it as the first example xD

and where I should put the "if" inside the while Loop?

here0, here1, here2?

while 1
here0
$nMsg = GUIGetMsg(1)
Switch $nMsg[1]
Case $Form1
Switch $nMsg[0]
here1
EndSwitch
here2
EndSwitch
Wend
Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

I do it as the first example xD

Then you know how to convert the 1st example to the second one.

and where I should put the "if" inside the while Loop?

Put your stuff where you want it to be executed, if you want it to be executed by a Ctrl event, then it's in your Switch, otherwise it's outside.

Br, FireFox.

Link to comment
Share on other sites

Put your stuff where you want it to be executed, if you want it to be executed by a Ctrl event, then it's in your Switch, otherwise it's outside.

Br, FireFox.

uh, OK, thanks

and if I need to do repetitive tasks, and stop after processing a array or something? how can I do it? (sorry but using the main while for everything is a bit confusing to me)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

and if I need to do repetitive tasks, and stop after processing a array or something? how can I do it? (sorry but using the main while for everything is a bit confusing to me)

I agree, but It's the best way to do it without having your GUI hanging/app crashing.

You can check with another boolean to end your stuff by a ExitLoop if you are in a For/While or a ContinueLoop.

Br, FireFox.

Link to comment
Share on other sites

I agree, but It's the best way to do it without having your GUI hanging/app crashing.

You can check with another boolean to end your stuff by a ExitLoop if you are in a For/While or a ContinueLoop.

Br, FireFox.

but executing the exitloop it won't stop the GuiGetMsg() from receving gui events?

EDIT: btw, there's some example script about it? (I never saw in this forum a script that uses the main loop to do cycle processing...)

Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

but executing the exitloop it won't stop the GuiGetMsg() from receving gui events?

I said only if you are using a loop inside the Main while

EDIT: btw, there's some example script about it? (I never saw in this forum a script that uses the main loop to do cycle processing...)

Because It's a bad way of scripting to check everytime for something if you have a GUI, or the GUI freezes but they don't care.

Br, FireFox.

Link to comment
Share on other sites

I said only if you are using a loop inside the Main while

ok, I use on event mode to grab a ctrl event, it executes a function and turns true a flag present inside of my loop or specified in "until $flag"...but gui freezes anyway...

Because It's a bad way of scripting to check everytime for something if you have a GUI, or the GUI freezes but they don't care.

that is what I think, autoIT should be able to handle the main loop always, even if you are executing more 2 loops...

thanks for the explanations, there's some way to listening the gui event associated window position change? (like I can listen if a ctrl is triggered OnEventMode)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

thanks for the explanations, there's some way to listening the gui event associated window position change? (like I can listen if a ctrl is triggered OnEventMode)

If your GUI freezes, it means that no event can be triggered because the events are blocked by your loop so I suggest you to remove your loop inside the main loop.

Br, Firefox.

Link to comment
Share on other sites

Do you absolutely need to use a mouse to move a window?

If you are just trying to move a window and don't require exact pixel placement, just use Send and do keyboard operations on the system menu.

No loop needed.

Run("Notepad.exe")
  WinMove("[CLASS:Notepad]", "", 20,20, 400, 300)

  Sleep(200)
  WinActivate("[CLASS:Notepad]", "")

  Send("{ALT}{SPACE}")
  Send("M")

  Sleep(2000)

  Send("{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}")
  Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")

  Sleep(500)

  Send("{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}")
  Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")

  Sleep(500)

  Send("{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}")
  Send("{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}")

  MouseClick("left")
Link to comment
Share on other sites

  • 2 weeks later...

Do you absolutely need to use a mouse to move a window?

If you are just trying to move a window and don't require exact pixel placement, just use Send and do keyboard operations on the system menu.

No loop needed.

Run("Notepad.exe")
WinMove("[CLASS:Notepad]", "", 20,20, 400, 300)

Sleep(200)
WinActivate("[CLASS:Notepad]", "")

Send("{ALT}{SPACE}")
Send("M")

Sleep(2000)

Send("{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}")
Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")

Sleep(500)

Send("{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}")
Send("{DOWN}{DOWN}{DOWN}{DOWN}{DOWN}")

Sleep(500)

Send("{RIGHT}{RIGHT}{RIGHT}{RIGHT}{RIGHT}")
Send("{UP}{UP}{UP}{UP}{UP}{UP}{UP}{UP}")

MouseClick("left")

yup, when I'm executing a loop, the main while loop don't listen window's inputs like window change is position

I was reading this thread:

is possible do it with adlib? or GUIRegisterMsg?, I just want to allow window movement with mouse (normal way of change window's position)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

Post your script if you can.

in this code is possible to move my window, I don't understand why, using inetget, winhttp, even do loops i cannot move my window, may be is because I'm using a windows classic theme, let try change it to aero and see how it works...

here's a example that should be impossible to move while is executing the for loop

Global $hGui = GUICreate("Window title", 320, 50, -1, -1)
Global $hprog = GUICtrlCreateProgress(10, 10, 300, 16)
Global $hbtn = GUICtrlCreateButton("Run progress bar",120,30,90,18)
GUISetState()

While 1
Switch GUIGetMsg()
Case -3
Exit
Case $hbtn
_run()
EndSwitch
WEnd

Func _run()
$x = 0
Do
$x +=1
GUICtrlSetData($hprog,$x)
If $x = 100 Then ExitLoop
Sleep(100)
Until GUIGetMsg() = -3
EndFunc

I just found this:

it works nice, the problem is, it only works if a msgbox is open

EDIT: while using ping function, the window cannot be moved:

Global $hGui = GUICreate("Window title", 320, 50, -1, -1)
Global $hprog = GUICtrlCreateProgress(10, 10, 300, 16)
Global $hbtn = GUICtrlCreateLabel("Run progress bar",120,30,90,18)
GUISetState()

While 1
Switch GUIGetMsg()
Case -3
Exit
Case $hbtn
_run()
EndSwitch
WEnd

Func _run()
$x = 0
Do
Ping("xina12387.com",1000)
$x +=1
GUICtrlSetData($hprog,$x)
If $x = 100 Then ExitLoop
Sleep(100)
Until GUIGetMsg() = -3
EndFunc
Edited by DiOgO

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

Link to comment
Share on other sites

  • Moderators

Both examples I can move my window while it's running (Win7 x64 - Aero disabled).

Your setup is kind of lacking ( might try events ).

I am not sure now if you mean you can't interact with the GUI while it's not capturing the GUIGetMsg() or not.

Try this:

Global $hGui = GUICreate("Window title", 320, 50, -1, -1)
Global $hprog = GUICtrlCreateProgress(10, 10, 300, 16)
Global $hbtn = GUICtrlCreateButton("Run progress bar",120,30,90,18)
GUISetState()

While 1
    Switch GUIGetMsg()
        Case -3
            Exit
    Case $hbtn
            _run()
    EndSwitch
WEnd

Func _run()
    $x = 0
    While GUIGetMsg() <> -3
        $x +=1
        GUICtrlSetData($hprog,$x)
        If $x = 100 Then ExitLoop
        Sleep(100)
    WEnd
    ; we already captured the exit command
    ; so if we want to actually exit we'll have to do it here
EndFunc
Edited by SmOke_N
forgot to take consolewrite out

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Both examples I can move my window while it's running (Win7 x64 - Aero disabled).

Your setup is kind of lacking ( might try events ).

I am not sure now if you mean you can't interact with the GUI while it's not capturing the GUIGetMsg() or not.

Try this:

---

I use events to abort loops, etc, but probably will fallow your hint, of checking GUIGetMsg() inside a loop

thanks

I can't replicate the error either, my only suggestion is to try downloading the beta.

I wish I could help more.

Good luck getting it fixed.

Maybe is due to a cpu load, or even event crash, don't know :s, but only happens to my gui, if i cannot move mine and the problem is cpu load, why I could move all the others (no autoit gui's...)

Heroes, there is no such thing

One day I'll discover what IE.au3 has of special for so many users using it.
C'mon there's InetRead and WinHTTP, way better
happy.png

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