Sign in to follow this  
Followers 0
sliceofpie

RadioButton with Opt("GUIonEventMode", 1) ?

5 posts in this topic

Hi,

I'd like to use radio buttons for my script. The problem is that the rest of my script depends on Opt("GUIonEventMode", 1). When I set GUIonEventMode to 0 then everything works fine. Is there a way to integrate both?

Here's my sample code:

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#Region ### START Koda GUI section ### Form=

Opt("GUIonEventMode", 1)

Global $Radio[2]

$Form2 = GUICreate("Form2", 413, 298, 255, 208)
$Radio[0] = GUICtrlCreateRadio("Radio1", 88, 64, 113, 17)
$Radio[1] = GUICtrlCreateRadio("Radio2", 88, 184, 113, 17)
$Button1 = GUICtrlCreateButton("Button1", 88, 112, 75, 25, $WS_GROUP)
GUICtrlSetState (-1, $GUI_DISABLE)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 80, 232, 97, 17)
GUICtrlSetState (-1, $GUI_DISABLE)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###


While 1
$nMsg = GUIGetMsg()
Switch $nMsg
  Case $GUI_EVENT_CLOSE
   Exit

EndSwitch

    For $i = 0 To UBound($Radio) - 1
  If $nmsg = $Radio[$i] And BitAND(GUICtrlRead($radio[$i]), $GUI_CHECKED) = $GUI_CHECKED Then ReSet($i)

    Next

WEnd

Func ReSet($num)
    For $i = 1 To UBound($Radio) - 1
        GUICtrlSetState($Radio[$i], $GUI_UNCHECKED)
        GUICtrlSetState($Button1, $GUI_DISABLE)
  GUICtrlSetState($Checkbox1, $GUI_DISABLE)
ConsoleWrite ($num)  
    Next
    
If $num = 0 Then
    GUICtrlSetState($Button1, $GUI_ENABLE)
    GUICtrlSetState($Radio[0], $GUI_CHECKED)
ElseIf $num = 1 Then
    GUICtrlSetState($Checkbox1, $GUI_ENABLE)
    GUICtrlSetState($Radio[1], $GUI_CHECKED)  
Endif
EndFunc   ;==>ReSet

Share this post


Link to post
Share on other sites



I don't think I exlained that right.. sorry about that. Posted Image

The current script is set to disable two options and only show them when one of the radio buttons is selected.

When selecting Radio[0] , it enables Button1

When selecting Radio[1], it enables Checkbox1

The problem that I'm having is that if Opt("GUIonEventMode", 1) then those two options stay disabled. When setting Opt("GUIonEventMode", 0) this sample script above works perfectly but I'm not able to insert it into my actual script since Opt("GUIonEventMode", 0) disables other controls that I have.

I'm doing something wrong.. is there some way to disable/enable items using Opt("GUIonEventMode", 1)?

Any help is appreciated. Posted Image

Share this post


Link to post
Share on other sites

sliceofpie,

You need to decide before starting your script whether to use OnEvent or GetMessage modes - you cannot use them both in the same script (see note below). Go and read the Help file section <GUI Reference> to understand better the difference between the 2 modes. ;)

Here is your script properly coded in OnEvent mode: ;)

#include <GUIConstantsEx.au3>

Opt("GUIonEventMode", 1)

Global $Radio[2]

$Form2 = GUICreate("Form2", 413, 298, 255, 208)
GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")

$Radio[0] = GUICtrlCreateRadio("Radio1", 88, 64, 113, 17)
GUICtrlSetOnEvent(-1, "_Radio")
$Radio[1] = GUICtrlCreateRadio("Radio2", 88, 184, 113, 17)
GUICtrlSetOnEvent(-1, "_Radio")
$Button1 = GUICtrlCreateButton("Button1", 88, 112, 75, 25)
GUICtrlSetState (-1, $GUI_DISABLE)
$Checkbox1 = GUICtrlCreateCheckbox("Checkbox1", 80, 232, 97, 17)
GUICtrlSetState (-1, $GUI_DISABLE)

GUISetState(@SW_SHOW)

While 1
    Sleep(10)
WEnd

Func _Radio()

    If GUICtrlRead($Radio[0]) = 1 Then
        GUICtrlSetState($Button1, $GUI_ENABLE)
        GUICtrlSetState($Checkbox1, $GUI_DISABLE)
    Else
        GUICtrlSetState($Checkbox1, $GUI_ENABLE)
        GUICtrlSetState($Button1, $GUI_DISABLE)
    EndIf

EndFunc

Func _Exit()
    Exit
EndFunc

Read the Help file as I suggested and ask if you have any questions. :)

M23

Note: You can mix the 2 modes if you are very careful, but normally you should stick to just the one. If you do find yourself having to use both, you should have alarm bells going off and you should seriously consider recasting the code. :P


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

Thanks M23. This explains why I see posts use GUISetOnEvent instead of GUICtrlSetState.Posted Image

I did check out the GUI OnEvent Mode in the help file. I understand what the difference between them are but it didn't say when it is better to use one or the other. Maybe when programs do multiple functions, you don't want your script stuck in a loop? Just a guess.. anyhow thanks again M23. Your knowledge has given me the right information to keep going.

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