private static void CaptureActiveWindow(Action <Bitmap> action) { var handle = WinApi.GetForegroundWindow(); if (IntPtr.Zero == handle) // The foreground window can be NULL in certain circumstances, such as when a window is losing activation { return; } using (var bitmap = GetWindowBitmap(handle)) { action.Invoke(bitmap); } }
private static void Capture(ScreenCaptureSource screenCaptureSource, Action <Bitmap> action) { switch (screenCaptureSource) { case ScreenCaptureSource.ActiveWindow: CaptureActiveWindow(action); break; case ScreenCaptureSource.ActiveScreen: CaptureScreen(Screen.FromHandle(WinApi.GetForegroundWindow()), action); break; case ScreenCaptureSource.PrimaryScreen: CaptureScreen(Screen.PrimaryScreen, action); break; case ScreenCaptureSource.AllScreens: CaptureAllScreens(action); break; default: throw new NotImplementedException(); } }