1

現在開いているアプリケーションを知る必要があります: すべてのアプリケーションはタスク マネージャーにあります。

これは画面キャプチャ用であるため、可能であれば、画面上のこれらのアプリケーションの場所へのアクセスが必要です。

.net c# 式エンコーダーの使用

4

2 に答える 2

1

タスクバーに表示されるウィンドウの公式ドキュメントがあります。

とにかく、このようなものは一般的な考え方を理解する必要があります。どこを見ればよいかがわかったので、自分で詳細を整理できます。

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;
    }
}
于 2011-03-07T23:40:11.990 に答える
0

マネージド System.Diagnostic.Processes クラスを使用できます。

Process[] running = Process.GetProcesses();

foreach(Process p in running)
  Console.WriteLine(p.ProcessName);
于 2011-03-07T22:16:25.573 に答える