Jump to content
Sign in to follow this  
jaberwacky

Setting a parameter via _WinAPI_SystemParametersInfo seemingly not taking effect.

Recommended Posts

So, I have this script that is supposed to set active window tracking which I go into in >this thread.

Because of orbs pointing out something to me, I now can focus on the meat of the script.  You'd think I didn't know what the helpfile is sometimes.  I did in fact read that, and I've used the BitAND method many times in the past too.

Anyhoo.

When I check the checkbox entitled "Enabled", the setting does not actually seem to take effect.  I've restarted afterwards, but no joy.

Any thoughts on the matter?

#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

; Majorly edited by hand because I messed up code generation.
; At least I didn't have to futz around with aligning the controls by hand.

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

Const $h_tracking = GUICtrlCreateCheckbox("Enabled", 10, 10, 70, 20)

Const $h_zorder = GUICtrlCreateCheckbox("ZOrder", 10, 40, 60, 20)

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

Const $h_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_tracking, $GUI_CHECKED)

    Case False
        GUICtrlSetState($h_tracking, $GUI_UNCHECKED)
EndSwitch

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

    Case False
        GUICtrlSetState($h_zorder, $GUI_UNCHECKED)
EndSwitch

GUICtrlSetData($h_timeout, _get_timeout())

GUISetState(@SW_SHOWNORMAL)

#EndRegion

_main_loop()

Func _main_loop()
    Local $timeout

    Do        
        Switch GUIGetMsg()
            Case $h_tracking
                Select
                    Case _if_checked($h_tracking)    
                        _SysParamInfo($SPI_SETACTIVEWINDOWTRACKING, True)

                    Case _if_unchecked($h_tracking)    
                        _SysParamInfo($SPI_SETACTIVEWINDOWTRACKING, False)
                EndSelect

            Case $h_zorder
                Select
                    Case _if_checked($h_zorder)    
                        _SysParamInfo($SPI_SETACTIVEWNDTRKZORDER, True)

                    Case _if_unchecked($h_zorder)    
                        _SysParamInfo($SPI_SETACTIVEWNDTRKZORDER, False)
                EndSelect

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

Func _SysParamInfo(Const $action, Const $v_param)
    Local Const $ret = _WinAPI_SystemParametersInfo($action, 0, $v_param, $SPIF_UPDATEINIFILE)
    
    Return $ret ? True : SetError(1, _WinAPI_GetLastErrorMessage(), False)
EndFunc

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

Func _if_unchecked(Const $ctrl)    
    Return BitAND(GUICtrlRead($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

omg, I just realized I have the checkbox's in the wrong order.  I really should get some sleep.  Why do I always get the urge to code when I'm well past my peak?

Share this post


Link to post
Share on other sites

I had a problem some time ago with this SystemParametersInfo, as I recall it had something to do with a global broadcast to all top level windows.

It's all I remember sorry, cannot find the thread, if I even made one.

Share this post


Link to post
Share on other sites

Thanks for the reply!

I'll search for this.  Which I should have done to begin with.

This is a weird morning for me.  I've been up all night.  I've had three cups of coffee.  I've lifted a bit of weights.  Now my heart is pumping adrenaline.  I feel all nervous and weird.  Woe is me.

Share this post


Link to post
Share on other sites

Got it!

Having looked at the function in the WinAPI include, I saw that the function was expecting a dllstruct.  So, created one and loaded it up with the boolean value.  And bam, it works!

Thanks!

#Region ; Active Window Tracking Toy

#Region ; AutoIt3Wrapper

#AutoIt3Wrapper_Version=B

#autoit3Wrapper_jump_to_first_error=y

#AutoIt3Wrapper_Run_AU3Check=n
#AutoIt3Wrapper_AU3Check_Parameters=-w 1 -w 2 -w 4 -w 6 -w 7

#AutoIt3Wrapper_Run_Tidy=n

#EndRegion

#RequireAdmin

#Region ; includes

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

#EndRegion

#Region ; GUI generated by GUIBuilderNxt Prototype 0.9

; Majorly edited by hand because I messed up code generation.
; At least I didn't have to futz around with aligning the controls by hand.

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

Const $h_tracking = GUICtrlCreateCheckbox("Enabled", 10, 10, 70, 20)

Const $h_zorder = GUICtrlCreateCheckbox("ZOrder", 10, 40, 60, 20)

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

Const $h_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_tracking, $GUI_CHECKED)

    Case False
        GUICtrlSetState($h_tracking, $GUI_UNCHECKED)
EndSwitch

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

    Case False
        GUICtrlSetState($h_zorder, $GUI_UNCHECKED)
EndSwitch

GUICtrlSetData($h_timeout, _get_timeout())

GUISetState(@SW_SHOWNORMAL)

#EndRegion

_main_loop()

Func _main_loop()
    Local $timeout

    Do      
        Switch GUIGetMsg()
            Case $h_tracking
                Select 
                    Case _if_checked($h_tracking)   
                        Local Const $zorder = DllStructCreate("bool")
                        
                        DllStructSetData($zorder, 1, False)
                        
                        _SysParamInfo($SPI_SETACTIVEWINDOWTRACKING, DllStructGetPtr($zorder))

                    Case _if_unchecked($h_tracking) 
                        Local Const $zorder = DllStructCreate("bool")
                        
                        DllStructSetData($zorder, 1, False)
                        
                        _SysParamInfo($SPI_SETACTIVEWINDOWTRACKING, DllStructGetPtr($zorder))
                EndSelect

            Case $h_zorder
                Select 
                    Case _if_checked($h_zorder) 
                        _SysParamInfo($SPI_SETACTIVEWNDTRKZORDER, True)

                    Case _if_unchecked($h_zorder)   
                        _SysParamInfo($SPI_SETACTIVEWNDTRKZORDER, False)
                EndSelect

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

Func _SysParamInfo(Const $action, Const $v_param)   
    Local Const $ret = _WinAPI_SystemParametersInfo($action, 0, $v_param, $SPIF_SENDCHANGE) ; $SPIF_UPDATEINIFILE
    
    Return $ret ? True : SetError(1, _WinAPI_GetLastErrorMessage(), False)
EndFunc

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

Func _if_unchecked(Const $ctrl) 
    Return BitAND(GUICtrlRead($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

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  

×
×
  • Create New...