Захват экрана Нужно в данный момент использовать запущенное приложение - PullRequest
1 голос
/ 08 марта 2011

Необходимо знать, какие приложения открыты в данный момент: все приложения в диспетчере задач.

Это для захвата экрана, поэтому мне нужен некоторый доступ к расположению этих приложений на экране, если это возможно.*

Использование .net c # Expression encoder

Ответы [ 2 ]

1 голос
/ 08 марта 2011

Существует официальная документация о том, какие окна появляются на панели задач.

В любом случае, что-то подобное должно распространиться на общую идею.Вы можете сами разобраться в деталях, теперь вы знаете, где искать.

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;
    }
}
0 голосов
/ 08 марта 2011

вы можете использовать управляемый класс System.Diagnostic.Processes:

Process[] running = Process.GetProcesses();

foreach(Process p in running)
  Console.WriteLine(p.ProcessName);
...