如何使Windows总是在最上层的应用 [英] How to make Windows Always on top application
问题描述
我想打一个小软件,它可以提供窗口运行的应用程序,以总在最前面功能,如Linux终端提供,VLC媒体播放器等
我发现与此相关的互联网上的某些应用。但我想在上面实用程序始终创建我自己的。
I want to make a small software which can provide the windows running applications to "always on top functionality" as available in Linux terminal, VLC media player etc. I have found some application related to this on internet. but i want to create my own always on top utility.
这将是更好的,如果ü可以建议C#.NET代码。和IDE:我会喜欢的Visual Studio
It will be better if u can suggest c# .net code. and IDE: i will prefer Visual Studio
我的目标是使应用程序如下所示:
My goal is to make the application as shown here:
< A HREF =http://www.pcworld.com/article/218511/Windows.html相对=nofollow> http://www.pcworld.com/article/218511/Windows.html
推荐答案
有关使它通用于所有的过程,你必须重载User32.dll中的两种方法是Win32 API中的一部分
For making it generic to any process, you have to overload two methods of the User32.dll which is a part of Win32 API.
只要使用如下的代码,并没有它的扩展名指定您的进程名,说了VLC - 指定
Just use the code given below and specify your process name without its extension, say for vlc - specify
processName =VLC;
和 NOT LIKE vlc.exe
public class ProcessManager
{
[DllImport("user32.dll")]
private static extern bool ShowWindow(IntPtr hWnd, uint windowStyle);
[DllImport("user32.dll")]
private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int x, int y, int cx, int cy, uint uFlags);
ProcessManager()
{
string processName = /* Your process name here */
SearchProcessAndModifyState(processName)
}
void SearchProcessAndModifyState(string targetProcessName)
{
Process specifiedProcess = null;
Process[] processes = Process.GetProcesses();
for (int i = 0; i < processes.Length; i++)
{
Process process = processes[i];
if (process.ProcessName == targetProcessName)
{
specifiedProcess = process;
break;
}
}
if (specifiedProcess != null)
{
ProcessManager.ShowWindow(specifiedProcess.MainWindowHandle, 1u);
ProcessManager.SetWindowPos(specifiedProcess.MainWindowHandle, new IntPtr(-1), 0, 0, 0, 0, 3u);
}
}
}
这篇关于如何使Windows总是在最上层的应用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!