Jump to content

menuitem checkbox not visible when unchecked


 Share

Recommended Posts

I have a menu item that is set up as a checkbox.  When it's checked, I see the little box around the checkmark.  But when I set the item to unchecked, I don't see the empty box.

Here is a test script:

#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>

Example()

Func Example()
    Local $iIDView, $iIDToggle, $val

    GUICreate("My GUI menu", 100, 100)

    $iIDView = GUICtrlCreateMenu("View", -1, 1)
    $iIDToggle = GUICtrlCreateMenuItem("", $iIDView)

    setChecked($iIDToggle, True)

    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $idCancel
                Exit

            Case $iIDToggle
                $val = isChecked($iIDToggle)
                setChecked($iIDToggle, (Not $val))
        EndSwitch
    WEnd
EndFunc   ;==>Example

Func setChecked($id, $truefalse)
    Local $was, $setto, $label, $state = GUICtrlRead($id)

    $truefalse = ($truefalse) ? True : False
    $was = (BitAND($state, $GUI_CHECKED) == $GUI_CHECKED) ? True : False

    ; First, clear the $GUI_CHECKED and $GUI_UNCHECKED bits
    $setto = BitAND($was, (Not BitOR($GUI_CHECKED, $GUI_UNCHECKED)))

    ; Now set one or the other of them, based on the $truefalse value.
    If ($truefalse == True) Then
        $setto = BitOR($setto, $GUI_CHECKED)
        $label = "Checked"
    Else
        $setto = BitOR($setto, $GUI_UNCHECKED)
        $label = "Unchecked"
    EndIf

    GUICtrlSetState($id, $setto)
    GUICtrlSetData($id, $label)
EndFunc   ;==>setChecked

Func isChecked($id)
    Local $ret, $state = GUICtrlRead($id)

    If (BitAND($state, $GUI_CHECKED) == $GUI_CHECKED) Then
        Return (True)
    Else
        Return (False)
    EndIf
EndFunc   ;==>isChecked

 

Link to comment
Share on other sites

  • Moderators

AndyS19,

Welcome to the AutoIt forums.

Setting an empty string as the first parameter in GUICtrlCreateMenuItem creates a separator bar - so you have nothing to change. Change that line to read:

$iIDToggle = GUICtrlCreateMenuItem(" ", $iIDView)

and all should be well.

M23

 

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

Link to comment
Share on other sites

I tried your suggestion.  Each time the menu item is clicked, I toggle the setting as well as change the menu text.  If you run my example code, you would see the bad behavior.  I ran Notepad and toggled the "Format => Word Wrap" menu option and I see the same behavior.  Perhaps I could do something like adding an icon that looks like the empty box.  The bottom line is that my users don't get a visual clue that the menu item is a think that they could click on to toggle the option settings.

Link to comment
Share on other sites

  • Moderators

AndyS19,

I ran Notepad and toggled the "Format => Word Wrap" menu option and I see the same behavior

Because what you complain of is the standard behaviour. So stop worrying and just let the user work it out for themselves - or explain in the Help documentation you of course provide for your app.

M23

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see 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

 

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...