Is there a way to overlay an application over a fu

2020-05-05 17:29发布

问题:

I am looking to develop an application which is essentially a timer window which is always shown on the screen in front of any other application and never falls to the background when focusing other windows. An example is when I play a full-screen game I would like this timer to be overlaying the game and when I click the timer buttons on the window it does not close the game.

Any ideas how I can achieve this in C#/java/C++?

Thanks

回答1:

C#: try setting the AlwaysOnTop property of the window (form)
java: call the setAlwaysOnTop(true) on the frame or dialog



回答2:

I think that what you want to achieve can be achieved with the property TopMost of the form in C#, and setAlwaysOnTop on a Java Window ...

In C++ on Windows you have to call the SetWindowPos function and passing as argument : HWND_TOPMOST attribue.

UPDATE

Since you have an application in fullscreen mode try setting your application in foreground with the Win32 API function : SetForegroundWindow .

[System.Runtime.InteropServices.DllImport("user32.dll")]
public static extern bool SetForegroundWindow(IntPtr hWnd);

SetForegroundWindow(this.Handle);

Otherwise you can try to avoid using the Win32 SetForegroundWindow function with something like this :

this.TopMost = true;
this.Activate();