tags:

views:

39

answers:

3

Is there a way to detect and store the location and size of all open windows, as well as their state (Minimized, Maximized etc)

I've never developed anything that gets information from the actual operating system in this way. Does it require a call to a Windows API and involve unmanaged code?

If this is not clear please comment and I will try to elaborate.

+3  A: 

Call EnumWindows to loop through all the windows, then call GetWindowPlacement to get out the information. It will require PInvoke to Windows API, but it's not that difficult, just can find all the information at the PInvoke site.

Btw, here's a codeproject article for finding a specific window and getting/setting the show state of it, might be a good starting point (the code is in VB.Net, but you could probably just use one of the online VB.Net to C# converters if you don't know VB.Net)

ho1
Thanks, I use VB.NET sometimes when working on older apps in work from before they went fully C#
Dan Harris
+1  A: 

Yes, you will begin with EnumWindows: http://msdn.microsoft.com/en-us/library/ms633497.aspx

See the Window Functions list for methods to gain access to the information you want: http://msdn.microsoft.com/en-us/library/ff468919.aspx

Tergiver
+1  A: 

System.Diagnostics.Process class gets you much of the information you need. You can try that.

        Process[] currentProcesses = Process.GetProcesses();           
        Console.WriteLine("MainWindowTitle: {0}",currentProcesses[0].MainWindowTitle);
        Console.WriteLine(currentProcesses[0].StartInfo.WindowStyle);

I am not sure if it provides all that you need. But Process class is capable of providing so much information about currently running processes. It's good to give a look at Process class before moving to APIs.

SaravananArumugam
Thanks i'm not sure this does everything I need but will investigate this before going down the API route.
Dan Harris