Sign in to follow this  
Followers 0
orange

Cannot Change Menu Item Checked State -

10 posts in this topic

#1 ·  Posted (edited)

I have this code to generate a menu item:

$menuControlID = GUICtrlCreateMenuItem("Example Menu", $SettingsMenu)
GUICtrlSetOnEvent(-1, "ExampleMenuFunction")
GUICtrlSetState(-1, $GUI_CHECKED)oÝ÷ Øz0z÷«¶ç$yÛ-j×8D97!jx"ج½êò~»¬¶¶­xáÞâë-j׬iº.¶g§º+^Ê'+ajÚ®¢×µ«^¡öªºfz{¨­ª®¢Ú®¢Ùè­zj®¢×(Úè·z-mèbuקý¿êº^J¥az»-jׯj¸nW¬j·¡Ë¦z{^vÚ0¢¹«Þ¶¸vë"¨Úèg­©Ýæ¬Áéejëh×6Func ExampleMenuFunction()
$TempHandle = ControlGetHandle("","",$menuControlID)
 if Guictrlgetstate($TempHandle) = $GUI_CHECKED then guictrlsetstate($TempHandle,$GUI_UNCHECKED)
 if Guictrlgetstate($TempHandle) = $GUI_UNCHECKED then guictrlsetstate($TempHandle,$GUI_CHECKED)
EndFuncoÝ÷ Ø­¶­v¬mÂäz+az²!j÷­®'z÷«ÊØbajÒ$!£§tz-ëm+,µ«^¶!jx"¯zÚâyÖÆP­®Tµ+rïÛlerÚåIëRµ«^
í®FzÑÚÙ^ý³h¶§ÇËhÂä¶!jx¶¬²Ö­xZ½ëj·!yÛayú+ºkÒjyèµø§u©ò¶§·¥jاÚ-+²Ø^­æ§ÊÞ¶­q©ÚÙ{aÂ-ÊÞjYr~»¬¶¶­xØ­±ç¦±«- Ø^­ë!¢é]mæ¬jezÊ%ºØ¨8ZKÀÊ¡ë'¢Ü(®F®¶­sbb33cµFV×ôæFÆRÒuT7G&ÄvWDæFÆRb33c¶ÖVçT6öçG&öÄB¢wV7G&Ç6WG7FFRb33cµFV×ôæFÆRÂb33c´uTõTä4T4´TB
Edited by orange

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Try changing this and see what happens

Func ExampleMenuFunction()
 if Guictrlgetstate($menuControlID ) = $GUI_CHECKED then guictrlsetstate($menuControlID ,$GUI_UNCHECKED)
 if Guictrlgetstate($menuControlID ) = $GUI_UNCHECKED then guictrlsetstate($menuControlID ,$GUI_CHECKED)
EndFunc

To

Func ExampleMenuFunction()
 MsgBox(0,"TEST",Guictrlgetstate($menuControlID ))
 if Guictrlgetstate($menuControlID ) = 65 then guictrlsetstate($menuControlID ,68)
 if Guictrlgetstate($menuControlID ) = 68 then guictrlsetstate($menuControlID ,65)
 MsgBox(0,"TEST",Guictrlgetstate($menuControlID ))
EndFunc

Just to see what happens.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

Return:

Msgbox 1: 0

Msgbox 2: 0

;************************************

EDIT:

Also does not work:

if bitand(Guictrlgetstate($menuControlID),$GUI_CHECKED) = 1 then msgbox (0,0,"Checked")
    if bitand(Guictrlgetstate($menuControlID),$GUI_UNCHECKED) = 1 then msgbox (0,0,"Checked")oÝ÷ Ù8b±«­¢+Ù¥¹Éä¡Õ¥ÑɱÑÍÑÑ ÀÌØíµ¹Õ
½¹Ñɽ±%¤¤

returns 0x000000.

Shouldn't there be SOMETHING initalized? $GUI_Checked = 1, and $GUI_Unchecked = 4, so shouldn't "binary(Guictrlgetstate($menuControlID))" return something like: 0x000001 or 0x000100

Edited by orange

Share this post


Link to post
Share on other sites

Return:

Msgbox 1: 0

Msgbox 2: 0

;************************************

EDIT:

Also does not work:

