Jump to content

Getting the name of a button on the menu item failed even though the menu was displayed in the event


Recommended Posts

Allow me to greedily ask 2 questions:
1> When putting guictrlcreatemenuitem in the function and catching the event, does it consume ram resources? Every time I load the menuitem, it cannot read the changed button name.

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>

Opt('GUIOnEventMode', 1)
Global $Button1
$GUI = GUICreate("Test Menu", 349, 222, 192, 124)
$Button1 = GUICtrlCreateButton("Button Show Menu", 96, 56, 131, 81)
GUISetOnEvent($GUI_EVENT_CLOSE, '_Exit')
GUISetOnEvent($GUI_EVENT_SECONDARYUP, "_SecondaryUp")
GUISetState(@SW_SHOW)

While 1
WEnd

Func _SecondaryUp()
    $aCInfo = GUIGetCursorInfo($GUI)
    Switch $aCInfo[4]
        Case $Button1
            _ShowMenu()
    EndSwitch
EndFunc   ;==>_SecondaryUp

Func _ShowMenu()
$CtMenu = GUICtrlCreateContextMenu($Button1)
$Event = GUICtrlCreateMenuItem(GUICtrlRead($Button1), $CtMenu)
GUICtrlSetOnEvent($Event, '_RMenu')
EndFunc

Func _RMenu()
GUICtrlSetData($Button1, 'Button Show Menu '& Random(0, 99, 1))
EndFunc

Func _Exit()
    Exit
EndFunc

2> I have an order of: 0000000000(10 zeros)
When there is the first order, then: 0000000001 (9 numbers 0 and 1)
When the order is up to 10, then 0000000010(8 zeros and 10s)
I searched but nothing came up so I did this:
$job = 0000000000
If StringLen($job) > 10 Then StringRight($job, 10)
Is there any better function? I don't find it effective

Link to post
Share on other sites

Thank you JockoDundee! Here is me cut out the example style. Normally, use Guictrlsetdata() guictrlread() when working on the gui. I'm looking for a function that can always add up, for example: 0001 + 0002 = 0003 0010 + 0020 = 0030 0100 + 0200 = 0300 1000 + 0100 = 1100 like that

Link to post
Share on other sites

1>

Func _ShowMenu()
    Local Static $CtMenu    ; <-- added
    GUICtrlDelete($CtMenu)  ; <-- added
    $CtMenu = GUICtrlCreateContextMenu($Button1)
    $Event = GUICtrlCreateMenuItem(GUICtrlRead($Button1), $CtMenu)
    GUICtrlSetOnEvent($Event, '_RMenu')
EndFunc   ;==>_ShowMenu

2>

StringFormat("%010s", $iYourNumber) ; <-- formats $iYourNumber as 10 chars with leading zero

 

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to post
Share on other sites
1 hour ago, Loc said:

1> It seems to be 1 or 2 beats slower

it's not slower, it shows "previous button title" because in the logic of your script, you first read the title of the button and after you set a new name to the the button, so you get "one title on late"

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

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
  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...