Jump to content

Menuitem checked / unckecked


Verssuss
 Share

Recommended Posts

after few try i can say that shorter code is better then long. long ago didint know what that mean...

how to finish this script in shortest (best way)
something is wrong at some point

 

#include <Constants.au3>
#include <GUIConstants.au3>
#include <AutoItConstants.au3>

GUICreate("123123",300,300,400,250)
GUISetState()
$menu_opt = GUICtrlCreateMenu("Options")
$menu_1 = GUICtrlCreateMenu("Set", $menu_opt)
Local $menu[5]
$menu[0] = GUICtrlCreateMenuItem("0", $menu_1)
$menu[1] = GUICtrlCreateMenuItem("1", $menu_1)
$menu[2] = GUICtrlCreateMenuItem("2", $menu_1)
$menu[3] = GUICtrlCreateMenuItem("3", $menu_1)
GUICtrlSetState(-1, $GUI_CHECKED)
$menu[4] = GUICtrlCreateMenuItem("4", $menu_1)


While 1

    Switch GUIGetMsg()

        Case $GUI_EVENT_CLOSE
            Exit

;~      Case $menu                                      Long version
;~          $cors_spot[0] = 0
;~          GUICtrlSetState($menu[0], $GUI_CHECKED)
;~          GUICtrlSetState($menu[1], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[2], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[3], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[4], $GUI_UNCHECKED)
;~      Case $menu
;~          $cors_spot[1] = 1
;~          GUICtrlSetState($menu[0], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[1], $GUI_CHECKED)
;~          GUICtrlSetState($menu[2], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[3], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[4], $GUI_UNCHECKED)
;~      Case $menu
;~          $cors_spot[2] = 2
;~          GUICtrlSetState($menu[0], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[1], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[2], $GUI_CHECKED)
;~          GUICtrlSetState($menu[3], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[4], $GUI_UNCHECKED)
;~      Case $menu
;~          $cors_spot[3] = 3
;~          GUICtrlSetState($menu[0], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[1], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[2], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[3], $GUI_CHECKED)
;~          GUICtrlSetState($menu[4], $GUI_UNCHECKED)
;~      Case $menu
;~          $cors_spot[4] = 4
;~          GUICtrlSetState($menu[0], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[1], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[2], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[3], $GUI_UNCHECKED)
;~          GUICtrlSetState($menu[4], $GUI_CHECKED)




;~      Case $menu[0]                                       Shorter version
;~          For  $i = 0 To UBound($menu) -1
;~              GUICtrlSetState($menu[$i], $GUI_UNCHECKED)
;~          Next
;~          GUICtrlSetState($menu[0], $GUI_CHECKED)

;~      Case $menu[1]
;~          For  $i = 0 To UBound($menu) -1
;~              GUICtrlSetState($menu[$i], $GUI_UNCHECKED)
;~          Next
;~          GUICtrlSetState($menu[1], $GUI_CHECKED)

;~      Case $menu[2]
;~          For  $i = 0 To UBound($menu) -1
;~              GUICtrlSetState($menu[$i], $GUI_UNCHECKED)
;~          Next
;~          GUICtrlSetState($menu[2], $GUI_CHECKED)

;~      Case $menu[3]
;~          For  $i = 0 To UBound($menu) -1
;~              GUICtrlSetState($menu[$i], $GUI_UNCHECKED)
;~          Next
;~          GUICtrlSetState($menu[3], $GUI_CHECKED)

;~      Case $menu[4]
;~          For  $i = 0 To UBound($menu) -1
;~              GUICtrlSetState($menu[$i], $GUI_UNCHECKED)
;~          Next
;~          GUICtrlSetState($menu[4], $GUI_CHECKED)



                                                            ;right version
        Case $menu[0] To $menu[4]
            For $i = 0 To UBound($menu) -1
                GUICtrlSetState($menu[$i], $GUI_UNCHECKED)
                If GUIGetMsg() = $menu[0] Then GUICtrlSetState($menu[0], $GUI_CHECKED)
                If GUIGetMsg() = $menu[1] Then GUICtrlSetState($menu[1], $GUI_CHECKED)
                If GUIGetMsg() = $menu[2] Then GUICtrlSetState($menu[2], $GUI_CHECKED)
                If GUIGetMsg() = $menu[3] Then GUICtrlSetState($menu[3], $GUI_CHECKED)
                If GUIGetMsg() = $menu[4] Then GUICtrlSetState($menu[4], $GUI_CHECKED)
            Next

    EndSwitch
WEnd

 

Link to comment
Share on other sites

Maybe you can use menuradioitem parameter in GUICtrlCreateMenuItem() like this:

#include <Constants.au3>
#include <GUIConstants.au3>
#include <AutoItConstants.au3>

GUICreate("123123",300,300,400,250)
GUISetState()
$menu_opt = GUICtrlCreateMenu("Options")
$menu_1 = GUICtrlCreateMenu("Set", $menu_opt)
Local $menu[5]
$menu[0] = GUICtrlCreateMenuItem("0", $menu_1, -1, 1)
$menu[1] = GUICtrlCreateMenuItem("1", $menu_1, -1, 1)
$menu[2] = GUICtrlCreateMenuItem("2", $menu_1, -1, 1)
$menu[3] = GUICtrlCreateMenuItem("3", $menu_1, -1, 1)
GUICtrlSetState(-1, $GUI_CHECKED)
$menu[4] = GUICtrlCreateMenuItem("4", $menu_1, -1, 1)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit
    EndSwitch
WEnd

 

Edited by Zedna
Link to comment
Share on other sites

got it

 

#include <Constants.au3>
#include <GUIConstants.au3>
#include <AutoItConstants.au3>

GUICreate("123123",300,300,400,250)
GUISetState()
$menu_opt = GUICtrlCreateMenu("Options")
$menu_1 = GUICtrlCreateMenu("Set", $menu_opt)
Local $menu[5]
$menu[0] = GUICtrlCreateMenuItem("0", $menu_1, -1, 1)
$menu[1] = GUICtrlCreateMenuItem("1", $menu_1, -1, 1)
$menu[2] = GUICtrlCreateMenuItem("2", $menu_1, -1, 1)
$menu[3] = GUICtrlCreateMenuItem("3", $menu_1, -1, 1)
GUICtrlSetState(-1, $GUI_CHECKED)
$menu[4] = GUICtrlCreateMenuItem("4", $menu_1, -1, 1)
$var = 100
While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $menu[0]
            $var = 0
        Case $menu[1]
            $var = 1
        Case $menu[2]
            $var = 2
        Case $menu[3]
            $var = 3
        Case $menu[4]
            $var = 4
    EndSwitch

    ConsoleWrite($var & @CRLF)
    Sleep(10)
WEnd


in this case it working right for me

also anyway i try figure out method with check-boxes how to control them better

Edited by Verssuss
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...