如何获取带有 ID 的菜单项的文本

How to get the text of a menu item with its ID

我有一个旧的可视序言项目,我必须在运行时更改其中的菜单文本。
这是我为更改文本所做的工作:

menu_setText(Win, id_menu, NewMenuText)

这很好用,但是,当我想 enable/disable 这个菜单时,下面的命令不起作用(这意味着菜单项不会改变它的状态):

menu_Enable(Win, id_menu, b_true)

经过一番搜索,我发现:

Under MS-Windows, submenus can not be referred to by a resource identifier. If the menu entry for a submenu, needs to enabled, disabled, checked or have the text changed. it is necessary to use a special versions of the menu_Enable, menu_Check and menu_SetText predicates, which specify the text of the menu entry instead of the constant.
menu_Enable(WinHandle, String, BOOLEAN)
menu_Check(WinHandle, String, BOOLEAN)
menu_SetText(WinHandle, String, NewString)

奇怪的是,在我的例子中,menu_setTextmenu_Enable 需要文本本身的常数一起工作得很好。 (是的,我用菜单项的初始文本测试了 menu_Enable,但是当文本更改时,一切都会中断)

我的问题来了:

How can I enable/disable a menu when I know its ID but not its name ?
If not possible directly, how can I get the current name of a menu when I know its ID ?

如果这有帮助,这个项目是用 VIP52 打开和编译的(自 2001 年之前)。

我终于找到了解决我问题的方法,但我仍然不是很满意,所以如果有人提出更好的答案,我会采纳!

我声明:

txt_menu(menu_tag,string)

然后调用:

txt_menu(id_menu, MenuText),
menu_setText(Win, MenuText, NewText),
retractAll(txt_menu(id_menu,_)),
assert(txt_menu(id_menu,NewText)),
menu_Update(Win)

每当我必须更改菜单项的文本时,这可以很容易地转换为 menu_setTextById 谓词,如下所示:

menu_setTextById(Win, MenuId, NewText):-
    txt_menu(MenuId, MenuText),
    menu_setText(Win, MenuText, NewText),
    retractAll(txt_menu(MenuId,_)),
    assert(txt_menu(MenuId, NewText)),
    menu_Update(Win).

用法:

menu_setTextById(Win, id_menu, "My new text menu").

请注意,如果我需要多个 windows 菜单,我必须将 Window ID 添加到我的 txt_menu 子句中。


此解决方法的主要问题是我无法在新文本菜单中使用 &,因为如果我的菜单将“&Menu”作为文本(意味着 M 将带有下划线) ,然后尝试使用 menu_setText(Win,"&Menu","New Menu") 将中断,因为未找到“&Menu”。

因此,在尝试在此类谓词中使用它之前,我需要从字符串中删除任何与号。