Mac OSX Overlay

六眼飞鱼酱① 提交于 2019-12-10 12:19:19

问题


How would I go about programming a HUD type overlay in OSX. I want to be able to have an application that will display text at a certain point over a different application's window.

And thus if the (other applications) window moves the HUD part will stay at the same coordinate of the other window.


回答1:


For the window itself, use a borderless, transparent window (plenty of examples) with your own custom view into which to draw your overlaid elements.

For the "other applications' windows" part, there's no public API that's going to let you do this smoothly. You use Universal Access and its window location/navigation API, but it requires your users to turn on "Enable access for assistive devices" (I think it still can't be done programmatically). I don't believe it "lets you know" when a window moves, but I could be wrong. If it does, it'd likely be a one-shot "here's where I am now", so your overlay would likely not keep up. I also don't think it gives you the "window level" to allow you to make sure you're "above" any given window/sheet/palette.

The only other option (to move with other apps' windows) is a system-wide, invasive hack a la Application Enhancer (which is quite controversial). It's easy to get this wrong and destabilize a user's system (hence the controversy).




回答2:


You could use undocumented CoreGraphics Functions in order to track a window, see http://code.google.com/p/undocumented-goodness/source/browse/trunk/CoreGraphics/CGSPrivate.h



来源:https://stackoverflow.com/questions/1825280/mac-osx-overlay

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