需要知道當前打開的應用程序:所有應用程序在任務管理器中。屏幕截圖需要當前使用'已啓動的應用程序
這是爲了屏幕截圖,所以如果可能的話,我需要一些訪問這些應用程序在屏幕上的位置。
使用.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