您的位置:首页 > 其它

设置窗口所有控件可用

2011-05-16 16:37 323 查看
;
; control button enabler -- enables all controls on target window
; credits to "SmOke_N" for _WinGetCtrlInfo()

; settings dialogs etc.. are children

#include <GuiConstants.au3>
;;;#include <Constants.au3>
#include <GuiListBox.au3>

; just to get a window
Run("calc.exe")

Sleep(1000); towait for program to start - or else its not in the list

;
;
;
#Region ### START Koda GUI section ###

$GUI = GUICreate("Enabler", 400, 400, 136, 185)
$List = GUICtrlCreateList("", 10, 10, 380, 300)
$enable_button = GUICtrlCreateButton("enable", 10, 320, 40, 25, 0)

#EndRegion ### START Koda GUI section ###
GUISetState(@SW_SHOW)

; get names of running programs
$var = WinList()

For $i = 1 To $var[0][0]
; Only display visble windows that have a title
If $var[$i][0] <> "" And IsVisible($var[$i][1]) Then
;MsgBox(0, "Details", "Title=" & $var[$i][0] & @LF & "Handle=" & $var[$i][1]);
_GUICtrlListBox_AddString($List, $var[$i][0])

EndIf
Next

; ------------------------ loop ------------------------
While 1

$msg = GUIGetMsg() ;

If $msg = $GUI_EVENT_CLOSE Then
ExitLoop ; Exit

ElseIf $msg = $enable_button Then

; get info from list and enable
$windowtitle = GUICtrlRead($List)
MsgBox(0, "Details", $windowtitle);
_enable_all_on_window_title($windowtitle)
EndIf

WEnd

;
; get only visible dialogs
;
Func IsVisible($handle)
If BitAND(WinGetState($handle), 2) Then
Return 1
Else
Return 0
EndIf

EndFunc ;==>IsVisible

;
; enable all control on given window
;
Func _enable_all_on_window_title($title)

local $Array = _WinGetCtrlInfo($title)

local $sOne = '[0][0] = ' & $Array[0][0] & @CR, $sTwo
For $iCC = 1 To $Array[0][0]
; $sOne &= '[' & $iCC & '][0] = ' & $Array[$iCC][0] & @CR
; $sTwo &= '[' & $iCC & '][1] = ' & $Array[$iCC][1] & @CR

$rc = ControlCommand($title, "", $Array[$iCC][0], "IsEnabled", "")

If $rc == 0 Then
MsgBox(64, "ret ", $rc) ; for DEBUG just to follow which button it enables

$rc = ControlEnable($title, "", $Array[$iCC][0])
EndIf

Next
; MsgBox(64, 'WinInfo', StringTrimRight($sOne, 1) & @CR & StringTrimRight($sTwo, 1))
EndFunc ;==>_enable_all_on_window_title

; by smoke_n
;

Func _WinGetCtrlInfo($hWin)
If IsString($hWin) Then $hWin = WinGetHandle($hWin)
Local $sClassList = WinGetClassList($hWin), $iAdd = 1, $aDLL, $sHold
Local $aSplitClass = StringSplit(StringTrimRight($sClassList, 1), @LF), $aReturn[1][2]
For $iCount = $aSplitClass[0] To 1 Step -1
Local $nCount = 0
While 1
$nCount += 1
If ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount) = '' Then ExitLoop
If Not StringInStr(Chr(1) & $sHold, Chr(1) & $aSplitClass[$iCount] & $nCount & Chr(1)) Then
$sHold &= $aSplitClass[$iCount] & $nCount & Chr(1)
$iAdd += 1
ReDim $aReturn[$iAdd][2]
$aReturn[$iAdd - 1][0] = $aSplitClass[$iCount] & $nCount
$aDLL = DllCall('User32.dll', 'int', 'GetDlgCtrlID', 'hwnd', _
ControlGetHandle($hWin, '', $aSplitClass[$iCount] & $nCount))
If @error = 0 Then
$aReturn[$iAdd - 1][1] = $aDLL[0] ; control ID
Else
$aReturn[$iAdd - 1][1] = ''
EndIf
EndIf
WEnd
Next
$aReturn[0][0] = $iAdd - 1
Return $aReturn
EndFunc ;==>_WinGetCtrlInfo

Exit ;---
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: