protected void SetWindowGeometry(Window w, int x, int y, int width, int height) { w.SetGeometry (WindowGravity.Northwest, WindowMoveResizeMask.Width, x, y, width, height); w.SetGeometry (WindowGravity.Northwest, WindowMoveResizeMask.Height, x, y, width, height); w.SetGeometry (WindowGravity.Northwest, WindowMoveResizeMask.X, x, y, width, height); w.SetGeometry (WindowGravity.Northwest, WindowMoveResizeMask.Y, x, y, width, height); }
//Callback for winAPI. enumerates through all the current windows private bool EnumWindows( int hWnd, int lParam ) { User32.tagWINDOWINFO info = new User32.tagWINDOWINFO(); User32.GetWindowInfo(hWnd, out info); if (hWnd != 0 && ((info.dwStyle & User32.WS_VISIBLE) != 0)/*&& ((info.dwStyle & User32.WS_GROUP) != 0)*/) //Window is valid, visible, and { //The next three lines are all just getting the window title of the handle int capacity = User32.GetWindowTextLength(new HandleRef(null, (IntPtr)hWnd)) * 2; StringBuilder stringBuilder = new StringBuilder(capacity); User32.GetWindowText(new HandleRef(null, (IntPtr)hWnd), stringBuilder, stringBuilder.Capacity); //Program manager/Start aren't technically windows, and we don't want anything to do with them. //Start is the desktop, and Program Manager is something that manages programs. (Who knew!) if (stringBuilder.Length > 0 && stringBuilder.ToString() != "Program Manager" && stringBuilder.ToString() != "Start") { //Get the process ID int id = 0; User32.GetWindowThreadProcessId((IntPtr)hWnd, out id); //We're going to use the process so we can get some useful info out of it System.Diagnostics.Process p = System.Diagnostics.Process.GetProcessById(id); //Create a new window class (A class that just holds some important info about the current windows) Window win = new Window(); win.Title = stringBuilder.ToString(); win.Handle = hWnd; //win.Icon = User32.GetSmallIcon(p.MainModule.FileName); //I wanted to get the little 16x16 icon like the task manager, but it seemed like a huge task windows.Add(win); //Add it to our list of windows //Replacing the little icon I have a little sign of whether the window is responding or not. //Doesn't look half bad if I say so myself int index = 1; if (p.Responding) index = 0; //Finally, add the window to the listview listWindows.Items.Add(win.Title); listWindows.Items[listWindows.Items.Count -1].ImageIndex = index; } } //We must return true so we keep enumerating to the next window return true; }