sypard Posted February 1, 2012 Posted February 1, 2012 I need this script, I want the image to change when i change radio #include <ButtonConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> #Region ### START Koda GUI section ### Form= $Form1 = GUICreate("Form1", 346, 177, 192, 124) $Pic1 = GUICtrlCreatePic("img\1.jpg", 24, 24, 120, 120, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) $green = GUICtrlCreateRadio("green", 184, 56, 113, 17) $red = GUICtrlCreateRadio("red", 184, 96, 113, 17) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 If GUICtrlRead($green) = $GUI_Checked Then $Pic1 = GUICtrlCreatePic("img\1.jpg", 24, 24, 120, 120, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) If GUICtrlRead($red) = $GUI_Checked Then $Pic1 = GUICtrlCreatePic("img\2.jpg", 24, 24, 120, 120, BitOR($SS_NOTIFY,$WS_GROUP,$WS_CLIPSIBLINGS)) $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
water Posted February 1, 2012 Posted February 1, 2012 If you want it to be repaired: What is broken? My UDFs and Tutorials: Spoiler UDFs: Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki Standard UDFs: Excel - Example Scripts - Wiki Word - Wiki Tutorials: ADO - Wiki WebDriver - Wiki
wraithdu Posted February 1, 2012 Posted February 1, 2012 (edited) First off, GUICtrlRead on a radio returns the state of the control... however the state is a summation of all applicable states. You cannot use an = test, you must use a bitwise test: If BitAND(GUICtrlRead($green), $GUI_CHECKED) Then... Also, checking the radio states like that in a loop where you act on the current state, even if it has not changed, is a huge waste of resources. You should only change the state of the control IF you NEED to change the state of the control. You are also just indiscriminately creating Pic controls then overwriting the variable that references them... you are seriously hemorrhaging resources again. You only need to create the control one time then use GUICtrlSetImage to update it. Edited February 1, 2012 by wraithdu
BrewManNH Posted February 1, 2012 Posted February 1, 2012 The code If GUICtrlRead($someradiocontrol) = $GUI_CHECKED is functionally the same as If BitAND(GUICtrlRead($someradiocontrol), $GUI_CHECKED). They both will fire off the comparison the same way. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
AdmiralAlkex Posted February 1, 2012 Posted February 1, 2012 The code If GUICtrlRead($someradiocontrol) = $GUI_CHECKED is functionally the same as If BitAND(GUICtrlRead($someradiocontrol), $GUI_CHECKED). They both will fire off the comparison the same way.So you are saying the helpfile lies? Explain yourself.For Checkbox, Radio control several states can be returned as $GUI_FOCUS and $GUI_CHECKED,. So use i.e. BitAnd(GUICtrlRead($Item),$GUI_CHECKED) to test if the control is checked. .Some of my scripts: ShiftER, Codec-Control, Resolution switcher for HTC ShiftSome of my UDFs: SDL UDF, SetDefaultDllDirectories, Converting GDI+ Bitmap/Image to SDL Surface
BrewManNH Posted February 1, 2012 Posted February 1, 2012 (edited) If it says you can't use GUICtrlRead to check the status of a radio box as to whether it's checked or not, then it's wrong. Here's a demo of it working just fine with GUICtrlRead. expandcollapse popup#include <GUIConstantsEx.au3> Example() Func Example() Local $msg, $Status, $LastStatus, $Radio1Status, $Radio2Status, $LastRadio1Status, $LastRadio2Status GUICreate("My GUI Checkbox") ; will create a dialog box that when displayed is centered Local $Checkbox1 = GUICtrlCreateCheckbox("CHECKBOX 1", 10, 10, 120, 20) Local $radio1 = GUICtrlCreateRadio("Radio 1", 10, 40, 120, 20) Local $radio2 = GUICtrlCreateRadio("Radio 2", 10, 70, 120, 20) GUICtrlSetState($radio2, $GUI_CHECKED) GUISetState() ; will display an dialog box with 1 checkbox ; Run the GUI until the dialog is closed While 1 $msg = GUIGetMsg() If $msg = $GUI_EVENT_CLOSE Then ExitLoop $Status = GUICtrlRead($Checkbox1) If $Status = $GUI_CHECKED Then If $Status <> $LastStatus Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Status = ' & $Status & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $LastStatus = $Status EndIf Else If $Status <> $LastStatus Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Status = ' & $Status & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $LastStatus = $Status EndIf EndIf $Radio1Status = GUICtrlRead($radio1) $Radio2Status = GUICtrlRead($radio2) If $Radio1Status = $GUI_CHECKED Then If $Radio1Status <> $LastRadio1Status Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Radio1Status = ' & $Radio1Status & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $LastRadio1Status = $Radio1Status EndIf Else If $Radio1Status <> $LastRadio1Status Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Radio1Status = ' & $Radio1Status & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $LastRadio1Status = $Radio1Status EndIf EndIf If $Radio2Status = $GUI_CHECKED Then If $Radio2Status <> $LastRadio2Status Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Radio2Status = ' & $Radio2Status & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console $LastRadio2Status = $Radio2Status EndIf Else If $Radio2Status <> $LastRadio2Status Then ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $Radio2Status = ' & $Radio2Status & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console $LastRadio2Status = $Radio2Status EndIf EndIf WEnd EndFunc ;==>ExampleThe help file has a lot of incorrect information in it, in this case that method will work but it's incorrect when it says you can't use GUICtrlRead reliably with checkboxes and radiobuttons.EDIT: Cut and paste error when I posted the code above, corrected it. Edited February 1, 2012 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
wraithdu Posted February 1, 2012 Posted February 1, 2012 In this case I would say the incorrect information is that GUICtrlRead returns all active states of a checkbox or radio button. It seems to only return checked or unchecked. GUICtrlGetState seems to be correct though, in that it returns all states except checked/unchecked. Regardless, I would rather write code based on the documentation of what the function is supposed to do, than what the function does in practice, when the devs can easily fix this bug and break all your code. Fixing behavior to fit the documentation would not constitute a script breaking change and might not be documented in the changelog so specifically. Whereas changing the documentation to fit behavior would (or at least should).
BrewManNH Posted February 1, 2012 Posted February 1, 2012 The help file states in the information for GUICtrlRead:Checkbox, Radio state of the button. See State table And the state table mentioned in GUICtrlRead has this information in it.$GUI_UNCHECKED Radio, Checkbox or ListViewItem will be unchecked. $GUI_CHECKED Radio, Checkbox or ListViewItem will be checked. So, the information in the help file that states that GUICtrlRead needs to be read with BitAnd is misleading even if it is partially correct. If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
BrewManNH Posted February 1, 2012 Posted February 1, 2012 (edited) Regardless, I would rather write code based on the documentation of what the function is supposed to do, than what the function does in practice, when the devs can easily fix this bug and break all your code. I would write code based on the correct information myself, if the documentation is wrong then the way you're doing it might be changed as well. Fixing behavior to fit the documentation would not constitute a script breaking change and might not be documented in the changelog so specifically. Whereas changing the documentation to fit behavior would (or at least should). Which behavior would you like to fit, the part where it says to use GUICtrlRead for checkboxes/radios directly or the part where it says you can't do that even though elsewhere it says you can. The documentation is constantly being changed when people find that it's wrong, or the software doesn't work the way it says it does. BTW, writing code that matches the documentation, when the documentation is wrong is bound to have more script breaking changes than writing code that fits how the commands actually work, especially when it works as intended.EDIT: Just realized we're talking about 2 different uses of GUICtrlRead where the BitAnd part seems to only be needed if you're using the Advanced flag which returns more information than just using GUICtrlRead without that flag being used. The only problem is that the example with BitAnd doesn't use the flag in it. Edited February 1, 2012 by BrewManNH If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag GudeHow to ask questions the smart way! I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from. Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays. - ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script. - Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label. - _FileGetProperty - Retrieve the properties of a file - SciTE Toolbar - A toolbar demo for use with the SciTE editor - GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI. - Latin Square password generator
wraithdu Posted February 1, 2012 Posted February 1, 2012 And the state table mentioned in GUICtrlRead has this information in it.So, the information in the help file that states that GUICtrlRead needs to be read with BitAnd is misleading even if it is partially correct.Ah, but don't misinterpret this part. Nothing in that verbage says that checked/unchecked states are the only states that a checkbox or radio may have. And it only implies by omission that checked/unchecked states are exclusive to those three controls. In fact if you read the control state with GUICtrlGetState you will see all the other applicable states (GUI_ENABLE, GUI_SHOW for example) are returned except for checked/unchecked.But certainly BitAND isn't going to do anything with the advanced flag set, as that will return text.Really, a dev is going to have to say which is correct, the behavior or the docs.
wraithdu Posted February 1, 2012 Posted February 1, 2012 (edited) BTW, writing code that matches the documentation, when the documentation is wrong is bound to have more script breaking changes than writing code that fits how the commands actually work, especially when it works as intended.Except that we don't know that the doc is wrong or that the function is working as intended. All we know is that the doc does not match the behavior. In this case I'll err on the side of the doc being the intended behavior. Which also happens to err on the side of caution, as the BitAND test will work in both situations, where a simple = test will fail in one. Edited February 1, 2012 by wraithdu
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