C# 屏幕截图当前需要使用';r启动了应用程序
需要知道当前打开的应用程序:任务管理器中的所有应用程序 这是用于屏幕捕获的,所以如果可能的话,我需要访问屏幕上这些应用程序的位置C# 屏幕截图当前需要使用';r启动了应用程序,c#,screen-capture,windows-applications,C#,Screen Capture,Windows Applications,需要知道当前打开的应用程序:任务管理器中的所有应用程序 这是用于屏幕捕获的,所以如果可能的话,我需要访问屏幕上这些应用程序的位置 使用.net c#表达式编码器可以使用托管System.Diagnostic.Processs类: Process[] running = Process.GetProcesses(); foreach(Process p in running) Console.WriteLine(p.ProcessName); 您可以使用托管System.Diagnosti
使用.net c#表达式编码器可以使用托管System.Diagnostic.Processs类:
Process[] running = Process.GetProcesses();
foreach(Process p in running)
Console.WriteLine(p.ProcessName);
您可以使用托管System.Diagnostic.Process类:
Process[] running = Process.GetProcesses();
foreach(Process p in running)
Console.WriteLine(p.ProcessName);
任务栏中显示的窗口有个
不管怎么说,像这样的事情应该能让人明白一般的想法。既然你知道该去哪里看,你就可以自己把细节整理出来了
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;
}
}
任务栏中显示的窗口有个
不管怎么说,像这样的事情应该能让人明白一般的想法。既然你知道该去哪里看,你就可以自己把细节整理出来了
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;
}
}
是的,我知道,问题是进程在运行,而不是应用程序。最好的例子是打开任务管理器,在应用程序和流程的选项卡中查看差异。我只需要应用程序。然后你可以使用EnumWindows。是的,我知道,问题是进程在运行,而不是应用程序。最好的例子是打开任务管理器,在应用程序和流程的选项卡中查看差异。我只需要应用程序的。然后你可以使用EnumWindows APICool,我将不得不研究一下你的代码。。。正在处理enumtoplevelwindows。。。。好的,今天我希望我能把一切都做好,稍后我会发布更新。。我实际上是在制作一个类来处理所有杂乱无章的WMI。在我眼里它就是没有美D好的,谢谢,当我看这篇文章的时候,我会给你一个提示。谢谢,你的代码让我进步了,并且理解了很多,但只有一个问题。如果(GetWindow(hWnd,GW_OWNER)==IntPtr.Zero)执行什么操作?理解itHmm有点困难,是不是IntPtr.Zero代表桌面/所有者,该语句表示如果当前应用程序所有者是桌面,则继续?注释对此进行了解释。它测试窗口是否为非所有者。@Reza如果此代码对您有帮助,您应该投票并接受它作为答案。很好,我将不得不查看一下您的代码。。。正在处理enumtoplevelwindows。。。。好的,今天我希望我能把一切都做好,稍后我会发布更新。。我实际上是在制作一个类来处理所有杂乱无章的WMI。在我眼里它就是没有美D好的,谢谢,当我看这篇文章的时候,我会给你一个提示。谢谢,你的代码让我进步了,并且理解了很多,但只有一个问题。如果(GetWindow(hWnd,GW_OWNER)==IntPtr.Zero)执行什么操作?理解itHmm有点困难,是不是IntPtr.Zero代表桌面/所有者,该语句表示如果当前应用程序所有者是桌面,则继续?注释对此进行了解释。它测试窗口是否为非所有者。@Reza如果此代码对您有帮助,您应该投票并接受它作为答案。