“粘性” MFC 弹出菜单

发布于 2024-08-08 20:25:53 字数 529 浏览 3 评论 0原文

目前,我有一些侧面带有小箭头的工具栏按钮 (TBSTYLE_EX_DRAWDDARROWS),单击这些按钮时,会在按钮下方显示一个弹出上下文菜单。这是通过构建自定义弹出菜单并调用 TrackPopupMenu 来完成的。

客户端现在希望能够在菜单关闭之前从菜单中选择多个选项,以便可以修改多个选项,而无需重新打开菜单并等待每次更改之间的中间重画。

例如:

  1. 用户单击下拉按钮
  2. 出现下拉菜单(模式,无限期等待用户操作)
  3. 用户单击某个项目(例如,切换复选标记)
  4. 计时器(例如,500 毫秒)启动
  5. 如果计时器到期,则菜单将关闭,并且所有选定的操作都会被取消。被执行。
  6. 用户在计时器到期之前单击另一个项目,返回到 4。

我能想到的最好办法是通过多次调用 TrackPopupMenu 来重新显示菜单。当您选择一个项目时,这会使菜单“闪烁”,并且可能需要我启动一个线程才能超时,我宁愿避免这种情况。

I currently have some toolbar buttons with a small arrow on the side (TBSTYLE_EX_DRAWDDARROWS) that, when clicked, result in a popup context menu being displayed under the button. This is done by constructing a custom popup menu and calling TrackPopupMenu.

The client now wants to be able to select multiple options from the menu before it closes, so that multiple options can be be modified without the need to re-open the menu and wait for an intermediate redraw between each change.

For example:

  1. User clicks dropdown button
  2. Dropdown menu appears (modal, waits indefinitely for user action)
  3. User clicks some item (e.g., toggle a checkmark)
  4. Timer (e.g., 500ms) starts
  5. If timer expires, the menu is closed and all selected actions are executed.
  6. User clicks another item before the timer expires, go back to 4.

The best I can come up with is to redisplay the menu by calling TrackPopupMenu multiple times. This makes the menu "flicker" when you select an item, and will probably require me to start a thread in order to do the timeouts, which I would rather avoid.

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

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

发布评论

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

评论(2

2024-08-15 20:25:53

设置一个包含选项的对话框,而不是菜单。对话框可以轻松完成所需的所有操作。

当您单击它时不关闭的菜单看起来就是错误的。自行关闭的对话似乎也是错误的,但这可能是两个弊端中最小的一个。

编辑:如果说我从 Microsoft 学到了什么,那就是不要试图对抗默认行为。如果你这样做,你就是在自找麻烦。

如果您正在动态构建菜单,我可以看到自动调整大小是多么方便,但这在对话框中也不难做到 - 让对话框非常大,在它变得可见之前,枚举子级并取所有它们的并集矩形,然后调整大小。检查边界以确保它们在屏幕上只需使用 OffsetRect 的几个 if 语句。复选框是微不足道的;图标不太好,但仍然不错。

另一项很容易添加的增强功能是双击后立即关闭对话框。

Rather than a menu, put up a dialog box with the options on it. A dialog can easily do all that is required.

A menu that doesn't close when you click it will just seem wrong. A dialog that closes by itself will seem wrong too, but it's probably the least of two evils.

Edit: If there's anything I've learned with Microsoft, it's don't try to fight the default behavior. You're asking for trouble if you do.

If you're building your menu dynamically I can see how automatic sizing can be handy, but it's not hard to do in a dialog either - make the dialog really big and before it becomes visible, enumerate the children and take a union of all their rectangles, then resize to that. Checking the boundaries to make sure they're on-screen is just a few if statements with OffsetRect. Checkboxes are trivial; icons less so, but still not bad.

One additional enhancement that would be easy to add is to dismiss the dialog immediately on a double-click.

俯瞰星空 2024-08-15 20:25:53

按照@Mark Ransom 的回答,您应该打开一个对话框。但是您可以使对话框成为无模式,并在您单击对话框外部时使其自行关闭(即对话框失去焦点)。这样它就可以更像一个菜单。

请注意,普通菜单永远不会自行消失,您始终必须单击菜单(或其选项之一)之外的某个位置才能使其消失。

Following @Mark Ransom's answer, you should put up a dialog box. But you can make the dialog modeless and make it close itself when you click outside of it (i.e., the dialog loses focus). That way it could behave more like a menu.

Notice that normal menus never go away by themselves, you always have to click somewhere outside the menu (or one of its options) to make it disappear.

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