Sign in to follow this  
Followers 0
aghering

Script for controlling windows(frames)

5 posts in this topic

hello members,

i am tryin to make a autoit script to control the windows on my desktop.

situation

is as follow i have tree screen now connected to my pc, 2 of them are monitors and one is my tv connected on hdmi.

the problem is sometimes when i don't use my tv as monitor i open up a program or a window and i pops up on its last used location for many application it means on my tv monitor. in that case i need to turn on my tv and switch to monitor to only move the window

i prefer a script that can show me wich windows are on what monitor at the moment located on with to option to move all or one of them to a other window.

and there here comes the problem, i have the idea but i really don't have a idea how i am gonna make it. with what functions and opperations i can make this possible

Share this post


Link to post
Share on other sites



hello members,

i am tryin to make a autoit script to control the windows on my desktop.

situation

is as follow i have tree screen now connected to my pc, 2 of them are monitors and one is my tv connected on hdmi.

the problem is sometimes when i don't use my tv as monitor i open up a program or a window and i pops up on its last used location for many application it means on my tv monitor. in that case i need to turn on my tv and switch to monitor to only move the window

i prefer a script that can show me wich windows are on what monitor at the moment located on with to option to move all or one of them to a other window.

and there here comes the problem, i have the idea but i really don't have a idea how i am gonna make it. with what functions and opperations i can make this possible

I would guess you could do something like this:

Get a list of the top level windows using WinList.

For each window get its position using WInGetPos. If the window is not on the monitor you want it to be on then move it.

If you want to associate a process with a window thenuse WinGetProcess.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

Hello i have been busy with school the past few days so i needed to put this project on a pause.

but i have made some time for it now and i have come back with some few questions. The working of WInGetPos i understand and got it working pretty fast.

But now i wanted to tune up the winlist search some so I came up with the following it works goods but my question is more why does it take so long for the script to complete its run in total now of 50 secs. Hopefully some of you guys can see the problem in it.

#include <Array.au3>
#Include <Timers.au3>

Global $SSEC = StringSplit("MediaPlayerClassicW|WMPlayerApp|Progman|SWT_Window0|SysListView32|BasicWindow|DV2ControlHost|DirectUIHWND|wxWindowClassNR|Start|Button|Desktop User Picture|BasicWindow|Windows Sidebar|SideBar_AppBarWindow|SideBar_AppBarBullet|Internet Explorer_Server" , "|")
Global $SSEC1 = StringSplit("Untitled - Notepad|Sticky Notes" , "|") ; filter for window titles
Global $aGlobalWin[1]

Local $starttime = _Timer_Init()
WinCheck()
ConsoleWrite ( _Timer_Diff($starttime))
_ArrayDisplay($aGlobalWin, "$avArray AFTER _ArrayAdd()")


Func WinCheck()
    Local $oTemp
    If $aGlobalWin[0] > 0 Then
        For $x = 1 To $aGlobalWin[0]
            Local $SSO = StringSplit($aGlobalWin[$x], ",")
            If WinExists(HWnd($SSO[1])) Then $oTemp &= $aGlobalWin[$x] & "|"
        Next
    EndIf
    If StringTrimRight($oTemp, 1) <> "" Then
        Local $SSP = StringSplit(StringTrimRight($oTemp, 1), "|")
        Dim $aGlobalWin[$SSP[0] + 1]
        $aGlobalWin[0] = $SSP[0]
        For $y = 1 To $SSP[0]
            $aGlobalWin[$y] = $SSP[$y]
        Next
    EndIf
    Local $aWin = WinList(), $cTemp
    For $w = 1 To $aWin[0][0]
        If $aWin[$w][0] <> "" And WinFilter($aWin[$w][1]) And (Not StringInStr($oTemp, $aWin[$w][1] )) Then
            ReDim $aGlobalWin[$aGlobalWin[0] + 2]
            $aGlobalWin[0] += 1
            $aGlobalWin[$aGlobalWin[0]] = $aWin[$w][0]
        EndIf
    Next
EndFunc

Func WinFilter($iHandle)
    If Not BitAnd(WinGetState($iHandle), 2) Then Return 0
    For $j = 1 To $SSEC[0]
        If (WinGetTitle($iHandle) == WinGetTitle("[CLASS:" & $SSEC[$j] & "]")) Then Return 0
    Next

    For $j = 1 To $SSEC1[0]
        If (WinGetTitle($iHandle) == WinGetTitle( $SSEC1[$j] )) Then Return 0
    Next

    Return 1
EndFunc

Share this post


Link to post
Share on other sites

looking again into my code noticed i added it a peace that isn’t used, sorry for that but this is what I have now. Still having a long run time…

#include <Array.au3>
#Include <Timers.au3>

Global $SSEC = StringSplit("MediaPlayerClassicW|WMPlayerApp|Progman|SWT_Window0|SysListView32|BasicWindow|DV2ControlHost|DirectUIHWND|wxWindowClassNR|Start|Button|Desktop User Picture|BasicWindow|Windows Sidebar|SideBar_AppBarWindow|SideBar_AppBarBullet|Internet Explorer_Server" , "|")
Global $SSEC1 = StringSplit("Sticky Notes|Untitled - Notepad" , "|") ; filter for window titles
Global $aGlobalWin[1]
sleep ( 2000 )
Local $starttime = _Timer_Init()
WinCheck()
ConsoleWrite ( _Timer_Diff($starttime))
_ArrayDisplay($aGlobalWin, "$avArray AFTER _ArrayAdd()")


Func WinCheck()
    Local $oTemp
    Local $aWin = WinList(), $cTemp
    For $w = 1 To $aWin[0][0]
        If $aWin[$w][0] <> "" And IsVisible($aWin[$w][1]) And WinFilter($aWin[$w][1]) Then
            ReDim $aGlobalWin[$aGlobalWin[0] + 2]
            $aGlobalWin[0] += 1
            $aGlobalWin[$aGlobalWin[0]] = $aWin[$w][0]
        EndIf
    Next
EndFunc

Func WinFilter($iHandle)
    If Not BitAnd(WinGetState($iHandle), 2) Then Return 0
    For $j = 1 To $SSEC[0]
        If (WinGetTitle($iHandle) == WinGetTitle("[CLASS:" & $SSEC[$j] & "]")) Then Return 0
    Next

    For $j = 1 To $SSEC1[0]
        If (WinGetTitle($iHandle) == WinGetTitle( $SSEC1[$j] )) Then Return 0
    Next

    Return 1
EndFunc

Func IsVisible($handle)
  If BitAnd( WinGetState($handle), 2 ) Then
    Return 1
  Else
    Return 0
  EndIf
EndFunc

Share this post


Link to post
Share on other sites

This might help a bit.

Func WinCheck()
    Local $oTemp
    Local $aWin = WinList(), $cTemp
    ReDim $aGlobalWin[$aWin[0][0]]

    For $w = 1 To $aWin[0][0]
        If $aWin[$w][0] <> "" And IsVisible($aWin[$w][1]) And WinFilter($aWin[$w][1]) Then
            ;ReDim $aGlobalWin[$aGlobalWin[0] + 2]
            $aGlobalWin[0] += 1
            $aGlobalWin[$aGlobalWin[0]] = $aWin[$w][0]
        EndIf
    Next
    ReDim $aGlobalWin[$aGlobalWin[0] + 1]
EndFunc

ReDim takes time so do it as little as possible.


Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

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