需要知道当前打开的应用程序:所有应用程序在任务管理器中。屏幕截图需要当前使用'已启动的应用程序
这是为了屏幕截图,所以如果可能的话,我需要一些访问这些应用程序在屏幕上的位置。
使用.NET C#Expression Encoder的
需要知道当前打开的应用程序:所有应用程序在任务管理器中。屏幕截图需要当前使用'已启动的应用程序
这是为了屏幕截图,所以如果可能的话,我需要一些访问这些应用程序在屏幕上的位置。
使用.NET C#Expression Encoder的
有official documentation其中的窗口出现在任务栏中。
无论如何,像这样的东西应该通过一般的想法。您现在可以自行排列详细信息,以了解您的目标。
using System;
using System.Runtime.InteropServices;
using System.Text;
public delegate bool CallBack(IntPtr hWnd, IntPtr lParam);
public class EnumTopLevelWindows {
[DllImport("user32", SetLastError=true)]
private static extern int EnumWindows(CallBack x, IntPtr y);
[DllImport("user32.dll", SetLastError = true)]
static extern IntPtr GetParent(IntPtr hWnd);
[DllImport("user32.dll", EntryPoint = "GetWindowLong", SetLastError = true)]
private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);
[DllImport("user32.dll", SetLastError = true)]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool IsWindowVisible(IntPtr hWnd);
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
static extern int GetWindowTextLength(IntPtr hWnd);
[DllImport("user32.dll", CharSet = CharSet.Auto, SetLastError = true)]
static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);
public static string GetText(IntPtr hWnd)
{
// Allocate correct string length first
int length = GetWindowTextLength(hWnd);
StringBuilder sb = new StringBuilder(length + 1);
GetWindowText(hWnd, sb, sb.Capacity);
return sb.ToString();
}
private const int GWL_STYLE = -16;
private const int WS_EX_APPWINDOW = 0x00040000;
public static void Main()
{
CallBack myCallBack = new CallBack(EnumTopLevelWindows.Report);
EnumWindows(myCallBack, IntPtr.Zero);
}
public static bool Report(IntPtr hWnd, IntPtr lParam)
{
if (GetParent(hWnd) == IntPtr.Zero)
{
//window is a non-owned top level window
if (IsWindowVisible(hWnd))
{
//window is visible
int style = GetWindowLongPtr(hWnd, GWL_STYLE).ToInt32();
if ((style & WS_EX_APPWINDOW) == WS_EX_APPWINDOW)
{
//window has WS_EX_APPWINDOW style
Console.WriteLine(GetText(hWnd));
}
}
}
return true;
}
}
您可以使用管理System.Diagnostic.Processes类:
Process[] running = Process.GetProcesses();
foreach(Process p in running)
Console.WriteLine(p.ProcessName);
是的,我知道,它是运行的进程而不是应用程序的问题。最好的例子是打开任务管理器,查看应用程序和进程选项卡的区别。我只需要应用程序。 – 2011-03-07 22:44:27
然后你可以使用EnumWindows API – 2011-03-08 08:55:40
很酷,我得看看你的代码有点......正在研究enumtoplevelwindows ....那么今天希望我会在所有事情发生之后再发布更新。 我实际上正在努力让班级与所有凌乱的WMI一起工作。 它在我眼中只是没有美丽。 :D谢谢,当我看透这个时,我会给你一个提醒。 – 2011-03-08 05:28:39
谢谢,你的代码让我提前了解了这一点,但更多的是一个问题。 if(GetWindow(hWnd,GW_OWNER)== IntPtr.Zero)做什么?有点难以理解它 – 2011-03-08 17:58:50
嗯,是IntPtr.Zero代表桌面/所有者,该声明意味着如果当前的应用程序所有者是桌面,然后继续? – 2011-03-08 18:06:06