主弹出菜单的左上角坐标 [英] the top left coordinates of a main popup menu

查看:75
本文介绍了主弹出菜单的左上角坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在处理子菜单的项目时,我想获得引起弹出菜单的右键单击的位置.我需要它相对于窗口.

我设法获得了子菜单的位置,但是没有成功获得指向主菜单的指针以获取后者的位置.子菜单窗口的getParent函数返回null.

I want to get the position of the right click that envoked a popup menu while handling the an item of the sub-menu. I need it relative to the window.

I managed to get the position of the sub menu but didn''t succeed getting the pointer to the main menu to get the latter''s position. The getParent function to the submenu window returns null.

推荐答案

在弹出菜单中获取它为时已晚.您想在右键单击时捕获鼠标位置.我的意思是某个事件导致您首先弹出菜单.

您可能直接或在消息映射中使用ON事件来处理WM_RBUTTONDOWN消息.那就是当您知道鼠标在哪里时. GetCursorPos()会为您提供该信息.

当然,您几乎可以随时发出GetCursorPos(),因此,如果您确定鼠标在右键单击和处理菜单的代码之间没有移动太多,那么在这里也可能有帮助.您将需要尝试一下.我不会那样做.

哦,顺便说一句,菜单的左上角可能根本不是单击发生的地方.考虑一个托盘图标,它在屏幕上非常低,但是具有与右键单击相关联的大菜单.左上角可能与您右键单击的实际图标相距很远.

OH和另一个BTW,就像Windows中几乎所有的东西一样,Mouse Position相对于询问它的窗口而言.也就是说,根据询问的上下文,鼠标的位置可能是指桌面,主窗口,菜单或菜单中的项.只是警告您要小心.
Getting it in the popup menu is too late. You want to capture the mouse position at the time of the Right-Click itself. I mean that some event caused you to popup the menu in the first place.

You probably handle the WM_RBUTTONDOWN message, either directly or using an ON event in your message map. That is when you know where the mouse is. GetCursorPos() will give you that information.

Of course, you can issue GetCursorPos() just about anytime so if you are sure the mouse didn''t move much between the right click and your code to process the menu, it might help there too. You''ll need to experiment with that. I don''t do things that way.

Oh, BTW, the top-left of the menu may not be where the click happened at all. Consider a tray Icon that is very low on the screen but has a large menu associated with the right click. The top-left can be very far from the actual Icon where you right-clicked.

OH, and another BTW, the Mouse Position, like just about anything in Windows, is Relative to the Window that asked about it. That is, the location of the mouse might refer to the desktop, the main window, the menu, or an item in the menu, depending on the context of asking. Just warning you to be careful.


这篇关于主弹出菜单的左上角坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