2

Currently I'm making a small gadget that made in WPF. It shows and hides according to another window's state.

So, let me name that another window be A. When A get shown or maximized, my gadget shows. When A minimized, my gadget hides.

So, how can I detect the change in state of a window of another process which is not in .NET? Btw sorry for my bad English :P

2 Answers2

7

It's only a part of the solution. If you know the title of the other window:

Process process = Process.GetProcesses().Where(p => p.MainWindowTitle == "Title of window").SingleOrDefault();
if (process != null) {
      IntPtr wHnd = process.MainWindowHandle;
      Console.WriteLine("Minimized: "  + IsIconic(wHnd));
}

and:

    [DllImport("user32.dll")]
    [return: MarshalAs(UnmanagedType.Bool)]
    static extern bool IsIconic(IntPtr hWnd);
romanoza
  • 4,775
  • 3
  • 27
  • 44
0

You'll want to get the HWND from the process you want to reach.

How to get main window handle from process id?

It requires loading win32 libraries in your C# WPF app like below.

How can I use EnumWindows to find windows with a specific caption/title?

Once you have the HWND, you can check the visibility of the app by a combination of the WS_VISIBLE and WS_MAXIMIZE properties.

How can I check if a window has WS_VISIBLE to set? (or if is visible)

Community
  • 1
  • 1
dBlisse
  • 801
  • 5
  • 13