seb-win-refactoring/SafeExamBrowser.Monitoring/Windows/WindowMonitor.cs

78 lines
1.8 KiB
C#
Raw Normal View History

2017-07-24 08:56:39 +02:00
/*
* Copyright (c) 2017 ETH Zürich, Educational Development and Technology (LET)
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
using System;
2017-07-24 15:29:17 +02:00
using System.Collections.Generic;
2017-07-24 08:56:39 +02:00
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.Monitoring;
using SafeExamBrowser.WindowsApi;
namespace SafeExamBrowser.Monitoring.Windows
{
public class WindowMonitor : IWindowMonitor
{
private ILogger logger;
2017-07-24 15:29:17 +02:00
private IList<Window> minimizedWindows = new List<Window>();
2017-07-24 08:56:39 +02:00
public WindowMonitor(ILogger logger)
{
this.logger = logger;
}
public void HideAllWindows()
{
2017-07-24 15:29:17 +02:00
logger.Info("Saving windows to be minimized...");
foreach (var handle in User32.GetOpenWindows())
{
var window = new Window
{
Handle = handle,
Title = User32.GetWindowTitle(handle)
};
minimizedWindows.Add(window);
logger.Info($"Saved window '{window.Title}' with handle = {window.Handle}.");
}
2017-07-24 08:56:39 +02:00
logger.Info("Minimizing all open windows...");
User32.MinimizeAllOpenWindows();
logger.Info("Open windows successfully minimized.");
}
public void RestoreHiddenWindows()
{
2017-07-24 15:29:17 +02:00
logger.Info("Restoring all minimized windows...");
foreach (var window in minimizedWindows)
{
User32.RestoreWindow(window.Handle);
logger.Info($"Restored window '{window.Title}' with handle = {window.Handle}.");
}
logger.Info("Minimized windows successfully restored.");
2017-07-24 08:56:39 +02:00
}
public void StartMonitoringWindows()
{
2017-07-24 15:29:17 +02:00
// TODO
2017-07-24 08:56:39 +02:00
}
public void StopMonitoringWindows()
{
2017-07-24 15:29:17 +02:00
// TODO
}
private struct Window
{
internal IntPtr Handle { get; set; }
internal string Title { get; set; }
2017-07-24 08:56:39 +02:00
}
}
}