C #: capturing window changes of another application (writes in c / C ++, I think)

I have a situation where I need to capture window changes of another window (which does not belong to my application, and I did not write it). I think it is written in C ++).

Actually I use a separate thread where I constantly do GetWindowState and fire custom events when this value changes (I have a window handle), but I would like to know if there is a better method

Thank,

PS I use winform if it can be useful anyway

0
source share
2 answers
//use this in a timer or hook the window
//this would be the easier way
using System;
using System.Runtime.InteropServices;

public static class WindowState
{
    [DllImport("user32")]
    private static extern int IsWindowEnabled(int hWnd);

    [DllImport("user32")]
    private static extern int IsWindowVisible(int hWnd);

    [DllImport("user32")]
    private static extern int IsZoomed(int hWnd);

    [DllImport("user32")]
    private static extern int IsIconic(int hWnd);

    public static bool IsMaximized(int hWnd) 
    {
        if (IsZoomed(hWnd) == 0)
            return false;
        else
            return true;
    }

    public static bool IsMinimized(int hWnd)
    {
        if (IsIconic(hWnd) == 0)
            return false;
        else
            return true;
    }

    public static bool IsEnabled(int hWnd)
    {
        if (IsWindowEnabled(hWnd) == 0)
            return false;
        else
            return true;
    }

    public static bool IsVisible(int hWnd)
    {
        if (IsWindowVisible(hWnd) == 0)
            return false;
        else
            return true;
    }

}
+2
source

WNDPROC . DLL , WH_CALLWNDPROC.

+1

Source: https://habr.com/ru/post/1746150/


All Articles