CMenu 未接收 Windows 触摸消息
在我的应用程序中,当我在某个窗口中收到 ON_WM_RBUTTONDOWN()
消息时,我会创建一个 CMenu,填充一些项目,然后使用 TrackPopupMenu(xxx)
显示。它与要创建的 Windows 消息没有其他交互。它默认接受左键单击来选择项目,当我使用鼠标时,我可以看到这些消息。
我试图允许在触摸屏上使用此上下文菜单 - 父窗口可以接收 WM_GESTURENOTIFY
消息(用于其他功能)以及我的应用程序的所有其他方面,例如其他窗口和对话框,它可以很好地处理触摸手势 - Spy++ 显示手势消息和 WM_LBUTTONDOWN
,这让我在整个应用程序中获得正常行为。当通过物理鼠标右键单击打开此菜单时,我可以可以触摸选择菜单项,并且触摸输入作为WM_LBUTTONDOWN
通过。
我尝试通过从触摸消息再次调用相同的创建代码来创建和显示此菜单,或者只是在触摸后手动向窗口发送 ON_WM_RBUTTONDOWN()
消息,并使用相同的标志。这创建得很好并且可以正常使用鼠标工作,就应用程序而言没有什么不同。然而,CMenu 根本没有收到任何触摸消息 - 我得到触摸式光标显示我正在点击的位置,但没有任何内容通过管道传送到菜单。
我尝试在交互发生时从手势更改为注册触摸,并确保原始手势句柄关闭,以防它因任何原因而阻塞。
我的假设是 Windows 正在幕后做一些超出我的应用程序所知的额外事情,以允许发送这些消息,所以我有点难以找到解决方案。
In my application when I receive an ON_WM_RBUTTONDOWN()
message in a certain window I create a CMenu, populated with some items, and then displayed with TrackPopupMenu(xxx)
. It has no other interaction with Windows messages to be created. It defaults to accepting left clicks to select items and I can see these messages coming in when I use the mouse.
I'm trying to allow use of this context menu on a touch screen - the parent window can receive WM_GESTURENOTIFY
messages (for other functionality) and in all other aspects of my app, such as other windows and dialogs, it handles touch gestures fine - Spy++ shows gesture messages and a WM_LBUTTONDOWN
which gives me normal behaviour across the app. I CAN touch select menu items when this menu is opened with a physical mouse right click, with the touch input coming through as a WM_LBUTTONDOWN
.
I've tried creating and displaying this menu by calling that same creation code again from a touch message, or just sending the window an ON_WM_RBUTTONDOWN()
message manually after a touch, with the same flags. This is created fine and works as normal with a mouse, and as far as the app is concerned nothing is different. However, the CMenu is not receiving any touch messages at all - I get the touch-style cursor showing where I'm tapping, but nothing is being piped through to the menu.
I've tried changing from gestures to registering touch while this interaction happens and ensuring the original gesture handle is closed in case it was blocking for whatever reason.
My assumption is that Windows is doing something additional behind the scenes beyond what my app is aware of to allow these messages to be sent through, so I'm a bit stuck for a solution.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我能够通过启用平板电脑按住手势(通常被禁用)来解决这个问题,该手势的目的是被视为右键单击并具有正确的可交互上下文菜单,而不是自己发送右键单击消息。适用于带有触摸屏的桌面和 Windows 平板电脑。
https://learn.microsoft.com/en-us/troubleshoot/developer/visualstudio/cpp/language-compilers/mfc-enable-tablet-press-and-hold-gesture
添加
ULONG CMyView::GetGestureStatus(CPoint /*ptTouch*/) { return 0; } } 是让它发挥作用的原因。
I was able to get around this issue by enabling the tablet press-and-hold gesture (it's normally disabled) which serves the purpose of being treated as a right click and having a properly interactable context menu, rather than sending the right click message myself. Works on desktop with a touch screen and a Windows tablet.
https://learn.microsoft.com/en-us/troubleshoot/developer/visualstudio/cpp/language-compilers/mfc-enable-tablet-press-and-hold-gesture
Adding
ULONG CMyView::GetGestureStatus(CPoint /*ptTouch*/) { return 0; }
was what enabled this to work.