Lexikos wrote:
Since a menu item is only deleted specifically at the script's request, I don't think it would be necessary (especially if the script is using a wrapper function to delete items)
Ok, so it sounds like the added functionality and this wrapper will be more co-op than a replacement? This is out of personal curiosity, just trying to figure what I need to modify for the Lexikos version. So, deleting items will still need to be done through this wrapper, since each menu and menu item's data needs to be destroyed with the menu / item?
Lexikos wrote:
Can you think of intuitive syntax for associating data with a menu?
A function that returns the Menu data for a menu? Menu_getData(MenuName) - or something like that. Like NumPut/Get, but for menus. Since the menu must be created before data can be associated, and because it makes little sense to add menu data to a menu item add command, I think this works.
It's a similar problem with wanting to add submenus to a menu - you must first create the menu, then add the submenu. Or, do what I do, create an "empty" menu - add a separator, then use DeleteAll, and add the "empty" submenu. I use this if I need to add a submenu, but haven't created the submenu yet... it's the one downside to using a iterative versus "recursive" programming style (I'm talking about my programmin style here). I'm a top-down thinker - so I think more breadth-first than depth-first. So, I always create empty menus when I need to add them as submenus - I don't worry about creating the submenu first.
Similarly, whatever method you currently use when creating submenus, can be used to associate menu data. Either create an empty menu, add the menu data, and then add the items; or create the menu (by adding an item), then add the menu data - either way works.
Lexikos wrote:
I think it is less difficult to associate information with a menu name than with a menu item, and therefore is less important
I agree that associated data with a menu name is easier, but it gets messy - especially if you have many values - this is why I needed OOP to begin with. For example, for the project I'm working on, the menu stores several values that are used to identify it - granted far less than a menu items. Also, the problem is if the internal data structure doesn't have a spot for the menu object, then it will be lost when AHK recreates the menu. I would love to let AHK rebuild the menus in my wrapper, but if AHK doesn't restore all the data, then the wrapper will have to do it. For example,
Menu,, [No]Standard needed a hack, because AHK would recreate the menu (and the menu / item data would be lost). Right now, using my menu wrapper, AHK has no clue if the menu has the standard menu. Instead, the code adds the standard items and removes them. This is necessary to retain the data the AHK can't restore (since its not part of the internal structure). So, bluntly, athough it's easier to associate data with a menu than a menu item, it cannot be seen as less important, because any data not being restored when AHK recreates the menus means the wrappers must be used to add data - because one of the values is if the menu has the standard items.
On a side note, that reminds me. Can you add a function to get the AHK label associated with the item? Right now, that data is stored with the item - so that the label is automatically retained when moving an item to a different menu (it's not needed when moving an item within the same menu). If you could add a command / function that returned the label, that would be awesome.
Lexikos wrote:
I realised it should also be possible to set the style of a menu. At the very least, MNS_CHECKORBMP should be the default...
Yeah, that sounds great - I should add that to the wrapper as well, thanks.
Lexikos wrote:
it will not be an issue as it has no impact on AutoHotkey's menu data structures.
Right, sorry, ignore that question. My mind was still thinking about menu and menu item objects needing to be part of AHK's menu data structures so that they will be restored. I meant to ask: will both menus and menu items have an associated value?
Lexikos wrote:
Obviously third-party applications pulling information from the application's menus while they aren't visible were not a design consideration. Why should they be?
No, I get that. But this I don't get. Why when I click Word-wrap, does the checkmark not get put until the menu is shown again? I would think it be more intuitive to put the checkmark when you click on word wrap. This way, if someone wants to know whether word-wrap is one, they can check for themselves (by sending the right message).
I mean, internally there is a variable that stores if word-wrap is on - this is how the check mark gets updated when the menu is shown. Also, when you click word-wrap, that variable toggles. Why wouldn't they update the checkmark at this time as well? Instead, they update the checkmark when the menu is shown. This sounds like a waste of energy. To gain any efficiency, don't you have to keep track of what values to update? I presume you don't update them all to the current state - that sounds foolish - and a waste. Thus, if they know that word-wrap was changed, and only update when the menu is shown, this would suggest they are trying to save the call to the menu api to set the checkmark (in case the menu is never shown again). This sounds like a lot of work for something so inexpensive as a dll call.
Lexikos wrote:
Like WinMenuSelectItem?
lol, I never knew that even existed... The wrapper function won't be exactly like it, since it requires passing the menu handle, item handle (or position - or a comma delimited list of positions), and the window. In fact, like all AHK functions, WinMenuSelectItem is nicely done, and I feel like a fool for trying to add a function that already exists. Well, I'll still keep it around because it allows selecting items from an AHK menu (like the Tray menu). But, thanks for bring that function to my awareness.