Loc Posted July 11, 2021 Share Posted July 11, 2021 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 comment Share on other sites More sharing options...
JockoDundee Posted July 11, 2021 Share Posted July 11, 2021 Instead of If StringLen($job) > 10 Then StringRight($job, 10) don’t you want If StringLen($job) > 10 Then $job = StringRight($job, 10) or some other assignment, otherwise it does nothing. Code hard, but don’t hard code... Link to comment Share on other sites More sharing options...
Loc Posted July 11, 2021 Author Share Posted July 11, 2021 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 comment Share on other sites More sharing options...
Gianni Posted July 11, 2021 Share Posted July 11, 2021 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 Loc 1 Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Loc Posted July 11, 2021 Author Share Posted July 11, 2021 1> It seems to be 1 or 2 beats slower Link to comment Share on other sites More sharing options...
Loc Posted July 11, 2021 Author Share Posted July 11, 2021 Link to comment Share on other sites More sharing options...
Gianni Posted July 11, 2021 Share Posted July 11, 2021 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" Chimp small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt.... Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now