I know its really easy to get the menu item count via DllCall but it seems like a standard enough property for the Menu object to implement.
MenuObj.length could just indirectly call DllCall("GetMenuItemCount", "Ptr", hwnd, "Int")
v2 Menu Object length
Re: v2 Menu Object length
i was just about to suggest to extend the prototype, but that doesn't appear to be at all possible
is that intended to be like so? or maybe still in the works?
is that intended to be like so? or maybe still in the works?
Re: v2 Menu Object length
It's a bug. Initialization order of object prototypes/classes is something I got wrong on several counts (but most are fixed). Most of the prototypes are constructed via static initializers, and there's no guarantee of order for static initializers in different files. Initially the Tray menu had no base because the prototype hadn't been constructed yet, but I changed it to construct the prototype when the first Menu is created. However, the Tray menu is always first; it is instantiated from the Script constructor, which is called by a static initializer in script.cpp, which (by chance) is executed before the static initializers in script_object.cpp. So in other words, as a result of the change, the Tray menu has a prototype but the prototype no longer inherits from Object.Prototype.
The prototype can be fixed like this:
Then you can use it like this:
I chose not to add Count or Length because it is not possible to retrieve items, and because my priority was on replacing the Menu command, which has no such capabilities.
With Length, there may be an expectation that you can iterate from this[1] to this[this.Length]. Map has Count, but there's no relation between the value of Count and the values you use as keys.
The prototype can be fixed like this:
Code: Select all
if !ObjGetBase(A_TrayMenu.base)
ObjSetBase(A_TrayMenu.base, Object.Prototype)
Code: Select all
A_TrayMenu.base.DefineProp("Length", {get: this => DllCall("GetMenuItemCount", "Ptr", this.Handle, "Int")})
M := MenuCreate()
M.Add("Foo", (*) => MsgBox("Bar"))
MsgBox M.Length
With Length, there may be an expectation that you can iterate from this[1] to this[this.Length]. Map has Count, but there's no relation between the value of Count and the values you use as keys.
Who is online
Users browsing this forum: No registered users and 17 guests