if bitand(Guictrlgetstate($menuControlID),$GUI_CHECKED) = 1 then msgbox (0,0,"Checked")
    if bitand(Guictrlgetstate($menuControlID),$GUI_UNCHECKED) = 1 then msgbox (0,0,"Checked")oÝ÷ Ù8b±«­¢+Ù¥¹Éä¡Õ¥ÑɱÑÍÑÑ ÀÌØíµ¹Õ
½¹Ñɽ±%¤¤

returns 0x000000.

Shouldn't there be SOMETHING initalized? $GUI_Checked = 1, and $GUI_Unchecked = 4, so shouldn't "binary(Guictrlgetstate($menuControlID))" return something like: 0x000001 or 0x000100

I just remembered, for menu items it's not GUICtrlGetState(). Use GUICtrlRead() instead.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

When I try this:

MsgBox(0,"TEST",binary(guictrlread($menuControlID )))
    guisetstate($menuControlID ,68)
    MsgBox(0,"TEST",binary(guictrlread($menuControlID )))

I get two return values of 0x4100000

However, if I manually change the declaration of the Menu item to Unchecked, I get this:

0x4400000

The difference is important; using GUICTRLREAD, I can find out the checked state, however, as noted above, GUICtrlSetState does not set the state of a menu control.

Edit: Yup, only the name of the control.

Anybody got any more ideas?

I am now trying GuiCtrlSetData, but I doubt that that is going to change anything but the name of the menu.

Edited by orange

Share this post


Link to post
Share on other sites

When I try this:

MsgBox(0,"TEST",binary(guictrlread($menuControlID )))
    guisetstate($menuControlID ,68)
    MsgBox(0,"TEST",binary(guictrlread($menuControlID )))

I get two return values of 0x4100000

However, if I manually change the declaration of the Menu item to Unchecked, I get this:

0x4400000

The difference is important; using GUICTRLREAD, I can find out the checked state, however, as noted above, GUICtrlSetState does not set the state of a menu control.

Edit: Yup, only the name of the control.

Anybody got any more ideas?

I am now trying GuiCtrlSetData, but I doubt that that is going to change anything but the name of the menu.

I just looked at a piece of my working code and I'm definitly using GUICtrlSetState() and I'm using the numeric values instead of those damned constants.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

SOLVED:

Here is the finalized version of working code, I am not sure why this took so long, but I hope that this is useful to someone who needs it:

if guictrlread($menuControlID) = 65 then 
        guictrlsetstate($menuControlID ,68)
    elseif guictrlread($menuControlID) = 68 
         guictrlsetstate($menuControlID ,65)
    EndIf

Thanks again to GEOSoft who saved my day. I appreciate it.

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I'm not using GUICtrlSetOnEvent(). I just have this code in the idle Loop

Case $Menu_Opts_Min To $Menu_Opts_Animate
            If $Msg = $Menu_Opts_Run_Locate Then
                NotAvail()
                Return
            EndIf
            If GUICtrlRead($Msg) = 65 Then
                GUICtrlSetState($Msg, 68)
                If $Msg = $Menu_Opts_Min Then
                    IniWrite($Ini,'Program Settings','MinimizeOnUse','4')
                    $Min = 4
                ElseIf $Msg = $Menu_Opts_Backups Then
                    IniWrite($Ini,'Program Settings','Save PreEdit','4')
                    $E_Back = 4
                ElseIf $Msg = $Menu_Opts_Cust Then
                    IniWrite($Ini,'Program Settings','CustFold','4')
                    $Cust_Fldrs = 4
                ElseIf $Msg = $Menu_Opts_Templ Then
                    IniWrite($Ini,'Program Settings','UseShell','4')
                    $Use_Templates = 4
                ElseIf $Msg = $Menu_Opts_Animate Then
                    IniWrite($Ini, 'Program Settings','Animate','4')
                    $Animate = 4
                EndIf
            Else
                GUICtrlSetState($Msg, 65)
                If $Msg = $Menu_Opts_Min Then
                    IniWrite($Ini,'Program Settings','MinimizeOnUse','1')
                    $Min = 1
                ElseIf $Msg = $Menu_Opts_Backups Then
                    IniWrite($Ini,'Program Settings','Save PreEdit','1')
                    $E_Back = 1
                ElseIf $Msg = $Menu_Opts_Cust Then
                    IniWrite($Ini,'Program Settings','CustFold','1')
                    $Cust_Fldrs = 1
                ElseIf $Msg = $Menu_Opts_Templ Then
                    IniWrite($Ini,'Program Settings','UseShell','1')
                    $Use_Templates = 1
                ElseIf $Msg = $Menu_Opts_Animate Then
                    IniWrite($Ini, 'Program Settings','Animate','1')
                    $Animate = 1
                EndIf
            EndIf

