jaberwacky Posted March 3, 2015 Share Posted March 3, 2015 (edited) 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? expandcollapse popup#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 March 3, 2015 by jaberwacky Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jaberwacky Posted March 3, 2015 Author Share Posted March 3, 2015 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? Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
jaberwacky Posted March 3, 2015 Author Share Posted March 3, 2015 Ok, code fixed and updated but still the problem persists. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
JohnOne Posted March 3, 2015 Share Posted March 3, 2015 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. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jaberwacky Posted March 3, 2015 Author Share Posted March 3, 2015 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. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Solution jaberwacky Posted March 3, 2015 Author Solution Share Posted March 3, 2015 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! expandcollapse popup#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 Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
JohnOne Posted March 3, 2015 Share Posted March 3, 2015 Might want to move your Const declarations out of that tight loop. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
jaberwacky Posted March 3, 2015 Author Share Posted March 3, 2015 You're right. I removed them already. Latest code is posted in the example scripts forum. Helpful Posts and Websites: AutoIt3 Variables and Function Parameters MHz | AutoIt Wiki | Using the GUIToolTip UDF BrewManNH | Can't find what you're looking for on the Forum? Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now