Sign in to follow this  
Followers 0
jaberwacky

GuiCtrlGetState seemingly not returning checkbox state.

3 posts in this topic

#1 ·  Posted (edited)

So I'm making what I had assumed would be a stupid simple script.  The script is supposed to change Window's active mouse tracking.  Essentially, it makes window focus follow the mouse cursor.  The problem is when I use GUICtrlGetState on the checkboxes.  They return 80 which is GUI_ENABLE + GUI_SHOW.  Should they also not return GUI_CHECKED or GUI_UNCHECKED?  I'm sure I'm just overlooking something really simple.

#Region ; Active Window Tracking Toy

#RequireAdmin

#Region ; includes

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WinAPI.au3>
#include <WinAPIsysinfoConstants.au3>

#EndRegion

#Region ; GUI generated by GUIBuilderNxt Prototype 0.9

Const $h_gui = GUICreate("Toy", 150, 140)

Const $h_active_window_tracking = GUICtrlCreateCheckbox("Enabled", 10, 40, 60, 20)

Const $h_active_window_tracking_zorder = GUICtrlCreateCheckbox("ZOrder", 10, 10, 70, 20)

GUICtrlCreateLabel("Timeout:", 10, 70, 55, 20)

Const $h_active_window_tracking_timeout = GUICtrlCreateInput('', 60, 67, 60, 20)

Const $h_exit = GUICtrlCreateButton("Exit", 100, 100, 40, 30)

#EndRegion

#Region ; init gui

Switch _get_tracking()
    Case True
        GUICtrlSetState($h_active_window_tracking, $GUI_CHECKED)

    Case False
        GUICtrlSetState($h_active_window_tracking, $GUI_UNCHECKED)
EndSwitch

Switch _get_zorder()
    Case True
        GUICtrlSetState($h_active_window_tracking_zorder, $GUI_CHECKED)

    Case False
        GUICtrlSetState($h_active_window_tracking_zorder, $GUI_UNCHECKED)
EndSwitch

GUICtrlSetData($h_active_window_tracking_timeout, _get_timeout())

GUISetState(@SW_SHOWNORMAL)

#EndRegion

_main_loop()

Func _main_loop()
    Local $msg, $timeout

    Do
        $ctrl = GUIGetMsg()
        
        Switch $ctrl
            Case $h_active_window_tracking
                Select 
                    Case _if_checked($ctrl)
                        MsgBox($MB_OK, "Checkbox1 State", GUICtrlGetState($ctrl))
    
                        _SysParamInfo($SPI_SETACTIVEWINDOWTRACKING, True)

                    Case _if_unchecked($ctrl)
                        MsgBox($MB_OK, "Checkbox1 State", GUICtrlGetState($ctrl))
    
                        _SysParamInfo($SPI_SETACTIVEWINDOWTRACKING, False)
                EndSelect

            Case $h_active_window_tracking_zorder
                Select 
                    Case _if_checked($ctrl)
                        MsgBox($MB_OK, "Checkbox2 State", GUICtrlGetState($ctrl))
    
                        _SysParamInfo($SPI_SETACTIVEWNDTRKZORDER, True)

                    Case _if_unchecked($ctrl)
                        MsgBox($MB_OK, "Checkbox2 State", GUICtrlGetState($ctrl))
    
                        _SysParamInfo($SPI_SETACTIVEWNDTRKZORDER, False)
                EndSelect

            Case $h_active_window_tracking_timeout
                $timeout = GUICtrlRead($ctrl)
                
                _SysParamInfo($SPI_SETACTIVEWNDTRKTIMEOUT, $timeout)
                
            Case $GUI_EVENT_CLOSE, $h_exit
                ExitLoop
        EndSwitch
    Until False
EndFunc

Func _SysParamInfo(Const $action, Const $v_param)
    Return _WinAPI_SystemParametersInfo($action, 0, $v_param, $SPIF_UPDATEINIFILE)
EndFunc

Func _if_checked(Const $ctrl)
    Return BitAND(GUICtrlGetState($ctrl), $GUI_CHECKED) = $GUI_CHECKED
EndFunc

Func _if_unchecked(Const $ctrl) 
    Return BitAND(GUICtrlGetState($ctrl), $GUI_UNCHECKED) = $GUI_UNCHECKED
EndFunc

Func _get_tracking()
    Local Const $tracking = DllStructCreate("bool")

    _WinAPI_SystemParametersInfo($SPI_GETACTIVEWINDOWTRACKING, 0, DllStructGetPtr($tracking))

    Return DllStructGetData($tracking, 1)
EndFunc

Func _get_zorder()
    Local Const $zorder = DllStructCreate("bool")

    _WinAPI_SystemParametersInfo($SPI_GETACTIVEWNDTRKZORDER, 0, DllStructGetPtr($zorder))

    Return DllStructGetData($zorder, 1)
EndFunc

Func _get_timeout()
    Local Const $timeout = DllStructCreate("dword")

    _WinAPI_SystemParametersInfo($SPI_GETACTIVEWNDTRKTIMEOUT, 0, DllStructGetPtr($timeout))

    Return DllStructGetData($timeout, 1)
EndFunc

#EndRegion
Edited by jaberwacky

Share this post


Link to post
Share on other sites



from the help of GUICtrlGetState():

As opposed to GUICtrlRead() this function returns ONLY the state of a control enabled/disabled/hidden/show/dropaccepted

so use GuiCtrlRead().

1 person likes this

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