And that is pasted directly from the working code

EDIT: Just forget about the INI lines and string variables like $Animate because they don't apply to your code. This was just an example of how I do it.

Edited by GEOSoft

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Share this post


Link to post
Share on other sites

This should be mentioned in the help file (about state of menu items - 65 and 68) - i am also a while ago had the same problem, and it took me couple of hours to figure it out (by checking every possibility with Gui... tools - just like you guys did).


 

Spoiler

Using OS: Win 7 Professional, Using AutoIt Ver(s): 3.3.6.1 / 3.3.8.1

AutoIt_Rus_Community.png AutoIt Russian Community

My Work...

Spoiler

AutoIt_Icon_small.pngProjects: ATT - Application Translate Tool {new}| BlockIt - Block files & folders {new}| SIP - Selected Image Preview {new}| SISCABMAN - SciTE Abbreviations Manager {new}| AutoIt Path Switcher | AutoIt Menu for Opera! | YouTube Download Center! | Desktop Icons Restorator | Math Tasks | KeyBoard & Mouse Cleaner | CaptureIt - Capture Images Utility | CheckFileSize Program

AutoIt_Icon_small.pngUDFs: OnAutoItErrorRegister - Handle AutoIt critical errors {new}| AutoIt Syntax Highlight {new}| Opera Library! | Winamp Library | GetFolderToMenu | Custom_InputBox()! | _FileRun UDF | _CheckInput() UDF | _GUIInputSetOnlyNumbers() UDF | _FileGetValidName() UDF | _GUICtrlCreateRadioCBox UDF | _GuiCreateGrid() | _PathSplitByRegExp() | _GUICtrlListView_MoveItems - UDF | GUICtrlSetOnHover_UDF! | _ControlTab UDF! | _MouseSetOnEvent() UDF! | _ProcessListEx - UDF | GUICtrl_SetResizing - UDF! | Mod. for _IniString UDFs | _StringStripChars UDF | _ColorIsDarkShade UDF | _ColorConvertValue UDF | _GUICtrlTab_CoverBackground | CUI_App_UDF | _IncludeScripts UDF | _AutoIt3ExecuteCode | _DragList UDF | Mod. for _ListView_Progress | _ListView_SysLink | _GenerateRandomNumbers | _BlockInputEx | _IsPressedEx | OnAutoItExit Handler | _GUICtrlCreateTFLabel UDF | WinControlSetEvent UDF | Mod. for _DirGetSizeEx UDF
 
AutoIt_Icon_small.pngExamples: 
ScreenSaver Demo - Matrix included | Gui Drag Without pause the script | _WinAttach()! | Turn Off/On Monitor | ComboBox Handler Example | Mod. for "Thinking Box" | Cool "About" Box | TasksBar Imitation Demo

Like the Projects/UDFs/Examples? Please rate the topic (up-right corner of the post header: Rating AutoIt_Rating.gif)

* === My topics === *

==================================================
My_Userbar.gif
==================================================

 

 

 

AutoIt is simple, subtle, elegant. © AutoIt Team

Share this post


Link to post
Share on other sites

This should be mentioned in the help file (about state of menu items - 65 and 68) - i am also a while ago had the same problem, and it took me couple of hours to figure it out (by checking every possibility with Gui... tools - just like you guys did).

It was worse at one time. AutoIt code was broken and instead of 68 you had to use 69. It was only when I asked a question in Developer Chat that someone noticed it. But actually for menu items it does make sense because they can't be set to hidden.

Therefore you have

Enabled = 64

Disabled = 128

Checked = 1

Unchecked = 4

Therefore

Enabled + checked = 65

Disabled + unchecked = 132


George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

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