Jump to content

Reduce MouseClickDrag durations


Recommended Posts

I need to move some sub-windows, which all reside inside a main window, in this way:

MouseClickDrag("left", 190, 55, 150, 55,0)
MouseClickDrag("left", 290, 55, 220, 55,0)
MouseClickDrag("left", 390, 55, 290, 55,0)
MouseClickDrag("left", 490, 55, 360, 55,0)
MouseClickDrag("left", 590, 55, 430, 55,0)
MouseClickDrag("left", 690, 55, 500, 55,0)
MouseClickDrag("left", 790, 55, 550, 55,0)


The above code works perfectly except that the draggings of individual sub-windows are clearly visible one by one - and the whole dragging takes at least 7 seconds for the 7 sub-windows.  Is there a way that this process can be made nearly Instant, so that the whole dragging takes just 2-3 seconds for all the 7 sub-windows? .... and so that, if I have 20 sub-windows to drag, the whole process takes less than about 5 seconds?

Thanks in advance for any assistance.

 

Link to comment
Share on other sites

@FrancescoDiMuro

Thanks for the instant reply.

I indeed use WinMove() to move the Main window, which does have a constant title.  However, the sub-windows do not have proper 'constant' title/hWnd/class, that is, the sub-windows change every time when the Main window changes.  That's why I chose to use MouseClickDrag instead of WinMove() which is instant.

The Main window is akin to a class/grade in a school while the sub-windows are the student names in that class.

Thanks.

 

Link to comment
Share on other sites

WinList() could be helpful :)
You retrieve all the Windows opened, and store in an array only the handles for the Windows which match your criteria.
In your case, something like:

Global $arrWinList, _
       $arrWinToMove[1]
       
       
$arrWinList = WinList()
For $i = 1 To $arrWinList[0][0] Step 1
    If StringInStr($arrWinList[$i][0], "Test 1 Class 3 (January)") Then
        _ArrayAdd($arrWinToMove, $arrWinList[$i][1]) ; Store the handle of the Window
    EndIf
Next

; Process Windows with WinMove...

Cheers :)

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

Link to comment
Share on other sites

@FrancescoDiMuro

Thanks a lot for your help.

Your solution is a little above my current knowledge, and probably a little overkill for my current purpose.

However, I will try it in due course if some other member do not suggest a simpler solution. [Simpler solutions are welcome!]

Thanks again.  :):)

 

Link to comment
Share on other sites

@hutralospi
I created a little sample script to let you know a very "basic", but at the same dynamic and simple solution for your question :)
I commented it out to let you understand what the script does.

Mouse* functions should be used only for very simple clicks and stuffs like that, but not for something that needs a bit of "dynamic" and, why not, something that does it "better" than Mouse* functions.

#include <Array.au3>
#include <GUIConstantsEx.au3>

Opt("GUIOnEventMode", 1)

Global $arrStudents[] = ["John", "Mattew", "Ronald", "Gary"], _
       $arrWinList, _       ; Array which stores all the Windows opened
       $arrWinToMove[1], _  ; Array which stores ONLY the Windows to move
       $intStartingX = 0, _ ; Starting offset for the X axis where to move your Window(s)
       $intStartingY = 0    ; Starting offset for the Y axis where to move your Window(s) (always 0 in this case)

; Create the GUIs, without storing the handle of them, and show them
For $i = 0 To UBound($arrStudents) - 1 Step 1
    GUICreate($arrStudents[$i] & " : Test 1 Class 3 (January)", 200, 200)
    GUISetState(@SW_SHOW)
Next

; This GUI will appears behind the _ArrayDisplay, and it doesn't need to be moved, since it won't match the criteria "Test 1 Class 3 (January)"
GUICreate("Some GUI that doesn't need to be moved", 200, 200)
GUISetState(@SW_SHOW)


; Get the list of ALL windows opened, and store in $arrWinToMove only the ones which match the criteria "Test 1 Class 3 (January)"
$arrWinList = WinList()
For $i = 1 To $arrWinList[0][0] Step 1
    If StringInStr($arrWinList[$i][0], "Test 1 Class 3 (January)") Then
        _ArrayAdd($arrWinToMove, $arrWinList[$i][1])
        If @error Then
            ConsoleWrite("Error while adding the item " & $arrWinList[$i][1] & " in the array. Error: " & @error & @CRLF)
        EndIf
    EndIf
Next

; Store the number of handles found with the criteria "Test 1 Class 3 (January)"
$arrWinToMove[0] = UBound($arrWinToMove)

; Move the Windows in $arrWinToMove, increasing the X offset by 250, in order to let you see how they are moved
For $i = 1 To $arrWinToMove[0] - 1 Step 1
    WinMove($arrWinToMove[$i], "", $intStartingX, $intStartingY)
    $intStartingX += 250
Next

; Click on the "X" button of the _ArrayDisplay to exit the script
_ArrayDisplay($arrWinToMove)

Exit

While 1
    Sleep(100)
WEnd

Cheers :)

Edited by FrancescoDiMuro

Click here to see my signature:

Spoiler

ALWAYS GOOD TO READ:

 

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