Added GetForegroundWindowProcessName to NativeMethods

This commit is contained in:
Jaex 2017-03-01 11:42:40 +03:00
parent d7dba60a14
commit 3171d43333
3 changed files with 23 additions and 26 deletions

View file

@ -74,6 +74,19 @@ public static Process GetForegroundWindowProcess()
return GetProcessByWindowHandle(handle);
}
public static string GetForegroundWindowProcessName()
{
using (Process process = GetForegroundWindowProcess())
{
if (process != null)
{
return process.ProcessName;
}
}
return null;
}
public static Process GetProcessByWindowHandle(IntPtr hwnd)
{
if (hwnd.ToInt32() > 0)

View file

@ -33,33 +33,20 @@ public class CaptureActiveWindow : CaptureBase
{
protected override ImageInfo Execute(TaskSettings taskSettings)
{
Image img;
string activeWindowTitle = NativeMethods.GetForegroundWindowText();
string activeProcessName = null;
using (Process process = NativeMethods.GetForegroundWindowProcess())
{
if (process != null)
{
activeProcessName = process.ProcessName;
}
}
ImageInfo imageInfo = new ImageInfo();
imageInfo.WindowTitle = NativeMethods.GetForegroundWindowText();
imageInfo.ProcessName = NativeMethods.GetForegroundWindowProcessName();
if (taskSettings.CaptureSettings.CaptureTransparent && !taskSettings.CaptureSettings.CaptureClientArea)
{
img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindowTransparent();
imageInfo.Image = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindowTransparent();
}
else
{
img = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindow();
imageInfo.Image = TaskHelpers.GetScreenshot(taskSettings).CaptureActiveWindow();
}
return new ImageInfo()
{
Image = img,
WindowTitle = activeWindowTitle,
ProcessName = activeProcessName
};
return imageInfo;
}
}
}

View file

@ -46,15 +46,12 @@ public void Capture(TaskSettings taskSettings = null, bool autoHideForm = false)
if (taskSettings.CaptureSettings.IsDelayScreenshot && taskSettings.CaptureSettings.DelayScreenshot > 0)
{
TaskEx.Run(() =>
{
int sleep = (int)(taskSettings.CaptureSettings.DelayScreenshot * 1000);
Thread.Sleep(sleep);
},
() =>
int delay = (int)(taskSettings.CaptureSettings.DelayScreenshot * 1000);
TaskEx.RunDelayed(() =>
{
CaptureInternal(taskSettings, autoHideForm);
});
}, delay);
}
else
{