public static bool GetBool(NativeMethods.SPI parameter) { var value = IntPtr.Zero; if (!NativeMethods.SystemParametersInfo(parameter, 0, ref value, SystemParametersInfoBehaviors.None)) { throw User32Api.CreateWin32Exception(nameof(User32Api.SystemParametersInfo)); } return(value != IntPtr.Zero); }
public static void SetBool(NativeMethods.SPI parameter, bool value) { // TODO: Log changed system settings var _ = IntPtr.Zero; if (!NativeMethods.SystemParametersInfo(parameter, (uint)(value ? 1 : 0), ref _, SystemParametersInfoBehaviors.None)) { throw User32Api.CreateWin32Exception(nameof(User32Api.SystemParametersInfo)); } }
/// <summary> /// Helper method to create an exception that might explain what is wrong while capturing /// </summary> /// <param name="method">string with current method</param> /// <param name="captureBounds">NativeRect of what we want to capture</param> /// <returns></returns> private static Exception CreateCaptureException(string method, NativeRect captureBounds) { var exceptionToThrow = User32Api.CreateWin32Exception(method); if (!captureBounds.IsEmpty) { exceptionToThrow.Data.Add("Height", captureBounds.Height); exceptionToThrow.Data.Add("Width", captureBounds.Width); } return(exceptionToThrow); }
/// <summary> /// Default constructor, this opens the input destop with GENERIC_ALL /// This is needed to support marshalling!! /// </summary> public SafeCurrentInputDesktopHandle() : base(true) { var hDesktop = User32Api.OpenInputDesktop(0, true, DesktopAccessRight.GENERIC_ALL); if (hDesktop != IntPtr.Zero) { // Got desktop, store it as handle for the ReleaseHandle SetHandle(hDesktop); if (User32Api.SetThreadDesktop(hDesktop)) { Log.Debug().WriteLine("Switched to desktop {0}", hDesktop); } else { Log.Warn().WriteLine("Couldn't switch to desktop {0}", hDesktop); Log.Error().WriteLine(User32Api.CreateWin32Exception("SetThreadDesktop")); } } else { Log.Warn().WriteLine("Couldn't get current desktop."); Log.Error().WriteLine(User32Api.CreateWin32Exception("OpenInputDesktop")); } }