From ae8c007528809a703020dc2a068bb359b96f2894 Mon Sep 17 00:00:00 2001 From: RKrom Date: Thu, 8 Nov 2012 07:00:29 +0000 Subject: [PATCH] Added some very basic support for Metro (Modern UI) Apps, the ones running can be captured over the "Capture window from list" and the one visible will be selectable with the interactive capture. (PrintScreen and space). What doesn't work is using printscreen on the Metro Tiles screen, here the space will only work like the desktop is visible. git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2247 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4 --- Greenshot/Helpers/CaptureHelper.cs | 10 +++++--- GreenshotPlugin/Core/WindowsHelper.cs | 37 ++++++++++++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Greenshot/Helpers/CaptureHelper.cs b/Greenshot/Helpers/CaptureHelper.cs index 2958a9f43..a3c12e21a 100644 --- a/Greenshot/Helpers/CaptureHelper.cs +++ b/Greenshot/Helpers/CaptureHelper.cs @@ -412,7 +412,9 @@ namespace Greenshot.Helpers { Thread getWindowDetailsThread = new Thread (delegate() { // Start Enumeration of "active" windows - foreach (WindowDetails window in WindowDetails.GetAllWindows()) { + List allWindows = WindowDetails.GetMetroApps(); + allWindows.AddRange(WindowDetails.GetAllWindows()); + foreach (WindowDetails window in allWindows) { // Window should be visible and not ourselves if (!window.Visible) { continue; @@ -456,9 +458,9 @@ namespace Greenshot.Helpers { // AddCaptureElementsForWindow(windowCaptureElement, window, goLevelDeep); //} } - lock (windows) { - windows = WindowDetails.SortByZOrder(IntPtr.Zero, windows); - } +// lock (windows) { +// windows = WindowDetails.SortByZOrder(IntPtr.Zero, windows); +// } }); getWindowDetailsThread.Name = "Retrieve window details"; getWindowDetailsThread.IsBackground = true; diff --git a/GreenshotPlugin/Core/WindowsHelper.cs b/GreenshotPlugin/Core/WindowsHelper.cs index bacf49bd9..6e66afe2e 100644 --- a/GreenshotPlugin/Core/WindowsHelper.cs +++ b/GreenshotPlugin/Core/WindowsHelper.cs @@ -181,6 +181,11 @@ namespace GreenshotPlugin.Core { private WindowDetails parent = null; private bool frozen = false; + public bool isMetroApp { + get; + set; + } + /// /// The window handle. /// @@ -246,6 +251,10 @@ namespace GreenshotPlugin.Core { /// public Image DisplayIcon { get { + if (isMetroApp) { + // No method yet to get the metro icon + return null; + } try { string filename = ProcessPath; if (!iconCache.ContainsKey(filename)) { @@ -1320,7 +1329,8 @@ namespace GreenshotPlugin.Core { public static List GetVisibleWindows() { List windows = new List(); Rectangle screenBounds = WindowCapture.GetScreenBounds(); - List allWindows = WindowDetails.GetAllWindows(); + List allWindows = GetMetroApps(); + allWindows.AddRange(WindowDetails.GetAllWindows()); foreach(WindowDetails window in allWindows) { // Ignore windows without title if (window.Text.Length == 0) { @@ -1346,15 +1356,34 @@ namespace GreenshotPlugin.Core { return windows; } + /// + /// Get the WindowDetails for all Metro Apps + /// These are all Windows with Classname "Windows.UI.Core.CoreWindow" + /// + /// List with visible metro apps + public static List GetMetroApps() { + List metroApps = new List(); + IntPtr nextHandle = User32.FindWindow("Windows.UI.Core.CoreWindow", null); + while (nextHandle != IntPtr.Zero) { + WindowDetails metroApp = new WindowDetails(nextHandle); + metroApp.isMetroApp = true; + metroApps.Add(metroApp); + LOG.DebugFormat("Found metro app {0}", metroApp.Text); + nextHandle = User32.FindWindowEx( IntPtr.Zero, nextHandle, "Windows.UI.Core.CoreWindow", null); + }; + + return metroApps; + } + /// /// Get all the top level windows /// /// List with all the top level windows public static List GetTopLevelWindows() { List windows = new List(); - Rectangle screenBounds = WindowCapture.GetScreenBounds(); - List allWindows = WindowDetails.GetAllWindows(); - foreach (WindowDetails window in allWindows) { + var possibleTopLevelWindows = GetMetroApps(); + possibleTopLevelWindows.AddRange(WindowDetails.GetAllWindows()); + foreach (WindowDetails window in possibleTopLevelWindows) { // Ignore windows without title if (window.Text.Length == 0) { continue;