private void SetStickKeysFlags(StickyKeys.Flags flags) { uint stickyKeysSize = (uint)Marshal.SizeOf(typeof(Win32Struct)); Win32Struct stickyKeys = new Win32Struct { cbSize = stickyKeysSize, dwFlags = flags }; bool result = SystemParametersInfo(uiActions.SPI_SETSTICKYKEYS, stickyKeysSize, ref stickyKeys, 0); if (!result) { throw new System.ComponentModel.Win32Exception(); } }
private Win32Struct GetSystemParameters() { Win32Struct win32Struct = new Win32Struct(); win32Struct.cbSize = Marshal.SizeOf(win32Struct);; bool result = SystemParametersInfo(uiActions.SPI_GETHIGHCONTRAST, win32Struct.cbSize, ref win32Struct, 0); if (!result) { throw new System.ComponentModel.Win32Exception(); } return(win32Struct); }
private Win32Struct GetStickyKeysFromSPI() { uint stickyKeysSize = (uint)Marshal.SizeOf(typeof(Win32Struct)); Win32Struct stickyKeys = new Win32Struct { cbSize = stickyKeysSize, dwFlags = 0 }; bool result = SystemParametersInfo(uiActions.SPI_GETSTICKYKEYS, stickyKeysSize, ref stickyKeys, 0); if (!result) { throw new System.ComponentModel.Win32Exception(); } return(stickyKeys); }
/// <summary> /// Applies the HighContrast instance's current state to the system /// </summary> /// <example> /// // turn high contrast on /// var hc = new HighContrast(); /// hc.IsHighContrastOn = true; /// hc.Apply(); /// </example> public void Apply() { Win32Struct win32Struct = new Win32Struct(); string colorSchemeText = GetColorSchemeText(this.Theme); win32Struct.lpszDefaultScheme = Marshal.StringToHGlobalUni(colorSchemeText); win32Struct.dwFlags = (int)BuildFlags(); win32Struct.cbSize = Marshal.SizeOf(win32Struct); bool result = SystemParametersInfo(uiActions.SPI_SETHIGHCONTRAST, win32Struct.cbSize, ref win32Struct, 0); Marshal.FreeHGlobal(win32Struct.lpszDefaultScheme); // TODO: Ensure this memory is freed via try/catch/finally if (!result) { throw new System.ComponentModel.Win32Exception(); } }