使窗口保持在所有其他C/Java窗口的顶部 [英] Keeping Window OnTop of all other windows C/Java

查看:61
本文介绍了使窗口保持在所有其他C/Java窗口的顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读,发现Java Swing无法在没有可怕的闪烁效果的情况下停留在全屏应用程序之上.这是真的?闪烁效果:我有一个线程,每200毫秒将frame.setAlwaysOnTop()更新为true.

I have been doing some reading and have found out that the Java Swing cannot stay on top of full screen applications without a horrible flickering effect. Is this true? The flickering effect: I have a thread that updates the frame.setAlwaysOnTop() to true every 200ms.

如果是的话,我正在寻找一种替代方法来进行此操作,并且正在阅读有关C/C ++/C#的SetWindowsPos的信息,那么这似乎会对我有所帮助.但是,在重写程序之前,我想知道是否可以将程序保留在另一个全屏应用程序的顶部.谢谢

If it is I was looking for an alternative to method to do this in and was reading about C/C++/C#s SetWindowsPos and it looks like this would do it for me. However, before I rewrite my program I want to know if this will allow me to keep my program on top of another fullscreen application. Thanks

推荐答案

简短的回答:不是,不是.

Short answer: Not really, no.

更长的答案:全屏"应用程序使用的显示方式与普通Windows GUI应用程序不同.它们的确切工作方式取决于应用程序和操作系统.大多数将利用DirectX或OpenGL API,这些API允许应用程序直接操纵代表屏幕的内存,以及访问GPU的加速功能.这些应用程序通过基本创建一个GUI窗口"(更像一个面板)来支持,该窗口"覆盖整个主显示并且始终在顶部",从而防止了桌面元素永远被绘制在全屏之后而被绘制应用程式的视窗(以Z顺序排列).然后,该应用程序可以轻松"访问代表该GUI窗口的显示矩形的内存,因此它可以操纵单个像素,而无需使用消息循环来重新绘制该区域.

Longer answer: A "full-screen" app uses the display in a different way than a normal Windows GUI app. Exactly how they work depends on the application and the OS; most will leverage the DirectX or OpenGL APIs which allow applications to directly manipulate the memory representing the screen, as well as access the accelerated capabilities of the GPU. These apps are supported by basically creating a GUI "window" (more like a panel) that covers the entire primary display and is "always on top", preventing the desktop elements from ever being painted as they're always behind the full-screen app's window in the Z-order. The application then gets "relaxed" access to the memory representing the display rectangle of that GUI window, so it can manipulate individual pixels without needing to use the message loop to repaint that area.

在这种情况下,显示是在应用程序需要时绘制的(实际上总是尽可能快"或与下一个监视器扫描同步"),而不是在Windows GUI认为合适的时候绘制.因此,当Windows认为这是个好主意时,涂上的所有东西都会闪烁.Windows在GUI的Z顺序中在应用程序的窗口"上绘制始终位于顶部"窗口,然后通过直接在其矩形上绘制,应用程序在窗口上绘制.这将导致Windows无效并重新绘制窗口,并且循环继续进行.

In this situation, the display is being painted when the application wants (which is virtually always either "as fast as possible" or "synchronized with the next monitor scan"), NOT when the Windows GUI thinks it's a good time. So, anything that IS painted when Windows thinks it's a good idea will flicker; Windows paints your "always on top" window over the app's "window" in the GUI's Z-order, then the app paints back over the window by drawing directly onto its rectangle. That causes Windows to invalidate and redraw your window, and the cycle continues.

解决方案不仅是创建始终位于顶部"窗口,而且还需要以编程方式从全屏应用程序窗口任务切换"到您的窗口.这可能要求您的应用具有大多数托管运行时无法或不会授予的特权.如果可能的话,全屏应用程序会最小化(对于您的用户而言,这可能是一个大问题,也可能不是一个大问题;无论您的应用程序试图告诉我什么,几乎都不值得将StarCraft 2会话最小化在线混战中.)

The solution is not only to make an "always-on-top" window, but to somehow programmatically "task-switch" from the full-screen app's window to yours. This may require your app to have privileges that most managed runtimes can't or won't grant. If it's possible, then when it happens the full-screen app will minimize (which may or may not be a HUGE problem for your users; whatever your app is trying to tell me, it will almost certainly NOT be worth minimizing my StarCraft 2 session in the middle of an online melee).

这篇关于使窗口保持在所有其他C/Java窗口的顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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