Jump to content

GUICtrlGetState Can't get enabled/disabled state


Go to solution Solved by Nine,

Recommended Posts

Hi,

I want to get the state of menu-items created with GUICtrlCreateMenuItem.

I want to get the state which has been set with GUICtrlSetState($n, $GUI_ENABLE) Or GUICtrlSetState($n, $GUI_DISABLE)

But whatever I try I cannot get it working.

Thanks for assistance.

Cheers mike

Link to comment
Share on other sites

Hi,

thanks for the answer.

I think, the problem comes from the initial value.

If the controls are created but not state is set yet, i get the value 0, which is not $enabled or $disabled.

So far as I see the values should be:

$enabled = 128

$disabled = 64

If i have set the values first time I get the right values with my code above.

i just do not understand, that controls, which are active by default respond with 0, until setting is changed for the first time.

cheers mike

 

 

Link to comment
Share on other sites

  • Developers
Posted (edited)

Use the bitand as suggested already or post that piece of code so we can suggest the change.

Edited by Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Hi again,

have come to this code piece, which works me:

If GUICtrlGetState($idGlo_WE_Replace) <= $GUI_ENABLE Then
    ;Enabled
EndIf

If GUICtrlGetState($idGlo_WE_Replace) > $GUI_ENABLE Then
    ;Disabled
EndIf

This works also if the control has not received a GUICtrlSetState before.
In this case GUICtrlGetState would get 0 instead of 64.
$GUI_ENABLE is 64
$GUI_DISABLE is 128

Thanks for your help.

Cheers mike

Link to comment
Share on other sites

  • Developers

Try something like this with BitAnd() :

If BitAND(GUICtrlGetState($idGlo_WE_Replace),$GUI_ENABLE) = $GUI_ENABLE Then

 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Guys, could you have a look at the script below.
As Mike noticed, why GUICtrlSetState returns 0 when you click the button "Menu Item State" for the 1st time ?

It seems strange, because when you add a button in a GUI, an immediate BitAnd(GUICtrlGetState(... $GUI_ENABLE)) indicates that the button IS enabled, so why is it different when it comes to a menuitem control ?

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

Opt("MustDeclareVars", 1) ;0=no, 1=require pre-declaration

Local $hGUI = GUICreate("Test", 250, 200)
Local $idMenu = GUICtrlCreateMenu("Languages") ; control id 3
Local $idMenuItem = GUICtrlCreateMenuItem("English", $idMenu) ; control id 4

Local $idState = GUICtrlCreateButton("Menu Item State", 50, 20, 150, 30) ; control id 5
Local $idDisable = GUICtrlCreateButton("Menu Item Disable", 50, 70, 150, 30) ; control id 6
Local $idEnable = GUICtrlCreateButton("Menu Item Enable", 50, 120, 150, 30) ; control id 7

GUISetState(@SW_SHOW)

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            Exit

        Case $idState
            For $i = $idMenu To $idEnable
                If BitAND(GUICtrlGetState($i), $GUI_ENABLE) = $GUI_ENABLE Then
                    ConsoleWrite("Controle #" & $i & " enable" & @crlf)
                EndIf
            Next
            ConsoleWrite("------------------" & @crlf)

            MsgBox($MB_TOPMOST, "State",  _
                "GuiCtrlGetState($idMenuItem) = " & GUICtrlGetState($idMenuItem) & @crlf & _
                "GuiCtrlRead($idMenuItem) = " & GUICtrlRead($idMenuItem))

        Case $idDisable
            GUICtrlSetState($idMenuItem, $GUI_DISABLE)

        Case $idEnable
            GUICtrlSetState($idMenuItem, $GUI_ENABLE)
    EndSwitch
WEnd
Link to comment
Share on other sites

It doesn't matter much.  If equals to 0, it means enable.  Same goes for _GUICtrlMenu_GetItemState.  You can alternatively use this function and it will return 0 also.  ps. i know it does not mean the same, but...

It is not possible (but did not extensively tested it) to have a disabled menu item to be at state 0.  So just test for disable, and if not then (you got your answer) ;)

Edited by Nine
Link to comment
Share on other sites

Posted (edited)
18 hours ago, Jos said:

Try something like this with BitAnd() :

If BitAND(GUICtrlGetState($idGlo_WE_Replace),$GUI_ENABLE) = $GUI_ENABLE Then

 

same result for enabled: first time 0 , when set before 64

the problem is that GUICtrlCreateMenuItem creates items, which are enabled by default, but the value is not 64.

Ofcourse you can workaround like this or that.

If GUICtrlCreateMenuItem would be in a library, this could be corrected by setting up GUICtrlSetState($id, $GUI_ENABLE) after.

cheers mike

Edited by mike1950r
Link to comment
Share on other sites

  • Developers
41 minutes ago, mike1950r said:

same result for enabled: first time 0 , when set before 64

Why care? I shown a way to test for enabled. 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

  • Solution
Link to comment
Share on other sites

1 hour ago, Nine said:

Alright, since you have not read my reply, here the code that will solve your "issue" :

Func IsMenuEnable($iID)
  Return Not BitAND(GUICtrlGetState($iID), $GUI_DISABLE)
EndFunc

 

 

Hi Nine,

sorry if I did not pay attention for your post.
(english is not my mother language, sometimes I miss something)

This function, testing via opposite of enabled works, cause disable is always sent allright.

Cheers mike

Link to comment
Share on other sites

  • Developers
26 minutes ago, mike1950r said:

Hi Jos,

I tried this, but without success.

Cheers mike

Show us what you tried so we see what is happening!

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Jos,

BitAND(GUICtrlGetState($idGlo_WE_Replace),$GUI_ENABLE)

does not change the result.

I get 0 or 64 like posted above.

If I want to use $GUI_ENABLE I must use:

If GUICtrlGetState($idGlo_WE_Replace) <= $GUI_ENABLE Then
    ;Enabled
EndIf

Or use $GUI_DISABLE instead:

If Not (GUICtrlGetState($idGlo_WE_Replace) = $GUI_DISABLE) Then
    ;Enabled
EndIf

I can live with these posibilities.

Cheers mike

Link to comment
Share on other sites

  • Developers

Again, post me an example that shows your issue, and I am happy to take a look, but am not in business to code a testscript for you! ;) 

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

Posted (edited)

Jos,

I have no issue anymore and you don't need to code a testscript for me.

Last post I have told the solutions which are fine.

Thanks for your help.

Cheers mike

🙂

Edited by mike1950r
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...