主弹出菜单的左上角坐标

编程入门 行业动态 更新时间:2024-10-26 10:40:31
本文介绍了主弹出菜单的左上角坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

在处理子菜单的项目时,我想获得引起弹出菜单的右键单击的位置.我需要它相对于窗口. 我设法获得了子菜单的位置,但是没有成功获得指向主菜单的指针以获取后者的位置.子菜单窗口的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.

更多推荐

主弹出菜单的左上角坐标

本文发布于:2023-07-18 04:54:20,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1141192.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:左上角   弹出   坐标   菜单

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!