diff --git a/SafeExamBrowser.Configuration/Bounds.cs b/SafeExamBrowser.Configuration/Bounds.cs
new file mode 100644
index 00000000..ce83b546
--- /dev/null
+++ b/SafeExamBrowser.Configuration/Bounds.cs
@@ -0,0 +1,20 @@
+/*
+ * 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 SafeExamBrowser.Contracts.WindowsApi;
+
+namespace SafeExamBrowser.Configuration
+{
+ internal class Bounds : IBounds
+ {
+ public int Left { get; set; }
+ public int Top { get; set; }
+ public int Right { get; set; }
+ public int Bottom { get; set; }
+ }
+}
diff --git a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj
index ef19d3db..86d1dbd6 100644
--- a/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj
+++ b/SafeExamBrowser.Configuration/SafeExamBrowser.Configuration.csproj
@@ -60,6 +60,7 @@
+
diff --git a/SafeExamBrowser.Configuration/WorkingArea.cs b/SafeExamBrowser.Configuration/WorkingArea.cs
index 804b1b03..00f8d00c 100644
--- a/SafeExamBrowser.Configuration/WorkingArea.cs
+++ b/SafeExamBrowser.Configuration/WorkingArea.cs
@@ -11,7 +11,6 @@ using SafeExamBrowser.Contracts.Configuration;
using SafeExamBrowser.Contracts.Logging;
using SafeExamBrowser.Contracts.UserInterface;
using SafeExamBrowser.Contracts.WindowsApi;
-using SafeExamBrowser.Contracts.WindowsApi.Types;
namespace SafeExamBrowser.Configuration
{
@@ -19,7 +18,7 @@ namespace SafeExamBrowser.Configuration
{
private ILogger logger;
private INativeMethods nativeMethods;
- private RECT? originalWorkingArea;
+ private IBounds originalWorkingArea;
public WorkingArea(ILogger logger, INativeMethods nativeMethods)
{
@@ -31,9 +30,9 @@ namespace SafeExamBrowser.Configuration
{
originalWorkingArea = nativeMethods.GetWorkingArea();
- LogWorkingArea("Saved original working area", originalWorkingArea.Value);
+ LogWorkingArea("Saved original working area", originalWorkingArea);
- var area = new RECT
+ var area = new Bounds
{
Left = 0,
Top = 0,
@@ -48,14 +47,14 @@ namespace SafeExamBrowser.Configuration
public void Reset()
{
- if (originalWorkingArea.HasValue)
+ if (originalWorkingArea != null)
{
- nativeMethods.SetWorkingArea(originalWorkingArea.Value);
- LogWorkingArea("Restored original working area", originalWorkingArea.Value);
+ nativeMethods.SetWorkingArea(originalWorkingArea);
+ LogWorkingArea("Restored original working area", originalWorkingArea);
}
}
- private void LogWorkingArea(string message, RECT area)
+ private void LogWorkingArea(string message, IBounds area)
{
logger.Info($"{message}: Left = {area.Left}, Top = {area.Top}, Right = {area.Right}, Bottom = {area.Bottom}.");
}
diff --git a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj
index 1d43922c..b0065bd9 100644
--- a/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj
+++ b/SafeExamBrowser.Contracts/SafeExamBrowser.Contracts.csproj
@@ -98,8 +98,8 @@
+
-
\ No newline at end of file
diff --git a/SafeExamBrowser.Contracts/WindowsApi/IBounds.cs b/SafeExamBrowser.Contracts/WindowsApi/IBounds.cs
new file mode 100644
index 00000000..6816f241
--- /dev/null
+++ b/SafeExamBrowser.Contracts/WindowsApi/IBounds.cs
@@ -0,0 +1,18 @@
+/*
+ * 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/.
+ */
+
+namespace SafeExamBrowser.Contracts.WindowsApi
+{
+ public interface IBounds
+ {
+ int Left { get; }
+ int Top { get; }
+ int Right { get; }
+ int Bottom { get; }
+ }
+}
diff --git a/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs b/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs
index a139d49b..8cd0145c 100644
--- a/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs
+++ b/SafeExamBrowser.Contracts/WindowsApi/INativeMethods.cs
@@ -9,7 +9,6 @@
using System;
using System.Collections.Generic;
using SafeExamBrowser.Contracts.Monitoring;
-using SafeExamBrowser.Contracts.WindowsApi.Types;
namespace SafeExamBrowser.Contracts.WindowsApi
{
@@ -52,7 +51,7 @@ namespace SafeExamBrowser.Contracts.WindowsApi
///
/// If the working area could not be retrieved.
///
- RECT GetWorkingArea();
+ IBounds GetWorkingArea();
///
/// Hides the given window. Returns true if successful, otherwise false.
@@ -105,7 +104,7 @@ namespace SafeExamBrowser.Contracts.WindowsApi
///
/// If the working area could not be set.
///
- void SetWorkingArea(RECT bounds);
+ void SetWorkingArea(IBounds bounds);
///
/// Unregisters the system hook for the given keyboard interceptor.
diff --git a/SafeExamBrowser.WindowsApi/Monitoring/KeyboardHook.cs b/SafeExamBrowser.WindowsApi/Monitoring/KeyboardHook.cs
index bc6a5312..ea18acdf 100644
--- a/SafeExamBrowser.WindowsApi/Monitoring/KeyboardHook.cs
+++ b/SafeExamBrowser.WindowsApi/Monitoring/KeyboardHook.cs
@@ -10,6 +10,7 @@ using System;
using System.Runtime.InteropServices;
using SafeExamBrowser.Contracts.Monitoring;
using SafeExamBrowser.WindowsApi.Constants;
+using SafeExamBrowser.WindowsApi.Types;
namespace SafeExamBrowser.WindowsApi.Monitoring
{
diff --git a/SafeExamBrowser.WindowsApi/NativeMethods.cs b/SafeExamBrowser.WindowsApi/NativeMethods.cs
index 4c942b3f..d6792052 100644
--- a/SafeExamBrowser.WindowsApi/NativeMethods.cs
+++ b/SafeExamBrowser.WindowsApi/NativeMethods.cs
@@ -15,9 +15,9 @@ using System.Runtime.InteropServices;
using System.Text;
using SafeExamBrowser.Contracts.Monitoring;
using SafeExamBrowser.Contracts.WindowsApi;
-using SafeExamBrowser.Contracts.WindowsApi.Types;
using SafeExamBrowser.WindowsApi.Constants;
using SafeExamBrowser.WindowsApi.Monitoring;
+using SafeExamBrowser.WindowsApi.Types;
namespace SafeExamBrowser.WindowsApi
{
@@ -99,7 +99,7 @@ namespace SafeExamBrowser.WindowsApi
return string.Empty;
}
- public RECT GetWorkingArea()
+ public IBounds GetWorkingArea()
{
var workingArea = new RECT();
var success = User32.SystemParametersInfo(SPI.GETWORKAREA, 0, ref workingArea, SPIF.NONE);
@@ -109,7 +109,7 @@ namespace SafeExamBrowser.WindowsApi
throw new Win32Exception(Marshal.GetLastWin32Error());
}
- return workingArea;
+ return workingArea.ToBounds();
}
public bool HideWindow(IntPtr window)
@@ -194,9 +194,10 @@ namespace SafeExamBrowser.WindowsApi
User32.SendMessage(window, Constant.WM_SYSCOMMAND, (IntPtr) SystemCommand.CLOSE, IntPtr.Zero);
}
- public void SetWorkingArea(RECT bounds)
+ public void SetWorkingArea(IBounds bounds)
{
- var success = User32.SystemParametersInfo(SPI.SETWORKAREA, 0, ref bounds, SPIF.UPDATEANDCHANGE);
+ var workingArea = new RECT { Left = bounds.Left, Top = bounds.Top, Right = bounds.Right, Bottom = bounds.Bottom };
+ var success = User32.SystemParametersInfo(SPI.SETWORKAREA, 0, ref workingArea, SPIF.UPDATEANDCHANGE);
if (!success)
{
diff --git a/SafeExamBrowser.WindowsApi/SafeExamBrowser.WindowsApi.csproj b/SafeExamBrowser.WindowsApi/SafeExamBrowser.WindowsApi.csproj
index 05670949..f7476236 100644
--- a/SafeExamBrowser.WindowsApi/SafeExamBrowser.WindowsApi.csproj
+++ b/SafeExamBrowser.WindowsApi/SafeExamBrowser.WindowsApi.csproj
@@ -60,8 +60,9 @@
-
-
+
+
+
@@ -70,6 +71,7 @@
+
diff --git a/SafeExamBrowser.WindowsApi/Types/Bounds.cs b/SafeExamBrowser.WindowsApi/Types/Bounds.cs
new file mode 100644
index 00000000..b9d3b44a
--- /dev/null
+++ b/SafeExamBrowser.WindowsApi/Types/Bounds.cs
@@ -0,0 +1,20 @@
+/*
+ * 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 SafeExamBrowser.Contracts.WindowsApi;
+
+namespace SafeExamBrowser.WindowsApi.Types
+{
+ internal class Bounds : IBounds
+ {
+ public int Left { get; set; }
+ public int Top { get; set; }
+ public int Right { get; set; }
+ public int Bottom { get; set; }
+ }
+}
diff --git a/SafeExamBrowser.WindowsApi/Constants/KBDLLHOOKSTRUCT.cs b/SafeExamBrowser.WindowsApi/Types/KBDLLHOOKSTRUCT.cs
similarity index 97%
rename from SafeExamBrowser.WindowsApi/Constants/KBDLLHOOKSTRUCT.cs
rename to SafeExamBrowser.WindowsApi/Types/KBDLLHOOKSTRUCT.cs
index 4568b295..06fb3cc2 100644
--- a/SafeExamBrowser.WindowsApi/Constants/KBDLLHOOKSTRUCT.cs
+++ b/SafeExamBrowser.WindowsApi/Types/KBDLLHOOKSTRUCT.cs
@@ -9,7 +9,7 @@
using System;
using System.Runtime.InteropServices;
-namespace SafeExamBrowser.WindowsApi.Constants
+namespace SafeExamBrowser.WindowsApi.Types
{
///
/// See http://www.pinvoke.net/default.aspx/Structures/KBDLLHOOKSTRUCT.html.
diff --git a/SafeExamBrowser.WindowsApi/Constants/KBDLLHOOKSTRUCTFlags.cs b/SafeExamBrowser.WindowsApi/Types/KBDLLHOOKSTRUCTFlags.cs
similarity index 94%
rename from SafeExamBrowser.WindowsApi/Constants/KBDLLHOOKSTRUCTFlags.cs
rename to SafeExamBrowser.WindowsApi/Types/KBDLLHOOKSTRUCTFlags.cs
index a4e07b0b..0e38ac8f 100644
--- a/SafeExamBrowser.WindowsApi/Constants/KBDLLHOOKSTRUCTFlags.cs
+++ b/SafeExamBrowser.WindowsApi/Types/KBDLLHOOKSTRUCTFlags.cs
@@ -6,7 +6,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
-namespace SafeExamBrowser.WindowsApi.Constants
+namespace SafeExamBrowser.WindowsApi.Types
{
///
/// See http://www.pinvoke.net/default.aspx/Structures/KBDLLHOOKSTRUCT.html.
diff --git a/SafeExamBrowser.Contracts/WindowsApi/Types/RECT.cs b/SafeExamBrowser.WindowsApi/Types/RECT.cs
similarity index 60%
rename from SafeExamBrowser.Contracts/WindowsApi/Types/RECT.cs
rename to SafeExamBrowser.WindowsApi/Types/RECT.cs
index 7b883657..c520e253 100644
--- a/SafeExamBrowser.Contracts/WindowsApi/Types/RECT.cs
+++ b/SafeExamBrowser.WindowsApi/Types/RECT.cs
@@ -7,18 +7,30 @@
*/
using System.Runtime.InteropServices;
+using SafeExamBrowser.Contracts.WindowsApi;
-namespace SafeExamBrowser.Contracts.WindowsApi.Types
+namespace SafeExamBrowser.WindowsApi.Types
{
///
/// See https://msdn.microsoft.com/en-us/library/windows/desktop/dd162897(v=vs.85).aspx.
///
[StructLayout(LayoutKind.Sequential)]
- public struct RECT
+ internal struct RECT
{
- public int Left;
- public int Top;
- public int Right;
- public int Bottom;
+ internal int Left;
+ internal int Top;
+ internal int Right;
+ internal int Bottom;
+
+ internal IBounds ToBounds()
+ {
+ return new Bounds
+ {
+ Left = Left,
+ Top = Top,
+ Right = Right,
+ Bottom = Bottom
+ };
+ }
}
}
diff --git a/SafeExamBrowser.WindowsApi/User32.cs b/SafeExamBrowser.WindowsApi/User32.cs
index 4a37ed18..0d6f5ed2 100644
--- a/SafeExamBrowser.WindowsApi/User32.cs
+++ b/SafeExamBrowser.WindowsApi/User32.cs
@@ -9,8 +9,8 @@
using System;
using System.Runtime.InteropServices;
using System.Text;
-using SafeExamBrowser.Contracts.WindowsApi.Types;
using SafeExamBrowser.WindowsApi.Constants;
+using SafeExamBrowser.WindowsApi.Types;
namespace SafeExamBrowser.WindowsApi
{