public Rectangle DrawEdge(IDeviceContext dc, Rectangle bounds, Edges edges, EdgeStyle style, EdgeEffects effects) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } if (!ClientUtils.IsEnumValid_Masked(edges, (int)edges, (uint)(Edges.Left | Edges.Top | Edges.Right | Edges.Bottom | Edges.Diagonal))) { throw new InvalidEnumArgumentException(nameof(edges), (int)edges, typeof(Edges)); } if (!ClientUtils.IsEnumValid_NotSequential(style, (int)style, (int)EdgeStyle.Raised, (int)EdgeStyle.Sunken, (int)EdgeStyle.Etched, (int)EdgeStyle.Bump)) { throw new InvalidEnumArgumentException(nameof(style), (int)style, typeof(EdgeStyle)); } if (!ClientUtils.IsEnumValid_Masked(effects, (int)effects, (uint)(EdgeEffects.FillInterior | EdgeEffects.Flat | EdgeEffects.Soft | EdgeEffects.Mono))) { throw new InvalidEnumArgumentException(nameof(effects), (int)effects, typeof(EdgeEffects)); } using var wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties); var hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc); RECT destRect = bounds; var contentRect = new RECT(); lastHResult = UxTheme.DrawThemeEdge(this, hdc, part, state, ref destRect, (User32.EDGE)style, (User32.BF)edges | (User32.BF)effects | User32.BF.ADJUST, ref contentRect); return(contentRect); }
public static bool SetAppMode(PreferredAppMode appMode) { var build = Environment.OSVersion.Version.Build; if (build >= 18362) { // memo: Workaround for the problem of not switching from dark theme to light theme. if (appMode == PreferredAppMode.APPMODE_DEFAULT || appMode == PreferredAppMode.APPMODE_FORCELIGHT) { UxTheme.SetPreferredAppMode(PreferredAppMode.APPMODE_ALLOWDARK); UxTheme.RefreshImmersiveColorPolicyState(); } var ret = UxTheme.SetPreferredAppMode(appMode) == appMode; UxTheme.RefreshImmersiveColorPolicyState(); return(ret); } else if (build >= 17763) { if (appMode == PreferredAppMode.APPMODE_DEFAULT || appMode == PreferredAppMode.APPMODE_FORCELIGHT) { return(UxTheme.AllowDarkModeForApp(false)); } else { return(UxTheme.AllowDarkModeForApp(true)); } } return(false); }
public Color this[string colorName] { get { IntPtr name = IntPtr.Zero; UInt32 colorType; try { name = Marshal.StringToHGlobalUni("Immersive" + colorName); colorType = UxTheme.GetImmersiveColorTypeFromName(name); if (colorType == 0xFFFFFFFF) { throw new InvalidOperationException(); } } finally { if (name != IntPtr.Zero) { Marshal.FreeHGlobal(name); name = IntPtr.Zero; } } return(this[colorType]); } }
internal unsafe void DrawBackground(IDeviceContext dc, Rectangle bounds, Rectangle clipRectangle, IntPtr hWnd) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } if (bounds.Width < 0 || bounds.Height < 0) { return; } if (clipRectangle.Width < 0 || clipRectangle.Height < 0) { return; } using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties)) { HandleRef hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc); if (IntPtr.Zero != hWnd) { using (ThemeHandle hTheme = ThemeHandle.Create(_class, true, hWnd)) { RECT rect = bounds; RECT clipRect = clipRectangle; lastHResult = UxTheme.DrawThemeBackground(hTheme, hdc, part, state, ref rect, &clipRect); } } else { RECT rect = bounds; RECT clipRect = clipRectangle; lastHResult = UxTheme.DrawThemeBackground(this, hdc, part, state, ref rect, &clipRect); } } }
internal static ThemeHandle Create(string className, bool throwExceptionOnFail, IntPtr hWndRef) { // HThemes require an HWND when display scaling is different between monitors. IntPtr hTheme = IntPtr.Zero; try { hTheme = UxTheme.OpenThemeData(hWndRef, className); } catch (Exception e) when(!ClientUtils.IsSecurityOrCriticalException(e)) { if (throwExceptionOnFail) { throw new InvalidOperationException(SR.VisualStyleHandleCreationFailed, e); } return(null); } if (hTheme == IntPtr.Zero) { if (throwExceptionOnFail) { throw new InvalidOperationException(SR.VisualStyleHandleCreationFailed); } return(null); } return(new ThemeHandle(hTheme)); }
/// <inheritdoc /> /// <summary>Raises the <see cref="M:System.Windows.Forms.Control.CreateControl" /> method.</summary> protected override void OnCreateControl() { // remove border BorderStyle = BorderStyle.None; if (!DesignMode) { // set native look for list view items UxTheme.SetWindowTheme(Handle, "explorer", null); // remove focus cues User32.SendMessage(Handle, (uint)User32.WindowMessage.WM_CHANGEUISTATE, new IntPtr(BitHelper.MakeLong((int)User32.UIStateFlags.UIS_SET, (int)User32.UIStateFlags.UISF_HIDEFOCUS)), IntPtr.Zero); // enable double buffer to reduce flicker and display a traslucent selection box User32.SendMessage(Handle, (uint)User32.WindowMessage.LVM_SETEXTENDEDLISTVIEWSTYLE, new IntPtr((int)User32.WindowStylesEx.LVS_EX_DOUBLEBUFFER), new IntPtr((int)User32.WindowStylesEx.LVS_EX_DOUBLEBUFFER)); // reset hot cursor User32.SendMessage(Handle, (uint)User32.WindowMessage.LVM_SETHOTCURSOR, IntPtr.Zero, Cursors.Arrow.Handle); } base.OnCreateControl(); }
public static string GetCurrentThemePath() { var sbFilename = new StringBuilder(0x200); var s = UxTheme.GetCurrentThemeName(sbFilename, 0x200, null, 0, null, 0); return(sbFilename.ToString()); }
protected override void OnHandleCreated(EventArgs e) { base.OnHandleCreated(e); SetDoubleBuffer(); SetExpandoesStyle(); SendMessage(this.Handle, TVM_SETEXTENDEDSTYLE, (IntPtr)TVS_EX_AUTOHSCROLL, (IntPtr)TVS_EX_AUTOHSCROLL); UxTheme.SetWindowTheme(this.Handle, "Explorer", 0); }
public override void DrawParentBackground(Graphics graphics, Rectangle bounds, Control childControl) { using (var mh = ManagedHdc.FromGraphics(graphics)) { var rect = Win32.RECT.FromRectangle(bounds); UxTheme.DrawThemeParentBackground(_theme, mh.Hdc, ref rect); } }
public override void DrawBackground(Graphics graphics, Rectangle bounds) { using (var mh = ManagedHdc.FromGraphics(graphics)) { var rect = Win32.RECT.FromRectangle(bounds); UxTheme.DrawThemeBackground(_theme, mh.Hdc, _partId, _stateId, ref rect, IntPtr.Zero); } }
internal static bool IsCombinationDefined(string className, int part) { bool returnVal = false; if (!IsSupported) { if (!VisualStyleInformation.IsEnabledByUser) { throw new InvalidOperationException(SR.VisualStyleNotActive); } else { throw new InvalidOperationException(SR.VisualStylesDisabledInClientArea); } } if (className == null) { throw new ArgumentNullException(nameof(className)); } IntPtr hTheme = GetHandle(className, false); if (hTheme != IntPtr.Zero) { // IsThemePartDefined doesn't work for part = 0, although there are valid parts numbered 0. We // allow these explicitly here. if (part == 0) { returnVal = true; } else { returnVal = UxTheme.IsThemePartDefined(hTheme, part, 0).IsTrue(); } } //if the combo isn't defined, check the validity of our theme handle cache if (!returnVal) { using (ThemeHandle tHandle = ThemeHandle.Create(className, false)) { if (tHandle != null) { returnVal = UxTheme.IsThemePartDefined(tHandle, part, 0).IsTrue(); } //if we did, in fact get a new correct theme handle, our cache is out of date -- update it now. if (returnVal) { RefreshCache(); } } } return(returnVal); }
public override void DrawText(Graphics graphics, Rectangle bounds, string text) { using (var mh = ManagedHdc.FromGraphics(graphics)) { var rect = Win32.RECT.FromRectangle(bounds); uint flags = (int)(TextFormatFlags.EndEllipsis); UxTheme.DrawThemeText(_theme, mh.Hdc, _partId, _stateId, text, text.Length, flags, 0, ref rect); } }
protected override void OnHandleCreated(EventArgs e) { if (!IsDesignMode) { UxTheme.SetWindowTheme(this.Handle, string.Empty, string.Empty); User32.DisableProcessWindowsGhosting(); } base.OnHandleCreated(e); }
public void Dispose() { if (Handle != IntPtr.Zero) { UxTheme.CloseThemeData(Handle); Handle = IntPtr.Zero; } GC.SuppressFinalize(this); }
public NativeStyleRenderer(IntPtr handle, VisualStyleElement element) { if (element == null) { throw new ArgumentNullException("element", "element is null."); } _theme = UxTheme.OpenTheme(handle, element.ClassName); _partId = element.Part; _stateId = element.State; }
public bool GetBoolean(BooleanProperty prop) { if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)BooleanProperty.Transparent, (int)BooleanProperty.SourceShrink)) { throw new InvalidEnumArgumentException(nameof(prop), (int)prop, typeof(BooleanProperty)); } BOOL val = BOOL.FALSE; lastHResult = UxTheme.GetThemeBool(this, part, state, (int)prop, ref val); return(val.IsTrue()); }
internal static void SetWindowTheme(Control window, String SubAppName, String SubIdList) { if (!Application.RenderWithVisualStyles) { return; } int result; if ((result = UxTheme.SetWindowTheme(window.Handle, SubAppName, SubIdList)) < 0) { throw new InvalidOperationException("SetWindowTheme failed with error " + result.ToString()); } }
public Color this[UInt32 colorType] { get { UInt32 nativeColor = UxTheme.GetImmersiveColorFromColorSetEx(this._colorSet, colorType, false, 0); //if (nativeColor == 0) // throw new InvalidOperationException(); return(Color.FromArgb( (Byte)((0xFF000000 & nativeColor) >> 24), (Byte)((0x000000FF & nativeColor) >> 0), (Byte)((0x0000FF00 & nativeColor) >> 8), (Byte)((0x00FF0000 & nativeColor) >> 16) )); } }
public int GetInteger(IntegerProperty prop) { //valid values are 0x961 to 0x978 if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)IntegerProperty.ImageCount, (int)IntegerProperty.MinDpi5)) { throw new InvalidEnumArgumentException(nameof(prop), (int)prop, typeof(IntegerProperty)); } int val = 0; lastHResult = UxTheme.GetThemeInt(this, part, state, (int)prop, ref val); return(val); }
public int GetEnumValue(EnumProperty prop) { //valid values are 0xfa1 to 0xfaf if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)EnumProperty.BackgroundType, (int)EnumProperty.TrueSizeScalingType)) { throw new InvalidEnumArgumentException(nameof(prop), (int)prop, typeof(EnumProperty)); } int val = 0; lastHResult = UxTheme.GetThemeEnumValue(this, part, state, (int)prop, ref val); return(val); }
public Color GetColor(ColorProperty prop) { //valid values are 0xed9 to 0xeef if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)ColorProperty.BorderColor, (int)ColorProperty.AccentColorHint)) { throw new InvalidEnumArgumentException(nameof(prop), (int)prop, typeof(ColorProperty)); } int color = 0; lastHResult = UxTheme.GetThemeColor(this, part, state, (int)prop, ref color); return(ColorTranslator.FromWin32(color)); }
public void GetThemeStreamTest() { Application.EnableVisualStyles(); using (var h = OpenThemeData(HWND.NULL, "DWMWINDOW")) { Assert.That(h.IsInvalid, Is.False); using (var hInstance = Kernel32.LoadLibraryEx(@"C:\Windows\resources\themes\Aero\Aero.msstyles", Kernel32.LoadLibraryExFlags.LOAD_LIBRARY_AS_DATAFILE)) { var hr = UxTheme.GetThemeStream(h, 0, 0, 213, out var themeStream, out var streamSize, hInstance); Assert.That(hr.Succeeded); Assert.That(streamSize, Is.GreaterThan(0)); Assert.That(() => themeStream.ToArray <byte>((int)streamSize), Throws.Nothing); } } }
public ArchiveDetailView(string pathIconLibrary, string pathArchive) { InitializeComponent(); //_iconReader = new IconReader(); //archiveTree.ImageList = new ImageList(); //_iconReader.ReadIcons(pathIconLibrary).ForEach(o => archiveTree.ImageList.Images.Add(o.Icon)); UxTheme.SetWindowTheme(lvArchiveDetails.Handle, "Explorer", 0); SysImageListHelper.SetListViewImageList(lvArchiveDetails, lst, false); SevenZipExtractor.SetLibraryPath(IntPtr.Size == 8 ? "7z64.dll" : "7z32.dll"); _pathArchive = pathArchive; Shown += ShowArchiveContent; }
// HACK: GetAllColorNames collects the available color names by brute forcing the OS function. // Since there is currently no known way to retrieve all possible color names, // the method below just tries all indices from 0 to 0xFFF ignoring errors. public List <String> GetAllColorNames() { List <String> allColorNames = new List <String>(); for (UInt32 i = 0; i < 0xFFF; i++) { IntPtr typeNamePtr = UxTheme.GetImmersiveColorNamedTypeByIndex(i); if (typeNamePtr != IntPtr.Zero) { IntPtr typeName = (IntPtr)Marshal.PtrToStructure(typeNamePtr, typeof(IntPtr)); allColorNames.Add(Marshal.PtrToStringUni(typeName)); } } return(allColorNames); }
private void DrawBorder(System.Drawing.Graphics g) { IntPtr hTheme = UxTheme.OpenThemeData(this.Handle, "EDIT"); // Makes sure Windows XP is running and // a .manifest file exists for the EXE. if (Environment.OSVersion.Version.Major >= 5 && Environment.OSVersion.Version.Minor > 0 && System.IO.File.Exists(Application.ExecutablePath + ".manifest") && (hTheme != IntPtr.Zero)) { //Get DC IntPtr hDC = g.GetHdc(); int state = (int)UxTheme.ETS_NORMAL; switch (this.m_state) { case State.Disabled: state = (int)UxTheme.ETS_DISABLED; break; default: break; } try { RECT r = new RECT(this.ClientRectangle.Left, this.ClientRectangle.Right, this.ClientRectangle.Top, this.ClientRectangle.Bottom); //Render button IntPtr hr = UxTheme.DrawThemeBackground(hTheme, hDC, UxTheme.EP_EDITTEXT, state, r, null); } finally { //Release DC g.ReleaseHdc(hDC); UxTheme.CloseThemeData(hTheme); } } else { using (Graphics y = this.CreateGraphics()) { ControlPaint.DrawBorder(y, ClientRectangle, SystemColors.Control, ButtonBorderStyle.Inset); } } }
public TaskbarButton(VisibleWindow window) { if (window == null) { throw new ArgumentNullException("window", "window is null."); } Window = window; Icon = window.Icon; Image = Icon.ToBitmap(); Text = window.Title; Margin = Padding.Empty; //TODO: find a way to do this managed... // it just doesnt work to call this and use // a managed VisualStyleRenderer instead =/ UxTheme.SetWindowTheme(base.Handle, "Taskband", null); }
public static Image GetDwmWindowButton(AeroTitlebarButtonPart button, TitlebarButtonState state) { const int tmtAtlasrect = 8002; const int tmtImagecount = 2401; using (var vs = GetDwmWindowVisualTheme()) { using (var hInstance = LoadAeroTheme()) { Image result; using (var nWindow = CreateNativeWindow()) { using (var theme = LoadAeroThemeData(nWindow)) { var atlas = GetImageAtlasFromTheme(vs, hInstance); if (atlas == null) { return(null); } var rect = GetThemeRect(theme, (int)button, (int)state, tmtAtlasrect); result = Slice(atlas, rect.Location, rect.Size); if (state != TitlebarButtonState.None) { //Slice the buttons UxTheme.GetThemeInt(theme, (int)button, (int)state, tmtImagecount, out var count); var buttonSize = rect.Height / count; var startPoint = Point.Empty; var btnSize = new Size(rect.Width, buttonSize); startPoint.Offset(0, buttonSize * ((int)state - 1)); var buttonRect = new Rectangle(startPoint, btnSize); buttonRect.Inflate(-1, -1); result = Slice(result, buttonRect.Location, buttonRect.Size); } } } return(result); } } }
// HACK: GetAllColorNames collects the available color names by brute forcing the OS function. // Since there is currently no known way to retrieve all possible color names, // the method below just tries all indices from 0 to 0xFFF ignoring errors. public List <string> GetAllColorNames() { var allColorNames = new List <string>(); for (uint i = 0; i < 0xFFF; i++) { var typeNamePtr = UxTheme.GetImmersiveColorNamedTypeByIndex(i); if (typeNamePtr == IntPtr.Zero) { continue; } var typeName = (IntPtr)Marshal.PtrToStructure(typeNamePtr, typeof(IntPtr)); allColorNames.Add(Marshal.PtrToStringUni(typeName)); } return(allColorNames); }
public Font GetFont(IDeviceContext dc, FontProperty prop) { if (dc == null) { throw new ArgumentNullException(nameof(dc)); } //valid values are 0xa29 to 0xa29 if (!ClientUtils.IsEnumValid(prop, (int)prop, (int)FontProperty.GlyphFont, (int)FontProperty.GlyphFont)) { throw new InvalidEnumArgumentException(nameof(prop), (int)prop, typeof(FontProperty)); } User32.LOGFONTW logfont = new User32.LOGFONTW(); using (WindowsGraphicsWrapper wgr = new WindowsGraphicsWrapper(dc, AllGraphicsProperties)) { HandleRef hdc = new HandleRef(wgr, wgr.WindowsGraphics.DeviceContext.Hdc); lastHResult = UxTheme.GetThemeFont(new HandleRef(this, Handle), hdc, part, state, (int)prop, ref logfont); } Font font = null; //check for a failed HR. if (lastHResult.Succeeded()) { try { font = Font.FromLogFont(logfont); } catch (Exception e) { if (ClientUtils.IsSecurityOrCriticalException(e)) { throw; } //Looks like the font was not true type font = null; } } return(font); }
static void Main() { try { AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); WindowManager.Start(); Application.Run(new Taskbar()); } finally { WindowManager.Stop(); UxTheme.CloseThemes(); AppBar.UnregisterAll(); } }