Jump to content

Enable Controls on a Dialog


nobbe
 Share

Recommended Posts

will enable all buttons an a target dialog

runs sample calculator, then waits and fills up list - select here now the name of the calculator and click "enable", then watch as it enables each button

calculator needs to be in scientific mode (more buttons)

;
; 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 ;---
Edited by nobbe
Link to comment
Share on other sites

  • 7 months later...

Run("calc.exe")

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

Wouldn't a

$prog = "calc.exe"

Run($prog)

Do

sleep(100)

until processexists($prog)

or something of that sorts be better?

And all it does is enable them? you can't do anything with them? Oh well still very neat.

Giggity

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