视窗.更改下拉菜单位置 [英] Windows. Change drop-down menu position

查看:26
本文介绍了视窗.更改下拉菜单位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法改变弹出菜单的位置.对于顶级窗口,我可以通过 CBTProc 回调函数和 MoveWindow 来完成.我可以对菜单做同样的事情吗?需要这样做,以便弹出菜单仅位于其父窗口的区域中.类似于轻型窗口管理器的东西.

Is there a way to change the position of the popup menu. With top-level windows I can do it by CBTProc Callback Function and MoveWindow. Can I do the same with menus? Needs to be done so that the pop-up menu is located only in the area of its parent window. Something like a light window manager.

推荐答案

是的,在 WH_CBT 钩子回调中,您将收到 HCBT_CREATEWND 每当创建菜单窗口时.测试类名,标准菜单/子菜单窗口的类名将是#32768".然后您可以发送 MN_GETHMENU 消息到窗口以找出即将激活的菜单.但是如文档所述,它太在收到通知时尽早移动窗口,菜单甚至还不可见,因此您可能需要对窗口进行子类化并处理其他消息.

Yes, in a WH_CBT hook callback, you'll be notified with an 'nCode' of HCBT_CREATEWND whenever a menu window is created. Test for the class name, standard menu/submenu windows would have a class name of '#32768'. You can then send a MN_GETHMENU message to the window to find out which menu is about to be activated. But as documented, it is too early to move the window when the notification is received, the menu is not even visible yet, so you might need to sub-class the window and process additional messages.

请注意,您不需要在显示菜单窗口时通知挂钩,您可以为 WM_ENTERIDLE 消息,测试 'wParam' 以查看菜单是否导致消息,获取菜单窗口从 'lParam' 再次发送一个 'MN_GETHMENU' 来找出具体的菜单.此时可以移动窗口而无需进一步处理消息.请注意,'WM_ENTERIDLE' 将被多次调用,因此您需要跟踪是否已经移动了特定窗口.

Note that you don't need a hook to be notified when a menu window is shown, you can put a handler for the WM_ENTERIDLE message, test for 'wParam' to see if a menu caused the message, get the menu window from 'lParam' and again send a 'MN_GETHMENU' to find out the specific menu. It is possible to move the window at this point without further message handling. Just be aware that 'WM_ENTERIDLE' will be called multiple times so you need to keep track of you've already moved a particular window or not.

这篇关于视窗.更改下拉菜单位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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