设置窗口所有控件可用
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 ;---
; 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 ;---
相关文章推荐
- swing 批量设置所有窗口控件的字体特征
- Qt无边框窗口, 设置最小化后, 再还原,所有子控件不刷新
- 设置页面的所有控件为只读,不可用
- MFC 静态文本框使用/更改button背景色/不使能button/设置标题/不显示控件/窗口最大最小化
- Android设置窗口、控件透明度
- EnableWindow(): 使某个控件或窗口可用
- MFC窗口最大化&移动窗口位置&获取控件句柄,设置控件大小
- windowsSDK利用子窗口控件设置窗口透明
- Gtk 窗口,控件,设置(添加图片等)
- WinForm容器内控件批量效验是否允许为空?设置是否只读?设置是否可用等方法分享
- MFC窗口各控件的颜色和字体的设置
- Qt4窗口及控件风格设置过程
- 设置窗口+动态创建控件
- windowsSDK利用子窗口控件设置窗口透明
- 设置控件随窗口大小而改变
- VC 遍历窗口所有子控件。
- UITextfield控件的所有属性设置与解析 [转]
- VFP如何控制一个窗口的所有控件的大小随窗口的变化而变化
- 写一个方法进行各种属性的更新,而不要每个界面设置改变都改变一个属性。就是点击应用或确定按钮时调用这个更新属性的方法,遍历所有(控制对象属性的)界面控件的状态(值),进行属性修改和刷新。
- UITextfield控件的所有属性设置与解析