AwesomeIt/playground.au3

254 lines
8.2 KiB
AutoIt
Raw Normal View History

2015-05-19 12:39:34 +02:00
#cs ----------------------------------------------------------------------------
AutoIt Version: 3.3.12.0
Author: Sqozz
Script Function:
Template AutoIt script.
#ce ----------------------------------------------------------------------------
#include "includes\_Subarray.au3"
#include "includes\_Monitor.au3"
#include <WinAPI.au3>
#include <WinAPISys.au3>
#include <Misc.au3>
#include <WinAPIGdi.au3>
#include <Array.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
_POC_CustomTaskbar()
; === POC for _Subarray UDF
Func _POC_Subarray()
#include <Array.au3>
Local $array[0]
Local $array2[0]
Local $subsubarray[0]
_ArrayAdd($subsubarray, "value1 in subsubarray")
_ArrayAdd($subsubarray, "value2 in subsubarray")
_ArrayDisplay($subsubarray)
_ArrayAddToArray($array2, $subsubarray)
_ArrayAddToArray($array, $array2)
$array_2 = _ArrayGetFromArray($array, 0)
$sub = _ArrayGetFromArray($array_2, 0)
ConsoleWrite($sub[0] & @CRLF)
EndFunc
; === This creates a huge green box on each monitor.
; Each of this box contains all windows which are currently on this monitor
Func _POC_CustomTaskbar()
; Create a GUI with various controls.
$monitors = _genMonitorList()
Dim $hGUIList[0][2]
Dim $ElementList[0]
Dim $UIElementContainer[0][2] ; Element[0] == HWND of GUICreate; Element[1] == Array of all elements contained in this UI
$windowList = _getVisibleWindowList()
Dim $winWithMon[0][2]
For $i = 0 To UBound($windowList) - 1
$winIndex = _ArrayAdd($winWithMon, WinGetTitle($windowList[$i]))
$winWithMon[$winIndex][1] = _WinAPI_MonitorFromWindow($windowList[$i])
Next
;This loop creates a taskbar for each monitor. Full width and 20px height
For $i = 0 To UBound($monitors) - 1
_ArrayAdd($UIElementContainer, GUICreate($monitors[$i][4], $monitors[$i][2], 200, $monitors[$i][0], $monitors[$i][1], BitOR($WS_SYSMENU,$WS_POPUP,$WS_CLIPSIBLINGS), BitOR($WS_EX_TOPMOST, $WS_EX_TOOLWINDOW)))
GUISetBkColor ("0x00FF00")
$elementY = 0
For $a = 0 To UBound($winWithMon) - 1
If $winWithMon[$a][1] == $monitors[$i][4] Then
GUICtrlCreateLabel ( $winWithMon[$a][0], 0, ($elementY * 20))
$elementY += 1
EndIf
Next
Next
;Now $UIElementContainer[n][0] is filled with every handle of each GUI
;Now we create a label on each of this
;For $i = 0 To UBound($UIElementContainer) - 1
; GUISwitch($UIElementContainer[$i][0])
; $id = GUICtrlCreateLabel ( "Autosome!", 0, 0 )
; $idBtn = GUICtrlCreateButton( "Hello on " & $id, 100, 0 )
; _ArrayAdd($ElementList, $id)
; _ArrayAdd($ElementList, $idBtn)
; _InsertArrayToArray($UIElementContainer, $ElementList, $i, 1)
; ReDim $ElementList[0]
;Next
For $i = 0 To UBound($UIElementContainer) - 1
GUISetState(@SW_SHOW, $UIElementContainer[$i][0])
Next
While Not _IsPressed("1B") ; ESC to exit
Switch GUIGetMsg()
Case $GUI_EVENT_CLOSE
ExitLoop
EndSwitch
WEnd
For $i = 0 To UBound($UIElementContainer) - 1
GUIDelete($UIElementContainer[$i][0])
Next
EndFunc
; Returns an array of visible windows.
; All windows, which have the "Window is visible" bit set, count as visible
Func _getVisibleWindowList()
Local $visibleList[0]
$plist = ProcessList()
For $i = 1 To $plist[0][0]
$hwndList = _ProcessGetWindow($plist[$i][1])
If IsArray($hwndList) Then
For $a = 1 To $hwndList[0]
$hwnd = $hwndList[$a]
$applState = WinGetState($hwnd)
$title = WinGetTitle($hwnd)
If (BitOR($applState, 2) == $applState) And $title <> "" Then
_ArrayAdd($visibleList, $hwnd)
EndIf
Next
EndIf
Next
Return $visibleList
EndFunc
; Returns an array with window styles
; $array[0] = Window styles
; $array[1] = Extended window styles
Func _getStyleOfWindow($hwnd)
Local $style[0]
$aStyle = _WinAPI_GetWindowLong($hwnd, $GWL_STYLE)
If @error == 0 Then
_ArrayAdd($style, $aStyle)
Else
_ArrayAdd($style, -1)
EndIf
$aExStyle = _WinAPI_GetWindowLong($hwnd, $GWL_EXSTYLE)
If @error == 0 Then
_ArrayAdd($style, $aExStyle)
Else
_ArrayAdd($style, -1)
EndIf
Return $style
EndFunc
; Iterates over an array of hwnds and returns an array of tilable window hwnds
Func _createTilableWindowList($windowList)
Local $tilableWindowList[0]
For $i = 0 To UBound($windowList) - 1
If _isTilable($windowList[$i]) Then
_ArrayAdd($tilableWindowList, $windowList[$i])
EndIf
Next
Return $tilableWindowList
EndFunc
; I assume, that a window should be tiles, if it has a thick frame
Func _isTilable($hwnd)
$styles = _getStyleOfWindow($hwnd)
If BitAND($styles[1], $WS_EX_DLGMODALFRAME) <> $WS_EX_DLGMODALFRAME Then
Return True
Else
Return False
EndIf
EndFunc
; #FUNCTION# ============================================================================================================================
; Name...........: _ProcessGetWindow
;
; Description ...: Returns an array of HWNDs containing all windows owned by the process $p_PID, or optionally a single "best guess."
;
; Syntax.........: _ProcessGetWindow( $p_PID [, $p_ReturnBestGuess = False ])
;
; Parameters ....: $p_PID - The PID of the process you want the Window for.
; $p_ReturnBestGuess - If True, function will return only 1 reult on a best-guess basis.
; The "Best Guess" is the VISIBLE window owned by $p_PID with the longest title.
;
; Return values .: Success - Return $_array containing HWND info.
; $_array[0] = Number of results
; $_array[n] = HWND of Window n
;
; Failure - Returns 0
;
; Error - Returns -1 and sets @error
; 1 - Requires a non-zero number.
; 2 - Process does not exist
; 3 - WinList() Error
;
; Author ........: Andrew Bobulsky, contact: RulerOf <at that public email service provided by Google>.
; Remarks .......: The reverse of WinGetProcess()
; =======================================================================================================================================
Func _ProcessGetWindow( $p_PID, $p_ReturnBestGuess = False )
Local $p_ReturnVal[1] = [0]
Local $p_WinList = WinList()
If @error Then ;Some Error handling
SetError(3)
Return -1
EndIf
If $p_PID = 0 Then ;Some Error handling
SetError(1)
Return -1
EndIf
If ProcessExists($p_PID) = 0 Then ;Some Error handling
ConsoleWrite("_ProcessGetWindow: Process " & $p_PID & " doesn't exist!" & @CRLF)
SetError(2)
Return -1
EndIf
For $i = 1 To $p_WinList[0][0] Step 1
Local $w_PID = WinGetProcess($p_WinList[$i][1])
If $w_PID = $p_PID Then
$p_ReturnVal[0] += 1
_ArrayAdd($p_ReturnVal, $p_WinList[$i][1])
EndIf
Next
If $p_ReturnVal[0] > 1 Then
If $p_ReturnBestGuess Then
Do
Local $i_State = WinGetState($p_ReturnVal[2])
Local $i_StateLongest = WinGetState($p_ReturnVal[1])
Select
Case BitAND($i_State, 2) And BitAND($i_StateLongest, 2) ;If they're both visible
If StringLen(WinGetTitle($p_ReturnVal[2])) > StringLen(WinGetTitle($p_ReturnVal[1])) Then ;And the new one has a longer title
_ArrayDelete($p_ReturnVal, 1) ;Delete the "loser"
$p_ReturnVal[0] -= 1 ;Decrement counter
Else
_ArrayDelete($p_ReturnVal, 2) ;Delete the failed challenger
$p_ReturnVal[0] -= 1
EndIf
Case BitAND($i_State, 2) And Not BitAND($i_StateLongest, 2) ;If the new one's visible and the old one isn't
_ArrayDelete($p_ReturnVal, 1) ;Delete the old one
$p_ReturnVal[0] -= 1 ;Decrement counter
Case Else ;Neither window is visible, let's just keep the first one.
_ArrayDelete($p_ReturnVal, 2)
$p_ReturnVal[0] -= 1
EndSelect
Until $p_ReturnVal[0] = 1
EndIf
Return $p_ReturnVal
ElseIf $p_ReturnVal[0] = 1 Then
Return $p_ReturnVal ;Only 1 window.
Else
Return 0 ;Window not found.
EndIf
EndFunc