动态操作菜单以在 Windows 应用程序中创建 MRU 进行中

发布于 2025-01-03 18:30:47 字数 1535 浏览 2 评论 0原文

我有一个用 Progress 编写的 Windows 应用程序。我正在使用 10.1C 版本。我想在菜单中添加 MRU 功能,即我想在应用程序的“文件”菜单中添加、删除和修改菜单项,以按使用顺序显示用户最近的文件。我已经在许多其他语言中经常这样做了,这是一个非常常见的功能并且非常容易做到。

但在 Progress 中如何做到这一点呢?在另一种语言中,我可以创建 10 个菜单项,然后简单地使未使用的菜单项不可见,但在 Progress 中您不能这样做。我无法想象为什么。

或者,我应该能够根据需要动态创建菜单项,并将它们添加到“文件”菜单中 MRU 列表的末尾,但我似乎也无法这样做:首先,我无法指定“文件”菜单中的位置该项目必须添加,它总是将其添加到底部,其次,我无法将动态菜单添加到静态菜单,因此我无法将我的 MRU 菜单添加到现有的文件菜单。如果我将整个文件菜单设为动态(我真的不想这样做),我就可以做到这一点,但是我无法将动态文件菜单添加到静态菜单栏。这给我留下了使整个菜单结构动态化的不可接受的选择。

有人有什么想法吗?



使用下面阿德的答案,这是我如何实现它的一个简短示例。更改 MRU 项目的标签和值不需要任何摆弄,只需设置适当的属性,但为了添加新的 MRU 项目,我必须删除并重新创建“退出”菜单项

/* Remove the RULE and Exit menu items */
IF VALID-HANDLE(ghMenuRule) THEN DELETE OBJECT ghMenuRule.
IF VALID-HANDLE(ghMenuExit) THEN DELETE OBJECT ghMenuExit.

/*

...
Coding to add MRU items.
...

*/


/* Create the RULE and Exit menu items */
CREATE MENU-ITEM ghMenuRule
  ASSIGN
    SUBTYPE = "RULE"
    PARENT    = MENU m_File:HANDLE IN MENU MENU-BAR-C-Win.

CREATE MENU-ITEM ghMenuExit
  ASSIGN
    PARENT    = MENU m_File:HANDLE IN MENU MENU-BAR-C-Win
    LABEL     = "E&xit"
  TRIGGERS:
      ON CHOOSE PERSISTENT RUN ExitApp IN THIS-PROCEDURE.
  END TRIGGERS.

:实际的 MRU 项的创建方式与此处创建的退出菜单类似,只是我将句柄存储在临时表中。

结果是这样的菜单:

        File
          New
          Open
          --------
          Print Setup
          Print
          --------
          1 Mru item 
          2 Mru Item
          3 Mru Item
          --------
          Exit

I have a Windows application written in Progress. I'm working with version 10.1C. I would like to add MRU functionality to the menu, i.e. I want to add, remove and modify menu items in the application's File menu, to show the user's most recent files in the order in which they were used. I've done this often enough in a number of other languages, it's a pretty common feature and very easy to do.

But how would one do this in Progress? In another language I could have created 10 menu items and simply made the unused ones invisible, but you can't do that in Progress. I can't imagine why.

Alternatively, I should be able to dynamically create menu items as needed and add them to the end of the MRU list in the File menu, but I can't seem do that either: Firstly, I can't specify where in the File menu the item must be added, it always adds it to the bottom, and secondly, I can't add dynamic menus to static menus, so I can't add my MRU menus to the existing File menu. I can do it if I make the whole File menu dynamic (which I really don't want to do), but then I can't add the dynamic File menu to the static menu bar. This leaves me with the unacceptable option of making the entire menu structure dynamic.

Does anybody have any ideas?


Using Ade's answer below, here is a brief example of how I achieved it. Changing the labels and values of the MRU items doesn't require any fiddling, just set the appropriate attributes, but in order to add new MRU items, I have to remove and recreate the Exit menu item:

/* Remove the RULE and Exit menu items */
IF VALID-HANDLE(ghMenuRule) THEN DELETE OBJECT ghMenuRule.
IF VALID-HANDLE(ghMenuExit) THEN DELETE OBJECT ghMenuExit.

/*

...
Coding to add MRU items.
...

*/


/* Create the RULE and Exit menu items */
CREATE MENU-ITEM ghMenuRule
  ASSIGN
    SUBTYPE = "RULE"
    PARENT    = MENU m_File:HANDLE IN MENU MENU-BAR-C-Win.

CREATE MENU-ITEM ghMenuExit
  ASSIGN
    PARENT    = MENU m_File:HANDLE IN MENU MENU-BAR-C-Win
    LABEL     = "E&xit"
  TRIGGERS:
      ON CHOOSE PERSISTENT RUN ExitApp IN THIS-PROCEDURE.
  END TRIGGERS.

The actual MRU items are created just like the Exit menu is created here, except that I store the handles in a temp-table.

The result is a menu like this:

        File
          New
          Open
          --------
          Print Setup
          Print
          --------
          1 Mru item 
          2 Mru Item
          3 Mru Item
          --------
          Exit

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

为人所爱 2025-01-10 18:30:47

创建静态菜单MENU-BAR-C-Win。

添加静态子菜单“文件”m_file。

将静态菜单项(使用“>>”)“退出”(m_Exit) 添加到 m_file。

定义....
将变量 hMRU#1 定义为处理 NO-UNDO。

创建一个按钮来动态地...

  CREATE MENU-ITEM hMRU#1
  ASSIGN
    PARENT    = MENU m_File:HANDLE IN MENU MENU-BAR-C-Win
    LABEL     = "MRU#1"
  TRIGGERS:
      ON CHOOSE PERSISTENT RUN SomeThing IN THIS-PROCEDURE.
  END TRIGGERS.

您需要以某种方式跟踪您的句柄(临时表?)。

create a static menu MENU-BAR-C-Win.

add static sub-menu "File" m_file.

add static menu-item (use ">>") "Exit" (m_Exit) to m_file.

define....
DEFINE VARIABLE hMRU#1 AS HANDLE NO-UNDO.

create a button to dynamically...

  CREATE MENU-ITEM hMRU#1
  ASSIGN
    PARENT    = MENU m_File:HANDLE IN MENU MENU-BAR-C-Win
    LABEL     = "MRU#1"
  TRIGGERS:
      ON CHOOSE PERSISTENT RUN SomeThing IN THIS-PROCEDURE.
  END TRIGGERS.

you'll want to keep track of your handles (temp-table?) some how.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文