Sign in to follow this  
Followers 0
magician13134

Disabled controls

11 posts in this topic

Ok, I wrote a small program from a script by Larry, and I'm having some troubles with it. It's supposed to enable/disable/click controls for you, but there are two problems... there's no ControlSetState, so I can't use $GUI_CHECKED for that, right now I'm using ControlClick(), but I'd like a way to specifically check or uncheck boxes. Also, the script Larry wrote can't detect hidden or disabled controls... can anyone help me? Here's the source, press the middle mouse button over a control (If you don't have a middle mouse button edit the line 'If _IsPressed(04)' to 'If _IsPressed(02)' for the right mouse click'.

#include <GUIConstants.au3>
#include <misc.au3>

Dim $color1 = 0x000084
Dim $color2 = 0xD4D0C8
Dim $color3 = 0xAA0000
Dim $color4 = 0xFFFFFF
Dim $name[11]
Dim $hidden = 0
Global $prevhWIN = 0
Global $hWIN = HWNDUnderMouse()
Global $classnn = ""

Opt("TrayMenuMode", 1)
TraySetToolTip("Control Command")
$TrayIcon = TrayCreateItem("Hide Icon")
TrayCreateItem("")
$TrayExit = TrayCreateItem("Exit")

$DummyParent = GUICreate("", 0, 0, -5, -5, $WS_POPUP)
$GUI = GUICreate("Cotrol Command", 125, 191, -1, -1, $WS_DLGFRAME + $WS_POPUP, -1, $DummyParent)
GUISetBkColor($color2)
$ControlName = GUICtrlCreateLabel("", 1, 3, 123, 16, $SS_CENTER)
$name[1] = GUICtrlCreateLabel("Check", 1, 20, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[2] = GUICtrlCreateLabel("Uncheck", 1, 37, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[3] = GUICtrlCreateLabel("Enable", 1, 54, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[4] = GUICtrlCreateLabel("Disable", 1, 71, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[5] = GUICtrlCreateLabel("Show", 1, 88, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[6] = GUICtrlCreateLabel("Hide", 1, 105, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[9] = GUICtrlCreateLabel("Click", 1, 122, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[7] = GUICtrlCreateLabel("Cancel", 1, 139, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[10] = GUICtrlCreateLabel("Hide Icon", 1, 156, 123, 17, $SS_SUNKEN + $SS_CENTER)
$name[8] = GUICtrlCreateLabel("Exit", 1, 173, 123, 17, $SS_SUNKEN + $SS_CENTER)

While 1
    $msg = TrayGetMsg()
    $mouse = MouseGetPos()
    If $msg = $TrayExit Then
        Opt("TrayIconHide", 1)
        Exit
    EndIf
    If $msg = $TrayIcon Then
        GUICtrlSetData($name[10], "Show Icon")
        Opt("TrayIconHide", 1)
        $hidden = 1
    EndIf
    If Not @error And $prevhWIN <> $hWIN Then
        $classnn = ClassNNOfHWND($hWIN)
        $prevhWIN = $hWIN
    EndIf 
    $hWIN = HWNDUnderMouse()
    If _IsPressed(04) Then options($classnn, WinGetTitle("", ""))
WEnd

Func options($control, $win)
    $control = ClassNNOfHWND($hWIN)
    $win = WinGetTitle("")
    WinMove("Cotrol Command", "", $mouse[0], $mouse[1])
    WinSetOnTop("Cotrol Command", "", 1)
    GUICtrlSetData($ControlName, $control)
    GUISetState(@SW_SHOW, $GUI)
    $id = 0
    While 1
        $msg = GUIGetMsg()
        $mouse = GUIGetCursorInfo($GUI)
        If Not WinActive("Cotrol Command", "") Then
            GUISetState(@SW_HIDE, $GUI)
            GUICtrlSetBkColor($name[7], $color2)
            GUICtrlSetColor($name[7], 0x000000)
            ExitLoop
        EndIf
        If $msg = $name[7] Then
            GUISetState(@SW_HIDE, $GUI)
            GUICtrlSetBkColor($name[7], $color2)
            GUICtrlSetColor($name[7], 0x000000)
            ExitLoop
        EndIf
        If $msg = $name[8] Then Exit
        If $msg = $name[1] Then ControlClick($win, "", $control)
        If $msg = $name[2] Then ControlClick($win, "", $control)
        If $msg = $name[3] Then ControlEnable($win, "", $control)
        If $msg = $name[4] Then ControlDisable($win, "", $control)
        If $msg = $name[5] Then ControlShow($win, "", $control)
        If $msg = $name[6] Then ControlHide($win, "", $control)
        If $msg = $name[9] Then ControlClick($win, "", $control)
        If $msg = $name[10] Then
            If $hidden = 1 Then
                Opt("TrayIconHide", 0)
                $hidden = 0
                GUICtrlSetData($name[10], "Hide Icon")
            Else
                Opt("TrayIconHide", 1)
                $hidden = 1
                GUICtrlSetData($name[10], "Show Icon")
            EndIf
        EndIf
        If $mouse[4] <> 0 and $mouse[4] <> $ControlName Then
            If $mouse[4] = $name[1] and $id <> 1 Then
                GUICtrlSetBkColor($name[1], $color1)
                GUICtrlSetColor($name[1], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 1
            ElseIf $mouse[4] = $name[2] and $id <> 2 Then
                GUICtrlSetBkColor($name[2], $color1)
                GUICtrlSetColor($name[2], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 2 
            ElseIf $mouse[4] = $name[3] and $id <> 3 Then
                GUICtrlSetBkColor($name[3], $color1)
                GUICtrlSetColor($name[3], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 3     
            ElseIf $mouse[4] = $name[4] and $id <> 4 Then
                GUICtrlSetBkColor($name[4], $color1)
                GUICtrlSetColor($name[4], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 4     
            ElseIf $mouse[4] = $name[5] and $id <> 5 Then
                GUICtrlSetBkColor($name[5], $color1)
                GUICtrlSetColor($name[5], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 5 
            ElseIf $mouse[4] = $name[6] and $id <> 6 Then
                GUICtrlSetBkColor($name[6], $color1)
                GUICtrlSetColor($name[6], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 6
            ElseIf $mouse[4] = $name[7] and $id <> 7 Then
                GUICtrlSetBkColor($name[7], $color1)
                GUICtrlSetColor($name[7], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 7 
            ElseIf $mouse[4] = $name[8] and $id <> 8 Then
                GUICtrlSetBkColor($name[8], $color3)
                GUICtrlSetColor($name[8], $color4)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 8
            ElseIf $mouse[4] = $name[9] and $id <> 9 Then
                GUICtrlSetBkColor($name[9], $color1)
                GUICtrlSetColor($name[9], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 9 
            ElseIf $mouse[4] = $name[10] and $id <> 10 Then
                GUICtrlSetBkColor($name[10], $color1)
                GUICtrlSetColor($name[10], $color2)
                GUICtrlSetBkColor($name[$id], $color2)
                GUICtrlSetColor($name[$id], 0x000000)
                $id = 10                
            EndIf
        Else
            GUICtrlSetBkColor($name[$id], $color2)
            GUICtrlSetColor($name[$id], 0x000000)
            $id = 0
        EndIf
    WEnd
    GUISetState(@SW_HIDE, $GUI)
EndFunc


Func HWNDUnderMouse()
    Local $point, $hwnd
    $point = MouseGetPos()
    If @error Then Return SetError(1,0,0)
    $hwnd = DLLCall("user32.dll", "hwnd", "WindowFromPoint", "int", $point[0], "int", $point[1])
    If Not @error Or $hwnd[0] <> 0 Then Return $hwnd[0]
    Return SetError(2,0,0)
EndFunc

Func ClassNNOfHWND(ByRef $hwnd)
    Local $i,$ctrl
    Local $phWnd = DLLCall("user32.dll","hwnd","GetAncestor","hwnd",$hwnd,"int",2)
    $phWnd = $phWnd[0]
    If $phwnd = 0 Or $phWnd = $hwnd Then Return SetError(1,1,0)
    Local $list = WinGetClassList($phWnd)
   
    While StringLen($list)
        $i = StringInStr($list,@lf)
        $ctrl = StringLeft($list,$i-1)
        $list = @lf & $list
        $i = 1
        Do
            If ControlGetHandle($phWnd,"",$ctrl & $i) = $hwnd Then Return $ctrl & $i
            $i += 1
            $list = StringReplace($list,@lf & $ctrl & @lf,@lf,1)
        Until Not StringInStr($list,@lf & $ctrl & @lf)
        $list = StringTrimLeft($list,1) 
    WEnd
    Return SetError(1,0,0)
EndFunc

Share this post


Link to post
Share on other sites



Cool, thanks! But does anyone know how to find hidden/disabled control under the mouse?

WinGetClassList + ControlGetPos + MouseGetPos + Loop + ControlCommand...

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

*sigh* I was afraid I'd have to do something like that... There's no easier way? Oh well, thanks...

Edited by magician13134

Share this post


Link to post
Share on other sites

I'm having some serious issues with ControlGetPos... Can someone write a simple script to use WindowGetClassList to list all window controls, then get their positions with ControlGetPos?

It's because WinGetClassList doesn't return the instance... Does anyone know how to work around this?

Share this post


Link to post
Share on other sites

I'm having some serious issues with ControlGetPos... Can someone write a simple script to use WindowGetClassList to list all window controls, then get their positions with ControlGetPos?

It's because WinGetClassList doesn't return the instance... Does anyone know how to work around this?

It's usually customary to show some effort rather than taking your word for it.

http://www.autoitscript.com/forum/index.ph...c=32781&hl=

http://www.autoitscript.com/forum/index.ph...c=30717&hl=


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)

Can someone help me with the control under mouse issue again? I took smoke_N's advice and the script he wrote, but it's returning multiple controls... can anyone help me figure out how to only return the right one?

#include <misc.au3>

Opt("WinTitleMatchMode", 3)

While 1
    GUIGetMsg()
    ;If _IsPressed(04) Then
        $controls = _WinGetCtrlInfo("")
        $win = _WinGetCtrlInfo("[ACTIVE]")
        For $i = 1 to $controls[0][0]
            If _PointIsOverControl($controls[$i][0], $win) Then ToolTip($controls[$i][0])
        Next
    ;EndIf
WEnd

Func _PointIsOverControl($CName, $title = "", $text = "", $x = -1, $y = -1)
    $mouse = MouseGetPos()
    If $x = -1 Then $x = $mouse[0]
    If $y = -1 Then $y = $mouse[1]
    $CPos = ControlGetPos($title, $text, $CName)
    If @error Then Return 0
    $win = WinGetPos($title, $text)
    $mouse = MouseGetPos()
    If $x >= $win[0]+$CPos[0] and $x <= $win[0]+$CPos[0]+$CPos[2] and $y >= $win[1]+$CPos[1] and $y <= $win[1]+$CPos[1]+$CPos[2] Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc

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]
                Else
                    $aReturn[$iAdd - 1][1] = ''
                EndIf
            EndIf
        WEnd
    Next
    $aReturn[0][0] = $iAdd - 1
    Return $aReturn
EndFunc
Edited by magician13134

Share this post


Link to post
Share on other sites

I think as long as you've been a member of the forum, and as much as you've coded, this is really something you need to code on your own. From what you've shown, you've put 0% effort forward, and that's just not good enough. You didn't even care to share a working piece of code, so why should we care to help?


Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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