且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

视窗.更改下拉菜单位置

更新时间:2022-06-26 00:19:13

是的,在 WH_CBT 钩子回调中,您将收到 HCBT_CREATEWND的nCode"通知> 每当创建菜单窗口时.测试类名,标准菜单/子菜单窗口的类名将是#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.