Mimic outside click on a popup menu

[亡魂溺海] 提交于 2020-01-04 06:31:31

问题


You know how in a popup menu if you click outside of the menu the popup disappears? Well I would like to reproduce that.

Currently I am having a panel created with some components on it when a button is clicked. The panel and sub components go away when you click a certain button on the panel. However I want it to go away if you click anywhere outside of the panel.


回答1:


I think you would need to install and application-wide mouse message hook, and if your panel is visible and the coordinates of the mouse event are outside of your panel bounds, then hide the panel. Also handle the WM_ACTIVATE message in your form.

[Edited: removed answer involving SetCaptureControl() because the bahaviour is not appropriate in this circumstance]



来源:https://stackoverflow.com/questions/3112402/mimic-outside-click-on-a-popup-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!