Horje
c# getforegroundwindow Code Example
c# getforegroundwindow
    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();
c# get foreground window
    #region Retrieve list of windows

    [DllImport("user32")]
    private static extern int GetWindowLongA(IntPtr hWnd, int index);

    [DllImport("USER32.DLL")]
    private static extern int GetWindowText(IntPtr hWnd, StringBuilder lpString, int nMaxCount);

    [DllImport("USER32.DLL")]
    private static extern bool EnumWindows(EnumWindowsProc enumFunc, int lParam);

    [DllImport("user32.dll")]
    private static extern IntPtr GetForegroundWindow();

    private const int GWL_STYLE = -16;

    private const ulong WS_VISIBLE = 0x10000000L;
    private const ulong WS_BORDER = 0x00800000L;
    private const ulong TARGETWINDOW = WS_BORDER | WS_VISIBLE;

    internal class Window
    {
        public string Title;
        public IntPtr Handle;

        public override string ToString()
        {
            return Title;
        }
    }

    private List<Window> windows;

    private void GetWindows()
    {
        windows = new List<Window>();
        EnumWindows(Callback, 0);
    }

    private bool Callback(IntPtr hwnd, int lParam)
    {
        if (this.Handle != hwnd && (GetWindowLongA(hwnd, GWL_STYLE) & TARGETWINDOW) == TARGETWINDOW)
        {
            StringBuilder sb = new StringBuilder(100);
            GetWindowText(hwnd, sb, sb.Capacity);

            Window t = new Window();
            t.Handle = hwnd;
            t.Title = sb.ToString();
            windows.Add(t);
        }

        return true; //continue enumeration
    }

    #endregion




Csharp

Related
tinyint in c# Code Example tinyint in c# Code Example
unity print Code Example unity print Code Example
how to create empty ui object unity Code Example how to create empty ui object unity Code Example
unity dontdestroyonload Code Example unity dontdestroyonload Code Example
http error 502.5 asp.net core 2.2 Code Example http error 502.5 asp.net core 2.2 Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
9