Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get location and size of all open windows using .NET (C#)

Tags:

.net

windows

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.

like image 238
Dan Harris Avatar asked Aug 04 '10 15:08

Dan Harris


2 Answers

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)

like image 200
Hans Olsson Avatar answered Oct 02 '22 12:10

Hans Olsson


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

like image 21
Tergiver Avatar answered Oct 02 '22 14:10

Tergiver